aboutsummaryrefslogtreecommitdiffstats
path: root/include/tests.h
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2010-02-20 21:48:29 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2010-02-20 21:48:29 -0500
commitf3d21c128e5b40acd1f15e3ddcd7fd54ca3a9bed (patch)
treedf9d7ed4b1948e04437d046b5ed2f85949993edb /include/tests.h
parent8a1912c177e978574250cf80f8a50edf7424b158 (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 'include/tests.h')
-rw-r--r--include/tests.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/include/tests.h b/include/tests.h
new file mode 100644
index 0000000..3adba18
--- /dev/null
+++ b/include/tests.h
@@ -0,0 +1,50 @@
1#ifndef TESTS_H
2#define TESTS_H
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <errno.h>
7
8#define fail(fmt, args...) \
9 do { \
10 fprintf(stderr, "\n!! TEST FAILURE " fmt "\n at %s:%d (%s)\n", \
11 ## args, __FILE__, __LINE__, __FUNCTION__); \
12 fflush(stderr); \
13 exit(200); \
14 } while (0)
15
16#define ASSERT(predicate) \
17 do { \
18 if (!(predicate)) \
19 fail("%s", #predicate); \
20 } while (0)
21
22#define SYSCALL(call) \
23 do { \
24 if ((call) < 0) \
25 fail("%s, %m", #call); \
26 } while (0)
27
28#define SYSCALL_FAILS(expected, call) \
29 do { \
30 if ((call) == 0 || errno != (expected)) \
31 fail("%s, %m (expected: %s)", #call, #expected); \
32 } while (0)
33
34
35typedef void (*testfun_t)(void);
36
37struct testcase {
38 testfun_t function;
39 const char* description;
40};
41
42struct testsuite {
43 const char* plugin;
44 int* testcases;
45 int num_cases;
46};
47
48#define TESTCASE(function, plugins, description) void test_ ## function (void)
49
50#endif