Commit graph

822 commits

Author SHA1 Message Date
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
Ederson de Souza
01d10a4115 twister: Look at SIMICS_PROJECT environment variable to find simics
While cmake/emu/simics.cmake uses SIMICS_PROJECT env var, twister checks
if a build is "runnable" by checking if `simics` is executable, but it
doesn't look at SIMICS_PROJECT env var.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2025-04-24 16:54:00 +02:00
Jordan Yates
a5ffd7f7a3 scripts: twisterlib: extend testcase schema for reboots
Extend the testcase schema to provide a way to communicate that a given
test is expected to reboot during execution. The generic harness takes
that information and suppresses `already STARTED` warnings if the
restart is expected.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-14 13:05:46 +02:00
Fabrice DJIATSA
cf517f92fc scripts: twister: fix regenerate serial device with unknown platform
Since BOOT-SERIAL isn't a recognized STMicroelectronics product name,
when Twister saves the new map.yaml, it will also check if the previous
map.yaml had the 'SERIAL-BOOT' product name and attach the corresponding
serial device.It won't generate a new one with an unknown platform name.


Signed-off-by: Fabrice DJIATSA <fabrice.djiatsa-ext@st.com>
2025-04-14 11:49:13 +02:00
Dmitrii Golovanov
067126abcd twister: harness: fix Ztest case summary pattern
Fix missing match on Ztest test case summary log entries, so even
if the test case 'END' log entry is missed or corrupted, its status
will be updated from the Ztest summary log entries, if present.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2025-04-08 11:45:08 +02:00
Torsten Rasmussen
483c76759d scripts: support quoted sysbuild Kconfig settings in twister
Kconfig settings of string type is passed to CMake with quotes to ensure
they are properly handled, for example when specified in testcase.yml as
>   extra_args:
>    - CONFIG_FOO="bar"

Support sysbuild Kconfig settings `SB_CONFIG` by performing the same
quoting for settings starting with `SB_CONFIG_`.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-04-04 14:56:39 +02:00
Arkadiusz Cholewinski
35b13e1629 Twister: Add power measurements support for Twister.
Add support for powerShield of stm32l562e_dk board.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
2025-03-31 08:06:25 +02:00
Reto Schneider
67834a84c9 twister: Add missing spaces
This adds some missing whitespaces, thus improves the output of `twister
--help`.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2025-03-27 17:18:04 +01:00
Hake Huang
c5aacbc22a twister: runner: --prep-artifacts-for-testing protection
need add protection when check with sysbuild filter out
application, the domains is NULL

fixes: #87163

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2025-03-27 03:50:04 +01:00
Grzegorz Chwierut
5d049b6451 twister: Fix quarantine filtering simulations
Quarantine filter was not correctly identifying the simulator name.
Now it uses the simulator name from the Platform object,
ensuring that quarantined tests are properly excluded or verified

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-03-24 19:23:31 +01:00
Lukasz Mrugala
6ef4db88dd twister: Remove unrecognised sections test
The section lists that govern whether the ELF
section is recognised or not are out of date.

A programming bug has rendered the unrecognised
section check unrunnable for years.

Thus, the practically dead code of the
unrecognised section check is removed
in this commit.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2025-03-24 07:53:01 +01:00
Anas Nashif
173468ca53 twister: filters: fix processing of platform scope
Optimize code and fix process being killed when llaunched with --all.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-03-23 10:15:30 -04:00
Lukasz Fundakowski
d45396a6bb twister: Cleanup twister loggers
Removed logger.setLevel(...) from all twister modules, becasue
there should be only one place where twister loggers are configured,
and the log level should be set in that place.
This should be done in twister_main.py in setup_logging function.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-03-19 09:08:00 -04:00
Anas Nashif
b0792bbfa2 twister: config: test on integration plaforms if defined
Add option to force integration mode on a defined list of tests, for
example tests for sample that are identified with 'sample.'.

A sample per definition shall be tested on documented and supported
platforms listed in the sample documentation. Samples shall not be used
as tests to verify functionality of a feature on all available plaforms
in Zephyr.

To still allow testing on platforms not listed in the doc, and when such
platforms are covered by the provided filter, we should still be able to
build/run the tests on those platforms (not directly listed in
integration_platforms).

We detect a sample by its test identifier, i.e., it starts with 'sample.'.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-03-19 08:51:50 -04:00
Lukasz Mrugala
ffe72a49bf scripts: Add invariant log closing
If BB tests failed, crashed, etc., log handles
could linger and crash test cleanup.
Adding log closing to a `finally` section
should prevent those issues.

