From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, axboe@kernel.dk
Subject: [PATCH liburing 1/1] tests/timeout: add abs imm timeout test
Date: Mon, 2 Mar 2026 16:40:00 +0000 [thread overview]
Message-ID: <652575b9e2b08c08a32537f27b398504236e8be5.1772469585.git.asml.silence@gmail.com> (raw)
Add a simple test for absolute immediate argument timeout.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
test/timeout.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/test/timeout.c b/test/timeout.c
index 6bef0a7e..0ca387ba 100644
--- a/test/timeout.c
+++ b/test/timeout.c
@@ -31,18 +31,19 @@ static void msec_to_ts(struct __kernel_timespec *ts, unsigned int msec)
ts->tv_nsec = (msec % 1000) * 1000000;
}
-static void t_prep_timeout_rel(struct io_uring_sqe *sqe,
- const struct __kernel_timespec *ts,
- bool immediate)
+static void t_prep_timeout(struct io_uring_sqe *sqe,
+ const struct __kernel_timespec *ts,
+ unsigned flags,
+ bool immediate)
{
if (!immediate) {
io_uring_prep_timeout(sqe, ts, 0, 0);
- return;
+ } else {
+ io_uring_prep_timeout(sqe, NULL, 0, 0);
+ sqe->addr = ts->tv_sec * 1000000000 + ts->tv_nsec;
+ sqe->timeout_flags = IORING_TIMEOUT_IMMEDIATE_ARG;
}
-
- io_uring_prep_timeout(sqe, NULL, 0, 0);
- sqe->addr = ts->tv_sec * 1000000000 + ts->tv_nsec;
- sqe->timeout_flags = IORING_TIMEOUT_IMMEDIATE_ARG;
+ sqe->timeout_flags |= flags;
}
/*
@@ -65,7 +66,7 @@ static int test_single_timeout_many(struct io_uring *ring, bool immediate)
}
msec_to_ts(&ts, TIMEOUT_MSEC);
- t_prep_timeout_rel(sqe, &ts, immediate);
+ t_prep_timeout(sqe, &ts, 0, immediate);
ret = io_uring_submit(ring);
if (ret <= 0) {
@@ -250,7 +251,7 @@ static int test_single_timeout(struct io_uring *ring, bool immediate)
}
msec_to_ts(&ts, TIMEOUT_MSEC);
- t_prep_timeout_rel(sqe, &ts, immediate);
+ t_prep_timeout(sqe, &ts, 0, immediate);
ret = io_uring_submit(ring);
if (ret <= 0) {
@@ -436,7 +437,7 @@ err:
/*
* Test single absolute timeout waking us up
*/
-static int test_single_timeout_abs(struct io_uring *ring)
+static int test_single_timeout_abs(struct io_uring *ring, bool immediate)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
@@ -455,7 +456,7 @@ static int test_single_timeout_abs(struct io_uring *ring)
clock_gettime(CLOCK_MONOTONIC, &abs_ts);
ts.tv_sec = abs_ts.tv_sec + 1;
ts.tv_nsec = abs_ts.tv_nsec;
- io_uring_prep_timeout(sqe, &ts, 0, IORING_TIMEOUT_ABS);
+ t_prep_timeout(sqe, &ts, IORING_TIMEOUT_ABS, immediate);
ret = io_uring_submit(ring);
if (ret <= 0) {
@@ -1805,12 +1806,20 @@ int main(int argc, char *argv[])
return ret;
}
- ret = test_single_timeout_abs(&ring);
+ ret = test_single_timeout_abs(&ring, false);
if (ret) {
fprintf(stderr, "test_single_timeout_abs failed\n");
return ret;
}
+ if (!no_immediate) {
+ ret = test_single_timeout_abs(&ring, true);
+ if (ret) {
+ fprintf(stderr, "test_single_timeout_abs (imm) failed\n");
+ return ret;
+ }
+ }
+
ret = test_single_timeout_remove(&ring);
if (ret) {
fprintf(stderr, "test_single_timeout_remove failed\n");
--
2.53.0
next reply other threads:[~2026-03-02 16:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-02 16:40 Pavel Begunkov [this message]
2026-03-02 16:42 ` [PATCH liburing 1/1] tests/timeout: add abs imm timeout test 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=652575b9e2b08c08a32537f27b398504236e8be5.1772469585.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/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