-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Describe the bug
If a test function fails (call to ztest_test_fail) or a ztest_test_pass is called from the function no teardown function is called.
To Reproduce
It is really enough to look into the code, but I may provide some tests if really required.
Expected behavior
Teardown function should be called even if ztest_test_fail) or a ztest_test_pass is called from the test function body.
Impact
annoyance
Environment (please complete the following information):
- Unit test on local machine, it means without a Kernel.
Additional context
The problem is that test teardown is called linearly here:
static void run_test_functions(struct unit_test *test)
{
phase = TEST_PHASE_SETUP;
test->setup();
phase = TEST_PHASE_TEST;
test->test();
phase = TEST_PHASE_TEARDOWN;
test->teardown();
phase = TEST_PHASE_FRAMEWORK;
}
While calling ztest_test_fail or ztest_test_fail pass would finally lead to longjump into run_test function from witch run_test_functions is called.
As an effect - the line test->teardown(); would be never reached.
To solve this it should be enough to move the teardown call into run_test function just after out: label.