From 80ad7ec71a6b05a6771653412b3dbf381d63556d Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Wed, 13 Aug 2025 12:17:35 +0200 Subject: [PATCH] test(panic_handler): Added unit test to verify panic handler can halt This test verifies that the panic handler can indeed halt when configured to print and halt instead of rebboting. --- tools/test_apps/system/panic/main/include/test_panic.h | 4 ++++ tools/test_apps/system/panic/main/test_app_main.c | 3 +++ tools/test_apps/system/panic/main/test_panic.c | 9 +++++++++ tools/test_apps/system/panic/pytest_panic.py | 9 +++++++++ tools/test_apps/system/panic/sdkconfig.ci.panic_halt | 5 +++++ 5 files changed, 30 insertions(+) create mode 100644 tools/test_apps/system/panic/sdkconfig.ci.panic_halt diff --git a/tools/test_apps/system/panic/main/include/test_panic.h b/tools/test_apps/system/panic/main/include/test_panic.h index 9c689c7aea..847a9eb958 100644 --- a/tools/test_apps/system/panic/main/include/test_panic.h +++ b/tools/test_apps/system/panic/main/include/test_panic.h @@ -83,6 +83,10 @@ void test_setup_coredump_summary(void); void test_coredump_summary(void); #endif +#if CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT +void test_panic_halt(void); +#endif /* CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT */ + #ifdef __cplusplus } #endif diff --git a/tools/test_apps/system/panic/main/test_app_main.c b/tools/test_apps/system/panic/main/test_app_main.c index 133986afeb..76bede0157 100644 --- a/tools/test_apps/system/panic/main/test_app_main.c +++ b/tools/test_apps/system/panic/main/test_app_main.c @@ -127,6 +127,9 @@ void app_main(void) HANDLE_TEST(test_name, test_tcb_corrupted); HANDLE_TEST(test_name, test_panic_handler_stuck0); HANDLE_TEST(test_name, test_panic_handler_crash0); +#if CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT + HANDLE_TEST(test_name, test_panic_halt); +#endif /* CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT */ #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH && CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF HANDLE_TEST(test_name, test_setup_coredump_summary); HANDLE_TEST(test_name, test_coredump_summary); diff --git a/tools/test_apps/system/panic/main/test_panic.c b/tools/test_apps/system/panic/main/test_panic.c index 348216fce0..3de9d7e5b4 100644 --- a/tools/test_apps/system/panic/main/test_panic.c +++ b/tools/test_apps/system/panic/main/test_panic.c @@ -443,3 +443,12 @@ void test_capture_dram(void) assert(0); } #endif + +#if CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT +void test_panic_halt(void) +{ + printf("Triggering panic. Device should print 'CPU halted.' and stop.\n"); + fflush(stdout); + assert(0); +} +#endif /* CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT */ diff --git a/tools/test_apps/system/panic/pytest_panic.py b/tools/test_apps/system/panic/pytest_panic.py index 36c1e916bf..af5966f73e 100644 --- a/tools/test_apps/system/panic/pytest_panic.py +++ b/tools/test_apps/system/panic/pytest_panic.py @@ -1237,3 +1237,12 @@ def test_tcb_corrupted(dut: PanicTestDut, target: str, config: str, test_func_na expected_backtrace=None, expected_coredump=coredump_pattern ) + + +@pytest.mark.generic +@pytest.mark.supported_targets +@pytest.mark.parametrize('config', ['panic_halt'], indirect=True) +def test_panic_halt(dut: PanicTestDut) -> None: + dut.run_test_func('test_panic_halt') + dut.expect_exact('CPU halted.', timeout=30) + dut.expect_none(dut.REBOOT, timeout=3) diff --git a/tools/test_apps/system/panic/sdkconfig.ci.panic_halt b/tools/test_apps/system/panic/sdkconfig.ci.panic_halt new file mode 100644 index 0000000000..31714460cd --- /dev/null +++ b/tools/test_apps/system/panic/sdkconfig.ci.panic_halt @@ -0,0 +1,5 @@ +# Panic halt CI config +CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y +CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT=n +CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT=n +CONFIG_ESP_SYSTEM_PANIC_GDBSTUB=n