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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Updated unit tests from pytest-twister-harness
with wupport of multiple connextions.
Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
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>
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>
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>
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>