esp-idf/tools/test_apps/system/panic
Jiang Jiang Jian 0d8ca93e8d Merge branch 'feature/update-gdb-to-12.1_20231023_v5.2' into 'release/v5.2'
feat(tools): update gdb version to 12.1_20231023 (v5.2)

See merge request espressif/esp-idf!27376
2023-12-26 10:32:07 +08:00
..
main change(xtensa): Deprecate ".../xtensa_context.h" include path 2023-12-05 18:04:52 +08:00
test_panic_util Merge branch 'feature/update-gdb-to-12.1_20231023_v5.2' into 'release/v5.2' 2023-12-26 10:32:07 +08:00
CMakeLists.txt test_app: Extend panic app to include memprot-related tests 2023-02-16 17:13:56 +05:30
conftest.py ci: fix import path 2022-10-20 20:34:51 +08:00
panic_utils.py ci: rename module name due to the wrong import in other packages 2022-07-02 08:03:49 +08:00
pytest_panic.py feat(coredump): save twdt panic output to coredump elf file 2023-12-07 15:21:24 +01:00
README.md feat(coredump): add panic details to the elf file 2023-08-24 10:20:56 +02:00
sdkconfig.ci.coredump_extram_stack Coredump: add a test to check that coredump supports stacks in SPIRAM 2022-12-22 12:47:22 +01:00
sdkconfig.ci.coredump_flash_bin_crc test_panic: add CONFIG_HAL_ASSERTION_DISABLE to coredump_flash_bin_crc config 2023-02-07 20:23:52 +08:00
sdkconfig.ci.coredump_flash_elf_sha Coredump config option rename throughout IDF 2020-09-30 20:22:27 +05:30
sdkconfig.ci.coredump_uart_bin_crc Coredump config option rename throughout IDF 2020-09-30 20:22:27 +05:30
sdkconfig.ci.coredump_uart_elf_crc Coredump config option rename throughout IDF 2020-09-30 20:22:27 +05:30
sdkconfig.ci.gdbstub test/panic: add gdbstub test configuration 2020-10-13 18:09:22 +02:00
sdkconfig.ci.gdbstub_coredump coredump: allow coredump at panic even if gdbstub is used. 2023-02-17 15:15:36 +08:00
sdkconfig.ci.memprot_esp32c2 test_app: Extend panic app to include memprot-related tests 2023-02-16 17:13:56 +05:30
sdkconfig.ci.memprot_esp32c3 test_app: Extend panic app to include memprot-related tests 2023-02-16 17:13:56 +05:30
sdkconfig.ci.memprot_esp32c6 esp32c6: Fix incorrect PMP configuration 2023-03-09 11:37:29 +05:30
sdkconfig.ci.memprot_esp32h2 test_apps: enable memprot tests for ESP32-H2 target 2023-03-15 13:16:26 +05:30
sdkconfig.ci.memprot_esp32s2 test_app: Extend panic app to include memprot-related tests 2023-02-16 17:13:56 +05:30
sdkconfig.ci.memprot_esp32s3 test_app: Extend panic app to include memprot-related tests 2023-02-16 17:13:56 +05:30
sdkconfig.ci.panic test_apps: add panic test 2020-05-12 22:27:06 +02:00
sdkconfig.ci.panic_delay refactor(esp_system): reboot delay: added docs, protected by watchdog 2022-12-20 15:51:00 +08:00
sdkconfig.defaults esp32c6: Fix incorrect PMP configuration 2023-03-09 11:37:29 +05:30

Supported Targets ESP32 ESP32-C2 ESP32-C3 ESP32-C6 ESP32-H2 ESP32-S2 ESP32-S3

Introduction

The panic test app checks the behavior of ESP-IDF Panic Handler.

This test app is relatively complex because it has to check many possible combinations of:

  • Failure scenario: abort, assertion, interrupt watchdog, illegal instruction, ...
  • Chip target: esp32, esp32c3, ...
  • Configuration: default, GDB Stub, Core Dump to UART, ...

Failure scenarios are implemented in test_panic.c. The test application receives the name of the scenario from console (e.g. test_illegal_instruction ). The failure scenario is executed and the app panics. Once the panic output is printed, the pytest-based test case parses the output and verifies that the behavior of the panic handler was correct.

In pytest_panic.py, there typically is one test function for each failure scenario. Each test function is then parametrized by config parameter. This creates "copies" of the test case for each of the configurations (default, GDB Stub, etc.) Tests are also parametrized with target-specific markers. Most tests can run on every target, but there are a few exceptions, such as failure scenarios specific to the dual-core chips.

The test cases use a customized DUT class PanicTestDut, defined in panic_dut.py. This class is derived from IdfDut. It defines several helper functions to make the test cases easier to read.

Building

Several configurations are provided as sdkconfig.ci.XXX and serve as a template.

For example, to build the test app with configuration panic for ESP32-C3, run:

idf.py set-target esp32c3
cat sdkconfig.defaults sdkconfig.ci.panic > sdkconfig
idf.py build

Building multiple configurations side by side

If you need to work with multiple configurations at the same time it can be useful to keep each build in a separate directory. For example, to build the panic configuration for ESP32-C3 in a separate directory, run:

idf.py -DIDF_TARGET=esp32c3 -DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.ci.panic" -DSDKCONFIG=build_esp32c3_panic/sdkconfig -B build_esp32c3_panic build

This way, all the build products and the sdkconfig file are kept in the directory build_esp32c3_gdbstub. pytest-embedded will search for binaries in this directory if you run tests as shown in the section below.

This approach allows switching between different build configurations and targets without deleting the build directories.

Running the app manually

idf.py flash monitor

(don't forget the -B argument if you have built the app in a directory other than build)

Once the app is running, input the name of the test (e.g. test_abort) and press Enter.

Running tests

Suppose you have built the app for a specific target and with a certain sdkconfig.ci.CONFIG config. You need to run the tests just for this config and the target:

pytest --target TARGET -k '[CONFIG]'

For example, if you have built the panic config for ESP32-C3, run:

pytest --target esp32c3 -k '[panic]'

Or, to run a single test for the given config, e.g. test_abort:

pytest --target esp32c3 -k 'test_abort[panic]'