Loggers should not be set up as globals,
as it makes testing much harder.
Running multiple Twisters may cause for the
logfiles to be still "in use".

When exiting main, close all logfiles
and remove their handlers from all loggers.
Do that for conftest as well.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2025-03-13 16:53:55 +00:00
Alberto Escolar Piedras
cb53e40ff9 drivers uart_native_posix: rename to native_pty and support N instances
Rename the driver from uart_native_posix to uart_native_pty.
Including renaming the DTS compatible, and kconfig options, deprecating
the old ones.

And refactor the driver, generalizing it, so we can have any number of
instances.
Note that, unfortunately generalizing to N instances cannot be done
without a degree of backwards compatibility breakage: This driver was
born with all its configuration and selection of the instances based on
kconfig.
When the driver was made to use DT, it was done in a way that required
both DT and kconfig needing to manually coherently enable the 2nd UART.
This has now been fixed, which it means only DT is used to decide how
many instances are avaliable, and UART_NATIVE_POSIX_PORT_1_ENABLE is
just ignored.

Including:
* Deprecate UART_NATIVE_WAIT_PTS_READY_ENABLE: the options is always on
  now as it has no practical drawbacks.
* Deprecate UART_NATIVE_POSIX_PORT_1_ENABLE: DTS intanciation defines it
  being available now.
* Rename a few functions and in general shorten pseudo-tty/pseudo-
  terminal to PTY instead of PTTY.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-11 18:54:02 +01:00
Ederson de Souza
70c89811be scripts and soc: Mark MD5 and SHA1 usage as not for security
MD5 and SHA1 are not supposed to be used nowadays on security context.
Some ancillary scripts in tree do use them, but for verification only -
or where externally mandated, such the SPDX tool.

This patch marks those usages as `usedforsecurity=False`, which helps
clarify intent.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2025-03-11 04:52:15 +01:00
Alberto Escolar Piedras
4338122248 drivers entropy: fake_entropy_native_posix rename to _native_sim
Rename the driver files, binding and kconfig options, while deprecating
the old binding and kconfig options.

Uses in tree are replaced.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-08 03:38:13 +01:00
Lukasz Fundakowski
c5e8664089 twister: Refactor python module to follow PEP8 rules
Incremental refactoring.
Fix PEP8 issues to make ruff green for config_parser.py module.
Add __init__.py to twister directory to make it a proper python package,
and make modules importable.

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2025-03-07 19:49:42 +01:00
Anas Nashif
a7e2846a94 twister: setup logging per process
Setup logging per process to fix issue on both mac and windows where
handlers are not available to the processes.

Fixes #86237

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-02-28 14:53:38 +01:00
Anas Nashif
73fd29f76e twister: logging: verbose names for logging handlers
Trivial rename of variables to make them more clear.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-02-26 01:39:10 +01:00
Anas Nashif
96ab891f3a twister: filter out native_sim on ! Linux
native_sim only works and builds on Linux, when running twister on the
Mac, this platform fails to build and reports errors.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-02-26 01:39:10 +01:00
Benjamin Cabé
46782dd862 twister: harness: fix spelling of "written"
s/writen/written/

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-02-21 11:41:46 +00:00
Benjamin Cabé
09d2a6c08c twister: Add --keep-artifacts option
Introduce a new command-line option `--keep-artifacts` in twister that
allows users to specify which artifacts should be preserved
during test cleanup in addition to the default set.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Co-authored-by: Anas Nashif <anas.nashif@intel.com>
2025-02-20 15:08:50 +00:00
Benjamin Cabé
9ca11f3e9c twister: allowlist build_info.yml and zephyr.dts
These files can be useful to troubleshoot a test that's failing,
and they're really small, too.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-02-20 15:08:50 +00:00
Michael Zimmermann
76b24fac09 twister: terminate_process: fix NoSuchProcess error
NOTE: Even though previous commits indicate, that this can only happen on
MacOS, that's actually not true. It happens on Linux as well.

The constructor of `psutil.Process` can throw an exception as well, so we
need to wrap the whole loop in another try, unfortunately.

Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
2025-02-20 06:04:31 +01:00
Michael Zimmermann
133e1278c2 twister: terminate_process: use contextlib.suppress
While it doesn't cause any issues, it's more consistent and makes future
commits which add handling for more exception types more readable.

Based on: 0df8240b49

Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
2025-02-20 06:04:31 +01:00
Grzegorz Swiderski
bb8b059e23 twister: Account for board & SoC extensions
Problem
-------

