#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 #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); et_test_status test_exi_readwrite(struct et_test_plan *plan, void *data, size_t data_sz, et_test_error base); /* 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), \ }, \ .test_init_f = _init_f, \ .test_cleanup_f = _cleanup_f, \ .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)