From c753271de1148e1a5f228e3abee10a1a04f88828 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Tue, 27 Feb 2024 23:51:28 +0100 Subject: [PATCH] ci(panic): add coredump tcb corrupted test --- .../system/panic/main/include/test_panic.h | 2 + .../system/panic/main/test_app_main.c | 1 + .../test_apps/system/panic/main/test_panic.c | 9 +++++ tools/test_apps/system/panic/pytest_panic.py | 40 ++++++++++++++++++- 4 files changed, 51 insertions(+), 1 deletion(-) 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 3b52370a34..1ed1735475 100644 --- a/tools/test_apps/system/panic/main/include/test_panic.h +++ b/tools/test_apps/system/panic/main/include/test_panic.h @@ -67,6 +67,8 @@ void test_illegal_access(void); void test_capture_dram(void); +void test_tcb_corrupted(void); + #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH && CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF void test_setup_coredump_summary(void); void test_coredump_summary(void); 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 6e3931b97b..3869bc7e50 100644 --- a/tools/test_apps/system/panic/main/test_app_main.c +++ b/tools/test_apps/system/panic/main/test_app_main.c @@ -116,6 +116,7 @@ void app_main(void) HANDLE_TEST(test_name, test_assert_cache_disabled); HANDLE_TEST(test_name, test_assert_cache_write_back_error_can_print_backtrace); HANDLE_TEST(test_name, test_assert_cache_write_back_error_can_print_backtrace2); + HANDLE_TEST(test_name, test_tcb_corrupted); #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 5603279d48..a9d41b0227 100644 --- a/tools/test_apps/system/panic/main/test_panic.c +++ b/tools/test_apps/system/panic/main/test_panic.c @@ -301,6 +301,15 @@ void test_coredump_summary(void) } #endif +void test_tcb_corrupted(void) +{ + uint32_t *tcb_ptr = (uint32_t *)xTaskGetIdleTaskHandleForCore(0); + for (size_t i = 0; i < sizeof(StaticTask_t) / sizeof(uint32_t); ++i) { + tcb_ptr[i] = 0xDEADBEE0; + } + vTaskDelay(2); +} + /* NOTE: The following test verifies the behaviour for the * Xtensa-specific MPU instructions (Refer WDTLB, DSYNC, WDTIB, ISYNC) * used for memory protection. diff --git a/tools/test_apps/system/panic/pytest_panic.py b/tools/test_apps/system/panic/pytest_panic.py index 34335987b4..249639ba7e 100644 --- a/tools/test_apps/system/panic/pytest_panic.py +++ b/tools/test_apps/system/panic/pytest_panic.py @@ -1,8 +1,11 @@ # SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import re +from typing import Any from typing import List from typing import Optional +from typing import Pattern +from typing import Sequence from typing import Union import pexpect @@ -108,7 +111,7 @@ def get_default_backtrace(config: str) -> List[str]: def common_test(dut: PanicTestDut, config: str, expected_backtrace: Optional[List[str]] = None, check_cpu_reset: Optional[bool] = True, - expected_coredump: Optional[List[Union[str, re.Pattern]]] = None) -> None: + expected_coredump: Optional[Sequence[Union[str, Pattern[Any]]]] = None) -> None: if 'gdbstub' in config: dut.expect_exact('Entering gdb stub now.') dut.start_gdb_for_gdbstub() @@ -1042,3 +1045,38 @@ def test_coredump_summary(dut: PanicTestDut) -> None: @pytest.mark.parametrize('config', CONFIG_COREDUMP_SUMMARY_FLASH_ENCRYPTED, indirect=True) def test_coredump_summary_flash_encrypted(dut: PanicTestDut, config: str) -> None: _test_coredump_summary(dut, True, config == 'coredump_flash_encrypted') + + +@pytest.mark.parametrize('config', [pytest.param('coredump_flash_elf_sha', marks=TARGETS_ALL)], indirect=True) +@pytest.mark.generic +def test_tcb_corrupted(dut: PanicTestDut, target: str, config: str, test_func_name: str) -> None: + dut.run_test_func(test_func_name) + if dut.is_xtensa: + dut.expect_gme('LoadProhibited') + dut.expect_reg_dump(0) + dut.expect_corrupted_backtrace() + else: + dut.expect_gme('Load access fault') + dut.expect_reg_dump(0) + dut.expect_stack_dump() + + dut.expect_elf_sha256() + dut.expect_none('Guru Meditation') + + # TCB NAME + # ---------- ---------------- + if dut.is_multi_core: + regex_patterns = [rb'[0-9xa-fA-F] main', + rb'[0-9xa-fA-F] ipc0', + rb'[0-9xa-fA-F] ipc1'] + else: + regex_patterns = [rb'[0-9xa-fA-F] main'] + + coredump_pattern = [re.compile(pattern.decode('utf-8')) for pattern in regex_patterns] + + common_test( + dut, + config, + expected_backtrace=None, + expected_coredump=coredump_pattern + )