From: Jackie Liu <[email protected]>
To: [email protected]
Cc: [email protected], Jackie Liu <[email protected]>
Subject: [PATCH v2] liburing: Add regression test case for link with drain
Date: Sat, 9 Nov 2019 13:36:56 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
Signed-off-by: Jackie Liu <[email protected]>
---
V2: - Fix loop iterators - close fd
test/Makefile | 4 +-
test/link_drain.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+), 2 deletions(-)
create mode 100644 test/link_drain.c
diff --git a/test/Makefile b/test/Makefile
index a3a2556..ddbcc6a 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 cq-overflow
+ link-timeout cq-overflow link_drain
include ../Makefile.quiet
@@ -26,7 +26,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.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 \
- cq-overflow.c
+ cq-overflow.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..c192a5d
--- /dev/null
+++ b/test/link_drain.c
@@ -0,0 +1,123 @@
+/*
+ * 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[3][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);
+ close(fd);
+
+ for (i = 0; i < 3; i++) {
+ if (memcmp(data, expect[i], 5) == 0)
+ break;
+ }
+ if (i == 3)
+ 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 reply other threads:[~2019-11-09 5:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-09 5:36 Jackie Liu [this message]
2019-11-09 14:09 ` [PATCH v2] 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=1573277816-3807-1-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