From e5373880befc273a9a9f9bf707144150a5fbdd57 Mon Sep 17 00:00:00 2001 From: Benjamin Lamowski Date: Wed, 7 Aug 2024 21:16:06 +0200 Subject: [PATCH] WIP: test/aio: very simplistic AIO test Issue #5302 --- repos/libports/run/aio.run | 41 ++++++++++ repos/libports/src/test/aio/aio.c | 109 ++++++++++++++++++++++++++ repos/libports/src/test/aio/target.mk | 8 ++ 3 files changed, 158 insertions(+) create mode 100644 repos/libports/run/aio.run create mode 100644 repos/libports/src/test/aio/aio.c create mode 100644 repos/libports/src/test/aio/target.mk diff --git a/repos/libports/run/aio.run b/repos/libports/run/aio.run new file mode 100644 index 00000000000..e154fd5b110 --- /dev/null +++ b/repos/libports/run/aio.run @@ -0,0 +1,41 @@ +build { core init timer lib/ld lib/libc lib/libm lib/vfs lib/posix test/aio } + +create_boot_directory + +install_config { + + + + + + + + + + + + + + + + + + + + + + + 2019-08-20 15:01 + + + + + + +} + +build_boot_image [build_artifacts] + +append qemu_args " -nographic " + +run_genode_until "child .* exited with exit value 0.*\n" 30 diff --git a/repos/libports/src/test/aio/aio.c b/repos/libports/src/test/aio/aio.c new file mode 100644 index 00000000000..1385aa4b832 --- /dev/null +++ b/repos/libports/src/test/aio/aio.c @@ -0,0 +1,109 @@ +/* + * \brief AIO test + * \author Benjamin Lamowski + * \date 2031-07-31 + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + struct kevent tevent; /* Event triggered */ + int kq, write_fd, read_fd, ret; + + if (argc != 2) + err(EXIT_FAILURE, "Usage: %s path\n", argv[0]); + write_fd = open(argv[1], O_WRONLY); + if (write_fd == -1) + err(EXIT_FAILURE, "Failed to open '%s'", argv[1]); + + /* Create kqueue. */ + kq = kqueue(); + if (kq == -1) + err(EXIT_FAILURE, "kqueue() failed"); + + /* + * write test + */ + char * write_string = "Hello log\n"; + + struct aiocb write_cb; + write_cb.aio_fildes = write_fd; + write_cb.aio_buf = write_string; + write_cb.aio_nbytes = strlen(write_string) + 1; + write_cb.aio_offset = 0; + write_cb.aio_sigevent.sigev_notify = SIGEV_KEVENT; + write_cb.aio_sigevent.sigev_notify_kqueue = kq; + write_cb.aio_sigevent.sigev_notify_kevent_flags = 0; + + + aio_write(&write_cb); + + while (aio_error(&write_cb) == EINPROGRESS) + { + sleep(1); + puts(">>> progressing write..."); + } + + printf(">>> Aio write error is: %i\n", aio_error(&write_cb)); + + if (aio_error(&write_cb) == 0) + printf("Aio write retval: %li\n", aio_return(&write_cb)); + + read_fd = open("/dev/rtc", O_RDONLY); + if (read_fd == -1) + err(EXIT_FAILURE, "Failed to open '%s'", argv[1]); + + + /* + * Read test + */ + struct aiocb read_cb; + + char buf[10]; + read_cb.aio_fildes =read_fd; + read_cb.aio_buf = buf; + read_cb.aio_nbytes = sizeof(buf); + read_cb.aio_offset = 0; + read_cb.aio_sigevent.sigev_notify = SIGEV_KEVENT; + read_cb.aio_sigevent.sigev_notify_kqueue = kq; + read_cb.aio_sigevent.sigev_notify_kevent_flags = 0; + + aio_read(&read_cb); + + while (aio_error(&read_cb) == EINPROGRESS) + { + sleep(1); + puts(">>> progressing read..."); + } + + printf(">>> Aio read error is: %i\n", aio_error(&read_cb)); + + if (aio_error(&read_cb) == 0) + printf("Aio read retval: %li\n", aio_return(&read_cb)); + + for (int i = 0; i < 2 ; i++) { + /* Sleep until something happens. */ + ret = kevent(kq, NULL, 0, &tevent, 1, NULL); + if (ret == -1) { + err(EXIT_FAILURE, "kevent wait"); + } else if (ret > 0) { + if (tevent.flags & EV_ERROR) + errx(EXIT_FAILURE, "Event error.\n"); + else + printf("Got AIO event for %i'\n", tevent.ident); + } + } + + /* kqueues are destroyed upon close() */ + (void)close(kq); + (void)close(write_fd); +} diff --git a/repos/libports/src/test/aio/target.mk b/repos/libports/src/test/aio/target.mk new file mode 100644 index 00000000000..ca1d96573c0 --- /dev/null +++ b/repos/libports/src/test/aio/target.mk @@ -0,0 +1,8 @@ +include $(REP_DIR)/lib/mk/libc-common.inc + +TARGET = test-aio +SRC_C = aio.c +LIBS = posix libc +CC_OPT += -I$(LIBC_DIR)/sys/sys + +CC_CXX_WARN_STRICT =