Commit graph

284 commits

Author SHA1 Message Date
Al Semjonovs
ccc0315e14 ztest: Handle assert failures without signal handler
The signal handler needs to return gracefully. When multiple
tests assert, the first assert will raise SIGABRT and the signal
handler will run and the test will stop running.
The second assert will raise SIGABRT but the signal handler
will not be called, therefore the test PASS/FAIL status is not
updated correctly.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2022-08-05 12:51:44 -04:00
Al Semjonovs
4a0040f346 ztest: Fix logic for SUITE_SKIP
When ZTEST setup fails z_assume, we should mark all tests within
suite as skipped.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2022-08-05 11:54:11 -04:00
Al Semjonovs
1463e1c26a ztest: Fix logic for listing tests once
A test case may invoke run_all multiple times, causing
logic for listing tests to run tests on second call.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2022-08-03 14:32:54 -04:00
Anas Nashif
d60e3123cb tests: TEST_EXTRA_STACK_SIZE depend on test
Make the option TEST_EXTRA_STACK_SIZE depend on Tests, otherwise it will
appear in each generated .config file.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-08-03 11:22:20 +02:00
Anas Nashif
51cb40e5b3 tests: ztest: move TEST_LOGGING_FLUSH_AFTER_TEST under ztest
This config option is only used with ztest, so move it under ztest.
Otherwise it appears in .config when you build ANY application.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-08-03 11:22:20 +02:00
Fabio Baltieri
def230187b test: fix more legacy #include paths
Add a bunch of missing "zephyr/" prefixes to #include statements in
various test and test framework files.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-08-02 16:41:41 +01:00
Stephanos Ioannidis
e7263b19e1 Revert "ztest: Add config switch for modes of test output"
This reverts commit 5a850a5d06, which
broke multiple tests in the CI.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-07-29 15:44:32 -04:00
Stephanos Ioannidis
caed3931a4 Revert "ztest: add test summary after all suites finish running"
This reverts commit 0456ddc27d, which
broke multiple tests in the CI.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-07-29 15:44:32 -04:00
Stephanos Ioannidis
a2e2569684 testsuite: ztress: Remove idle thread NULL check
This commit removes the NULL check on the idle thread array
(`idle_tid`) because it is statically declared and will never be NULL.

This fixes the "comparison will always evaluate as ‘false’" warning
generated by the GCC 12.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-07-29 08:45:02 -04:00
Ming Shao
0456ddc27d ztest: add test summary after all suites finish running
Add test summary after all test suites finish running.
The summary can be one-line or verbose, which is configured
with CONFIG_ZTEST_VERBOSE_SUMMARY. The one-line summary covers
overall suite stats. The verbose summary covers each test
function within the suite besides the one-line summary.

Signed-off-by: Ming Shao <ming.shao@intel.com>
2022-07-28 18:07:01 -04:00
Ming Shao
5a850a5d06 ztest: Add config switch for modes of test output
Support verbose or one-line summary at test suite level.
Support verbose or no output at test function level.

Totally 4 combinations configurable:
- function verbose + suite verbose
- function verbose + suite oneline
- no function output + suite verbose
- no function output + suite oneline

Signed-off-by: Ming Shao <ming.shao@intel.com>
2022-07-28 18:07:01 -04:00
Yuval Peress
b513e621b0 docs: ztest: Update documentation for new API
Documentation now includes:
- How to create a test suite
- How to use predicates
- How to use setup/before/after/teardown
- How to use test rules
- Direct people to use FFF instead of ztest mock

Fixes #47420

Signed-off-by: Yuval Peress <peress@google.com>
2022-07-15 22:25:41 +00:00
Anas Nashif
32c22cc63a ztest: generate symbols for tests
This will help with parsing testcases in test binaries.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-11 11:56:39 +02:00
Andrei Emeltchenko
5b633db288 ztest: Add Z_TEST_SKIP_IFNDEF macro
Add macro Z_TEST_SKIP_IFNDEF which is used when you want to skip test
if configuration option is not enabled.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-07-07 15:07:02 -04:00
Yuval Peress
10feb693f5 unittest: support ztest_new_api
Add support for the new Ztest API when using unittest.

Fixes #47420

Signed-off-by: Yuval Peress <peress@google.com>
2022-07-07 18:22:14 +02:00
Aaron Massey
83253023cf ztest: Track skipping test versus entire suite
The addition of the assumption API introduced a bug where a skipped test
would subsequently skip later tests within the same suite. A skipped test
was being treated as an entire skipped test suite.

Keep track of tests being skipped due to skipping in the suite setup versus
being skipped within their test function.

