diff --git a/base-linux/src/test/lx_hybrid_errno/main.cc b/base-linux/src/test/lx_hybrid_errno/main.cc new file mode 100644 index 0000000000..0f49cd2536 --- /dev/null +++ b/base-linux/src/test/lx_hybrid_errno/main.cc @@ -0,0 +1,67 @@ +/* + * \brief Test for thread-local errno handling of hybrid Linux/Genode programs + * \author Norman Feske + * \date 2011-12-05 + */ + +/* Genode includes */ +#include +#include + +/* libc includes */ +#include +#include +#include + +enum { STACK_SIZE = 4096 }; + +struct Thread : Genode::Thread +{ + Genode::Lock &_barrier; + + Thread(Genode::Lock &barrier) : _barrier(barrier) { start(); } + + void entry() + { + /* + * Stat syscall should return with errno ENOENT + */ + struct stat buf; + int ret = stat("", &buf); + + Genode::printf("thread: stat returned %d, errno=%d\n", ret, errno); + + /* + * Let main thread procees + */ + _barrier.unlock(); + } +}; + + +int main(int, char **) +{ + Genode::printf("--- thread-local errno test ---\n"); + + static Genode::Lock barrier(Genode::Lock::LOCKED); + + int const orig_errno = errno; + + Genode::printf("main: before thread creation, errno=%d\n", orig_errno); + + /* create thread, which modifies its thread-local errno value */ + static Thread thread(barrier); + + /* block until the thread performed a 'stat' syscall */ + barrier.lock(); + + Genode::printf("main: after thread completed, errno=%d\n", errno); + + if (orig_errno != errno) { + PERR("unexpected change of main thread's errno value"); + return -1; + } + + Genode::printf("--- finished thread-local errno test ---\n"); + return 0; +} diff --git a/base-linux/src/test/lx_hybrid_errno/target.mk b/base-linux/src/test/lx_hybrid_errno/target.mk new file mode 100644 index 0000000000..66a5e93d92 --- /dev/null +++ b/base-linux/src/test/lx_hybrid_errno/target.mk @@ -0,0 +1,3 @@ +TARGET = test-lx_hybrid_errno +SRC_CC = main.c +LIBS = env cxx thread lx_hybrid