Commit graph

822 commits

Author SHA1 Message Date
Yuval Peress
bfb893a0c5 gtest: Add support for gtest 1.15.0
The gtest 1.15 has slightly different output from the original one that
was used to set up the harness. With this change we support both output
formats.

Fixes #72318

Signed-off-by: Yuval Peress <peress@google.com>
2024-08-23 09:54:41 +02:00
Michael Arnold
5ee4284320 twister: runner: j-link: use dev-id instead of SelectEmuBySN
The serial number for debugger selection over USB
can be selected with the dev-id. This change
reflects also more the workflow of west flash
with J-Link.
The usage of SelectEmuBySN breaks the support for
J-Link over IP with twister.

Signed-off-by: Michael Arnold <marnold@baumer.com>
2024-08-20 14:52:48 -04:00
Arkadiusz Cholewinski
150a7cd810 twister: Add Nuvoton to manufacturer
Expand manufacturer table in hardwarempa.py to include Nuvoton.

Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
2024-08-19 17:22:42 -04:00
Grzegorz Chwierut
7cca59c81a twister: pytest: Allow using pytest-args from command file and yaml
Extend pytest-args from configuration yaml file with args
from command line instead of overwriting.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-08-19 10:00:47 -04:00
Dmitrii Golovanov
b8bed5b077 twister: Fix TypeError at get_installed_packages
Fix confusing `TypeError: 'type' object is not subscriptable`
at _get_installed_packages() if twister runs on python version < 3.9

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-08-16 08:49:33 -04:00
Dmitrii Golovanov
a4cb802d54 twister: DeviceHandler improve DUT selection
Improve DUT selection at DeviceHandler: for each DUT it counts
how many test instances have been failed on it during the current
twister execution, so the next available DUT will be chosen
ordering the eligible DUTs by less failures occured so far.

The new selection mechanism should increase chances to retry failed
tests on different DUTs, for instance to resolve ploblems when some
DUTs have connectivity or HW issues slowing down test plan execution,
or even block the execution when only one test suite runs whereas
the same first DUT candidate in the list is not working and others
were not chosen.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-08-15 10:15:41 +01:00
Dmitrii Golovanov
ab9cb5f8b2 twister: PyTest plugin's DUT release sequence change
Change Twister PyTest plugin's test finalizing sequence to release
the DUT it is used as the very last operation, after the Test Instance
status becomes fully updated from the execution results.

This also fix a race condition possible when pytest plugin releases
the DUT and it becomes acquired by another test while the current test
is not yet finalized completely.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-08-15 10:15:41 +01:00
Dmitrii Golovanov
c5e8ac7cbf twister: DeviceHandler count test failures on DUTs
Twister DeviceHandler - add test failure counter for how many
test instances have been failed on each DUT (Device Under Test)
when it executes the current test plan.
Output DUT falure counter summary at the end of Twister run.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-08-15 10:15:41 +01:00
Dmitrii Golovanov
bd6e1a2da4 twister: DeviceHandler make DUT counter increment atomic
Twister DeviceHandler - make DUT use counter increment
operation atomic.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-08-15 10:15:41 +01:00
Dmitrii Golovanov
21f4ec8b14 twister: Fix DeviceHandler exit on exception at 'flash before'
Fix Twister DeviceHandler exit on SerialException when
it connects to the serial device in 'flash before' mode.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-08-15 10:15:41 +01:00
Dmitrii Golovanov
44852d05ec twister: Improve DUT release at DeviceHandler
Several improvements at Twister DeviceHandler when it releases
current DUT (Device Under Test):

 - release the exact DUT which is used for the test instance
   instead of all configured DUTs which happened to have
   the same serial device configured.

 - Twister PyTtest harness plugin adjustment to the above.

 - additional debug logging to track DUT waiting/retain/release.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-08-15 10:15:41 +01:00
Grzegorz Chwierut
913434e83d twister: pytest: Capture and log error messages from subprocess
Updated the Pytest-Harness methods to capture and log error messages from
the subprocess, when pytest command fails.
Ensured that error messages are logged with `--inline-log` option
and placed in twister log reports.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-08-14 12:33:27 -04:00
Ederson de Souza
1893a12d37 twister/pytest: Inform pytest which platform a test is being done for
While the option to inform pytest about which platform a test is for
(platform being the board, such as mps2/an385) is available, it wasn't
being used. This patch fixes that, by building a pytest command which
includes the platform.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2024-08-14 09:15:40 -04:00
Ederson de Souza
55613d035b twister/pytest: Add unlaunched_dut fixture
Add a new fixture, `unlaunched_dut`, which is basically the `dut`
one, but without launching the device - thus also not building the
application. It is useful for tests who need a finer control of
the building of the application, before the dut can be launched
to run it.

It will be used on a future patch, which will use it to enable LLEXT EDK
tests.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2024-08-14 09:15:40 -04:00
Dmitrii Golovanov
0728358422 twister: Fix reporting filter status type mismatch
Fix after #71401 merge at Twister Reporting:
 * filter status value type mismatch;
 * tesplan.json generation incorrect error logs.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-08-14 09:14:19 -04:00
Lukasz Mrugala
306dba1d91 scripts: twister: Elevate status errors
Incorrect status assignments were previously just warnings in logs.
Now they are elevated to errors.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-08-12 19:23:07 -04:00
Lukasz Mrugala
f429b33d63 scripts: twister: Bring 3.7 changes into the new status system
Some 3.7 changes still used string statuses.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-08-12 19:23:07 -04:00
Lukasz Mrugala
212f48c146 scripts: twister: Unify Twister Statuses
Various different Statuses were joined into a single class,
TwisterStatus. This change anticipates further streamlining
of the Twister's approach to Status.

Code guarding Twister's Properties was shortened to a
value check only.

QEMUOutputStatus was left separate, as doubts were cast
whether it should remain a status. Leaving it separate makes
its removal easier.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-08-12 19:23:07 -04:00
Lukasz Mrugala
6f452e81f7 scripts: twister: Remove unused statuses
TestInstanceStatus of TIMEOUT and FLASH were never really used.
They were checked for, but never assigned.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-08-12 19:23:07 -04:00
Lukasz Mrugala
5c6c44a247 scripts: twister: Isolate statuses into a separate class
Now statuses are not just a str that can be easily mistyped
or assigned wrong. Now they are an Enum.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-08-12 19:23:07 -04:00
Lukasz Fundakowski
857adb28e3 twister: Fix failing tests on CI with Python 3.12
This change is removing some deprecation warnings
which for some reason causing failing tests with
Python 3.12 on CI #76877.

Also, it fixes warnings from pytest like:
PytestCollectionWarning: cannot collect test class 'TestPlan'
because it has a __init__ constructor
(from: scripts/tests/twister/test_testplan.py)

Signed-off-by: Lukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
2024-08-09 09:27:59 -04:00
Jordan Yates
bdcd5d00d0 scripts: twister: twisterlib: cwd relative path
When presenting an example of how to run a failing test case with
`west build`, provide the source dir path relative to the current
working directory, not the zephyr root directory.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-08-05 18:41:14 -04:00
Grzegorz Chwierut
eff7f4d56a twister: pytest: Use configured shell prompt in pytest-harness
Read CONFIG_SHELL_PROMPT_UART from config file and use them
in shell fixture in pytest-harness package.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-08-05 16:29:13 +02:00
Grzegorz Chwierut
8e7cda75cc twister: pytest: Move helper methods to pyteste-harness package
Moved helper methods from tests/boot/with_mcumgr to pytest-harness
package. It can be reused by other tests.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-08-05 16:29:13 +02:00
Grzegorz Chwierut
663786d0a4 twister: Skip scanning non-ztest tests in Twister
Twister scans C-files to find testcases that are implemented
using ZTest framework. Also runs scanning of Elf files
after building. Skip scanning files if it is not required.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-08-02 03:31:24 -04:00
Daniel Leung
b2f3d801b4 twister: pytest: use test timeout as the default base timeout
The default base timeout for pytest is statically set by
the TwisterHarnessConfig class to be 60 seconds. However,
sometimes it takes longer than 60s before the app starts
to run, especially on emulator/simulator where it takes
quite some time to start. So pass the test timeout as
the base timeout via pytest command line argument.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-07-27 15:18:01 +03:00
Jordan Yates
af0cbb19c0 scripts: twisterlib: coverage: ignore __ASSERT branches
Disable branch coverage for the `__ASSERT` family of macros. Covering
all of the assertion branches by definition means triggering the
assertion, which can be either challenging or impossible to exercise,
and in either case results in the immediate termination of the test.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-07-08 20:41:31 -04:00
Jordan Yates
53bd9ead64 scripts: twisterlib: coverage: fix multiple branch excludes
Multiple values for `--exclude-branches-by-pattern` will result in only
the last value taking effect. Resolve this by merging all the provided
regex patterns into a single pattern with the `|` operator.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-07-08 20:41:31 -04:00
Hake Huang
e0f772e880 test: pytest: add linkserver support in pytest
pytest supporting add linkserver for nxp platforms

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2024-07-08 09:23:48 +02:00
Yuval Peress
1b51740fa3 twister: Fix gTest harness
The gTest harness asssumed that the lines end with the test name, but
some gTest implementations include the test duration in the line. Update
both the tests and regex to allow this and also avoid capturing
characters into the `test_name` that cannot be valid test name chars.