TEST=west build -p -b native_posix tests/kernel/condvar/condvar_api/ -t run
TEST=twister -T tests/ztest -p native_posix

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2022-07-06 18:50:35 -04:00
Anas Nashif
718750f962 fs/testsuite: add mising braces to single line if statements
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-06 11:00:45 -04:00
Yuval Peress
e9e030f56b ztest: Add zassume* API
Add an assume API which works like JUnit's. Assumptions can be made
at any point before your test returns (setup, before, and during the
test). If an assumption fails, the test will be marked as skipped.

This helps avoid a cascading affect of failed tests when a base
feature breaks. The feature is expected to have tests and the tests
which depend on it should be skipped (not failed) if that feature
is broken.

Issue #42472

Signed-off-by: Yuval Peress <peress@google.com>
2022-07-04 14:16:34 -04:00
Yuval Peress
16b9fdf6a0 ztest: run clang-format for easier diffs
Run clang-format on ztest-new.c to make diffs a bit easier

Signed-off-by: Yuval Peress <peress@google.com>
2022-07-04 14:16:34 -04:00
Yuval Peress
54adba4633 ztest: use an enum for the test result
Update `test_result` to use an enum for better code clarity

Signed-off-by: Yuval Peress <peress@google.com>
2022-07-04 14:16:34 -04:00
Yuval Peress
e26ea1b936 ztest: run clang-format on ztest_assert.h
Simple pass to make the diff easier to read for additional changes.

Signed-off-by: Yuval Peress <peress@google.com>
2022-07-04 14:16:34 -04:00
Krzysztof Chruscinski
2153c91877 testsuite: ztress: Add test skipping if system clock is too high
When system clock is set globally for the test which is executed
on various qemu platforms it may happen that clock is set too
high compared to CPU clock frequency. In that case test may stuck.
Added check and test skipping in that case.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-07-04 15:50:53 +02:00
Keith Packard
34473f6821 subsys/testsuite: Don't add empty z_malloc_partition to mem domain
The malloc partition may actually be empty, if so, don't try to add it to
the domain as that will generate an error.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-30 10:33:24 +02:00
Yuval Peress
a7ceba3710 testing: add zephyr/ prefix to testing include path
Continuation of issue #41543 to add prefix scope for Zephyr's include
files.

Signed-off-by: Yuval Peress <peress@google.com>
2022-06-29 06:04:32 -04:00
Krzysztof Chruscinski
7f1b4f88e3 logging: Rename files and test from log_msg2 to log_msg
Renaming log_msg2 files to log_msg.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 09:10:33 +02:00
Chen Peng1
5a23383ad6 tests: interrupt: remove unused macro TRIGGER_IRQ_INT.
On X86 platforms, the interrupt trigger method has been
changed to use APIC IPI, we don't use INT command to trigger
interrupt, so remove this unused macro.

Signed-off-by: Chen Peng1 <peng1.chen@intel.com>
2022-06-23 09:08:43 +02:00
Chen Peng1
40fb6fca05 tests: interrupt: add some nop operations in trigger_irq function.
On X86 platforms, the interrupt trigger method has been changed
from using INT command to using APIC IPI, we need to make sure
the IPI interrupt is handled before do our check, so add some
nop operations.

Signed-off-by: Chen Peng1 <peng1.chen@intel.com>
2022-06-23 09:08:43 +02:00
Benjamin Gwin
ee22ae79a4 testsuite: Make ztest_error_hook compatible with C++
This lets ztest error hooks be used from C++ based tests.

Signed-off-by: Benjamin Gwin <bgwin@google.com>
2022-06-22 19:30:06 -04:00
Yuval Peress
d813e9b39f ztest: Fix incorrect use of this as fixture
Update `this` to `fixture` to avoid C++ keyword error.

Fixes #46459

Signed-off-by: Yuval Peress <peress@google.com>
2022-06-16 16:13:18 -04:00
Yuval Peress
3634456e6b ztest: re-format header
Run clang-format on ztest_test_new.h to clean up some style issues

Signed-off-by: Yuval Peress <peress@google.com>
2022-06-16 12:31:27 -04:00
Yuval Peress
beecf051d9 ztest: cleanup old linker script
A reminant of the old linker script was left in a previous PR.
Remove it.

Signed-off-by: Yuval Peress <peress@google.com>
2022-06-16 12:31:27 -04:00
Al Semjonovs
0411aa666c ztest: Add CLI arguments to filter test/suites ran
Added test command line arguments to filter
which tests are executed. Filtered tests should follow
suiteA::test1,suiteB::test2 format.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2022-06-15 18:06:54 -04:00
Benjamin Gwin
0cc9ad4f50 testsuite: Make ztress header C++ compatible
This allows ztress to be linked correctly from C++ based tests.

