-
Notifications
You must be signed in to change notification settings - Fork 2
/
nanotest_main.c
57 lines (42 loc) · 1.68 KB
/
nanotest_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <nanotest.h>
#include <autogen_tests.h>
/* Global pointers to test state. Neither are thread safe in this case
* and there is a race condition on callees corrupting them if they should
* crash during test.
*
* FIXME: Not thread safe.
*/
struct nanotest_fail g_nanotest_fail;
jmp_buf g_nanotest_jmpbuf;
/* Declared as global to prevent clobbering by setjmp/longjmp() */
static struct nanotest_unit** ptr = autogen_tests;
static struct nanotest_unit* test;
static int tests_run = 0;
static int tests_failed = 0;
int main(void)
{
/* Iterate until the end of array NULL pointer is encountered */
while ((test = *ptr++)) {
printf("[Running ] %s::%s\n", test->suite, test->name);
/* Jump back to this point if a test fails */
int ret = setjmp(g_nanotest_jmpbuf);
if (!ret) {
test->func(test);
/* Only gets to this line if longjmp() isn't called first */
printf("[ Done] %s::%s\n", test->suite, test->name);
} else {
printf("[ FAILED] %s::%s %s:%u\n", test->suite, test->name,
g_nanotest_fail.file,
g_nanotest_fail.line);
printf("[ MSG] %s::%s assert( %s )\n", test->suite, test->name,
g_nanotest_fail.expr);
tests_failed += 1;
}
tests_run += 1;
}
printf("=========================================\n");
printf("Tests run: %d\n",tests_run);
printf("Tests failed: %d\n", tests_failed);
return (tests_failed ? 1 : 0);
}