matos/tests/test.c
Mathieu Maret a7b6139f06 fix page alloc
And add some test for it
2018-11-09 16:30:42 +01:00

51 lines
1.1 KiB
C

#include "list.h"
#include "mem.h"
#include "serial.h"
#include "vga.h"
static void testPhymem()
{
printf("Testing memory PHY\n");
struct mem_desc *allocated_page_list;
struct mem_desc
*page; // Cast in mem_desc to use it. In fact it's the addr of 4K free memory
list_init(allocated_page_list);
int allocCount = 0;
int freeCount = 0;
while ((page = (struct mem_desc *)allocPage()) != NULL) {
page->phy_addr = allocCount;
allocCount++;
list_add_tail(allocated_page_list, page);
}
printf("%d pages allocated\n", allocCount);
while ((page = list_pop_head(allocated_page_list)) != NULL) {
if (page->phy_addr != (ulong)freeCount) {
printf("Error page %d modified\n", (ulong)page);
}
if (unrefPage((ulong)page)) {
printf("Failed to free page %d\n", (ulong)page);
}
freeCount++;
}
printf("%d pages freed\n", freeCount);
if ((page = (struct mem_desc *)allocPage()) == NULL) {
printf("Error ! Cannot allocate memory\n");
} else {
unrefPage((ulong)page);
}
}
void run_test()
{
testPhymem();
printf("Testing Serial");
serialWrite('h');
serialWrite('e');
serialWrite('l');
serialWrite('l');
serialWrite('o');
}