Commit graph

942 commits

Author SHA1 Message Date
Hake Huang
b3dff9bbbc tests: twister: using --no-rebuild in west flash
west flash deprecates --skip-rebuild to --no-rebuild

Signed-off-by: Hake Huang <hake.huang@nxp.com>
2025-12-08 13:12:04 -05:00
Jordan Yates
d020049f01 scripts: twisterlib: main: trim run duration
Display the total run duration to two decimal points instead of ~14,
similar to the other displayed timestamps.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-12-08 13:11:44 -05:00
Jordan Yates
d1cd982f8f scripts: twisterlib: display testplan build duration
Display how long it takes to build the testplan in the logs. This can
be useful since the duration to bulid the plan can vary wildly depending
on the arguments given. Without this information, it is difficult to
tell (from CI logs) whether a long execution time is from actually
building and running the tests, or just generating the testplan.

For example, in a downstream repo:
```
./zephyr/scripts/twister --integration -iv -T . --dry-run

INFO    - Building initial testsuite list...
INFO    - Built testsuite list in 10.58 seconds
```
vs
```
./zephyr/scripts/twister --integration -iv -T . --dry-run \
--vendor nordic --vendor zephyr

INFO    - Building initial testsuite list...
INFO    - Built testsuite list in 201.01 seconds
```

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-12-08 13:11:44 -05:00
Mathieu Choplain
636df434b9 twister: device-handler: use --dev-id for STM32CubeProgrammer runner
Now that the STM32CubeProgrammer runner supports the standard `--dev-id`
argument, replace usage of `--tool-opt` in the Twister device handler code.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2025-12-03 09:12:09 -05:00
Mathieu Choplain
aaaf1d3992 scripts: pytest: hw_adapter: use --dev-id for STM32CubeProgrammer runner
Now that the STM32CubeProgrammer runner supports the standard `--dev-id`
argument, replace usage of `--tool-opt` in the pytest harness hardware
adapter.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2025-12-03 09:12:09 -05:00
Eemil Visakorpi
1d70b705b0 twister: Fix serial open for UART devices that do not immediately appear
Testing on linux, --flash-before argument did not work to wait for jlink
upload to complete. Instead Serial port opening throws file not found. The
fix ensures that the code waits for the serial port to appear before
attempting to connect. Tested on a proprietary platform with virtual UART
through usb.

Signed-off-by: Eemil Visakorpi <eemil@doublepoint.com>
2025-11-24 17:22:22 +01:00
Arkadiusz Cholewinski
1d6e0d533a Power harness: Update path for the raw data file.
Change direction for raw data file from $ZEPHYR_BASE
to <path_to>twister-out/../<test>/

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
2025-11-22 11:45:44 +01:00
Lukasz Fundakowski
3a1428f957 twister: Keep pytest output formatting in log
Fixed formatting of pytest output in log by not removing
leading whitespaces.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-11-20 06:02:15 -05:00
Lukasz Fundakowski
bd187425f7 twister: Don't print full stack trace in readlines_until method
The readlines_until method is part of the testing framework
(pytest harness) and should not print a full stack trace
when the expected line isn't found. It should also raise
an AssertionError instead of a TwisterHarnessTimeoutException,
allowing users to know that a test failed because the expected
condition did not happen.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-11-14 15:25:41 +02:00
Grzegorz Chwierut
b33387c44a scripts: twister: Add support for passing extra serial port to pytest
Extend twister's device serial handling to support multiple serial ports
for pytest-based tests. This enables testing scenarios that require
communication with multiple UART interfaces on the same device.
This enhancement enables comprehensive testing of multi-UART devices
while maintaining backward compatibility with single serial setups.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-11-13 20:42:31 -05:00
Appana Durga Kedareswara rao
639739169e twister: handlers: pass platinfo to serialPTY reorder pre-script execution
This commit makes two key improvements to the DeviceHandler:

1. Pass TWISTER_PLATFORM environment variable to serial PTY scripts
   - Enables serial PTY scripts to access platform-specific configuration
   - The platform name is now available via TWISTER_PLATFORM env variable
   - Allows board-specific serial port and baudrate configuration in
     external serial forwarding scripts

2. Reorder pre-script execution before serial PTY initialization
   - Moved pre-script execution before serial PTY setup to avoid conflicts
   - Prevents race conditions when pre-script performs board power cycling
     or reset operations that might interfere with active serial
     connections

These changes enable more flexible hardware testing scenarios where:
- Serial configuration can be automatically selected based on board type
- Board initialization (power cycling, FPGA programming) completes
  before establishing serial connections

Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
2025-11-13 23:19:28 +02:00
Benjamin Cabé
4a1d4b0c19 twister: harness: display_capture: drop requirements.txt
This requirements file can be confusing and will only get stale over
time. Drop it since these dependencies are actually captured in
scripts/requirements-run-test.txt

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-11-13 23:11:32 +02:00
Benjamin Cabé
dc0b225919 twister: harness: display_capture: remove duplicate code
Introduce a helper function to check if an exception is expected in
headless environment.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-11-13 23:11:32 +02:00
Benjamin Cabé
4b67237aaa twister: harness: display_capture: remove unnecessary "noqa: B007"
Properly ignore the unused loop variable

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-11-13 23:11:32 +02:00
Benjamin Cabé
53649a4f76 twister: harness: display_capture: remove unused fields from UVCCamera
This removes a few unused fields from the UVCCamera class.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-11-13 23:11:32 +02:00
Abderrahmane JARMOUNI
5be6aa13b9 scripts: pylib: twister: expr_parser: some enhancements
Rename dt_node_prop_enabled filtering expression to
dt_nodelabel_prop_enabled as it takes a node label as a 1st argument.

Enhance dt_node_has_prop inline doc and param name.

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
2025-11-06 15:49:28 +02:00
Benjamin Cabé
1e8a5f7dd0 doc: twister: add/move doc for display harness
The display harness initial documentation was a separate, stale (had
references to a personal Github repo), README.rst buried in the
twister/scripts folder.
Move the docs to be a "first class" part of the Twister documentation
alongside other harnesses.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-10-31 10:36:57 -04:00
WenBin Zhang
a43f48b15e twister: Enhanced Filtering Command Help
Collect filter commands into a single location and sort them in the
order: arch, vendor, platform, pattern, filter, tag. This enhances
the readability of help information and reduces the time spent
searching for filter command options.

Signed-off-by: WenBin Zhang <freey7955@gmail.com>
2025-10-28 20:27:20 -04:00
WenBin Zhang
30e5ea8eea twister: Enhanced device-testing Command Help
Collect device-testing commands into a single location to enhance
readability of help information and reduce the time spent
locating device-testing options.

Signed-off-by: WenBin Zhang <freey7955@gmail.com>
2025-10-28 20:27:20 -04:00
Henrik Brix Andersen
58a334f2f9 scripts: pylib: twister: hardwaremap: add Tigard support
Add support for the Tigard multi-protocol hardware hacking tool from
SecuringHardware.com.

More information available at https://github.com/tigard-tools/tigard

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2025-10-24 20:17:04 -04:00
Anas Nashif
6ea5f0abd7 twister: prefer 'fork' on POSIX to maintain pre-3.14 behavior
multiprocessing no longer defaults to fork, so force it to maintain pre
3.14 behavior. We will need to revisit the implementation and at some
point move to forkserver

Fixes #95058

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-24 08:59:30 -07:00
Keith Short
028cf7f3d9 twister: fix environment:os tag
Set the environment:os tag to the return value of platform.system(),
which is more useful than os.name() which always returns "posix".

Signed-off-by: Keith Short <keithshort@google.com>
2025-10-23 15:59:41 -04:00
Artur Wilczak
de183df157 tests: pm: Fix collecting data after fail
Fix for collecting and presenting measured data.
During verify measured values, the test skipped all results
after the first incorrect one. Furthermore, it duplicated
already collected data on the output list. So in this case the
result list include wrong data.

Signed-off-by: Artur Wilczak <arturx.wilczak@intel.com>
2025-10-16 22:38:01 -04:00
Ł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