Commit graph

858 commits

Author SHA1 Message Date
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
Arkadiusz Cholewinski
471aa1b477 PM: Record metrics in power management tests
Add metrics recording functionality to power management tests.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
2025-06-09 08:55:31 +02:00
Anas Nashif
e12457dd6e twister: reports: try to show more build failures in generated summary
Some Build failures are actually cmake issues, so in that case, if
nothing is found as build failure, try to parse for cmake issues.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-06-05 15:13:07 -05:00
Maciej Perkowski
49595c7309 twister: Adjust status for quarantined instances
Skipped status fits quarantined items better than filtered.
Filtered tests are by default removed from reports, which
shouldn't be the case for quarantined tests.
Adjust tests unit and blackbox tests accordingly.

Signed-off-by: Maciej Perkowski <maciej.perkowski@nordicsemi.no>
2025-06-05 09:34:13 +02:00
Maciej Perkowski
50f36f0002 twister: logging: decouple status reporting from logging level
Verbosity >1 should be enough to see filtered tests. Coupling
it with debug logging level makes the output messy.

Signed-off-by: Maciej Perkowski <maciej.perkowski@nordicsemi.no>
2025-06-05 09:34:13 +02:00
Grzegorz Chwierut
632d006260 twister: Convert platform names before printing
Just move a code with workaroud to convert platform names
to the full name with variants.
It fixes an issue, that not every platforms are printed
before running tests.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-05-27 17:55:46 +02:00
Ederson de Souza
9741c25715 twister: More restrictive regex for log markers
Some simulators - like simics - may end up adding extraneous suffixes to
logged lines. This may cause some regex that match too much fail. This
patch fixes two such cases:

  - regex to find RunID changed to only match valid hexadecimal
    characters;
  - regex to match start of testsuite changed to only match valid word
    characters (0-9A-Za-z_).

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2025-05-17 14:11:45 +02:00
Anas Nashif
5fe84d5b69 arch: nios2: remove arch
Remove architecture and dependencies.
Remove altera HAL supporting nios2

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-15 20:01:05 -04:00
Felix Behnke
a045eaebad fix: twister: quit-on-failure
use public queue methods to clear queue on failure

-s Felix Behnke felixbeiderarbeit@gmail.com

Signed-off-by: Felix Behnke <felixbeiderarbeit@gmail.com>
2025-05-15 22:14:27 +02:00
Mateusz Junkier
04b49fadab twister: harness_config extended by test retries in testcase.yaml
Extend Twister to allow defining repeat counts
for specific scenarios by harness_config.

Signed-off-by: Mateusz Junkier <mateusz.junkier@intel.com>
2025-05-13 03:20:10 +02:00
Yuval Peress
5b19a9b94d twister: Better manage gcov sym link
In twister coverage runs we create the gcov sym link to llvm-cov
executable. This code runs multiple times which causes errors with the
current implementation since creating the symlink will fail; then
copying will also fail because we're using the symlink (self copy the
file).

Add a helper function to `try_making_symlink` which will handle the
following cases:
1. If the symlink already exists and is correct, do nothing.
2. If the symlink exists but points to the wrong file, replace it.
3. If the symlink doesn't exist create it.
4. If creating a symlink fails, just copy the file.

Signed-off-by: Yuval Peress <peress@google.com>
2025-05-07 21:20:45 +02:00
Luca Burelli
2d264618bc twister: improve the alignment of columns in verbose output
This commit improves the alignment of columns in the verbose Twister
output by reclaiming extra space in the testsuite name column when the
platform name oveflows its allocated width.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-05-07 03:59:05 +02:00