diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-02-20 21:48:29 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-02-20 21:48:29 -0500 |
commit | f3d21c128e5b40acd1f15e3ddcd7fd54ca3a9bed (patch) | |
tree | df9d7ed4b1948e04437d046b5ed2f85949993edb /tests/runner.c | |
parent | 8a1912c177e978574250cf80f8a50edf7424b158 (diff) |
Introduce test framework for LITMUS^RT.
This is the beginning of the LITMUS^RT testsuite.
The main design goals are flexibility and ease of test writing.
To create a new test, simply write a test case in any C file in the
tests/ subdirectory. The buildsystem will find the test and hook it
up with the testrunner.
Have a look at tests/fdso.c and include/tests.h to get an idea for what
tests look like.
Tests can be executed with the 'runtests' tool. Each testcase is executed
in a separate process in order to ensure that tests do not influence
each other.
Diffstat (limited to 'tests/runner.c')
-rw-r--r-- | tests/runner.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/runner.c b/tests/runner.c new file mode 100644 index 0000000..f2e42b2 --- /dev/null +++ b/tests/runner.c | |||
@@ -0,0 +1,77 @@ | |||
1 | #include <fcntl.h> | ||
2 | #include <unistd.h> | ||
3 | |||
4 | #include <sys/wait.h> | ||
5 | |||
6 | #include <string.h> | ||
7 | #include <stdio.h> | ||
8 | |||
9 | |||
10 | /* auto generated by SConstruct */ | ||
11 | #include "__test_catalog.inc" | ||
12 | |||
13 | #include "litmus.h" | ||
14 | |||
15 | int run_test(struct testcase *tc) { | ||
16 | int status; | ||
17 | pid_t pid; | ||
18 | |||
19 | printf("** Testing: %s... ", tc->description); | ||
20 | fflush(stdout); | ||
21 | SYSCALL( pid = fork() ); | ||
22 | if (pid == 0) { | ||
23 | /* child: init liblitmus and carry out test */ | ||
24 | SYSCALL( init_litmus() ); | ||
25 | tc->function(); | ||
26 | exit(0); | ||
27 | } else { | ||
28 | /* parent: wait for completion of test */ | ||
29 | SYSCALL( waitpid(pid, &status, 0) ); | ||
30 | if (WEXITSTATUS(status) == 0) | ||
31 | printf("ok.\n"); | ||
32 | } | ||
33 | return WEXITSTATUS(status) == 0; | ||
34 | } | ||
35 | |||
36 | int run_tests(int* testidx, int num_tests, const char* plugin) | ||
37 | { | ||
38 | int idx, i; | ||
39 | int ok = 0; | ||
40 | |||
41 | printf("** Running tests for %s.\n", plugin); | ||
42 | for (i = 0; i < num_tests; i++) { | ||
43 | idx = testidx[i]; | ||
44 | ok += run_test(test_catalog + idx); | ||
45 | } | ||
46 | return ok; | ||
47 | } | ||
48 | |||
49 | #define streq(s1, s2) (!strcmp(s1, s2)) | ||
50 | |||
51 | int main(int argc, char** argv) | ||
52 | { | ||
53 | int ok, i; | ||
54 | |||
55 | printf("** LITMUS^RT test suite.\n"); | ||
56 | |||
57 | if (argc == 2) { | ||
58 | for (i = 0; i < NUM_PLUGINS; i++) | ||
59 | if (streq(testsuite[i].plugin, argv[1])) { | ||
60 | ok = run_tests(testsuite[i].testcases, | ||
61 | testsuite[i].num_cases, | ||
62 | testsuite[i].plugin); | ||
63 | printf("** Result: %d ok, %d failed.\n", | ||
64 | ok, testsuite[i].num_cases - ok); | ||
65 | return ok == testsuite[i].num_cases ? 0 : 3; | ||
66 | } | ||
67 | fprintf(stderr, "** Unknown plugin: '%s'\n", argv[1]); | ||
68 | return 1; | ||
69 | } else { | ||
70 | fprintf(stderr, "Usage: %s <plugin name>\n", argv[0]); | ||
71 | fprintf(stderr, "Supported plugins: "); | ||
72 | for (i = 0; i < NUM_PLUGINS; i++) | ||
73 | fprintf(stderr, "%s ", testsuite[i].plugin); | ||
74 | fprintf(stderr, "\n"); | ||
75 | return 2; | ||
76 | } | ||
77 | } | ||