Skip to content

Commit 462b13e

Browse files
committed
Revert "ztest: Fix userspace ztests in new API"
This reverts commit 900b672. Signed-off-by: Anas Nashif <[email protected]>
1 parent c882843 commit 462b13e

File tree

7 files changed

+52
-80
lines changed

7 files changed

+52
-80
lines changed

cmake/modules/unittest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ target_compile_options(testbinary PRIVATE
6262
)
6363

6464
target_link_options(testbinary PRIVATE
65-
-T "${ZEPHYR_BASE}/subsys/testsuite/include/ztest_unittest.ld"
65+
-T "${ZEPHYR_BASE}/subsys/testsuite/include/ztest.ld"
6666
)
6767

6868
target_link_libraries(testbinary PRIVATE

include/zephyr/linker/common-ram.ld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,11 @@
145145
#ifdef CONFIG_USERSPACE
146146
_static_kernel_objects_end = .;
147147
#endif
148+
149+
#if defined(CONFIG_ZTEST)
150+
ITERABLE_SECTION_RAM(ztest_suite_node, 4)
151+
#if defined(CONFIG_ZTEST_NEW_API)
152+
ITERABLE_SECTION_RAM(ztest_unit_test, 4)
153+
ITERABLE_SECTION_RAM(ztest_test_rule, 4)
154+
#endif /* CONFIG_ZTEST_NEW_API */
155+
#endif /* CONFIG_ZTEST */

subsys/testsuite/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,3 @@ zephyr_include_directories_ifdef(CONFIG_TEST
88
add_subdirectory_ifdef(CONFIG_COVERAGE_GCOV coverage)
99

1010
zephyr_library_sources_ifdef(CONFIG_TEST_BUSY_SIM busy_sim/busy_sim.c)
11-
12-
if(NOT BOARD STREQUAL unit_testing)
13-
zephyr_linker_sources(RODATA include/ztest.ld)
14-
endif()

subsys/testsuite/include/ztest.ld

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#if defined(CONFIG_ARM_MMU)
8-
#define _ZTEST_ALIGN CONFIG_MMU_PAGE_SIZE
9-
#elif defined(CONFIG_ARM_MPU)
10-
#define _ZTEST_ALIGN CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
11-
#elif defined(CONFIG_PMP_POWER_OF_TWO_ALIGNMENT)
12-
#define _ZTEST_ALIGN 16
13-
#else
14-
#define _ZTEST_ALIGN 4
15-
#endif
16-
17-
#if defined(CONFIG_ZTEST)
18-
Z_LINK_ITERABLE_ALIGNED(ztest_suite_node, _ZTEST_ALIGN);
19-
20-
#if defined(CONFIG_ZTEST_NEW_API)
21-
Z_LINK_ITERABLE_ALIGNED(ztest_unit_test, _ZTEST_ALIGN);
22-
Z_LINK_ITERABLE_ALIGNED(ztest_test_rule, _ZTEST_ALIGN);
23-
#endif /* CONFIG_ZTEST_NEW_API */
24-
25-
#endif /* CONFIG_ZTEST */
7+
SECTIONS
8+
{
9+
.data.ztest_suite_node_area : ALIGN(4)
10+
{
11+
_ztest_suite_node_list_start = .;
12+
KEEP(*(SORT_BY_NAME(._ztest_suite_node.static.*)))
13+
_ztest_suite_node_list_end = .;
14+
}
15+
.data.ztest_unit_test_area : ALIGN(4)
16+
{
17+
_ztest_unit_test_list_start = .;
18+
KEEP(*(SORT_BY_NAME(._ztest_unit_test.static.*)))
19+
_ztest_unit_test_list_end = .;
20+
}
21+
.data.ztest_test_rule_area : ALIGN(4)
22+
{
23+
_ztest_test_rule_list_start = .;
24+
KEEP(*(SORT_BY_NAME(._ztest_test_rule.static.*)))
25+
_ztest_test_rule_list_end = .;
26+
}
27+
}
28+
INSERT AFTER .data;

subsys/testsuite/include/ztest_unittest.ld

Lines changed: 0 additions & 28 deletions
This file was deleted.

subsys/testsuite/ztest/include/ztest_test_new.h

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
#include <init.h>
1818
#include <stdbool.h>
1919

20-
#if defined(CONFIG_USERSPACE) || defined(CONFIG_TEST_USERSPACE)
21-
#define __USERSPACE_FLAGS (K_USER)
22-
#else
23-
#define __USERSPACE_FLAGS (0)
24-
#endif
25-
2620
#ifdef __cplusplus
2721
extern "C" {
2822
#endif
@@ -55,41 +49,41 @@ struct ztest_suite_stats {
5549
*/
5650
struct ztest_suite_node {
5751
/** The name of the test suite. */
58-
const char * const name;
52+
const char *name;
5953
/**
6054
* Setup function to run before running this suite
6155
*
6256
* @return Pointer to the data structure that will be used throughout this test suite
6357
*/
64-
void *(*const setup)(void);
58+
void *(*setup)(void);
6559
/**
6660
* Function to run before each test in this suite
6761
*
6862
* @param data The test suite's data returned from setup()
6963
*/
70-
void (*const before)(void *data);
64+
void (*before)(void *data);
7165
/**
7266
* Function to run after each test in this suite
7367
*
7468
* @param data The test suite's data returned from setup()
7569
*/
76-
void (*const after)(void *data);
70+
void (*after)(void *data);
7771
/**
7872
* Teardown function to run after running this suite
7973
*
8074
* @param data The test suite's data returned from setup()
8175
*/
82-
void (*const teardown)(void *data);
76+
void (*teardown)(void *data);
8377
/**
8478
* An optional predicate function to determine if the test should run. If NULL, then the
8579
* test will only run once on the first attempt.
8680
*
8781
* @param state The current state of the test application.
8882
* @return True if the suite should be run; false to skip.
8983
*/
90-
bool (*const predicate)(const void *state);
84+
bool (*predicate)(const void *state);
9185
/** Stats */
92-
struct ztest_suite_stats * const stats;
86+
struct ztest_suite_stats stats;
9387
};
9488

9589
extern struct ztest_suite_node _ztest_suite_node_list_start[];
@@ -109,18 +103,17 @@ extern struct ztest_suite_node _ztest_suite_node_list_end[];
109103
* @param after_fn The function to call after each unit test in this suite
110104
* @param teardown_fn The function to call after running all the tests in this suite
111105
*/
112-
#define ZTEST_SUITE(SUITE_NAME, PREDICATE, setup_fn, before_fn, after_fn, teardown_fn) \
113-
static struct ztest_suite_stats UTIL_CAT(z_ztest_test_node_stats_, SUITE_NAME); \
114-
static const STRUCT_SECTION_ITERABLE(ztest_suite_node, \
115-
UTIL_CAT(z_ztest_test_node_, SUITE_NAME)) = { \
116-
.name = STRINGIFY(SUITE_NAME), \
117-
.setup = (setup_fn), \
118-
.before = (before_fn), \
119-
.after = (after_fn), \
120-
.teardown = (teardown_fn), \
121-
.predicate = PREDICATE, \
122-
.stats = &UTIL_CAT(z_ztest_test_node_stats_, SUITE_NAME), \
106+
#define ZTEST_SUITE(SUITE_NAME, PREDICATE, setup_fn, before_fn, after_fn, teardown_fn) \
107+
static STRUCT_SECTION_ITERABLE(ztest_suite_node, \
108+
UTIL_CAT(z_ztest_test_node_, SUITE_NAME)) = { \
109+
.name = STRINGIFY(SUITE_NAME), \
110+
.setup = (setup_fn), \
111+
.before = (before_fn), \
112+
.after = (after_fn), \
113+
.teardown = (teardown_fn), \
114+
.predicate = PREDICATE, \
123115
}
116+
124117
/**
125118
* Run the registered unit tests which return true from their pragma function.
126119
*
@@ -247,7 +240,7 @@ static inline void unit_test_noop(void)
247240
* @param suite The name of the test suite to attach this test
248241
* @param fn The test function to call.
249242
*/
250-
#define ZTEST_USER(suite, fn) Z_ZTEST(suite, fn, __USERSPACE_FLAGS)
243+
#define ZTEST_USER(suite, fn) Z_ZTEST(suite, fn, COND_CODE_1(CONFIG_USERSPACE, (K_USER), (0)))
251244

252245
/**
253246
* @brief Define a test function
@@ -269,7 +262,7 @@ static inline void unit_test_noop(void)
269262
* @param suite The name of the test suite to attach this test
270263
* @param fn The test function to call.
271264
*/
272-
#define ZTEST_USER_F(suite, fn) Z_ZTEST_F(suite, fn, __USERSPACE_FLAGS)
265+
#define ZTEST_USER_F(suite, fn) Z_ZTEST_F(suite, fn, COND_CODE_1(CONFIG_USERSPACE, (K_USER), (0)))
273266

274267
/**
275268
* @brief Test rule callback function signature

subsys/testsuite/ztest/src/ztest_new.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ int ztest_run_test_suites(const void *state)
559559
int count = 0;
560560

561561
for (ptr = _ztest_suite_node_list_start; ptr < _ztest_suite_node_list_end; ++ptr) {
562-
struct ztest_suite_stats *stats = ptr->stats;
562+
struct ztest_suite_stats *stats = &ptr->stats;
563563
bool should_run = true;
564564

565565
if (ptr->predicate != NULL) {
@@ -590,7 +590,7 @@ void ztest_verify_all_test_suites_ran(void)
590590
struct ztest_unit_test *test;
591591

592592
for (suite = _ztest_suite_node_list_start; suite < _ztest_suite_node_list_end; ++suite) {
593-
if (suite->stats->run_count < 1) {
593+
if (suite->stats.run_count < 1) {
594594
PRINT("ERROR: Test suite '%s' did not run.\n", suite->name);
595595
all_tests_run = false;
596596
}

0 commit comments

Comments
 (0)