Commit graph

822 commits

Author SHA1 Message Date
Hake Huang
c268f15ae3 twister: testinstance: compare hwmap platform name with alias
in hwmap we may use short name, so need compare alias

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2025-02-06 07:44:55 +01:00
Dmitrii Golovanov
e9cb2ef86b twister: runner: Log trace on general exception
Log trace on general exception at ProjectBuilder to provide
more details on its cause.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2025-02-05 14:59:00 +01:00
Erwan Gouriou
b859423051 scripts: twister: Board id not needed for stm32cubeprog in BOOT-SERIAL
Flashing in BOOT-SERIAL mode with stm32cubeprogrammer doesn't support
using serial number.

Signed-off-by: Erwan Gouriou <erwan.gouriou@st.com>
2025-02-03 19:56:49 +01:00
Daniel DeGrasse
b9fa7b95fb scripts: twisterlib: write full output of from pytest to twister harness
When pytest is executed, it only writes logging messages to the twister
harness, and does not include information about any test assertion
failures. This information is printed to stdout, so simply write
the contents stdout to the harness log.

Remove the log file arguments previously passed to pytest, as these are
no longer needed.

Signed-off-by: Daniel DeGrasse <ddegrasse@tenstorrent.com>
2025-01-31 14:02:59 +01:00
Dmitrii Golovanov
53f7f6bcd1 twister: coverage: Merge gcovr reports
In `--coverage-per-instance` mode for 'gcovr' merge individual
coverage.json reports into the aggregate code coverage report
instead of processing .gcda data files again.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2025-01-30 18:29:08 +01:00
Dmitrii Golovanov
f93f82f160 twister: coverage: Data collection and reporting per-test instance
With this change, the coverage data (GCOV dump) is extracted from the
test log files after each of the test instance parallel execution,
instead of post processing all the logs at the end of the Twister run.

The new `--coverage-per-instance` mode extends Twister coverage operations
to report coverage statistics on each test instance execution individually
in addition to the default reporting mode which aggregates data to one
report with all the test instances in the current scope of the Twister run.
The split mode allows to identify precisely what amount of code coverage
each test suite provides and to analyze its contribution to the overall
test plan's coverage. Each test configuration's output directory will have
its own coverage report and data files, so the overall disk space and
the total execution time increase.

Another new `--disable-coverage-aggregation` option allows to execute
only the `--coverage-per-instance` mode when the aggregate coverage
report for the whole Twister run scope is not needed.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2025-01-30 18:29:08 +01:00
Dmitrii Golovanov
220f251241 twister: coverage: Group command line arguments
Group Twister code coverage command line arguments for better usability.
Add more details in descriptions.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2025-01-30 18:29:08 +01:00
David Leach
21aefb60ea twister: add details on a depends_on filter hit
In situations where a test won't be run because there is a gap
in the hardware support, add the gap information to the "reason"
field to aid in debugging test cases.

With this change, the reason field for the error in test case
will show the gap:

e.g. reason field now updated with gaps

"No hardware support {'usbd'} but is one of the integration platforms"

Signed-off-by: David Leach <david.leach@nxp.com>
2025-01-30 07:20:38 +01:00
Lukasz Mrugala
5834525649 scripts: twister: Fix too early error clearing
Actually using the error count before clearing it
would probably be more useful.
ExecutionCounter's error count was set to 0
before being used to lower the done count properly.
This should fix in-progress overcounting,
where Twister claimed to execute more tests than planned.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2025-01-28 23:43:00 +01:00
Dmitrii Golovanov
aa705089d3 twister: reporting: Add custom JSON encoder
Refactor Reporting to use custom ReportingJSONEncoder and encode
all pathlib.Path derived instances there which are possible
e.g. in 'environment.options' received from command line.

Fixes: #83823

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2025-01-23 19:22:40 +01:00
Thomas Günther
c2d011f366 twister: fix shell prompt detection with VT100 colors disabled
Device adapter strips all whitespace from output lines causing test
failures when matching default shell prompt "uart:~$ " with trailing
space. Update _handle_device_output to only strip line endings (\r\n)
while preserving whitespace required for prompt detection.

