From a596bfe7978115ea888b0d155b2ed6c0a06b9335 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Mon, 2 Dec 2013 10:24:35 +0100 Subject: [PATCH] run: test for main thread_base object ref #989 --- base/run/thread.run | 26 +++++++++++++++++++ base/src/test/thread/main.cc | 47 ++++++++++++++++++++++++++++++++++ base/src/test/thread/target.mk | 3 +++ 3 files changed, 76 insertions(+) create mode 100644 base/run/thread.run create mode 100644 base/src/test/thread/main.cc create mode 100644 base/src/test/thread/target.mk diff --git a/base/run/thread.run b/base/run/thread.run new file mode 100644 index 000000000..4a02c6f04 --- /dev/null +++ b/base/run/thread.run @@ -0,0 +1,26 @@ +build "core init test/thread" + +create_boot_directory + +install_config { + + + + + + + + + + + + +} + +build_boot_image "core init test-thread" + +append qemu_args "-nographic -m 64" + +run_genode_until "child exited with exit value 0.*\n" 10 + +puts "Test succeeded" diff --git a/base/src/test/thread/main.cc b/base/src/test/thread/main.cc new file mode 100644 index 000000000..8a83f52b1 --- /dev/null +++ b/base/src/test/thread/main.cc @@ -0,0 +1,47 @@ +/* + * \brief Testing thread environment of a main thread + * \author Alexander Boettcher + * \date 2013-12-13 + */ + +/* + * Copyright (C) 2013 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 + +using namespace Genode; + +int main(int argc, char **argv) +{ + /* check wether my thread object exists */ + Thread_base * myself = Genode::Thread_base::myself(); + if (!myself) { return -1; } + printf("thread base %p\n", myself); + + /* check wether my stack is inside the first context region */ + addr_t const context_base = Native_config::context_area_virtual_base(); + addr_t const context_size = Native_config::context_area_virtual_size(); + addr_t const context_top = context_base + context_size; + addr_t const stack_top = (addr_t)myself->stack_top(); + addr_t const stack_base = (addr_t)myself->stack_base(); + if (stack_top <= context_base) { return -2; } + if (stack_top > context_top) { return -3; } + if (stack_base >= context_top) { return -4; } + if (stack_base < context_base) { return -5; } + printf("thread stack top %p\n", myself->stack_top()); + printf("thread stack bottom %p\n", myself->stack_base()); + + /* check wether my stack pointer is inside my stack */ + unsigned dummy = 0; + addr_t const sp = (addr_t)&dummy; + if (sp >= stack_top) { return -6; } + if (sp < stack_base) { return -7; } + printf("thread stack pointer %p\n", (void *)sp); + return 0; +} diff --git a/base/src/test/thread/target.mk b/base/src/test/thread/target.mk new file mode 100644 index 000000000..bf2a0e788 --- /dev/null +++ b/base/src/test/thread/target.mk @@ -0,0 +1,3 @@ +TARGET = test-thread +SRC_CC = main.cc +LIBS = base