Signed-off-by: Benjamin Gwin <bgwin@google.com>
2022-06-07 11:53:41 +02:00
Fabio Baltieri
e24314f10f include: add more missing zephyr/ prefixes
Adds few missing zephyr/ prefixes to leftover #include statements that
either got added recently or were using double quote format.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-05-27 15:20:27 -07:00
Yuval Peress
138f399e6c ztest: run clang-format on ztest_new.c
Clang-format was updated to allow 100 column lines.

Signed-off-by: Yuval Peress <peress@google.com>
2022-05-25 11:20:13 +09:00
Yuval Peress
86cadf9283 ztest: Fix userspace ztests in new API
Update the new API to use K_USER as the flags for both
CONFIG_USERSPACE and CONFIG_TEST_USERSPACE. Also, fix the linker
script to properly include the suites, tests, and rules.

Fixes #44108

Signed-off-by: Yuval Peress <peress@google.com>
2022-05-25 11:20:13 +09:00
Anas Nashif
dacca51266 ztest: use TESTSUITE instead of test suite in output
output of ztest is not easy to ready with many testsuites running in
sequence, make it a bit more readable.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-05-13 12:16:57 -04:00
Jordan Yates
f2b8a9918f ztest: Add zassert_between_inclusive macro
Added macro to test that a value falls within a defined range, including
the provided end points.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-05-13 14:17:08 +02:00
Al Semjonovs
47850a301c ztest: Add config to shuffle test order
Enable ZTEST_DO_THE_SHUFFLE to shuffle the order tests are ran.
Additional configs ZTEST_DO_THE_SHUFFLE_SUITE_REPEAT_COUNT
ZTEST_DO_THE_SHUFFLE_TEST_REPEAT_COUNT specify the number of times
the test or suite is executed.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2022-05-11 12:14:31 -04:00
Gerard Marull-Paretas
5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Gerard Marull-Paretas
a4eac53b9e ztest: add support for new and legacy include paths
The ztest unittest module relies on some headers that fake the real
ones, e.g. <zephyr/arch/cpu.h>. When new header location was introduced,
their path was not updates. This patch fixes this problem and provides
ztest with both, legacy and new include paths so that it can keep
working on both scenarios.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 20:03:00 +02:00
Anas Nashif
462b13e16e Revert "ztest: Fix userspace ztests in new API"
This reverts commit 900b6723e7.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-04-26 18:55:32 -04:00
Yuval Peress
900b6723e7 ztest: Fix userspace ztests in new API
Update the new API to use K_USER as the flags for both
CONFIG_USERSPACE and CONFIG_TEST_USERSPACE. Also, fix the linker
script to properly include the suites, tests, and rules.

Fixes #44108

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-26 14:29:18 -04:00
Al Semjonovs
fef6e46f01 ztest: Add Z_TEST_SKIP_IFDEF macro
Defined Z_TEST_SKIP_IFDEF macro to skip tests when specified
config is enabled.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2022-04-20 15:28:14 -04:00
Bartosz Bilas
e89f441146 testsuite: ztest: remove superfluous default n for boolean
bool symbols implicitly default to n so
there is no need to redundant those values.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-04-19 11:49:27 +02:00
Anas Nashif
1537ee7a0b ztest: if runid is set, propagate it
define test run id and make it available to ztest. This will be used to
verify we are evaluating the same test we have just built and flashed
and that we are not looking at some old output.

Existing code in ztest will use this, and twister will define the run
id.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-04-12 08:54:41 -07:00
Yuval Peress
648bb9ebdf ztest: fix before function ordering
Make sure that the test rules' `before` function runs before the
suite's. This allows the suite to override any defaults set by the
rule.

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-08 15:49:57 -07:00
Trond Einar Snekvik
6224ecbfa6 kernel: Remove idle thread cpu index on single-core devices
The idle thread got an index suffix in #23536 to make it easier to
identify different idle threads on different cores. This looks out of
place on single-core devices when the idle thread is listed next to
other kernel threads, such as main.

Remove the idle thread index on single-core platforms, and replace all
references to this format in tests and documentation.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2022-03-30 10:08:48 -04:00
Nazar Kazakov
f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Krzysztof Chruscinski
fe423d52a7 testsuite: ztress: Delay start of the test
Delay start of threads and timer to ensure that setup
is completed. Especially, vital on multiple CPUs.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-15 13:19:28 -04:00