forked from genodelabs/genode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: test/aio: very simplistic AIO test
Issue genodelabs#5302
- Loading branch information
Showing
3 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = |