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.
This commit is contained in:
Martin Willi 2015-04-14 08:59:58 +02:00
parent d36b30803e
commit 30003bc51a
1 changed files with 3 additions and 0 deletions

View 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;
}