diff --git a/repos/libports/run/libc_counter.run b/repos/libports/run/libc_counter.run new file mode 100644 index 0000000000..13dbf63472 --- /dev/null +++ b/repos/libports/run/libc_counter.run @@ -0,0 +1,84 @@ +# +# Build +# + +set build_components { + core init drivers/timer server/terminal_crosslink test/libc_counter +} + +build $build_components + +create_boot_directory + +# +# Generate config +# + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +install_config $config + +# +# Boot modules +# + + +set boot_modules { + core init timer terminal_crosslink + test-libc_counter-source test-libc_counter-sink + ld.lib.so libc.lib.so libm.lib.so +} + +build_boot_image $boot_modules + +append qemu_args "-nographic -m 64" + +# +# Execute test case +# + +run_genode_until forever + +# vi: set ft=tcl : diff --git a/repos/libports/src/test/libc_counter/sink/main.cc b/repos/libports/src/test/libc_counter/sink/main.cc new file mode 100644 index 0000000000..42d4386547 --- /dev/null +++ b/repos/libports/src/test/libc_counter/sink/main.cc @@ -0,0 +1,44 @@ +/* + * \brief LibC counter test - sink + * \author Christian Helmuth + * \date 2017-01-31 + */ + +/* + * Copyright (C) 2017 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. + */ + +/* libc includes */ +#include +#include +#include + + +#define min(a,b) (((a) < (b)) ? (a) : (b)) + +enum { MAX_COUNT = 10 }; + + +int main(int argc, char **argv) +{ + fprintf(stderr, "--- counter sink started ---\n"); + + static char buf[32]; + + /* stdin/stdout are connected to the source */ + for (unsigned i = 0; i < MAX_COUNT; ++i) { + int nbytes = 0; + + /* XXX busy loop - read does not block */ + unsigned retry = 0; + while (0 == (nbytes = read(0, buf, sizeof(buf)))) ++retry; + fprintf(stderr, "nbytes=%d retry=%u\n", nbytes, retry); + buf[31] = 0; + fprintf(stderr, "buf=\"%s\"\n", buf); + } + + fprintf(stderr, "--- counter sink terminates ---\n"); +} diff --git a/repos/libports/src/test/libc_counter/sink/target.mk b/repos/libports/src/test/libc_counter/sink/target.mk new file mode 100644 index 0000000000..5a27433926 --- /dev/null +++ b/repos/libports/src/test/libc_counter/sink/target.mk @@ -0,0 +1,3 @@ +TARGET = test-libc_counter-sink +SRC_CC = main.cc +LIBS = posix diff --git a/repos/libports/src/test/libc_counter/source/main.cc b/repos/libports/src/test/libc_counter/source/main.cc new file mode 100644 index 0000000000..f2f2a56db3 --- /dev/null +++ b/repos/libports/src/test/libc_counter/source/main.cc @@ -0,0 +1,38 @@ +/* + * \brief LibC counter test - source + * \author Christian Helmuth + * \date 2017-01-31 + */ + +/* + * Copyright (C) 2017 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. + */ + +/* libc includes */ +#include +#include +#include + + +enum { MAX_COUNT = 10 }; + + +int main(int argc, char **argv) +{ + fprintf(stderr, "--- counter source started ---\n"); + + static char buf[32]; + + /* stdin/stdout are connected to the source */ + for (unsigned i = 0; i < MAX_COUNT; ++i) { + int nbytes = snprintf(buf, sizeof(buf), "%u.", i); + nbytes = write(1, buf, nbytes); + fprintf(stderr, "nbytes=%d\n", nbytes); + sleep(1); + } + + fprintf(stderr, "--- counter source terminates ---\n"); +} diff --git a/repos/libports/src/test/libc_counter/source/target.mk b/repos/libports/src/test/libc_counter/source/target.mk new file mode 100644 index 0000000000..dadb382b29 --- /dev/null +++ b/repos/libports/src/test/libc_counter/source/target.mk @@ -0,0 +1,3 @@ +TARGET = test-libc_counter-source +SRC_CC = main.cc +LIBS = posix