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
+5 -28
View File
@@ -35,35 +35,12 @@
#define TTY(color) tty_escape_get(2, TTY_FG_##color)
/**
* Initialize the lookup table for testable functions (defined in
* libstrongswan). We don't use the constructor attribute as the order can't
* really be defined (clang does not support it and gcc does not adhere to it in
* the monolithic build). The function here is a weak symbol in libstrongswan.
* A global symbol indicating libtest linkage
*/
void testable_functions_create()
{
if (!testable_functions)
{
/* as this is executed before chunk_hash() seed initialization used
* by hashtables, we enforce seeding it here. */
chunk_hash_seed();
testable_functions = hashtable_create(hashtable_hash_str,
hashtable_equals_str, 8);
}
}
/**
* Destroy the lookup table for testable functions
*/
static void testable_functions_destroy() __attribute__ ((destructor));
static void testable_functions_destroy()
{
DESTROY_IF(testable_functions);
/* if leak detective is enabled plugins are not actually unloaded, which
* means their destructor is called AFTER this one when the process
* terminates, make sure this does not crash */
testable_functions = NULL;
}
#ifdef WIN32
__declspec(dllexport)
#endif
bool test_runner_available = TRUE;
/**
* Destroy a single test suite and associated data