From 1ed37c52144de555e761500084dbffe24fede1c9 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 29 Aug 2019 08:40:34 -0600 Subject: Add test case for poll hang Signed-off-by: Jens Axboe --- test/500f9fbadef8-test.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ test/Makefile | 7 ++-- 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 test/500f9fbadef8-test.c diff --git a/test/500f9fbadef8-test.c b/test/500f9fbadef8-test.c new file mode 100644 index 0000000..88602ad --- /dev/null +++ b/test/500f9fbadef8-test.c @@ -0,0 +1,88 @@ +/* + * Description: Single depth submit+wait poll hang test + * + */ +#include +#include +#include +#include +#include +#include + +#include "liburing.h" + +#define BLOCKS 4096 + +int main(int argc, char *argv[]) +{ + struct io_uring ring; + struct io_uring_sqe *sqe; + struct io_uring_cqe *cqe; + struct iovec iov; + char buf[32]; + off_t offset; + unsigned blocks; + int ret, fd; + + if (posix_memalign(&iov.iov_base, 4096, 4096)) { + fprintf(stderr, "memalign failed\n"); + return 1; + } + iov.iov_len = 4096; + + ret = io_uring_queue_init(1, &ring, IORING_SETUP_IOPOLL); + if (ret) { + fprintf(stderr, "ring setup failed\n"); + return 1; + + } + + sprintf(buf, "./XXXXXX"); + mktemp(buf); + fd = open(buf, O_WRONLY | O_DIRECT | O_CREAT, 0644); + if (fd < 0) { + perror("mkstemp"); + return 1; + } + + offset = 0; + blocks = BLOCKS; + do { + sqe = io_uring_get_sqe(&ring); + if (!sqe) { + fprintf(stderr, "get sqe failed\n"); + goto err; + } + io_uring_prep_writev(sqe, fd, &iov, 1, offset); + ret = io_uring_submit_and_wait(&ring, 1); + if (ret < 0) { + fprintf(stderr, "submit_and_wait: %d\n", ret); + goto err; + } + ret = io_uring_wait_cqe(&ring, &cqe); + if (ret < 0) { + fprintf(stderr, "wait completion: %d\n", ret); + goto err; + } + if (cqe->res != 4096) { + if (cqe->res == -EOPNOTSUPP) + goto skipped; + goto err; + } + io_uring_cqe_seen(&ring, cqe); + offset += 4096; + } while (--blocks); + + close(fd); + unlink(buf); + return 0; +err: + close(fd); + unlink(buf); + return 1; +skipped: + fprintf(stderr, "Polling not supported in current dir, test skipped\n"); + close(fd); + unlink(buf); + return 0; +} diff --git a/test/Makefile b/test/Makefile index 4d056f8..2770219 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,14 +4,15 @@ 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 + send_recvmsg a4c0b3decb33-test 500f9fbadef8-test all: $(all_targets) 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 + eeed8b54e0df-test.c link.c send_recvmsg.c a4c0b3decb33-test.c \ + 500f9fbadef8-test.c test_objs := $(patsubst %.c,%.ol,$(test_srcs)) @@ -49,6 +50,8 @@ send_recvmsg: send_recvmsg.c $(CC) $(CFLAGS) -o $@ send_recvmsg.c -luring a4c0b3decb33-test: a4c0b3decb33-test.c $(CC) $(CFLAGS) -o $@ a4c0b3decb33-test.c -luring +500f9fbadef8-test: 500f9fbadef8-test.c + $(CC) $(CFLAGS) -o $@ 500f9fbadef8-test.c -luring clean: rm -f $(all_targets) $(test_objs) -- cgit