heap: fix the size of buffers in ignored tests

the ignored tests are updated with the minimum required buffer size to create
a new heap using the tlsf heap callocator.
This commit is contained in:
Guillaume Souchere 2022-10-05 12:00:21 +02:00
parent 87ea3142ac
commit a29627f59d
4 changed files with 18 additions and 17 deletions

View File

@ -1,4 +1,4 @@
set(src_test "test_app_main.c"
set(src_test "test_heap_main.c"
"test_aligned_alloc_caps.c"
"test_allocator_timings.c"
"test_corruption_check.c"

View File

@ -8,7 +8,7 @@
#include "unity_test_runner.h"
#include "esp_heap_caps.h"
#define TEST_MEMORY_LEAK_THRESHOLD (-1024)
#define TEST_MEMORY_LEAK_THRESHOLD (-3000)
static size_t before_free_8bit;
static size_t before_free_32bit;

View File

@ -15,13 +15,17 @@
#include "esp_system.h"
#include "heap_memory_layout.h"
#include "../tlsf/tlsf.h"
/* NOTE: This is not a well-formed unit test, it leaks memory */
TEST_CASE("Allocate new heap at runtime", "[heap][ignore]")
{
const size_t BUF_SZ = 1000;
const size_t HEAP_OVERHEAD_MAX = 200;
// 60 bytes of overhead in multi_heap + size of control_t from tlsf
const size_t HEAP_OVERHEAD_MAX = tlsf_size() + 60;
const size_t MIN_HEAP_SIZE = HEAP_OVERHEAD_MAX + tlsf_block_size_min();
const size_t BUF_SZ = MIN_HEAP_SIZE;
void *buffer = malloc(BUF_SZ);
TEST_ASSERT_NOT_NULL(buffer);
uint32_t before_free = esp_get_free_heap_size();
TEST_ESP_OK( heap_caps_add_region((intptr_t)buffer, (intptr_t)buffer + BUF_SZ) );
@ -36,12 +40,12 @@ TEST_CASE("Allocate new heap at runtime", "[heap][ignore]")
*/
TEST_CASE("Allocate new heap with new capability", "[heap][ignore]")
{
const size_t BUF_SZ = 100;
#ifdef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
const size_t ALLOC_SZ = 32;
#else
const size_t ALLOC_SZ = 64; // More than half of BUF_SZ
#endif
// 60 bytes of multi_heap structures overhead + size of control_t from tlsf
const size_t HEAP_OVERHEAD = tlsf_size() + 60;
const size_t MIN_HEAP_SIZE = HEAP_OVERHEAD + tlsf_block_size_min();
const size_t BUF_SZ = MIN_HEAP_SIZE;
const size_t ALLOC_SZ = tlsf_block_size_min();
const uint32_t MALLOC_CAP_INVENTED = (1 << 30); /* this must be unused in esp_heap_caps.h */
/* no memory exists to provide this capability */
@ -62,8 +66,8 @@ TEST_CASE("Allocate new heap with new capability", "[heap][ignore]")
TEST_CASE("Add .bss memory to heap region runtime", "[heap][ignore]")
{
#define BUF_SZ 1000
#define HEAP_OVERHEAD_MAX 200
#define HEAP_OVERHEAD_MAX 3248
#define BUF_SZ 3260
static uint8_t s_buffer[BUF_SZ];
printf("s_buffer start %08x end %08x\n", (intptr_t)s_buffer, (intptr_t)s_buffer + BUF_SZ);
@ -73,9 +77,6 @@ TEST_CASE("Add .bss memory to heap region runtime", "[heap][ignore]")
printf("Before %"PRIu32" after %"PRIu32"\n", before_free, after_free);
/* allow for some 'heap overhead' from accounting structures */
TEST_ASSERT(after_free >= before_free + BUF_SZ - HEAP_OVERHEAD_MAX);
/* Twice add must be failed */
TEST_ASSERT( (heap_caps_add_region((intptr_t)s_buffer, (intptr_t)s_buffer + BUF_SZ) != ESP_OK) );
}
extern esp_err_t heap_caps_check_add_region_allowed(intptr_t heap_start, intptr_t heap_end, intptr_t start, intptr_t end);

View File

@ -17,7 +17,7 @@ from pytest_embedded import Dut
)
def test_heap_poisoning(dut: Dut) -> None:
dut.expect_exact('Press ENTER to see the list of tests')
dut.write('![ignore]')
dut.write('*')
dut.expect_unity_test_output(timeout=300)
@ -34,7 +34,7 @@ def test_heap_poisoning(dut: Dut) -> None:
)
def test_heap(dut: Dut) -> None:
dut.expect_exact('Press ENTER to see the list of tests')
dut.write('![ignore]')
dut.write('*')
dut.expect_unity_test_output(timeout=300)