]> git.ipfire.org Git - thirdparty/kmod.git/blob - testsuite/testsuite.h
testsuite: add trap to fopen() including tests
[thirdparty/kmod.git] / testsuite / testsuite.h
1 #ifndef _LIBKMOD_TESTSUITE_
2 #define _LIBKMOD_TESTSUITE_
3
4 #include <stdbool.h>
5 #include <stdarg.h>
6
7 struct test;
8 typedef int (*testfunc)(const struct test *t);
9
10 enum test_config {
11 TC_ROOTFS = 0,
12 TC_UNAME_R,
13 _TC_LAST,
14 };
15
16 #define S_TC_ROOTFS "TESTSUITE_ROOTFS"
17 #define S_TC_UNAME_R "TESTSUITE_UNAME_R"
18
19
20 struct test {
21 const char *name;
22 const char *description;
23 testfunc func;
24 const char *config[_TC_LAST];
25 bool need_spawn;
26 };
27
28
29 const struct test *test_find(const struct test *tests[], const char *name);
30 int test_init(int argc, char *const argv[], const struct test *tests[]);
31 int test_spawn_prog(const char *prog, const char *args[]);
32
33 int test_run(const struct test *t);
34
35 #define TS_EXPORT __attribute__ ((visibility("default")))
36
37 #define _LOG(prefix, fmt, ...) printf("TESTSUITE: " prefix fmt, ## __VA_ARGS__)
38 #define LOG(fmt, ...) _LOG("", fmt, ## __VA_ARGS__)
39 #define WARN(fmt, ...) _LOG("WARN: ", fmt, ## __VA_ARGS__)
40 #define ERR(fmt, ...) _LOG("ERR: ", fmt, ## __VA_ARGS__)
41
42 /* Test definitions */
43 #define DEFINE_TEST(_name) \
44 struct test s_name = { \
45 .name = #_name, \
46 .func = _name, \
47 }
48
49 #endif