Skip to content

Commit ba9b4f3

Browse files
yperesskartben
authored andcommitted
ztest: Fix confusing SKIP log
When CONFIG_ZTEST_FAIL_ON_ASSUME is set, a failed assumption will cause the suite to fail, but the individual test will be marked as SKIPPED. We should fail the test so it's clear what's going on. Fixes zephyrproject-rtos#86611 Signed-off-by: Yuval Peress <[email protected]>
1 parent b5adb44 commit ba9b4f3

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

subsys/testsuite/ztest/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ config ZTEST_VERBOSE_SUMMARY
208208

209209
config ZTEST_FAIL_ON_ASSUME
210210
bool "Fail the test run when an assumption fails"
211-
default y
212211
help
213212
When enabled, the test binary will fail at the end if an assumption failed. This means
214213
that while tests will still be marked as skipped on failed zassume calls, the final test

subsys/testsuite/ztest/src/ztest.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,10 @@ void ztest_skip_failed_assumption(void)
393393
{
394394
if (IS_ENABLED(CONFIG_ZTEST_FAIL_ON_ASSUME)) {
395395
current_test_failed_assumption = true;
396+
ztest_test_fail();
397+
} else {
398+
ztest_test_skip();
396399
}
397-
ztest_test_skip();
398400
}
399401

400402
#ifndef KERNEL

tests/ztest/fail/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ string(REGEX MATCHALL "(^|;)CONFIG_ZTEST_FAIL_TEST_[A-Za-z0-9_]+" fail_test_conf
3030
list(FILTER fail_test_config EXCLUDE REGEX "^$")
3131
list(TRANSFORM fail_test_config PREPEND "-D")
3232
list(TRANSFORM fail_test_config APPEND "=y")
33-
string(REPLACE ";" " " fail_test_config "${fail_test_config}")
33+
if(CONFIG_ZTEST_FAIL_ON_ASSUME)
34+
list(APPEND fail_test_config "-DCONFIG_ZTEST_FAIL_ON_ASSUME=y")
35+
endif()
3436

3537
# Add the 'core' external project which will mirror the configs of this project.
3638
ExternalProject_Add(core

tests/ztest/fail/Kconfig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ config TEST_ERROR_STRING
3131
string
3232
default "ERROR: cannot fail in test phase 'after()', bailing" if ZTEST_FAIL_TEST_ASSERT_AFTER
3333
default "ERROR: cannot fail in test phase 'teardown()', bailing" if ZTEST_FAIL_TEST_ASSERT_TEARDOWN
34-
default "ERROR: cannot skip in test phase 'after()', bailing" if ZTEST_FAIL_TEST_ASSUME_AFTER
35-
default "ERROR: cannot skip in test phase 'teardown()', bailing" if ZTEST_FAIL_TEST_ASSUME_TEARDOWN
34+
default "ERROR: cannot skip in test phase 'after()', bailing" if ZTEST_FAIL_TEST_ASSUME_AFTER && !ZTEST_FAIL_ON_ASSUME
35+
default "ERROR: cannot skip in test phase 'teardown()', bailing" if ZTEST_FAIL_TEST_ASSUME_TEARDOWN && !ZTEST_FAIL_ON_ASSUME
36+
default "ERROR: cannot fail in test phase 'after()', bailing" if ZTEST_FAIL_TEST_ASSUME_AFTER && ZTEST_FAIL_ON_ASSUME
37+
default "ERROR: cannot fail in test phase 'teardown()', bailing" if ZTEST_FAIL_TEST_ASSUME_TEARDOWN && ZTEST_FAIL_ON_ASSUME
3638
default "ERROR: cannot pass in test phase 'after()', bailing" if ZTEST_FAIL_TEST_PASS_AFTER
3739
default "ERROR: cannot pass in test phase 'teardown()', bailing" if ZTEST_FAIL_TEST_PASS_TEARDOWN
3840
default "Assumption failed at " if ZTEST_FAIL_TEST_UNEXPECTED_ASSUME

tests/ztest/fail/core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ elseif(CONFIG_ZTEST_FAIL_TEST_UNEXPECTED_ASSUME)
2323
list(APPEND test_sources src/unexpected_assume.cpp)
2424
endif()
2525

26+
if(CONFIG_ZTEST_FAIL_ON_ASSUME)
27+
add_definitions(-DCONFIG_ZTEST_FAIL_ON_ASSUME=1)
28+
endif()
29+
2630
if(BOARD STREQUAL "unit_testing" OR BOARD STREQUAL "unit_testing/unit_testing")
2731
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
2832
project(base)

tests/ztest/fail/testcase.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,22 @@ tests:
4242
testing.fail.zephyr.assert_teardown:
4343
extra_configs:
4444
- CONFIG_ZTEST_FAIL_TEST_ASSERT_TEARDOWN=y
45-
testing.fail.zephyr.assume_after:
45+
testing.fail.zephyr.assume_after.fail:
4646
extra_configs:
4747
- CONFIG_ZTEST_FAIL_TEST_ASSUME_AFTER=y
48-
testing.fail.zephyr.assume_teardown:
48+
- CONFIG_ZTEST_FAIL_ON_ASSUME=y
49+
testing.fail.zephyr.assume_teardown.fail:
4950
extra_configs:
5051
- CONFIG_ZTEST_FAIL_TEST_ASSUME_TEARDOWN=y
52+
- CONFIG_ZTEST_FAIL_ON_ASSUME=y
53+
testing.fail.zephyr.assume_after.skip:
54+
extra_configs:
55+
- CONFIG_ZTEST_FAIL_TEST_ASSUME_AFTER=y
56+
- CONFIG_ZTEST_FAIL_ON_ASSUME=n
57+
testing.fail.zephyr.assume_teardown.skip:
58+
extra_configs:
59+
- CONFIG_ZTEST_FAIL_TEST_ASSUME_TEARDOWN=y
60+
- CONFIG_ZTEST_FAIL_ON_ASSUME=n
5161
testing.fail.zephyr.pass_after:
5262
extra_configs:
5363
- CONFIG_ZTEST_FAIL_TEST_PASS_AFTER=y
@@ -58,6 +68,8 @@ tests:
5868
type: unit
5969
extra_configs:
6070
- CONFIG_ZTEST_FAIL_TEST_UNEXPECTED_ASSUME=y
71+
- CONFIG_ZTEST_FAIL_ON_ASSUME=y
6172
testing.fail.zephyr.fail_on_bad_assumption:
6273
extra_configs:
6374
- CONFIG_ZTEST_FAIL_TEST_UNEXPECTED_ASSUME=y
75+
- CONFIG_ZTEST_FAIL_ON_ASSUME=y

0 commit comments

Comments
 (0)