A testcase sample.pytest.shell.no_vt100 was added to verify prompt
matching works with CONFIG_SHELL_VT100_COLORS disabled.

Signed-off-by: Thomas Günther <thomas.guenther@limatica.com>
2025-01-17 16:35:33 +01:00
Stephanos Ioannidis
0e6f6cfb12 twister: Remove 'xtools' toolchain variant references
This commit removes all references to the `xtools` toolchain variant in the
twister scripts.

Note that the `xtools` toolchain variant has been deprecated since Zephyr
v3.3.0 and now removed.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2025-01-17 10:50:07 +01:00
Dmitrii Golovanov
b4d22420e9 twister: harness: recording: Allow multiple patterns
Extend Twister Harness 'recording' feature to allow multiple
regular expression patterns to extract different types of records
from test output.

Add 'merge' recording mode to collect all extracted data fields
into a single record object of the test instance.

Export to CSV file now takes all field names occurred in the collected
records, sort it alphabetically, and then use it for columns instead of
using only the first record's fields. This is done to address possible
situation when records have different set of fields.

Adjust Twister documentation and test suite to the above changes.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2025-01-16 22:38:51 +01:00
Sylvio Alves
ccfd1fa099 runner.py: update overflow list options
Adds custom memory section names used in
Espressif linker files.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-01-14 00:01:31 +01:00
Pieter De Gendt
0b67255b0f scripts: twister: Add CTest harness
Introduce a twister harness for CMake's CTest.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-01-10 04:12:42 +01:00
Anas Nashif
5769966d0f twister: deal with variants set on command line
not force host variant if environment is setting something different in
the case of posix arch.

Fixes #83766

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-01-09 22:12:26 -05:00
Anas Nashif
11e656bb6a twister: support testing multiple toolchain variants
Added integration_toolchains to allow building/testing with multiple
toolchains available in the environment.

This changes the output structure and adds another level in the path
under twister_out signifying the toolchain used. The toolchain used
(variant) is also part of the json output now.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-01-08 12:58:59 +01:00
Dmitrii Golovanov
05c167e0b8 twister: ztest: Optimize logging and comment special cases
Add more comments and optimize logging on Ztest tracing.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2025-01-08 06:07:35 +01:00
Hake Huang
15edce26e4 twister: add dt_node_prop_enabled support
using "dt_node_prop_enabled" to filter out supported platforms
1. check node existing.
2. check prop in node.
3. check the prop is True.

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2024-12-20 18:30:43 +01:00
Dmitrii Golovanov
26e0aa268f twister: handlers: Pass harness reason to instance
Pass a test failure reason text from harness to the instance
to convey more details on the failure.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-12-17 11:37:40 +00:00
Dmitrii Golovanov
ea3f105f82 twister: binaryhandler: Fix None status on test fail
Set missing TestCase statuses when a test under the BinaryHandler failed
(crashed), so remaining 'STARTED' and 'NONE' are now 'BLOCK' instead.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-12-17 11:37:40 +00:00
Benjamin Cabé
9d4c027993 twister: reports: use Path instead of PosixPath
Directly instantiating a PosixPath is not allowed on Windows, use
Path instead.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-12-16 13:08:22 +01:00
Dmitrii Golovanov
2c5195c814 twister: reports: Pretty print XML reports
Pretty print XML reports with tab identation on levels for better
readability and ease text diff there as well.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-12-16 08:35:34 +01:00
Dmitrii Golovanov
c5c4165f68 twister: reports: Long testcase.classname XML properties
The testcase.classname properties in `twister_report.xml` and
`twister_suite_report.xml` now contain the full testsuite name
(without its path prefix) instead of just two its dot-separated
leftmost components. This way `twister_report.xml` testsuite container
has no duplicate testcase elements with the same `classname` and `name`
properties executing with --no-detailed-test-id for a project with same
testcase names in its 'sibling' suites, for example`tests/kernel/sleep`.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-12-16 08:35:34 +01:00
Dmitrii Golovanov
b69a8d1deb twister: ztest: short test case names on --no-detailed-test-id
Extend `--no-detailed-test-id` command line option: in addition to its
current behavior to exclude from a test Suite name its configuration path
prefix, also don't prefix each Ztest Case name with its Scenario name.

