-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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: add a ztest shell command #65437
Conversation
Duplicate of #58374? |
Oh wow - I didn't even notice that. I guess it is, although I kind of like this one better tbh ;-) |
5d39409
to
a532da6
Compare
Opening this up. I could maybe add filtering capabilities in this PR. Maybe json / xml output to the console? |
888ed0a
to
0231484
Compare
For details, see https://github.com/google/googletest/blob/main/googletest/test/googletest-filter-unittest.py |
Unable to repro CI failures locally. twister -i -p qemu_arc_em -p qemu_arc_hs -p qemu_arc_hs5x -p qemu_arc_hs6x -p qemu_arc_hs_xip -p qemu_cortex_a9 -p qemu_cortex_m3 -p qemu_cortex_r5 -p qemu_nios2 -p qemu_riscv32e -T tests/ztest/shell/
...
INFO - Total complete: 10/ 10 100% skipped: 1, failed: 0, error: 0
INFO - 1 test scenarios (10 test instances) selected, 1 configurations skipped (0 by static filter, 1 at runtime).
INFO - 9 of 10 test configurations passed (100.00%), 0 failed, 0 errored, 1 skipped with 0 warnings in 17.62 seconds
INFO - In total 117 test cases were executed, 12 skipped on 10 out of total 644 platforms (1.55%)
INFO - 9 test configurations executed on platforms, 0 test configurations were only built.
INFO - Saving reports...
INFO - Writing JSON report /home/cfriedt/zephyrproject/zephyr/twister-out/twister.json
INFO - Writing xunit report /home/cfriedt/zephyrproject/zephyr/twister-out/twister.xml...
INFO - Writing xunit report /home/cfriedt/zephyrproject/zephyr/twister-out/twister_report.xml...
INFO - Run completed Edit: until I rebased on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small issue. I don't see anything other show stoppers other than failing tests.
Will unfortunately need to exclude the esp32s2 / xtensa variant because they have some conflicting headers and it looks as though the include paths are ordered such that the broken version is included prior to the Zephyr version. It's possible that the headers would be interchangeable, but |
Fixed |
Updated some comments / warnings / error messages. I was looking at adding shuffle and repeat support (both are actually pretty trivial), but it will require refactoring other ztest parts. Probably ok to defer on that. |
@yperess - PTAL. Should I keep working on this? Does it duplicate what Google is doing ATM? We will likely be using this internally until there is an equivalent solution upstream (i.e. shell command with the same arguments - and ideally output - as gtest). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
b2fb4c7
to
65f6cf3
Compare
|
Add a ztest shell command so that select tests can be run via the shell. This is useful for e.g. systems where we do not necessarily want to run all tests immediately from main() or would prefer to only run certain tests without modifying the source or binary. Since we are using getopt_long() under the hood, option arguments can be separated with '=' or space ' '. E.g. ztest # run all tests ztest --help ztest --ztest_list_tests ztest --ztest_filter POSITIVE_PATTERNS[-NEGATIVE_PATTERNS] ztest --ztest_repeat=N ztest --ztest_shuffle ztest --ztest_random_seed 42 ztest --ztest_color=(yes|no|auto) ztest --ztest_output=(json|xml)[:DIRECTORY/|:FILE_PATH] Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Add a testsuite for the ztest shell. In particular, ensure that all filter functionality works as expected per Google Test Framework criteria. Test inputs were adapted from googletest-filter-unittest.py in https://github.com/google/googletest. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a gTest compat mode rather than a natve shell implementation for ztest as can be demonstrated in #58374. I know is a bit stale, but I have an updated version based on the initial feedback. gTest compatibility mode can always be added on top, but IMO leveraging shell features and exposing ztest features whether in gtest or not should be the priority and gtest support should be a mode rather than the main feature.
Also, many of the options listed are not supported yet, I suggest to only list and document what is working:
E.g.
ztest # run all tests
ztest --help
ztest --ztest_list_tests
ztest --ztest_filter POSITIVE_PATTERNS[-NEGATIVE_PATTERNS]
ztest --ztest_repeat=N
ztest --ztest_shuffle
ztest --ztest_random_seed 42
ztest --ztest_color=(yes|no|auto)
ztest --ztest_output=(json|xml)[:DIRECTORY/|:FILE_PATH]
I ran a few tests and getting lots of issues, i.e.
uart:~$ ztest --filter=+threads_lifecycle.test_thread_join
Running TESTSUITE threads_lifecycle
===================================================================
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
TESTSUITE threads_lifecycle succeeded
Running TESTSUITE threads_lifecycle_1cpu
===================================================================
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
Warning: CONFIG_ZTEST_SHELL_PATTERN_MAX is not large enough for
Warning: +threads_lifecycle.test_thread_join
Warning: Needed: 36
Warning: Actual: 32
TESTSUITE threads_lifecycle_1cpu succeeded
------ TESTSUITE SUMMARY START ------
SUITE SKIP - 0.00% [threads_lifecycle]: pass = 0, fail = 0, skip = 29, total = 29 duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_abort_from_isr] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_abort_from_isr_not_self] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_essential_thread_abort] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_essential_thread_operation] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_k_busy_wait] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_k_thread_stack_space_get_user] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_resume_unsuspend_thread] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_systhreads_idle] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_systhreads_main] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_thread_join] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_thread_join_deadlock] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_thread_join_isr] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_thread_name_get_set] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_thread_name_user_get_set] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_thread_runtime_stats_get] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_thread_start] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_thread_start_user] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_thread_timeout_remaining_expires] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_abort_others] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_abort_self] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_priority_set] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_spawn_delay] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_spawn_forever] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_spawn_params] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_spawn_priority] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_suspend] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_suspend_resume_preemptible] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_threads_suspend_timeout] duration = 0.000 seconds
- SKIP - [threads_lifecycle.test_user_mode] duration = 0.000 seconds
SUITE SKIP - 0.00% [threads_lifecycle_1cpu]: pass = 0, fail = 0, skip = 12, total = 12 duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_customdata_get_set_coop] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_customdata_get_set_preempt] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_delayed_thread_abort] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_k_busy_wait_user] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_k_thread_foreach] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_k_thread_foreach_null_cb] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_k_thread_foreach_unlocked] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_k_thread_foreach_unlocked_null_cb] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_k_thread_state_str] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_threads_abort_repeat] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_threads_cpu_mask] duration = 0.000 seconds
- SKIP - [threads_lifecycle_1cpu.test_threads_suspend_resume_cooperative] duration = 0.000 seconds
------ TESTSUITE SUMMARY END ------
Need to spend some more time on this. Will also update my PR so we can see how we can converge.
@@ -62,6 +62,13 @@ static void end_report(void) | |||
} | |||
} | |||
|
|||
#ifdef CONFIG_ZTEST_SHELL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, ztest_new.c should not be there, must have forgotten to remove it when old ztest was removed, so not sure about all those changes and why they were needed, strange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying to be consistent. But yea was kind of surprised to see it still here. For anyone using tagged v3.5.0, it's still the active version for CONFIG_ZTEST_NEW
@@ -181,6 +181,58 @@ config TEST_LOGGING_FLUSH_AFTER_TEST | |||
default y | |||
depends on MULTITHREADING | |||
|
|||
config ZTEST_MAIN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this? Either you run with shell, then you jump into shell and run the tests from there, or run the tests without shell and just execute the test as usual. Do not see the value of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is to prevent ZTest from running by default immediately. Some systems need additional application-time setup before you can start executing tests.
# currently this is broken due to getopt_state / conflicting native definitions on POSIX arch | ||
depends on !ARCH_POSIX | ||
help | ||
Provide a shell command to run ZTests from the Zephyr shell. The arguments of the 'ztest' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ztest and the zephyr shell can do more than what gtest does or provides, so this is rather limiting, i.e. I would like to see feature of the shell being used, such as sub commands, auto-completion etc instead of depending on command lines for everything.
Compatibility mode with gtest is fine, but not as the main shell implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subcommands are fine for a specific class of command. Here, flags make a bit more sense. Simply because subcommands exist is not justification to use them everywhere.
string "Prefix for ztest shell options" | ||
default "" | ||
help | ||
This option is for compatibility with Google Test Framework, where each option specific to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main motivation here seems to be compatibility with gtest instead of providing full shell support for tests, which is very limiting. And then, most of those options insipred by gtest are not implemented, so basically we go back what can be done already as demonstrated in #58374
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See earlier comment #65437 (comment)
Additional features were pretty trivial to implement, but require refactorization.
Well, it is a native shell implementation.. Many of the existing Kconfig options for ZTest today mirror gtest options and terminology, but there are also only so many ways to skin a ZTest.
That is true. It would be quite good if the subsys were capable of supporting arbitrary different frontends, like many of the existing Zephyr subsystems. A Gtest-like shell cmd is only one possible frontend.
Of course. gtest compatibility is a nice feature for myself and many others from Meta (I would guess Google as well, and others elsewhere).
As mentioned earlier in the comments, it's quite trivial to refactor the code that is there so that multiple test runners can use the same implementation. I already have repeat, random_seed, and shuffle working, but wanted to wait until there was some movement here.
I would suggest increasing CONFIG_ZTEST_SHELL_PATTERN_MAX by 4 in your case. It could really be set to any amount though and the storage could even be stored inside the state object.
Sure - that would be great. |
Just putting this into draft mode. It might need a rework |
just mentioning in case you missed it but #58374 has now been merged |
Yes - there are some features that exist here that do not exist there |
which? |
I think filtering was one of them |
Add a
ztest
shell command so that select tests can be run via the shell. This is useful for e.g. systems where we do not necessarily want to run all tests immediately frommain()
or would prefer to only run certain tests without modifying the source or binary.Since we are using
.
getopt_long()
under the hood, option arguments can be separated with=
orThe CLI is intentionally similar to that of
gtest
binaries. It might be nice to optionally clone the output format of gtest as well.https://pastebin.com/GtBg0aHZ
uart:~$ ztest --list_tests libc_common.test_abort libc_common.test_abs libc_common.test_atoi libc_common.test_bsearch libc_common.test_checktype libc_common.test_exit libc_common.test_limits libc_common.test_memchr libc_common.test_memcmp libc_common.test_memcpy libc_common.test_memmove libc_common.test_memset libc_common.test_qsort libc_common.test_qsort_r libc_common.test_rand libc_common.test_rand_reproducibility libc_common.test_sqrt libc_common.test_sqrtf libc_common.test_srand libc_common.test_ssize_t libc_common.test_stdbool libc_common.test_stddef libc_common.test_stdint libc_common.test_str_operate libc_common.test_strchr libc_common.test_strcmp libc_common.test_strcpy libc_common.test_strlen libc_common.test_strncmp libc_common.test_strncpy libc_common.test_strtok_r libc_common.test_strtol libc_common.test_strtoul libc_common.test_strxspn libc_common.test_time libc_common.test_time_t libc_common.test_tolower_toupper