1.. _twister_script: 2 3Test Runner (Twister) 4##################### 5 6Twister scans for the set of test applications in the git repository 7and attempts to execute them. By default, it tries to build each test 8application on boards marked as default in the board definition file. 9 10The default options will build the majority of the test applications on a 11defined set of boards and will run in an emulated environment if available for 12the architecture or configuration being tested. 13 14Because of the limited test execution coverage, twister 15cannot guarantee local changes will succeed in the full build 16environment, but it does sufficient testing by building samples and 17tests for different boards and different configurations to help keep the 18complete code tree buildable. 19 20When using (at least) one ``-v`` option, twister's console output 21shows for every test application how the test is run (qemu, native_sim, etc.) or 22whether the binary was just built. The resultant 23:ref:`status <twister_statuses>` 24of a test is likewise reported in the ``twister.json`` and other report files. 25There are a few reasons why twister only builds a test and doesn't run it: 26 27- The test is marked as ``build_only: true`` in its ``.yaml`` 28 configuration file. 29- The test configuration has defined a ``harness`` but you don't have 30 it or haven't set it up. 31- The target device is not connected and not available for flashing 32- You or some higher level automation invoked twister with 33 ``--build-only``. 34 35To run the script in the local tree, follow the steps below: 36 37.. tabs:: 38 39 .. group-tab:: Linux 40 41 .. code-block:: bash 42 43 $ source zephyr-env.sh 44 $ ./scripts/twister 45 46 .. group-tab:: Windows 47 48 .. code-block:: bat 49 50 zephyr-env.cmd 51 python .\scripts\twister 52 53 54If you have a system with a large number of cores and plenty of free storage space, 55you can build and run all possible tests using the following options: 56 57.. tabs:: 58 59 .. group-tab:: Linux 60 61 .. code-block:: bash 62 63 $ ./scripts/twister --all --enable-slow 64 65 .. group-tab:: Windows 66 67 .. code-block:: bat 68 69 python .\scripts\twister --all --enable-slow 70 71This will build for all available boards and run all applicable tests in 72a simulated (for example QEMU) environment. 73 74If you want to run tests on one or more specific platforms, you can use 75the ``--platform`` option, it is a platform filter for testing, with this 76option, test suites will only be built/run on the platforms specified. 77This option also supports different revisions of one same board, 78you can use ``--platform board@revision`` to test on a specific revision. 79 80The list of command line options supported by twister can be viewed using: 81 82.. tabs:: 83 84 .. group-tab:: Linux 85 86 .. code-block:: bash 87 88 $ ./scripts/twister --help 89 90 .. group-tab:: Windows 91 92 .. code-block:: bat 93 94 python .\scripts\twister --help 95 96 97Board Configuration 98******************* 99 100To build tests for a specific board and to execute some of the tests on real 101hardware or in an emulation environment such as QEMU a board configuration file 102is required which is generic enough to be used for other tasks that require a 103board inventory with details about the board and its configuration that is only 104available during build time otherwise. 105 106The board metadata file is located in the board directory and is structured 107using the YAML markup language. The example below shows a board with a data 108required for best test coverage for this specific board: 109 110.. code-block:: yaml 111 112 identifier: frdm_k64f 113 name: NXP FRDM-K64F 114 type: mcu 115 arch: arm 116 toolchain: 117 - zephyr 118 - gnuarmemb 119 supported: 120 - arduino_gpio 121 - arduino_i2c 122 - netif:eth 123 - adc 124 - i2c 125 - nvs 126 - spi 127 - gpio 128 - usb_device 129 - watchdog 130 - can 131 - pwm 132 testing: 133 default: true 134 135 136identifier: 137 A string that matches how the board is defined in the build system. This same 138 string is used when building, for example when calling ``west build`` or 139 ``cmake``: 140 141 .. code-block:: console 142 143 # with west 144 west build -b reel_board 145 # with cmake 146 cmake -DBOARD=reel_board .. 147 148name: 149 The actual name of the board as it appears in marketing material. 150type: 151 Type of the board or configuration, currently we support 2 types: mcu, qemu 152simulation: 153 Simulator(s) used to simulate the platform, e.g. qemu. 154 155 .. code-block:: yaml 156 157 simulation: 158 - name: qemu 159 - name: armfvp 160 exec: FVP_Some_Platform 161 - name: custom 162 exec: AnotherBinary 163 164 By default, tests will be executed using the first entry in the simulation array. Another 165 simulation can be selected with ``--simulation <simulation_name>``. 166 The ``exec`` attribute is optional. If it is set but the required simulator is not available, the 167 tests will be built only. 168 If it is not set and the required simulator is not available the tests will fail to run. 169 The simulation name must match one of the element of ``SUPPORTED_EMU_PLATFORMS``. 170arch: 171 Architecture of the board 172toolchain: 173 The list of supported toolchains that can build this board. This should match 174 one of the values used for :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` when building on the command line 175ram: 176 Available RAM on the board (specified in KB). This is used to match test scenario 177 requirements. If not specified we default to 128KB. 178flash: 179 Available FLASH on the board (specified in KB). This is used to match test scenario 180 requirements. If not specified we default to 512KB. 181supported: 182 A list of features this board supports. This can be specified as a single word 183 feature or as a variant of a feature class. For example: 184 185 .. code-block:: yaml 186 187 supported: 188 - pci 189 190 This indicates the board does support PCI. You can make a test scenario build or 191 run only on such boards, or: 192 193 .. code-block:: yaml 194 195 supported: 196 - netif:eth 197 - sensor:bmi16 198 199 A test scenario can depend on 'eth' to only test ethernet or on 'netif' to run 200 on any board with a networking interface. 201 202testing: 203 testing relating keywords to provide best coverage for the features of this 204 board. 205 206.. _twister_default_testing_board: 207 208 binaries: 209 A list of custom binaries to be kept for device testing. 210 default: [True|False]: 211 This is a default board, it will tested with the highest priority and is 212 covered when invoking the simplified twister without any additional 213 arguments. 214 ignore_tags: 215 Do not attempt to build (and therefore run) tests marked with this list of 216 tags. 217 only_tags: 218 Only execute tests with this list of tags on a specific platform. 219 220 .. _twister_board_timeout_multiplier: 221 222 timeout_multiplier: <float> (default 1) 223 Multiply each test scenario timeout by specified ratio. This option allows to tune timeouts only 224 for required platform. It can be useful in case naturally slow platform I.e.: HW board with 225 power-efficient but slow CPU or simulation platform which can perform instruction accurate 226 simulation but does it slowly. 227 228env: 229 A list of environment variables. Twister will check if all these environment variables are set, 230 and otherwise skip this platform. This allows the user to define a platform which should be 231 used, for example, only if some required software or hardware is present, and to signal that 232 presence to twister using these environment variables. 233 234.. _twister_tests_long_version: 235 236Tests 237****** 238 239Tests are detected by the presence of a ``testcase.yaml`` or a ``sample.yaml`` 240files in the application's project directory. This test application 241configuration file may contain one or more entries in the ``tests:`` section each 242identifying a Test Scenario. 243 244.. _twister_test_project_diagram: 245 246.. figure:: figures/twister_test_project.svg 247 :alt: Twister and a Test application project. 248 :figclass: align-center 249 250 Twister and a Test application project. 251 252 253Test application configurations are written using the YAML syntax and share the 254same structure as samples. 255 256A Test Scenario is a set of conditions and variables defined in a Test Scenario 257entry, under which a set of Test Suites will be built and executed. 258 259A Test Suite is a collection of Test Cases which are intended to be used to test 260a software program to ensure it meets certain requirements. The Test Cases in a 261Test Suite are either related or meant to be executed together. 262 263Test Scenario, Test Suite, and Test Case names must follow to these basic rules: 264 265#. The format of the Test Scenario identifier shall be a string without any spaces or 266 special characters (allowed characters: alphanumeric and [\_=]) consisting 267 of multiple sections delimited with a dot (``.``). 268 269#. Each Test Scenario identifier shall start with a section name followed by a 270 subsection names delimited with a dot (``.``). For example, a test scenario 271 that covers semaphores in the kernel shall start with ``kernel.semaphore``. 272 273#. All Test Scenario identifiers within a Test Configuration (``testcase.yaml`` file) 274 need to be unique. 275 For example a ``testcase.yaml`` file covering semaphores in the kernel can have: 276 277 * ``kernel.semaphore``: For general semaphore tests 278 * ``kernel.semaphore.stress``: Stress testing semaphores in the kernel. 279 280#. The full canonical name of a Test Suite is: 281 ``<Test Application Project path>/<Test Scenario identifier>`` 282 283#. Depending on the Test Suite implementation, its Test Case identifiers consist 284 of **at least three sections** delimited with a dot (``.``): 285 286 * **Ztest tests**: 287 a Test Scenario identifier from the corresponding ``testcase.yaml`` file, 288 a Ztest suite name, and a Ztest test name: 289 ``<Test Scenario identifier>.<Ztest suite name>.<Ztest test name>`` 290 291 * **Standalone tests and samples**: 292 a Test Scenario identifier from the corresponding ``testcase.yaml`` (or 293 ``sample.yaml``) file where the last section signifies the standalone 294 Test Case name, for example: ``debug.coredump.logging_backend``. 295 296 297The ``--no-detailed-test-id`` command line option modifies the above rules in this way: 298 299#. A Test Suite name has only ``<Test Scenario identifier>`` component. 300 Its Application Project path can be found in ``twister.json`` report as ``path:`` property. 301 302#. With short Test Suite names in this mode, all corresponding Test Scenario names 303 must be unique for the Twister execution scope. 304 305#. **Ztest** Test Case names have only Ztest components ``<Ztest suite name>.<Ztest test name>``. 306 Its parent Test Suite name equals to the corresponding Test Scenario identifier. 307 308 309The following is an example test configuration with a few options that are 310explained in this document. 311 312 313 .. code-block:: yaml 314 315 tests: 316 bluetooth.gatt: 317 build_only: true 318 platform_allow: qemu_cortex_m3 qemu_x86 319 tags: bluetooth 320 bluetooth.gatt.br: 321 build_only: true 322 extra_args: CONF_FILE="prj_br.conf" 323 filter: not CONFIG_DEBUG 324 platform_exclude: up_squared 325 platform_allow: qemu_cortex_m3 qemu_x86 326 tags: bluetooth 327 328 329A sample with tests will have the same structure with additional information 330related to the sample and what is being demonstrated: 331 332 .. code-block:: yaml 333 334 sample: 335 name: hello world 336 description: Hello World sample, the simplest Zephyr application 337 tests: 338 sample.basic.hello_world: 339 build_only: true 340 tags: tests 341 min_ram: 16 342 sample.basic.hello_world.singlethread: 343 build_only: true 344 extra_args: CONF_FILE=prj_single.conf 345 filter: not CONFIG_BT 346 tags: tests 347 min_ram: 16 348 349A Test Scenario entry in the ``tests:`` YAML dictionary has its Test Scenario 350identifier as a key. 351 352Each Test Scenario entry in the Test Application configuration can define the 353following key/value pairs: 354 355.. _test_config_args: 356 357tags: <list of tags> (required) 358 A set of string tags for the test scenario. Usually pertains to 359 functional domains but can be anything. Command line invocations 360 of this script can filter the set of tests to run based on tag. 361 362skip: <True|False> (default False) 363 skip test scenario unconditionally. This can be used for broken tests for 364 example. 365 366slow: <True|False> (default False) 367 Don't run this test scenario unless ``--enable-slow`` or ``--enable-slow-only`` was 368 passed in on the command line. Intended for time-consuming test scenarios that 369 are only run under certain circumstances, like daily builds. These test 370 scenarios are still compiled. 371 372extra_args: <list of extra arguments> 373 Extra arguments to pass to build tool when building or running the 374 test scenario. 375 376 Using namespacing, it is possible to apply extra_args only to some 377 hardware. Currently architectures/platforms/simulation are supported: 378 379 .. code-block:: yaml 380 381 common: 382 tags: drivers adc 383 tests: 384 test: 385 depends_on: adc 386 test_async: 387 extra_args: 388 - arch:x86:CONFIG_ADC_ASYNC=y 389 - platform:qemu_x86:CONFIG_DEBUG=y 390 - platform:mimxrt1060_evk:SHIELD=rk043fn66hs_ctg 391 - simulation:qemu:CONFIG_MPU=y 392 393extra_configs: <list of extra configurations> 394 Extra configuration options to be merged with a main prj.conf 395 when building or running the test scenario. For example: 396 397 .. code-block:: yaml 398 399 common: 400 tags: drivers adc 401 tests: 402 test: 403 depends_on: adc 404 test_async: 405 extra_configs: 406 - CONFIG_ADC_ASYNC=y 407 408 Using namespacing, it is possible to apply a configuration only to some 409 hardware. Currently both architectures and platforms are supported: 410 411 .. code-block:: yaml 412 413 common: 414 tags: drivers adc 415 tests: 416 test: 417 depends_on: adc 418 test_async: 419 extra_configs: 420 - arch:x86:CONFIG_ADC_ASYNC=y 421 - platform:qemu_x86:CONFIG_DEBUG=y 422 423 424build_only: <True|False> (default False) 425 If true, twister will not try to run the test even if the test is runnable 426 on the platform. 427 428 This keyword is reserved for tests that are used to test if some code 429 actually builds. A ``build_only`` test is not designed to be run in any 430 environment and should not be testing any functionality, it only verifies 431 that the code builds. 432 433 This option is often used to test drivers and the fact that they are correctly 434 enabled in Zephyr and that the code builds, for example sensor drivers. Such 435 test shall not be used to verify the functionality of the driver. 436 437build_on_all: <True|False> (default False) 438 If true, attempt to build test scenario on all available platforms. This is mostly 439 used in CI for increased coverage. Do not use this flag in new tests. 440 441depends_on: <list of features> 442 A board or platform can announce what features it supports, this option 443 will enable the test only those platforms that provide this feature. 444 445levels: <list of levels> 446 Test levels this test should be part of. If a level is present, this 447 test will be selectable using the command line option ``--level <level name>`` 448 449min_ram: <integer> 450 estimated minimum amount of RAM in KB needed for this test to build and run. This is 451 compared with information provided by the board metadata. 452 453min_flash: <integer> 454 estimated minimum amount of ROM in KB needed for this test to build and run. This is 455 compared with information provided by the board metadata. 456 457.. _twister_test_case_timeout: 458 459timeout: <number of seconds> 460 Length of time to run test before automatically killing it. 461 Default to 60 seconds. 462 463arch_allow: <list of arches, such as x86, arm, arc> 464 Set of architectures that this test scenario should only be run for. 465 466arch_exclude: <list of arches, such as x86, arm, arc> 467 Set of architectures that this test scenario should not run on. 468 469vendor_allow: <list of vendors> 470 Set of platform vendors that this test scenario should only be run for. The 471 vendor is defined as part of the board definition. Boards associated with 472 this vendors will be included. Other boards, including those without a 473 vendor will be excluded. 474 475vendor_exclude: <list of vendors> 476 Set of platform vendors that this test scenario should not run on. 477 The vendor is defined as part of the board. Boards associated with this 478 vendors will be excluded. 479 480platform_allow: <list of platforms> 481 Set of platforms that this test scenario should only be run for. Do not use 482 this option to limit testing or building in CI due to time or resource 483 constraints, this option should only be used if the test or sample can 484 only be run on the allowed platform and nothing else. 485 486integration_platforms: <YML list of platforms/boards> 487 This option limits the scope to the listed platforms when twister is 488 invoked with the ``--integration`` option. Use this instead of 489 platform_allow if the goal is to limit scope due to timing or 490 resource constraints. 491 492integration_toolchains: <YML list of toolchain variants> 493 This option expands the scope to all the listed toolchains variants and 494 adds another vector of testing where desired. By default, test 495 configurations are generated based on the toolchain configured in the environment: 496 497 test scenario -> platforms1 -> toolchain1 498 test scenario -> platforms2 -> toolchain1 499 500 501 When a platform supports multiple toolchains that are available during the 502 twister run, it is possible to expand the test configurations to include 503 additional tests for each toolchain. For example, if a platform supports 504 toolchains ``toolchain1`` and ``toolchain2``, and the test scenario 505 includes: 506 507 .. code-block:: yaml 508 509 integration_toolchains: 510 - toolchain1 511 - toolchain2 512 513 the following configurations are generated: 514 515 test scenario -> platforms1 -> toolchain1 516 test scenario -> platforms1 -> toolchain2 517 test scenario -> platforms2 -> toolchain1 518 test scenario -> platforms2 -> toolchain2 519 520 521 .. note:: 522 523 This functionality is evaluated always and is not limited to the 524 ``--integration`` option. 525 526platform_exclude: <list of platforms> 527 Set of platforms that this test scenario should not run on. 528 529extra_sections: <list of extra binary sections> 530 When computing sizes, twister will report errors if it finds 531 extra, unexpected sections in the Zephyr binary unless they are named 532 here. They will not be included in the size calculation. 533 534sysbuild: <True|False> (default False) 535 Build the project using sysbuild infrastructure. Only the main project's 536 generated devicetree and Kconfig will be used for filtering tests. 537 on device testing must use the hardware map, or west flash to load 538 the images onto the target. The ``--erase`` option of west flash is 539 not supported with this option. Usage of unsupported options will result 540 in tests requiring sysbuild support being skipped. 541 542harness: <string> 543 A harness keyword in the ``testcase.yaml`` file identifies a Twister 544 harness needed to run a test successfully. A harness is a feature of 545 Twister and implemented by Twister, some harnesses are defined as 546 placeholders and have no implementation yet. 547 548 A harness can be seen as the handler that needs to be implemented in 549 Twister to be able to evaluate if a test passes criteria. For example, a 550 keyboard harness is set on tests that require keyboard interaction to reach 551 verdict on whether a test has passed or failed, however, Twister lack this 552 harness implementation at the moment. 553 554 Supported harnesses: 555 556 - ztest 557 - test 558 - console 559 - pytest 560 - gtest 561 - robot 562 - ctest 563 - shell 564 565 See :ref:`twister_harnesses` for more information. 566 567platform_key: <list of platform attributes> 568 Often a test needs to only be built and run once to qualify as passing. 569 Imagine a library of code that depends on the platform architecture where 570 passing the test on a single platform for each arch is enough to qualify the 571 tests and code as passing. The platform_key attribute enables doing just 572 that. 573 574 For example to key on (arch, simulation) to ensure a test is run once 575 per arch and simulation (as would be most common): 576 577 .. code-block:: yaml 578 579 platform_key: 580 - arch 581 - simulation 582 583 Adding platform (board) attributes to include things such as soc name, 584 soc family, and perhaps sets of IP blocks implementing each peripheral 585 interface would enable other interesting uses. For example, this could enable 586 building and running SPI tests once for each unique IP block. 587 588harness_config: <harness configuration options> 589 Extra harness configuration options to be used to select a board and/or 590 for handling generic Console with regex matching. Config can announce 591 what features it supports. This option will enable the test to run on 592 only those platforms that fulfill this external dependency. 593 594 595 fixture: <expression> 596 Specify a test scenario dependency on an external device(e.g., sensor), 597 and identify setups that fulfill this dependency. It depends on 598 specific test setup and board selection logic to pick the particular 599 board(s) out of multiple boards that fulfill the dependency in an 600 automation setup based on ``fixture`` keyword. Some sample fixture names 601 are i2c_hts221, i2c_bme280, i2c_FRAM, ble_fw and gpio_loop. 602 603 Only one fixture can be defined per test scenario and the fixture name has to 604 be unique across all tests in the test suite. 605 606 607 The following is an example yaml file with robot harness_config options. 608 609 .. code-block:: yaml 610 611 tests: 612 robot.example: 613 harness: robot 614 harness_config: 615 robot_testsuite: [robot file path] 616 617 It can be more than one test suite using a list. 618 619 .. code-block:: yaml 620 621 tests: 622 robot.example: 623 harness: robot 624 harness_config: 625 robot_testsuite: 626 - [robot file path 1] 627 - [robot file path 2] 628 - [robot file path n] 629 630 One or more options can be passed to robotframework. 631 632 .. code-block:: yaml 633 634 tests: 635 robot.example: 636 harness: robot 637 harness_config: 638 robot_testsuite: [robot file path] 639 robot_option: 640 - --exclude tag 641 - --stop-on-error 642 643filter: <expression> 644 Filter whether the test scenario should be run by evaluating an expression 645 against an environment containing the following values: 646 647 .. code-block:: none 648 649 { ARCH : <architecture>, 650 PLATFORM : <platform>, 651 <all CONFIG_* key/value pairs in the test's generated defconfig>, 652 *<env>: any environment variable available 653 } 654 655 Twister will first evaluate the expression to find if a "limited" cmake call, i.e. using package_helper cmake script, 656 can be done. Existence of "dt_*" entries indicates devicetree is needed. 657 Existence of "CONFIG*" entries indicates kconfig is needed. 658 If there are no other types of entries in the expression a filtration can be done without creating a complete build system. 659 If there are entries of other types a full cmake is required. 660 661 The grammar for the expression language is as follows: 662 663 .. code-block:: antlr 664 665 expression : expression 'and' expression 666 | expression 'or' expression 667 | 'not' expression 668 | '(' expression ')' 669 | symbol '==' constant 670 | symbol '!=' constant 671 | symbol '<' NUMBER 672 | symbol '>' NUMBER 673 | symbol '>=' NUMBER 674 | symbol '<=' NUMBER 675 | symbol 'in' list 676 | symbol ':' STRING 677 | symbol 678 ; 679 680 list : '[' list_contents ']'; 681 682 list_contents : constant (',' constant)*; 683 684 constant : NUMBER | STRING; 685 686 For the case where ``expression ::= symbol``, it evaluates to ``true`` 687 if the symbol is defined to a non-empty string. 688 689 Operator precedence, starting from lowest to highest: 690 691 * or (left associative) 692 * and (left associative) 693 * not (right associative) 694 * all comparison operators (non-associative) 695 696 ``arch_allow``, ``arch_exclude``, ``platform_allow``, ``platform_exclude`` 697 are all syntactic sugar for these expressions. For instance: 698 699 .. code-block:: none 700 701 arch_exclude = x86 arc 702 703 Is the same as: 704 705 .. code-block:: none 706 707 filter = not ARCH in ["x86", "arc"] 708 709 The ``:`` operator compiles the string argument as a regular expression, 710 and then returns a true value only if the symbol's value in the environment 711 matches. For example, if ``CONFIG_SOC="stm32f107xc"`` then 712 713 .. code-block:: none 714 715 filter = CONFIG_SOC : "stm.*" 716 717 Would match it. 718 719required_snippets: <list of needed snippets> 720 :ref:`Snippets <snippets>` are supported in twister for test scenarios that 721 require them. As with normal applications, twister supports using the base 722 zephyr snippet directory and test application directory for finding 723 snippets. Listed snippets will filter supported tests for boards (snippets 724 must be compatible with a board for the test to run on them, they are not 725 optional). 726 727 The following is an example yaml file with 2 required snippets. 728 729 .. code-block:: yaml 730 731 tests: 732 snippet.example: 733 required_snippets: 734 - cdc-acm-console 735 - user-snippet-example 736 737The set of test scenarios that actually run depends on directives in the test scenario 738filed and options passed in on the command line. If there is any confusion, 739running with ``-v`` or examining the discard report 740(:file:`twister_discard.csv`) can help show why particular test scenarios were 741skipped. 742 743Metrics (such as pass/fail state and binary size) for the last code 744release are stored in ``scripts/release/twister_last_release.csv``. 745To update this, pass the ``--all --release`` options. 746 747To load arguments from a file, add ``+`` before the file name, e.g., 748``+file_name``. File content must be one or more valid arguments separated by 749line break instead of white spaces. 750 751Most everyday users will run with no arguments. 752 753.. _twister_harnesses: 754 755Harnesses 756********* 757 758Harnesses ``ztest``, ``gtest`` and ``console`` are based on parsing of the 759output and matching certain phrases. ``ztest`` and ``gtest`` harnesses look 760for pass/fail/etc. frames defined in those frameworks. 761 762Some widely used harnesses that are not supported yet: 763 764- keyboard 765- net 766- bluetooth 767 768The following is an example yaml file with a few harness_config options. 769 770.. code-block:: yaml 771 772 sample: 773 name: HTS221 Temperature and Humidity Monitor 774 common: 775 tags: sensor 776 harness: console 777 harness_config: 778 type: multi_line 779 ordered: false 780 regex: 781 - "Temperature:(.*)C" 782 - "Relative Humidity:(.*)%" 783 fixture: i2c_hts221 784 tests: 785 test: 786 tags: sensors 787 depends_on: i2c 788 789Ctest 790===== 791 792ctest_args: <list of arguments> (default empty) 793 Specify a list of additional arguments to pass to ``ctest`` e.g.: 794 ``ctest_args: [‘--repeat until-pass:5’]``. Note that 795 ``--ctest-args`` can be passed multiple times to pass several arguments 796 to the ctest. 797 798 799Gtest 800===== 801 802Use ``gtest`` harness if you've already got tests written in the gTest 803framework and do not wish to update them to zTest. 804 805Pytest 806====== 807 808The :ref:`pytest harness <integration_with_pytest>` is used to execute pytest 809test suites in the Zephyr test. The following options apply to the pytest harness: 810 811.. _pytest_root: 812 813pytest_root: <list of pytest testpaths> (default pytest) 814 Specify a list of pytest directories, files or subtests that need to be 815 executed when a test scenario begins to run. The default pytest directory is 816 ``pytest``. After the pytest run is finished, Twister will check if 817 the test scenario passed or failed according to the pytest report. 818 As an example, a list of valid pytest roots is presented below: 819 820 .. code-block:: yaml 821 822 harness_config: 823 pytest_root: 824 - "pytest/test_shell_help.py" 825 - "../shell/pytest/test_shell.py" 826 - "/tmp/test_shell.py" 827 - "~/tmp/test_shell.py" 828 - "$ZEPHYR_BASE/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py" 829 - "pytest/test_shell_help.py::test_shell2_sample" # select pytest subtest 830 - "pytest/test_shell_help.py::test_shell2_sample[param_a]" # select pytest parametrized subtest 831 832.. _pytest_args: 833 834pytest_args: <list of arguments> (default empty) 835 Specify a list of additional arguments to pass to ``pytest`` e.g.: 836 ``pytest_args: [‘-k=test_method’, ‘--log-level=DEBUG’]``. Note that 837 ``--pytest-args`` can be passed multiple times to pass several arguments 838 to the pytest. 839 840.. _pytest_dut_scope: 841 842pytest_dut_scope: <function|class|module|package|session> (default function) 843 The scope for which ``dut`` and ``shell`` pytest fixtures are shared. 844 If the scope is set to ``function``, DUT is launched for every test case 845 in python script. For ``session`` scope, DUT is launched only once. 846 847 848 The following is an example yaml file with pytest harness_config options, 849 default pytest_root name "pytest" will be used if pytest_root not specified. 850 please refer the examples in samples/subsys/testsuite/pytest/. 851 852 .. code-block:: yaml 853 854 common: 855 harness: pytest 856 tests: 857 pytest.example.directories: 858 harness_config: 859 pytest_root: 860 - pytest_dir1 861 - $ENV_VAR/samples/test/pytest_dir2 862 pytest.example.files_and_subtests: 863 harness_config: 864 pytest_root: 865 - pytest/test_file_1.py 866 - test_file_2.py::test_A 867 - test_file_2.py::test_B[param_a] 868 869Console 870======= 871 872The ``console`` harness tells Twister to parse a test's text output for a 873regex defined in the test's YAML file. 874 875The following options are currently supported: 876 877type: <one_line|multi_line> (required) 878 Depends on the regex string to be matched 879 880regex: <list of regular expressions> (required) 881 Strings with regular expressions to match with the test's output 882 to confirm the test runs as expected. 883 884ordered: <True|False> (default False) 885 Check the regular expression strings in orderly or randomly fashion 886 887record: <recording options> (optional) 888 regex: <list of regular expressions> (required) 889 Regular expressions with named subgroups to match data fields found 890 in the test instance's output lines where it provides some custom data 891 for further analysis. These records will be written into the build 892 directory ``recording.csv`` file as well as ``recording`` property 893 of the test suite object in ``twister.json``. 894 895 With several regular expressions given, each of them will be applied 896 to each output line producing either several different records from 897 the same output line, or different records from different lines, 898 or similar records from different lines. 899 900 The .CSV file will have as many columns as there are fields detected 901 in all records; missing values are filled by empty strings. 902 903 For example, to extract three data fields ``metric``, ``cycles``, 904 ``nanoseconds``: 905 906 .. code-block:: yaml 907 908 record: 909 regex: 910 - "(?P<metric>.*):(?P<cycles>.*) cycles, (?P<nanoseconds>.*) ns" 911 912 merge: <True|False> (default False) 913 Allows to keep only one record in a test instance with all the data 914 fields extracted by the regular expressions. Fields with the same name 915 will be put into lists ordered as their appearance in recordings. 916 It is possible for such multi value fields to have different number 917 of values depending on the regex rules and the test's output. 918 919 as_json: <list of regex subgroup names> (optional) 920 Data fields, extracted by the regular expressions into named subgroups, 921 which will be additionally parsed as JSON encoded strings and written 922 into ``twister.json`` as nested ``recording`` object properties. 923 The corresponding ``recording.csv`` columns will contain JSON strings 924 as-is. 925 926 Using this option, a test log can convey layered data structures 927 passed from the test image for further analysis with summary results, 928 traces, statistics, etc. 929 930 For example, this configuration: 931 932 .. code-block:: yaml 933 934 record: 935 regex: "RECORD:(?P<type>.*):DATA:(?P<metrics>.*)" 936 as_json: [metrics] 937 938 when matched to a test log string: 939 940 .. code-block:: none 941 942 RECORD:jitter_drift:DATA:{"rollovers":0, "mean_us":1000.0} 943 944 will be reported in ``twister.json`` as: 945 946 .. code-block:: json 947 948 "recording":[ 949 { 950 "type":"jitter_drift", 951 "metrics":{ 952 "rollovers":0, 953 "mean_us":1000.0 954 } 955 } 956 ] 957 958Robot 959===== 960 961The ``robot`` harness is used to execute Robot Framework test suites 962in the Renode simulation framework. 963 964robot_testsuite: <robot file path> (default empty) 965 Specify one or more paths to a file containing a Robot Framework test suite to be run. 966 967robot_option: <robot option> (default empty) 968 One or more options to be send to robotframework. 969 970Bsim 971==== 972 973Harness ``bsim`` is implemented in limited way - it helps only to copy the 974final executable (``zephyr.exe``) from build directory to BabbleSim's 975``bin`` directory (``${BSIM_OUT_PATH}/bin``). 976 977This action is useful to allow BabbleSim's tests to directly run after. 978By default, the executable file name is (with dots and slashes 979replaced by underscores): ``bs_<platform_name>_<test_path>_<test_scenario_name>``. 980This name can be overridden with the ``bsim_exe_name`` option in 981``harness_config`` section. 982 983bsim_exe_name: <string> 984 If provided, the executable filename when copying to BabbleSim's bin 985 directory, will be ``bs_<platform_name>_<bsim_exe_name>`` instead of the 986 default based on the test path and scenario name. 987 988Shell 989===== 990 991The shell harness is used to execute shell commands and parse the output and utilizes the pytest 992framework and the pytest harness of twister. 993 994The following options apply to the shell harness: 995 996shell_commands: <list of pairs of commands and their expected output> (default empty) 997 Specify a list of shell commands to be executed and their expected output. 998 For example: 999 1000 .. code-block:: yaml 1001 1002 harness_config: 1003 shell_commands: 1004 - command: "kernel cycles" 1005 expected: "cycles: .* hw cycles" 1006 - command: "kernel version" 1007 expected: "Zephyr version .*" 1008 - command: "kernel sleep 100" 1009 1010 1011 If expected output is not provided, the command will be executed and the output 1012 will be logged. 1013 1014shell_commands_file: <string> (default empty) 1015 Specify a file containing test parameters to be used in the test. 1016 The file should contain a list of commands and their expected output. For example: 1017 1018 .. code-block:: yaml 1019 1020 - command: "mpu mtest 1" 1021 expected: "The value is: 0x.*" 1022 - command: "mpu mtest 2" 1023 expected: "The value is: 0x.*" 1024 1025 1026 If no file is specified, the shell harness will use the default file 1027 ``test_shell.yml`` in the test directory. 1028 ``shell_commands`` will take precedence over ``shell_commands_file``. 1029 1030Selecting platform scope 1031************************ 1032 1033One of the key features of Twister is its ability to decide on which platforms a given 1034test scenario should run. This behavior has its roots in Twister being developed as 1035a test runner for Zephyr's CI. With hundreds of available platforms and thousands of 1036tests, the testing tools should be able to adapt the scope and select/filter out what 1037is relevant and what is not. 1038 1039Twister always prepares an initial list of platforms in scope for a given test, 1040based on command line arguments and the :ref:`test's configuration <test_config_args>`. Then, 1041platforms that don't fulfill the conditions required in the configuration yaml 1042(e.g. minimum ram) are filtered out from the scope. 1043Using ``--force-platform`` allows to override filtering caused by ``platform_allow``, 1044``platform_exclude``, ``arch_allow`` and ``arch_exclude`` keys in test configuration 1045files. 1046 1047Command line arguments define the initial scope in the following way: 1048 1049* ``-p/--platform <platform_name>`` (can be used multiple times): only platforms 1050 passed with this argument; 1051* ``-l/--all``: all available platforms; 1052* ``-G/--integration``: all platforms from an ``integration_platforms`` list in 1053 a given test configuration file. If a test has no ``integration_platforms`` 1054 *"scope presumption"* will happen; 1055* No scope argument: *"scope presumption"* will happen. 1056 1057*"Scope presumption"*: A list of Twister's :ref:`default platforms <twister_default_testing_board>` 1058is used as the initial list. If nothing is left after the filtration, the ``platform_allow`` list 1059is used as the initial scope. 1060 1061Managing tests timeouts 1062*********************** 1063 1064There are several parameters which control tests timeouts on various levels: 1065 1066* ``timeout`` option in each test scenario. See :ref:`here <twister_test_case_timeout>` for more 1067 details. 1068* ``timeout_multiplier`` option in board configuration. See 1069 :ref:`here <twister_board_timeout_multiplier>` for more details. 1070* ``--timeout-multiplier`` twister option which can be used to adjust timeouts in exact twister run. 1071 It can be useful in case of simulation platform as simulation time may depend on the host 1072 speed & load or we may select different simulation method (i.e. cycle accurate but slower 1073 one), etc... 1074 1075Overall test scenario timeout is a multiplication of these three parameters. 1076 1077Running in Integration Mode 1078*************************** 1079 1080This mode is used in continuous integration (CI) and other automated 1081environments used to give developers fast feedback on changes. The mode can 1082be activated using the ``--integration`` option of twister and narrows down 1083the scope of builds and tests if applicable to platforms defined under the 1084integration keyword in the test configuration file (``testcase.yaml`` and 1085``sample.yaml``). 1086 1087 1088Running tests on custom emulator 1089******************************** 1090 1091Apart from the already supported QEMU and other simulated environments, Twister 1092supports running any out-of-tree custom emulator defined in the board's :file:`board.cmake`. 1093To use this type of simulation, add the following properties to 1094:file:`custom_board/custom_board.yaml`: 1095 1096.. code-block:: yaml 1097 1098 simulation: 1099 - name: custom 1100 exec: <name_of_emu_binary> 1101 1102This tells Twister that the board is using a custom emulator called ``<name_of_emu_binary>``, 1103make sure this binary exists in the PATH. 1104 1105Then, in :file:`custom_board/board.cmake`, set the supported emulation platforms to ``custom``: 1106 1107.. code-block:: cmake 1108 1109 set(SUPPORTED_EMU_PLATFORMS custom) 1110 1111Finally, implement the ``run_custom`` target in :file:`custom_board/board.cmake`. 1112It should look something like this: 1113 1114.. code-block:: cmake 1115 1116 add_custom_target(run_custom 1117 COMMAND 1118 <name_of_emu_binary to invoke during 'run'> 1119 <any args to be passed to the command, i.e. ${BOARD}, ${APPLICATION_BINARY_DIR}/zephyr/zephyr.elf> 1120 WORKING_DIRECTORY ${APPLICATION_BINARY_DIR} 1121 DEPENDS ${logical_target_for_zephyr_elf} 1122 USES_TERMINAL 1123 ) 1124 1125Running Tests on Hardware 1126************************* 1127 1128Beside being able to run tests in QEMU and other simulated environments, 1129twister supports running most of the tests on real devices and produces 1130reports for each run with detailed FAIL/PASS results. 1131 1132 1133Executing tests on a single device 1134=================================== 1135 1136To use this feature on a single connected device, run twister with 1137the following new options: 1138 1139.. tabs:: 1140 1141 .. group-tab:: Linux 1142 1143 .. code-block:: bash 1144 1145 scripts/twister --device-testing --device-serial /dev/ttyACM0 \ 1146 --device-serial-baud 115200 -p frdm_k64f -T tests/kernel 1147 1148 .. group-tab:: Windows 1149 1150 .. code-block:: bat 1151 1152 python .\scripts\twister --device-testing --device-serial COM1 \ 1153 --device-serial-baud 115200 -p frdm_k64f -T tests/kernel 1154 1155The ``--device-serial`` option denotes the serial device the board is connected to. 1156This needs to be accessible by the user running twister. You can run this on 1157only one board at a time, specified using the ``--platform`` option. 1158 1159The ``--device-serial-baud`` option is only needed if your device does not run at 1160115200 baud. 1161 1162To support devices without a physical serial port, use the ``--device-serial-pty`` 1163option. In this cases, log messages are captured for example using a script. 1164In this case you can run twister with the following options: 1165 1166.. tabs:: 1167 1168 .. group-tab:: Linux 1169 1170 .. code-block:: bash 1171 1172 scripts/twister --device-testing --device-serial-pty "script.py" \ 1173 -p intel_adsp/cavs25 -T tests/kernel 1174 1175 .. group-tab:: Windows 1176 1177 .. note:: 1178 1179 Not supported on Windows OS 1180 1181The script is user-defined and handles delivering the messages which can be 1182used by twister to determine the test execution status. 1183 1184The ``--device-flash-timeout`` option allows to set explicit timeout on the 1185device flash operation, for example when device flashing takes significantly 1186large time. 1187 1188The ``--device-flash-with-test`` option indicates that on the platform 1189the flash operation also executes a test scenario, so the flash timeout is 1190increased by a test scenario timeout. 1191 1192Executing tests on multiple devices 1193=================================== 1194 1195To build and execute tests on multiple devices connected to the host PC, a 1196hardware map needs to be created with all connected devices and their 1197details such as the serial device, baud and their IDs if available. 1198Run the following command to produce the hardware map: 1199 1200.. tabs:: 1201 1202 .. group-tab:: Linux 1203 1204 .. code-block:: bash 1205 1206 ./scripts/twister --generate-hardware-map map.yml 1207 1208 .. group-tab:: Windows 1209 1210 .. code-block:: bat 1211 1212 python .\scripts\twister --generate-hardware-map map.yml 1213 1214The generated hardware map file (map.yml) will have the list of connected 1215devices, for example: 1216 1217.. tabs:: 1218 1219 .. group-tab:: Linux 1220 1221 .. code-block:: yaml 1222 1223 - connected: true 1224 id: OSHW000032254e4500128002ab98002784d1000097969900 1225 platform: unknown 1226 product: DAPLink CMSIS-DAP 1227 runner: pyocd 1228 serial: /dev/cu.usbmodem146114202 1229 - connected: true 1230 id: 000683759358 1231 platform: unknown 1232 product: J-Link 1233 runner: unknown 1234 serial: /dev/cu.usbmodem0006837593581 1235 1236 .. group-tab:: Windows 1237 1238 .. code-block:: yaml 1239 1240 - connected: true 1241 id: OSHW000032254e4500128002ab98002784d1000097969900 1242 platform: unknown 1243 product: unknown 1244 runner: unknown 1245 serial: COM1 1246 - connected: true 1247 id: 000683759358 1248 platform: unknown 1249 product: unknown 1250 runner: unknown 1251 serial: COM2 1252 1253 1254Any options marked as ``unknown`` need to be changed and set with the correct 1255values, in the above example the platform names, the products and the runners need 1256to be replaced with the correct values corresponding to the connected hardware. 1257In this example we are using a reel_board and an nrf52840dk/nrf52840: 1258 1259.. tabs:: 1260 1261 .. group-tab:: Linux 1262 1263 .. code-block:: yaml 1264 1265 - connected: true 1266 id: OSHW000032254e4500128002ab98002784d1000097969900 1267 platform: reel_board 1268 product: DAPLink CMSIS-DAP 1269 runner: pyocd 1270 serial: /dev/cu.usbmodem146114202 1271 baud: 9600 1272 - connected: true 1273 id: 000683759358 1274 platform: nrf52840dk/nrf52840 1275 product: J-Link 1276 runner: nrfjprog 1277 serial: /dev/cu.usbmodem0006837593581 1278 baud: 9600 1279 1280 .. group-tab:: Windows 1281 1282 .. code-block:: yaml 1283 1284 - connected: true 1285 id: OSHW000032254e4500128002ab98002784d1000097969900 1286 platform: reel_board 1287 product: DAPLink CMSIS-DAP 1288 runner: pyocd 1289 serial: COM1 1290 baud: 9600 1291 - connected: true 1292 id: 000683759358 1293 platform: nrf52840dk/nrf52840 1294 product: J-Link 1295 runner: nrfjprog 1296 serial: COM2 1297 baud: 9600 1298 1299The baud entry is only needed if not running at 115200. 1300 1301If the map file already exists, then new entries are added and existing entries 1302will be updated. This way you can use one single master hardware map and update 1303it for every run to get the correct serial devices and status of the devices. 1304 1305With the hardware map ready, you can run any tests by pointing to the map 1306 1307.. tabs:: 1308 1309 .. group-tab:: Linux 1310 1311 .. code-block:: bash 1312 1313 ./scripts/twister --device-testing --hardware-map map.yml -T samples/hello_world/ 1314 1315 .. group-tab:: Windows 1316 1317 .. code-block:: bat 1318 1319 python .\scripts\twister --device-testing --hardware-map map.yml -T samples\hello_world 1320 1321The above command will result in twister building tests for the platforms 1322defined in the hardware map and subsequently flashing and running the tests 1323on those platforms. 1324 1325.. note:: 1326 1327 Currently only boards with support for pyocd, nrfjprog, jlink, openocd, or dediprog 1328 are supported with the hardware map features. Boards that require other runners to flash the 1329 Zephyr binary are still work in progress. 1330 1331Hardware map allows to set ``--device-flash-timeout`` and ``--device-flash-with-test`` 1332command line options as ``flash-timeout`` and ``flash-with-test`` fields respectively. 1333These hardware map values override command line options for the particular platform. 1334 1335Serial PTY support using ``--device-serial-pty`` can also be used in the 1336hardware map: 1337 1338.. code-block:: yaml 1339 1340 - connected: true 1341 id: None 1342 platform: intel_adsp/cavs25 1343 product: None 1344 runner: intel_adsp 1345 serial_pty: path/to/script.py 1346 runner_params: 1347 - --remote-host=remote_host_ip_addr 1348 - --key=/path/to/key.pem 1349 1350 1351The runner_params field indicates the parameters you want to pass to the 1352west runner. For some boards the west runner needs some extra parameters to 1353work. It is equivalent to following west and twister commands. 1354 1355.. tabs:: 1356 1357 .. group-tab:: Linux 1358 1359 .. code-block:: bash 1360 1361 west flash --remote-host remote_host_ip_addr --key /path/to/key.pem 1362 1363 twister -p intel_adsp/cavs25 --device-testing --device-serial-pty script.py 1364 --west-flash="--remote-host=remote_host_ip_addr,--key=/path/to/key.pem" 1365 1366 .. group-tab:: Windows 1367 1368 .. note:: 1369 1370 Not supported on Windows OS 1371 1372.. note:: 1373 1374 For serial PTY, the "--generate-hardware-map" option cannot scan it out 1375 and generate a correct hardware map automatically. You have to edit it 1376 manually according to above example. This is because the serial port 1377 of the PTY is not fixed and being allocated in the system at runtime. 1378 1379Fixtures 1380+++++++++ 1381 1382Some tests require additional setup or special wiring specific to the test. 1383Running the tests without this setup or test fixture may fail. A test scenario can 1384specify the fixture it needs which can then be matched with hardware capability 1385of a board and the fixtures it supports via the command line or using the hardware 1386map file. 1387 1388Fixtures are defined in the hardware map file as a list: 1389 1390.. code-block:: yaml 1391 1392 - connected: true 1393 fixtures: 1394 - gpio_loopback 1395 id: 0240000026334e450015400f5e0e000b4eb1000097969900 1396 platform: frdm_k64f 1397 product: DAPLink CMSIS-DAP 1398 runner: pyocd 1399 serial: /dev/ttyACM9 1400 1401When running ``twister`` with ``--device-testing``, the configured fixture 1402in the hardware map file will be matched to test scenarios requesting the same fixtures 1403and these tests will be executed on the boards that provide this fixture. 1404 1405.. figure:: figures/fixtures.svg 1406 :figclass: align-center 1407 1408Fixtures can also be provided via twister command option ``--fixture``, this option 1409can be used multiple times and all given fixtures will be appended as a list. And the 1410given fixtures will be assigned to all boards, this means that all boards set by 1411current twister command can run those test scenarios which request the same fixtures. 1412 1413Some fixtures allow for configuration strings to be appended, separated from the 1414fixture name by a ``:``. Only the fixture name is matched against the fixtures 1415requested by test scenarios. 1416 1417Notes 1418+++++ 1419 1420It may be useful to annotate board descriptions in the hardware map file 1421with additional information. Use the ``notes`` keyword to do this. For 1422example: 1423 1424.. code-block:: yaml 1425 1426 - connected: false 1427 fixtures: 1428 - gpio_loopback 1429 id: 000683290670 1430 notes: An nrf5340dk/nrf5340 is detected as an nrf52840dk/nrf52840 with no serial 1431 port, and three serial ports with an unknown platform. The board id of the serial 1432 ports is not the same as the board id of the development kit. If you regenerate 1433 this file you will need to update serial to reference the third port, and platform 1434 to nrf5340dk/nrf5340/cpuapp or another supported board target. 1435 platform: nrf52840dk/nrf52840 1436 product: J-Link 1437 runner: jlink 1438 serial: null 1439 1440Overriding Board Identifier 1441+++++++++++++++++++++++++++ 1442 1443When (re-)generated the hardware map file will contain an ``id`` keyword 1444that serves as the argument to ``--board-id`` when flashing. In some 1445cases the detected ID is not the correct one to use, for example when 1446using an external J-Link probe. The ``probe_id`` keyword overrides the 1447``id`` keyword for this purpose. For example: 1448 1449.. code-block:: yaml 1450 1451 - connected: false 1452 id: 0229000005d9ebc600000000000000000000000097969905 1453 platform: mimxrt1060_evk 1454 probe_id: 000609301751 1455 product: DAPLink CMSIS-DAP 1456 runner: jlink 1457 serial: null 1458 1459Using Single Board For Multiple Variants 1460++++++++++++++++++++++++++++++++++++++++ 1461 1462 The ``platform`` attribute can be a list of names or a string 1463 with names separated by spaces. This allows to run tests for 1464 different platform variants on the same physical board, without 1465 re-configuring the hardware map file for each variant. For example: 1466 1467.. code-block:: yaml 1468 1469 - connected: true 1470 id: '001234567890' 1471 platform: 1472 - nrf5340dk/nrf5340/cpuapp 1473 - nrf5340dk/nrf5340/cpuapp/ns 1474 product: J-Link 1475 runner: nrfjprog 1476 serial: /dev/ttyACM1 1477 1478Quarantine 1479++++++++++ 1480 1481Twister allows user to provide configuration files defining a list of tests or 1482platforms to be put under quarantine. Such tests will be skipped and marked 1483accordingly in the output reports. This feature is especially useful when 1484running larger test suits, where a failure of one test can affect the execution 1485of other tests (e.g. putting the physical board in a corrupted state). 1486 1487To use the quarantine feature one has to add the argument 1488``--quarantine-list <PATH_TO_QUARANTINE_YAML>`` to a twister call. 1489Multiple quarantine files can be used. 1490The current status of tests on the quarantine list can also be verified by adding 1491``--quarantine-verify`` to the above argument. This will make twister skip all tests 1492which are not on the given list. 1493 1494A quarantine yaml has to be a sequence of dictionaries. Each dictionary has to have 1495``scenarios`` and ``platforms`` entries listing combinations of scenarios and platforms 1496to put under quarantine. In addition, an optional entry ``comment`` can be used, where 1497some more details can be given (e.g. link to a reported issue). These comments will also 1498be added to the output reports. 1499 1500When quarantining a class of tests or many scenarios in a single testsuite or 1501when dealing with multiple issues within a subsystem, it is possible to use 1502regular expressions, for example, **kernel.*** would quarantine 1503all kernel tests. 1504 1505An example of entries in a quarantine yaml: 1506 1507.. code-block:: yaml 1508 1509 - scenarios: 1510 - sample.basic.helloworld 1511 comment: "Link to the issue: https://github.com/zephyrproject-rtos/zephyr/pull/33287" 1512 1513 - scenarios: 1514 - kernel.common 1515 - kernel.common.(misra|tls) 1516 - kernel.common.nano64 1517 platforms: 1518 - .*_cortex_.* 1519 - native_sim 1520 1521To exclude a platform, use the following syntax: 1522 1523.. code-block:: yaml 1524 1525 - platforms: 1526 - qemu_x86 1527 comment: "broken qemu" 1528 1529Additionally you can quarantine entire architectures or a specific simulator for executing tests. 1530 1531Test Configuration 1532****************** 1533 1534A test configuration can be used to customize various aspects of twister 1535and the default enabled options and features. This allows tweaking the filtering 1536capabilities depending on the environment and makes it possible to adapt and 1537improve coverage when targeting different sets of platforms. 1538 1539The test configuration also adds support for test levels and the ability to 1540assign a specific test to one or more levels. Using command line options of 1541twister it is then possible to select a level and just execute the tests 1542included in this level. 1543 1544Additionally, the test configuration allows defining level 1545dependencies and additional inclusion of tests into a specific level if 1546the test itself does not have this information already. 1547 1548In the configuration file you can include complete components using 1549regular expressions and you can specify which test level to import from 1550the same file, making management of levels easier. 1551 1552To help with testing outside of upstream CI infrastructure, additional 1553options are available in the configuration file, which can be hosted 1554locally. As of now, those options are available: 1555 1556- Ability to ignore default platforms as defined in board definitions 1557 (Those are mostly emulation platforms used to run tests in upstream 1558 CI) 1559- Option to specify your own list of default platforms overriding what 1560 upstream defines. 1561- Ability to override ``build_on_all`` options used in some test scenarios. 1562 This will treat tests or sample as any other just build for default 1563 platforms you specify in the configuration file or on the command line. 1564- Ignore some logic in twister to expand platform coverage in cases where 1565 default platforms are not in scope. 1566 1567 1568Platform Configuration 1569====================== 1570 1571The following options control platform filtering in twister: 1572 1573- ``override_default_platforms``: override default key a platform sets in board 1574 configuration and instead use the list of platforms provided in the 1575 configuration file as the list of default platforms. This option is set to 1576 False by default. 1577- ``increased_platform_scope``: This option is set to True by default, when 1578 disabled, twister will not increase platform coverage automatically and will 1579 only build and run tests on the specified platforms. 1580- ``default_platforms``: A list of additional default platforms to add. This list 1581 can either be used to replace the existing default platforms or can extend it 1582 depending on the value of ``override_default_platforms``. 1583 1584And example platforms configuration: 1585 1586.. code-block:: yaml 1587 1588 platforms: 1589 override_default_platforms: true 1590 increased_platform_scope: false 1591 default_platforms: 1592 - qemu_x86 1593 1594 1595Test Level Configuration 1596======================== 1597 1598The test configuration allows defining test levels, level dependencies and 1599additional inclusion of tests into a specific test level if the test itself 1600does not have this information already. 1601 1602In the configuration file you can include complete components using 1603regular expressions and you can specify which test level to import from 1604the same file, making management of levels simple. 1605 1606And example test level configuration: 1607 1608.. code-block:: yaml 1609 1610 levels: 1611 - name: my-test-level 1612 description: > 1613 my custom test level 1614 adds: 1615 - kernel.threads.* 1616 - kernel.timer.behavior 1617 - arch.interrupt 1618 - boards.* 1619 1620 1621Combined configuration 1622====================== 1623 1624To mix the Platform and level configuration, you can take an example as below: 1625 1626An example platforms plus level configuration: 1627 1628.. code-block:: yaml 1629 1630 platforms: 1631 override_default_platforms: true 1632 default_platforms: 1633 - frdm_k64f 1634 levels: 1635 - name: smoke 1636 description: > 1637 A plan to be used verifying basic zephyr features. 1638 - name: unit 1639 description: > 1640 A plan to be used verifying unit test. 1641 - name: integration 1642 description: > 1643 A plan to be used verifying integration. 1644 - name: acceptance 1645 description: > 1646 A plan to be used verifying acceptance. 1647 - name: system 1648 description: > 1649 A plan to be used verifying system. 1650 - name: regression 1651 description: > 1652 A plan to be used verifying regression. 1653 1654 1655To run with above test_config.yaml file, only default_platforms with given test level 1656test scenarios will run. 1657 1658.. tabs:: 1659 1660 .. group-tab:: Linux 1661 1662 .. code-block:: bash 1663 1664 scripts/twister --test-config=<path to>/test_config.yaml 1665 -T tests --level="smoke" 1666 1667 1668 1669Running in Tests in Random Order 1670******************************** 1671Enable ZTEST framework's :kconfig:option:`CONFIG_ZTEST_SHUFFLE` config option to 1672run your tests in random order. This can be beneficial for identifying 1673dependencies between test cases. For native_sim platforms, you can provide 1674the seed to the random number generator by providing ``-seed=value`` as an 1675argument to twister. See :ref:`Shuffling Test Sequence <ztest_shuffle>` for more 1676details. 1677 1678Robot Framework Tests 1679********************* 1680Zephyr supports `Robot Framework <https://robotframework.org/>`_ as one of solutions for automated testing. 1681 1682Robot files allow you to express interactive test scenarios in human-readable text format and execute them in simulation or against hardware. 1683At this moment Zephyr integration supports running Robot tests in the `Renode <https://renode.io/>`_ simulation framework. 1684 1685To execute a Robot test suite with twister, run the following command: 1686 1687.. tabs:: 1688 1689 .. group-tab:: Linux 1690 1691 .. code-block:: bash 1692 1693 $ ./scripts/twister --platform hifive1 --test samples/subsys/shell/shell_module/sample.shell.shell_module.robot 1694 1695 .. group-tab:: Windows 1696 1697 .. code-block:: bat 1698 1699 python .\scripts\twister --platform hifive1 --test samples/subsys/shell/shell_module/sample.shell.shell_module.robot 1700 1701Writing Robot tests 1702=================== 1703 1704For the list of keywords provided by the Robot Framework itself, refer to `the official Robot documentation <https://robotframework.org/robotframework/>`_. 1705 1706Information 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. 1707It provides a list of the most commonly used keywords together with links to the source code where those are defined. 1708 1709It'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. 1710For details see the `extending Robot Framework <https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#extending-robot-framework>`_ section in the official Robot documentation. 1711 1712Running a single testsuite 1713========================== 1714 1715To run a single testsuite instead of a whole group of test you can run: 1716 1717.. code-block:: bash 1718 1719 $ twister -p qemu_riscv32 -s tests/kernel/interrupt/arch.shared_interrupt 1720