summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-07-11 09:49:45 -0600
committerJens Axboe <axboe@kernel.dk>2020-07-11 09:49:45 -0600
commit9633f082d32ba4395eca8efbbce220423b8efe05 (patch)
tree6bdd3cd539535bd9a0590cb331f0ce30a5d86981
parent45f0735219a615ae848033c47c7e2d85d101d43e (diff)
downloadliburing-9633f082d32ba4395eca8efbbce220423b8efe05.tar.gz
liburing-9633f082d32ba4395eca8efbbce220423b8efe05.tar.bz2
Add test case for testing full fill of SQ and CQ ring
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/Makefile6
-rw-r--r--test/nop-all-sizes.c106
2 files changed, 110 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index cbbd400..a693d6f 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -25,7 +25,8 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
short-read openat2 probe shared-wq personality eventfd \
send_recv eventfd-ring across-fork sq-poll-kthread splice \
lfs-openat lfs-openat-write iopoll d4ae271dfaae-test \
- eventfd-disable close-opath ce593a6c480a-test cq-overflow-peek
+ eventfd-disable close-opath ce593a6c480a-test cq-overflow-peek \
+ nop-all-sizes
include ../Makefile.quiet
@@ -65,7 +66,8 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
madvise.c short-read.c openat2.c probe.c shared-wq.c \
personality.c eventfd.c eventfd-ring.c across-fork.c sq-poll-kthread.c \
splice.c lfs-openat.c lfs-openat-write.c iopoll.c d4ae271dfaae-test.c \
- eventfd-disable.c close-opath.c ce593a6c480a-test.c cq-overflow-peek.c
+ eventfd-disable.c close-opath.c ce593a6c480a-test.c cq-overflow-peek.c \
+ nop-all-sizes.c
ifdef CONFIG_HAVE_STATX
test_srcs += statx.c
diff --git a/test/nop-all-sizes.c b/test/nop-all-sizes.c
new file mode 100644
index 0000000..aacd584
--- /dev/null
+++ b/test/nop-all-sizes.c
@@ -0,0 +1,106 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Description: exercise full filling of SQ and CQ ring
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+#define MAX_ENTRIES 32768
+
+static int fill_nops(struct io_uring *ring)
+{
+ struct io_uring_sqe *sqe;
+ int filled = 0;
+
+ do {
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe)
+ break;
+
+ io_uring_prep_nop(sqe);
+ filled++;
+ } while (1);
+
+ return filled;
+}
+
+static int test_nops(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ int ret, nr, total = 0, i;
+
+ nr = fill_nops(ring);
+ if (nr < 0) {
+ fprintf(stderr, "Fill: %d\n", nr);
+ goto err;
+ }
+
+ ret = io_uring_submit(ring);
+ if (ret != nr) {
+ fprintf(stderr, "submit %d, wanted %d\n", ret, nr);
+ goto err;
+ }
+ total += ret;
+
+ nr = fill_nops(ring);
+ if (nr < 0) {
+ fprintf(stderr, "Fill: %d\n", nr);
+ goto err;
+ }
+
+ ret = io_uring_submit(ring);
+ if (ret != nr) {
+ fprintf(stderr, "submit %d, wanted %d\n", ret, nr);
+ goto err;
+ }
+ total += ret;
+
+ for (i = 0; i < total; i++) {
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ fprintf(stderr, "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, depth;
+
+ if (argc > 1)
+ return 0;
+
+ depth = 1;
+ while (depth <= MAX_ENTRIES) {
+ ret = io_uring_queue_init(depth, &ring, 0);
+ if (ret) {
+ if (ret == -ENOMEM)
+ break;
+ fprintf(stderr, "ring setup failed: %d\n", ret);
+ return 1;
+ }
+
+ ret = test_nops(&ring);
+ if (ret) {
+ fprintf(stderr, "test_single_nop failed\n");
+ return ret;
+ }
+ depth <<= 1;
+ }
+
+ return 0;
+}