summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHrvoje Zeba <zeba.hrvoje@gmail.com>2019-11-25 11:00:30 -0700
committerJens Axboe <axboe@kernel.dk>2019-11-25 11:03:22 -0700
commit8f087e9031d23708047108ca2ce2f4a5444c3fd2 (patch)
tree20104373b3fe78dbc6ab9971a597a5523ce3e1ce
parentb5837bd5311d5f0cbc581ff7a492600f6a8d9812 (diff)
downloadliburing-8f087e9031d23708047108ca2ce2f4a5444c3fd2.tar.gz
liburing-8f087e9031d23708047108ca2ce2f4a5444c3fd2.tar.bz2
Add a regression test for behavior before commit b5837bd5311d
This test checks for io_submit_and_wait() behavior where before the specified commit, this function would cap wait_nr parameter and would ignore any sqes submited in previous calls. Signed-off-by: Hrvoje Zeba <zeba.hrvoje@gmail.com> [axboe: made a few stylistic changes] Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/Makefile5
-rw-r--r--test/b5837bd5311d-test.c73
2 files changed, 76 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index b4aa6b3..9bdb074 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -11,7 +11,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
socket-rw accept timeout-overflow defer read-write io-cancel \
link-timeout cq-overflow link_drain fc2a85cb02ef-test \
poll-link accept-link fixed-link poll-cancel-ton teardowns \
- poll-many
+ poll-many b5837bd5311d-test
include ../Makefile.quiet
@@ -29,7 +29,8 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.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 link_drain.c fc2a85cb02ef-test.c poll-link.c \
- accept-link.c fixed-link.c poll-cancel-ton.c teardowns.c poll-many.c
+ accept-link.c fixed-link.c poll-cancel-ton.c teardowns.c poll-many.c \
+ b5837bd5311d-test.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/b5837bd5311d-test.c b/test/b5837bd5311d-test.c
new file mode 100644
index 0000000..3758b6c
--- /dev/null
+++ b/test/b5837bd5311d-test.c
@@ -0,0 +1,73 @@
+/*
+ * Description: Check to see if wait_nr is being honored.
+ */
+#include <stdio.h>
+#include "liburing.h"
+
+int main(int argc, char *argv[])
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ struct io_uring ring;
+ int ret;
+ struct __kernel_timespec ts = {
+ .tv_sec = 0,
+ .tv_nsec = 10000000
+ };
+
+ if (io_uring_queue_init(4, &ring, 0) != 0) {
+ fprintf(stderr, "ring setup failed\n");
+ return 1;
+ }
+
+ /*
+ * First, submit the timeout sqe so we can actually finish the test
+ * if everything is in working order.
+ */
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ fprintf(stderr, "get sqe failed\n");
+ return 1;
+ }
+ io_uring_prep_timeout(sqe, &ts, (unsigned)-1, 0);
+
+ ret = io_uring_submit(&ring);
+ if (ret != 1) {
+ fprintf(stderr, "Got submit %d, expected 1\n", ret);
+ return 1;
+ }
+
+ /*
+ * Next, submit a nop and wait for two events. If everything is working
+ * as it should, we should be waiting for more than a millisecond and we
+ * should see two cqes. Otherwise, execution continues immediately
+ * and we see only one cqe.
+ */
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ fprintf(stderr, "get sqe failed\n");
+ return 1;
+ }
+ io_uring_prep_nop(sqe);
+
+ ret = io_uring_submit_and_wait(&ring, 2);
+ if (ret != 1) {
+ fprintf(stderr, "Got submit %d, expected 1\n", ret);
+ return 1;
+ }
+
+ if (io_uring_peek_cqe(&ring, &cqe) != 0) {
+ fprintf(stderr, "Unable to peek cqe!\n");
+ return 1;
+ }
+
+ io_uring_cqe_seen(&ring, cqe);
+
+ if (io_uring_peek_cqe(&ring, &cqe) != 0) {
+ fprintf(stderr, "Unable to peek cqe!\n");
+ return 1;
+ }
+
+ io_uring_queue_exit(&ring);
+ return 0;
+}