Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Nautilus Host Support (proof of concept)
[palacios.git] / nautilus / palacios-nautilus-mm-test.c
diff --git a/nautilus/palacios-nautilus-mm-test.c b/nautilus/palacios-nautilus-mm-test.c
new file mode 100644 (file)
index 0000000..ad39a7a
--- /dev/null
@@ -0,0 +1,68 @@
+/* 
+ * Unit test for palacios-nautilus memory allocator 
+ * Can be invoked in init_palacios_nautilus_mm 
+ */
+
+#include <nautilus/printk.h> // 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");
+}