1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/tests
bors[bot] 60d6decbd7
Merge #20022 #20025
20022: pkg/lwip: add support for slipdev r=benpicco a=benpicco



20025: tests/drivers/at: fix device table overflow r=benpicco a=krzysztof-cabaj

### Contribution description

This PR fix device table overflow in `tests/driver/at`, which could lead to device crash.

### Testing procedure

PR was tested on two nucleo boards with 2 and 3 UARTs (nucleo-l476rg and nucleo-l496zg).
Flash `tests/driver/at` with and without this PR.

Output with this PR:

```
> main(): This is RIOT! (Version: 2022.07-devel-5083-g2b9e8-tests-drivers-at)
AT command test app
> init 5 9600

Wrong UART device number - should by in range 0-2.
>
```

Output without this PR:

```
> main(): This is RIOT! (Version: 2022.07-devel-5083-g2b9e8)
AT command test app
> init 5 9600

8001afd
*** RIOT kernel panic:
FAILED ASSERTION.

*** halted.


Context before hardfault:
   r0: 0x0000000a
   r1: 0x00000000
   . . . 
```

### Issues/PRs references

None

Co-authored-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
Co-authored-by: krzysztof-cabaj <kcabaj@gmail.com>
2023-10-27 14:54:54 +00:00
..
bench tests/bench/runtime_coreapis: disable test with LLVM 2023-07-18 12:24:08 +02:00
board_microbit
build_system boards,sys/arduino: major clean up 2023-06-26 17:24:07 +02:00
buttons
core tests/core/thread_cooperation: clean up test 2023-10-26 10:34:01 +02:00
cpu cpu/riscv: Add PMP driver 2023-06-28 11:55:34 +02:00
drivers tests/drivers/at: fix device table overflow 2023-10-26 19:48:28 +02:00
fault_handler examples and tests: add atmega8 to relevent Makefile.ci 2023-07-11 21:22:02 +02:00
leds tests/leds: add test where LEDs are mapped to buttons 2022-03-29 09:05:46 +02:00
mcuboot
minimal tests/minimal: disable test_utils_print_stack_usage 2022-03-29 21:49:35 +02:00
net tree-wide: fix typos in doc and comments 2023-10-16 12:17:48 +02:00
periph tests/periph/fmc: remove a double empty line 2023-07-28 14:50:06 +02:00
pkg tests/pkg/minmea: fixing RMC timestamp 2023-10-27 10:43:41 +03:00
riotboot examples,tests: Drop redundant dependency 2023-04-19 16:58:10 +02:00
riotboot_flashwrite boards/sipeed-longan-nano-tft: blacklist in tests and examples 2023-08-06 12:56:36 +02:00
riotboot_hdr examples and tests: add atmega8 to relevent Makefile.ci 2023-07-11 21:22:02 +02:00
rust_libs tests: move sys related applications to tests/sys/ subdirectory 2023-05-10 12:02:58 +02:00
rust_minimal Rust: Update riot-wrappers 2023-04-25 09:20:58 +02:00
sys add Makefile.ci 2023-10-23 14:18:21 +02:00
turo examples and tests: add atmega8 to relevent Makefile.ci 2023-07-11 21:22:02 +02:00
turo_txt examples and tests: add atmega8 to relevent Makefile.ci 2023-07-11 21:22:02 +02:00
unittests tests/unittests: add a unit test for ztimer 2023-10-23 15:44:52 +02:00
.gitignore examples,tests: ignore core dumps via .gitignore 2022-08-31 15:05:14 +02:00
Makefile.boards.netif tests/Makefile.boards.netif: add lora-e5-dev 2023-04-13 10:55:24 +02:00
Makefile.tests_common tests/drivers: move all driver tests into own folder 2023-05-04 12:45:07 +02:00
README.md tests/README.md: Add directory overview 2023-05-13 17:46:56 +02:00
riot_logo.h tests: use common riot_logo.h 2022-04-13 08:00:48 +02:00
test_print_stack_usage.config sys/test_utils/print_stack_usage: add Kconfig support 2022-03-29 21:49:35 +02:00
test_utils.config sys/test_utils/print_stack_usage: add Kconfig support 2022-03-29 21:49:35 +02:00

Running and creating tests

There are a number of tests included in RIOT. They are located in the tests directory. These tests allow basic functionality to be verified as well as provide an example of usage.

Directory Structure

The tests directory in RIOT is further divided into a number of subdirectories.

  • bench: Benchmark tests, these provide numbers on how RIOT performs on the used hardware.
  • build_system: Tests the RIOT build system functionality, such as blob, external board/module/package dirs, and kconfig.
  • core: Tests the RIOT core functionality such as threading and IPC.
  • cpu: Tests RIOT cpu specific features such as efm32, stm32, native and AVR.
  • drivers: Tests individual drivers. The tests for sensors print the measured values to the console, others demonstrate the functionality of the driver and attached hardware.
  • net: Tests the networking features provided in RIOT, such as CoAP, emcute, GNRC, IEEE 802.15.4 and sntp.
  • periph: Tests the low level peripherals in RIOT, such as interacting with SPI and I2C peripherals.
  • pkg: Tests the external packages available in RIOT, such as lvgl, lwip, nanocbor, and tinyusb.
  • sys: Collection of tests for the utilities in sys directory of RIOT.
  • unittests: Collection of very simple test applications that test simple modules and do not rely on extra hardware. Can be flashed and run as single application to test all unit tests at once.

Running automated tests

Some tests can be performed automatically. The test automation scripts are defined in the <test_application>/tests/ folder. They are written in python and interact through the serial (typically UART) with the test application code running on a board to do the validation. It is recommended to flash the board with the test just before running it because some platforms cannot be reset while testing.

Running single test

From the test application directory run:

BOARD=<board_of_your_choice> make flash test

An automated way of knowing if a test is available is to execute the 'test/available' target from the test application directory. It executes without error if tests run by 'make test' are present.

make test/available

Running all test for particular board

If you would like execute all tests for given board, you could use dedicated script compile_and_test_for_board.py

Go to main RIOT directory and execute command:

./dist/tools/compile_and_test_for_board/compile_and_test_for_board.py . <board_of_your_choice> --with-test-only --jobs=4

More details concerning other available parameters provided by this tool can be found in README.md file and directly in compile_and_test_for_board.py script.

Running tests that require a preliminary manual configuration

Some tests need active monitoring or manual setup steps but still have some automated scripts. The test automation scripts are defined in the <test_application>/tests-with-config/ folder. For running them, follow the setup or analysis documentation and use the test-with-config target.

Running tests that require root privileges

Some tests require root privileges to launch their automated script. In this case, the test automation scripts are defined in the <test_application>/tests-as-root/ folder. For running them, follow the setup or analysis documentation and use the test-as-root target.

Cleaning intermediate files

After test execution intermediate files are not automatically deleted. Execution of multiple tests, especially all for particular board could generate many files. For example, after execution of all test for stm32f469i-disco board (more than 230 tests) around 7.5 GB of intermediate files are created.

There are few methods for cleaning intermediate files.

If you would like to clean intermediate file only for particular board you should go to main RIOT directory and execute one from these commands:

./dist/tools/compile_and_test_for_board/compile_and_test_for_board.py . <board_of_your_choice> --compile-targets clean

or

make BOARD=<board_of_your_choice> clean

If you would like to clean intermediate files for all boards go to main RIOT directory and use this command.

@warning This command cleans all local files, for example, pkg downloads and locally generared docs.

make distclean

Implementing automated tests

The goal is to be able to run all tests in a sequential way for as many targets as possible.

As some board can't be reset without a manual trigger tests should be implemented with some kind of synchronization. This can be done in two ways:

  • use test_utils_interactive_sync when uart input/output does not need to be disabled for the test. This is enabled by default.
  • set up the test in a loop so the test script will be able so sync with some kind of start condition in the test.

The module for the first option is test_utils_interactive_sync and is set as a default module in Makefile.tests_common. It can be disabled by setting in the application makefile DISABLE_MODULE += test_utils_interactive_sync. The python test script will adapt to it automatically.

When using the shell module, test_utils_interactive_sync will use the shell itself to synchronize, and will not use test_utils_interactive_sync(); function to synchronize. Some times you will want to synchronize before the start of the script and use test_utils_interactive_sync(); function (e.g.: tests/ps_schedstatistics). For these cases you can disable test_utils_interactive_sync_shell module in the application Makefile: DISABLE_MODULE += test_utils_interactive_sync_shell.

Automated Tests Guidelines

When using pexpect $ is useless for matching the end of a line, instead use \r\n(pexpect end-of-line).

Beware of + and * at the end of patterns. These patterns will always get a minimal match (non-greedy).(pexpect end-of-patterns) This can be an issue when matching groups and using the matched groups to verify some kind of behavior since * could return an empty match and + only a subset.

This is especially prevalent since printf() is buffered so the output might not arrive in a single read to pexpect.

To avoid this make sure to match a non-ambiguous character at the end of the pattern like \r\n, \s, \), etc..

don't:

    child.expect(r'some string: (\d+)')

do:

    child.expect(r'some string: (\d+)\r\n')
    child.expect(r'some string: (\d+)\s')
    child.expect(r'some string: (\d+) ,')

Use expect() instead of assert()

In order to make a test application functional in all cases, use expect() instead of assert(). The former works like the latter, but will still be compiled in if NDEBUG is defined. This is useful to keep a test application working even when compiling with -DNDEBUG, allowing for the code-under-test to be compiled with that flag. Otherwise, the application would force compiling all tested code with assertions enabled. expect() is defined in the header test_utils/expect.h.

Interaction through the uart

Tests implemented with testrunner use the cleanterm target that provides an interaction without adding extra text output or input handling. It can currently be expected to have unmodified line based interaction with the board.

The expected behavior is verified with the test in tests/test_tools.

Tests cannot rely on having on all boards and terminal programs:

  • unbuffered input
  • allowing sending special characters like ctrl+c/ctrl+d