feat(tools/test_apps): Add violation tests for the flash I/DROM region

- For SoCs supporting PMP
This commit is contained in:
Laukik Hase 2024-02-05 17:18:44 +05:30
parent 5fcd908d26
commit 9ed7c8b426
No known key found for this signature in database
GPG Key ID: D6F3208C06086AC8
4 changed files with 84 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -42,6 +42,11 @@ void test_rtc_slow_reg1_execute_violation(void);
void test_rtc_slow_reg2_execute_violation(void); void test_rtc_slow_reg2_execute_violation(void);
void test_irom_reg_write_violation(void);
void test_drom_reg_write_violation(void);
void test_drom_reg_execute_violation(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -134,6 +134,12 @@ void app_main(void)
HANDLE_TEST(test_name, test_rtc_slow_reg2_execute_violation); HANDLE_TEST(test_name, test_rtc_slow_reg2_execute_violation);
#endif #endif
#if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
HANDLE_TEST(test_name, test_irom_reg_write_violation);
HANDLE_TEST(test_name, test_drom_reg_write_violation);
HANDLE_TEST(test_name, test_drom_reg_execute_violation);
#endif
#endif #endif
die("Unknown test name"); die("Unknown test name");

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -15,7 +15,7 @@
#include "soc/soc.h" #include "soc/soc.h"
#include "test_memprot.h" #include "test_memprot.h"
#include "sdkconfig.h"
#define RND_VAL (0xA5A5A5A5) #define RND_VAL (0xA5A5A5A5)
#define SPIN_ITER (16) #define SPIN_ITER (16)
@ -213,3 +213,36 @@ static void __attribute__((constructor)) test_print_rtc_var_func(void)
printf("foo_s: %p | var_s: %p\n", &foo_s, &var_s); printf("foo_s: %p | var_s: %p\n", &foo_s, &var_s);
#endif #endif
} }
/* ---------------------------------------------------- I/D Cache (Flash) Violation Checks ---------------------------------------------------- */
#if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
static const uint16_t foo_buf[8] = {
0x0001, 0x0001, 0x0001, 0x0001,
0x0001, 0x0001, 0x0001, 0x0001,
};
void test_irom_reg_write_violation(void)
{
extern int _instruction_reserved_end;
uint32_t *test_addr = (uint32_t *)((uint32_t)(&_instruction_reserved_end - 0x100));
printf("Flash (IROM): Write operation | Address: %p\n", test_addr);
*test_addr = RND_VAL;
}
void test_drom_reg_write_violation(void)
{
uint32_t *test_addr = (uint32_t *)((uint32_t)(foo_buf));
printf("Flash (DROM): Write operation | Address: %p\n", test_addr);
*test_addr = RND_VAL;
}
void test_drom_reg_execute_violation(void)
{
printf("Flash (DROM): Execute operation | Address: %p\n", foo_buf);
void (*func_ptr)(void);
func_ptr = (void(*)(void))foo_buf;
func_ptr();
}
#endif

View File

@ -1,8 +1,9 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
import re import re
from typing import List, Optional, Union from typing import List
from typing import Optional
from typing import Union
import pexpect import pexpect
import pytest import pytest
@ -536,6 +537,11 @@ CONFIGS_MEMPROT_RTC_SLOW_MEM = [
pytest.param('memprot_esp32s2', marks=[pytest.mark.esp32s2]), pytest.param('memprot_esp32s2', marks=[pytest.mark.esp32s2]),
] ]
CONFIGS_MEMPROT_FLASH_IDROM = [
pytest.param('memprot_esp32c6', marks=[pytest.mark.esp32c6]),
pytest.param('memprot_esp32h2', marks=[pytest.mark.esp32h2])
]
@pytest.mark.parametrize('config', CONFIGS_MEMPROT_DCACHE, indirect=True) @pytest.mark.parametrize('config', CONFIGS_MEMPROT_DCACHE, indirect=True)
@pytest.mark.generic @pytest.mark.generic
@ -751,6 +757,33 @@ def test_rtc_slow_reg2_execute_violation(dut: PanicTestDut, test_func_name: str)
dut.expect_corrupted_backtrace() dut.expect_corrupted_backtrace()
@pytest.mark.parametrize('config', CONFIGS_MEMPROT_FLASH_IDROM, indirect=True)
@pytest.mark.generic
def test_irom_reg_write_violation(dut: PanicTestDut, test_func_name: str) -> None:
dut.run_test_func(test_func_name)
if dut.target == 'esp32c6':
dut.expect_gme('Store access fault')
elif dut.target == 'esp32h2':
dut.expect_gme('Cache error')
dut.expect_reg_dump(0)
@pytest.mark.parametrize('config', CONFIGS_MEMPROT_FLASH_IDROM, indirect=True)
@pytest.mark.generic
def test_drom_reg_write_violation(dut: PanicTestDut, test_func_name: str) -> None:
dut.run_test_func(test_func_name)
dut.expect_gme('Store access fault')
dut.expect_reg_dump(0)
@pytest.mark.parametrize('config', CONFIGS_MEMPROT_FLASH_IDROM, indirect=True)
@pytest.mark.generic
def test_drom_reg_execute_violation(dut: PanicTestDut, test_func_name: str) -> None:
dut.run_test_func(test_func_name)
dut.expect_gme('Instruction access fault')
dut.expect_reg_dump(0)
@pytest.mark.esp32 @pytest.mark.esp32
@pytest.mark.parametrize('config', ['gdbstub_coredump'], indirect=True) @pytest.mark.parametrize('config', ['gdbstub_coredump'], indirect=True)
def test_gdbstub_coredump(dut: PanicTestDut) -> None: def test_gdbstub_coredump(dut: PanicTestDut) -> None: