ztest: do teardown in main thread

If the test exits from some APIs like ztest_test_pass(),
ztest_test_skip(), or a test crashes out, the teardown
function is never run.

Fixes: #16329

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2019-12-17 22:14:16 -08:00 committed by Andrew Boie
commit 7d29f3b06e

View file

@ -146,9 +146,6 @@ static void run_test_functions(struct unit_test *test)
test->setup();
phase = TEST_PHASE_TEST;
test->test();
phase = TEST_PHASE_TEARDOWN;
test->teardown();
phase = TEST_PHASE_FRAMEWORK;
}
#ifndef KERNEL
@ -312,6 +309,11 @@ static int run_test(struct unit_test *test)
* phase": this will corrupt the kernel ready queue.
*/
k_sem_take(&test_end_signal, K_FOREVER);
phase = TEST_PHASE_TEARDOWN;
test->teardown();
phase = TEST_PHASE_FRAMEWORK;
if (test_result == -1) {
ret = TC_FAIL;
}