summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-12-01 09:30:32 -0700
committerJens Axboe <axboe@kernel.dk>2019-12-01 09:30:32 -0700
commita24269f3ac34318bb1862b236bd4ba8b8e71a90f (patch)
tree3049cbc8869c4ae77dc8c4aa13d308a1a1cdaff2
parent7ad0e4b2f83c25a996b918585b019afb044acc9f (diff)
downloadliburing-a24269f3ac34318bb1862b236bd4ba8b8e71a90f.tar.gz
liburing-a24269f3ac34318bb1862b236bd4ba8b8e71a90f.tar.bz2
Add test case for commit 7ad0e4b2f83cissue25
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/7ad0e4b2f83c-test.c89
-rw-r--r--test/Makefile5
2 files changed, 92 insertions, 2 deletions
diff --git a/test/7ad0e4b2f83c-test.c b/test/7ad0e4b2f83c-test.c
new file mode 100644
index 0000000..1abde44
--- /dev/null
+++ b/test/7ad0e4b2f83c-test.c
@@ -0,0 +1,89 @@
+#include <stdio.h>
+#include <time.h>
+#include <sys/time.h>
+#include "liburing.h"
+
+static unsigned long long mtime_since(const struct timeval *s,
+ const struct timeval *e)
+{
+ long long sec, usec;
+
+ sec = e->tv_sec - s->tv_sec;
+ usec = (e->tv_usec - s->tv_usec);
+ if (sec > 0 && usec < 0) {
+ sec--;
+ usec += 1000000;
+ }
+
+ sec *= 1000;
+ usec /= 1000;
+ return sec + usec;
+}
+
+static unsigned long long mtime_since_now(struct timeval *tv)
+{
+ struct timeval end;
+
+ gettimeofday(&end, NULL);
+ return mtime_since(tv, &end);
+}
+
+int main(int argc, char *argv[])
+{
+ struct __kernel_timespec ts1, ts2;
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ struct io_uring ring;
+ unsigned long msec;
+ struct timeval tv;
+ int ret;
+
+ ret = io_uring_queue_init(32, &ring, 0);
+ if (ret) {
+ fprintf(stderr, "io_uring_queue_init=%d\n", ret);
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_nop(sqe);
+ ret = io_uring_submit(&ring);
+ if (ret != 1) {
+ fprintf(stderr, "io_uring_submit1=%d\n", ret);
+ return 1;
+ }
+
+
+ ts1.tv_sec = 5,
+ ts1.tv_nsec = 0;
+ ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts1);
+ if (ret) {
+ fprintf(stderr, "io_uring_wait_cqe_timeout=%d\n", ret);
+ return 1;
+ }
+ io_uring_cqe_seen(&ring, cqe);
+ gettimeofday(&tv, NULL);
+
+ ts2.tv_sec = 1;
+ ts2.tv_nsec = 0;
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_timeout(sqe, &ts2, 0, 0);
+ sqe->user_data = 89;
+ ret = io_uring_submit(&ring);
+ if (ret != 1) {
+ fprintf(stderr, "io_uring_submit2=%d\n", ret);
+ return 1;
+ }
+
+ io_uring_wait_cqe(&ring, &cqe);
+ io_uring_cqe_seen(&ring, cqe);
+ msec = mtime_since_now(&tv);
+ if (msec >= 900 && msec <= 1100) {
+ io_uring_queue_exit(&ring);
+ return 0;
+ }
+
+ fprintf(stderr, "%s: Timeout seems wonky (got %lu)\n", __FUNCTION__,
+ msec);
+ io_uring_queue_exit(&ring);
+ return 1;
+}
diff --git a/test/Makefile b/test/Makefile
index eb83bc1..69ebdbf 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -17,7 +17,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
link-timeout cq-overflow link_drain fc2a85cb02ef-test \
poll-link accept-link fixed-link poll-cancel-ton teardowns \
poll-many b5837bd5311d-test accept-test d77a67ed5f27-test \
- connect
+ connect 7ad0e4b2f83c-test
include ../Makefile.quiet
@@ -36,7 +36,8 @@ 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 d77a67ed5f27-test.c connect.c
+ b5837bd5311d-test.c accept-test.c d77a67ed5f27-test.c connect.c \
+ 7ad0e4b2f83c-test.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))