diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2014-07-11 07:23:31 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2014-07-11 07:23:31 +0200 |
commit | 81c63b0eed39432878f78727f60a1e7499645199 (patch) | |
tree | 82387d8fecd1c20788fd8bd784a9b0bde091fb6b /src/libstrongswan/tests/test_runner.c | |
parent | c5ebfc7b9c16551fe825dc1d79c3f7e2f096f6c9 (diff) | |
download | vyos-strongswan-81c63b0eed39432878f78727f60a1e7499645199.tar.gz vyos-strongswan-81c63b0eed39432878f78727f60a1e7499645199.zip |
Imported Upstream version 5.2.0
Diffstat (limited to 'src/libstrongswan/tests/test_runner.c')
-rw-r--r-- | src/libstrongswan/tests/test_runner.c | 67 |
1 files changed, 30 insertions, 37 deletions
diff --git a/src/libstrongswan/tests/test_runner.c b/src/libstrongswan/tests/test_runner.c index 5ec4198e7..8f2e9855e 100644 --- a/src/libstrongswan/tests/test_runner.c +++ b/src/libstrongswan/tests/test_runner.c @@ -18,6 +18,7 @@ #include "test_runner.h" #include <library.h> +#include <threading/thread.h> #include <plugins/plugin_feature.h> #include <collections/array.h> #include <utils/test.h> @@ -26,6 +27,7 @@ #include <dirent.h> #include <unistd.h> #include <limits.h> +#include <stdlib.h> /** * Get a tty color escape character for stderr @@ -33,32 +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) - { - 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 @@ -114,13 +96,13 @@ static void filter_suites(array_t *loaded) * Load all available test suites, or optionally only selected ones. */ static array_t *load_suites(test_configuration_t configs[], - test_runner_init_t init) + test_runner_init_t init, char *cfg) { array_t *suites; bool old = FALSE; int i; - library_init(NULL, "test-runner"); + library_init(cfg, "test-runner"); test_setup_handler(); @@ -205,11 +187,17 @@ static bool call_fixture(test_case_t *tcase, bool up) { if (up) { - fixture->setup(); + if (fixture->setup) + { + fixture->setup(); + } } else { - fixture->teardown(); + if (fixture->teardown) + { + fixture->teardown(); + } } } else @@ -226,12 +214,12 @@ static bool call_fixture(test_case_t *tcase, bool up) /** * Test initialization, initializes libstrongswan for the next run */ -static bool pre_test(test_runner_init_t init) +static bool pre_test(test_runner_init_t init, char *cfg) { level_t level = LEVEL_SILENT; char *verbosity; - library_init(NULL, "test-runner"); + library_init(cfg, "test-runner"); /* use non-blocking RNG to generate keys fast */ lib->settings->set_default_str(lib->settings, @@ -371,6 +359,7 @@ static void print_failures(array_t *failures) { failure_t failure; + threads_init(); backtrace_init(); while (array_remove(failures, 0, &failure)) @@ -390,12 +379,13 @@ static void print_failures(array_t *failures) } backtrace_deinit(); + threads_deinit(); } /** * Run a single test case with fixtures */ -static bool run_case(test_case_t *tcase, test_runner_init_t init) +static bool run_case(test_case_t *tcase, test_runner_init_t init, char *cfg) { enumerator_t *enumerator; test_function_t *tfun; @@ -414,7 +404,7 @@ static bool run_case(test_case_t *tcase, test_runner_init_t init) for (i = tfun->start; i < tfun->end; i++) { - if (pre_test(init)) + if (pre_test(init, cfg)) { bool ok = FALSE; int leaks = 0; @@ -483,7 +473,7 @@ static bool run_case(test_case_t *tcase, test_runner_init_t init) /** * Run a single test suite */ -static bool run_suite(test_suite_t *suite, test_runner_init_t init) +static bool run_suite(test_suite_t *suite, test_runner_init_t init, char *cfg) { enumerator_t *enumerator; test_case_t *tcase; @@ -494,7 +484,7 @@ static bool run_suite(test_suite_t *suite, test_runner_init_t init) enumerator = array_create_enumerator(suite->tcases); while (enumerator->enumerate(enumerator, &tcase)) { - if (run_case(tcase, init)) + if (run_case(tcase, init, cfg)) { passed++; } @@ -522,11 +512,14 @@ int test_runner_run(const char *name, test_configuration_t configs[], test_suite_t *suite; enumerator_t *enumerator; int passed = 0, result; + char *cfg; /* redirect all output to stderr (to redirect make's stdout to /dev/null) */ dup2(2, 1); - suites = load_suites(configs, init); + cfg = getenv("TESTS_STRONGSWAN_CONF"); + + suites = load_suites(configs, init, cfg); if (!suites) { return EXIT_FAILURE; @@ -537,7 +530,7 @@ int test_runner_run(const char *name, test_configuration_t configs[], enumerator = array_create_enumerator(suites); while (enumerator->enumerate(enumerator, &suite)) { - if (run_suite(suite, init)) + if (run_suite(suite, init, cfg)) { passed++; } |