diff options
Diffstat (limited to 'include/tests.h')
| -rw-r--r-- | include/tests.h | 50 |
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 | |||
| 35 | typedef void (*testfun_t)(void); | ||
| 36 | |||
| 37 | struct testcase { | ||
| 38 | testfun_t function; | ||
| 39 | const char* description; | ||
| 40 | }; | ||
| 41 | |||
| 42 | struct 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 | ||
