diff options
Diffstat (limited to '02-usart/test_harness')
-rw-r--r-- | 02-usart/test_harness/fake_env.c | 3 | ||||
-rw-r--r-- | 02-usart/test_harness/fake_env.h | 1 | ||||
-rw-r--r-- | 02-usart/test_harness/test_harness.c | 66 | ||||
-rw-r--r-- | 02-usart/test_harness/test_harness.h | 38 |
4 files changed, 93 insertions, 15 deletions
diff --git a/02-usart/test_harness/fake_env.c b/02-usart/test_harness/fake_env.c index d1dba35..43a6caa 100644 --- a/02-usart/test_harness/fake_env.c +++ b/02-usart/test_harness/fake_env.c @@ -14,6 +14,9 @@ return fake_##name; \ } +/* Reset and clock control. */ +DEFINE_MEMORY_SEGMENT(rcc, 0x40021000, 0x400210A0) + /* Peripheral buses */ DEFINE_MEMORY_SEGMENT(apb1, 0x40000000, 0x40010000) DEFINE_MEMORY_SEGMENT(apb2, 0x40010000, 0x40020000) diff --git a/02-usart/test_harness/fake_env.h b/02-usart/test_harness/fake_env.h index 3cc6310..787abf5 100644 --- a/02-usart/test_harness/fake_env.h +++ b/02-usart/test_harness/fake_env.h @@ -11,5 +11,6 @@ void* load_fake_sram1__(); void* load_fake_sram2__(); void* load_fake_scb__(); void* load_fake_nvic__(); +void* load_fake_rcc__(); #endif /* FAKE_ENV_H_ */ diff --git a/02-usart/test_harness/test_harness.c b/02-usart/test_harness/test_harness.c index 3a6d10a..87606ee 100644 --- a/02-usart/test_harness/test_harness.c +++ b/02-usart/test_harness/test_harness.c @@ -26,7 +26,58 @@ test_t* iter = &__start_tests; static int execute_test(test_t* test); -int main() { +void test_printll(size_t sz, long long v1, long long v2) +{ + fprintf(stderr, "%lld == %lld\n", v1, v2); +} +void test_printul(size_t sz, unsigned long v1, unsigned long v2) +{ + fprintf(stderr, "%lu == %lu\n", v1, v2); +} +void test_printd(size_t sz, int v1, int v2) +{ + fprintf(stderr, "%d == %d\n", v1, v2); +} +void test_printl(size_t sz, long v1, long v2) +{ + fprintf(stderr, "%lu == %lu\n", v1, v2); +} +void test_printui(size_t sz, unsigned int v1, unsigned int v2) +{ + fprintf(stderr, "%u == %u\n", v1, v2); +} +void test_prints(size_t sz, short v1, short v2) +{ + fprintf(stderr, "%hu == %hu\n", v1, v2); +} +void test_printus(size_t sz, unsigned short v1, unsigned short v2) +{ + fprintf(stderr, "%hu == %hu\n", v1, v2); +} +void test_printc(size_t sz, char v1, char v2) +{ + fprintf(stderr, "'%c' == '%c'\n", v1, v2); +} +void test_printf(size_t sz, double v1, double v2) +{ + fprintf(stderr, "%f == %f\n", v1, v2); +} +void test_printp(size_t sz, void* v1, void* v2) +{ + fprintf(stderr, "%p == %p\n", v1, v2); +} +void test_printuc( + size_t sz, unsigned char v1, unsigned char v2) +{ + fprintf(stderr, "%02x == %02x\n", (int) v1, (int) v2); +} + +int do_fork = 1; +int main(int argc, char** argv) { + if (argc > 1 && strcmp(argv[1], "--nofork") == 0) { + do_fork = 0; + } + for( ; iter < &__stop_tests; ++ iter) { if (iter->fn_ptr != NULL) { execute_test(iter); @@ -44,12 +95,23 @@ static int execute_test(test_t* test) { char fullname[512]; int status; - int ec; + int ec = 0; pid_t pid; snprintf( fullname, sizeof(fullname), "%s::%s", iter->test_suite, iter->test_name); + if (!do_fork) { + if ((ec = setjmp(jmpbuf)) == 0) { + test->fn_ptr(); + printf("%s " GREEN "[PASS]" RESET "\n", fullname); + return 0; + } else { + printf("%s " RED "[FAIL] %d" RESET "\n", fullname, ec); + return ec; + } + } + if (!(pid = fork())) { // child diff --git a/02-usart/test_harness/test_harness.h b/02-usart/test_harness/test_harness.h index 74f3faa..b236cba 100644 --- a/02-usart/test_harness/test_harness.h +++ b/02-usart/test_harness/test_harness.h @@ -19,19 +19,31 @@ typedef struct { #define GENPR(fmt, v1, v2) \ fprintf(stderr, fmt "\n", v1, v2) +void test_printll(size_t sz, long long v1, long long v2); +void test_printul(size_t sz, unsigned long v1, unsigned long v2); +void test_printd(size_t sz, int v1, int v2); +void test_printl(size_t sz, long v1, long v2); +void test_printui(size_t sz, unsigned int v1, unsigned int v2); +void test_prints(size_t sz, short v1, short v2); +void test_printus(size_t sz, unsigned short v1, unsigned short v2); +void test_printc(size_t sz, char v1, char v2); +void test_printf(size_t sz, double v1, double v2); +void test_printp(size_t sz, void* v1, void* v2); +void test_printuc(size_t sz, unsigned char v1, unsigned char v2); + #define FORMAT_STRING(v1, v2) \ - fprintf( \ - stderr, \ - _Generic((v1), long: "%ld == %ld\n", \ - unsigned long: "%lu == %lu\n", \ - int: "%d == %d\n", \ - unsigned int: "%u == %u\n", \ - short: "%hu == %hu\n", \ - unsigned short: "%hu == %hu\n", \ - char: "%c == %c\n", \ - double: "%f == %f\n", \ - default: "%p == %p\n"), \ - (v1), (v2)); \ + _Generic((v1), \ + long long: test_printll, \ + unsigned long: test_printul, \ + int: test_printd, \ + long: test_printl, \ + unsigned int: test_printui, \ + short: test_prints, \ + unsigned short: test_printus, \ + char: test_printc, \ + unsigned char: test_printuc, \ + double: test_printf, \ + default: test_printp)(sizeof(v1), v1, v2) \ #define TRY_PRINT_TYPE(v1, v2, type, fmt) \ else if (__builtin_types_compatible_p(typeof (v1), type)) { \ @@ -54,7 +66,7 @@ typedef struct { do { \ if ((x) != (y)) { \ fprintf(stderr, RED "ASSERT_EQ FAILED! " RESET "Not true that "); \ - FORMAT_STRING(x, y); \ + FORMAT_STRING((x), (y)); \ fprintf(stderr, " - " YELLOW "In expression ASSERT_EQ(" #x ", " #y ")\n"); \ fprintf(stderr, RESET " - " YELLOW "At " __FILE__ ":%d\n" RESET, __LINE__); \ test_harness_abort(1); \ |