Revert "ztest: Fix userspace ztests in new API"
This reverts commit 900b6723e7
.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
c882843af2
commit
462b13e16e
|
@ -62,7 +62,7 @@ target_compile_options(testbinary PRIVATE
|
|||
)
|
||||
|
||||
target_link_options(testbinary PRIVATE
|
||||
-T "${ZEPHYR_BASE}/subsys/testsuite/include/ztest_unittest.ld"
|
||||
-T "${ZEPHYR_BASE}/subsys/testsuite/include/ztest.ld"
|
||||
)
|
||||
|
||||
target_link_libraries(testbinary PRIVATE
|
||||
|
|
|
@ -145,3 +145,11 @@
|
|||
#ifdef CONFIG_USERSPACE
|
||||
_static_kernel_objects_end = .;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ZTEST)
|
||||
ITERABLE_SECTION_RAM(ztest_suite_node, 4)
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ITERABLE_SECTION_RAM(ztest_unit_test, 4)
|
||||
ITERABLE_SECTION_RAM(ztest_test_rule, 4)
|
||||
#endif /* CONFIG_ZTEST_NEW_API */
|
||||
#endif /* CONFIG_ZTEST */
|
||||
|
|
|
@ -8,7 +8,3 @@ zephyr_include_directories_ifdef(CONFIG_TEST
|
|||
add_subdirectory_ifdef(CONFIG_COVERAGE_GCOV coverage)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_TEST_BUSY_SIM busy_sim/busy_sim.c)
|
||||
|
||||
if(NOT BOARD STREQUAL unit_testing)
|
||||
zephyr_linker_sources(RODATA include/ztest.ld)
|
||||
endif()
|
||||
|
|
|
@ -4,22 +4,25 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_ARM_MMU)
|
||||
#define _ZTEST_ALIGN CONFIG_MMU_PAGE_SIZE
|
||||
#elif defined(CONFIG_ARM_MPU)
|
||||
#define _ZTEST_ALIGN CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
|
||||
#elif defined(CONFIG_PMP_POWER_OF_TWO_ALIGNMENT)
|
||||
#define _ZTEST_ALIGN 16
|
||||
#else
|
||||
#define _ZTEST_ALIGN 4
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ZTEST)
|
||||
Z_LINK_ITERABLE_ALIGNED(ztest_suite_node, _ZTEST_ALIGN);
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
Z_LINK_ITERABLE_ALIGNED(ztest_unit_test, _ZTEST_ALIGN);
|
||||
Z_LINK_ITERABLE_ALIGNED(ztest_test_rule, _ZTEST_ALIGN);
|
||||
#endif /* CONFIG_ZTEST_NEW_API */
|
||||
|
||||
#endif /* CONFIG_ZTEST */
|
||||
SECTIONS
|
||||
{
|
||||
.data.ztest_suite_node_area : ALIGN(4)
|
||||
{
|
||||
_ztest_suite_node_list_start = .;
|
||||
KEEP(*(SORT_BY_NAME(._ztest_suite_node.static.*)))
|
||||
_ztest_suite_node_list_end = .;
|
||||
}
|
||||
.data.ztest_unit_test_area : ALIGN(4)
|
||||
{
|
||||
_ztest_unit_test_list_start = .;
|
||||
KEEP(*(SORT_BY_NAME(._ztest_unit_test.static.*)))
|
||||
_ztest_unit_test_list_end = .;
|
||||
}
|
||||
.data.ztest_test_rule_area : ALIGN(4)
|
||||
{
|
||||
_ztest_test_rule_list_start = .;
|
||||
KEEP(*(SORT_BY_NAME(._ztest_test_rule.static.*)))
|
||||
_ztest_test_rule_list_end = .;
|
||||
}
|
||||
}
|
||||
INSERT AFTER .data;
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Copyright 2022 Google LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.data.ztest_suite_node_area : ALIGN(4)
|
||||
{
|
||||
_ztest_suite_node_list_start = .;
|
||||
KEEP(*(SORT_BY_NAME(._ztest_suite_node.static.*)))
|
||||
_ztest_suite_node_list_end = .;
|
||||
}
|
||||
.data.ztest_unit_test_area : ALIGN(4)
|
||||
{
|
||||
_ztest_unit_test_list_start = .;
|
||||
KEEP(*(SORT_BY_NAME(._ztest_unit_test.static.*)))
|
||||
_ztest_unit_test_list_end = .;
|
||||
}
|
||||
.data.ztest_test_rule_area : ALIGN(4)
|
||||
{
|
||||
_ztest_test_rule_list_start = .;
|
||||
KEEP(*(SORT_BY_NAME(._ztest_test_rule.static.*)))
|
||||
_ztest_test_rule_list_end = .;
|
||||
}
|
||||
}
|
||||
INSERT AFTER .data;
|
|
@ -17,12 +17,6 @@
|
|||
#include <init.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined(CONFIG_USERSPACE) || defined(CONFIG_TEST_USERSPACE)
|
||||
#define __USERSPACE_FLAGS (K_USER)
|
||||
#else
|
||||
#define __USERSPACE_FLAGS (0)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -55,31 +49,31 @@ struct ztest_suite_stats {
|
|||
*/
|
||||
struct ztest_suite_node {
|
||||
/** The name of the test suite. */
|
||||
const char * const name;
|
||||
const char *name;
|
||||
/**
|
||||
* Setup function to run before running this suite
|
||||
*
|
||||
* @return Pointer to the data structure that will be used throughout this test suite
|
||||
*/
|
||||
void *(*const setup)(void);
|
||||
void *(*setup)(void);
|
||||
/**
|
||||
* Function to run before each test in this suite
|
||||
*
|
||||
* @param data The test suite's data returned from setup()
|
||||
*/
|
||||
void (*const before)(void *data);
|
||||
void (*before)(void *data);
|
||||
/**
|
||||
* Function to run after each test in this suite
|
||||
*
|
||||
* @param data The test suite's data returned from setup()
|
||||
*/
|
||||
void (*const after)(void *data);
|
||||
void (*after)(void *data);
|
||||
/**
|
||||
* Teardown function to run after running this suite
|
||||
*
|
||||
* @param data The test suite's data returned from setup()
|
||||
*/
|
||||
void (*const teardown)(void *data);
|
||||
void (*teardown)(void *data);
|
||||
/**
|
||||
* An optional predicate function to determine if the test should run. If NULL, then the
|
||||
* test will only run once on the first attempt.
|
||||
|
@ -87,9 +81,9 @@ struct ztest_suite_node {
|
|||
* @param state The current state of the test application.
|
||||
* @return True if the suite should be run; false to skip.
|
||||
*/
|
||||
bool (*const predicate)(const void *state);
|
||||
bool (*predicate)(const void *state);
|
||||
/** Stats */
|
||||
struct ztest_suite_stats * const stats;
|
||||
struct ztest_suite_stats stats;
|
||||
};
|
||||
|
||||
extern struct ztest_suite_node _ztest_suite_node_list_start[];
|
||||
|
@ -109,18 +103,17 @@ extern struct ztest_suite_node _ztest_suite_node_list_end[];
|
|||
* @param after_fn The function to call after each unit test in this suite
|
||||
* @param teardown_fn The function to call after running all the tests in this suite
|
||||
*/
|
||||
#define ZTEST_SUITE(SUITE_NAME, PREDICATE, setup_fn, before_fn, after_fn, teardown_fn) \
|
||||
static struct ztest_suite_stats UTIL_CAT(z_ztest_test_node_stats_, SUITE_NAME); \
|
||||
static const STRUCT_SECTION_ITERABLE(ztest_suite_node, \
|
||||
UTIL_CAT(z_ztest_test_node_, SUITE_NAME)) = { \
|
||||
.name = STRINGIFY(SUITE_NAME), \
|
||||
.setup = (setup_fn), \
|
||||
.before = (before_fn), \
|
||||
.after = (after_fn), \
|
||||
.teardown = (teardown_fn), \
|
||||
.predicate = PREDICATE, \
|
||||
.stats = &UTIL_CAT(z_ztest_test_node_stats_, SUITE_NAME), \
|
||||
#define ZTEST_SUITE(SUITE_NAME, PREDICATE, setup_fn, before_fn, after_fn, teardown_fn) \
|
||||
static STRUCT_SECTION_ITERABLE(ztest_suite_node, \
|
||||
UTIL_CAT(z_ztest_test_node_, SUITE_NAME)) = { \
|
||||
.name = STRINGIFY(SUITE_NAME), \
|
||||
.setup = (setup_fn), \
|
||||
.before = (before_fn), \
|
||||
.after = (after_fn), \
|
||||
.teardown = (teardown_fn), \
|
||||
.predicate = PREDICATE, \
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the registered unit tests which return true from their pragma function.
|
||||
*
|
||||
|
@ -247,7 +240,7 @@ static inline void unit_test_noop(void)
|
|||
* @param suite The name of the test suite to attach this test
|
||||
* @param fn The test function to call.
|
||||
*/
|
||||
#define ZTEST_USER(suite, fn) Z_ZTEST(suite, fn, __USERSPACE_FLAGS)
|
||||
#define ZTEST_USER(suite, fn) Z_ZTEST(suite, fn, COND_CODE_1(CONFIG_USERSPACE, (K_USER), (0)))
|
||||
|
||||
/**
|
||||
* @brief Define a test function
|
||||
|
@ -269,7 +262,7 @@ static inline void unit_test_noop(void)
|
|||
* @param suite The name of the test suite to attach this test
|
||||
* @param fn The test function to call.
|
||||
*/
|
||||
#define ZTEST_USER_F(suite, fn) Z_ZTEST_F(suite, fn, __USERSPACE_FLAGS)
|
||||
#define ZTEST_USER_F(suite, fn) Z_ZTEST_F(suite, fn, COND_CODE_1(CONFIG_USERSPACE, (K_USER), (0)))
|
||||
|
||||
/**
|
||||
* @brief Test rule callback function signature
|
||||
|
|
|
@ -559,7 +559,7 @@ int ztest_run_test_suites(const void *state)
|
|||
int count = 0;
|
||||
|
||||
for (ptr = _ztest_suite_node_list_start; ptr < _ztest_suite_node_list_end; ++ptr) {
|
||||
struct ztest_suite_stats *stats = ptr->stats;
|
||||
struct ztest_suite_stats *stats = &ptr->stats;
|
||||
bool should_run = true;
|
||||
|
||||
if (ptr->predicate != NULL) {
|
||||
|
@ -590,7 +590,7 @@ void ztest_verify_all_test_suites_ran(void)
|
|||
struct ztest_unit_test *test;
|
||||
|
||||
for (suite = _ztest_suite_node_list_start; suite < _ztest_suite_node_list_end; ++suite) {
|
||||
if (suite->stats->run_count < 1) {
|
||||
if (suite->stats.run_count < 1) {
|
||||
PRINT("ERROR: Test suite '%s' did not run.\n", suite->name);
|
||||
all_tests_run = false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue