Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ztest: support runs suites and cases from shell #58374

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/develop/test/ztest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ function can be written as follows:

/* Only suites that use a predicate checking for phase == PWR_PHASE_0 will run. */
state.phase = PWR_PHASE_0;
ztest_run_all(&state);
ztest_run_all(&state, false, 1, 1);

/* Only suites that use a predicate checking for phase == PWR_PHASE_1 will run. */
state.phase = PWR_PHASE_1;
ztest_run_all(&state);
ztest_run_all(&state, false, 1, 1);

/* Only suites that use a predicate checking for phase == PWR_PHASE_2 will run. */
state.phase = PWR_PHASE_2;
ztest_run_all(&state);
ztest_run_all(&state, false, 1, 1);

/* Check that all the suites in this binary ran at least once. */
ztest_verify_all_test_suites_ran();
Expand Down
2 changes: 2 additions & 0 deletions subsys/testsuite/ztest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ zephyr_library_sources_ifdef(CONFIG_ZTRESS src/ztress.c)

if(CONFIG_ARCH_POSIX)
zephyr_library_sources(src/ztest_posix.c)
elseif(CONFIG_ZTEST_SHELL)
zephyr_library_sources(src/ztest_shell.c)
else()
zephyr_library_sources(src/ztest_defaults.c)
endif()
9 changes: 9 additions & 0 deletions subsys/testsuite/ztest/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ config ZTEST_TEST_DELAY_MS
Add a delay between between tests to manage output on the console on
systems that can't handle the rapid output rate.

config ZTEST_SHELL
bool "Ztest with shell support"
select SHELL
select SHELL_THREAD_PRIORITY_OVERRIDE
select GETOPT_LONG
select SHELL_GETOPT
help
Enable shell to manage test execution and selection.

config ZTEST_CPU_HOLD_TIME_MS
int "Time in milliseconds to hold other CPUs for 1cpu type tests"
default 3000
Expand Down
30 changes: 22 additions & 8 deletions subsys/testsuite/ztest/include/zephyr/ztest_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,11 @@ extern struct ztest_suite_node _ztest_suite_node_list_end[];
* Default entry point for running or listing registered unit tests.
*
* @param state The current state of the machine as it relates to the test executable.
* @param shuffle Shuffle tests
* @param suite_iter Test suite repetitions.
* @param case_iter Test case repetitions.
*/
void ztest_run_all(const void *state);
void ztest_run_all(const void *state, bool shuffle, int suite_iter, int case_iter);

/**
* The result of the current running test. It's possible that the setup function sets the result
Expand Down Expand Up @@ -265,18 +268,25 @@ enum ztest_phase {
* Run the registered unit tests which return true from their predicate function.
*
* @param state The current state of the machine as it relates to the test executable.
* @param shuffle Shuffle tests
* @param suite_iter Test suite repetitions.
* @param case_iter Test case repetitions.
* @return The number of tests that ran.
*/

#ifdef ZTEST_UNITTEST
int z_impl_ztest_run_test_suites(const void *state);
static inline int ztest_run_test_suites(const void *state)
int z_impl_ztest_run_test_suites(const void *state, bool shuffle,
int suite_iter, int case_iter);

static inline int ztest_run_test_suites(const void *state, bool shuffle,
int suite_iter, int case_iter)
{
return z_impl_ztest_run_test_suites(state);
return z_impl_ztest_run_test_suites(state, shuffle, suite_iter, case_iter);
}

#else
__syscall int ztest_run_test_suites(const void *state);
__syscall int ztest_run_test_suites(const void *state, bool shuffle,
int suite_iter, int case_iter);
#endif

#ifdef ZTEST_UNITTEST
Expand Down Expand Up @@ -315,9 +325,12 @@ void ztest_verify_all_test_suites_ran(void);
* checks for fast failures and initialization.
*
* @param name The name of the suite to run.
* @param shuffle Shuffle tests
* @param suite_iter Test suite repetitions.
* @param case_iter Test case repetitions.
* @return Negative value if the test suite never ran; otherwise, return the number of failures.
*/
int z_ztest_run_test_suite(const char *name);
int z_ztest_run_test_suite(const char *name, bool shuffle, int suite_iter, int case_iter);

/**
* @brief Returns next test within suite.
Expand Down Expand Up @@ -534,14 +547,15 @@ void ztest_simple_1cpu_after(void *data);
*
* @param suite Test suite to run.
*/
#define ztest_run_test_suite(suite) z_ztest_run_test_suite(STRINGIFY(suite))
#define ztest_run_test_suite(suite) z_ztest_run_test_suite(STRINGIFY(suite), \
int suite_iter, int case_iter)

/**
* @brief Structure for architecture specific APIs
*
*/
struct ztest_arch_api {
void (*run_all)(const void *state);
void (*run_all)(const void *state, bool shuffle, int suite_iter, int case_iter);
bool (*should_suite_run)(const void *state, struct ztest_suite_node *suite);
bool (*should_test_run)(const char *suite, const char *test);
};
Expand Down
Loading
Loading