Skip to content

Commit

Permalink
WIP: test/aio: very simplistic AIO test
Browse files Browse the repository at this point in the history
  • Loading branch information
atopia committed Aug 7, 2024
1 parent ab7ff54 commit e537388
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
41 changes: 41 additions & 0 deletions repos/libports/run/aio.run
Original file line number Diff line number Diff line change
@@ -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 {
<config>
<parent-provides>
<service name="ROM"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
</parent-provides>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
<default caps="200"/>
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides> <service name="Timer"/> </provides>
</start>
<start name="test-aio">
<resource name="RAM" quantum="400M"/>
<config>
<vfs> <dir name="dev"> <log/> <inline name="rtc">2019-08-20 15:01</inline> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc"/>
<arg value="test-aio"/>
<arg value="/dev/log"/>
</config>
</start>
</config>
}

build_boot_image [build_artifacts]

append qemu_args " -nographic "

run_genode_until "child .* exited with exit value 0.*\n" 30
109 changes: 109 additions & 0 deletions repos/libports/src/test/aio/aio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* \brief AIO test
* \author Benjamin Lamowski
* \date 2031-07-31
*/
#include <aio.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/event.h>

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);
}
8 changes: 8 additions & 0 deletions repos/libports/src/test/aio/target.mk
Original file line number Diff line number Diff line change
@@ -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 =

0 comments on commit e537388

Please sign in to comment.