1/** 2 * \file 3 * \brief Test program for large page code 4 */ 5 6/* 7 * Copyright (c) 2014, HP Labs. 8 * All rights reserved. 9 * 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. 13 */ 14 15#include <barrelfish/barrelfish.h> 16#include <barrelfish/sys_debug.h> 17 18#define DEFAULT_RUNS 2 19// 128MB buffer 20#define DEFAULT_BUFSIZE (128UL*1024*1024) 21 22int main(int argc, char *argv[]) 23{ 24 unsigned long BUFSIZE = DEFAULT_BUFSIZE; 25 unsigned RUNS = DEFAULT_RUNS; 26 if (argc == 2) { 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); 32 return 0; 33 } 34 BUFSIZE = strtol(argv[1], NULL, 0); 35 } 36 if (argc == 3) { 37 RUNS = strtol(argv[1], NULL, 0); 38 } 39 debug_printf("running malloc test with BUFSIZE = %lu, runs = %u\n", BUFSIZE, RUNS); 40 void *bufs[RUNS]; 41 for (int k = 0; k < RUNS; k++) { 42 // touch every 4k page in region 43 bufs[k] = malloc(BUFSIZE); 44 if (!bufs[k]) { 45 debug_printf("malloc %d FAILED\n", k); 46 break; 47 } 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; 51 } 52 // clear out caches 53 sys_debug_flush_cache(); 54 int errors = 0; 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]); 59 errors++; 60 } 61 } 62 debug_printf("test %s\n", errors ? "FAILED" : "PASSED"); 63 if (errors) { 64 debug_printf(" %d errors\n", errors); 65 } 66 } 67 for (int k = 0; k < RUNS; k++) { 68 debug_printf("bufs[%d] = %p\n", k, bufs[k]); 69 } 70 debug_dump_hw_ptables(); 71 for (int k = 0; k < RUNS; k++) { 72 free(bufs[k]); 73 } 74 return 0; 75} 76