fix(esp_rom): Set poison check hook for tlsf_walk_pool patch

This commit is contained in:
Guillaume Souchere
2026-06-02 08:37:24 +02:00
parent e60589404d
commit fdf45116eb
19 changed files with 505 additions and 67 deletions
@@ -203,7 +203,7 @@ TEST_CASE("test get allocated size", "[heap]")
void *ptr_array[iterations];
for (size_t i = 0; i < iterations; i++) {
ptr_array[i] = heap_caps_malloc(alloc_sizes[i], MALLOC_CAP_DEFAULT);
ptr_array[i] = heap_caps_malloc(alloc_sizes[i], MALLOC_CAP_INTERNAL);
TEST_ASSERT_NOT_NULL(ptr_array[i]);
// test that the heap_caps_get_allocated_size() returns the right number of bytes (aligned to 4 bytes
@@ -216,7 +216,7 @@ TEST_CASE("test get allocated size", "[heap]")
// when the pointer to the first, last (calculated from the requested size) and to a byte
// in the middle of the chunk is passed as parameter
TEST_ASSERT(aligned_size <= heap_caps_get_containing_block_size(ptr_array[i]));
TEST_ASSERT(aligned_size <= heap_caps_get_containing_block_size(ptr_array[i] + alloc_sizes[i]));
TEST_ASSERT(aligned_size <= heap_caps_get_containing_block_size(ptr_array[i] + alloc_sizes[i] - 1));
TEST_ASSERT(aligned_size <= heap_caps_get_containing_block_size(ptr_array[i] + (alloc_sizes[i] / 2)));
heap_caps_free(ptr_array[i]);
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -59,7 +59,7 @@ TEST_CASE("Capabilities allocator test", "[heap]")
m1 = heap_caps_malloc(alloc32, MALLOC_CAP_32BIT);
printf("--> %p\n", m1);
//Check that we got IRAM back
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
TEST_ASSERT(esp_ptr_in_iram(m1));
free8 = heap_caps_get_free_size(MALLOC_CAP_8BIT);
free32 = heap_caps_get_free_size(MALLOC_CAP_32BIT);
printf("Free 8bit-capable memory (after 32-bit): %dK, 32-bit capable memory %dK\n", free8, free32);
@@ -83,8 +83,8 @@ TEST_CASE("Capabilities allocator test", "[heap]")
m2[x]= heap_caps_malloc(alloc32, MALLOC_CAP_32BIT);
printf("--> %p\n", m2[x]);
}
TEST_ASSERT((((int)m2[0])&0xFF000000)==0x40000000);
TEST_ASSERT((((int)m2[9])&0xFF000000)==0x3F000000);
TEST_ASSERT(esp_ptr_in_iram(m2[0]));
TEST_ASSERT(esp_ptr_in_dram(m2[9]));
} else {
printf("This platform has no IRAM-only so changeover will never occur, jumping to next test\n");
@@ -96,7 +96,7 @@ TEST_CASE("Capabilities allocator test", "[heap]")
free_iram = heap_caps_get_free_size(MALLOC_CAP_EXEC);
m1= heap_caps_malloc(MIN(free_iram / 2, 10*1024), MALLOC_CAP_EXEC);
printf("--> %p\n", m1);
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
TEST_ASSERT(esp_ptr_in_iram(m1) || esp_ptr_in_diram_iram(m1));
for (x=0; x<10; x++) free(m2[x]);
} else {
@@ -104,7 +104,7 @@ TEST_CASE("Capabilities allocator test", "[heap]")
free_iram = heap_caps_get_free_size(MALLOC_CAP_EXEC);
m1= heap_caps_malloc(MIN(free_iram / 2, 10*1024), MALLOC_CAP_EXEC);
printf("--> %p\n", m1);
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
TEST_ASSERT(esp_ptr_in_iram(m1) || esp_ptr_in_diram_iram(m1));
}
free(m1);
@@ -366,8 +366,16 @@ TEST_CASE("RTC memory should be lowest priority and its free size should be big
TEST_ASSERT_NOT_NULL(ptr);
TEST_ASSERT(!esp_ptr_in_rtc_dram_fast(ptr));
free_size = heap_caps_get_free_size(MALLOC_CAP_RTCRAM);
TEST_ASSERT_GREATER_OR_EQUAL(1024 * 4, free_size);
const size_t min_rtc_size_since_init = heap_caps_get_minimum_free_size(MALLOC_CAP_RTCRAM);
const size_t rtc_free_size = heap_caps_get_free_size(MALLOC_CAP_RTCRAM);
TEST_ASSERT_EQUAL(min_rtc_size_since_init, rtc_free_size);
/* The ROM TLSF implementation uses a statically-sized control_t (sized for the
* maximum DRAM pool) which has much higher overhead on small pools like RTCRAM.
* The 80% threshold only applies when the IDF TLSF is used. */
#if !CONFIG_HEAP_TLSF_USE_ROM_IMPL
const size_t max_rtc_size = SOC_RTC_DATA_HIGH - SOC_RTC_DATA_LOW;
TEST_ASSERT_GREATER_OR_EQUAL((max_rtc_size * 8) / 10, rtc_free_size);
#endif
free(ptr);
}
@@ -34,7 +34,7 @@ def test_heap_poisoning_qemu(dut: Dut) -> None:
@pytest.mark.generic
@pytest.mark.parametrize('config', ['in_flash'])
@pytest.mark.parametrize('config', ['in_flash', 'in_rom'])
@idf_parametrize('target', ['supported_targets'], indirect=['target'])
def test_heap_in_flash(dut: Dut) -> None:
dut.run_all_single_board_cases()
@@ -0,0 +1,2 @@
CONFIG_HEAP_TLSF_USE_ROM_IMPL=y
CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH=n