diff --git a/libsel4test/include/sel4test/test.h b/libsel4test/include/sel4test/test.h index 86522e582..62476b4c2 100644 --- a/libsel4test/include/sel4test/test.h +++ b/libsel4test/include/sel4test/test.h @@ -96,10 +96,16 @@ typedef struct test_type { test_result_t (*run_test)(struct testcase *test, uintptr_t e); } ALIGN(32) test_type_t; +#if defined(__has_attribute) && __has_attribute(retain) +#define ATTR_USED_RETAIN __attribute__((used,retain)) +#else +#define ATTR_USED_RETAIN __attribute__((used)) +#endif + /* Declare a test type. * For now, we put the test types in a separate elf section. */ #define DEFINE_TEST_TYPE(_name, _id, _set_up_test_type, _tear_down_test_type, _set_up, _tear_down, _run_test) \ - __attribute__((used)) __attribute__((section("_test_type"))) struct test_type TEST_TYPE_ ##_name = { \ + ATTR_USED_RETAIN __attribute__((section("_test_type"))) struct test_type TEST_TYPE_ ##_name = { \ .name = #_name, \ .id = _id, \ .set_up_test_type = _set_up_test_type, \ @@ -133,6 +139,16 @@ typedef struct testcase ALIGN(sizeof(struct testcase)) testcase_t; * C99 style (name = _name, desc = _desc, func = _func...) to make sure * that it is accepted by C++ compilers. */ +#if defined(__has_attribute) && __has_attribute(retain) +#define DEFINE_TEST_WITH_TYPE(_name, _description, _function, _test_type, _enabled) \ + __attribute__((used,retain)) __attribute__((section("_test_case"))) struct testcase TEST_ ## _name = { \ + #_name, \ + _description, \ + (test_fn)_function, \ + _test_type, \ + _enabled, \ +}; +#else #define DEFINE_TEST_WITH_TYPE(_name, _description, _function, _test_type, _enabled) \ __attribute__((used)) __attribute__((section("_test_case"))) struct testcase TEST_ ## _name = { \ #_name, \ @@ -141,6 +157,7 @@ typedef struct testcase ALIGN(sizeof(struct testcase)) testcase_t; _test_type, \ _enabled, \ }; +#endif #define DEFINE_TEST(_name, _description, _function, _enabled) DEFINE_TEST_WITH_TYPE(_name, _description, _function, BASIC, _enabled)