Commit graph

822 commits

Author SHA1 Message Date
Anas Nashif
52f9a129b5 twister: custom simulator needs an exec defined
custom simulator needs an executable defined, or else we will have tests
marked runnable with nothing to run them which would result in an
error/warning.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-11-07 11:06:10 -08:00
Dmitrii Golovanov
7e1cd18be4 twister: Fix NOTRUN status
Fix Twister TestCase statuses left not assigned ('NONE') in these 'NOTRUN'
situations:

 * a test suite has `integration platform` which is not available to run.

 * `--cmake-only` execution.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-11-06 09:52:25 -08:00
Lukasz Mrugala
4bb945300b scripts: twister: Python Version Guard
Twister shall now verify that the user does not
use an obsolete Python version. If user's Python
is deemed too old, it will raise a relevant error.
This check will also happen when running Twister
via west.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-11-04 17:24:24 -05:00
Lukasz Mrugala
9dc0af55e2 scripts: twister: Fix NOTRUN in test_only
When using the --build-only into --test-only
Twister setup, NOTRUN statuses were not properly rerun.

Now they are properly run again if runnable.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-10-31 14:18:17 -05:00
Armin Kessler
78f688a3e7 scripts: twister: Fix serial_py referenced before assignment
This fixes `serial_py referenced before assignment` if `flash_before`
is set.

Signed-off-by: Armin Kessler <ake@espros.com>
2024-10-31 14:16:36 -05:00
Armin Kessler
e31bf8bf50 scripts: twister: Add Espressif as manufacturer
Adds Espressif as manufacturer so that generation of HW-Map file is
possible

Signed-off-by: Armin Kessler <ake@espros.com>
2024-10-31 14:16:25 -05:00
Lukasz Mrugala
ff1857af55 scripts: twister: Enchance TestCase/Instance info and presentation
ExecutionCounter has been expanded and now hold i.a.
more information on the statuses of TestCases.
This information is now incorporated in relevant summaries
- runner.py and reports.py.
Layout of those was changed to present that
and previous information in a clear and concise way.

TestInstance execution counter now is more intuitive.
Instances filtered out before running are no longer included there.
Retries now properly reset the counter.

TestCases with None and other incorrect final statuses
are logged as errors, but do not
exit Twister with a nonzero exit code.
This is because None statuses, although incorrect,
are currently common.

Inconsistent spacing in ERROR and FAILED fixed.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>

scripts: Dmitri fix

Fix of a problem noticed by Dmitri

Removed unnecessary additional spaces when
printing FAILED and ERROR status.
Now TwisterStatus.get_color is used more.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-10-31 09:24:18 -05:00
Reto Schneider
743761d7d1 scripts: Fix CMake spelling
As per its creators, CMake is written with a capital "M".

The initial reason for this change is that I want Twister to print
"ERROR : CMake build failure" instead of "ERROR : Cmake build failure".

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-10-30 16:32:24 -05:00
Anas Nashif
2c43d7fe76 twister: oot soc: set soc_root using Path
Set soc_root using Path to avoid wrong generated path in the list of
soc_roots and other roots read from module.yml file

Fixes #80531

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-10-30 08:54:49 -05:00
Anas Nashif
b417524b66 twister: cleanup notrun tests with -M
Cleanup notrun tests with the -M option. This is used in the weekly
build and fails because devices will run out of space.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-10-28 15:58:23 -07:00
Torsten Rasmussen
536d34fa7a cmake: scripts: support board extension
Fixes: #69548

Support extending an existing board with new board variants.

This commit introduces the following changes to allow a board to be
extended out-of-tree.

The board yaml schema is extended to support an extend field which
will be used to identify the board to be extended.

A board 'plank' can be extended like this:
> board:
>   extend: plank
>   variants:
>     - name: ext
>       qualifier: soc1

For the rest of the build system this means that there is no longer a
single board directory.
The existing CMake variable BOARD_DIR is kept and reference the
directory which defines the board.
A new CMake variable BOARD_DIRECTORIES provides a list of all
directories which defines board targets for the board.
This means the directory which defines the board as well as all
directories that extends the board.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-26 17:14:06 +02:00
Anas Nashif
7066c40afc twister: also convert platform names from the hardwaremap
Convert platform names from the hardware map to full target names.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-10-26 13:41:55 +02:00
Anas Nashif
e90559f0da twister: fix platform filter when loading plan from file
if alias or shorthand name is provided on the command line, we need
convert this to complete target name for the filters to work.

Fixes #80332

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-10-26 13:41:55 +02:00
Anas Nashif
625246f241 twister: --device-testing always implies --filter runnable
--device-testing implies runnable tests, this was the case before the
rework and was missed in one spot, so instead do that directly in the
argument parser.

Fixes #80428

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-10-26 13:41:43 +02:00
Anas Nashif
dfc7860ab1 twister: rework board handling
We now use hwmv2 to list boards instead of relying on twister specific
config files.
One yaml files (twister.yaml for now) will have all the data needed for
all possible targets and variations of a board reusing most of the data
where possible and variations can override the top level data.

Twister keeps track of 'aliases' of boards and identifies that for
example native_sim is the same as native_sim/native, so either names
will be possible in both test yaml files or on the command line,
however, the reporting will always use the full name, so no there is no
confusion about what is being tested/built.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-10-22 18:31:09 -04:00
Mara Furland
7ac41a1b24 scripts: twister: set Python3_EXECUTABLE when calling cmake
When twister calls cmake, set Python3_EXECUTABLE so things work as expected
when using non-global python

Signed-off-by: Mara Furland <mara@fur.land>
2024-10-18 14:15:13 +02:00
Lukasz Mrugala
82548410bd scripts: twister: NOTRUN status
Adds a new NOTRUN status, which indicates
that a test was successfully built, but
not run on account of being not
runnable in given test instance.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-10-17 09:46:17 +02:00
Hake Huang
c759068c40 twister: runner: add extra_args supporting platform and soc
like extra_confs, add extr_args filterable by
soc:<arch>:<extra_args> or
platfrom:<platform name>: <extra_args>
simulation:<simulator name>: <extra_args>

which will only apply to given platform or arch

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2024-10-15 04:09:16 -04:00
Ioannis Damigos
7455bf50d2 twister: Fix reported testcase execution time
Testcase execution time doesn't match between twister.xml and
twister.log. Testcase execution time is the sum of the previous
testcases' execution time plus its own execution time in
twister.xml.

This patch fixes the issue above.

Signed-off-by: Ioannis Damigos <ioannis.damigos.uj@renesas.com>
2024-10-11 09:27:51 +02:00
Dmitrii Golovanov
2ddab56bfd scripts: twister: Fix trailing CR/LF at BinaryHandler logs
Fix trailing `\\r\\n` (escaped CR/LF) didn't cut off because of rstrip()
removed by #58338, so the CR/LF suffix was never found as the actual line
end was `\\r\\n\n`.

Add ANSI code sequence to `test_handlers` Twister unit test.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-09-27 14:30:26 +01:00
Benedikt Schmidt
fe3287a9ac scripts: dts: extract pickled EDT generation
Separate the pickled EDT generation from the C-Macro header
generation in gen_defines.py to have a more clear responsibility
of the scripts in the DTS parsing process.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2024-09-25 13:46:32 -05:00
Dmitrii Golovanov
4cc3134aa1 scripts: twister: Don't use match/case statements
Don't use match/case syntax to allow twister to run with
python3 versions < 3.10.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-09-21 12:24:05 +01:00
Lukasz Mrugala
558c74be04 scripts: twister: decouple debug and verbosity
Currently, debug logging in the console and verbosity
are tightly coupled - verbosity of level 2 and higher
enables logging at the debug level.

This change introduces a separate Twister flag
responsible for controlling the debug logging,
while leaving the rest of verbosity unchanged.

This allows for controlling the verbosity on
both logging levels, according to one's needs.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-09-20 11:07:48 +02:00
Piotr Kosycarz
ca770dbeb7 scripts: pylib: twister: twisterlib: prevent empty gcda files
In case of problem with parsing hex data from coverage dump,
do not create empty gcda file.
Such empty file will break gcovr parsing.

Signed-off-by: Piotr Kosycarz <piotr.kosycarz@nordicsemi.no>
2024-09-19 15:14:33 +02:00
Grzegorz Swiderski
eadc3d08c2 twister: Fix inconsistency among DT compat filters
This small change concerns the following filter functions:

   1. `dt_compat_enabled(C)`:
      There's a node with compatible `C` and status "okay".

   2. `dt_enabled_alias_with_parent_compat(A, C)`:
      There's a node with alias `A` and status "okay", and its parent
      has compatible `C`.

   3. `dt_label_with_parent_compat_enabled(L, C)`:
      There's a node with label `L`, and its parent has compatible `C`
      and status "okay".

All three functions involve checking whether some node or its parent has
a given compatible, but the way this has been checked is inconsistent.
Function (1) has done it with this Python conditional:

   compat in node.compats

while (2) and (3) have used:

   parent.matching_compat == compat

The first check works well with nodes that have multiple compatibles,
and it is more aligned with the notion of "has_compat" as seen in the
devicetree macros for C, CMake, and Kconfig.

Arguably, `matching_compat` shouldn't have been used here, because it is
actually a property of a node's binding, moreso than of the node itself.
In practice, it's usually equal to the first compatible for which edtlib
has found a binding, which at first glance is just more constrained than
the `node.compats` check. However, there also exist obscure cases where
the `node.compats` are empty, while the `node.matching_compat` is not.

For now, the three functions can use a combined check, to improve
consistency and utility while avoiding breakage:

   node.matching_compat == compat or compat in node.compats

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2024-09-18 19:56:06 +01:00
Grzegorz Swiderski
89bf698d90 twister: Remove dt_compat_enabled_with_alias filter
It has been deprecated since Zephyr v2.6.0.

The filter that replaced it - `dt_enabled_alias_with_parent_compat` -
had shared code with it, which can now be inlined into `ast_expr()` to
match the parser's overall code structure.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2024-09-18 19:56:06 +01:00
Lukasz Mrugala
418b1e0e21 scripts: twister: Add TestCase status printing
When at verbosity 1, we print out the status of TestInstances.
This makes it harder to notice changes at TestCase level,
which require perusing the logs.

This adds TestCase status and reason printing
if verbosity level is 2 or more.
Reason printing is suppressed if the reason is empty or None.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-09-17 15:04:04 -04:00
Wilfried Chauveau
6194159608 scripts: twister: handlers: Enable BinaryHandler to run sysbuilt tests
Running sysbuilt tests fails because of missing "run" target.

This adds the default domain context to the command.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2024-09-17 09:13:26 -05:00
Lukasz Mrugala
14a72b5158 scripts: Plug TwisterStatus type gaps
Some dict.get() calls did not use a TwisterStatus
as a default value, thus using a NoneType where
TwisterStatus should appear.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-09-16 20:18:09 +02:00
Anas Nashif
02bca9f6f6 twister: abort on unrecognised platforms
identify misnamed platforms and abort.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-09-16 10:07:51 +02:00
Hake Huang
7f63faa4f5 twister: hwmap: add script parameter support
for pre/post/post_flash script, add timeout as param

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2024-09-16 10:03:53 +02:00
Benjamin Cabé
df294e34e1 doc: sphinx-lint: fix bad usage of "default role"
Fixes bad usage of single backticks in lieu of double backticks for
rendering inline literals, or simple '*' for italics.

When appropriate, a better construct than double backticks has been
selected (ex. :file:, :kconfig:option:, :c:func:, ...), or proper :ref:
have been used if the original intention was to have a link.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-09-13 11:42:51 -05:00
Lukasz Mrugala
f78949b18c scripts: twister: Process KeyboardInterrupt Hardening
If you interrupt process() operation, we want Twister
to exit as gracefully as it can. This avoids the
UnboundLocalError that could appear e.g.
when interrupting the operation via SIGINT.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-09-13 13:42:05 +02:00
Anas Nashif
a053f1ae05 twister: add simics as supported simulator
Enable simics as a support simulation platform.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-09-12 14:49:21 +02:00
Pieter De Gendt
d2bae91803 scripts: pylib: twister: Pass testsuite name to cmake
Add a CMake argument with the current testsuite name.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-09-12 10:04:05 +02:00
Wilfried Chauveau
a55bb955af scripts: twister: add type hint to twister_main.py
Twister main expects an instance of TwisterEnv. Let's the linter know
about this.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2024-09-12 10:03:44 +02:00
Wilfried Chauveau
30dc833cab scripts: twister: Use args rather than injecting members
This changes how some arguments are set in the `Handler`s.
`options`, `generator_cmd` and `suite_name_check` are now passed as
arguments to the constructor rather than injected from an other module.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2024-09-12 10:03:44 +02:00
Wilfried Chauveau
6d9e5df401 scripts: twister: TwisterEnv is always used with an options parameter
Adjusting the type hints and code accordingly.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2024-09-12 10:03:44 +02:00
Wilfried Chauveau
5ad5af3713 scripts: twisterlib: Fix warning about deprecation of truthiness
Python 3.12 warns that

> Testing an element's truth value will raise an exception in future
> versions. Use specific 'len(elem)' or 'elem is not None' test instead.
>    if elem_ts := root.find('testsuite'):

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2024-09-12 10:03:44 +02:00
Wilfried Chauveau
28add0cd36 scripts: twister: check for deprecation notice for space-separated lists
Space separated lists are deprecated but this notice is not checked for.
extract_fields_from_arg_list also converts lists back to space-separated
lists causing a warning on get_scenario

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2024-09-12 10:03:44 +02:00
Maciej Perkowski
c743821f96 twister: fix dts path for module
Fixes twister with modules (TypeError for undefined dts_root)

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
2024-09-10 11:42:51 +02:00
Lukasz Mrugala
345eb8e94a scripts: twister: Elevate Status Error
Status errors previously logged an error, but didn't fail the running test.
This commit changes that
 and introduces a new StatusAttributeError to use there.

