From d6f956e37effb5f7adc6d1903734ecc3a4a52d65 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 20 Apr 2012 10:59:26 +0200 Subject: [PATCH] Test for enforcing dataspace ownership --- base/run/ds_ownership.run | 42 ++++++++++++++++++++ base/src/test/ds_ownership/main.cc | 57 ++++++++++++++++++++++++++++ base/src/test/ds_ownership/target.mk | 3 ++ 3 files changed, 102 insertions(+) create mode 100644 base/run/ds_ownership.run create mode 100644 base/src/test/ds_ownership/main.cc create mode 100644 base/src/test/ds_ownership/target.mk diff --git a/base/run/ds_ownership.run b/base/run/ds_ownership.run new file mode 100644 index 0000000000..038c4a7c8a --- /dev/null +++ b/base/run/ds_ownership.run @@ -0,0 +1,42 @@ +build "core init test/ds_ownership" + +create_boot_directory + +install_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. +} diff --git a/base/src/test/ds_ownership/main.cc b/base/src/test/ds_ownership/main.cc new file mode 100644 index 0000000000..fac075fca5 --- /dev/null +++ b/base/src/test/ds_ownership/main.cc @@ -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 +#include +#include + +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; +} + diff --git a/base/src/test/ds_ownership/target.mk b/base/src/test/ds_ownership/target.mk new file mode 100644 index 0000000000..562d33f381 --- /dev/null +++ b/base/src/test/ds_ownership/target.mk @@ -0,0 +1,3 @@ +TARGET = test-ds_ownership +SRC_CC = main.cc +LIBS = env thread