summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile6
-rw-r--r--test/link.c209
2 files changed, 213 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index 7866047..e4fe57d 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -2,14 +2,14 @@ CFLAGS ?= -g -O2 -Wall -D_GNU_SOURCE -L../src/
all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register \
io_uring_enter nop sq-full cq-full 35fa71a030ca-test \
- 917257daa0fe-test b19062a56726-test eeed8b54e0df-test
+ 917257daa0fe-test b19062a56726-test eeed8b54e0df-test link
all: $(all_targets)
test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
io_uring_register.c io_uring_enter.c nop.c sq-full.c cq-full.c \
35fa71a030ca-test.c 917257daa0fe-test.c b19062a56726-test.c \
- eeed8b54e0df-test
+ eeed8b54e0df-test link
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
@@ -41,6 +41,8 @@ b19062a56726-test: b19062a56726-test.c
$(CC) $(CFLAGS) -o $@ b19062a56726-test.c
eeed8b54e0df-test: eeed8b54e0df-test.c
$(CC) $(CFLAGS) -o $@ eeed8b54e0df-test.c -luring
+link: link.c
+ $(CC) $(CFLAGS) -o $@ link.c -luring
clean:
rm -f $(all_targets) $(test_objs)
diff --git a/test/link.c b/test/link.c
new file mode 100644
index 0000000..b656bb2
--- /dev/null
+++ b/test/link.c
@@ -0,0 +1,209 @@
+/*
+ * Description: run various linked sqe tests
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "../src/liburing.h"
+
+/*
+ * Test two independent chains
+ */
+static int test_double_chain(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ int ret, i;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+ sqe->flags |= IOSQE_IO_LINK;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+ sqe->flags |= IOSQE_IO_LINK;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+
+ ret = io_uring_submit(ring);
+ if (ret <= 0) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ for (i = 0; i < 4; i++) {
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ return 0;
+err:
+ return 1;
+}
+
+/*
+ * Test multiple dependents
+ */
+static int test_double_link(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ int ret, i;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+ sqe->flags |= IOSQE_IO_LINK;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+ sqe->flags |= IOSQE_IO_LINK;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+
+ ret = io_uring_submit(ring);
+ if (ret <= 0) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ for (i = 0; i < 3; i++) {
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ return 0;
+err:
+ return 1;
+}
+
+/*
+ * Test single dependency
+ */
+static int test_single_link(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ int ret, i;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+ sqe->flags |= IOSQE_IO_LINK;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_nop(sqe);
+
+ ret = io_uring_submit(ring);
+ if (ret <= 0) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ for (i = 0; i < 2; i++) {
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ return 0;
+err:
+ return 1;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring ring;
+ int ret;
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ printf("ring setup failed\n");
+ return 1;
+
+ }
+
+ ret = test_single_link(&ring);
+ if (ret) {
+ printf("test_single_link failed\n");
+ return ret;
+ }
+
+ ret = test_double_link(&ring);
+ if (ret) {
+ printf("test_double_link failed\n");
+ return ret;
+ }
+
+ ret = test_double_chain(&ring);
+ if (ret) {
+ printf("test_double_chain failed\n");
+ return ret;
+ }
+
+ return 0;
+}