From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 2/2] tests: test timeout cancellation fails links
Date: Thu, 9 Sep 2021 14:07:09 +0100 [thread overview]
Message-ID: <966a04e2acf0d7e8362141e4e57861311356688e.1631192734.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Test that we appropriately fail linked requests when we cancel a
normal timeout.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/timeout.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git a/test/timeout.c b/test/timeout.c
index d2e4930..cef6846 100644
--- a/test/timeout.c
+++ b/test/timeout.c
@@ -10,6 +10,8 @@
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
+#include <sys/wait.h>
+#include <sys/types.h>
#include "liburing.h"
#include "../src/syscall.h"
@@ -1171,6 +1173,82 @@ err:
return 1;
}
+static int test_timeout_link_cancel(void)
+{
+ struct io_uring ring;
+ struct io_uring_cqe *cqe;
+ pid_t p;
+ int ret, i, wstatus;
+
+ 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) {
+ struct io_uring_sqe *sqe;
+ struct __kernel_timespec ts;
+ const char *prog_path = "./exec-target";
+
+ msec_to_ts(&ts, 10000);
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_timeout(sqe, &ts, 0, 0);
+ sqe->flags |= IOSQE_IO_LINK;
+ sqe->user_data = 0;
+
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_nop(sqe);
+ sqe->user_data = 1;
+
+ ret = io_uring_submit(&ring);
+ if (ret != 2) {
+ fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
+ exit(1);
+ }
+
+ /* trigger full cancellation */
+ ret = execl(prog_path, prog_path, NULL);
+ if (ret) {
+ fprintf(stderr, "exec failed %i\n", errno);
+ exit(1);
+ }
+ exit(0);
+ }
+
+ 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 < 2; ++i) {
+ ret = io_uring_wait_cqe(&ring, &cqe);
+ if (ret) {
+ fprintf(stderr, "wait_cqe=%d\n", ret);
+ return 1;
+ }
+ if (cqe->res != -ECANCELED) {
+ fprintf(stderr, "invalid result, user_data: %i res: %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[])
{
struct io_uring ring, sqpoll_ring;
@@ -1348,6 +1426,12 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_timeout_link_cancel();
+ if (ret) {
+ fprintf(stderr, "test_timeout_link_cancel failed\n");
+ return ret;
+ }
+
if (sqpoll)
io_uring_queue_exit(&sqpoll_ring);
return 0;
--
2.33.0
next prev parent reply other threads:[~2021-09-09 14:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-09 13:07 [PATCH liburing 0/2] exec + timeout cancellation Pavel Begunkov
2021-09-09 13:07 ` [PATCH liburing 1/2] tests: add no-op executable for exec Pavel Begunkov
2021-09-09 13:07 ` Pavel Begunkov [this message]
2021-09-09 15:33 ` [PATCH liburing 0/2] exec + timeout cancellation Jens Axboe
2021-09-11 10:46 ` Pavel Begunkov
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=966a04e2acf0d7e8362141e4e57861311356688e.1631192734.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