For example: 'kernel.common.timing' Scenario name, the same Suite name,
and 'sleep.usleep' test Case (where 'sleep' is its Ztest suite name
and 'usleep' is Ztest test name.

This way both TestSuite and TestCase names follow the same principle
having no parent object name prefix.

There is no information loss in Twister reports with this naming:
TestSuite is a container object for its TestCases, whereas TestSuite
has its configuration path as a property.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2024-12-16 08:35:34 +01:00
Anas Nashif
82f7857a94 twister: debug: change skipped -> filtered
Change debug message to say filtered instead of skipped.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-12-13 09:12:59 +01:00
Anas Nashif
63caa67f52 twister: plan: unify messaging, testsuite vs testcase
Many places use test case instead of testsuite or testsuite scenario.
Unify to avoid confusion.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-12-13 09:12:59 +01:00
Marcin Niestroj
fc73447acb scripts: pytest: log msec with leading zeros
Milliseconds are logged as is, without leading zeros. This means that
following log content is produced, which is not aligned by columns:

  12:54:27.972:INFO:root: Test message
  12:54:27.992:INFO:root: Test message
  12:54:28.12:INFO:root: Test message
  12:54:28.32:INFO:root: Test message
  12:54:28.52:INFO:root: Test message
  12:54:28.73:INFO:root: Test message
  12:54:28.93:INFO:root: Test message
  12:54:28.113:INFO:root: Test message
  12:54:28.133:INFO:root: Test message

Change milliseconds logging to include leading zeroes. This allows to print
nicely aligned log messages:

  12:54:27.972:INFO:root: Test message
  12:54:27.992:INFO:root: Test message
  12:54:28.012:INFO:root: Test message
  12:54:28.032:INFO:root: Test message
  12:54:28.052:INFO:root: Test message
  12:54:28.073:INFO:root: Test message
  12:54:28.093:INFO:root: Test message
  12:54:28.113:INFO:root: Test message
  12:54:28.133:INFO:root: Test message

Additionally it is much easier to configure programs simplifying
timestamped log browsing (like in logview-mode for Emacs), as it is more
standard and does not require custom regex matching.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-12-13 03:03:07 +01:00
Grzegorz Chwierut
c4d884cc65 twister: Pass extra test args to pytest
Pass additional args to test binary. Twister
passes it only for native_sim.
Fixes #82463

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-12-12 10:20:55 -05:00
Anas Nashif
072a430cea twister: handler: open files using with statement
Use with statement to open stdout/stderr and resolve current warning
when running twister:

	ResourceWarning: unclosed file....

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-12-09 15:10:19 +01:00
Anas Nashif
30ad1901f3 twister: testplan: do not verify_platforms_existence again
We already sanitize those lists very early on, no need to call this
check again on the same lists.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-12-09 09:49:46 +01:00
Anas Nashif
c0dbcdab10 twister: error on invalid platforms
In case of unknown platforms in filters such as plaform_allow,
integration_plaforms or platform_exclude, report an error and exit.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-12-09 09:49:46 +01:00
Artur Dobrynin
f84dadde59 scripts: twister: adding default cmake/config arguments for bsim
Bsim tests need some addtional kconfig arguments enabled by default.

Signed-off-by: Artur Dobrynin <artur.dobrynin@nordicsemi.no>
2024-12-07 02:03:31 +01:00
Thomas Günther
20409ca2cc doc: add get_filtered_output method documentation
Add documentation for the get_filtered_output method in both the Python
implementation and the Integration with pytest chapter. The method is used
to filter command outputs by removing prompts and log messages, making it
easier to process shell command results.

Signed-off-by: Thomas Günther <thomas.guenther@limatica.com>

removed traling whitespace
2024-12-05 20:00:47 -05:00
Hake Huang
6996436ed6 tests: twister: add quit-on-failure option
in CI, we may need to quit if there is any failure
to save time, so add this --quit-on-failure so that
any failure will quit the test.

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2024-12-05 22:10:28 +01:00
Armin Kessler
443afd421a scripts: twister: add esp32 runner
Adds support for the `esp32` runner when using the hardware-map feature.

Signed-off-by: Armin Kessler <ake@espros.com>
2024-12-05 15:17:18 +01:00
Dat Nguyen Duy
1069f57f5c twister: fix issue twister with --device-testing on Windows
There is an incorrect logic that causes twister with
--device-testing to skip all tests on Windows. Correct
the logical condition.

Signed-off-by: Dat Nguyen Duy <dat.nguyenduy@nxp.com>
2024-12-04 18:19:23 -05:00
Anas Nashif
e873d503a9 twister: testplan: do not error on missing or unsatisfied env
bsim requires a special setup for it to be usuable and run by twister.
If this environment is not available, we should not error when the
platform is an integration platform.

Most developers and users of twister will not have the babblesim setup
and reporting errors is misleading and confusing. So if such env. is not
available, just filter as usual and do not error.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-12-04 14:37:58 -05:00
Gerard Marull-Paretas
714e193340 scripts: twister: drop support for space-separated lists
Support for space-separated lists was deprecated a long time ago
a91620f5bb so it is time to remove
support for them.

Any project that has not migrated can still use
`scripts/utils/twister_to_list.py` to automatically migrate twister
files.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2024-12-04 14:14:53 -05:00
Grzegorz Chwierut
5cd8ef8529 twister: allow using empty board revision
Allow providing an empty board revision. Fixes issue
found in PR #81857

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
2024-12-04 14:14:22 -05:00
Hake Huang
afba775304 twister: test: update test case
update test cases for twister
1. test_errors.py add protection.
2. test_handlers.py change call to status
3. test_testsuite.py change call to status

The log traces for TwisterException objects only.
And the stack trace output follow the same rules for all exceptions,
but StatusAttributeError with its dedicated handlers.

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2024-12-04 02:03:33 +01:00
Hake Huang
798768e40d twister: add trace print in exception
add trace print when exception happens

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2024-12-04 02:03:33 +01:00
Anas Nashif
440659878d twister: do not create overlays/run_id for filtered cases
Avoid creating directories and files for instances that are filtered.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-12-04 02:02:52 +01:00
Anas Nashif
00f620870e twister: config: increase min_ram to 16k
Increase default to 16k, this can be overidden in the test configuration
where needed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-11-30 18:33:10 +01:00
Fabio Baltieri
092e559366 twister: add an explicit path before import Domains
This is line is breaking in some CI setups since the recent ruff fixup
with:

ModuleNotFoundError: No module named 'domains'

Try and fixit by explicitly adding the path before the include, all
other instances have it already.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-11-30 10:33:29 +00:00
Lukasz Mrugala
63dd36993c scripts: Remove useless PyLint suppression
Consider using with suppression became
obsolte and should be removed.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-11-29 15:29:31 +01:00
Lukasz Mrugala
89d4aa8559 scripts: Fix twisterlib for ruff - E501
This fixes ruff linting error E501,
indicating overlong lines.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-11-29 15:29:31 +01:00
Lukasz Mrugala
bbd5d16a7a scripts: Fix twisterlib for ruff - UP007
This fixes ruff linting error UP007,
where one would use Optional or Union
instead of X | Y notation.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-11-29 15:29:31 +01:00
Lukasz Mrugala
9b4397a764 scripts: Fix twisterlib for ruff - UP030, UP031, UP032
Fixes ruff linting errors UP030, UP031, UP032,
which make you use format specifiers (fstrings)
instead of printf formatting or str.format().

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-11-29 15:29:31 +01:00
Lukasz Mrugala
7746a97e31 scripts: Fix twisterlib for ruff - F541
This fixes ruff linting error F541,
where an fstring is used when a normal
string would suffice.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2024-11-29 15:29:31 +01:00