From: Jackie Liu <[email protected]>
To: [email protected]
Cc: [email protected], [email protected]
Subject: [PATCH] liburing: Add regression test case for link with drain
Date: Sat, 9 Nov 2019 11:00:09 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
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
next prev parent reply other threads:[~2019-11-09 3:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2019-11-09 3:10 ` [PATCH] liburing: Add regression test case for link with drain Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1573268409-86058-2-git-send-email-liuyun01@kylinos.cn \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox