Commit graph

942 commits

Author SHA1 Message Date
Krzysztof Chruściński
ca750d6730 scripts: pylib: twister: shell: Add option to read more data
Add option to execute command and then read the resposne for a
specified time. It can be useful if we want to validate additional
data that is output as the result of a command execution.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2026-04-17 13:43:51 +02:00
Kasper Sloth
231853800d twister: Move serial import to try except clause
Twister would incorrectly fail, if you didn't have
the serial library installed. Instead moving it
to the try except clause causes it to be handled
correctly

Signed-off-by: Kasper Sloth <kasper.sloth99@gmail.com>
2026-04-16 14:45:07 +02:00
Jeppe Odgaard
afc92ea7a1 scripts: west_commands: move zspdx to pylib
Allow twister to make use of zspdx by moving it to pylib to prevent code
duplication.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2026-04-14 22:27:52 -04:00
Martin Moya
ba480d810b twister: add support for gtest parametrized tests
Parametrized tests in gtest are shown as the following example in a log:

[  FAILED  ] FooTest/FooTypedTest/0.TypedTestFoo, where TypeParam = <type>

current regex of the gtest harness didn't detect such test so it marks
this as pass or that the result wasn't found. This commit extends the
regex to detect such behavior and adds unit test to verify that.

Signed-off-by: Martin Moya <moyamartin1@gmail.com>
2026-04-14 22:04:44 -04:00
Lucas Romero
32f7b0f231 twister: fix harmful wait on virtual com port
that can never succeed because it is not in the com port filter list.
This would trigger every time that a combination of --flash-before and
--serial-pty is used.

The list of monitored serial ports - at least on linux - does not contain
/dev/pts but that list is constantly checked if the /dev/pts/X device might
magically appear some day.

