From bfa2ad7d47579598afd1df6e838dbcce80bff3f5 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Fri, 2 Jan 2015 20:16:49 +0100 Subject: [PATCH] nova: platform test for portal permission usage Test and run script showcasing issue #1335. The test mainly tries out syscalls which should not succeed. --- repos/base-nova/run/platform.run | 32 +++++++++ repos/base-nova/src/test/platform/main.cc | 80 +++++++++++++++++++++ repos/base-nova/src/test/platform/target.mk | 3 + 3 files changed, 115 insertions(+) create mode 100644 repos/base-nova/run/platform.run create mode 100644 repos/base-nova/src/test/platform/main.cc create mode 100644 repos/base-nova/src/test/platform/target.mk diff --git a/repos/base-nova/run/platform.run b/repos/base-nova/run/platform.run new file mode 100644 index 0000000000..638432ea73 --- /dev/null +++ b/repos/base-nova/run/platform.run @@ -0,0 +1,32 @@ +build "core init test/platform" + +create_boot_directory + +install_config { + + + + + + + + + + + + + + + + + + +} + +build_boot_image "core init test-platform" + +append qemu_args "-nographic -m 128" + +run_genode_until {Test finished} 15 + +puts "\nTest succeeded" diff --git a/repos/base-nova/src/test/platform/main.cc b/repos/base-nova/src/test/platform/main.cc new file mode 100644 index 0000000000..779032b0fd --- /dev/null +++ b/repos/base-nova/src/test/platform/main.cc @@ -0,0 +1,80 @@ +/* + * \brief Some platform tests for the base-nova + * \author Alexander Boettcher + * \date 2015-01-02 + * + */ + +/* + * Copyright (C) 2015 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. + */ + +#include +#include +#include + +using namespace Genode; + +static unsigned failed = 0; + +void check(uint8_t res, const char *format, ...) +{ + static char buf[128]; + + va_list list; + va_start(list, format); + + String_console sc(buf, sizeof(buf)); + sc.vprintf(format, list); + + va_end(list); + + if (res == Nova::NOVA_OK) { + PERR("res=%u %s - TEST FAILED", res, buf); + failed++; + } + else + printf("res=%u %s\n", res, buf); +} + +int main(int argc, char **argv) +{ + printf("testing base-nova platform\n"); + + Thread_base * myself = Thread_base::myself(); + if (!myself) + return -__LINE__; + + addr_t sel_pd = cap_map()->insert(); + addr_t sel_ec = myself->tid().ec_sel; + addr_t sel_cap = cap_map()->insert(); + addr_t handler = 0UL; + uint8_t res = 0; + + Nova::Mtd mtd(Nova::Mtd::ALL); + + if (sel_cap == ~0UL || sel_ec == ~0UL || sel_cap == ~0UL) + return -__LINE__; + + /* negative syscall tests - they should not succeed */ + res = Nova::create_pt(sel_cap, sel_pd, sel_ec, mtd, handler); + check(res, "create_pt"); + + res = Nova::create_sm(sel_cap, sel_pd, 0); + check(res, "create_sm"); + + /* changing the badge of one of the portal must fail */ + for (unsigned i = 0; i < (1U << Nova::NUM_INITIAL_PT_LOG2); i++) { + addr_t sel_exc = myself->tid().exc_pt_sel + i; + res = Nova::pt_ctrl(sel_exc, 0xbadbad); + check(res, "pt_ctrl %2u", i); + } + + if (!failed) + printf("Test finished\n"); + + return -failed; +} diff --git a/repos/base-nova/src/test/platform/target.mk b/repos/base-nova/src/test/platform/target.mk new file mode 100644 index 0000000000..0c0447039d --- /dev/null +++ b/repos/base-nova/src/test/platform/target.mk @@ -0,0 +1,3 @@ +TARGET = test-platform +SRC_CC = main.cc +LIBS = base