Commit graph

869 commits

Author SHA1 Message Date
Łukasz Fundakowski
8201d20b24 twister: remove not needed try..except
Removed redundant try..except around the code
and fixed a test for that code which was false positive.

Signed-off-by: Łukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-10-13 18:13:11 -04:00
Maciej Torhan
12d21dfc2d twister: scripts: add missing failure reason in Robot test runner
Add failure reason with return code when Renode process fails

Signed-off-by: Maciej Torhan <mtorhan@antmicro.com>
2025-10-09 12:35:48 -04:00
Abderrahmane JARMOUNI
fed89a038d scripts: pylib: twister: expr_parser: add dt_node_has_prop expression
Add 'dt_node_has_prop' expression to use the existence of a node property
as a filter in Twister test configuration yaml files.
First argument must be a node alias (in aliases node) or a node path,
not a nodelabel.

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
2025-10-08 08:47:27 +02:00
Bartlomiej Buczek
cbe94caa77 scripts: twister: coverage: do not fail when suspicious_hits are detected.
gcovr 8.0 introduces suspicious_hits detection, warn on such detection, but
do not stop coverage calculation at all.

Signed-off-by: Bartlomiej Buczek <bartlomiej.buczek@nordicsemi.no>
2025-10-03 12:50:24 +03:00
Łukasz Fundakowski
f23b1f59da twister: Improve handling SystemExit exceptions
If twister exits by sys.exit function or by raising
the SystemExit exception, catch that exceptions and
return proper exit code.

Signed-off-by: Łukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-09-26 09:38:10 -04:00
Jordan Yates
61298e31c7 scripts: twisterlib: more efficient coverage merging
Use `collections.defaultdict` to simplify code, and use the `bytes`
type internally rather than hex strings.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-09-19 08:34:32 -04:00
Jordan Yates
aa08e0df20 testsuite: coverage: convert dump method to choice
To support future coverage dump methods (semihosting) move
`COVERAGE_DUMP` inside a choice symbol.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-09-19 08:34:32 -04:00
Hake Huang
4c8419b992 twsiter: binary handler: pass verbose setting to west call
pass verbose setting to west call. when the v > 2 west log
will be triggerred

Signed-off-by: Hake Huang <hake.huang@nxp.com>
2025-09-15 14:43:51 +02:00
Grzegorz Chwierut
bf2378e36b twister: scripts: sharing of built applications
This feature enables sharing of built applications between test
scenarios, allowing tests to access build artifacts from other
applications.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-09-15 10:29:40 +02:00
Hake Huang
504fb0158f doc: scripts: display_harness: update document on installation
add Installation Guide section

Signed-off-by: Hake Huang <hake.huang@nxp.com>
2025-09-13 11:21:53 -04:00
Hake Huang
2d8a6d23f8 tests: display: support headless mode
for test machine without display, need support open-cv-headless mode.

1. support headless mode
2. add parser for environment path

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2025-09-13 11:21:53 -04:00
Benjamin Cabé
b1c7f9c126 scripts: do not install/recommend vulnerable python packages
requests < 2.32.4 is subject to GHSA-9hjg-9r4m-mvj7
pyyaml < 5.4 is subject to GHSA-8q59-q68h-6hv4
pyyaml < 5.1 is subject to GHSA-rprw-h62v-c2w7
protobuf < 5.29.5 is subject to GHSA-8qvm-5x2c-j2w7

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-09-12 14:23:18 -04:00
Fabio Baltieri
c0c757d892 twister: use csv to split extra argument arguments for west flags
Use csv instead of a plain split to split extra arguments for extra west
flags, this allows correct passing of arguments that are internally
escaped in quotes, such as arugments containing commas.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-09-09 11:44:54 +02:00
Lukasz Fundakowski
4f637258ef twister: refactor twister_main to simplify the system tests
Refactored twister_main.py module to simplify the code and system tests.
Removed the need to patch `sys.argv` in blackbox tests.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-09-04 16:45:42 +02:00
Lukasz Fundakowski
6fcb3ff219 twister: refactoring: Improve error message when test failed
Modified the assertion statements to raise informative exceptions
that indicate which lines did not pass the assertions.
Added unit tests using pytest to validate the functionality of
the modified functions.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-09-03 11:03:47 +02:00
Sylvio Alves
4651a02ff4 twister: reset ESP32 via RTS/DTR to capture early boot logs
When testing ESP32-based platforms in CI, early boot logs can be missed
if the serial connection isn't reset properly. This patch applies the
standard RTS/DTR toggle sequence to reset the ESP32 after flashing,
ensuring consistent log capture from the very beginning.

The logic is applied conditionally when the runner is "esp32".

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-09-03 11:03:20 +02:00
Fabio Baltieri
867676c906 twister: pass flash_command to the harness
Add the necessary logic to pass the custom flash_command to the pytest
harness.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-09-03 06:10:37 +02:00
Fabio Baltieri
a31f784e95 twister: add a --flash-command flag
Currently twister requires west to flash a board, either directly using
west-flash or indirectly through the cmake flash target.

Add an option to specify a custom flash script, this is passed a
build-dir and board-id flags so it can be used to implement custom
flashing scripts in a system that does not use west.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-09-03 06:10:37 +02:00
Fabrice DJIATSA
7ff93d7454 scripts: twister: pylib: not needed board id with BOOT-SERIAL mode
STM32CubeProgrammer does not support flashing in BOOT-SERIAL mode
using the device's serial number.

Signed-off-by: Fabrice DJIATSA <fabrice.djiatsa-ext@st.com>
2025-09-02 15:54:07 +02:00
Anas Nashif
8d0a6b59c6 twister: do not use twister internals for reason field
Do not use twister internals for reason field.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-09-02 10:00:24 +02:00
Anas Nashif
a6277ddaef twister: remove stray debug message
Remove leftover debug message.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-09-02 10:00:24 +02:00
Anas Nashif
f42dc20073 twister: deal with status/reason setting in handler in one place
Multiple handlers were setting status/reason in slightly different ways,
but the code was mostly trying to do the same. Put this code in the
handler class and implement in one place.

This fixes an issue where in some cases qemu failures were not handled
correctly and status of cases was not updated, leading to multiple
failures.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-08-31 06:17:16 -04:00
Tim Pambor
375d51452e scripts: twister: Fix --flash-before with serial-pty script
Honor the --flash-before option when using a serial-pty script with
--device-serial-pty <script> and start the script only after
flashing the device.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-08-30 18:00:32 +01:00
Anas Nashif
de8914ddc0 twister: coverage: --gcov-object-directory works with >= gcovr 7.0
This command line option is not available in older versions of gcovr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-08-30 18:00:09 +01:00
Lukasz Fundakowski
71a5f29150 twister: Add configuration reader to pytest-twister-harness
Added a class that helps to read Kconfigs from a configuration file.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-08-30 12:30:26 +02:00
Marco Widmer
d45985347b twister: coverage: set gcov working directory
gcovr runs gcov to generate temporary coverage files into the gcov
working directory. The working directory defaults to gcovr's -r
argument.

When running twister with the --coverage-per-instance argument, multiple
gcovr instances may run in parallel. Since they all share the same gcov
working directory, they may interfere with each other, resulting in
errors like this:

	AssertionError: Sanity check failed, output file
	spinlock.h##4167b923a06cc9590c8eef372f016a6d.gcov doesn't exist
	but no error from GCOV detected.

To fix this, specify a separate gcov working directory for every test
through gcovr's --gcov-object-directory option.

Signed-off-by: Marco Widmer <marco.widmer@bytesatwork.ch>
2025-08-14 15:49:35 +02:00
Lukasz Fundakowski
fc8164036c twister: Fix pytest warnings while discovers tests
Added `__test__ = False` to classes that have
`Test` in the name.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-08-12 20:39:29 -04:00
Fabio Baltieri
ee5b5f30fe twister: always call flash directly
Drop the logic to use the generator "flash" target, that is using west
anyway, always call flash directly anyway so that those targets can be
deprecated.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-08-12 09:55:47 +03:00
Hake Huang
9e551f5877 twister: harness: add display harness
display harness to validate display content

Signed-off-by: Hake Huang <hake.huang@nxp.com>
Co-authored-by: Abderrahmane JARMOUNI <git@jarmouni.me>
2025-08-12 09:54:27 +03:00
Anas Nashif
b1a3dc00b0 twister: report: switch --detailed-test-id logic
now no-detailed-test-id is enabled by default, so switch the logic so we
do not require the extra parameter when reruning.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-08-01 07:50:10 -04:00
Robert Robinson
8e69b52205 scripts: twister: handlers: Append dev-id for runner nrfutil_next
appends the --dev-id argument when using nrfutil_next runner.

Signed-off-by: Robert Robinson <robert.robinson@nordicsemi.no>
2025-07-29 11:24:21 -04:00
Tim Pambor
dff24c8c00 twister: Fix race condition in try_making_symlink
Replaces the check-then-create pattern for symlinks with
opportunistic creation. Instead of checking for existence
before creating the symlink, the code now attempts to
create it directly and gracefully handles the case
where it already exists.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-07-25 23:30:31 +02:00
Anas Nashif
ac4aabc10d twister: support filtering tests using regex
Use --test-pattern to filter scenarios using regular expressions, for
example:

./scripts/twister --test-pattern '^kernel.semaphore.*' -v

will run all those test using this identifier pattern, and nothing else.
Multiple patterns are possible.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-07-21 07:23:58 -04:00
Anas Nashif
9219c81b66 twister: make no-detailed-test-id default
Make this option default and reduce amount of details displayed by
twister.
This options has been enabled in CI for a while now with the intention
of making it default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-07-19 15:50:47 -04:00
Afonso Oliveira
467d2e8297 scripts: twister: clarify output directory renaming message
Change "Renaming output directory to" message to "Renaming previous
output directory to" to make it clearer that twister is renaming the
existing directory, not the current output directory.

