6 struct harness_cfg
*cfg
= NULL
;
7 struct harness_test tests
[MAX_TESTS
] = {0};
10 harness_init(struct harness_cfg
*harness_cfg
)
12 if (harness_cfg
== NULL
) {
13 (void)fprintf(stderr
, "harness: harness_cfg cannot be NULL\n");
16 if (harness_cfg
->setup
== NULL
|| harness_cfg
->teardown
== NULL
) {
17 (void)fprintf(stderr
, "harness: setup or teardown functions "
27 harness_add_test(char *test_name
, test_function
*test
, void *user_data
)
29 if (cfg
->ntests
>= MAX_TESTS
) {
30 (void)fprintf(stderr
, "harness: Unable to add more tests\n");
33 tests
[cfg
->ntests
].test_functions
= test
;
34 tests
[cfg
->ntests
].test_name
= test_name
;
35 tests
[cfg
->ntests
].user_data
= user_data
;
42 harness_run(void *user_data
)
44 int res
, npass
, nfail
;
46 cfg
->setup(user_data
);
47 (void)fprintf(stdout
, "[----------] Test environment set-up.\n");
49 res
= npass
= nfail
= 0;
50 (void)fprintf(stdout
, "[==========] Running %d test cases.\n",
52 for (int i
= 0; i
< cfg
->ntests
; i
++) {
53 res
= tests
[i
].test_functions(tests
[i
].user_data
);
55 (void)fprintf(stdout
, "[ %8s ] %s\n", "OK",
59 (void)fprintf(stdout
, "[ %8s ] %s\n", "NOK",
65 (void)fprintf(stdout
, "[==========] %d test cases ran.\n", cfg
->ntests
);
66 (void)fprintf(stdout
, "[ PASSED ] %d tests.\n", npass
);
67 (void)fprintf(stdout
, "[ FAILED ] %d tests.\n", nfail
);
69 cfg
->teardown(user_data
);
70 (void)fprintf(stdout
, "[----------] Test environment teardown.\n");