From fef6e46f011aa8829e39b79c1861dfad3a19020d Mon Sep 17 00:00:00 2001 From: Al Semjonovs Date: Fri, 15 Apr 2022 11:59:07 -0600 Subject: [PATCH] ztest: Add Z_TEST_SKIP_IFDEF macro Defined Z_TEST_SKIP_IFDEF macro to skip tests when specified config is enabled. Signed-off-by: Al Semjonovs --- doc/develop/test/ztest.rst | 13 +++++++++++++ subsys/testsuite/ztest/include/ztest_test_new.h | 10 ++++++++++ tests/ztest/base/Kconfig | 9 +++++++++ tests/ztest/base/src/main.c | 6 ++++++ 4 files changed, 38 insertions(+) create mode 100644 tests/ztest/base/Kconfig diff --git a/doc/develop/test/ztest.rst b/doc/develop/test/ztest.rst index c0b3c412a09..1db7b041fe0 100644 --- a/doc/develop/test/ztest.rst +++ b/doc/develop/test/ztest.rst @@ -138,6 +138,19 @@ it needs to report either a pass or fail. For example:: ztest_run_test_suite(common); } +Use the following macro at the start of your test to skip it with a KConfig +option. + +#define Z_TEST_SKIP_IFDEF(config) + +For example:: + + void test_test1(void) + { + Z_TEST_SKIP_IFDEF(CONFIG_BUGxxxxx); + zassert_equal(1, 0, NULL); + } + Quick start - Unit testing ************************** diff --git a/subsys/testsuite/ztest/include/ztest_test_new.h b/subsys/testsuite/ztest/include/ztest_test_new.h index 02b7da5aafc..c000f75a9fd 100644 --- a/subsys/testsuite/ztest/include/ztest_test_new.h +++ b/subsys/testsuite/ztest/include/ztest_test_new.h @@ -210,6 +210,16 @@ static inline void unit_test_noop(void) #define Z_ZTEST(suite, fn, t_options) Z_TEST(suite, fn, t_options, 0) #define Z_ZTEST_F(suite, fn, t_options) Z_TEST(suite, fn, t_options, 1) +/** + * @brief Skips the test if config is enabled + * + * Use this macro at the start of your test case, to skip it when + * config is enabled. Useful when your test is still under development. + * + * @param config The Kconfig option used to skip the test. + */ +#define Z_TEST_SKIP_IFDEF(config) COND_CODE_1(config, (ztest_test_skip()), ()) + /** * @brief Create and register a new unit test. * diff --git a/tests/ztest/base/Kconfig b/tests/ztest/base/Kconfig new file mode 100644 index 00000000000..f8f5f9d338c --- /dev/null +++ b/tests/ztest/base/Kconfig @@ -0,0 +1,9 @@ +# Copyright 2022 Google LLC +# +# SPDX-License-Identifier: Apache-2.0 + +config BUGxxxxx + bool + default y + +source "Kconfig.zephyr" diff --git a/tests/ztest/base/src/main.c b/tests/ztest/base/src/main.c index 07fc9eb4747..70242e04b8d 100644 --- a/tests/ztest/base/src/main.c +++ b/tests/ztest/base/src/main.c @@ -35,6 +35,12 @@ ZTEST(framework_tests, test_assert_mem_equal) zassert_mem_equal(actual, expected, sizeof(expected), NULL); } +ZTEST(framework_tests, test_skip_config) +{ + Z_TEST_SKIP_IFDEF(CONFIG_BUGxxxxx); + zassert_true(false, NULL); +} + /*************************************************************************************************** * Sample fixture tests **************************************************************************************************/