TOFIX: implement testing for paging
This commit is contained in:
parent
4a5f5674ce
commit
a120647ecb
@ -8,3 +8,4 @@
|
|||||||
int pagingSetup(paddr_t upperKernelAddr);
|
int pagingSetup(paddr_t upperKernelAddr);
|
||||||
|
|
||||||
int pageMap(vaddr_t vaddr, paddr_t paddr, int flags);
|
int pageMap(vaddr_t vaddr, paddr_t paddr, int flags);
|
||||||
|
int pageUnmap(vaddr_t vaddr);
|
||||||
|
40
tests/test.c
40
tests/test.c
@ -1,5 +1,6 @@
|
|||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
#include "paging.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "vga.h"
|
#include "vga.h"
|
||||||
|
|
||||||
@ -38,8 +39,47 @@ void testPhymem(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void testPaging(void)
|
||||||
|
{
|
||||||
|
printf("Testing paging\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 *)allocPhyPage()) != NULL) {
|
||||||
|
pageMap((vaddr_t)page, (paddr_t)page, 0);
|
||||||
|
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 (unrefPhyPage((ulong)page)) {
|
||||||
|
printf("Failed to free page %d\n", (ulong)page);
|
||||||
|
}
|
||||||
|
pageUnmap((vaddr_t)page);
|
||||||
|
freeCount++;
|
||||||
|
}
|
||||||
|
printf("%d pages freed\n", freeCount);
|
||||||
|
|
||||||
|
if ((page = (struct mem_desc *)allocPhyPage()) == NULL) {
|
||||||
|
printf("Error ! Cannot allocate memory\n");
|
||||||
|
} else {
|
||||||
|
unrefPhyPage((ulong)page);
|
||||||
|
pageUnmap((vaddr_t)page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void run_test(void)
|
void run_test(void)
|
||||||
{
|
{
|
||||||
|
testPaging();
|
||||||
printf("Testing Serial");
|
printf("Testing Serial");
|
||||||
serialWrite('h');
|
serialWrite('h');
|
||||||
serialWrite('e');
|
serialWrite('e');
|
||||||
|
Loading…
Reference in New Issue
Block a user