Commit graph

272 commits

Author SHA1 Message Date
Anas Nashif
d20a52c4aa ztest: add missing break statement in ztest_test_pass function
Adds missing break in switch statement.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-06-18 17:48:03 -04:00
Benjamin Cabé
75d50742a7 Revert "testsuite: ztest: Add validation of zassert strings"
This reverts commit 6deca93285.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-05-22 11:58:43 -04:00
Krzysztof Chruściński
6deca93285 testsuite: ztest: Add validation of zassert strings
Add noncallable printf with string used for ztest assert/assume
macros to ensure printf-like argument validation at compile time.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-05-22 16:17:23 +02:00
Yuval Peress
ba9b4f3734 ztest: Fix confusing SKIP log
When CONFIG_ZTEST_FAIL_ON_ASSUME is set, a failed assumption will
cause the suite to fail, but the individual test will be marked as
SKIPPED. We should fail the test so it's clear what's going on.

Fixes #86611

Signed-off-by: Yuval Peress <peress@google.com>
2025-04-04 21:16:34 +02:00
Hake Huang
1847b882a2 tests: ztest: enable ztest_no_yield for all in PM
if CONFIG_PM=y, board will enter low power,
which will cause problem for debugger.
So for ztest cases, we need enable this to avoid problem.
This used to apply to soc/platform level, now remove them.

Signed-off-by: Hake Huang <hake.huang@nxp.com>
2025-03-25 22:14:20 +01:00
Tom Hughes
bddaff1d1b ztest: ztest_mock: Fix typo
"data provided don't match" should be
"data provided doesn't match"

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-13 01:13:56 +01:00
Tom Hughes
eff76caa17 ztest: mock: Fix typo
"Return value no used by mock" should be
"Return value not used by mock".

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-07 14:34:39 +01:00
Jeremy Bettis
027e19fe1f ztest: Don't clear test stats before running suite
test_main can call ztest_run_all multiple times. For example
tests/bluetooth/host/keys/bt_keys_get_addr/src/main.c does so.  If the
first call skips some tests and then they run in the second call,
everything is fine. However if they passed or failed in the first run
and skipped in the second run, then the test output (json, xml, and
printed summary) show the test as skipped even though it ran.

The solution is to not clear the test stats.

__ztest_init_unit_test_result_for_suite was added in commit
996c8457d7 by nashif.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-01-29 15:12:51 +01:00
Tom Burdick
5de7e415a0 logging: Add a log flush operation
Ensure all pending log messages are processed by the log processing
thread when log_flush is called, blocking the caller until done.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2025-01-15 09:33:28 +01:00
Chris Friedt
9504034733 sys: util: use BITS_PER_BYTE macro instead of the magic number 8
Obviously, everyone knows that there are 8 bits per byte, so
there isn't a lot of magic happening, per se, but it's also
helpful to clearly denote where the magic number 8 is referring
to the number of bits in a byte.

Occasionally, 8 will refer to a field size or offset in a
structure, MMR, or word. Occasionally, the number 8 will refer
to the number of bytes in a 64-bit value (which should probably
be replaced with `sizeof(uint64_t)`).

For converting bits to bytes, or vice-versa, let's use
`BITS_PER_BYTE` for clarity (or other appropriate `BITS_PER_*`
macros).

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-11-16 15:22:35 -05:00
Firas Sammoura
6f072ba774 Ztest: Including the missing C standard library header
The ztest.c calls atoi, which is provided by the C standard library.
Remove the conditional inclusion of the C standard library with the
definition of CONFIG_ZTEST_SHUFFLE.

