mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Malloc test: tabs -> spaces, fix description
This commit is contained in:
parent
3462b53fbc
commit
ab5bbfa74b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Test for multicore FreeRTOS. This test spins up threads, fiddles with queues etc.
|
Generic test for malloc/free
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <esp_types.h>
|
#include <esp_types.h>
|
||||||
@ -17,33 +17,33 @@
|
|||||||
#include "soc/io_mux_reg.h"
|
#include "soc/io_mux_reg.h"
|
||||||
|
|
||||||
static int tryAllocMem() {
|
static int tryAllocMem() {
|
||||||
int **mem;
|
int **mem;
|
||||||
int i, noAllocated, j;
|
int i, noAllocated, j;
|
||||||
mem=malloc(sizeof(int)*1024);
|
mem=malloc(sizeof(int)*1024);
|
||||||
if (!mem) return 0;
|
if (!mem) return 0;
|
||||||
for (i=0; i<1024; i++) {
|
for (i=0; i<1024; i++) {
|
||||||
mem[i]=malloc(1024);
|
mem[i]=malloc(1024);
|
||||||
if (mem[i]==NULL) break;
|
if (mem[i]==NULL) break;
|
||||||
for (j=0; j<1024/4; j++) mem[i][j]=(0xdeadbeef);
|
for (j=0; j<1024/4; j++) mem[i][j]=(0xdeadbeef);
|
||||||
}
|
}
|
||||||
noAllocated=i;
|
noAllocated=i;
|
||||||
for (i=0; i<noAllocated; i++) {
|
for (i=0; i<noAllocated; i++) {
|
||||||
for (j=0; j<1024/4; j++) {
|
for (j=0; j<1024/4; j++) {
|
||||||
TEST_ASSERT(mem[i][j]==(0xdeadbeef));
|
TEST_ASSERT(mem[i][j]==(0xdeadbeef));
|
||||||
}
|
}
|
||||||
free(mem[i]);
|
free(mem[i]);
|
||||||
}
|
}
|
||||||
free(mem);
|
free(mem);
|
||||||
return noAllocated;
|
return noAllocated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("Malloc/overwrite, then free all available DRAM", "[freertos]")
|
TEST_CASE("Malloc/overwrite, then free all available DRAM", "[freertos]")
|
||||||
{
|
{
|
||||||
int m1=0, m2=0;
|
int m1=0, m2=0;
|
||||||
m1=tryAllocMem();
|
m1=tryAllocMem();
|
||||||
m2=tryAllocMem();
|
m2=tryAllocMem();
|
||||||
printf("Could allocate %dK on first try, %dK on 2nd try.\n", m1, m2);
|
printf("Could allocate %dK on first try, %dK on 2nd try.\n", m1, m2);
|
||||||
TEST_ASSERT(m1==m2);
|
TEST_ASSERT(m1==m2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user