3 * \brief Test program for large page code
7 * Copyright (c) 2014, HP Labs.
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
15 #include <barrelfish/barrelfish.h>
16 #include <barrelfish/sys_debug.h>
18 #define DEFAULT_RUNS 2
20 #define DEFAULT_BUFSIZE (128UL*1024*1024)
22 int main(int argc, char *argv[])
24 unsigned long BUFSIZE = DEFAULT_BUFSIZE;
25 unsigned RUNS = DEFAULT_RUNS;
27 if (strcmp(argv[1], "-h") == 0) {
28 debug_printf("usage: %s <bufsize> <runs>\n", argv[0]);
29 debug_printf(" both arguments are optional, defaults are:\n");
30 debug_printf(" BUFSIZE = %lu\n", DEFAULT_BUFSIZE);
31 debug_printf(" RUNS = %u\n", DEFAULT_RUNS);
34 BUFSIZE = strtol(argv[1], NULL, 0);
37 RUNS = strtol(argv[1], NULL, 0);
39 debug_printf("running malloc test with BUFSIZE = %lu, runs = %u\n", BUFSIZE, RUNS);
41 for (int k = 0; k < RUNS; k++) {
42 // touch every 4k page in region
43 bufs[k] = malloc(BUFSIZE);
45 debug_printf("malloc %d FAILED\n", k);
48 uint8_t *buf = bufs[k];
49 for (int i = 0; i < BUFSIZE / BASE_PAGE_SIZE; i++) {
50 buf[i*BASE_PAGE_SIZE] = i % 256;
53 sys_debug_flush_cache();
55 for (int i = 0; i < BUFSIZE / BASE_PAGE_SIZE; i++) {
56 if (buf[i*BASE_PAGE_SIZE] != i % 256) {
57 debug_printf("mismatch in page %d: expected %d, was %d\n",
58 i, i % 256, buf[i*BASE_PAGE_SIZE]);
62 debug_printf("test %s\n", errors ? "FAILED" : "PASSED");
64 debug_printf(" %d errors\n", errors);
67 for (int k = 0; k < RUNS; k++) {
68 debug_printf("bufs[%d] = %p\n", k, bufs[k]);
70 debug_dump_hw_ptables();
71 for (int k = 0; k < RUNS; k++) {