diff --git a/repos/gems/run/depot_autopilot.run b/repos/gems/run/depot_autopilot.run index 605d6f4e17..1a84d0a02e 100644 --- a/repos/gems/run/depot_autopilot.run +++ b/repos/gems/run/depot_autopilot.run @@ -692,6 +692,7 @@ set default_test_pkgs { test-nic_loopback test-part_block_gpt test-part_block_mbr + test-pipe_read_ready test-pthread test-ram_fs_chunk test-read_only_rom diff --git a/repos/libports/recipes/pkg/test-pipe_read_ready/README b/repos/libports/recipes/pkg/test-pipe_read_ready/README new file mode 100644 index 0000000000..eea1bee388 --- /dev/null +++ b/repos/libports/recipes/pkg/test-pipe_read_ready/README @@ -0,0 +1 @@ +Test for using select to wait for a pipe at a VFS server diff --git a/repos/libports/recipes/pkg/test-pipe_read_ready/archives b/repos/libports/recipes/pkg/test-pipe_read_ready/archives new file mode 100644 index 0000000000..cfa04372d6 --- /dev/null +++ b/repos/libports/recipes/pkg/test-pipe_read_ready/archives @@ -0,0 +1,6 @@ +_/src/init +_/src/libc +_/src/vfs +_/src/vfs_pipe +_/src/posix +_/src/test-pipe_read_ready diff --git a/repos/libports/recipes/pkg/test-pipe_read_ready/hash b/repos/libports/recipes/pkg/test-pipe_read_ready/hash new file mode 100644 index 0000000000..9e4ff58b51 --- /dev/null +++ b/repos/libports/recipes/pkg/test-pipe_read_ready/hash @@ -0,0 +1 @@ +2023-03-15 2d8860bc863bcb722b03982ec1b68bc21fcf6553 diff --git a/repos/libports/recipes/pkg/test-pipe_read_ready/runtime b/repos/libports/recipes/pkg/test-pipe_read_ready/runtime new file mode 100644 index 0000000000..b06ff5624a --- /dev/null +++ b/repos/libports/recipes/pkg/test-pipe_read_ready/runtime @@ -0,0 +1,73 @@ + + + + + + + [init -> select] 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/repos/libports/recipes/src/test-pipe_read_ready/content.mk b/repos/libports/recipes/src/test-pipe_read_ready/content.mk new file mode 100644 index 0000000000..fd1fb11356 --- /dev/null +++ b/repos/libports/recipes/src/test-pipe_read_ready/content.mk @@ -0,0 +1,10 @@ +MIRROR_FROM_REP_DIR := src/test/pipe_read_ready + +content: $(MIRROR_FROM_REP_DIR) LICENSE + +$(MIRROR_FROM_REP_DIR): + $(mirror_from_rep_dir) + +LICENSE: + cp $(GENODE_DIR)/LICENSE $@ + diff --git a/repos/libports/recipes/src/test-pipe_read_ready/hash b/repos/libports/recipes/src/test-pipe_read_ready/hash new file mode 100644 index 0000000000..1140baa086 --- /dev/null +++ b/repos/libports/recipes/src/test-pipe_read_ready/hash @@ -0,0 +1 @@ +2023-03-15 b7831174a141db784aa219327a3e40ac726e07f1 diff --git a/repos/libports/recipes/src/test-pipe_read_ready/used_apis b/repos/libports/recipes/src/test-pipe_read_ready/used_apis new file mode 100644 index 0000000000..0c483273a8 --- /dev/null +++ b/repos/libports/recipes/src/test-pipe_read_ready/used_apis @@ -0,0 +1,2 @@ +libc +posix diff --git a/repos/libports/src/test/pipe_read_ready/counter/main.c b/repos/libports/src/test/pipe_read_ready/counter/main.c new file mode 100644 index 0000000000..64d139ac99 --- /dev/null +++ b/repos/libports/src/test/pipe_read_ready/counter/main.c @@ -0,0 +1,23 @@ +/* + * \brief Print counter every second + * \author Norman Feske + * \date 2023-03-14 + */ + +/* + * Copyright (C) 2023 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#include +#include + +int main(int argc, char **argv) +{ + for (unsigned count = 0; ; count++) { + printf("%d\n", count); + sleep(1); + } +} diff --git a/repos/libports/src/test/pipe_read_ready/counter/target.mk b/repos/libports/src/test/pipe_read_ready/counter/target.mk new file mode 100644 index 0000000000..e2b5c556b4 --- /dev/null +++ b/repos/libports/src/test/pipe_read_ready/counter/target.mk @@ -0,0 +1,3 @@ +TARGET := test-pipe_read_ready_counter +SRC_C := main.c +LIBS += posix diff --git a/repos/libports/src/test/pipe_read_ready/select/main.c b/repos/libports/src/test/pipe_read_ready/select/main.c new file mode 100644 index 0000000000..1dbffbd504 --- /dev/null +++ b/repos/libports/src/test/pipe_read_ready/select/main.c @@ -0,0 +1,38 @@ +/* + * \brief Watch stdin using select and forward data to stout + * \author Norman Feske + * \date 2023-03-15 + */ + +/* + * Copyright (C) 2023 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + for (;;) { + + /* wait until stdin becomes ready to read */ + fd_set fds; + FD_ZERO(&fds); + FD_SET(STDIN_FILENO, &fds); + select(1, &fds, NULL, NULL, NULL); + + char buffer[4096]; + ssize_t const bytes = read(STDIN_FILENO, buffer, sizeof(buffer)); + + if (bytes == -1) + fprintf(stderr, "read failed, errno=%d\n", errno); + + if (bytes > 0) + write(STDOUT_FILENO, buffer, bytes); + } +} diff --git a/repos/libports/src/test/pipe_read_ready/select/target.mk b/repos/libports/src/test/pipe_read_ready/select/target.mk new file mode 100644 index 0000000000..e2cd27e24d --- /dev/null +++ b/repos/libports/src/test/pipe_read_ready/select/target.mk @@ -0,0 +1,3 @@ +TARGET := test-pipe_read_ready_select +SRC_C := main.c +LIBS += posix