From: Tobias Brunner Date: Sat, 1 Mar 2014 07:35:59 +0000 (+0100) Subject: unit-tests: Implement registered functions without __builtin_apply() X-Git-Tag: 5.1.3dr1~5^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b751f6f25a176cd773fbe73f7739f24cb2745d4f;p=thirdparty%2Fstrongswan.git unit-tests: Implement registered functions without __builtin_apply() This makes the tests work with clang, which does not implement said builtin. --- diff --git a/src/libstrongswan/utils/test.h b/src/libstrongswan/utils/test.h index 38887946d9..51362a15b5 100644 --- a/src/libstrongswan/utils/test.h +++ b/src/libstrongswan/utils/test.h @@ -65,32 +65,32 @@ static void testable_function_unregister_##fn() \ /** * 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 name name of the function * @param ret return type of the function * @param ... arguments of the function */ #define IMPORT_FUNCTION_FOR_TESTS(ns, name, ret, ...) \ -static ret TEST_##name(__VA_ARGS__) \ -{ \ - void (*fn)() = NULL; \ - if (testable_functions) \ +static ret (*TEST_##ns##name)(__VA_ARGS__); + +/** + * 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(); \ - __builtin_return(__builtin_apply(fn, args, 16*sizeof(void*))); \ + test_fail_msg(__FILE__, __LINE__, "function " #name " (" #ns ") not found"); \ } \ - test_fail_msg(__FILE__, __LINE__, "function " #name " (" #ns ") not found"); \ - __builtin_return(NULL); \ -} + TEST_##ns##name(__VA_ARGS__); \ +}) #endif /** TEST_H_ @}*/