One test is modified so it follows proper status form.
One test for the new error has been added.

Status errors now will properly mark the Instance as ERROR
and not run TestCases as SKIP.
This necessitated some code layout changes in runner.py

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-09-09 09:28:37 +02:00
Pieter De Gendt
5a3c9c914a scripts: pylib: twister: Write version to testplan.json
The twister environment version is already set, write it to the
testplan.json file.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-09-06 11:31:57 -04:00
Piotr Kosycarz
f0bfaa4c19 scripts: pylib: twister: fix missing newlines at handler.log
Keep new lines at handler.log.

Signed-off-by: Piotr Kosycarz <piotr.kosycarz@nordicsemi.no>
2024-09-04 19:07:19 -04:00
Grzegorz Chwierut
392304706b twister: Pass device flash timeout to pytest-harness.
Pass flashing timeout to pytest-harness and use them

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-09-03 10:41:45 +02:00
Anas Nashif
d145db01b4 twister: setup soc/arch roots based on module settings
Get data for various roots from modules and do not hardcode location
when retrieving list of boards in testplan.

Fixes #71761

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-08-30 11:46:41 -04:00
Dmitrii Golovanov
87c1e2a40f twister: Group test plan reporting options
Re-arrange Twister command line options for test plan reporting
to a dedicated group with mutally-exclusive options to reflect
actual implementation and its dry-run execution mode.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-08-27 15:13:52 -04:00
Reto Schneider
7f1c3d1841 twister: runner: j-link: Fix parameter passing
To specify the serial number, JLink expects either one argument
('--dev-id=xxx') or two (e.g. '--dev-id' 'xxx'), but it can not deal
with a single one that is '--dev-id xxx'.

The problem has been introduced (or just made visible?) by commit
5ee4284320 (twister: runner: j-link: use
dev-id instead of SelectEmuBySN) in PR #76931.

How to reproduce:

1. Create a HW configuration map, e.g.:

```
$ cat zephyr-hw-map-nrf52840dk-1.yml
- connected: true
  id: '683517317'
  platform: nrf52840dk/nrf52840
  product: nRF52840 DK 1
  runner: jlink
  serial: /dev/ttyACM-nrf-dk-1
```

2. Run test `logging.dictionary` with Twister:

```
$ west twister --platform nrf52840dk/nrf52840 --device-testing \
  --hardware-map zephyr-hw-map-nrf52840dk-1.yml -s logging.dictionary
```

3. The build will fail, and the `twister_harness.log` contains:

```
10:21:24.375:DEBUG:twister_harness.device.factory: Get device type
  "hardware"
10:21:24.375:DEBUG:twister_harness.device.hardware_adapter: Opening
  serial connection for /dev/ttyACM-nrf-dk-1
10:21:24.376:DEBUG:twister_harness.device.hardware_adapter: Flashing
  device 683517317
10:21:24.376:DEBUG:twister_harness.device.hardware_adapter: Flashing
  command: <snip>/bin/west flash --skip-rebuild --build-dir
  twister-out/<snip>/tests/subsys/logging/dictionary/logging.dictionary
  --runner jlink '--dev-id 683517317'
10:21:24.590:ERROR:twister_harness.device.hardware_adapter: Could not
  flash device 683517317
10:21:24.592:DEBUG:twister_harness.device.hardware_adapter: Closed
  serial connection for /dev/ttyACM-nrf-dk-1
```
(note the '--dev-id 683517317' part)

4. Running the stated `west flash` command shows the following error
   message:

```
-- west flash: using runner jlink
FATAL ERROR: runner jlink received unknown arguments: ['--dev-id
  683517317']
```

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-08-26 17:07:40 +02:00
Grzegorz Chwierut
79ef0b6b10 twister: scripts: Split lines before processing
Readline method sometimes receives more lines in buffer.
Split them to avoid misinterpreting data in harness module.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-08-24 07:15:17 -04:00
Grzegorz Chwierut
fcf17dd17e twister: pytest: Change the order or pytest-args
Use pytest-args parameters provided in command line after
parameters taken from yaml file. The last occurence is
considered by argparse, so parameters from command line
will be used.

Fixes: #77319

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-08-23 15:50:19 +01:00