Signed-off-by: Firas Sammoura <fsammoura@google.com>
2024-10-08 06:00:45 -04:00
Arkadiusz Cholewinski
a421f339d5 Ztest: Ztest_param fix
Add the missing #ifndef CONFIG_ZTEST_SHUFFLE in ztest.c file.
This fixes multiple definitions of NUM_ITER_PER_SUITE
and NUM_ITER_PER_TEST.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
2024-09-19 03:25:17 -04:00
Arkadiusz Cholewinski
9d9089edd0 ztest: Add Support for Multiple Test Runs.
Introduces new kconfig options to enable multiple test runs in the ztest.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
2024-09-18 15:32:28 +02:00
Anas Nashif
376085c9ed tests: kernel: add missing test call argument
Add missing param argument.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-08-24 07:17:15 -04:00
Arkadiusz Cholewinski
f58a4c4b1c ztest: expand ztest functionality.
Expanding the ZTEST shell to include a command that
accepts additional parameters, such as ztest run_testcase
<suite:test> -p any_value.

Adding the new ZTEST_P macro, to create the
parameterized test.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
2024-08-23 15:48:57 +01:00
Arkadiusz Cholewinski
6d5243cbed ztest: expand ztest_shell command
Expand ztest_shell subcommands `run-testcase`
and `run-testsuite` to include additional parameter `-r`
repeat-iter. This allows to run a particular testcase or
testsuite several times.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
2024-08-23 15:48:57 +01:00
Pisit Sawangvonganan
14c6925596 ztest: replace shell_fprintf(sh, SHELL_ERROR, ...) with shell_error
Replace `shell_fprintf(sh, SHELL_ERROR, ...)` with
`shell_error(sh, ...)` since it brings the same underlying
action with less typing.

Note: `shell_error` already concatenates `\n` to format strings,
so we remove `\n` from the original code.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-08-15 10:16:36 +01:00
Pisit Sawangvonganan
347c56c600 ztest: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in `subsys/testsuite/ztest/src/ztest.c` file.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-08-15 10:16:36 +01:00
Dawid Niedzwiecki
c2151ad1e3 ztest: undefine _POSIX_C_SOURCE before defining it
Undefine _POSIX_C_SOURCE before defining it to avoid double
definition

The previous version, changed in this PR
https://github.com/zephyrproject-rtos/zephyr/pull/70363, did the undef.
Make sure to do the same for all files in the current dir.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2024-08-13 14:56:06 +02:00
Keith Short
da4f4e8748 ztest: Replace PRINT with PRINT_DATA
The testsuite subsystem provides the macro PRINT_DATA() which can be
overridden using CONFIG_ZTEST_TC_UTIL_USER_OVERRIDE. Switch all calls of
PRINT() to PRINT_DATA withing the testsuite subsystem.

Signed-off-by: Keith Short <keithshort@google.com>
2024-08-09 08:39:18 -04:00
Keith Short
82a2a16649 ztest: Fix formatting
Run clang-format on some ztest files.

Signed-off-by: Keith Short <keithshort@google.com>
2024-08-09 08:39:18 -04:00
Keith Short
d8bc125469 ztest: fix compliance issue
Check compliance flagged an UNNESSARY_INT error.

Signed-off-by: Keith Short <keithshort@google.com>
2024-08-09 08:39:18 -04:00
Dmitrii Golovanov
c59412b1bf ztest: shell: Fix compilation error for NEWLIB_LIBC
Fix compilation error implicit declaration of function 'free'
in case of `CONFIG_NEWLIB_LIBC`.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-07-27 15:08:14 +03:00
Joakim Andersson
276850ca02 testsuite: Remove reference to deprecated ztest API
Remove reference to deprecated ztest_test_suite function from API
description.

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
2024-07-23 09:14:04 +02:00
Anas Nashif
1e20f58c17 ztest: doc: fix doxygen for ztest
Many ztest macros were not indexed correctly as part of the ztest_test
group, for example ZTEST_SUITE was completely missing in the
documentation.