This helps avoid confusion for new twister users who might think the
current output is going to the renamed directory.

Signed-off-by: Afonso Oliveira <afonsoo@synopsys.com>
2025-07-19 13:51:57 -04:00
Anas Nashif
63dd2db594 twister: match platform regex pattern
Use --platform-pattern <regex> to match platforms, something like

twister -T samples/hello_world/ --platform-pattern ".*/stm32f4.*"

will build/run all those platform targets with stm32f4 in them.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-07-19 13:45:30 -04:00
Tim Pambor
51989cbe0a twister: Fix exception if twister fails to create symlink
This fixes a typo in the formatting code that caused an exception
if the symlink creation failed.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-07-16 16:39:47 -05:00
Anas Nashif
4d82c48789 twister: make test configuration handling a class
Split test configuration code into own class and do parsing in two steps
to get the right context of platforms and scenarios.

Fixes zephyrproject-rtos/zephyr#89774

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-07-14 07:11:22 -10:00
Benjamin Cabé
125b23ba02 twister: harness: power: fix amp to milliamp conversion
Fix amp to milliamp conversion where a 10^4 factor was applied instead
of 10^3.
Adjust existing test cases accordingly (including a small change to one
of the expected RMS values in pm.power_states that either changed
since the test was introduced or was set too aggressively back then).

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-07-11 08:16:58 -10:00
Benjamin Cabé
daf5584c63 Revert "scripts: Bump Python target version for ruff"
This reverts commit e8caaf4137.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-07-04 15:50:06 -05:00
Katarzyna Giądła
9b428c8e5f twister: Fix tests statuses if quarantine is verified
If test configuration is not quarantined and `--quarantine-verify`
mode is enabled, these should be filtered and not attached
to reports.

Proposed change applies this approach.

Signed-off-by: Katarzyna Giądła <katarzyna.giadla@nordicsemi.no>
2025-07-01 10:17:53 -05:00
Katarzyna Giądła
bec789d364 twister: Enable gathering footprint if test plan exists
If test plan is used, memory usage metrics are overridden.
Result of this operation is missing memory footprint.

This change removes redundand metrics update and fixes
described inconvenience.

Signed-off-by: Katarzyna Giądła <katarzyna.giadla@nordicsemi.no>
2025-07-01 10:16:32 -05:00
Daniel DeGrasse
0b0af06da5 scripts: pylib: fix twister report handling for junitparser >= 4.0.2
With junitparser 4.0.2, the JunitXml.fromfile() now returns a JUnitXml
instance. In order to access the junit.TestSuite instance, we must use
TestSuite.fromelem() to convert it back.

Signed-off-by: Daniel DeGrasse <ddegrasse@tenstorrent.com>
2025-06-27 18:28:50 -05:00
Grzegorz Chwierut
c6b3b9342c twister: pytest: Add support for mcumgr go tool with BLE
Added basic support to run upgrade with mcumgr tool
using BLE transport.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-06-27 12:21:56 +02:00
Marco Widmer
07b4f30b2d pytest twister harness: increase timeout when stopping subprocess
When running pytest tests with coverage enabled, the test process starts
to write the coverage data when it receives the SIGTERM signal. On slow
machines, this can take longer than 0.5s. Increase the timeout and only
attempt to kill the process if it is still running after the timeout.

Signed-off-by: Marco Widmer <marco.widmer@bytesatwork.ch>
2025-06-26 10:59:12 -05:00
Dmitrii Golovanov
208a8b3ac7 twister: Enable 'flash-before' mode on serial-pty
Enable `flash-before` mode for devices connected via serial-pty
the same way, as for physical serial.

This mode allows Twister to start reading from the DUT's serial
connection only after the flashing stage has been completed,
thus excluding an early part of the log stream not directly
related to the current test.

It can help in situations, when the device is connected via some
serial-over-network harness which is still transferring device
logs or keeping in its buffer a tail with different RunID etc.
from the previous test image run.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2025-06-24 20:05:46 -10:00
Pieter De Gendt
e8caaf4137 scripts: Bump Python target version for ruff
Now that Python 3.12 is the minimum required version for Zephyr, ruff
should target that instead of 3.10.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-06-23 15:48:57 +01:00
Anas Nashif
91dc04d5d0 twister: adapt ctest results for twister
When we have skips in ctest, the overall result should not be marked as
a SKIP unless all tests have been skipped. If we have passing tests,
mark the test as PASS. Any failures/errors obviously will fail the
tests.

Also pass the skip reason from ctest to twister to give a hint about
what is going on in case of skips.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-06-19 14:04:18 +02:00
Anas Nashif
c511b16fca twister: remove useless . at end of message
No need to have a period here.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-06-19 14:04:18 +02:00
Maciej Perkowski
61e9de5ec4 twister: Minor quarantine fixes
Statuses of quarantined test cases were not updated properly.
Quarantined tests shouldn't cause errors in integration mode.
Removed obsolate filter type.

Signed-off-by: Maciej Perkowski <maciej.perkowski@nordicsemi.no>
2025-06-10 10:22:51 -04:00