X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=nautilus%2Fpalacios-nautilus-mm-test.c;fp=nautilus%2Fpalacios-nautilus-mm-test.c;h=ad39a7acc8e4f27d677a610cccd7aa1f2f57c23c;hp=0000000000000000000000000000000000000000;hb=66c338acdc299d7496da982999ff3cd3828e442a;hpb=68f8c4cd303c5da40c1083cbabdaf6395e4dbaa1 diff --git a/nautilus/palacios-nautilus-mm-test.c b/nautilus/palacios-nautilus-mm-test.c new file mode 100644 index 0000000..ad39a7a --- /dev/null +++ b/nautilus/palacios-nautilus-mm-test.c @@ -0,0 +1,68 @@ +/* + * Unit test for palacios-nautilus memory allocator + * Can be invoked in init_palacios_nautilus_mm + */ + +#include // for panic + +#include "palacios-nautilus-mm.h" +#include "palacios-nautilus-mm-test.h" +#include "palacios.h" + +void test_palacios_mm(unsigned num_pages_limit) +{ + uintptr_t some_ptr; + unsigned int i = 0; + unsigned alignment = 4096; // gonna keep this constant for now since palacios only uses 4k pages + num_pages_limit -= 10; + + /* Allocate a gigantic piece of memory at once */ + some_ptr = alloc_palacios_pgs(num_pages_limit, alignment, 0, 0, 0); + if(!some_ptr) { + printk("ERROR IN PALACIOS-MM TEST: returned bogus address when not supposed to\n"); + panic(); + } + free_palacios_pgs(some_ptr, num_pages_limit); + + /* check if free_palacios_pg worked */ + some_ptr = alloc_palacios_pgs(100, alignment, 0, 0, 0); + if(!some_ptr) { + printk("FREE_PALACIOS_PGS DIDN'T WORK\n"); + panic(); + } + + /* Allocate many small pieces of memory consecutively */ + for(i = 0; i < num_pages_limit/100; i++) { + free_palacios_pgs(some_ptr, 100); + some_ptr = alloc_palacios_pgs(100, alignment, 0, 0, 0); + if (!some_ptr) { + printk("ERROR IN PALACIOS-MM TEST: returned bogus address when not supposed to\n"); + panic(); + } + } + + free_palacios_pgs(some_ptr, 100); + + uintptr_t ptrs[num_pages_limit]; + + for(i = 0; i < num_pages_limit/100; i++) { + ptrs[i] = alloc_palacios_pgs(100, alignment, 0, 0, 0); + } + + // first free random pages and then try to allocate them again + free_palacios_pgs(ptrs[0], 100); + free_palacios_pgs(ptrs[3], 100); + free_palacios_pgs(ptrs[4], 100); + + ptrs[0] = alloc_palacios_pgs(100, alignment, 0, 0, 0); + ptrs[3] = alloc_palacios_pgs(100, alignment, 0, 0, 0); + ptrs[4] = alloc_palacios_pgs(100, alignment, 0, 0, 0); + + for(i = 0; i < num_pages_limit/100; i++) { + free_palacios_pgs(ptrs[i], 100); + } + + + // TODO: WRITE MORE TESTS + printk("ALL TESTS PASSED - FREED ALL MEMORY\n"); +}