In addition, document a few macros that did not have any documentation.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-07-11 18:58:45 -04:00
Dmitrii Golovanov
5d80e253b7 ztest: shell: Fix memory leaks processing test arguments
Fix Ztest shell memory leaks when it process test arguments.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-07-11 16:16:28 +02:00
Roman Studenikin
fdd81f87c2 testsuite: coverage: Add CONFIG_ZTEST_COVERAGE_RESET_BEFORE_TESTS
Add an option to reset gcov counters before running tests.
This ensures that only code lines triggered by test itself are counted in
the coverage report and all the board initialization code and pre-test
bootstrap is not counted. This is useful when, for example, you are
testing code that is also executed during bootup

Test Plan:
west build -p always -b qemu_x86_64 tests/ztest/base/ -- \
-DCONFIG_COVERAGE=y -DCONFIG_COVERAGE_GCOV=y -DCONFIG_COVERAGE_DUMP=y \
-DCONFIG_ZTEST_COVERAGE_RESET_BEFORE_TESTS=y
ninja -Cbuild run | tee log.log

Signed-off-by: Roman Studenikin <srv@meta.com>
2024-06-12 14:32:04 +03:00
Rubin Gerritsen
a35d5e7851 ztest: Add macros for comparing strings
These macros allows us to compare strings in a simpler way.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-11 11:39:36 +01:00
Krzysztof Chruściński
8f3989412f testsuite: ztest: ztress: Add missing static keywords
Add static to local timers definition.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-06-07 18:08:22 +01:00
Yong Cong Sin
e54b27b967 arch: define struct arch_esf and deprecate z_arch_esf_t
Make `struct arch_esf` compulsory for all architectures by
declaring it in the `arch_interface.h` header.

After this commit, the named struct `z_arch_esf_t` is only used
internally to generate offsets, and is slated to be removed
from the `arch_interface.h` header in the future.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-04 14:02:51 -05:00
Yong Cong Sin
3998e18ec4 arch: rename all esf struct to struct arch_esf
Rename every architecture's esf struct to `struct esf`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-04 14:02:51 -05:00
Yong Cong Sin
bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00
Yong Cong Sin
2e072ad017 ztest: include: unittest: relocate cpu.h and include only if unit-test
The `cpu.h` is meant to be a hack around Zephyr's dependencies
for unit-test, relocate it to a folder that's included only by
unit-test.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-10 11:50:36 +02:00
Yong Cong Sin
af78efaa4d subsys/testsuite/ztest: create stub headers at CMake configure time
Create unittest stub headers at CMake configure time.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-10 11:50:36 +02:00
Anas Nashif
0510e081a3 testsuite: ztress: fix doxygen command
Fix doxygen command.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-04-30 12:00:58 +02:00
Fin Maaß
e354927895 tests: use appropriate sys_randX_get()
use the appropriate sys_randX_get() instead
of always sys_rand32_get().

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-04-05 10:57:45 -05:00
Peter Mitsis
87ca079e49 tests: z_test_1cpu_start() makes only CPU0 active
When z_test_1cpu_start() is called to ensure that only a single CPU
on an SMP system is available for use in a test, this commit will
ensure that that CPU is the primary CPU--CPU0. This is done because
some timer drivers only have the timer interrupt processed by one CPU.

A bit of a song and dance is performed to achieve this without enabling
the CPU mask/affinity pinning API. If the cpuhold thread is found to
be executing on CPU0, then a new copy of cpuhold thread is created. Once
the new copy is executing (incidentally guaranteed to be on another CPU)
then it informs the original copy and busy waits until it the original
copy is switched out of CPU0. At this point, we can create the next
cpuhold thread to occupy another CPU if needed.

