Skip to content

Commit 5f3d3f5

Browse files
committed
ci(panic): extend extram_stack tests
1 parent 1848079 commit 5f3d3f5

13 files changed

+117
-21
lines changed

components/espcoredump/src/core_dump_elf.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ static int elf_process_task_tcb(core_dump_elf_t *self, core_dump_task_header_t *
334334
static int elf_process_task_stack(core_dump_elf_t *self, core_dump_task_header_t *task)
335335
{
336336
int ret = 0;
337-
uint32_t stack_vaddr, stack_len = 0, stack_paddr = 0;
337+
uint32_t stack_vaddr;
338+
uint32_t stack_len = 0;
339+
uint32_t stack_paddr = 0;
338340

339341
ELF_CHECK_ERR((task), ELF_PROC_ERR_OTHER, "Invalid input data.");
340342

@@ -343,8 +345,11 @@ static int elf_process_task_stack(core_dump_elf_t *self, core_dump_task_header_t
343345
task->tcb_addr, stack_vaddr, stack_len);
344346

345347
#if CONFIG_ESP_COREDUMP_CAPTURE_DRAM
346-
/* If the task data located in the PSRAM, we will save it here.
347-
Otherwise it will be saved in esp_core_dump_store_section()
348+
/*
349+
When saving all data sections (enabled by `CONFIG_ESP_COREDUMP_CAPTURE_DRAM`),
350+
the task stack located in DRAM will be saved in `esp_core_dump_store_section()`.
351+
Therefore, we filter them out here.
352+
PSRAM data do not fall into any ELF section, so we always save such stacks here.
348353
*/
349354
if (esp_ptr_external_ram((void *)stack_vaddr))
350355
#endif
@@ -457,11 +462,12 @@ static int elf_save_task(core_dump_elf_t *self, core_dump_task_header_t *task)
457462

458463
static int elf_process_task_data(core_dump_elf_t *self)
459464
{
460-
int elf_len = 0, ret;
465+
int elf_len = 0;
461466
core_dump_task_header_t task_hdr = { 0 };
462467
core_dump_mem_seg_header_t interrupted_stack = { 0 };
463468
TaskIterator_t task_iter;
464-
uint16_t tasks_num = 0, bad_tasks_num = 0;
469+
uint16_t tasks_num = 0;
470+
uint16_t bad_tasks_num = 0;
465471

466472
ESP_COREDUMP_LOG_PROCESS("================ Processing task data ================");
467473
// processes all task's stack data and writes segment data into partition
@@ -474,7 +480,7 @@ static int elf_process_task_data(core_dump_elf_t *self)
474480
bad_tasks_num++;
475481
continue;
476482
}
477-
ret = elf_save_task(self, &task_hdr);
483+
int ret = elf_save_task(self, &task_hdr);
478484
ELF_CHECK_ERR((ret > 0), ret,
479485
"Task %x, TCB write failed, return (%d).", task_iter.pxTaskHandle, ret);
480486
elf_len += ret;

tools/test_apps/system/panic/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if(CONFIG_TEST_MEMPROT)
1717
endif()
1818
endif()
1919

20-
if(NOT CONFIG_TEST_MEMPROT AND NOT CONFIG_ESP_COREDUMP_CAPTURE_DRAM)
20+
if(NOT CONFIG_TEST_MEMPROT AND NOT CONFIG_ESP_COREDUMP_CAPTURE_DRAM AND NOT CONFIG_SPIRAM)
2121
# Enable UBSAN checks
2222
#
2323
# shift-base sanitizer is disabled due to the following pattern found in register header files:

tools/test_apps/system/panic/main/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ endif()
1313

1414
idf_component_register(SRCS "${srcs}"
1515
INCLUDE_DIRS "include"
16-
REQUIRES spi_flash esp_psram esp_system esp_partition espcoredump
17-
PRIV_REQUIRES esp_gdbstub)
16+
REQUIRES spi_flash esp_psram esp_system esp_partition
17+
PRIV_REQUIRES esp_gdbstub espcoredump)
1818

1919
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-unused-variable"
2020
"-Wno-infinite-recursion"

tools/test_apps/system/panic/main/include/test_panic.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ void test_hw_stack_guard_cpu1(void);
3232
#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD
3333

3434
#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
35-
void test_panic_extram_stack(void);
35+
void test_panic_extram_stack_heap(void);
36+
#if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
37+
void test_panic_extram_stack_bss(void);
38+
#endif
3639
#endif
3740

3841
#if !CONFIG_FREERTOS_UNICORE

tools/test_apps/system/panic/main/test_app_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ void app_main(void)
9696
#endif // CONFIG_FREERTOS_UNICORE
9797
#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD
9898
#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
99-
HANDLE_TEST(test_name, test_panic_extram_stack);
99+
HANDLE_TEST(test_name, test_panic_extram_stack_heap);
100+
#if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
101+
HANDLE_TEST(test_name, test_panic_extram_stack_bss);
102+
#endif
100103
#endif
101104
#if CONFIG_ESP_COREDUMP_CAPTURE_DRAM
102105
HANDLE_TEST(test_name, test_capture_dram);

tools/test_apps/system/panic/main/test_panic.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void stack_in_extram(void* arg) {
104104
abort();
105105
}
106106

107-
void test_panic_extram_stack(void) {
107+
void test_panic_extram_stack_heap(void) {
108108
/* Start by initializing a Task which has a stack in external RAM */
109109
StaticTask_t handle;
110110
const uint32_t stack_size = 8192;
@@ -119,8 +119,17 @@ void test_panic_extram_stack(void) {
119119

120120
vTaskDelay(1000);
121121
}
122+
#if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
123+
static EXT_RAM_BSS_ATTR StackType_t stack[8192];
124+
void test_panic_extram_stack_bss(void)
125+
{
126+
StaticTask_t handle;
122127

128+
xTaskCreateStatic(stack_in_extram, "Task_stack_extram", sizeof(stack), NULL, 4, stack, &handle);
123129

130+
vTaskDelay(1000);
131+
}
132+
#endif
124133
#endif // ESP_COREDUMP_ENABLE_TO_FLASH && SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
125134

126135

tools/test_apps/system/panic/pytest_panic.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@
7070
# This list is used to check if the target is a dual-core one.
7171
TARGETS_DUAL_CORE_NAMES = [x.mark.name for x in TARGETS_DUAL_CORE]
7272

73-
# The tests which panic on external stack require PSRAM capable runners
7473
CONFIGS_EXTRAM_STACK = [
75-
pytest.param('coredump_extram_stack', marks=[pytest.mark.esp32, pytest.mark.psram]),
76-
pytest.param('coredump_extram_stack', marks=[pytest.mark.esp32s2, pytest.mark.generic]),
77-
pytest.param('coredump_extram_stack', marks=[pytest.mark.esp32s3, pytest.mark.quad_psram]),
74+
pytest.param('coredump_flash_extram_stack_heap_esp32', marks=[pytest.mark.esp32, pytest.mark.psram]),
75+
pytest.param('coredump_flash_extram_stack_heap_esp32s2', marks=[pytest.mark.esp32s2, pytest.mark.generic]),
76+
pytest.param('coredump_flash_extram_stack_heap_esp32s3', marks=[pytest.mark.esp32s3, pytest.mark.quad_psram]),
77+
pytest.param('coredump_flash_extram_stack_bss_esp32', marks=[pytest.mark.esp32, pytest.mark.psram]),
78+
pytest.param('coredump_flash_extram_stack_bss_esp32s2', marks=[pytest.mark.esp32s2, pytest.mark.generic]),
79+
pytest.param('coredump_flash_extram_stack_bss_esp32s3', marks=[pytest.mark.esp32s3, pytest.mark.quad_psram]),
7880
]
7981

8082
CONFIGS_HW_STACK_GUARD = [
@@ -208,8 +210,11 @@ def test_task_wdt_cpu1(dut: PanicTestDut, config: str, test_func_name: str) -> N
208210

209211

210212
@pytest.mark.parametrize('config', CONFIGS_EXTRAM_STACK, indirect=True)
211-
def test_panic_extram_stack(dut: PanicTestDut, config: str, test_func_name: str) -> None:
212-
dut.run_test_func(test_func_name)
213+
def test_panic_extram_stack(dut: PanicTestDut, config: str) -> None:
214+
if 'heap' in config:
215+
dut.run_test_func('test_panic_extram_stack_heap')
216+
else:
217+
dut.run_test_func('test_panic_extram_stack_bss')
213218
dut.expect_none('Allocated stack is not in external RAM')
214219
dut.expect_none('Guru Meditation')
215220
dut.expect_backtrace()
@@ -222,7 +227,22 @@ def test_panic_extram_stack(dut: PanicTestDut, config: str, test_func_name: str)
222227
# The caller must be accessible after restoring the stack
223228
dut.expect_exact('Core dump has been saved to flash.')
224229

225-
common_test(dut, config)
230+
if dut.target == 'esp32':
231+
# ESP32 External data memory range [0x3f800000-0x3fc00000)
232+
coredump_pattern = re.compile('.coredump.tasks.data (0x3[fF][8-9a-bA-B][0-9a-fA-F]{5}) (0x[a-fA-F0-9]+) RW')
233+
elif dut.target == 'esp32s2':
234+
# ESP32-S2 External data memory range [0x3f500000-0x3ff80000)
235+
coredump_pattern = re.compile('.coredump.tasks.data (0x3[fF][5-9a-fA-F][0-7][0-9a-fA-F]{4}) (0x[a-fA-F0-9]+) RW')
236+
else:
237+
# ESP32-S3 External data memory range [0x3c000000-0x3e000000)
238+
coredump_pattern = re.compile('.coredump.tasks.data (0x3[c-dC-D][0-9a-fA-F]{6}) (0x[a-fA-F0-9]+) RW')
239+
240+
common_test(
241+
dut,
242+
config,
243+
expected_backtrace=None,
244+
expected_coredump=[coredump_pattern]
245+
)
226246

227247

228248
@pytest.mark.parametrize('config', CONFIGS, indirect=True)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CONFIG_IDF_TARGET="esp32"
2+
CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y
3+
CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=y
4+
CONFIG_ESP_COREDUMP_CHECKSUM_SHA256=y
5+
# We need to have the coredump info log
6+
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
7+
CONFIG_SPIRAM=y
8+
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
9+
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
10+
CONFIG_ESP_COREDUMP_USE_STACK_SIZE=y
11+
CONFIG_ESP_COREDUMP_CAPTURE_DRAM=y
12+
CONFIG_PARTITION_TABLE_CUSTOM=y
13+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_capture_dram.csv"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CONFIG_IDF_TARGET="esp32s2"
2+
CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y
3+
CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=y
4+
CONFIG_ESP_COREDUMP_CHECKSUM_SHA256=y
5+
# We need to have the coredump info log
6+
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
7+
CONFIG_SPIRAM=y
8+
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
9+
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
10+
CONFIG_ESP_COREDUMP_USE_STACK_SIZE=y
11+
CONFIG_ESP_COREDUMP_CAPTURE_DRAM=y
12+
CONFIG_PARTITION_TABLE_CUSTOM=y
13+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_capture_dram.csv"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CONFIG_IDF_TARGET="esp32s3"
2+
CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y
3+
CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=y
4+
CONFIG_ESP_COREDUMP_CHECKSUM_SHA256=y
5+
# We need to have the coredump info log
6+
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
7+
CONFIG_SPIRAM=y
8+
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
9+
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
10+
CONFIG_ESP_COREDUMP_USE_STACK_SIZE=y
11+
CONFIG_ESP_COREDUMP_CAPTURE_DRAM=y
12+
CONFIG_PARTITION_TABLE_CUSTOM=y
13+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_capture_dram.csv"

0 commit comments

Comments
 (0)