Test for combining select with a pipe

The test exercises the VFS's read-ready mechanism when using the
vfs_pipe plugin.

Issue #4785
This commit is contained in:
Norman Feske 2023-03-14 15:07:13 +01:00 committed by Christian Helmuth
parent 2c1b51be65
commit bd3936c7ed
12 changed files with 162 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1 @@
Test for using select to wait for a pipe at a VFS server

View File

@ -0,0 +1,6 @@
_/src/init
_/src/libc
_/src/vfs
_/src/vfs_pipe
_/src/posix
_/src/test-pipe_read_ready

View File

@ -0,0 +1 @@
2023-03-15 2d8860bc863bcb722b03982ec1b68bc21fcf6553

View File

@ -0,0 +1,73 @@
<runtime ram="32M" caps="1000" binary="init">
<requires> <timer/> </requires>
<events>
<timeout meaning="failed" sec="30" />
<log meaning="succeeded">[init -> select] 3</log>
</events>
<content>
<rom label="ld.lib.so"/>
<rom label="libc.lib.so"/>
<rom label="libm.lib.so"/>
<rom label="posix.lib.so"/>
<rom label="vfs"/>
<rom label="vfs.lib.so"/>
<rom label="vfs_pipe.lib.so"/>
<rom label="test-pipe_read_ready_counter"/>
<rom label="test-pipe_read_ready_select"/>
</content>
<config>
<parent-provides>
<service name="ROM"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
<service name="Timer"/>
</parent-provides>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
<default caps="100"/>
<start name="vfs">
<resource name="RAM" quantum="12M"/>
<provides> <service name="File_system"/> </provides>
<config>
<vfs> <pipe> <fifo name="fifo"/> </pipe> </vfs>
<default-policy root="/" writeable="yes"/>
</config>
</start>
<start name="select">
<resource name="RAM" quantum="3M"/>
<binary name="test-pipe_read_ready_select"/>
<config>
<vfs>
<dir name="dev"> <log/> </dir>
<dir name="rw"> <fs/> </dir>
</vfs>
<libc stdin="/rw/fifo" stdout="/dev/log" stderr="/dev/log"/>
</config>
</start>
<start name="counter" caps="120">
<resource name="RAM" quantum="3M"/>
<binary name="test-pipe_read_ready_counter"/>
<config>
<vfs>
<dir name="dev"> <null/> <fs/> <log/> </dir>
<dir name="rw"> <fs/> </dir>
</vfs>
<libc stdin="/dev/null" stdout="/rw/fifo" stderr="/dev/log"/>
</config>
</start>
</config>
</runtime>

View File

@ -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 $@

View File

@ -0,0 +1 @@
2023-03-15 b7831174a141db784aa219327a3e40ac726e07f1

View File

@ -0,0 +1,2 @@
libc
posix

View File

@ -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 <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
for (unsigned count = 0; ; count++) {
printf("%d\n", count);
sleep(1);
}
}

View File

@ -0,0 +1,3 @@
TARGET := test-pipe_read_ready_counter
SRC_C := main.c
LIBS += posix

View File

@ -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 <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/select.h>
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);
}
}

View File

@ -0,0 +1,3 @@
TARGET := test-pipe_read_ready_select
SRC_C := main.c
LIBS += posix