Commit graph

349 commits

Author SHA1 Message Date
Hake Huang
4b25c9b617 twister: fix packaged sysbuild artifacts for west flash
Rework the sysbuild artifact relocation approach based on
reviewer feedback: instead of rewriting domains.yaml with
relative paths at package time, keep the original absolute
paths and rebase them transparently in Domains.from_file()
when the file has been moved to a different location.

This makes the fix generic - it works for any consumer of
Domains.from_file() (west flash, twister, pytest-twister-
harness), not just the --package-artifacts path.

Changes:
- domains.py: update from_file() to detect when build_dir
  stored in domains.yaml differs from the file's actual
  directory and rebase all domain paths accordingly.
  Remove the now-unused _resolve_build_dir() helper and
  get_domains_with_build_dirs_relative_to() method.
- runner.py: remove _sanitize_domains_file() and its call
  site; path fixup is now handled by Domains.from_file().
- test_domains.py: replace the mocked __init__ approach
  with end-to-end assertions; add a 'relocated artifacts'
  test case that exercises the new rebasing logic.
- test_runner.py: remove test_projectbuilder_sanitize_
  domains_file() and references to the deleted method.

Signed-off-by: Hake Huang <hake.huang@nxp.com>
2026-05-12 17:12:06 +02:00
Grzegorz Chwierut
86c3c6eead twister: add script harness for script execution to enable bsim
Introduce a Script harness base class to enable running
shell-script-based tests through Twister, primarily
targeting BabbleSim test scenarios. The class provides
subprocess execution, output streaming, and log handling
that Pytest, Ctest, and Bsim now share through inheritance.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-05-12 11:25:32 +02:00
Etienne Carriere
ac5f115bc8 twister: add dt_label_compat_enabled()
Add dt_label_compat_enabled() to filter targets that embed a node
label matching a target compatible string.

This helper function will be useful to consider zephyr,mapped-partition
compatible nodes that are now used instead of fixed-partition compatible
nodes for memory mapped flash partitions.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
2026-05-12 11:25:12 +02:00
Grzegorz Chwierut
3557bdf8a4 twister: multidut: Add native_sim support for multi-DUT tests
Allow multi-DUT test scenarios to run on native_sim simulator.

For non-device handlers, create placeholder reserved_duts entries
using CompoundHardwareData so pytest harness can find DUT configs.
Multi-DUT on native_sim is only allowed when all required devices
use the same platform (no cross-platform multi-DUT in simulation).

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-04-29 16:29:29 -04:00
Grzegorz Chwierut
1ea17fd1e6 twister: replace required_applications dict with dataclass
Replace plain dict usage for required_application elements with
a typed RequiredApplication dataclass for improved type safety

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-04-29 16:29:29 -04:00
Grzegorz Chwierut
320a88ee1b twister: multidut: Support different app per required device
Add support for flashing a different application to a required
DUT in multi-DUT testing. When a required_device entry specifies
an 'application' field, twister matches it against the
required_applications build dirs and assigns the correct
build_dir to the reserved DUT before flashing.

Move the required applications readiness check from
process_tasks() into ProjectBuilder.process() at the 'run'
stage. This ensures that building is not blocked by the
required_applications mechanism. Mutual
dependencies between instances is also allowed.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-04-29 16:29:29 -04:00
Grzegorz Chwierut
3047951393 twister: Add support for reserving multiple DUTs
Main:
- Add HardwareReservationManager class and move DUT reservation
  logic from HardwareMap to improve separation of concerns
- Add 'required_devices' structure to testsuite YAML schema to
  define multiple device requirements for a test
- Add option to reserve multiple devices, filtered by platform
  and fixtures. Fixtures can have an extra parameter (after ':')
  that must match across the main DUT and required devices

Other:
- Add HarnessConfig dataclass to provide structured access to
  harness configuration data instead of raw dict access
- Change 'fixture' parameter in harness_config from string to
  list of strings for more flexibility when matching DUTs with
  multiple fixture requirements
- Move conversion of short platform names to full target names
  from hardware map into TestPlan module. This ensures platform
  names are resolved before test discovery
