Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test runner constructors order and _FORTIFY_SOURCE failure #729

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 62 additions & 58 deletions test/lib/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,28 +218,29 @@ static inline void log_sqlite_error(void *arg, int e, const char *msg)

/* Declare the MunitSuite[] and the MunitTest[] arrays that compose the test
* suite identified by S. */
#define TEST_SUITE__DECLARE(S) \
static MunitSuite _##S##_suites[TEST__CAP]; \
static MunitTest _##S##_tests[TEST__CAP]; \
static MunitTestSetup _##S##_setup = NULL; \
static MunitTestTearDown _##S##_tear_down = NULL; \
static int _##S##_suites_n = 0; \
static int _##S##_tests_n = 0; \
__attribute__((constructor)) static void _##S##_init(void) \
{ \
memset(_##S##_suites, 0, sizeof(_##S##_suites)); \
memset(_##S##_tests, 0, sizeof(_##S##_tests)); \
(void)_##S##_suites_n; \
(void)_##S##_tests_n; \
(void)_##S##_setup; \
(void)_##S##_tear_down; \
#define TEST_SUITE__DECLARE(S) \
static MunitSuite _##S##_suites[TEST__CAP]; \
static MunitTest _##S##_tests[TEST__CAP]; \
static MunitTestSetup _##S##_setup = NULL; \
static MunitTestTearDown _##S##_tear_down = NULL; \
static int _##S##_suites_n = 0; \
static int _##S##_tests_n = 0; \
__attribute__((constructor(101))) static void _##S##_init(void) \
{ \
memset(_##S##_suites, 0, sizeof(_##S##_suites)); \
memset(_##S##_tests, 0, sizeof(_##S##_tests)); \
(void)_##S##_suites_n; \
(void)_##S##_tests_n; \
(void)_##S##_setup; \
(void)_##S##_tear_down; \
}

/* Set the tests and suites attributes of the next available slot of the
* MunitSuite[] array of S1 to the MunitTest[] and MunitSuite[] arrays of S2,
* using the given PREXIX. */
#define TEST_SUITE__ADD_CHILD(S1, PREFIX, S2) \
__attribute__((constructor)) static void _##S1##_##S2##_init(void) \
__attribute__((constructor(102))) static void _##S1##_##S2##_init( \
void) \
{ \
int n = _##S1##_suites_n; \
_##S1##_suites[n].prefix = PREFIX; \
Expand All @@ -252,35 +253,35 @@ static inline void log_sqlite_error(void *arg, int e, const char *msg)

/* Set the tests attribute of the next available slot of the MunitSuite[] array
* of S to the MunitTest[] array of G, using /G as prefix. */
#define TEST_SUITE__ADD_GROUP(S, G) \
__attribute__((constructor)) static void _##S##_##G##_init(void) \
{ \
int n = _##S##_suites_n; \
_##S##_suites[n].prefix = "/" #G; \
_##S##_suites[n].tests = _##S##_##G##_tests; \
_##S##_suites[n].suites = NULL; \
_##S##_suites[n].iterations = 0; \
_##S##_suites[n].options = 0; \
_##S##_suites_n = n + 1; \
#define TEST_SUITE__ADD_GROUP(S, G) \
__attribute__((constructor(102))) static void _##S##_##G##_init(void) \
{ \
int n = _##S##_suites_n; \
_##S##_suites[n].prefix = "/" #G; \
_##S##_suites[n].tests = _##S##_##G##_tests; \
_##S##_suites[n].suites = NULL; \
_##S##_suites[n].iterations = 0; \
_##S##_suites[n].options = 0; \
_##S##_suites_n = n + 1; \
}

/* Choose the appropriate TEST_SETUP__N_ARGS() macro depending on the number of
* arguments passed to TEST_SETUP(). */
#define TEST_SETUP__MACRO_CHOOSER(...) \
TEST__GET_3RD_ARG(__VA_ARGS__, TEST_SETUP__2_ARGS, TEST_SETUP__1_ARGS)

#define TEST_SETUP__1_ARGS(S) \
static void *S##__setup(const MunitParameter[], void *); \
__attribute__((constructor)) static void _##S##_setup_init(void) \
{ \
_##S##_setup = S##__setup; \
} \
#define TEST_SETUP__1_ARGS(S) \
static void *S##__setup(const MunitParameter[], void *); \
__attribute__((constructor(102))) static void _##S##_setup_init(void) \
{ \
_##S##_setup = S##__setup; \
} \
static void *S##__setup(const MunitParameter params[], void *user_data)

#define TEST_SETUP__2_ARGS(S, F) \
__attribute__((constructor)) static void _##S##_setup_init(void) \
{ \
_##S##_setup = F; \
#define TEST_SETUP__2_ARGS(S, F) \
__attribute__((constructor(102))) static void _##S##_setup_init(void) \
{ \
_##S##_setup = F; \
}

/* Choose the appropriate TEST_TEAR_DOWN__N_ARGS() macro depending on the number
Expand All @@ -291,14 +292,16 @@ static inline void log_sqlite_error(void *arg, int e, const char *msg)

#define TEST_TEAR_DOWN__1_ARGS(S) \
static void S##__tear_down(void *data); \
__attribute__((constructor)) static void _##S##__tear_down_init(void) \
__attribute__((constructor(102))) static void _##S##__tear_down_init( \
void) \
{ \
_##S##_tear_down = S##__tear_down; \
} \
static void S##__tear_down(void *data)

#define TEST_TEAR_DOWN__2_ARGS(S, F) \
__attribute__((constructor)) static void _##S##_tear_down_init(void) \
__attribute__((constructor(102))) static void _##S##_tear_down_init( \
void) \
{ \
_##S##_tear_down = F; \
}
Expand Down Expand Up @@ -331,20 +334,21 @@ static inline void log_sqlite_error(void *arg, int e, const char *msg)
void *data)

/* Add a test case to the MunitTest[] array of the file module. */
#define TEST_CASE__ADD_TO_MODULE(C, PARAMS) \
__attribute__((constructor)) static void _module_tests_##C##_init( \
void) \
{ \
MunitTest *tests = _module_tests; \
int n = _module_tests_n; \
TEST_CASE__SET_IN_ARRAY(tests, n, "/" #C, test_##C, NULL, \
NULL, PARAMS); \
_module_tests_n = n + 1; \
#define TEST_CASE__ADD_TO_MODULE(C, PARAMS) \
__attribute__(( \
constructor(103))) static void _module_tests_##C##_init(void) \
{ \
MunitTest *tests = _module_tests; \
int n = _module_tests_n; \
TEST_CASE__SET_IN_ARRAY(tests, n, "/" #C, test_##C, NULL, \
NULL, PARAMS); \
_module_tests_n = n + 1; \
}

/* Add a test case to the MunitTest[] array of suite S. */
#define TEST_CASE__ADD_TO_SUITE(S, C, PARAMS) \
__attribute__((constructor)) static void _##S##_tests_##C##_init(void) \
__attribute__((constructor(103))) static void _##S##_tests_##C##_init( \
void) \
{ \
MunitTest *tests = _##S##_tests; \
int n = _##S##_tests_n; \
Expand All @@ -355,16 +359,16 @@ static inline void log_sqlite_error(void *arg, int e, const char *msg)
}

/* Add a test case to MunitTest[] array of group G in suite S. */
#define TEST_CASE__ADD_TO_GROUP(S, G, C, PARAMS) \
__attribute__(( \
constructor)) static void _##S##_##G##_tests_##C##_init(void) \
{ \
MunitTest *tests = _##S##_##G##_tests; \
int n = _##S##_##G##_tests_n; \
TEST_CASE__SET_IN_ARRAY(tests, n, "/" #C, \
test_##S##_##G##_##C, _##S##_setup, \
_##S##_tear_down, PARAMS); \
_##S##_##G##_tests_n = n + 1; \
#define TEST_CASE__ADD_TO_GROUP(S, G, C, PARAMS) \
__attribute__(( \
constructor(103))) static void _##S##_##G##_tests_##C##_init(void) \
{ \
MunitTest *tests = _##S##_##G##_tests; \
int n = _##S##_##G##_tests_n; \
TEST_CASE__SET_IN_ARRAY(tests, n, "/" #C, \
test_##S##_##G##_##C, _##S##_setup, \
_##S##_tear_down, PARAMS); \
_##S##_##G##_tests_n = n + 1; \
}

/* Set the values of the I'th test case slot in the given test array */
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_tuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ TEST_CASE(decoder, type, iso8601, NULL)
(void)data;
(void)params;

strcpy((char *)buf[1], "2018-07-20 09:49:05+00:00");
strcpy((char *)buf + 8, "2018-07-20 09:49:05+00:00");

DECODER_INIT(1);
DECODER_NEXT;
Expand Down