Added malloc test to check whether large page magic works.
authorSimon Gerber <simon.gerber@hp.com>
Fri, 18 Jul 2014 00:44:55 +0000 (17:44 -0700)
committerSimon Gerber <simon.gerber@inf.ethz.ch>
Mon, 4 May 2015 09:28:13 +0000 (11:28 +0200)
Signed-off-by: Simon Gerber <simon.gerber@hp.com>

usr/tests/large_page/Hakefile
usr/tests/large_page/malloc_test.c [new file with mode: 0644]

index 2489406..e5568d8 100644 (file)
                       cFiles = [ "map_test.c" ],
                       architectures = [ "x86_64" ]
                     },
+ build application { target = "test_large_malloc",
+                      cFiles = [ "malloc_test.c" ],
+                      architectures = [ "x86_64" ]
+                    },
   build application { target = "test_large_mappings",
                       cFiles = [ "map_test_32.c" ],
                       architectures = [ "x86_32" ]
diff --git a/usr/tests/large_page/malloc_test.c b/usr/tests/large_page/malloc_test.c
new file mode 100644 (file)
index 0000000..0bb1433
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * \file
+ * \brief Test program for large page code
+ */
+
+/*
+ * Copyright (c) 2014, HP Labs.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
+ */
+
+#include <barrelfish/barrelfish.h>
+#include <barrelfish/sys_debug.h>
+
+#define RUNS 2
+// 128MB buffer
+#define BUFSIZE (128UL*1024*1024)
+
+int main(void)
+{
+    void *bufs[RUNS];
+    for (int k = 0; k < RUNS; k++) {
+        // touch every 4k page in region
+        bufs[k] = malloc(BUFSIZE);
+        uint8_t *buf = bufs[k];
+        for (int i = 0; i < BUFSIZE / X86_64_BASE_PAGE_SIZE; i++) {
+            buf[i*BASE_PAGE_SIZE] = i % 256;
+        }
+        // clear out caches
+        sys_debug_flush_cache();
+        int errors = 0;
+        for (int i = 0; i < BUFSIZE / X86_64_BASE_PAGE_SIZE; i++) {
+            if (buf[i*BASE_PAGE_SIZE] != i % 256) {
+                debug_printf("mismatch in page %d: expected %d, was %d\n",
+                        i, i % 256, buf[i*BASE_PAGE_SIZE]);
+                errors++;
+            }
+        }
+        debug_printf("test %s\n", errors ? "FAILED" : "PASSED");
+        if (errors) {
+            debug_printf("  %d errors\n", errors);
+        }
+    }
+    for (int k = 0; k < RUNS; k++) {
+        debug_printf("bufs[%d] = %p\n", k, bufs[k]);
+    }
+    debug_dump_hw_ptables();
+    for (int k = 0; k < RUNS; k++) {
+        free(bufs[k]);
+    }
+    return 0;
+}