Fixes #72318

Signed-off-by: Yuval Peress <peress@google.com>
2024-07-03 08:52:13 +02:00
Gerson Fernando Budke
768b8bbca3 scripts: west robot & simulation: Fix OOT
The current version of scipts do not consider OOT boards use cases and
the tests with robot now are strict to only one robot file, which is
not realistic for real environment. This address those issues and allow
multiple testsuits at command line and lists at tests entries. It add
another test parameter to allow configure robotframework options.

Fixes: #74563

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2024-07-01 16:10:35 -04:00
Maciej Perkowski
a033ba65d2 twister: Add warning to the "-footprint-from-buildlog" flag
The flag won't work with sysbuild since there is no way to
reliably tell to a parser which data came from which image.

fixes: #74092

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
2024-06-28 21:12:57 -04:00
Jordan Yates
07870934e3 everywhere: replace double words
Treewide search and replace on a range of double word combinations:
    * `the the`
    * `to to`
    * `if if`
    * `that that`
    * `on on`
    * `is is`
    * `from from`

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-22 05:40:22 -04:00
Marcin Niestroj
efcc0ed27f scripts: pytest: execute 'zephyr.exe' in application build directory cwd
Execute 'zephyr.exe' in application build directory as 'current working
directory' (cwd). This makes sure that native_sim specific drivers (like
flash simulator with file backend in 'flash.bin') are using unique context
for external resources with relative paths.

This fixes executing native_sim tests in twister with flash simulator.
Previously a shared 'flash.bin' was used for all executed 'zephyr.exe'
processes in twister. After this patch a unique 'flash.bin' file is used
for each tested sample, since those 'flash.bin' is placed in application
build directory instead of twister root directory.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-06-18 15:53:00 +02:00
Dmitrii Golovanov
1ccd972563 twister: Fix on output directory reaching backup limit
Stop Twister if there are too many backup copies of the output
directory already.
Before this fix, Twister silently kept artifacts from the last run,
unless `--clobber-output` was explicitly given.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-06-17 12:08:20 -04:00
Jordan Yates
25fa41c209 scripts: twisterlib: coverage: handle multiple gcov dumps
Extend the coverage tool to handle applications that generate multiple
gcov dumps in a single execution. This can happen when the application
calls `sys_reboot`.

Handling multiple dumps enables coverage testing of exception handlers.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-15 04:39:53 -04:00
Dmitrii Golovanov
68bb87bd50 twister: pytest: Log output passthrough
Pass Twister pytest plugin's log output, as well as output from
a test image running with pytest, up to Twister log irregardless
of the current verbosity level set at Twister.
This allows to collect full test output and also ensures that
recording data embedded in the test log is passed to the Twister
pytest harness for export.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-06-14 09:41:52 -04:00
Dmitrii Golovanov
35e313f9e5 twister: recording: Allow JSON data fields
Extend Twister Harness recording feature to allow selected data fields,
extracted from the log by a regular expression, to be parsed into JSON
objects and eventually reported in `twister.json` as `recording` list
property of the test suite.

With this extension, log records can convey layered data structures
passed from a test image as summary results, traces, statistics, etc.

This extension also allows flexible recording structure: a test image
can output different types of data records incapsulated into a fixed
set of fields, so `recording.csv` file columns are respected, whereas
some of the columns keep strings with json-encoded semi-structured data.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-06-14 09:41:52 -04:00
Maciej Perkowski
da1066fa4b twister: Add sysbuild boolean to platform definitions
More complex platforms require sysbuild to use always, even for
such "simple" samples like hello_world. Such platforms can have
`sysbuild: true` entry in their board_name.yaml used by twister.
Using such entry will tell twister, that sysbuild must always be used
on a given platform.
Twister is aligned to have information about need of sysbuild at
instance (platform + suite) level (was only at suite level before).
Instance.sysbuild is true whenever a test suite or a platform requires
sysbuild.
Twister pytest unit tests are aligned with changes.

Signed-off-by: Maciej Perkowski <Maciej.Perkowski@nordicsemi.no>
2024-06-13 16:46:25 -04:00
Juha Kuikka
14c2be6d9d twister: Capture qemu launch stdout and stderr
Currently we launch qemu (well, "ninja run" usually) using Popen and
request stdout and stderr to be redirected into a pipe. However we never
read that pipe so the information is not captured.

Instead log directly into files that can be inspected after a failed
to to find out why qemu run failed.

Note that this is really only useful in cases where qemu either fails to
launch or crashes.

Regular test data is still handled via the qemu fifo.

Signed-off-by: Juha Kuikka <juha.kuikka@gmail.com>
2024-06-13 08:04:07 -04:00
Anas Nashif
eaafd30b56 twister: cleanup how we capture results of handlers
we use reason for a failure to indicate state and then set the status
later and reason for the failure, in case of the failure is taken from
the handler status. Clean this up by setting status and reason coming
from the handler very early, so we do not have to go through replacing
meaning later.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-06-12 21:12:13 -04:00
Lothar Felten
3334b55207 scripts: twister: help - change help text to match hwmv2
fix the twister help text, boards are now organized as:
boards/<vendor>/<board_name>

Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
2024-06-11 16:18:15 +02:00
Jordan Yates
b1290cb86c scripts: twisterlib: filter coverage information
When dumping logs from the `--inline-logs` option, remove any coverage
information that may be contained in those logs. Coverage dumps are
unrelated to any test failures and make it harder to find the failing
test information. In extreme cases the relevant information is lost due
to terminal scrollback limits.

If the raw dump information is required, it is still present in the
original `handler.log` file.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-11 16:37:31 +03:00
Dmitrii Golovanov
eebbd5c411 twister: footprint: Add optional detailed JSON report on symbols
New Twister option `--footprint-report` is introduced to collect and
write detailed memory footprint results for symbols as an additional
JSON file. By default, the new option is disabled.

The new option implies and extends `--create-rom-ram-report`, so there
are three choices: 'ROM', 'RAM', and 'all' to select what memory area
symbols to report in `twister_footprint.json`.
In case of the custom report name, or per-platform report, it is always
composed with the rightmost '_footprint.json' suffix.

The memory footprint report has similar structure as `twister.json`
and compelements it having reduced set of test suite properties:
- instead of `testcases` it contains `footprint` object with
  `rom.json` and `ram.json` artifacts embedded there;
- other properites are limited to represent only the essential test
  suite context, thus to allow further data processing consistently
  and independently from the `twister.json`.
- 'filtered' test instances are not included into the footprint report.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-06-06 20:08:11 -04:00
Dmitrii Golovanov
a425db20b1 twister: Add test suite filtering on twister.json compose
When Twister composes resulting twister.json reports, add optional
filtering by a test instance resulting status and/or its individual
properties to be allowed/denied on output to the JSON file.
This internal feature is introduced to facilitate JSON reports with
a custom data schema.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-06-06 20:08:11 -04:00
Henrik Brix Andersen
331b404185 twister: hardwaremap: avoid exceptions when generating hardware map
Avoid exceptions when generating persistent hardware maps on Linux with no
devices available.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-06-06 07:50:51 -04:00
Dmitrii Golovanov
4dc2a98d0c twister: Ensure serial-pty process termination
Make sure Twster DeviceHandler serial-pty process is terminated
with all its remaining children to avoid Twister hanging on it
infinitely.
The reolved issue occurs sometimes, for example when serial-pty
script is used for serial port tunneling over network.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-06-05 17:38:42 -05:00
Lukasz Mrugala
5f4d330db6 scripts: twister: Do not report filtered test instances by default
Filtered testcases are removed by default from Twister tests.
Older functionality is preserved via a new Twister flag:
--report-filtered.
Old tests were adjusted and a new test for that flag added.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-06-05 01:38:47 -07:00
Henrik Brix Andersen
3eb3c33096 scripts: twister: allow fixtures to contain extra configuration
Allow twister fixtures to contain extra information, which can be used for
test suite configuration. The extra information can be appended to existing
fixtures separated by a colon (i.e. <fixture>:<configuration>).

This is especially useful for the pytest harness, where a fixture of a
given type may need to refer to an instance of a particular piece of host
hardware needed by the pytest suite (e.g. a network interface, a UART, or a
CAN interface connected to the device under test).

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-06-04 21:27:35 -05:00
Henrik Brix Andersen
a7d55cfa13 twister: harness: pytest: list available fixtures in device config
Pass the list of supported twister fixtures for a given platform to pytest
via DeviceConfig. This allows for the pytest suites to use knowledge of the
fixtures for test suite configuration.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-06-04 21:27:35 -05:00