This is the proper fix instead of adding /dev/pts/* to the monitor list
because the reason why we need to wait is because in the codepath without
serial_pty, we might be resetting the target device, causing the dev node
to disappear/reappear. This is not the case for the virtual ports created
for serial_pty.

Signed-off-by: Lucas Romero <lucas.romero@a-labs.io>
2026-04-03 23:14:12 +09:00
Łukasz Fundakowski
e3c03691a7 twister: minor improvement for sys.path
Moved all `sys.path.insert` from twister's modules
to `twisterlib.__init__.py` to have only one place where all paths
are added.

Signed-off-by: Łukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2026-04-02 08:45:58 -05:00
Łukasz Fundakowski
79f47b7a5f twister: write unit tests to increase code coverage
Added unit tests for `twister_main.py` module to increase code coverage.
Did minor refactoring in `twister_main.py`.
Fixed type hints and added type ignores.
Removed unused variables.

Signed-off-by: Łukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2026-03-27 20:19:21 -04:00
Daniel Leung
223876cba4 twister: fix unnecessary trailing slash for toolchain variant
When TOOLCHAIN_VARIANT_COMPILER is empty, we should not append
a trailing slash (/) to ZEPHYR_TOOLCHAIN_VARIANT. Or else any
matching of ZEPHYR_TOOLCHAIN_VARIANT would be incorrect.

For example, ZEPHYR_TOOLCHAIN_VARIANT == 'xt-clang' and west
build would have it correct, while twister would have it as
'xt-clang/'. This prevents kconfig from matching correctly
(possibly among other things).

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-03-23 14:58:50 -05:00
Daniel Leung
f225fd06e9 twister: add support for whisper simulator
This adds support for running with whisper simulator under
twister.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-03-23 08:56:34 -04:00
Joel Holdsworth
09cd8302ef scripts: twister: Add OpenRISC as a supported test platform
Adds the openrisc CPU architecture to the twister platform definitions.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2026-03-21 07:50:57 -05:00
Jjateen Gundesha
7386141720 scripts: twister: fix monitor_serial writing handler.log in binary mode
- monitor_serial() opens handler.log in binary mode (\"wb\") and writes
re-encoded bytes. When the runner (e.g. linkserver for frdm-mcxn947)
produces serial output that is not cleanly decodable as UTF-8, the
decode('utf-8', 'ignore') silently drops bytes and the resulting
handler.log is unreadable.

- Fix by opening handler.log in text mode with explicit UTF-8 encoding,
consistent with BinaryHandler.handle_serial() which uses open(\"w\").
Change the decode error handler from 'ignore' to 'replace' so
corruption becomes visible as replacement characters rather than
silently dropped bytes.

Signed-off-by: Jjateen Gundesha <jjateen97@gmail.com>
2026-03-19 14:53:58 -05:00
Grzegorz Chwierut
2eb3bb9588 twister: move hardware reservation to runner context manager
Hardware reservation logic moved from Handler class to ProjectBuilder
runner using context manager approach. When NoDeviceAvailableException
is raised due to no free devices, the task is re-queued for later
processing instead of blocking the execution pipeline.

The reserve_hardware() context manager handles device reservation,
yields execution control only when hardware is available, and ensures
proper cleanup in the finally block.

All DUT management logic is now consolidated in HardwareMap class,
removing DUT references from Handler classes. This improves code
maintainability by centralizing responsibilities and eliminating
shared ownership of hardware resources between modules.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-03-18 15:19:30 -05:00
Sylvio Alves
e2f6e190cb twister: increase ESP32 reset pulse duration
Increase the reset pulse from 10ms to 100ms to ensure reliable
boot across all Espressif SoCs. Shorter pulses may cause the UART
to miss early bootloader output, leading to false-positive test
failures.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-03-18 08:45:23 -05:00
Stephanos Ioannidis
109099c962 scripts: twisterlib: Update Zephyr SDK gcov path
Update the gcov executable path for Zephyr SDK 1.0.0.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2026-03-17 15:43:52 -04:00
Anas Nashif
3bf6c859ef twister: support new toolchain variant syntax
support new syntax involving compiler and toolchains with multiple
compilers, i.e. zephyr/gnu

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2026-03-17 15:43:52 -04:00
Lukasz Fundakowski
8168f74916 twister: Remove DisablePyTestCollectionMixin and related tests
Simplified the code by removing useless class.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2026-03-16 09:06:24 +01:00
Grzegorz Chwierut
b5ba2c991e tests: twister: Update pytest tests for YAML config serialization
Update unit tests to verify YAML-based parameter serialization instead
of CLI arguments. Add tests for twister config file parsing and update
existing tests to check pytest_params object and YAML output.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-03-09 11:10:57 -05:00
Grzegorz Chwierut
bedba6412a twister: Add YAML config file support in pytest-harness
Add comprehensive YAML configuration support for pytest-harness
integration, replacing CLI argument approach with structured
configuration files while maintaining backward compatibility.

Key changes:
- Add --twister-config option to load test parameters from YAML
- Refactor TwisterHarnessConfig to support CLI and YAML configuration
- Move pytest parameter generation from CLI args to config files

This enables more flexible test configuration through structured YAML
files and improves the overall architecture of pytest-twister
integration.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-03-09 11:10:57 -05:00
Hake Huang
b69a35d02a tests: scripts: add west debug support in twister
in some multi-core platform, `west flash` can not support all cores.
`west debug` is supported to test secondary core, add this to twister
such as with
`--west-flash-cmd=debug` in twister command
or with
`--west-flash-cmd: debug` in hwmap.yaml

and same with pytest

command line setting will overrid the one in hwmap

Signed-off-by: Hake Huang <hake.huang@nxp.com>
Co-authored-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-03-08 22:00:45 -04:00
Grzegorz Chwierut
106ea725a5 twister: Remove redundant DUT storage from classes
Simplify the design by removing the `detected` attribute from
HardwareMap class and DUT storage from ProjectBuilder class.
Instead of storing detected DUTs as instance attributes, pass
them as method parameters where needed.

This eliminates data duplication since ProjectBuilder can access DUTs
directly from the environment object, and HardwareMap doesn't need to
maintain its own copy of detected DUTs. The refactoring makes the code
cleaner and reduces the risk of inconsistent state between different
objects storing the same DUT information.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-02-27 21:02:56 +00:00
Benjamin Cabé
2c8957fa0a doc: build: ci: twister: Zephyr now requires Python 3.12 or higher
Update getting started guide, release notes, CI actions, ruff,
build system, and Python version compliance check to use Python
3.12 as minimum supported version.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-02-26 21:25:03 +00:00
Grzegorz Chwierut
69edab8c97 twister: move ZEPHYR_BASE to constants to reduce dependencies
Moving ZEPHYR_BASE from environment.py to constants.py
allows importing classes like HardwareMap in
pytest-twister-harness module without pulling in unnecessary
dependencies from environment.py.

This refactoring improves module independence and makes selective
imports cleaner across the twister Python package structure.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-02-17 17:41:16 -06:00
Lukasz Fundakowski
d73ea02be1 twister: Do not clean previous results for listing tests
When user only wants to list tests or tags twister should
not clean previous results.
This change improves also performance for listing tests.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2026-02-17 13:22:35 -06:00
Lukasz Fundakowski
98c6fbfc9b twister: Refactor twister_main.py
Refactored main function for Twister execution.

- Rewrote the main function as a class and divided it into smaller,
  more maintainable methods.
- Improved code structure, making it easier
  to test with unit and module tests.
- Reduced the amount of code in a single function,
  enhancing readability and understanding

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2026-02-17 10:32:02 +01:00
Guðni Már Gilbert
fc8e096ee1 scripts: twister: minor speedup in apply_filters
Move a check to run earlier in a for-loop to minimize doing unnecessary
work like creating TestInstance class instances.

This is a very minor optimization when the number of testsuites are low.
But starts to count when there are a lot of testsuites.

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-02-02 14:46:34 +01:00
Hake Huang
cdd9d63a46 twister: handler: add spsdk support with dev_id
spsdk now support dev_id as parameter

Signed-off-by: Hake Huang <hake.huang@nxp.com>
2026-01-31 10:56:06 +01:00
Guðni Már Gilbert
bcb00aaa9a scripts: twister: don't parse snippets multiple times
Currently apply_filters is parsing & validating a snippet YAML
file multiple times, duplicating expensive work.

Do the work once per testsuite instead of for each testsuite
multiplied by number of toolchains.

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-01-30 16:56:25 -06:00
Lukasz Fundakowski
2ad2ce9fe1 twister: Improve error handling for user's errors
Exit from twister in case of user's error e.g. empty list
of tests provided by user instead of throwing unhandled
exception.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2026-01-30 16:55:29 -06:00
Piotr Kosycarz
aedada06c6 scripts: pylib: twister: twisterlib: coverage: catch hex parsing
As parsing hex was moved, move also catching its possible errors.

Signed-off-by: Piotr Kosycarz <piotr.kosycarz@nordicsemi.no>
2026-01-30 05:59:28 -06:00
Grzegorz Chwierut
1b1e902540 Revert "twister: pytest: fix duplicate log lines from pytest"
This reverts commit 96985a32e8.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-01-29 14:26:41 +00:00
Sharon Lin
5d56e00bfb scripts: twister: fix codec cp950 error when running on Windows
When running twister on Windows host, the build will fail from
cmakecache.py with error as:
UnicodeDecodeError: 'cp950' codec can't decode byte 0xe2 in
position 3444: illegal multibyte sequence

Signed-off-by: Sharon Lin <slin@atmosic.com>
2026-01-27 08:05:16 +01:00
Guðni Már Gilbert
e3575fc848 scripts: twister: fix issue with empty serial in hwmap
jsonschema is more strict when it comes to typing and only allows
strings for 'serial' in hwmap-schema.yaml.

Since 'serial' is not a required key in the schema, this commit
removes the 'serial' key from generated hardware maps when the
'serial' value is empty /unknown.

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-01-26 10:11:35 -06:00
Guðni Már Gilbert
e9f106dd7a twister: replace pykwalify with jsonschema
Usage of pykwalify is deprecated.

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-01-26 10:11:35 -06:00
Grzegorz Chwierut
efc36d96d3 twister: refactor DUT class to dataclass for serialization support
Convert the DUT class from a traditional class to a dataclass to enable
proper serialization and support for future multi-device testing with
pytest-harness.

Key changes:
- Migrated DUT class to use `dataclass` decorator with proper type hints
- Renamed `baud` property to `serial_baud` for consistency
- Updated hardware map schema to support both `baud` (legacy) and
`serial_baud` fields for backward compatibility
- Updated tests

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-01-21 17:06:36 +01:00
Guðni Már Gilbert
284a30053f scripts: twister: don't parse west modules in TestPlan
TwisterEnv already parses west modules during initialization, but TestPlan
was parsing them again via zephyr_module.parse_modules(), duplicating work.

Store the parsed module objects on TwisterEnv (self.modules) and have
TestPlan derive its module name list from env.modules instead. This drops
the redundant parse in TestPlan by removing handle_modules() and its call
site.

Each call to parse_modules() takes around 250-300ms on my end.

Update twister unit tests

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-01-20 20:04:37 -05:00
Guðni Már Gilbert
e19ebfb49a scripts: twister: use os.scandir for platform YAML discovery
Use a single os.scandir() pass per board directory to load twister.yaml
and collect legacy *.yaml files, replacing Path checks and globbing.

On my end this reduces execution time by ~50ms on Ubuntu 24.04 and
eliminates  ~80k Python function calls.

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-01-20 14:35:03 -05:00
Grzegorz Chwierut
f8e4c6cf6a twister: pytest: Fix post-script calling in initialization phase
The post-script was being called multiple times and during the
initialization phase when it should only run after the reader
thread has started and the device testing is complete.

Fixes #102386

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-01-20 14:34:54 -05:00
Lukasz Fundakowski
c5bc1a9779 twister: fix access to item in empty list
Fixed default argument in run_cmake_script method,
which cannot be an empty list.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2026-01-20 14:34:05 -05:00
Grzegorz Chwierut
5d73bc00ca twister: fix --list-tests output, remove duplication in names
This fixes the issue where --list-tests and --test-tree commands
showed duplicated testsuite IDs in the output,
simplifies testcase name handling in harness and runner modules.
Removed feature to extend behaviour of --no-detailed-test-id to shorten
test case names - feature was introduced in #82302.
This makes the twister output more predictable and the codebase easier
to maintain.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-01-20 15:30:44 +00:00
Mohamed Moawad
7fb39e806c twister: Add board-level flash_before support for pytest/shell harnesses
Add support for boards to specify flash_before in their board YAML files,
which is then used by pytest and shell harnesses. This is needed for
Synopsys ARC development boards (hsdk, hsdk/arc_hsdk/2cores, hsdk4xd
and iotdk) where the USB serial port disconnects during flashing.

Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
2026-01-14 13:00:22 -06:00
Tom Burdick
c97ccba142 twister: Support kitprog when generating hw map
Hardware map file generation should at least get you part way now with
Infineon boards with the Cypress derived KitProg3.

Signed-off-by: Tom Burdick <thomas.burdick@infineon.com>
2026-01-13 10:24:30 +01:00
Lauren Murphy
69ce125083 twister, west: test extra_conf_files arg to EXTRA_CONF_FILE
The extra_conf_files arg in testcase.yaml was being improperly
assigned to the CONF_FILE CMake arg, which caused
configuration_files.cmake to ignore soc and board Kconfig overlays.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2026-01-09 14:22:41 -06:00
Yves Wang
88e7b3b451 scripts: build: Accept python object in Domain's constructor
Make Domain's class constructor accept python object to avoid redundant
YAML serialize and unserialize which may introduce potential yaml type
errors.

Signed-off-by: Yves Wang <zhengjia.wang@nxp.com>
2026-01-07 14:51:44 -06:00
Guðni Már Gilbert
465150d796 twister: avoid scanning subcases for unselected test suites
Optimize testsuite discovery by skipping subcase scans for filtered suites

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-01-07 07:44:44 +01:00
Mike Szczys
06d5728d07 twister: fix --keep-artifacts
use the allow-list generated by --keep-artifacts whenever
cleanup_artifacts() is called. This resolves an issue where this allow-list
was not being honored when using the --prep-artifacts-for-testing flag.

Signed-off-by: Mike Szczys <mike@golioth.io>
2026-01-06 11:18:11 -05:00
Grzegorz Chwierut
4b6ad9db3c tests: twister: Update unit tests to support miltiple ports
Updated unit tests from pytest-twister-harness
with wupport of multiple connextions.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-12-22 20:36:34 +01:00
Grzegorz Chwierut
1b7810f0cb scripts: twister: Support multiple ports in pytest-twister-harness
Add support for multiple connections (e.g. UART) from one device,
enabling communication with second core UARTs. Feature implemented
by extracting connection logic from DeviceAdapter to new
DeviceConnection class with specialized implementations:
- SerialConnection for hardware UART ports
- ProcessConnection for native simulation
- FifoConnection for QEMU communication
Each connection maintains separate log files (handler.log,
handler_1.log, etc.) and can be accessed via connection_index
parameter in device methods like readline() and write().
This enables testing multi-core applications where different
cores communicate through separate UART interfaces.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-12-22 20:36:34 +01:00
Grzegorz Chwierut
96985a32e8 twister: pytest: fix duplicate log lines from pytest
The combination of pytest's `-s` (--capture=no) option and
`--log-cli-level=DEBUG` was causing duplicate log output.
Fixed by replacing `--log-cli-level=DEBUG` with `--log-level=DEBUG`.
`--log-cli-format` removed as is not used.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-12-19 07:51:49 -06:00
Grzegorz Chwierut
8827ea2643 twister: prevent infinite loop in required app resolution
When using --only-failed with required applications, twister could enter
an infinite loop during application dependency resolution.

Fixes #100808

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-12-19 07:51:23 -06:00
Mateusz Junkier
fb8a1ec9f3 Twister: fix serial port timeout
Fix for 1d70b70. Original code used start_time (set before flashing)
to calculate serial port wait timeout, which caused wait loop
to include flash duration, leading to exceed overall timeout.
Added serial_wait_start timestamp for avoid
including flash time in serial port enumeration timeout.
Make timeout dynamic (20% of flash_timeout, minimum 10s).

Signed-off-by: Mateusz Junkier <mateusz.junkier@intel.com>
2025-12-08 13:19:16 -05:00