summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-09-17 10:01:23 -0600
committerJens Axboe <axboe@kernel.dk>2019-09-17 10:03:00 -0600
commit4652762d5be96e08a0ff8194de1e6f6d8127cee5 (patch)
tree6132582f6b144e6e891c5a4340a1bbef8c1f7958
parentf102231b0fdbfe8587efda0b24c79a69ee4d8ba7 (diff)
downloadliburing-4652762d5be96e08a0ff8194de1e6f6d8127cee5.tar.gz
liburing-4652762d5be96e08a0ff8194de1e6f6d8127cee5.tar.bz2
Add basic IORING_OP_TIMEOUT test case
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/Makefile6
-rw-r--r--test/timeout.c74
2 files changed, 78 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index 2770219..8bd96c1 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -4,7 +4,7 @@ override CFLAGS += -Wall -D_GNU_SOURCE -L../src/ -I../src/include/
all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register \
io_uring_enter nop sq-full cq-full 35fa71a030ca-test \
917257daa0fe-test b19062a56726-test eeed8b54e0df-test link \
- send_recvmsg a4c0b3decb33-test 500f9fbadef8-test
+ send_recvmsg a4c0b3decb33-test 500f9fbadef8-test timeout
all: $(all_targets)
@@ -12,7 +12,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
io_uring_register.c io_uring_enter.c nop.c sq-full.c cq-full.c \
35fa71a030ca-test.c 917257daa0fe-test.c b19062a56726-test.c \
eeed8b54e0df-test.c link.c send_recvmsg.c a4c0b3decb33-test.c \
- 500f9fbadef8-test.c
+ 500f9fbadef8-test.c timeout.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
@@ -52,6 +52,8 @@ a4c0b3decb33-test: a4c0b3decb33-test.c
$(CC) $(CFLAGS) -o $@ a4c0b3decb33-test.c -luring
500f9fbadef8-test: 500f9fbadef8-test.c
$(CC) $(CFLAGS) -o $@ 500f9fbadef8-test.c -luring
+timeout: timeout.c
+ $(CC) $(CFLAGS) -o $@ timeout.c -luring
clean:
rm -f $(all_targets) $(test_objs)
diff --git a/test/timeout.c b/test/timeout.c
new file mode 100644
index 0000000..0d9e447
--- /dev/null
+++ b/test/timeout.c
@@ -0,0 +1,74 @@
+/*
+ * Description: run various timeout tests
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+static int test_single_timeout(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ struct timespec ts;
+ int ret;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ ts.tv_sec = 1;
+ ts.tv_nsec = 0;
+ io_uring_prep_timeout(sqe, &ts);
+
+ ret = io_uring_submit(ring);
+ if (ret <= 0) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+ if (cqe->res == -EINVAL)
+ printf("Timeout not supported, ignored\n");
+ else if (cqe->res != 0) {
+ printf("Timeout: %s\n", strerror(-cqe->res));
+ 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;
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ printf("ring setup failed\n");
+ return 1;
+
+ }
+
+ ret = test_single_timeout(&ring);
+ if (ret) {
+ printf("test_single_timeout failed\n");
+ return ret;
+ }
+
+ return 0;
+}