diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 6 | ||||
-rw-r--r-- | test/poll-cancel.c | 98 |
2 files changed, 102 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile index dcf7a56..574f90b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,11 +1,11 @@ CC = gcc CFLAGS ?= -g -O2 -Wall -D_GNU_SOURCE -L../src/ -all_targets += io_uring-test io_uring-cp poll +all_targets += io_uring-test io_uring-cp poll poll-cancel all: $(all_targets) -test_srcs := io_uring-test.c io_uring-cp.c poll.c +test_srcs := io_uring-test.c io_uring-cp.c poll.c poll-cancel.c test_objs := $(patsubst %.c,%.ol,$(test_srcs)) @@ -15,5 +15,7 @@ io_uring-cp: io_uring-cp.c $(CC) $(CFLAGS) -o $@ io_uring-cp.c -luring poll: poll.c $(CC) $(CFLAGS) -o $@ poll.c -luring +poll-cancel: poll-cancel.c + $(CC) $(CFLAGS) -o $@ poll-cancel.c -luring clean: rm -f $(all_targets) $(test_objs) diff --git a/test/poll-cancel.c b/test/poll-cancel.c new file mode 100644 index 0000000..ec12353 --- /dev/null +++ b/test/poll-cancel.c @@ -0,0 +1,98 @@ +/* + * Description: test io_uring poll cancel handling + * + */ +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/poll.h> +#include <sys/wait.h> + +#include "../src/liburing.h" + +int main(int argc, char *argv[]) +{ + struct io_uring ring; + int pipe1[2]; + struct io_uring_cqe *cqe; + struct io_uring_sqe *sqe; + unsigned long addr; + int ret; + + if (pipe(pipe1) != 0) { + printf("pipe failed\n"); + return 1; + } + + ret = io_uring_queue_init(2, &ring, 0); + if (ret) { + printf("child: ring setup failed\n"); + return 1; + } + + sqe = io_uring_get_sqe(&ring); + if (!sqe) { + printf("child: get sqe failed\n"); + return 1; + } + sqe->opcode = IORING_OP_POLL; + sqe->flags = 0; + sqe->ioprio = 0; + sqe->fd = pipe1[0]; + sqe->addr = POLLIN; + sqe->off = 0; + sqe->len = 0; + sqe->buf_index = 0; + sqe->user_data = addr = (unsigned long) &sqe; + + ret = io_uring_submit(&ring); + if (ret <= 0) { + printf("child: sqe submit failed\n"); + return 1; + } + + sqe = io_uring_get_sqe(&ring); + if (!sqe) { + printf("child: get sqe failed\n"); + return 1; + } + sqe->opcode = IORING_OP_POLL_CANCEL; + sqe->flags = 0; + sqe->ioprio = 0; + sqe->fd = 0; + sqe->addr = addr; + sqe->off = 0; + sqe->len = 0; + sqe->buf_index = 0; + sqe->user_data = (unsigned long) &sqe; + + ret = io_uring_submit(&ring); + if (ret <= 0) { + printf("child: sqe submit failed\n"); + return 1; + } + + ret = io_uring_wait_completion(&ring, &cqe); + if (ret < 0) { + printf("child: get cqe failed\n"); + return 1; + } + + if (cqe->user_data != addr) { + printf("first complete not poll\n"); + return 1; + } + + ret = io_uring_wait_completion(&ring, &cqe); + if (ret < 0) { + printf("parent: get failed\n"); + return 1; + } + if (cqe->user_data != (unsigned long) &sqe) { + printf("second not cancel\n"); + return 1; + } + + return 0; +} |