* [PATCH] liburing: Add regression test case for link with drain
2019-11-09 3:00 [PATCH] io_uring: separate the io_free_req and io_free_req_find_next interface Jackie Liu
@ 2019-11-09 3:00 ` Jackie Liu
2019-11-09 3:10 ` Jens Axboe
0 siblings, 1 reply; 3+ messages in thread
From: Jackie Liu @ 2019-11-09 3:00 UTC (permalink / raw)
To: axboe; +Cc: io-uring, liuyun01
Signed-off-by: Jackie Liu <[email protected]>
---
test/Makefile | 5 ++-
test/link_drain.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+), 2 deletions(-)
create mode 100644 test/link_drain.c
diff --git a/test/Makefile b/test/Makefile
index 345e663..f7310cf 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -9,7 +9,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
sq-space_left stdout cq-ready cq-peek-batch file-register \
cq-size 8a9973408177-test a0908ae19763-test 232c93d07b74-test \
socket-rw accept timeout-overflow defer read-write io-cancel \
- link-timeout
+ link-timeout link_drain
include ../Makefile.quiet
@@ -25,7 +25,8 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
500f9fbadef8-test.c timeout.c sq-space_left.c stdout.c cq-ready.c\
cq-peek-batch.c file-register.c cq-size.c 8a9973408177-test.c \
a0908ae19763-test.c 232c93d07b74-test.c socket-rw.c accept.c \
- timeout-overflow.c defer.c read-write.c io-cancel.c link-timeout.c
+ timeout-overflow.c defer.c read-write.c io-cancel.c link-timeout.c \
+ link_drain.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/link_drain.c b/test/link_drain.c
new file mode 100644
index 0000000..aafd139
--- /dev/null
+++ b/test/link_drain.c
@@ -0,0 +1,122 @@
+/*
+ * Description: test io_uring link io with drain io
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+char expect[6][5] = {
+ { 0, 1, 2, 3, 4 },
+ { 0, 1, 2, 4, 3 },
+ { 0, 1, 4, 2, 3 }
+};
+
+static int test_link_drain(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe[5];
+ struct iovec iovecs;
+ int i, fd, ret;
+ off_t off = 0;
+ char data[5] = {0};
+
+ fd = open("testfile", O_WRONLY | O_CREAT, 0644);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ iovecs.iov_base = malloc(4096);
+ iovecs.iov_len = 4096;
+
+ for (i = 0; i < 5; i++) {
+ sqe[i] = io_uring_get_sqe(ring);
+ if (!sqe[i]) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+ }
+
+ /* normal heavy io */
+ io_uring_prep_writev(sqe[0], fd, &iovecs, 1, off);
+ sqe[0]->user_data = 0;
+
+ /* link io */
+ io_uring_prep_nop(sqe[1]);
+ sqe[1]->flags |= IOSQE_IO_LINK;
+ sqe[1]->user_data = 1;
+
+ /* link drain io */
+ io_uring_prep_nop(sqe[2]);
+ sqe[2]->flags |= (IOSQE_IO_LINK | IOSQE_IO_DRAIN);
+ sqe[2]->user_data = 2;
+
+ /* link io */
+ io_uring_prep_nop(sqe[3]);
+ sqe[3]->user_data = 3;
+
+ /* normal nop io */
+ io_uring_prep_nop(sqe[4]);
+ sqe[4]->user_data = 4;
+
+ ret = io_uring_submit(ring);
+ if (ret < 5) {
+ printf("Submitted only %d\n", ret);
+ goto err;
+ } else if (ret < 0) {
+ printf("sqe submit failed\n");
+ goto err;
+ }
+
+ for (i = 0; i < 5; i++) {
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("child: wait completion %d\n", ret);
+ goto err;
+ }
+
+ data[i] = cqe->user_data;
+ io_uring_cqe_seen(ring, cqe);
+ }
+
+ free(iovecs.iov_base);
+
+ for (i = 0; i < 6; i++) {
+ if (memcmp(data, expect[i], 5) == 0)
+ break;
+ }
+ if (i == 6)
+ goto err;
+
+ unlink("testfile");
+ return 0;
+err:
+ unlink("testfile");
+ return 1;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring ring;
+ int i, ret;
+
+ ret = io_uring_queue_init(5, &ring, 0);
+ if (ret) {
+ printf("ring setup failed\n");
+ return 1;
+ }
+
+ for (i = 0; i < 1000; i++)
+ ret |= test_link_drain(&ring);
+
+ if (ret)
+ return ret;
+
+ return 0;
+}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread