forked from espressif/esp-idf
Merge branch 'refactor/hal_mpu_test' into 'master'
refactor(tools/test_apps): Move HAL tests for MPU to the `panic` test-app Closes IDF-5590 See merge request espressif/esp-idf!26422
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
idf_component_register(SRC_DIRS "."
|
|
||||||
PRIV_INCLUDE_DIRS "${include_dirs}"
|
|
||||||
PRIV_REQUIRES cmock test_utils)
|
|
@@ -1,53 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "unity.h"
|
|
||||||
|
|
||||||
#include "esp_attr.h"
|
|
||||||
|
|
||||||
#include "hal/mpu_hal.h"
|
|
||||||
|
|
||||||
// TODO ESP32-C3 IDF-2375
|
|
||||||
// LL still not implemented
|
|
||||||
|
|
||||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3)
|
|
||||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2, ESP32C6, ESP32H2)
|
|
||||||
//IDF-5058
|
|
||||||
|
|
||||||
volatile static int RTC_NOINIT_ATTR access = 0;
|
|
||||||
|
|
||||||
static void trigger_illegal_access(void)
|
|
||||||
{
|
|
||||||
access = 0;
|
|
||||||
intptr_t addr = 0x80000000; // MPU region 4
|
|
||||||
volatile int __attribute__((unused)) val = 0;
|
|
||||||
|
|
||||||
// Marked as an illegal access region at startup in ESP32, ESP32S2.
|
|
||||||
// Make accessible temporarily.
|
|
||||||
mpu_hal_set_region_access(4, MPU_REGION_RW);
|
|
||||||
|
|
||||||
val = *((int*) addr);
|
|
||||||
++access;
|
|
||||||
TEST_ASSERT_EQUAL(1, access);
|
|
||||||
printf("Sucessfully accessed location %p\r\n", (void*)addr);
|
|
||||||
|
|
||||||
// Make access to region illegal again.
|
|
||||||
mpu_hal_set_region_access(4, MPU_REGION_ILLEGAL);
|
|
||||||
++access;
|
|
||||||
|
|
||||||
// Since access to region is illegal, this should fail (causing a reset), and the increment
|
|
||||||
// to access count is not performed.
|
|
||||||
val = *((int*) addr);
|
|
||||||
++access;
|
|
||||||
}
|
|
||||||
|
|
||||||
void check_access(void)
|
|
||||||
{
|
|
||||||
TEST_ASSERT_EQUAL(2, access);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE_MULTIPLE_STAGES("Can set illegal access regions", "[soc][mpu]",
|
|
||||||
trigger_illegal_access,
|
|
||||||
check_access);
|
|
||||||
|
|
||||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(...)
|
|
||||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3)
|
|
@@ -546,7 +546,6 @@ components/freertos/FreeRTOS-Kernel-SMP/timers.c
|
|||||||
components/hal/include/hal/dac_types.h
|
components/hal/include/hal/dac_types.h
|
||||||
components/hal/spi_slave_hal.c
|
components/hal/spi_slave_hal.c
|
||||||
components/hal/spi_slave_hal_iram.c
|
components/hal/spi_slave_hal_iram.c
|
||||||
components/hal/test/test_mpu.c
|
|
||||||
components/heap/test_multi_heap_host/main.cpp
|
components/heap/test_multi_heap_host/main.cpp
|
||||||
components/heap/test_multi_heap_host/test_multi_heap.cpp
|
components/heap/test_multi_heap_host/test_multi_heap.cpp
|
||||||
components/idf_test/include/idf_performance.h
|
components/idf_test/include/idf_performance.h
|
||||||
|
@@ -53,6 +53,8 @@ void test_assert(void);
|
|||||||
|
|
||||||
void test_assert_cache_disabled(void);
|
void test_assert_cache_disabled(void);
|
||||||
|
|
||||||
|
void test_illegal_access(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -100,6 +100,9 @@ void app_main(void)
|
|||||||
HANDLE_TEST(test_name, test_ub);
|
HANDLE_TEST(test_name, test_ub);
|
||||||
HANDLE_TEST(test_name, test_assert);
|
HANDLE_TEST(test_name, test_assert);
|
||||||
HANDLE_TEST(test_name, test_assert_cache_disabled);
|
HANDLE_TEST(test_name, test_assert_cache_disabled);
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
|
HANDLE_TEST(test_name, test_illegal_access);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CONFIG_TEST_MEMPROT
|
#if CONFIG_TEST_MEMPROT
|
||||||
|
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
|
||||||
|
#include "hal/mpu_hal.h"
|
||||||
|
|
||||||
/* Test utility function */
|
/* Test utility function */
|
||||||
|
|
||||||
extern void esp_restart_noos(void) __attribute__ ((noreturn));
|
extern void esp_restart_noos(void) __attribute__ ((noreturn));
|
||||||
@@ -202,3 +204,31 @@ void test_ub(void)
|
|||||||
uint8_t stuff[1] = {rand()};
|
uint8_t stuff[1] = {rand()};
|
||||||
printf("%d\n", stuff[rand()]);
|
printf("%d\n", stuff[rand()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: The following test verifies the behaviour for the
|
||||||
|
* Xtensa-specific MPU instructions (Refer WDTLB, DSYNC, WDTIB, ISYNC)
|
||||||
|
* used for memory protection.
|
||||||
|
*
|
||||||
|
* However, this test is not valid for S2 and S3, because they have PMS
|
||||||
|
* enabled on top of this, giving unpredicatable results.
|
||||||
|
*/
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
|
void test_illegal_access(void)
|
||||||
|
{
|
||||||
|
intptr_t addr = 0x80000000; // MPU region 4
|
||||||
|
volatile int __attribute__((unused)) val = INT16_MAX;
|
||||||
|
|
||||||
|
// Marked as an illegal access region at startup in ESP32, ESP32S2.
|
||||||
|
// Make accessible temporarily.
|
||||||
|
mpu_hal_set_region_access(4, MPU_REGION_RW);
|
||||||
|
|
||||||
|
val = *((int*) addr);
|
||||||
|
printf("[1] val: %d at %p\n", val, (void *)addr);
|
||||||
|
|
||||||
|
// Make access to region illegal again.
|
||||||
|
mpu_hal_set_region_access(4, MPU_REGION_ILLEGAL);
|
||||||
|
val = *((int*) addr);
|
||||||
|
// Does not reach here as device resets due to illegal access
|
||||||
|
printf("[2] val: %d at %p\n", val, (void *)addr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@@ -822,3 +822,17 @@ def test_hw_stack_guard_cpu0(dut: PanicTestDut, config: str, test_func_name: str
|
|||||||
dut.expect_exact('Stack pointer: 0x')
|
dut.expect_exact('Stack pointer: 0x')
|
||||||
dut.expect(r'Stack bounds: 0x(.*) - 0x')
|
dut.expect(r'Stack bounds: 0x(.*) - 0x')
|
||||||
common_test(dut, config)
|
common_test(dut, config)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.parametrize('config', ['panic'], indirect=True)
|
||||||
|
@pytest.mark.generic
|
||||||
|
def test_illegal_access(dut: PanicTestDut, config: str, test_func_name: str) -> None:
|
||||||
|
dut.run_test_func(test_func_name)
|
||||||
|
if dut.is_xtensa:
|
||||||
|
dut.expect(r'\[1\] val: (-?\d+) at 0x80000000', timeout=30)
|
||||||
|
dut.expect_gme('LoadProhibited')
|
||||||
|
dut.expect_reg_dump(0)
|
||||||
|
dut.expect_backtrace()
|
||||||
|
dut.expect_elf_sha256()
|
||||||
|
dut.expect_none('Guru Meditation')
|
||||||
|
Reference in New Issue
Block a user