During this song and dance, it is critical that the 'copy' not pend. If
it pends, we can not guarantee which CPU it will execute on when it
unpends. As the cpuhold threads have the highest priority, nothing is
going to cause them to execute on another CPU for as long as they do
not pend.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2024-03-26 18:07:41 -05:00
Daniel Leung
3664ed64c3 arch: move arch_interface.h under zephyr/arch
arch_interface.h is for architecture and should not be
under sys/. So move it under include/zephyr/arch/.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-03-25 09:58:35 +00:00
Dawid Niedzwiecki
f36570a357 ztest: define _POSIX_C_SOURCE macro
Add declaration of the _POSIX_C_SOURCE < 200809L for ztest library for
declaration of strtok_r and strdup functions.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2024-03-25 09:56:37 +00:00
Alberto Escolar Piedras
50542682df subsys/testsuite/ztest: Replace native_posix in one comment
As we are replacing native_posix with native_sim, let's
refer to native_sim instead of native_posix in the comments.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-03-20 15:43:05 +01:00
Reto Schneider
c45026fc08 testsuite: ztest: Fix argument name
As per current definition of the Z_TEST macro, defined in
include/zephyr/ztest_test_new.h, the passed parameter is named
'fixture', not 'this'.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-03-19 17:53:30 +01:00
Stephanos Ioannidis
c64d0b9ce5 testsuite: ztest: Increase ZTEST_TEST_DELAY_MS to 5000
This commit increases the default value of `ZTEST_TEST_DELAY_MS` from 3000
to 5000 milliseconds because the current value of 3000ms may not be
sufficient for the hosts with lower CPU clock frequency (e.g. new Zephyr CI
runners with cost-effective processors).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2024-03-06 16:42:33 -05:00
Reto Schneider
7178113a3e ztest: Remove superfluous comment
This is obviously a copy & paste error. It was introduced by
107cb86bb3 (ztest: Add initial zexpect API
for delayed failing).

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-02-25 20:45:52 -05:00
Jordan Yates
9e9913a4fd testsuite: ztest: fix doxygen warnings
Document missing parameters on `ztest_run_test_suite`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2024-01-30 18:42:30 +01:00
Alberto Escolar Piedras
2417599dc0 ztest native extensions: Set standard source macro appropriately
This file uses strtok_r which is an extension to the the
std C library. Let's explicity select one of the extensions
which includes it instead of relaying on somebody having
set it for this file somewhere else.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-01-26 07:48:55 -05:00
Luca Burelli
5f2c6e58b0 ztest: export ztest_test_* symbols to llexts
Export the minimal set of ztest_test_* symbols to llexts so that the
zassert_* macros can be used by the extension code to affect test
execution. Calling these also requires vprintk() to be exported.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-01-26 12:36:23 +01:00
Anas Nashif
91841587d6 ztest: fix ztest_run_test_suite usage and macros
Fix usage of ztest_run_test_suite that was missed when introducing shell
support.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-01-09 08:15:22 -05:00
Anas Nashif
afc319e3fa ztest: shell: add shell support
- Support for listing both testcases and testsuites
- Support for running single suites or single test cases
- Support shuffling tests and repeating execution based on command line
  arguments.

For example, build with

west build -p  -b qemu_cortex_m3  tests/kernel/sleep   -t run -- \
-DCONFIG_ZTEST_SHUFFLE=y -DCONFIG_ZTEST_SHELL=y

Following commands are available:

uart:~$ ztest
ztest - Ztest commands
Subcommands:
  run-all          :Run all tests
  shuffle          :Shuffle tests
  list-testsuites  :List all test suites
  list-testcases   :List all test cases
  run-testsuite    :Run test suite
  run-testcase     :Run testcase

shuffle accepts two arguments --suite_iter and --case_iter which allows
repeated exercution of testcases or suites.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-01-09 09:58:57 +01:00
Anas Nashif
37529505ad ztest: remove old file
This c file is not being used anymore, so remove it.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-01-09 09:58:57 +01:00
Greter Raffael
774858c6dc ztest: Add comfort functions for non-zero return codes
Many functions return non-zero return codes on errors. I added an assert
for the case, when a function is expected to fail. It is just a
shorthand for `zassert_not_equal(0, ret);`, analogous to
`zassert_ok`, introduced in c5d85e175f.

I also added the corresponding `zassume_nok` and `zexpect_nok`.

Signed-off-by: Greter Raffael <rgreter@baumer.com>
2023-11-04 07:39:46 -04:00