summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-11-27 17:14:19 -0700
committerJens Axboe <axboe@kernel.dk>2019-11-27 17:14:19 -0700
commit9695826eaf549c10a51f7df9e922908300a76781 (patch)
tree4cf1c499327bcfe2f08a869cb3d7ac18cee9c2fe
parentd77a67ed5f27a37db11b7fbc871a4bf0e4c492da (diff)
downloadliburing-9695826eaf549c10a51f7df9e922908300a76781.tar.gz
liburing-9695826eaf549c10a51f7df9e922908300a76781.tar.bz2
Add regression test for the bug fix in d77a67ed5f27
Based on the test case in the issue raised: https://github.com/axboe/liburing/issues/24 Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/Makefile4
-rw-r--r--test/d77a67ed5f27-test.c64
2 files changed, 66 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index 3388ef1..cad90d6 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 b5837bd5311d-test accept-test
+ poll-many b5837bd5311d-test accept-test d77a67ed5f27-test
include ../Makefile.quiet
@@ -30,7 +30,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.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 \
- b5837bd5311d-test.c accept-test.c
+ b5837bd5311d-test.c accept-test.c d77a67ed5f27-test.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/d77a67ed5f27-test.c b/test/d77a67ed5f27-test.c
new file mode 100644
index 0000000..5f48b24
--- /dev/null
+++ b/test/d77a67ed5f27-test.c
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include "liburing.h"
+
+static void sig_alrm(int sig)
+{
+ fprintf(stderr, "Timed out!\n");
+ exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ struct io_uring_params p;
+ struct io_uring ring;
+ int ret, data;
+
+ signal(SIGALRM, sig_alrm);
+
+ memset(&p, 0, sizeof(p));
+ p.sq_thread_idle = 100;
+ p.flags = IORING_SETUP_SQPOLL;
+ ret = io_uring_queue_init_params(4, &ring, &p);
+ if (ret) {
+ if (geteuid()) {
+ fprintf(stdout, "SQPOLL requires root, skipped\n");
+ return 0;
+ }
+ fprintf(stderr, "ring create failed: %d\n", ret);
+ return 1;
+ }
+
+ /* make sure sq thread is sleeping at this point */
+ usleep(150000);
+ alarm(1);
+
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ fprintf(stderr, "sqe get failed\n");
+ return 1;
+ }
+
+ io_uring_prep_nop(sqe);
+ io_uring_sqe_set_data(sqe, (void *) (unsigned long) 42);
+ io_uring_submit_and_wait(&ring, 1);
+
+ ret = io_uring_peek_cqe(&ring, &cqe);
+ if (ret) {
+ fprintf(stderr, "cqe get failed\n");
+ return 1;
+ }
+
+ data = (unsigned long) io_uring_cqe_get_data(cqe);
+ if (data != 42) {
+ fprintf(stderr, "invalid data: %d\n", data);
+ return 1;
+ }
+
+ return 0;
+}