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 RUNS 2 19#define PAGE_COUNT 64 20#define TOTAL_SIZE (PAGE_COUNT * LARGE_PAGE_SIZE) 21 22int main(void) 23{ 24#if defined(__x86__) && !defined(CONFIG_PSE) 25 debug_printf("PSE not enabled, change Config.hs and rebuild.\n"); 26 return 0; 27#endif 28 errval_t err; 29 struct capref frame; 30 size_t retsize; 31 void *vbuf; 32 struct vregion *vregion; 33 uint8_t *buf; 34 int errors; 35 36 // get frame 37 err = frame_alloc(&frame, TOTAL_SIZE, &retsize); 38 assert(retsize >= TOTAL_SIZE); 39 if (err_is_fail(err)) { 40 debug_printf("frame_alloc: %s\n", err_getstring(err)); 41 return 1; 42 } 43 44 for (int k = 0; k < RUNS; k++) { 45 debug_printf("Running large page test\n"); 46 // map with alignment and huge flag (don't need memobj and vregion) 47 err = vspace_map_one_frame_attr_aligned(&vbuf, retsize, frame, 48 VREGION_FLAGS_READ_WRITE | VREGION_FLAGS_LARGE, 49 TOTAL_SIZE, NULL, &vregion); 50 if (err_is_fail(err)) { 51 debug_printf("vspace_map: %s\n", err_getstring(err)); 52 return 1; 53 } 54 55 debug_printf("vaddr: %p\n", vbuf); 56 57 // touch every 4k page in region 58 buf = vbuf; 59 for (int i = 0; i < TOTAL_SIZE / BASE_PAGE_SIZE; i++) { 60 buf[i*BASE_PAGE_SIZE] = i % 256; 61 } 62 // clear out caches 63 sys_debug_flush_cache(); 64 errors = 0; 65 for (int i = 0; i < TOTAL_SIZE / BASE_PAGE_SIZE; i++) { 66 if (buf[i*BASE_PAGE_SIZE] != i % 256) { 67 debug_printf("mismatch in page %d: expected %d, was %d\n", 68 i, i % 256, buf[i*BASE_PAGE_SIZE]); 69 errors++; 70 } 71 } 72 debug_printf("large page test %s\n", errors ? "FAILED" : "PASSED"); 73 if (errors) { 74 debug_printf(" %d errors\n", errors); 75 } 76 77 vregion_destroy(vregion); 78 } 79 80 return 0; 81} 82