heap/test_malloc_caps: changed malloc caps test to deal with esp32 and esp32s2 memory differencies.
This commit is contained in:
parent
cf95ea40d4
commit
ecc4955c68
1 changed files with 47 additions and 26 deletions
|
@ -24,7 +24,7 @@ TEST_CASE("Capabilities allocator test", "[heap]")
|
||||||
free8start = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
free8start = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||||
free32start = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
free32start = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||||
printf("Free 8bit-capable memory (start): %dK, 32-bit capable memory %dK\n", free8start, free32start);
|
printf("Free 8bit-capable memory (start): %dK, 32-bit capable memory %dK\n", free8start, free32start);
|
||||||
TEST_ASSERT(free32start>free8start);
|
TEST_ASSERT(free32start >= free8start);
|
||||||
|
|
||||||
printf("Allocating 10K of 8-bit capable RAM\n");
|
printf("Allocating 10K of 8-bit capable RAM\n");
|
||||||
m1= heap_caps_malloc(10*1024, MALLOC_CAP_8BIT);
|
m1= heap_caps_malloc(10*1024, MALLOC_CAP_8BIT);
|
||||||
|
@ -44,39 +44,60 @@ TEST_CASE("Capabilities allocator test", "[heap]")
|
||||||
size_t free_iram = heap_caps_get_free_size(MALLOC_CAP_INTERNAL) -
|
size_t free_iram = heap_caps_get_free_size(MALLOC_CAP_INTERNAL) -
|
||||||
heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
|
heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
|
||||||
size_t alloc32 = MIN(free_iram / 2, 10*1024) & (~3);
|
size_t alloc32 = MIN(free_iram / 2, 10*1024) & (~3);
|
||||||
printf("Freeing; allocating %u bytes of 32K-capable RAM\n", alloc32);
|
if(free_iram) {
|
||||||
m1 = heap_caps_malloc(alloc32, MALLOC_CAP_32BIT);
|
printf("Freeing; allocating %u bytes of 32K-capable RAM\n", alloc32);
|
||||||
printf("--> %p\n", m1);
|
m1 = heap_caps_malloc(alloc32, MALLOC_CAP_32BIT);
|
||||||
//Check that we got IRAM back
|
printf("--> %p\n", m1);
|
||||||
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
|
//Check that we got IRAM back
|
||||||
free8 = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
|
||||||
free32 = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
free8 = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||||
printf("Free 8bit-capable memory (after 32-bit): %dK, 32-bit capable memory %dK\n", free8, free32);
|
free32 = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||||
//Only 32-bit should have gone down by alloc32: 32-bit isn't necessarily 8bit capable
|
printf("Free 8bit-capable memory (after 32-bit): %dK, 32-bit capable memory %dK\n", free8, free32);
|
||||||
TEST_ASSERT(free32<(free32start-alloc32));
|
//Only 32-bit should have gone down by alloc32: 32-bit isn't necessarily 8bit capable
|
||||||
TEST_ASSERT(free8==free8start);
|
TEST_ASSERT(free32<(free32start-alloc32));
|
||||||
free(m1);
|
TEST_ASSERT(free8==free8start);
|
||||||
|
free(m1);
|
||||||
|
} else {
|
||||||
|
printf("This platform has no 32-bit only capable RAM, jumping to next test \n");
|
||||||
|
}
|
||||||
|
|
||||||
printf("Allocating impossible caps\n");
|
printf("Allocating impossible caps\n");
|
||||||
m1= heap_caps_malloc(10*1024, MALLOC_CAP_8BIT|MALLOC_CAP_EXEC);
|
m1= heap_caps_malloc(10*1024, MALLOC_CAP_8BIT|MALLOC_CAP_EXEC);
|
||||||
printf("--> %p\n", m1);
|
printf("--> %p\n", m1);
|
||||||
TEST_ASSERT(m1==NULL);
|
TEST_ASSERT(m1==NULL);
|
||||||
printf("Testing changeover iram -> dram");
|
|
||||||
// priorities will exhaust IRAM first, then start allocating from DRAM
|
if(free_iram) {
|
||||||
for (x=0; x<10; x++) {
|
printf("Testing changeover iram -> dram");
|
||||||
m2[x]= heap_caps_malloc(alloc32, MALLOC_CAP_32BIT);
|
// priorities will exhaust IRAM first, then start allocating from DRAM
|
||||||
printf("--> %p\n", m2[x]);
|
for (x=0; x<10; x++) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("This platform has no IRAM-only so changeover will never occur, jumping to next test\n");
|
||||||
}
|
}
|
||||||
TEST_ASSERT((((int)m2[0])&0xFF000000)==0x40000000);
|
|
||||||
TEST_ASSERT((((int)m2[9])&0xFF000000)==0x3F000000);
|
|
||||||
printf("Test if allocating executable code still gives IRAM, even with dedicated IRAM region depleted\n");
|
printf("Test if allocating executable code still gives IRAM, even with dedicated IRAM region depleted\n");
|
||||||
// (the allocation should come from D/IRAM)
|
if(free_iram) {
|
||||||
free_iram = heap_caps_get_free_size(MALLOC_CAP_EXEC);
|
// (the allocation should come from D/IRAM)
|
||||||
m1= heap_caps_malloc(MIN(free_iram / 2, 10*1024), MALLOC_CAP_EXEC);
|
free_iram = heap_caps_get_free_size(MALLOC_CAP_EXEC);
|
||||||
printf("--> %p\n", m1);
|
m1= heap_caps_malloc(MIN(free_iram / 2, 10*1024), MALLOC_CAP_EXEC);
|
||||||
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
|
printf("--> %p\n", m1);
|
||||||
|
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
|
||||||
|
for (x=0; x<10; x++) free(m2[x]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// (the allocation should come from D/IRAM)
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
free(m1);
|
free(m1);
|
||||||
for (x=0; x<10; x++) free(m2[x]);
|
|
||||||
printf("Done.\n");
|
printf("Done.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue