test: panic: make stack overflow test more robust

The previous approach was to allocate an array on the stack, and
have the array extend past the stack size. This worked by would
result in SP being moved near the end of the stack. If an interrupt
triggered at that time, interrupt prologue would try to save the
context to the stack, tripping the stack overflow watchpoint.

Replacing this with the approach which doesn't move the SP and simply
writes to decreasing addresses from SP, until stack overflow check
triggers.
This commit is contained in:
Ivan Grokhotkov 2020-12-28 17:41:43 +01:00
parent b7b9ea4361
commit 7ab57605cb

View File

@ -102,9 +102,11 @@ static void IRAM_ATTR test_int_wdt_cache_disabled(void)
static void test_stack_overflow(void) static void test_stack_overflow(void)
{ {
volatile uint8_t stuff[CONFIG_ESP_MAIN_TASK_STACK_SIZE + 1000]; register uint32_t* sp asm("sp");
for (int i = 0; i < sizeof(stuff); ++i) { uint32_t *end = sp - CONFIG_ESP_MAIN_TASK_STACK_SIZE;
stuff[i] = rand(); // offset - 20 bytes from SP in order to not corrupt the current frame.
for (uint32_t* ptr = sp - 5; ptr != end; --ptr) {
*ptr = rand();
} }
} }