test: add more malloc/free test

This commit is contained in:
Mathieu Maret 2019-04-17 23:47:25 +02:00
parent 340ae6a4d0
commit 3cda78532b
1 changed files with 36 additions and 10 deletions

View File

@ -38,12 +38,20 @@ void testPhymem(void)
unrefPhyPage((ulong)page);
}
static void *testAllocNSet(size_t size)
{
void *allocated = malloc(size);
assert(allocated);
memset(allocated, size, size);
return allocated;
}
static void testAlloc(void)
{
for( uint i = 0; i < PAGE_SIZE/(sizeof(struct slabEntry)); i++){
for (uint i = 0; i < PAGE_SIZE / (sizeof(struct slabEntry)); i++) {
malloc(sizeof(struct slabEntry));
}
for( uint i = 0; i < PAGE_SIZE/(sizeof(struct slabDesc)); i++){
for (uint i = 0; i < PAGE_SIZE / (sizeof(struct slabDesc)); i++) {
malloc(sizeof(struct slabDesc));
}
assert(malloc(1));
@ -56,14 +64,32 @@ static void testAlloc(void)
free(malloc2);
void *malloc3 = malloc(sizeof(void *));
assertmsg((char *)malloc2 == (char *)malloc3, " %d %d\n", malloc2, malloc3);
assert(malloc(1024));
assert(malloc(1024));
assert(malloc(1024));
assert(malloc(1024));
assert(malloc(1024));
assert(malloc(1024));
assert(malloc(2048));
//assert(malloc(4096));
void *alloc1 = testAllocNSet(1024);
void *alloc2 = testAllocNSet(1024);
void *alloc3 = testAllocNSet(1024);
void *alloc4 = testAllocNSet(1024);
void *alloc5 = testAllocNSet(1024);
void *alloc6 = testAllocNSet(1024);
void *alloc7 = testAllocNSet(4096);
free(alloc1);
free(alloc2);
free(alloc3);
free(alloc4);
free(alloc5);
free(alloc6);
free(alloc7);
void *alloc11 = testAllocNSet(1024);
void *alloc12 = testAllocNSet(1024);
void *alloc13 = testAllocNSet(1024);
void *alloc14 = testAllocNSet(1024);
void *alloc15 = testAllocNSet(1024);
void *alloc16 = testAllocNSet(1024);
free(alloc11);
free(alloc12);
free(alloc13);
free(alloc14);
free(alloc15);
free(alloc16);
}
static void testPaging(void)