summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2021-03-25 18:28:24 +0000
committerJens Axboe <axboe@kernel.dk>2021-03-26 09:55:12 -0600
commit13002f787a3744aec62c973e85668ca2ac8d7f24 (patch)
tree6ffaf8af5504c9e43519c4e020ec00c629f69ee8
parent941a5c7cdf35fd562553491a539e81005fbcebd6 (diff)
downloadliburing-13002f787a3744aec62c973e85668ca2ac8d7f24.tar.gz
liburing-13002f787a3744aec62c973e85668ca2ac8d7f24.tar.bz2
tests: more cancellation tests
Add a test checking we don't cancel extra on exit() cancellation. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/io-cancel.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/io-cancel.c b/test/io-cancel.c
index 9b52c7b..c08b7e5 100644
--- a/test/io-cancel.c
+++ b/test/io-cancel.c
@@ -11,6 +11,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
+#include <sys/poll.h>
#include "helpers.h"
#include "liburing.h"
@@ -365,6 +366,79 @@ static int test_cancel_req_across_fork(void)
return 0;
}
+static int test_cancel_inflight_exit(void)
+{
+ struct __kernel_timespec ts = { .tv_sec = 1, .tv_nsec = 0, };
+ struct io_uring ring;
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ int ret, i;
+ pid_t p;
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ fprintf(stderr, "ring create failed: %d\n", ret);
+ return 1;
+ }
+ p = fork();
+ if (p == -1) {
+ fprintf(stderr, "fork() failed\n");
+ return 1;
+ }
+
+ if (p == 0) {
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN);
+ sqe->user_data = 1;
+ sqe->flags |= IOSQE_IO_LINK;
+
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_timeout(sqe, &ts, 0, 0);
+ sqe->user_data = 2;
+
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_timeout(sqe, &ts, 0, 0);
+ sqe->user_data = 3;
+
+ ret = io_uring_submit(&ring);
+ if (ret != 3) {
+ fprintf(stderr, "io_uring_submit() failed %s, ret %i\n", __FUNCTION__, ret);
+ exit(1);
+ }
+ exit(0);
+ } else {
+ int wstatus;
+
+ if (waitpid(p, &wstatus, 0) == (pid_t)-1) {
+ perror("waitpid()");
+ return 1;
+ }
+ if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus)) {
+ fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus));
+ return 1;
+ }
+ }
+
+ for (i = 0; i < 3; ++i) {
+ ret = io_uring_wait_cqe(&ring, &cqe);
+ if (ret) {
+ fprintf(stderr, "wait_cqe=%d\n", ret);
+ return 1;
+ }
+ if ((cqe->user_data == 1 && cqe->res != -ECANCELED) ||
+ (cqe->user_data == 2 && cqe->res != -ECANCELED) ||
+ (cqe->user_data == 3 && cqe->res != -ETIME)) {
+ fprintf(stderr, "%i %i\n", (int)cqe->user_data, cqe->res);
+ return 1;
+ }
+ io_uring_cqe_seen(&ring, cqe);
+ }
+
+ io_uring_queue_exit(&ring);
+ return 0;
+}
+
+
int main(int argc, char *argv[])
{
int i, ret;
@@ -382,6 +456,11 @@ int main(int argc, char *argv[])
return 1;
}
+ if (test_cancel_inflight_exit()) {
+ fprintf(stderr, "test_cancel_inflight_exit() failed\n");
+ return 1;
+ }
+
t_create_file(".basic-rw", FILE_SIZE);
vecs = t_create_buffers(BUFFERS, BS);