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 <asemjonovs@google.com>
This commit is contained in:
Al Semjonovs 2022-04-15 11:59:07 -06:00 committed by Anas Nashif
parent 72f81021b2
commit fef6e46f01
4 changed files with 38 additions and 0 deletions

View file

@ -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
**************************

View file

@ -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.
*

9
tests/ztest/base/Kconfig Normal file
View file

@ -0,0 +1,9 @@
# Copyright 2022 Google LLC
#
# SPDX-License-Identifier: Apache-2.0
config BUGxxxxx
bool
default y
source "Kconfig.zephyr"

View file

@ -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
**************************************************************************************************/