Test for enforcing dataspace ownership

This commit is contained in:
Martin Stein 2012-04-20 10:59:26 +02:00 committed by Norman Feske
parent 88aab61e09
commit d6f956e37e
3 changed files with 102 additions and 0 deletions

42
base/run/ds_ownership.run Normal file
View File

@ -0,0 +1,42 @@
build "core init test/ds_ownership"
create_boot_directory
install_config {
<config verbose="yes">
<parent-provides>
<service name="ROM"/>
<service name="RAM"/>
<service name="CAP"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
</parent-provides>
<start name="test-ds_ownership">
<resource name="RAM" quantum="10M"/>
<route><any-service><parent/></any-service></route>
<config verbose="yes">
<parent-provides>
<service name="ROM"/>
<service name="RAM"/>
<service name="CAP"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
</parent-provides>
</config>
</start>
</config>
}
build_boot_image "core init test-ds_ownership"
run_genode_until {.*Test ended.*\.} 10
grep_output {\[init -\> test-ds_ownership\] Test ended}
compare_output_to {
[init -> test-ds_ownership] Test ended successfully.
}

View File

@ -0,0 +1,57 @@
/*
* \brief Testing the distinction between user and owner of a RAM dataspace
* \author Martin Stein
* \date 2012-04-19
*
*/
/*
* Copyright (C) 2008-2012 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/env.h>
#include <ram_session/connection.h>
#include <base/printf.h>
using namespace Genode;
int main(int argc, char **argv)
{
/* Create some RAM sessions */
printf("Dataspace ownership test\n");
static Ram_connection ram_1;
static Ram_connection ram_2;
/* Allocate dataspace at one of the RAM sessions */
ram_1.ref_account(env()->ram_session_cap());
env()->ram_session()->transfer_quota(ram_1.cap(), 8*1024);
Ram_dataspace_capability ds = ram_1.alloc(sizeof(unsigned));
/* Try to free dataspace at another RAM session */
ram_2.free(ds);
/* Check if dataspace was falsely freed */
try { env()->rm_session()->attach(ds); }
catch (...) {
printf("Test ended faulty.\n");
return -2;
}
/* Try to free dataspace at its originating RAM session */
ram_1.free(ds);
/* Check if dataspace was freed as expected */
try { env()->rm_session()->attach(ds); }
catch (...) {
printf("Test ended successfully.\n");
return 0;
}
printf("Test ended faulty.\n");
return -4;
}

View File

@ -0,0 +1,3 @@
TARGET = test-ds_ownership
SRC_CC = main.cc
LIBS = env thread