public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 1/1] tests: more cancellation tests
Date: Thu, 25 Mar 2021 18:28:24 +0000	[thread overview]
Message-ID: <914c86e2d94aafe7e623c07f4e39c7eba0c04228.1616696841.git.asml.silence@gmail.com> (raw)

Add a test checking we don't cancel extra on exit() cancellation.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/io-cancel.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

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);
-- 
2.24.0


             reply	other threads:[~2021-03-25 18:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25 18:28 Pavel Begunkov [this message]
2021-03-26 15:55 ` [PATCH 1/1] tests: more cancellation tests Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=914c86e2d94aafe7e623c07f4e39c7eba0c04228.1616696841.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox