mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 12:10:59 +00:00
Heap: fix free bytes calculation for TLSF heap
* Closes https://github.com/espressif/esp-idf/issues/8270
This commit is contained in:
@@ -503,3 +503,23 @@ TEST_CASE("multi_heap aligned allocations", "[multi_heap]")
|
||||
printf("[ALIGNED_ALLOC] heap_size after: %d \n", multi_heap_free_size(heap));
|
||||
REQUIRE((old_size - multi_heap_free_size(heap)) <= leakage);
|
||||
}
|
||||
|
||||
// TLSF has some overhead when allocating blocks, check that overhead
|
||||
TEST_CASE("multi_heap allocation overhead", "[multi_heap]")
|
||||
{
|
||||
uint8_t heapdata[4 * 1024];
|
||||
size_t alloc_size = 256;
|
||||
multi_heap_handle_t heap = multi_heap_register(heapdata, sizeof(heapdata));
|
||||
size_t free_bytes_1 = multi_heap_free_size(heap);
|
||||
|
||||
/* Allocate any amount of data, in any case there will be an overhead */
|
||||
void *x = multi_heap_malloc(heap, alloc_size);
|
||||
|
||||
/* free_bytes_2 should be free_bytes_1 - alloc_size - overhead.
|
||||
* We don't know the value of overhead, let's check that it is non-zero */
|
||||
size_t free_bytes_2 = multi_heap_free_size(heap);
|
||||
REQUIRE( free_bytes_1 > free_bytes_2 );
|
||||
REQUIRE( free_bytes_1 - free_bytes_2 > alloc_size );
|
||||
|
||||
multi_heap_free(heap, x);
|
||||
}
|
||||
|
Reference in New Issue
Block a user