2020-12-07 17:46:56 +01:00
.. _twister_script:
2019-02-20 16:04:14 +01:00
2020-12-07 17:46:56 +01:00
Test Runner (Twister)
#####################
2017-06-17 00:35:39 +02:00
This script scans for the set of unit test applications in the git repository
2017-10-17 23:04:56 +02:00
and attempts to execute them. By default, it tries to build each test
case on boards marked as default in the board definition file.
2017-06-17 00:35:39 +02:00
2017-10-17 23:04:56 +02:00
The default options will build the majority of the tests on a defined set of
2019-09-22 16:41:44 +02:00
boards and will run in an emulated environment if available for the
2017-06-17 00:35:39 +02:00
architecture or configuration being tested.
2020-12-07 17:46:56 +01:00
In normal use, twister runs a limited set of kernel tests (inside
an emulator). Because of its limited test execution coverage, twister
2017-10-17 23:04:56 +02:00
cannot guarantee local changes will succeed in the full build
environment, but it does sufficient testing by building samples and
tests for different boards and different configurations to help keep the
2019-09-22 16:41:44 +02:00
complete code tree buildable.
2017-06-17 00:35:39 +02:00
2020-12-07 17:46:56 +01:00
When using (at least) one `` -v `` option, twister's console output
2023-11-10 12:29:28 +01:00
shows for every test how the test is run (qemu, native_sim, etc.) or
2020-12-07 17:46:56 +01:00
whether the binary was just built. There are a few reasons why twister
2019-04-08 23:02:34 +02:00
only builds a test and doesn't run it:
- The test is marked as `` build_only: true `` in its `` .yaml ``
configuration file.
- The test configuration has defined a `` harness `` but you don't have
it or haven't set it up.
2019-09-22 16:41:44 +02:00
- The target device is not connected and not available for flashing
2020-12-07 17:46:56 +01:00
- You or some higher level automation invoked twister with
2019-04-08 23:02:34 +02:00
`` --build-only `` .
2017-06-17 00:35:39 +02:00
To run the script in the local tree, follow the steps below:
2022-08-02 05:11:55 +02:00
.. tabs ::
.. group-tab :: Linux
.. code-block :: bash
$ source zephyr-env.sh
$ ./scripts/twister
.. group-tab :: Windows
.. code-block :: bat
zephyr-env.cmd
python .\scripts\twister
2017-06-17 00:35:39 +02:00
2021-10-06 00:34:54 +02:00
If you have a system with a large number of cores and plenty of free storage space,
you can build and run all possible tests using the following options:
2017-06-17 00:35:39 +02:00
2022-08-02 05:11:55 +02:00
.. tabs ::
.. group-tab :: Linux
.. code-block :: bash
2017-06-17 00:35:39 +02:00
2022-08-02 05:11:55 +02:00
$ ./scripts/twister --all --enable-slow
.. group-tab :: Windows
.. code-block :: bat
python .\scripts\twister --all --enable-slow
2017-06-17 00:35:39 +02:00
2017-10-17 23:04:56 +02:00
This will build for all available boards and run all applicable tests in
2019-09-22 16:41:44 +02:00
a simulated (for example QEMU) environment.
2022-07-28 17:25:39 +02:00
If you want to run tests on one or more specific platforms, you can use
the `` --platform `` option, it is a platform filter for testing, with this
option, test suites will only be built/run on the platforms specified.
This option also supports different revisions of one same board,
you can use `` --platform board@revision `` to test on a specific revision.
2022-08-02 05:11:55 +02:00
The list of command line options supported by twister can be viewed using:
.. tabs ::
.. group-tab :: Linux
2019-09-22 16:41:44 +02:00
2022-08-02 05:11:55 +02:00
.. code-block :: bash
2019-09-22 16:41:44 +02:00
2022-08-02 05:11:55 +02:00
$ ./scripts/twister --help
.. group-tab :: Windows
.. code-block :: bat
python .\scripts\twister --help
2017-06-17 00:35:39 +02:00
2018-05-24 14:58:08 +02:00
2017-06-17 00:35:39 +02:00
Board Configuration
***** ***** ***** *** *
To build tests for a specific board and to execute some of the tests on real
hardware or in an emulation environment such as QEMU a board configuration file
is required which is generic enough to be used for other tasks that require a
board inventory with details about the board and its configuration that is only
available during build time otherwise.
The board metadata file is located in the board directory and is structured
using the YAML markup language. The example below shows a board with a data
required for best test coverage for this specific board:
.. code-block :: yaml
2019-09-22 16:41:44 +02:00
identifier: frdm_k64f
name: NXP FRDM-K64F
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
supported:
- arduino_gpio
- arduino_i2c
- netif:eth
- adc
- i2c
- nvs
- spi
- gpio
- usb_device
- watchdog
- can
- pwm
testing:
default: true
2017-06-17 00:35:39 +02:00
identifier:
A string that matches how the board is defined in the build system. This same
2019-06-13 21:59:12 +02:00
string is used when building, for example when calling `` west build `` or
2023-10-18 03:46:03 +02:00
`` cmake `` :
.. code-block :: console
2017-06-17 00:35:39 +02:00
2019-06-13 21:59:12 +02:00
# with west
2020-05-07 18:02:48 +02:00
west build -b reel_board
2019-06-13 21:59:12 +02:00
# with cmake
2020-05-07 18:02:48 +02:00
cmake -DBOARD=reel_board ..
2017-06-17 00:35:39 +02:00
name:
The actual name of the board as it appears in marketing material.
type:
Type of the board or configuration, currently we support 2 types: mcu, qemu
2023-01-09 17:52:36 +01:00
simulation:
Simulator used to simulate the platform, e.g. qemu.
2017-06-17 00:35:39 +02:00
arch:
Architecture of the board
toolchain:
The list of supported toolchains that can build this board. This should match
2023-10-18 03:46:03 +02:00
one of the values used for :envvar: `ZEPHYR_TOOLCHAIN_VARIANT` when building on the command line
2017-06-17 00:35:39 +02:00
ram:
2017-06-22 16:12:13 +02:00
Available RAM on the board (specified in KB). This is used to match testcase
requirements. If not specified we default to 128KB.
2017-06-17 00:35:39 +02:00
flash:
2017-06-22 16:12:13 +02:00
Available FLASH on the board (specified in KB). This is used to match testcase
requirements. If not specified we default to 512KB.
2017-07-31 14:47:41 +02:00
supported:
A list of features this board supports. This can be specified as a single word
feature or as a variant of a feature class. For example:
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2017-07-31 14:47:41 +02:00
supported:
- pci
This indicates the board does support PCI. You can make a testcase build or
run only on such boards, or:
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2017-07-31 14:47:41 +02:00
supported:
- netif:eth
- sensor:bmi16
A testcase can both depend on 'eth' to only test ethernet or on 'netif' to run
on any board with a networking interface.
2017-06-17 00:35:39 +02:00
testing:
testing relating keywords to provide best coverage for the features of this
board.
default: [True|False]:
This is a default board, it will tested with the highest priority and is
2020-12-07 17:46:56 +01:00
covered when invoking the simplified twister without any additional
2017-06-17 00:35:39 +02:00
arguments.
ignore_tags:
2017-06-22 16:12:13 +02:00
Do not attempt to build (and therefore run) tests marked with this list of
tags.
2020-07-16 22:27:04 +02:00
only_tags:
Only execute tests with this list of tags on a specific platform.
2017-06-17 00:35:39 +02:00
2023-09-28 01:28:26 +02:00
.. _twister_board_timeout_multiplier:
timeout_multiplier: <float> (default 1)
Multiply each test case timeout by specified ratio. This option allows to tune timeouts only
for required platform. It can be useful in case naturally slow platform I.e.: HW board with
power-efficient but slow CPU or simulation platform which can perform instruction accurate
simulation but does it slowly.
2024-03-22 13:30:54 +01:00
env:
A list of environment variables. Twister will check if all these environment variables are set,
and otherwise skip this platform. This allows the user to define a platform which should be
used, for example, only if some required software or hardware is present, and to signal that
presence to twister using these environment variables.
2017-06-17 00:35:39 +02:00
Test Cases
***** *****
2023-10-18 03:46:03 +02:00
Test cases are detected by the presence of a `` testcase.yaml `` or a `` sample.yaml ``
2017-06-17 00:35:39 +02:00
files in the application's project directory. This file may contain one or more
2019-12-02 14:50:11 +01:00
entries in the test section each identifying a test scenario.
The name of each testcase needs to be unique in the context of the overall
testsuite and has to follow basic rules:
#. The format of the test identifier shall be a string without any spaces or
2022-03-16 22:07:43 +01:00
special characters (allowed characters: alphanumeric and [\_=]) consisting
of multiple sections delimited with a dot (.).
2019-12-02 14:50:11 +01:00
#. Each test identifier shall start with a section followed by a subsection
separated by a dot. For example, a test that covers semaphores in the kernel
2022-03-16 22:07:43 +01:00
shall start with `` kernel.semaphore `` .
2019-12-02 14:50:11 +01:00
#. All test identifiers within a testcase.yaml file need to be unique. For
example a testcase.yaml file covering semaphores in the kernel can have:
* `` kernel.semaphore `` : For general semaphore tests
2022-03-16 22:07:43 +01:00
* `` kernel.semaphore.stress `` : Stress testing semaphores in the kernel.
2019-12-02 14:50:11 +01:00
#. Depending on the nature of the test, an identifier can consist of at least
two sections:
* Ztest tests: The individual testcases in the ztest testsuite will be
concatenated to identifier in the testcase.yaml file generating unique
identifiers for every testcase in the suite.
* Standalone tests and samples: This type of test should at least have 3
sections in the test identifier in the testcase.yaml (or sample.yaml) file.
The last section of the name shall signify the test itself.
2017-06-17 00:35:39 +02:00
2017-10-17 23:04:56 +02:00
Test cases are written using the YAML syntax and share the same structure as
2017-06-17 00:35:39 +02:00
samples. The following is an example test with a few options that are
2017-08-02 20:05:59 +02:00
explained in this document.
2017-06-17 00:35:39 +02:00
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2017-06-17 00:35:39 +02:00
2017-11-19 22:36:30 +01:00
tests:
2019-12-02 14:50:11 +01:00
bluetooth.gatt:
2017-12-08 14:41:03 +01:00
build_only: true
2020-08-26 17:28:25 +02:00
platform_allow: qemu_cortex_m3 qemu_x86
2017-12-08 14:41:03 +01:00
tags: bluetooth
2019-12-02 14:50:11 +01:00
bluetooth.gatt.br:
2017-12-08 14:41:03 +01:00
build_only: true
extra_args: CONF_FILE="prj_br.conf"
filter: not CONFIG_DEBUG
2019-06-22 00:21:11 +02:00
platform_exclude: up_squared
2020-08-26 17:28:25 +02:00
platform_allow: qemu_cortex_m3 qemu_x86
2017-12-08 14:41:03 +01:00
tags: bluetooth
2017-06-17 00:35:39 +02:00
A sample with tests will have the same structure with additional information
related to the sample and what is being demonstrated:
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2017-06-17 00:35:39 +02:00
2017-11-19 22:36:30 +01:00
sample:
name: hello world
description: Hello World sample, the simplest Zephyr application
tests:
2019-12-02 14:50:11 +01:00
sample.basic.hello_world:
2017-12-08 14:41:03 +01:00
build_only: true
2018-10-15 21:28:35 +02:00
tags: tests
2017-12-08 14:41:03 +01:00
min_ram: 16
2019-12-02 14:50:11 +01:00
sample.basic.hello_world.singlethread:
2017-12-08 14:41:03 +01:00
build_only: true
extra_args: CONF_FILE=prj_single.conf
2019-09-17 18:41:40 +02:00
filter: not CONFIG_BT
2018-10-15 21:28:35 +02:00
tags: tests
2017-12-08 14:41:03 +01:00
min_ram: 16
2017-06-17 00:35:39 +02:00
2023-10-18 03:46:03 +02:00
The full canonical name for each test case is:`` <path to test case>/<test entry> ``
2017-06-17 00:35:39 +02:00
Each test block in the testcase meta data can define the following key/value
pairs:
tags: <list of tags> (required)
A set of string tags for the testcase. Usually pertains to
functional domains but can be anything. Command line invocations
of this script can filter the set of tests to run based on tag.
skip: <True|False> (default False)
skip testcase unconditionally. This can be used for broken tests.
slow: <True|False> (default False)
2023-10-18 03:46:03 +02:00
Don't run this test case unless `` --enable-slow `` or `` --enable-slow-only `` was
2023-06-22 16:03:35 +02:00
passed in on the command line. Intended for time-consuming test cases that
are only run under certain circumstances, like daily builds. These test
cases are still compiled.
2017-06-17 00:35:39 +02:00
extra_args: <list of extra arguments>
Extra arguments to pass to Make when building or running the
test case.
2017-10-17 15:00:33 +02:00
extra_configs: <list of extra configurations>
Extra configuration options to be merged with a master prj.conf
2023-10-18 03:46:03 +02:00
when building or running the test case. For example:
.. code-block :: yaml
2017-10-17 15:00:33 +02:00
2017-11-19 22:36:30 +01:00
common:
tags: drivers adc
tests:
2017-12-08 14:41:03 +01:00
test:
depends_on: adc
2019-02-25 15:12:57 +01:00
test_async:
2017-12-08 14:41:03 +01:00
extra_configs:
2019-02-25 15:12:57 +01:00
- CONFIG_ADC_ASYNC=y
2017-10-17 15:00:33 +02:00
2023-01-11 23:25:08 +01:00
Using namespacing, it is possible to apply a configuration only to some
2023-10-18 03:46:03 +02:00
hardware. Currently both architectures and platforms are supported:
.. code-block :: yaml
2023-01-11 23:25:08 +01:00
common:
tags: drivers adc
tests:
test:
depends_on: adc
test_async:
extra_configs:
- arch:x86:CONFIG_ADC_ASYNC=y
- platform:qemu_x86:CONFIG_DEBUG=y
2017-10-17 15:00:33 +02:00
2017-06-17 00:35:39 +02:00
build_only: <True|False> (default False)
2023-01-30 17:18:42 +01:00
If true, twister will not try to run the test even if the test is runnable
on the platform.
This keyword is reserved for tests that are used to test if some code
actually builds. A `` build_only `` test is not designed to be run in any
environment and should not be testing any functionality, it only verifies
that the code builds.
This option is often used to test drivers and the fact that they are correctly
enabled in Zephyr and that the code builds, for example sensor drivers. Such
2024-01-11 17:36:12 +01:00
test shall not be used to verify the functionality of the driver.
2017-06-17 00:35:39 +02:00
build_on_all: <True|False> (default False)
2023-03-06 07:14:38 +01:00
If true, attempt to build test on all available platforms. This is mostly
used in CI for increased coverage. Do not use this flag in new tests.
2017-06-17 00:35:39 +02:00
depends_on: <list of features>
A board or platform can announce what features it supports, this option
will enable the test only those platforms that provide this feature.
2023-10-18 03:46:03 +02:00
levels: <list of levels>
2023-03-06 07:14:38 +01:00
Test levels this test should be part of. If a level is present, this
test will be selectable using the command line option `` --level <level name> ``
2017-06-17 00:35:39 +02:00
min_ram: <integer>
2021-08-24 18:24:46 +02:00
minimum amount of RAM in KB needed for this test to build and run. This is
2017-06-17 00:35:39 +02:00
compared with information provided by the board metadata.
min_flash: <integer>
2021-08-24 18:24:46 +02:00
minimum amount of ROM in KB needed for this test to build and run. This is
2017-06-17 00:35:39 +02:00
compared with information provided by the board metadata.
2023-09-28 01:28:26 +02:00
.. _twister_test_case_timeout:
2017-06-17 00:35:39 +02:00
timeout: <number of seconds>
2023-04-03 10:24:46 +02:00
Length of time to run test before automatically killing it.
2017-06-17 00:35:39 +02:00
Default to 60 seconds.
2020-08-26 17:28:25 +02:00
arch_allow: <list of arches, such as x86, arm, arc>
2017-06-17 00:35:39 +02:00
Set of architectures that this test case should only be run for.
arch_exclude: <list of arches, such as x86, arm, arc>
Set of architectures that this test case should not run on.
2020-08-26 17:28:25 +02:00
platform_allow: <list of platforms>
2020-07-08 04:43:11 +02:00
Set of platforms that this test case should only be run for. Do not use
this option to limit testing or building in CI due to time or resource
constraints, this option should only be used if the test or sample can
2020-08-26 17:28:25 +02:00
only be run on the allowed platform and nothing else.
2020-07-08 04:43:11 +02:00
integration_platforms: <YML list of platforms/boards>
2020-12-07 17:46:56 +01:00
This option limits the scope to the listed platforms when twister is
2023-10-18 03:46:03 +02:00
invoked with the `` --integration `` option. Use this instead of
2020-08-26 17:28:25 +02:00
platform_allow if the goal is to limit scope due to timing or
2020-07-08 04:43:11 +02:00
resource constraints.
2017-06-17 00:35:39 +02:00
platform_exclude: <list of platforms>
Set of platforms that this test case should not run on.
extra_sections: <list of extra binary sections>
2020-12-07 17:46:56 +01:00
When computing sizes, twister will report errors if it finds
2017-06-17 00:35:39 +02:00
extra, unexpected sections in the Zephyr binary unless they are named
here. They will not be included in the size calculation.
2022-08-25 20:24:50 +02:00
sysbuild: <True|False> (default False)
Build the project using sysbuild infrastructure. Only the main project's
generated devicetree and Kconfig will be used for filtering tests.
on device testing must use the hardware map, or west flash to load
2023-10-18 03:46:03 +02:00
the images onto the target. The `` --erase `` option of west flash is
2022-08-25 20:24:50 +02:00
not supported with this option. Usage of unsupported options will result
in tests requiring sysbuild support being skipped.
2018-09-27 23:12:54 +02:00
harness: <string>
2023-01-30 16:14:00 +01:00
A harness keyword in the `` testcase.yaml `` file identifies a Twister
harness needed to run a test successfully. A harness is a feature of
Twister and implemented by Twister, some harnesses are defined as
placeholders and have no implementation yet.
A harness can be seen as the handler that needs to be implemented in
Twister to be able to evaluate if a test passes criteria. For example, a
keyboard harness is set on tests that require keyboard interaction to reach
verdict on whether a test has passed or failed, however, Twister lack this
2023-12-17 23:41:07 +01:00
harness implementation at the moment.
2023-01-30 16:14:00 +01:00
Supported harnesses:
- ztest
- test
- console
- pytest
2023-05-19 07:36:17 +02:00
- gtest
2023-04-05 15:21:44 +02:00
- robot
2023-05-19 07:36:17 +02:00
Harnesses `` ztest `` , `` gtest `` and `` console `` are based on parsing of the
output and matching certain phrases. `` ztest `` and `` gtest `` harnesses look
for pass/fail/etc. frames defined in those frameworks. Use `` gtest ``
harness if you've already got tests written in the gTest framework and do
not wish to update them to zTest. The `` console `` harness tells Twister to
parse a test's text output for a regex defined in the test's YAML file.
2023-04-05 15:21:44 +02:00
The `` robot `` harness is used to execute Robot Framework test suites
in the Renode simulation framework.
2023-01-30 16:14:00 +01:00
Some widely used harnesses that are not supported yet:
- keyboard
- net
- bluetooth
2023-12-17 23:41:07 +01:00
Harness `` bsim `` is implemented in limited way - it helps only to copy the
final executable (`` zephyr.exe `` ) from build directory to BabbleSim's
`` bin `` directory (`` ${BSIM_OUT_PATH}/bin `` ). This action is useful to allow
BabbleSim's tests to directly run after. By default, the executable file
name is (with dots and slashes replaced by underscores):
`` bs_<platform_name>_<test_path>_<test_scenario_name> `` .
This name can be overridden with the `` bsim_exe_name `` option in
`` harness_config `` section.
2018-09-27 23:12:54 +02:00
2022-11-15 18:49:06 +01:00
platform_key: <list of platform attributes>
Often a test needs to only be built and run once to qualify as passing.
Imagine a library of code that depends on the platform architecture where
passing the test on a single platform for each arch is enough to qualify the
tests and code as passing. The platform_key attribute enables doing just
that.
For example to key on (arch, simulation) to ensure a test is run once
2023-10-18 03:46:03 +02:00
per arch and simulation (as would be most common):
.. code-block :: yaml
2022-11-15 18:49:06 +01:00
platform_key:
- arch
- simulation
Adding platform (board) attributes to include things such as soc name,
soc family, and perhaps sets of IP blocks implementing each peripheral
interface would enable other interesting uses. For example, this could enable
2024-01-11 17:36:12 +01:00
building and running SPI tests once for each unique IP block.
2022-11-15 18:49:06 +01:00
2018-09-27 23:12:54 +02:00
harness_config: <harness configuration options>
Extra harness configuration options to be used to select a board and/or
for handling generic Console with regex matching. Config can announce
what features it supports. This option will enable the test to run on
only those platforms that fulfill this external dependency.
The following options are currently supported:
type: <one_line|multi_line> (required)
Depends on the regex string to be matched
2023-12-01 21:19:09 +01:00
regex: <list of regular expressions> (required)
Strings with regular expressions to match with the test's output
to confirm the test runs as expected.
2018-09-27 23:12:54 +02:00
ordered: <True|False> (default False)
Check the regular expression strings in orderly or randomly fashion
2023-12-01 21:19:09 +01:00
record: <recording options> (optional)
regex: <regular expression> (required)
2024-01-11 17:36:12 +01:00
The regular expression with named subgroups to match data fields
2023-12-01 21:19:09 +01:00
at the test's output lines where the test provides some custom data
for further analysis. These records will be written into the build
directory 'recording.csv' file as well as 'recording' property
of the test suite object in 'twister.json'.
For example, to extract three data fields 'metric', 'cycles', 'nanoseconds':
.. code-block :: yaml
record:
regex: "(?P<metric>.*):(?P<cycles>.* ) cycles, (?P<nanoseconds>.*) ns"
2018-09-27 23:12:54 +02:00
fixture: <expression>
Specify a test case dependency on an external device(e.g., sensor),
and identify setups that fulfill this dependency. It depends on
specific test setup and board selection logic to pick the particular
board(s) out of multiple boards that fulfill the dependency in an
2023-10-18 03:46:03 +02:00
automation setup based on `` fixture `` keyword. Some sample fixture names
2020-05-22 12:53:27 +02:00
are i2c_hts221, i2c_bme280, i2c_FRAM, ble_fw and gpio_loop.
2023-01-30 16:14:00 +01:00
Only one fixture can be defined per testcase and the fixture name has to
be unique across all tests in the test suite.
2018-09-27 23:12:54 +02:00
2023-11-22 19:57:10 +01:00
.. _pytest_root:
2023-09-14 15:38:34 +02:00
pytest_root: <list of pytest testpaths> (default pytest)
2023-11-22 19:57:10 +01:00
Specify a list of pytest directories, files or subtests that need to be
executed when a test case begins to run. The default pytest directory is
`` pytest `` . After the pytest run is finished, Twister will check if
the test case passed or failed according to the pytest report.
As an example, a list of valid pytest roots is presented below:
.. code-block :: yaml
harness_config:
pytest_root:
- "pytest/test_shell_help.py"
- "../shell/pytest/test_shell.py"
- "/tmp/test_shell.py"
- "~/tmp/test_shell.py"
- "$ZEPHYR_BASE/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py"
- "pytest/test_shell_help.py::test_shell2_sample" # select pytest subtest
- "pytest/test_shell_help.py::test_shell2_sample[param_a]" # select pytest parametrized subtest
.. _pytest_args:
2020-10-22 03:37:27 +02:00
2022-02-24 12:45:29 +01:00
pytest_args: <list of arguments> (default empty)
2023-11-22 19:57:10 +01:00
Specify a list of additional arguments to pass to `` pytest `` e.g.:
`` pytest_args: [‘ -k=test_method’ , ‘ --log-level=DEBUG’ ] `` . Note that
`` --pytest-args `` can be passed multiple times to pass several arguments
to the pytest.
.. _pytest_dut_scope:
2022-02-24 12:45:29 +01:00
2023-10-25 12:33:23 +02:00
pytest_dut_scope: <function|class|module|package|session> (default function)
The scope for which `` dut `` and `` shell `` pytest fixtures are shared.
If the scope is set to `` function `` , DUT is launched for every test case
in python script. For `` session `` scope, DUT is launched only once.
2023-04-05 15:21:44 +02:00
robot_test_path: <robot file path> (default empty)
Specify a path to a file containing a Robot Framework test suite to be run.
2023-12-17 23:41:07 +01:00
bsim_exe_name: <string>
If provided, the executable filename when copying to BabbleSim's bin
directory, will be `` bs_<platform_name>_<bsim_exe_name> `` instead of the
default based on the test path and scenario name.
2018-09-27 23:12:54 +02:00
The following is an example yaml file with a few harness_config options.
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2018-09-27 23:12:54 +02:00
sample:
name: HTS221 Temperature and Humidity Monitor
common:
tags: sensor
harness: console
harness_config:
type: multi_line
ordered: false
regex:
- "Temperature:(.*)C"
- "Relative Humidity:(.*)%"
2020-05-22 12:53:27 +02:00
fixture: i2c_hts221
2018-09-27 23:12:54 +02:00
tests:
test:
2018-10-15 21:28:35 +02:00
tags: sensors
2018-09-27 23:12:54 +02:00
depends_on: i2c
2020-10-22 03:37:27 +02:00
The following is an example yaml file with pytest harness_config options,
default pytest_root name "pytest" will be used if pytest_root not specified.
2023-09-14 15:38:34 +02:00
please refer the examples in samples/subsys/testsuite/pytest/.
2020-10-22 03:37:27 +02:00
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2020-10-22 03:37:27 +02:00
2023-09-14 15:38:34 +02:00
common:
harness: pytest
2020-10-22 03:37:27 +02:00
tests:
2023-09-14 15:38:34 +02:00
pytest.example.directories:
harness_config:
pytest_root:
- pytest_dir1
- $ENV_VAR/samples/test/pytest_dir2
pytest.example.files_and_subtests:
2020-10-22 03:37:27 +02:00
harness_config:
2023-09-14 15:38:34 +02:00
pytest_root:
- pytest/test_file_1.py
- test_file_2.py::test_A
- test_file_2.py::test_B[param_a]
2020-10-22 03:37:27 +02:00
2023-04-05 15:21:44 +02:00
The following is an example yaml file with robot harness_config options.
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2023-04-05 15:21:44 +02:00
tests:
robot.example:
harness: robot
harness_config:
robot_test_path: [robot file path]
2017-06-17 00:35:39 +02:00
filter: <expression>
Filter whether the testcase should be run by evaluating an expression
against an environment containing the following values:
2023-10-18 03:46:03 +02:00
.. code-block :: none
2017-06-17 00:35:39 +02:00
{ ARCH : <architecture>,
PLATFORM : <platform>,
<all CONFIG_* key/value pairs in the test's generated defconfig>,
*<env> : any environment variable available
}
2022-10-13 00:24:57 +02:00
Twister will first evaluate the expression to find if a "limited" cmake call, i.e. using package_helper cmake script,
can be done. Existence of "dt_*" entries indicates devicetree is needed.
Existence of "CONFIG*" entries indicates kconfig is needed.
2023-08-03 21:11:31 +02:00
If there are no other types of entries in the expression a filtration can be done without creating a complete build system.
2022-10-13 00:24:57 +02:00
If there are entries of other types a full cmake is required.
2017-06-17 00:35:39 +02:00
The grammar for the expression language is as follows:
2023-10-18 03:46:03 +02:00
.. code-block :: antlr
2017-06-17 00:35:39 +02:00
2023-10-18 03:46:03 +02:00
expression : expression 'and' expression
| expression 'or' expression
| 'not' expression
| '(' expression ')'
| symbol '==' constant
| symbol '!=' constant
| symbol '<' NUMBER
| symbol '>' NUMBER
| symbol '>=' NUMBER
| symbol '<=' NUMBER
| symbol 'in' list
| symbol ':' STRING
| symbol
;
2017-06-17 00:35:39 +02:00
2023-10-18 03:46:03 +02:00
list : '[' list_contents ']';
2017-06-17 00:35:39 +02:00
2023-10-18 03:46:03 +02:00
list_contents : constant (',' constant)*;
2017-06-17 00:35:39 +02:00
2023-10-18 03:46:03 +02:00
constant : NUMBER | STRING;
2017-06-17 00:35:39 +02:00
2023-10-18 03:46:03 +02:00
For the case where `` expression ::= symbol `` , it evaluates to `` true ``
2017-06-17 00:35:39 +02:00
if the symbol is defined to a non-empty string.
Operator precedence, starting from lowest to highest:
2023-10-18 03:46:03 +02:00
* or (left associative)
* and (left associative)
* not (right associative)
* all comparison operators (non-associative)
`` arch_allow `` , `` arch_exclude `` , `` platform_allow `` , `` platform_exclude ``
are all syntactic sugar for these expressions. For instance:
2017-06-17 00:35:39 +02:00
2023-10-18 03:46:03 +02:00
.. code-block :: none
2017-06-17 00:35:39 +02:00
arch_exclude = x86 arc
Is the same as:
2023-10-18 03:46:03 +02:00
.. code-block :: none
2017-06-17 00:35:39 +02:00
filter = not ARCH in ["x86", "arc"]
2023-10-18 03:46:03 +02:00
The `` : `` operator compiles the string argument as a regular expression,
2017-06-17 00:35:39 +02:00
and then returns a true value only if the symbol's value in the environment
2023-10-18 03:46:03 +02:00
matches. For example, if `` CONFIG_SOC="stm32f107xc" `` then
.. code-block :: none
2017-06-17 00:35:39 +02:00
2019-07-12 16:54:35 +02:00
filter = CONFIG_SOC : "stm.*"
2017-06-17 00:35:39 +02:00
Would match it.
2023-08-21 09:23:55 +02:00
required_snippets: <list of needed snippets>
:ref: `Snippets <snippets>` are supported in twister for test cases that
require them. As with normal applications, twister supports using the base
zephyr snippet directory and test application directory for finding
snippets. Listed snippets will filter supported tests for boards (snippets
must be compatible with a board for the test to run on them, they are not
optional).
The following is an example yaml file with 2 required snippets.
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2023-08-21 09:23:55 +02:00
tests:
snippet.example:
required_snippets:
- cdc-acm-console
- user-snippet-example
2017-06-17 00:35:39 +02:00
The set of test cases that actually run depends on directives in the testcase
filed and options passed in on the command line. If there is any confusion,
2023-10-18 03:46:03 +02:00
running with `` -v `` or examining the discard report
2020-12-07 17:46:56 +01:00
(:file: `twister_discard.csv` ) can help show why particular test cases were
2019-11-20 12:47:27 +01:00
skipped.
2017-06-17 00:35:39 +02:00
Metrics (such as pass/fail state and binary size) for the last code
2023-10-18 03:46:03 +02:00
release are stored in `` scripts/release/twister_last_release.csv `` .
To update this, pass the `` --all --release `` options.
2017-06-17 00:35:39 +02:00
2023-10-18 03:46:03 +02:00
To load arguments from a file, add `` + `` before the file name, e.g.,
`` +file_name `` . File content must be one or more valid arguments separated by
2017-06-17 00:35:39 +02:00
line break instead of white spaces.
Most everyday users will run with no arguments.
2018-05-24 14:58:08 +02:00
2023-09-28 01:28:26 +02:00
Managing tests timeouts
***** ***** ***** ***** ***
There are several parameters which control tests timeouts on various levels:
* `` timeout `` option in each test case. See :ref: `here <twister_test_case_timeout>` for more
details.
* `` timeout_multiplier `` option in board configuration. See
:ref: `here <twister_board_timeout_multiplier>` for more details.
* `` --timeout-multiplier `` twister option which can be used to adjust timeouts in exact twister run.
It can be useful in case of simulation platform as simulation time may depend on the host
speed & load or we may select different simulation method (i.e. cycle accurate but slower
one), etc...
Overall test case timeout is a multiplication of these three parameters.
2020-07-08 04:43:11 +02:00
Running in Integration Mode
***** ***** ***** ***** ***** **
This mode is used in continuous integration (CI) and other automated
environments used to give developers fast feedback on changes. The mode can
2023-10-18 03:46:03 +02:00
be activated using the `` --integration `` option of twister and narrows down
2020-07-08 04:43:11 +02:00
the scope of builds and tests if applicable to platforms defined under the
integration keyword in the testcase definition file (testcase.yaml and
sample.yaml).
2018-05-24 14:58:08 +02:00
2023-06-20 08:51:26 +02:00
Running tests on custom emulator
***** ***** ***** ***** ***** ***** **
Apart from the already supported QEMU and other simulated environments, Twister
supports running any out-of-tree custom emulator defined in the board's :file: `board.cmake` .
To use this type of simulation, add the following properties to
:file: `custom_board/custom_board.yaml` :
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2023-06-20 08:51:26 +02:00
simulation: custom
simulation_exec: <name_of_emu_binary>
This tells Twister that the board is using a custom emulator called `` <name_of_emu_binary> `` ,
make sure this binary exists in the PATH.
Then, in :file: `custom_board/board.cmake` , set the supported emulation platforms to `` custom `` :
2023-10-18 03:46:03 +02:00
.. code-block :: cmake
2023-06-20 08:51:26 +02:00
set(SUPPORTED_EMU_PLATFORMS custom)
Finally, implement the `` run_custom `` target in :file: `custom_board/board.cmake` .
It should look something like this:
2023-10-18 03:46:03 +02:00
.. code-block :: cmake
2023-06-20 08:51:26 +02:00
add_custom_target(run_custom
COMMAND
<name_of_emu_binary to invoke during 'run'>
<any args to be passed to the command, i.e. ${BOARD}, ${APPLICATION_BINARY_DIR}/zephyr/zephyr.elf>
WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
DEPENDS ${logical_target_for_zephyr_elf}
USES_TERMINAL
)
2018-05-24 14:58:08 +02:00
Running Tests on Hardware
***** ***** ***** ***** *****
Beside being able to run tests in QEMU and other simulated environments,
2020-12-07 17:46:56 +01:00
twister supports running most of the tests on real devices and produces
2018-05-24 14:58:08 +02:00
reports for each run with detailed FAIL/PASS results.
2019-09-22 16:41:44 +02:00
Executing tests on a single device
===================================
2020-12-07 17:46:56 +01:00
To use this feature on a single connected device, run twister with
2022-08-02 05:11:55 +02:00
the following new options:
.. tabs ::
2018-05-24 14:58:08 +02:00
2022-08-02 05:11:55 +02:00
.. group-tab :: Linux
.. code-block :: bash
scripts/twister --device-testing --device-serial /dev/ttyACM0 \
--device-serial-baud 115200 -p frdm_k64f -T tests/kernel
.. group-tab :: Windows
.. code-block :: bat
python .\scripts\twister --device-testing --device-serial COM1 \
--device-serial-baud 115200 -p frdm_k64f -T tests/kernel
2018-05-24 14:58:08 +02:00
The `` --device-serial `` option denotes the serial device the board is connected to.
2020-12-07 17:46:56 +01:00
This needs to be accessible by the user running twister. You can run this on
2019-09-22 16:41:44 +02:00
only one board at a time, specified using the `` --platform `` option.
2021-10-06 00:34:54 +02:00
The `` --device-serial-baud `` option is only needed if your device does not run at
115200 baud.
2022-04-15 05:32:03 +02:00
To support devices without a physical serial port, use the `` --device-serial-pty ``
option. In this cases, log messages are captured for example using a script.
2022-08-02 05:11:55 +02:00
In this case you can run twister with the following options:
.. tabs ::
.. group-tab :: Linux
.. code-block :: bash
scripts/twister --device-testing --device-serial-pty "script.py" \
2022-09-14 22:23:15 +02:00
-p intel_adsp/cavs25 -T tests/kernel
2022-04-15 05:32:03 +02:00
2022-08-02 05:11:55 +02:00
.. group-tab :: Windows
.. note ::
Not supported on Windows OS
2022-04-15 05:32:03 +02:00
The script is user-defined and handles delivering the messages which can be
used by twister to determine the test execution status.
2023-04-03 10:24:46 +02:00
The `` --device-flash-timeout `` option allows to set explicit timeout on the
device flash operation, for example when device flashing takes significantly
large time.
The `` --device-flash-with-test `` option indicates that on the platform
the flash operation also executes a test case, so the flash timeout is
increased by a test case timeout.
2019-09-22 16:41:44 +02:00
Executing tests on multiple devices
===================================
To build and execute tests on multiple devices connected to the host PC, a
hardware map needs to be created with all connected devices and their
2021-10-06 00:34:54 +02:00
details such as the serial device, baud and their IDs if available.
2022-08-02 05:11:55 +02:00
Run the following command to produce the hardware map:
.. tabs ::
.. group-tab :: Linux
.. code-block :: bash
2019-09-22 16:41:44 +02:00
2022-08-02 05:11:55 +02:00
./scripts/twister --generate-hardware-map map.yml
.. group-tab :: Windows
.. code-block :: bat
python .\scripts\twister --generate-hardware-map map.yml
2019-09-22 16:41:44 +02:00
The generated hardware map file (map.yml) will have the list of connected
2022-08-02 05:11:55 +02:00
devices, for example:
.. tabs ::
.. group-tab :: Linux
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
- connected: true
id: OSHW000032254e4500128002ab98002784d1000097969900
platform: unknown
product: DAPLink CMSIS-DAP
runner: pyocd
serial: /dev/cu.usbmodem146114202
- connected: true
id: 000683759358
platform: unknown
product: J-Link
runner: unknown
serial: /dev/cu.usbmodem0006837593581
2022-08-02 05:11:55 +02:00
.. group-tab :: Windows
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2022-08-02 05:11:55 +02:00
2023-10-18 03:46:03 +02:00
- connected: true
id: OSHW000032254e4500128002ab98002784d1000097969900
platform: unknown
product: unknown
runner: unknown
serial: COM1
- connected: true
id: 000683759358
platform: unknown
product: unknown
runner: unknown
serial: COM2
2019-09-22 16:41:44 +02:00
2023-10-18 03:46:03 +02:00
Any options marked as `` unknown `` need to be changed and set with the correct
2022-08-02 05:11:55 +02:00
values, in the above example the platform names, the products and the runners need
to be replaced with the correct values corresponding to the connected hardware.
2022-09-14 22:23:15 +02:00
In this example we are using a reel_board and an nrf52840dk/nrf52840:
2022-08-02 05:11:55 +02:00
.. tabs ::
.. group-tab :: Linux
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
- connected: true
id: OSHW000032254e4500128002ab98002784d1000097969900
platform: reel_board
product: DAPLink CMSIS-DAP
runner: pyocd
serial: /dev/cu.usbmodem146114202
baud: 9600
- connected: true
id: 000683759358
2022-09-14 22:23:15 +02:00
platform: nrf52840dk/nrf52840
2023-10-18 03:46:03 +02:00
product: J-Link
runner: nrfjprog
serial: /dev/cu.usbmodem0006837593581
baud: 9600
2022-08-02 05:11:55 +02:00
.. group-tab :: Windows
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
- connected: true
id: OSHW000032254e4500128002ab98002784d1000097969900
platform: reel_board
product: DAPLink CMSIS-DAP
runner: pyocd
serial: COM1
baud: 9600
- connected: true
id: 000683759358
2022-09-14 22:23:15 +02:00
platform: nrf52840dk/nrf52840
2023-10-18 03:46:03 +02:00
product: J-Link
runner: nrfjprog
serial: COM2
baud: 9600
2021-10-06 00:34:54 +02:00
The baud entry is only needed if not running at 115200.
2019-09-22 16:41:44 +02:00
If the map file already exists, then new entries are added and existing entries
will be updated. This way you can use one single master hardware map and update
it for every run to get the correct serial devices and status of the devices.
With the hardware map ready, you can run any tests by pointing to the map
2022-08-02 05:11:55 +02:00
.. tabs ::
.. group-tab :: Linux
.. code-block :: bash
./scripts/twister --device-testing --hardware-map map.yml -T samples/hello_world/
.. group-tab :: Windows
.. code-block :: bat
python .\scripts\twister --device-testing --hardware-map map.yml -T samples\hello_world
2019-09-22 16:41:44 +02:00
2020-12-07 17:46:56 +01:00
The above command will result in twister building tests for the platforms
2019-09-22 16:41:44 +02:00
defined in the hardware map and subsequently flashing and running the tests
on those platforms.
.. note ::
2024-01-09 11:38:51 +01:00
Currently only boards with support for pyocd, nrfjprog, jlink, openocd, or dediprog
are supported with the hardware map features. Boards that require other runners to flash the
2019-09-22 16:41:44 +02:00
Zephyr binary are still work in progress.
2018-05-24 14:58:08 +02:00
2023-04-03 10:24:46 +02:00
Hardware map allows to set `` --device-flash-timeout `` and `` --device-flash-with-test ``
command line options as `` flash-timeout `` and `` flash-with-test `` fields respectively.
These hardware map values override command line options for the particular platform.
2022-04-15 05:32:03 +02:00
Serial PTY support using `` --device-serial-pty `` can also be used in the
2023-10-18 03:46:03 +02:00
hardware map:
.. code-block :: yaml
2022-04-15 05:32:03 +02:00
2023-10-18 03:46:03 +02:00
- connected: true
id: None
2022-09-14 22:23:15 +02:00
platform: intel_adsp/cavs25
2023-10-18 03:46:03 +02:00
product: None
runner: intel_adsp
serial_pty: path/to/script.py
runner_params:
- --remote-host=remote_host_ip_addr
- --key=/path/to/key.pem
2022-04-15 05:32:03 +02:00
The runner_params field indicates the parameters you want to pass to the
west runner. For some boards the west runner needs some extra parameters to
2022-08-02 05:11:55 +02:00
work. It is equivalent to following west and twister commands.
.. tabs ::
.. group-tab :: Linux
.. code-block :: bash
west flash --remote-host remote_host_ip_addr --key /path/to/key.pem
2022-09-14 22:23:15 +02:00
twister -p intel_adsp/cavs25 --device-testing --device-serial-pty script.py
2022-08-02 05:11:55 +02:00
--west-flash="--remote-host=remote_host_ip_addr,--key=/path/to/key.pem"
2022-04-15 05:32:03 +02:00
2022-08-02 05:11:55 +02:00
.. group-tab :: Windows
2022-04-15 05:32:03 +02:00
2022-08-02 05:11:55 +02:00
.. note ::
2022-04-15 05:32:03 +02:00
2022-08-02 05:11:55 +02:00
Not supported on Windows OS
2022-04-15 05:32:03 +02:00
.. note ::
For serial PTY, the "--generate-hardware-map" option cannot scan it out
and generate a correct hardware map automatically. You have to edit it
manually according to above example. This is because the serial port
of the PTY is not fixed and being allocated in the system at runtime.
2020-05-22 12:53:27 +02:00
Fixtures
+++++++++
Some tests require additional setup or special wiring specific to the test.
Running the tests without this setup or test fixture may fail. A testcase can
specify the fixture it needs which can then be matched with hardware capability
of a board and the fixtures it supports via the command line or using the hardware
map file.
2023-10-18 03:46:03 +02:00
Fixtures are defined in the hardware map file as a list:
.. code-block :: yaml
2020-05-22 12:53:27 +02:00
2021-05-17 15:45:03 +02:00
- connected: true
2020-05-22 12:53:27 +02:00
fixtures:
- gpio_loopback
id: 0240000026334e450015400f5e0e000b4eb1000097969900
platform: frdm_k64f
product: DAPLink CMSIS-DAP
runner: pyocd
serial: /dev/ttyACM9
2021-12-10 13:14:27 +01:00
When running `` twister `` with `` --device-testing `` , the configured fixture
2020-05-22 12:53:27 +02:00
in the hardware map file will be matched to testcases requesting the same fixtures
and these tests will be executed on the boards that provide this fixture.
.. figure :: fixtures.svg
:figclass: align-center
2020-05-21 18:03:18 +02:00
2022-02-16 10:53:26 +01:00
Fixtures can also be provided via twister command option `` --fixture `` , this option
can be used multiple times and all given fixtures will be appended as a list. And the
given fixtures will be assigned to all boards, this means that all boards set by
current twister command can run those testcases which request the same fixtures.
2020-05-21 18:03:18 +02:00
Notes
+++++
It may be useful to annotate board descriptions in the hardware map file
2023-10-18 03:46:03 +02:00
with additional information. Use the `` notes `` keyword to do this. For
example:
.. code-block :: yaml
2020-05-21 18:03:18 +02:00
2021-05-17 15:45:03 +02:00
- connected: false
2020-05-21 18:03:18 +02:00
fixtures:
- gpio_loopback
id: 000683290670
2022-09-14 22:23:15 +02:00
notes: An nrf5340dk/nrf5340 is detected as an nrf52840dk/nrf52840 with no serial
2020-05-21 18:03:18 +02:00
port, and three serial ports with an unknown platform. The board id of the serial
2023-11-15 11:10:16 +01:00
ports is not the same as the board id of the development kit. If you regenerate
2020-05-21 18:03:18 +02:00
this file you will need to update serial to reference the third port, and platform
2022-09-14 22:23:15 +02:00
to nrf5340dk/nrf5340/cpuapp or another supported board target.
platform: nrf52840dk/nrf52840
2020-05-21 18:03:18 +02:00
product: J-Link
runner: jlink
serial: null
2020-05-25 15:21:44 +02:00
Overriding Board Identifier
+++++++++++++++++++++++++++
2023-10-18 03:46:03 +02:00
When (re-)generated the hardware map file will contain an `` id `` keyword
2020-05-25 15:21:44 +02:00
that serves as the argument to `` --board-id `` when flashing. In some
cases the detected ID is not the correct one to use, for example when
2023-10-18 03:46:03 +02:00
using an external J-Link probe. The `` probe_id `` keyword overrides the
`` id `` keyword for this purpose. For example:
.. code-block :: yaml
2020-05-25 15:21:44 +02:00
2021-05-17 15:45:03 +02:00
- connected: false
2020-05-25 15:21:44 +02:00
id: 0229000005d9ebc600000000000000000000000097969905
platform: mimxrt1060_evk
probe_id: 000609301751
product: DAPLink CMSIS-DAP
runner: jlink
serial: null
2021-04-01 18:38:30 +02:00
Quarantine
++++++++++
2024-01-11 17:36:12 +01:00
Twister allows user to provide configuration files defining a list of tests or
2023-01-13 13:28:31 +01:00
platforms to be put under quarantine. Such tests will be skipped and marked
accordingly in the output reports. This feature is especially useful when
running larger test suits, where a failure of one test can affect the execution
of other tests (e.g. putting the physical board in a corrupted state).
2021-04-01 18:38:30 +02:00
To use the quarantine feature one has to add the argument
`` --quarantine-list <PATH_TO_QUARANTINE_YAML> `` to a twister call.
2023-01-13 13:28:31 +01:00
Multiple quarantine files can be used.
2021-04-01 18:38:30 +02:00
The current status of tests on the quarantine list can also be verified by adding
`` --quarantine-verify `` to the above argument. This will make twister skip all tests
which are not on the given list.
A quarantine yaml has to be a sequence of dictionaries. Each dictionary has to have
2023-10-18 03:46:03 +02:00
`` scenarios `` and `` platforms `` entries listing combinations of scenarios and platforms
to put under quarantine. In addition, an optional entry `` comment `` can be used, where
2021-04-01 18:38:30 +02:00
some more details can be given (e.g. link to a reported issue). These comments will also
be added to the output reports.
2023-01-13 13:28:31 +01:00
When quarantining a class of tests or many scenarios in a single testsuite or
when dealing with multiple issues within a subsystem, it is possible to use
regular expressions, for example, **kernel.** * would quarantine
all kernel tests.
2023-10-18 03:46:03 +02:00
An example of entries in a quarantine yaml:
.. code-block :: yaml
2021-04-01 18:38:30 +02:00
- scenarios:
- sample.basic.helloworld
comment: "Link to the issue: https://github.com/zephyrproject-rtos/zephyr/pull/33287"
- scenarios:
- kernel.common
2023-01-13 13:28:31 +01:00
- kernel.common.(misra|tls)
2021-04-01 18:38:30 +02:00
- kernel.common.nano64
platforms:
2023-01-13 13:28:31 +01:00
- .*_cortex_.*
2023-11-10 12:29:28 +01:00
- native_sim
2022-01-31 19:12:54 +01:00
2023-10-18 03:46:03 +02:00
To exclude a platform, use the following syntax:
.. code-block :: yaml
2023-01-13 13:28:31 +01:00
- platforms:
- qemu_x86
comment: "broken qemu"
Additionally you can quarantine entire architectures or a specific simulator for executing tests.
2023-03-06 07:14:38 +01:00
Test Configuration
***** ***** ***** ***
2024-01-11 17:36:12 +01:00
A test configuration can be used to customize various aspects of twister
2023-03-06 07:14:38 +01:00
and the default enabled options and features. This allows tweaking the filtering
capabilities depending on the environment and makes it possible to adapt and
improve coverage when targeting different sets of platforms.
The test configuration also adds support for test levels and the ability to
assign a specific test to one or more levels. Using command line options of
twister it is then possible to select a level and just execute the tests
included in this level.
2024-01-11 17:36:12 +01:00
Additionally, the test configuration allows defining level
2023-03-06 07:14:38 +01:00
dependencies and additional inclusion of tests into a specific level if
the test itself does not have this information already.
In the configuration file you can include complete components using
regular expressions and you can specify which test level to import from
the same file, making management of levels easier.
To help with testing outside of upstream CI infrastructure, additional
options are available in the configuration file, which can be hosted
locally. As of now, those options are available:
- Ability to ignore default platforms as defined in board definitions
(Those are mostly emulation platforms used to run tests in upstream
CI)
- Option to specify your own list of default platforms overriding what
upstream defines.
2024-01-11 17:36:12 +01:00
- Ability to override `build_on_all` options used in some testcases.
2023-03-06 07:14:38 +01:00
This will treat tests or sample as any other just build for default
2023-08-03 21:11:31 +02:00
platforms you specify in the configuration file or on the command line.
2023-03-06 07:14:38 +01:00
- Ignore some logic in twister to expand platform coverage in cases where
default platforms are not in scope.
Platform Configuration
======================
The following options control platform filtering in twister:
- `override_default_platforms` : override default key a platform sets in board
configuration and instead use the list of platforms provided in the
configuration file as the list of default platforms. This option is set to
False by default.
- `increased_platform_scope` : This option is set to True by default, when
disabled, twister will not increase platform coverage automatically and will
only build and run tests on the specified platforms.
- `default_platforms` : A list of additional default platforms to add. This list
can either be used to replace the existing default platforms or can extend it
depending on the value of `override_default_platforms` .
2023-10-18 03:46:03 +02:00
And example platforms configuration:
.. code-block :: yaml
2023-03-06 07:14:38 +01:00
platforms:
override_default_platforms: true
increased_platform_scope: false
default_platforms:
- qemu_x86
Test Level Configuration
========================
The test configuration allows defining test levels, level dependencies and
additional inclusion of tests into a specific test level if the test itself
does not have this information already.
In the configuration file you can include complete components using
regular expressions and you can specify which test level to import from
the same file, making management of levels simple.
2023-10-18 03:46:03 +02:00
And example test level configuration:
.. code-block :: yaml
2023-03-06 07:14:38 +01:00
levels:
- name: my-test-level
description: >
my custom test level
adds:
- kernel.threads.*
- kernel.timer.behavior
- arch.interrupt
- boards.*
2023-03-16 07:55:30 +01:00
Combined configuration
======================
2023-08-03 21:11:31 +02:00
To mix the Platform and level configuration, you can take an example as below:
2023-03-16 07:55:30 +01:00
2024-01-11 17:36:12 +01:00
An example platforms plus level configuration:
2023-10-18 03:46:03 +02:00
.. code-block :: yaml
2023-03-16 07:55:30 +01:00
platforms:
override_default_platforms: true
default_platforms:
- frdm_k64f
levels:
- name: smoke
description: >
A plan to be used verifying basic zephyr features.
- name: unit
description: >
A plan to be used verifying unit test.
- name: integration
description: >
A plan to be used verifying integration.
- name: acceptance
description: >
A plan to be used verifying acceptance.
- name: system
description: >
A plan to be used verifying system.
- name: regression
description: >
A plan to be used verifying regression.
2024-01-11 17:36:12 +01:00
To run with above test_config.yaml file, only default_platforms with given test level
2023-03-16 07:55:30 +01:00
test cases will run.
.. tabs ::
.. group-tab :: Linux
.. code-block :: bash
scripts/twister --test-config=<path to>/test_config.yaml
-T tests --level="smoke"
2022-01-31 19:12:54 +01:00
Running in Tests in Random Order
***** ***** ***** ***** ***** ***** **
Enable ZTEST framework's :kconfig:option: `CONFIG_ZTEST_SHUFFLE` config option to
run your tests in random order. This can be beneficial for identifying
2023-11-10 12:29:28 +01:00
dependencies between test cases. For native_sim platforms, you can provide
2022-01-31 19:12:54 +01:00
the seed to the random number generator by providing `` -seed=value `` as an
argument to twister. See :ref: `Shuffling Test Sequence <ztest_shuffle>` for more
details.
2023-04-05 15:21:44 +02:00
Robot Framework Tests
***** ***** ***** ***** *
Zephyr supports `Robot Framework <https://robotframework.org/> `_ as one of solutions for automated testing.
Robot files allow you to express interactive test scenarios in human-readable text format and execute them in simulation or against hardware.
At this moment Zephyr integration supports running Robot tests in the `Renode <https://renode.io/> `_ simulation framework.
To execute a Robot test suite with twister, run the following command:
.. tabs ::
.. group-tab :: Linux
.. code-block :: bash
$ ./scripts/twister --platform hifive1 --test samples/subsys/shell/shell_module/sample.shell.shell_module.robot
.. group-tab :: Windows
.. code-block :: bat
python .\scripts\twister --platform hifive1 --test samples/subsys/shell/shell_module/sample.shell.shell_module.robot
It's also possible to run it by `west` directly, with:
.. code-block :: bash
$ ROBOT_FILES=shell_module.robot west build -p -b hifive1 -s samples/subsys/shell/shell_module -t run_renode_test
Writing Robot tests
===================
For the list of keywords provided by the Robot Framework itself, refer to `the official Robot documentation <https://robotframework.org/robotframework/> `_ .
Information on writing and running Robot Framework tests in Renode can be found in `the testing section <https://renode.readthedocs.io/en/latest/introduction/testing.html> `_ of Renode documentation.
It provides a list of the most commonly used keywords together with links to the source code where those are defined.
It's possible to extend the framework by adding new keywords expressed directly in Robot test suite files, as an external Python library or, like Renode does it, dynamically via XML-RPC.
For details see the `extending Robot Framework <https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#extending-robot-framework> `_ section in the official Robot documentation.
2024-01-09 11:38:51 +01:00
Running a single testsuite
==========================
To run a single testsuite instead of a whole group of test you can run:
.. code-block :: bash
$ twister -p qemu_riscv32 -s tests/kernel/interrupt/arch.shared_interrupt