x1000-installer: simple test suite runner

Change-Id: I0b9ee81cbd8dda593924b2f7c32a1d1d87ce84b0
This commit is contained in:
Aidan MacDonald 2021-11-28 13:44:16 +00:00
parent 7ca8623927
commit b027063c03
2 changed files with 80 additions and 60 deletions

View file

@ -19,54 +19,43 @@
* *
****************************************************************************/ ****************************************************************************/
#include "xf_nandio.h"
#include "xf_error.h"
#include "xf_update.h"
#include "file.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
static struct xf_nandio nio; static int test_num_executed = 0;
static int test_num_failed = 0;
int test_num_asserts_executed = 0;
int test_num_asserts_failed = 0;
static struct xf_map testmap[] = { void test_failure(const char* file, int line, const char* msg)
{ {
.name = "src/xf_error.c", fprintf(stderr, "%s:%d: ASSERTION FAILED: %s\n", file, line, msg);
.offset = 0x00000000, ++test_num_asserts_failed;
.length = 0x00004000, }
},
{ typedef void(*test_t)(void);
.name = "src/xf_update.c",
.offset = 0x00010000, struct test_info {
.length = 0x00004000, const char* name;
}, test_t func;
{
.name = "src/xf_package.c",
.offset = 0x00020000,
.length = 0x00001800,
},
}; };
void checkrc(int rc) #define TEST(x) {#x, x}
static const struct test_info all_tests[] = {
};
#undef TEST
void run_test(const struct test_info* tinfo)
{ {
if(rc == XF_E_SUCCESS) int asserts_now = test_num_asserts_failed;
return; ++test_num_executed;
if(rc == XF_E_NAND) { fprintf(stderr, "RUN %s\n", tinfo->name);
printf("NAND error: %d\n", nio.nand_err); tinfo->func();
} else {
printf("error: %s\n", xf_strerror(rc)); if(test_num_asserts_failed > asserts_now) {
printf(" CurBlock = %lu\n", (unsigned long)nio.cur_block); fprintf(stderr, " %s: FAILED!\n", tinfo->name);
printf(" CurOffset = %lu\n", (unsigned long)nio.offset_in_block); ++test_num_failed;
} }
exit(1);
}
int openstream_file(void* arg, const char* file, struct xf_stream* stream)
{
(void)arg;
return xf_open_file(file, O_RDONLY, stream);
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
@ -74,25 +63,17 @@ int main(int argc, char* argv[])
(void)argc; (void)argc;
(void)argv; (void)argv;
nand_trace_reset(65535); size_t num_tests = sizeof(all_tests) / sizeof(struct test_info);
for(size_t i = 0; i < num_tests; ++i)
run_test(&all_tests[i]);
int rc = xf_nandio_init(&nio); fprintf(stderr, "------------------------------------------\n");
checkrc(rc); fprintf(stderr, "TEST COMPLETE\n");
fprintf(stderr, " Tests %d failed / %d executed\n",
test_num_failed, test_num_executed);
fprintf(stderr, " Assertions %d failed / %d executed\n",
test_num_asserts_failed, test_num_asserts_executed);
rc = xf_updater_run(XF_UPDATE, &nio, if(test_num_failed > 0)
testmap, sizeof(testmap)/sizeof(struct xf_map), return 1;
openstream_file, NULL);
checkrc(rc);
for(size_t i = 0; i < nand_trace_length; ++i) {
const char* types[] = {"READ", "PROGRAM", "ERASE"};
const char* excep[] = {"NONE", "DOUBLE_PROGRAMMED", "CLEARED"};
printf("%s %s %lu\n",
types[nand_trace[i].type],
excep[nand_trace[i].exception],
(unsigned long)nand_trace[i].addr);
}
xf_nandio_destroy(&nio);
return 0;
} }

View file

@ -0,0 +1,39 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2021 Aidan MacDonald
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef TEST_H
#define TEST_H
extern int test_num_asserts_executed;
extern int test_num_asserts_failed;
extern void test_failure(const char* file, int line, const char* msg);
#define T_ASSERT(cond) \
do { \
++test_num_asserts_executed; \
if(!(cond)) { \
test_failure(__FILE__, __LINE__, #cond); \
goto cleanup; \
} \
} while(0)
#endif