Board & SoC extensions are used to define out-of-tree board variants or
SoC qualifiers. When a board is extended, it has multiple directories
associated with it (each with its own `board.yml`), where twister should
be able to find additional platform files to support these qualifiers.
Currently, this doesn't work, because twister only traverses the primary
BOARD_DIR and ignores the rest.

The fix would've been trivial in the case of "legacy" platform files,
i.e. those of the form `<normalized_board_target>.yaml`, but it's less
straightforward for the newly introduced `twister.yaml` format.

A `twister.yaml` file contains platform configuration that can be shared
by multiple board targets and tweaked for specific targets by using the
top-level `variants` key. Normally, there is at most one `twister.yaml`
per board, but the file isn't necessarily unique to one board. Instead,
it's unique to one directory, which may define multiple boards (as is
the case with e.g. `boards/qemu/x86/`).

With extensions in the picture, the goal is to initialize platforms when
given multiple `twister.yaml` per board. The OOT files are expected to
only provide information about OOT board targets, without being able to
override in-tree targets (same principle as in the Zephyr build system).

Solution
--------

The `twister.yaml` handling is broken up into multiple passes - first
loading all the files, then splitting the `variants` keys apart from the
shared configuration, before constructing the Platform instances.

The purpose of the split is to treat the variant information as global,
instead of making unnecessary or faulty assumptions about locality.
Remember that the build system can derive board target names not only
from `board.yml`, but from `soc.yml` too. Considering that any board may
end up using an OOT-extended SoC (and hence multiple `soc.yml` files),
not every board target can be said to belong to some board dir.

Unlike the variant data, the remaining top-level config is still rooted
to the primary BOARD_DIR and inherited by the extension dirs from there.
This is quite intuitive in most imagined cases, but there is a caveat:
if a `twister.yaml` resides in an extension dir, then it is allowed to
have a top-level config of its own, but it will be silently ignored.
This is to support corner cases where, much like how a single board dir
can define multiple boards, a single board dir can also extend multiple
boards, or even do both. In those cases, the primary BOARD_DIR rule
should make it unambiguous which config belongs to which board, even if
it may seem counter-intuitive at first.

For concrete examples of what this means, please see the newly added
platform unit tests.

As part of these functional changes, a good chunk of logic is moved out
of `TestPlan.add_configurations()` into a new function in `platform.py`.
This is because recombining the top-level and variant configs requires
direct manipulation of the loaded YAML contents, which would be improper
to do outside of the module responsible for encapsulating this data.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2025-02-14 21:01:33 +01:00
Grzegorz Chwierut
df40aa5574 twister: shell harness with commands alongside the harness_config
Allow user to add shell commands in testcase/sample yaml file
alongside the harness_config like in the console harness.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-02-14 19:14:38 +00:00
Anas Nashif
7b8a5ed655 twister: platforms: fix parsing testing metadata
Fix parsing of testing metadata, global defaults were being ignore in
some cases.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-02-14 17:07:24 +01:00
Armin Kessler
20b1dddce5 scripts: twister: fix flash to esp32 using esp32 runner
Twister and pytest now flash to the device specified with board_id.

Signed-off-by: Armin Kessler <ake@espros.com>
2025-02-14 17:06:46 +01:00
Grzegorz Chwierut
cac967db9f twister: extend reason field in Twister reports
Extended the reason field in Twister report to include
more detailed information for 'Build failure' and
'CMake build failure'

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2025-02-13 16:42:23 +01:00
Anas Nashif
d80e3f7687 twister: harness: introduce shell harness
Introduce a new harness based on pytest that does basic shell command
handling. The harness is enabeld using:

harness: shell

and expects a file with parameters in the form:

test_shell_harness:
- command: "kernel version"
  expected: "Zephyr version .*"
- ...

Multiple commands and their expected output can be tested.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-02-08 08:13:46 +01:00
Jeremy Bettis
e88499cf8e twister: Check lcov exit codes
Don't ignore lcov exit codes, but instead log and return if one of the
lcov commands fails.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-02-08 00:31:54 +01:00
Jeremy Bettis
1385f02979 twister: Collect test names in lcov
When using --coverage-per-instance, collect the test names in lcov, and
add --show-details to the html report to display those test names.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-02-08 00:31:54 +01:00
Jeremy Bettis
b544e0a2b3 twister: Implement coverage file merging for lcov
Instead of capturing the coverage data twice with
--coverage-per-instance, just merge the lcov files in the aggregation
report.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-02-08 00:31:54 +01:00
Jeremy Bettis
6c7d518300 twister: Fix --disable-coverage-aggregation help text
There is no flag named --coverage-split, switch help to
--coverage-per-instance

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-02-08 00:31:54 +01:00