From: Martin Willi Date: Tue, 14 Apr 2015 06:59:58 +0000 (+0200) Subject: unit-tests: Invoke all registered thread cleanup handlers on test failure X-Git-Tag: 5.3.1dr1~16^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30003bc51ad230663e329aea259784bbbaf3b865;p=thirdparty%2Fstrongswan.git unit-tests: Invoke all registered thread cleanup handlers on test failure If a test fails in a timeout or a test failure, longjmp() is used to restore the thread context and handle test failure. However, there might be unreleased resources, namely locks, which prevent the library to clean up properly after finishing the test. By using thread cleanup handlers, we can release any test subject internal or test specific external resources on test failure. We do so by calling all registered cleanup handlers. --- diff --git a/src/libstrongswan/tests/test_runner.c b/src/libstrongswan/tests/test_runner.c index b77302820b..83f4e8faff 100644 --- a/src/libstrongswan/tests/test_runner.c +++ b/src/libstrongswan/tests/test_runner.c @@ -185,6 +185,7 @@ static bool run_test(test_function_t *tfun, int i) tfun->cb(i); return TRUE; } + thread_cleanup_popall(); return FALSE; } @@ -219,6 +220,7 @@ static bool call_fixture(test_case_t *tcase, bool up) } else { + thread_cleanup_popall(); failure = TRUE; break; } @@ -336,6 +338,7 @@ static bool post_test(test_runner_init_t init, bool check_leaks, } else { + thread_cleanup_popall(); library_deinit(); return FALSE; }