summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/Makefile5
-rw-r--r--test/eventfd-ring.c93
2 files changed, 96 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index 4ee68d2..8cabbb0 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -19,7 +19,8 @@ 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 eventfd send_recv
+ short-read openat2 probe shared-wq personality eventfd \
+ send_recv eventfd-ring
include ../Makefile.quiet
@@ -46,7 +47,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 eventfd.c
+ personality.c eventfd.c eventfd-ring.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/eventfd-ring.c b/test/eventfd-ring.c
new file mode 100644
index 0000000..274da49
--- /dev/null
+++ b/test/eventfd-ring.c
@@ -0,0 +1,93 @@
+/*
+ * 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_params p = {};
+ struct io_uring ring1, ring2;
+ struct io_uring_sqe *sqe;
+ int ret, evfd1, evfd2;
+
+ ret = io_uring_queue_init_params(8, &ring1, &p);
+ if (ret) {
+ fprintf(stderr, "ring setup failed: %d\n", ret);
+ return 1;
+ }
+ if (!(p.features & IORING_FEAT_CUR_PERSONALITY)) {
+ fprintf(stdout, "Skipping\n");
+ return 0;
+ }
+ ret = io_uring_queue_init(8, &ring2, 0);
+ if (ret) {
+ fprintf(stderr, "ring setup failed: %d\n", ret);
+ return 1;
+ }
+
+ evfd1 = eventfd(0, EFD_CLOEXEC);
+ if (evfd1 < 0) {
+ perror("eventfd");
+ return 1;
+ }
+
+ evfd2 = eventfd(0, EFD_CLOEXEC);
+ if (evfd2 < 0) {
+ perror("eventfd");
+ return 1;
+ }
+
+ ret = io_uring_register_eventfd(&ring1, evfd1);
+ if (ret) {
+ fprintf(stderr, "failed to register evfd: %d\n", ret);
+ return 1;
+ }
+
+ ret = io_uring_register_eventfd(&ring2, evfd2);
+ if (ret) {
+ fprintf(stderr, "failed to register evfd: %d\n", ret);
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(&ring1);
+ io_uring_prep_poll_add(sqe, evfd2, POLLIN);
+ sqe->user_data = 1;
+
+ sqe = io_uring_get_sqe(&ring2);
+ io_uring_prep_poll_add(sqe, evfd1, POLLIN);
+ sqe->user_data = 1;
+
+ ret = io_uring_submit(&ring1);
+ if (ret != 1) {
+ fprintf(stderr, "submit: %d\n", ret);
+ return 1;
+ }
+
+ ret = io_uring_submit(&ring2);
+ if (ret != 1) {
+ fprintf(stderr, "submit: %d\n", ret);
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(&ring1);
+ io_uring_prep_nop(sqe);
+ sqe->user_data = 3;
+
+ ret = io_uring_submit(&ring1);
+ if (ret != 1) {
+ fprintf(stderr, "submit: %d\n", ret);
+ return 1;
+ }
+
+ return 0;
+}