unit-tests: Support testable functions on Windows, avoid weak GCC symbols

Instead of using weak symbols, we use dlsym() on Windows to find an arbitrary
symbol in libtest to detect its linkage. Instead of creating the associated
hashtable in the test runner, we maintain it in libstrongswan, making it
significantly simpler.
This commit is contained in:
Martin Willi
2014-06-04 15:53:12 +02:00
parent 460adb5d09
commit 0c34c1b3af
3 changed files with 62 additions and 62 deletions
+9 -11
View File
@@ -23,13 +23,6 @@
#include "collections/hashtable.h"
/**
* Collection of testable functions.
*
* @note Is initialized only if libtest is loaded.
*/
extern hashtable_t *testable_functions;
/**
* Register a (possibly static) function so that it can be called from tests.
*
@@ -38,6 +31,14 @@ extern hashtable_t *testable_functions;
*/
void testable_function_register(char *name, void *fn);
/**
* Find a previously registered testable function.
*
* @param name name (namespace/function)
* @return function, NULL if not found
*/
void* testable_function_get(char *name);
/**
* Macro to automatically register/unregister a function that can be called
* from tests.
@@ -82,10 +83,7 @@ static ret (*TEST_##ns##name)(__VA_ARGS__);
*/
#define TEST_FUNCTION(ns, name, ...) \
({ \
if (testable_functions) \
{ \
TEST_##ns##name = testable_functions->get(testable_functions, #ns "/" #name); \
} \
TEST_##ns##name = testable_function_get( #ns "/" #name); \
if (!TEST_##ns##name) \
{ \
test_fail_msg(__FILE__, __LINE__, "function " #name " (" #ns ") not found"); \