summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-01-31 16:19:43 -0700
committerJens Axboe <axboe@kernel.dk>2020-01-31 16:19:43 -0700
commitdbebec80a042e93d117a1a61ef44cde815f3d7d9 (patch)
treeefa511978e5fd5acc042976b3fc96fa486feeb34
parent85679339e38a8dad5264d13a91cd787881214510 (diff)
downloadliburing-dbebec80a042e93d117a1a61ef44cde815f3d7d9.tar.gz
liburing-dbebec80a042e93d117a1a61ef44cde815f3d7d9.tar.bz2
Add eventfd test case
Tests both the completion side, but also the recursion bug that was fixed in commit 50167d5bc585 in mainline. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/Makefile4
-rw-r--r--test/eventfd.c103
2 files changed, 105 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index a975999..a311699 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -19,7 +19,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
poll-many b5837bd5311d-test accept-test d77a67ed5f27-test \
connect 7ad0e4b2f83c-test submit-reuse fallocate open-close \
file-update statx accept-reuse poll-v-poll fadvise madvise \
- short-read openat2 probe shared-wq personality
+ short-read openat2 probe shared-wq personality eventfd
include ../Makefile.quiet
@@ -46,7 +46,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
7ad0e4b2f83c-test.c submit-reuse.c fallocate.c open-close.c \
file-update.c statx.c accept-reuse.c poll-v-poll.c fadvise.c \
madvise.c short-read.c openat2.c probe.c shared-wq.c \
- personality.c
+ personality.c eventfd.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/eventfd.c b/test/eventfd.c
new file mode 100644
index 0000000..54f6871
--- /dev/null
+++ b/test/eventfd.c
@@ -0,0 +1,103 @@
+/*
+ * Description: run various nop tests
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/poll.h>
+#include <sys/eventfd.h>
+
+#include "liburing.h"
+
+int main(int argc, char *argv[])
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ struct io_uring ring;
+ uint64_t ptr;
+ struct iovec vec = {
+ .iov_base = &ptr,
+ .iov_len = sizeof(ptr)
+ };
+ int ret, evfd, i;
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ fprintf(stderr, "ring setup failed: %d\n", ret);
+ return 1;
+ }
+
+ evfd = eventfd(0, EFD_CLOEXEC);
+ if (evfd < 0) {
+ perror("eventfd");
+ return 1;
+ }
+
+ ret = io_uring_register_eventfd(&ring, evfd);
+ if (ret) {
+ fprintf(stderr, "failed to register evfd: %d\n", ret);
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_poll_add(sqe, evfd, POLLIN);
+ sqe->flags |= IOSQE_IO_LINK;
+ sqe->user_data = 1;
+
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_readv(sqe, evfd, &vec, 1, 0);
+ sqe->flags |= IOSQE_IO_LINK;
+ sqe->user_data = 2;
+
+ ret = io_uring_submit(&ring);
+ if (ret != 2) {
+ fprintf(stderr, "submit: %d\n", ret);
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_nop(sqe);
+ sqe->user_data = 3;
+
+ ret = io_uring_submit(&ring);
+ if (ret != 1) {
+ fprintf(stderr, "submit: %d\n", ret);
+ return 1;
+ }
+
+ for (i = 0; i < 3; i++) {
+ ret = io_uring_wait_cqe(&ring, &cqe);
+ if (ret) {
+ fprintf(stderr, "wait: %d\n", ret);
+ return 1;
+ }
+ switch (cqe->user_data) {
+ case 1:
+ /* POLLIN */
+ if (cqe->res != 1) {
+ fprintf(stderr, "poll: %d\n", cqe->res);
+ return 1;
+ }
+ break;
+ case 2:
+ if (cqe->res != sizeof(ptr)) {
+ fprintf(stderr, "read: %d\n", cqe->res);
+ return 1;
+ }
+ break;
+ case 3:
+ if (cqe->res) {
+ fprintf(stderr, "nop: %d\n", cqe->res);
+ return 1;
+ }
+ break;
+ }
+ io_uring_cqe_seen(&ring, cqe);
+ }
+
+ return 0;
+}