- Add unit tests for HardwareReservationManager
- Align existing tests with new dataclass structures

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-04-29 16:29:29 -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
Ł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
Grzegorz Chwierut
86a1c954a2 tests: twister: Align tests with hardware reservation changes
Update unit tests after moving hardware reservation logic from
Handler class to HardwareMap. Relocate and rename tests to match
the new module structure and API changes.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-03-18 15:19:30 -05:00
Stephanos Ioannidis
935a5283f1 scripts: tests: twister_blackbox: Update Zephyr SDK toolchain name
This commit updates the Twister Black Box tests to expect the enhanced
toolchain variant names (i.e. `host/gnu` and `zephyr/gnu`).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2026-03-17 15:43:52 -04:00
Anas Nashif
ea41428980 twister: tests: adapt for new zephyr sdk 1.0
Fix toolchain detection which now has a compiler part.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
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
Hake Huang
bd5e3f52cd tests: twister: add west_flash_cmd mock
add west_flash_cmd for debug testing

Signed-off-by: Hake Huang <hake.huang@nxp.com>
2026-03-08 22:00:45 -04:00
Grzegorz Chwierut
be78f760e3 tests: twister: Update unit tests after changes in HardwareMap
Updated twister unit tests after refactoring of HardwareMap
class.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2026-02-27 21:02:56 +00:00
Guðni Már Gilbert
b4108b53f6 scripts: tests: speed up test_output_levels
Assign a platform to the test so Twister doesn't
pick up multiple platforms.

This reduces the test time by ~2 minutes.

Before: 9 passed in 265.88s (0:04:25)
After: 9 passed in 140.24s (0:02:20)

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-02-02 14:46:53 +01: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
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
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
Guðni Már Gilbert
6bb7a1b54b scripts: twister: Add full_name to board.yml
Fixes regression introduced by e45ac11aeb9b874038a2925c2588b94100aa28cc

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-01-13 09:33:35 -05: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
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
Guðni Már Gilbert
28fe8d5c87 scripts: tests: twister: mock listed serial port
Reduce the test time by ~300 seconds by mocking the listed serial port

Result from running:
pytest --durations=0 ./scripts/tests/twister/test_handlers.py

Before:
60.12s test_devicehandler_handle[valid pty]
60.12s test_devicehandler_handle[communicate timeout]
60.06s test_devicehandler_handle[popen called process error]
60.05s test_devicehandler_handle[valid dev]
60.03s test_devicehandler_handle[nonzero returncode]
0.01s  test_devicehandler_handle[create serial failure]

After:
0.01s test_devicehandler_handle[valid dev]
0.01s test_devicehandler_handle[valid pty]
0.01s test_devicehandler_handle[nonzero returncode]
0.01s test_devicehandler_handle[create serial failure]
0.01s test_devicehandler_handle[communicate timeout]
0.01s test_devicehandler_handle[popen called process error]

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-01-06 16:07:24 +00:00
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
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
5f67dfdf41 twister: device-handler: silence no-name-in-module warning
Silence CI warning caused by line "from . import ZEPHYR_BASE". This is a
legitimate pattern, but pylint seems unable to deduce so. Many other
scripts perform a similar silencing.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2025-12-03 09:12:09 -05:00
Kyle Bonnici
589be43e2e devicetree: remaining files
Applying dts-linter results for remaining format files

Signed-off-by: Kyle Bonnici <kylebonnici@hotmail.com>
2025-11-28 10:09:39 +00:00
Lukasz Fundakowski
03eff37921 twister: Remove unnecessary code
Removed some old code which is not used/needed any more.

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
Pieter De Gendt
aad2408b30 scripts: Don't use isort known-first-party
Partially revert 1bcc0652241af70d0b28aee155f260cd9ca0fc74

This change impacts all other scripts that import those modules, while
those weren't updated.

It will be hard to maintain this list, whilst keeping the entire tree
compliant.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-10-16 17:09:14 +03:00
Łukasz Fundakowski
2d60533558 twister: Refactor twister tests
- Removed redundant `sys.path.insert`
- Fixed imports order to follow PEP8 style

Signed-off-by: Łukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-10-15 17:36:11 -04:00
Lukasz Fundakowski
9c5325df29 twister: Add unit tests for Pytest harness
Added unit tests for parsing JUnitXml report by Pytest harness.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-10-14 17:41:32 -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
Anas Nashif
bf82f7ffac copyrights: fix copyright line
Add space before (c) to allow correct parsing by linters.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-07 22:53:45 -04:00
Grzegorz Chwierut
51cba9d11f twister: Add unit tests for required applications
Added tests for sharing of build application feature
added in #94167

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-09-24 19:20:15 -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
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
Marc Herbert
8ad23f8313 twister: add space in custom_flash_scripts example and test
This makes sure parsers don't trip over whitespace (as many do).

I suggested this late in #93944

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2025-09-05 17:11:51 +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
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
Anas Nashif
232db11f0d twister: tests: fix test output parsing
Fix test output parsing and update to what twister produces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-09-02 10:00:24 +02:00