1/** 2 * \file 3 * \brief memory free test. 4 * 5 * This program allocates a RAM capability, splits it in half, throws 6 * away the parent and returns only one half. The memory server has to 7 * cope with such a situation. 8 */ 9 10/* 11 * Copyright (c) 2011, ETH Zurich. 12 * All rights reserved. 13 * 14 * This file is distributed under the terms in the attached LICENSE file. 15 * If you do not find this file, copies can be found by writing to: 16 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 17 */ 18 19#include <barrelfish/barrelfish.h> 20#include <assert.h> 21#include <stdio.h> 22 23int main(int argc, char **argv) 24{ 25 struct capref theram; 26 27 // Get an 8K RAM cap 28 errval_t err = ram_alloc(&theram, BASE_PAGE_BITS+1); 29 assert(err_is_ok(err)); 30 31 for(int i = 0; i < 100; i++) { 32 thread_yield(); 33 } 34 35 struct capability cap; 36 err = debug_cap_identify(theram, &cap); 37 assert(err_is_ok(err)); 38 assert(cap.type == ObjType_RAM); 39 printf("got RAM at 0x%" PRIxGENPADDR ", size %u\n", 40 cap.u.ram.base, cap.u.ram.bits); 41 42 struct capref leftcap, rightcap; 43 44 // XXX: Hopefully allocates two consecutive slots 45 err = slot_alloc(&leftcap); 46 assert(err_is_ok(err)); 47 err = slot_alloc(&rightcap); 48 assert(err_is_ok(err)); 49 50 // Split in half 51 err = cap_retype(leftcap, theram, 0, ObjType_RAM, BASE_PAGE_SIZE, 1); 52 assert(err_is_ok(err)); 53 54 err = debug_cap_identify(leftcap, &cap); 55 assert(err_is_ok(err)); 56 assert(cap.type == ObjType_RAM); 57 printf("left half at 0x%" PRIxGENPADDR ", size %u\n", 58 cap.u.ram.base, cap.u.ram.bits); 59 60 err = debug_cap_identify(rightcap, &cap); 61 assert(err_is_ok(err)); 62 assert(cap.type == ObjType_RAM); 63 printf("right half at 0x%" PRIxGENPADDR ", size %u\n", 64 cap.u.ram.base, cap.u.ram.bits); 65 66 // Delete the parent (8K range) 67 printf("deleting parent\n"); 68 err = cap_delete(theram); 69 assert(err_is_ok(err)); 70 71 // Delete the left half (4K) 72 printf("deleting left half\n"); 73 err = cap_delete(leftcap); 74 assert(err_is_ok(err)); 75 76 // Delete the right half (4K) 77 printf("deleting right half\n"); 78 err = cap_delete(rightcap); 79 assert(err_is_ok(err)); 80 81 return 0; 82} 83