Add more test

This commit is contained in:
Mathieu Maret 2021-10-26 23:26:42 +02:00
parent 7f6bb8eef3
commit 9ae500f06e

View File

@ -1,4 +1,5 @@
#include "alloc.h" #include "alloc.h"
#include "allocArea.h"
#include "ata.h" #include "ata.h"
#include "assert.h" #include "assert.h"
#include "cpu_context.h" #include "cpu_context.h"
@ -84,14 +85,22 @@ static void *testAllocNSet(size_t size)
return allocated; return allocated;
} }
static void testAlloc(void) void testAllocArea(){
vaddr_t area = areaAlloc(1, 0);
vaddr_t area2 = areaAlloc(1, AREA_PHY_MAP);
assert(area != area2);
areaFree(area);
areaFree(area2);
}
void testAlloc(void)
{ {
assert(malloc(1410065407) == NULL); assert(malloc(1410065407) == NULL);
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)); assert(malloc(sizeof(struct slabEntry)) != NULL);
} }
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(sizeof(struct slabDesc)) != NULL);
} }
assert(malloc(1)); assert(malloc(1));
assert(malloc(2)); assert(malloc(2));
@ -103,6 +112,8 @@ static void testAlloc(void)
free(malloc2); free(malloc2);
void *malloc3 = malloc(sizeof(void *)); void *malloc3 = malloc(sizeof(void *));
assertmsg((char *)malloc2 == (char *)malloc3, " %d %d\n", malloc2, malloc3); assertmsg((char *)malloc2 == (char *)malloc3, " %d %d\n", malloc2, malloc3);
free(malloc1);
free(malloc3);
void *alloc1 = testAllocNSet(1024); void *alloc1 = testAllocNSet(1024);
void *alloc2 = testAllocNSet(1024); void *alloc2 = testAllocNSet(1024);
void *alloc3 = testAllocNSet(1024); void *alloc3 = testAllocNSet(1024);
@ -388,6 +399,7 @@ void run_test(void)
serialPutc('l'); serialPutc('l');
serialPutc('o'); serialPutc('o');
testAlloc(); testAlloc();
testAllocArea();
printf("Testing backtrace\n"); printf("Testing backtrace\n");
test_backtrace(); test_backtrace();
testCoroutine(); testCoroutine();