mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 05:34:32 +02:00
heap: Add memory protection activation test
Check that when trying to allocate in IRAM with the system memory protection enabled, null pointer is returned, or that an address in IRAM is returned if the memory protection is disabled.
This commit is contained in:
@@ -3,8 +3,3 @@
|
||||
components/heap/host_test/host_test_linux:
|
||||
enable:
|
||||
- if: IDF_TARGET == "linux"
|
||||
components/heap/test_apps:
|
||||
disable_test:
|
||||
- if: IDF_TARGET == "esp32c6"
|
||||
temporary: true
|
||||
reason: target esp32c6 is not supported yet
|
||||
|
@@ -278,3 +278,23 @@ TEST_CASE("RTC memory shoule be lowest priority and its free size should be big
|
||||
free(ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("test memory protection features", "[heap][mem_prot]")
|
||||
{
|
||||
// try to allocate memory in IRAM and check that if memory protection is active,
|
||||
// no memory is being allocated
|
||||
uint32_t *iram_ptr = heap_caps_malloc(4, MALLOC_CAP_EXEC);
|
||||
|
||||
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
|
||||
// System memory protection not active, check that iram_ptr is not null
|
||||
// Check that iram_ptr is in IRAM
|
||||
TEST_ASSERT_NOT_NULL(iram_ptr);
|
||||
TEST_ASSERT(true == esp_ptr_in_iram(iram_ptr));
|
||||
|
||||
// free the memory
|
||||
heap_caps_free(iram_ptr);
|
||||
#else
|
||||
// System memory protection is active, DIRAM seen as DRAM, iram_ptr should be null
|
||||
TEST_ASSERT_NULL(iram_ptr);
|
||||
#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
import pytest
|
||||
@@ -92,3 +92,18 @@ def test_heap_trace_dump(dut: Dut) -> None:
|
||||
dut.expect_exact('Enter next test, or \'enter\' to see menu')
|
||||
dut.write('[heap-trace]')
|
||||
dut.expect_unity_test_output(timeout=100)
|
||||
|
||||
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.supported_targets
|
||||
@pytest.mark.temp_skip_ci(targets=['esp32c3', 'esp32s3'], reason='test failed')
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'mem_prot'
|
||||
]
|
||||
)
|
||||
def test_memory_protection(dut: Dut) -> None:
|
||||
dut.expect_exact('Press ENTER to see the list of tests')
|
||||
dut.write('[heap][mem_prot]')
|
||||
dut.expect_unity_test_output(timeout=300)
|
||||
|
1
components/heap/test_apps/sdkconfig.ci.mem_prot
Normal file
1
components/heap/test_apps/sdkconfig.ci.mem_prot
Normal file
@@ -0,0 +1 @@
|
||||
CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=y
|
Reference in New Issue
Block a user