blob: a4f0fa24c5891f062c7957157bd3f191877cd636 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
#include <check.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* lower address-space is protected from user-allocation, so this is invalid */
#define TEST_INVALID_PTR ((void*)0x10)
#define TEST_DEFINE_CASE(_name) \
static TCase *test_create_case_##_name(void) \
{ \
TCase *tc; \
\
tc = tcase_create(#_name); \
#define TEST(_name) tcase_add_test(tc, _name);
#define TEST_END_CASE \
return tc; \
} \
#define TEST_END NULL
#define TEST_CASE(_name) test_create_case_##_name
static inline Suite *test_create_suite(const char *name, ...)
{
Suite *s;
va_list list;
TCase *(*fn)(void);
s = suite_create(name);
va_start(list, name);
while ((fn = va_arg(list, TCase *(*)(void))))
suite_add_tcase(s, fn());
va_end(list);
return s;
}
#define TEST_SUITE(_name, ...) test_create_suite((#_name), ##__VA_ARGS__)
static inline int test_run_suite(Suite *s)
{
int ret;
SRunner *sr;
sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
ret = srunner_ntests_failed(sr);
srunner_free(sr);
return ret;
}
#define TEST_DEFINE(_suite) \
int main(int argc, char **argv) \
{ \
return test_run_suite(_suite); \
}
#endif /* TEST_COMMON_H */
|