2 * Unit test for palacios-nautilus memory allocator
3 * Can be invoked in init_palacios_nautilus_mm
6 #include <nautilus/printk.h> // for panic
8 #include "palacios-nautilus-mm.h"
9 #include "palacios-nautilus-mm-test.h"
12 void test_palacios_mm(unsigned num_pages_limit)
16 unsigned alignment = 4096; // gonna keep this constant for now since palacios only uses 4k pages
17 num_pages_limit -= 10;
19 /* Allocate a gigantic piece of memory at once */
20 some_ptr = alloc_palacios_pgs(num_pages_limit, alignment, 0, 0, 0);
22 printk("ERROR IN PALACIOS-MM TEST: returned bogus address when not supposed to\n");
25 free_palacios_pgs(some_ptr, num_pages_limit);
27 /* check if free_palacios_pg worked */
28 some_ptr = alloc_palacios_pgs(100, alignment, 0, 0, 0);
30 printk("FREE_PALACIOS_PGS DIDN'T WORK\n");
34 /* Allocate many small pieces of memory consecutively */
35 for(i = 0; i < num_pages_limit/100; i++) {
36 free_palacios_pgs(some_ptr, 100);
37 some_ptr = alloc_palacios_pgs(100, alignment, 0, 0, 0);
39 printk("ERROR IN PALACIOS-MM TEST: returned bogus address when not supposed to\n");
44 free_palacios_pgs(some_ptr, 100);
46 uintptr_t ptrs[num_pages_limit];
48 for(i = 0; i < num_pages_limit/100; i++) {
49 ptrs[i] = alloc_palacios_pgs(100, alignment, 0, 0, 0);
52 // first free random pages and then try to allocate them again
53 free_palacios_pgs(ptrs[0], 100);
54 free_palacios_pgs(ptrs[3], 100);
55 free_palacios_pgs(ptrs[4], 100);
57 ptrs[0] = alloc_palacios_pgs(100, alignment, 0, 0, 0);
58 ptrs[3] = alloc_palacios_pgs(100, alignment, 0, 0, 0);
59 ptrs[4] = alloc_palacios_pgs(100, alignment, 0, 0, 0);
61 for(i = 0; i < num_pages_limit/100; i++) {
62 free_palacios_pgs(ptrs[i], 100);
66 // TODO: WRITE MORE TESTS
67 printk("ALL TESTS PASSED - FREED ALL MEMORY\n");