ztest: add tests for failing on zassume
Add a test to make sure that when a zassume fails, we mark the test as failed and print an "Assumption failed" error for the test Signed-off-by: Yuval Peress <peress@google.com>
This commit is contained in:
parent
a40a2f5c50
commit
dbd63e8008
4 changed files with 30 additions and 0 deletions
|
@ -22,6 +22,9 @@ config ZTEST_FAIL_TEST_PASS_AFTER
|
||||||
config ZTEST_FAIL_TEST_PASS_TEARDOWN
|
config ZTEST_FAIL_TEST_PASS_TEARDOWN
|
||||||
bool "Add a call to ztest_test_pass() in the teardown phase"
|
bool "Add a call to ztest_test_pass() in the teardown phase"
|
||||||
|
|
||||||
|
config ZTEST_FAIL_TEST_UNEXPECTED_ASSUME
|
||||||
|
bool "Add a test which fails a zassume() call"
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config TEST_ERROR_STRING
|
config TEST_ERROR_STRING
|
||||||
|
@ -32,5 +35,6 @@ config TEST_ERROR_STRING
|
||||||
default "ERROR: cannot skip in test 'teardown()', bailing" if ZTEST_FAIL_TEST_ASSUME_TEARDOWN
|
default "ERROR: cannot skip in test 'teardown()', bailing" if ZTEST_FAIL_TEST_ASSUME_TEARDOWN
|
||||||
default "ERROR: cannot pass in test 'after()', bailing" if ZTEST_FAIL_TEST_PASS_AFTER
|
default "ERROR: cannot pass in test 'after()', bailing" if ZTEST_FAIL_TEST_PASS_AFTER
|
||||||
default "ERROR: cannot pass in test 'teardown()', bailing" if ZTEST_FAIL_TEST_PASS_TEARDOWN
|
default "ERROR: cannot pass in test 'teardown()', bailing" if ZTEST_FAIL_TEST_PASS_TEARDOWN
|
||||||
|
default "Assumption failed at " if ZTEST_FAIL_TEST_UNEXPECTED_ASSUME
|
||||||
|
|
||||||
source "Kconfig.zephyr"
|
source "Kconfig.zephyr"
|
||||||
|
|
|
@ -19,6 +19,8 @@ elseif(CONFIG_ZTEST_FAIL_TEST_PASS_AFTER)
|
||||||
list(APPEND SOURCES src/pass_after.cpp)
|
list(APPEND SOURCES src/pass_after.cpp)
|
||||||
elseif(CONFIG_ZTEST_FAIL_TEST_PASS_TEARDOWN)
|
elseif(CONFIG_ZTEST_FAIL_TEST_PASS_TEARDOWN)
|
||||||
list(APPEND SOURCES src/pass_teardown.cpp)
|
list(APPEND SOURCES src/pass_teardown.cpp)
|
||||||
|
elseif(CONFIG_ZTEST_FAIL_TEST_UNEXPECTED_ASSUME)
|
||||||
|
list(APPEND SOURCES src/unexpected_assume.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(BOARD STREQUAL unit_testing)
|
if(BOARD STREQUAL unit_testing)
|
||||||
|
|
16
tests/ztest/fail/core/src/unexpected_assume.cpp
Normal file
16
tests/ztest/fail/core/src/unexpected_assume.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/* Copyright (c) 2022 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
|
#include "fail_test.hpp"
|
||||||
|
|
||||||
|
void fail_test_after_impl(void) {}
|
||||||
|
|
||||||
|
void fail_test_teardown_impl(void) {}
|
||||||
|
|
||||||
|
ZTEST(fail, test_unexpected_assume)
|
||||||
|
{
|
||||||
|
zassume_true(false, NULL);
|
||||||
|
}
|
|
@ -50,3 +50,11 @@ tests:
|
||||||
platform_allow: native_posix
|
platform_allow: native_posix
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_ZTEST_FAIL_TEST_PASS_TEARDOWN=y
|
- CONFIG_ZTEST_FAIL_TEST_PASS_TEARDOWN=y
|
||||||
|
testing.fail.unit.fail_on_bad_assumption:
|
||||||
|
type: unit
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_ZTEST_FAIL_TEST_UNEXPECTED_ASSUME=y
|
||||||
|
testing.fail.zephyr.fail_on_bad_assumption:
|
||||||
|
platform_allow: native_posix
|
||||||
|
extra_configs:
|
||||||
|
- CONFIG_ZTEST_FAIL_TEST_UNEXPECTED_ASSUME=y
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue