unit-tests: Invoke all registered thread cleanup handlers on test failure
authorMartin Willi <martin@revosec.ch>
Tue, 14 Apr 2015 06:59:58 +0000 (08:59 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 15 Apr 2015 12:38:43 +0000 (14:38 +0200)
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.

src/libstrongswan/tests/test_runner.c

index b773028..83f4e8f 100644 (file)
@@ -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;
                }