From 9421a449ab377bf95484294259ba87155cac2ce1 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 1 Dec 2022 16:41:27 +0100 Subject: [PATCH] test/libc_many_writes for examining write batching This test reveals the patters of the batching of consecutive write operations on a file-system session. It issues 100 writes of one byte each, which should ideally result in large batches of operations submitted to the file-system session at once. The run script performs the write operations through a chain of two VFS servers, thereby exercising the write batching of both the libc and the intermediate VFS server. Issue #4697 --- repos/libports/run/libc_many_writes.run | 86 +++++++++++++++++++ .../libports/src/test/libc_many_writes/main.c | 59 +++++++++++++ .../src/test/libc_many_writes/target.mk | 3 + 3 files changed, 148 insertions(+) create mode 100644 repos/libports/run/libc_many_writes.run create mode 100644 repos/libports/src/test/libc_many_writes/main.c create mode 100644 repos/libports/src/test/libc_many_writes/target.mk diff --git a/repos/libports/run/libc_many_writes.run b/repos/libports/run/libc_many_writes.run new file mode 100644 index 0000000000..b75971b6fe --- /dev/null +++ b/repos/libports/run/libc_many_writes.run @@ -0,0 +1,86 @@ +build { + core lib/ld init timer + lib/vfs lib/vfs_audit server/vfs + lib/libc lib/posix test/libc_many_writes +} + +create_boot_directory + +install_config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +build_boot_image [build_artifacts] + +append qemu_args " -nographic " + +run_genode_until "child .* exited with exit value 0.*\n" 20 + diff --git a/repos/libports/src/test/libc_many_writes/main.c b/repos/libports/src/test/libc_many_writes/main.c new file mode 100644 index 0000000000..378edc780d --- /dev/null +++ b/repos/libports/src/test/libc_many_writes/main.c @@ -0,0 +1,59 @@ +/* + * \brief Libc test stressing the batching of write operations + * \author Norman Feske + * \date 2022-12-01 + */ + +/* + * Copyright (C) 2022 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 +#include +#include + + +static void print_time(char const *msg) +{ + struct timespec tp; + bzero(&tp, sizeof(tp)); + + int res = clock_gettime(CLOCK_MONOTONIC, &tp); + if (res != 0) { + printf("error: clock_gettime failed (%d)\n", res); + exit(-1); + } + + printf("%s: %ld s %ld ms\n", msg, tp.tv_sec, tp.tv_nsec/1000000); +} + + +int main(int argc, char **argv) +{ + char const * const path = "/rw/data"; + + int const fd = open(path, O_CREAT | O_RDWR); + if (fd < 0) + printf("error: creation of file '%s' failed (%d)\n", path, fd); + + print_time("start"); + + for (int i = 0; i < 100; i++) { + printf("write\n"); + unsigned char c = i & 0xffu; + write(fd, &c, 1); + } + + print_time("end"); + + close(fd); + + printf("exiting\n"); + return 0; +} diff --git a/repos/libports/src/test/libc_many_writes/target.mk b/repos/libports/src/test/libc_many_writes/target.mk new file mode 100644 index 0000000000..a4b1a441e5 --- /dev/null +++ b/repos/libports/src/test/libc_many_writes/target.mk @@ -0,0 +1,3 @@ +TARGET = test-libc_many_writes +SRC_C = main.c +LIBS = posix