3c3f19141e5747b75e2d632e27a0b4c2f51bfe1e
[lunaix-os.git] / lunaix-os / tests / shared / framework.c
1 #include <testing/basic.h>
2 #include <testing/memchk.h>
3 #include <stdlib.h>
4
5 struct test_context* __test_ctx;
6
7 void 
8 main(int argc, const char* argv[])
9 {
10     __test_ctx = calloc(sizeof(*__test_ctx), 1);
11
12     printf("\n");
13
14     run_test(argc, argv);
15
16     printf(
17         "All test done: %d passed, %d failed\n\n",
18         __test_ctx->stats.total_passed,
19         __test_ctx->stats.total_failed
20     );
21
22     memchk_print_stats();
23
24     printf("\n************\n\n");
25
26     exit(__test_ctx->stats.total_failed > 0);
27 }
28
29 void
30 begin_testcase(const char* name)
31 {
32     if (__test_ctx->name) {
33         printf("previous test case: '%s' is still actuive\n", name);
34         exit(1);
35     }
36
37     __test_ctx->name = name;
38     __test_ctx->stats.countings[0] = 0;
39     __test_ctx->stats.countings[1] = 0;
40
41     printf("%s\n", name);
42 }
43
44 void
45 end_testcase()
46 {
47     printf("..... passed: %d, failed: %d\n\n", 
48             __test_ctx->stats.passed, __test_ctx->stats.failed);
49
50     __test_ctx->stats.total_passed += __test_ctx->stats.passed;
51     __test_ctx->stats.total_failed += __test_ctx->stats.failed;
52     __test_ctx->name = NULL;
53
54 }