aboutsummaryrefslogtreecommitdiffstats
path: root/tests/runner.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/runner.c')
-rw-r--r--tests/runner.c77
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
15int 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
36int 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
51int 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}