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
|
#ifndef ET__ALLOW_TEST_IMPL_INC
#error "Do not include this file directly! Include test.h instead."
#endif
#undef ET__ALLOW_TEST_IMPL_INC
/* This file will be included in .c files which implement tests. */
#ifdef _CLANGD
#include <gccore.h>
#include "test.h"
/* include stuff this file uses here to make clangd happy (will not be visible to test.h) */
#endif
struct et_test_state_private_base {
struct et_test_plan *plan;
};
/* function prototypes for test-internal stuff */
int test_next(struct et_test_plan *plan, struct et_next_state *next_state);
int test_state_init(const struct et_state *state, void *data, et_state_init_data init_data);
void test_state_cleanup(const struct et_state *state, void *data);
void test_plan_entry_set_error(struct et_test_plan_entry *entry, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
void test_plan_entry_set_error_static(struct et_test_plan_entry *entry, const char *str);
/* Expands to a struct initializer for a struct et_test */
#define TEST_STRUCT_INIT_FULL(_namestr, _flags, _init_f, _tick_f, _cleanup_f, _private_type) \
{ \
.parent = { \
.init_f = test_state_init, \
.tick_f = _tick_f, \
.cleanup_f = test_state_cleanup, \
.private_size = sizeof(_private_type), \
}, \
.name = _namestr, \
.flags = _flags \
}
#define TEST__STRUCT_NAME(_name) PASTE(TEST_SYM(_name), __struct)
#define TEST__STRUCT_DEF(_name, _ini) static const struct et_test TEST__STRUCT_NAME(_name) = _ini
#define TEST__STRUCT_SANITY_CHECK(_ty) static_assert(sizeof(_ty) >= sizeof(struct et_test_state_private_base), "private data type too small (does it include base?)")
#define TEST__SYM_DEF(_name) const struct et_test *const TEST_SYM(_name) = &TEST__STRUCT_NAME(_name)
#define TEST_DEF(_name, _namestr, _flags, _init_f, _tick_f, _cleanup_f, _private_type) \
TEST__STRUCT_SANITY_CHECK(_private_type); \
TEST__STRUCT_DEF(_name, TEST_STRUCT_INIT_FULL(_namestr, _flags, _init_f, _tick_f, _cleanup_f, _private_type)); \
TEST__SYM_DEF(_name)
#define test_current(_plan) ((_plan)->tests + (_plan)->current_test)
|