unit-tests: Implement registered functions without __builtin_apply()
This makes the tests work with clang, which does not implement said builtin.
This commit is contained in:
@@ -65,32 +65,32 @@ static void testable_function_unregister_##fn() \
|
|||||||
/**
|
/**
|
||||||
* Import a registered function so that it can be called from tests.
|
* Import a registered function so that it can be called from tests.
|
||||||
*
|
*
|
||||||
* The function name is prefixed with TEST_ to avoid clashes when building
|
|
||||||
* monolithically.
|
|
||||||
*
|
|
||||||
* @note We allocate an arbitrary amount of stack space, hopefully enough for
|
|
||||||
* all arguments.
|
|
||||||
*
|
|
||||||
* @param ns namespace of the function
|
* @param ns namespace of the function
|
||||||
* @param name name of the function
|
* @param name name of the function
|
||||||
* @param ret return type of the function
|
* @param ret return type of the function
|
||||||
* @param ... arguments of the function
|
* @param ... arguments of the function
|
||||||
*/
|
*/
|
||||||
#define IMPORT_FUNCTION_FOR_TESTS(ns, name, ret, ...) \
|
#define IMPORT_FUNCTION_FOR_TESTS(ns, name, ret, ...) \
|
||||||
static ret TEST_##name(__VA_ARGS__) \
|
static ret (*TEST_##ns##name)(__VA_ARGS__);
|
||||||
{ \
|
|
||||||
void (*fn)() = NULL; \
|
/**
|
||||||
if (testable_functions) \
|
* Call a registered function from tests.
|
||||||
|
*
|
||||||
|
* @param ns namespace of the function
|
||||||
|
* @param name name of the function
|
||||||
|
* @param ... arguments for the function
|
||||||
|
*/
|
||||||
|
#define TEST_FUNCTION(ns, name, ...) \
|
||||||
|
({ \
|
||||||
|
if (!TEST_##ns##name && testable_functions) \
|
||||||
{ \
|
{ \
|
||||||
fn = testable_functions->get(testable_functions, #ns "/" #name); \
|
TEST_##ns##name = testable_functions->get(testable_functions, #ns "/" #name); \
|
||||||
} \
|
} \
|
||||||
if (fn) \
|
if (!TEST_##ns##name) \
|
||||||
{ \
|
{ \
|
||||||
void *args = __builtin_apply_args(); \
|
test_fail_msg(__FILE__, __LINE__, "function " #name " (" #ns ") not found"); \
|
||||||
__builtin_return(__builtin_apply(fn, args, 16*sizeof(void*))); \
|
|
||||||
} \
|
} \
|
||||||
test_fail_msg(__FILE__, __LINE__, "function " #name " (" #ns ") not found"); \
|
TEST_##ns##name(__VA_ARGS__); \
|
||||||
__builtin_return(NULL); \
|
})
|
||||||
}
|
|
||||||
|
|
||||||
#endif /** TEST_H_ @}*/
|
#endif /** TEST_H_ @}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user