From: Prateek <kprateek283@gmail.com>
To: io-uring@vger.kernel.org
Cc: axboe@kernel.dk, Prateek <kprateek283@gmail.com>
Subject: [PATCH 2/2] test/timeout-swallow: verify -ETIME is not swallowed
Date: Mon, 13 Jul 2026 03:42:22 +0530 [thread overview]
Message-ID: <20260712221222.535794-1-kprateek283@gmail.com> (raw)
In-Reply-To: <20260712221049.534729-1-kprateek283@gmail.com>
Regression test for the previous commit. Submits an SQE and waits with a
zero timeout for more completions than can arrive; the result must be
-ETIME, not the positive submit count. Covers the normal EXT_ARG wait
path and the registered-wait path, each skipped gracefully where
unsupported.
Signed-off-by: Prateek <kprateek283@gmail.com>
---
test/Makefile | 1 +
test/timeout-swallow.c | 117 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 118 insertions(+)
create mode 100644 test/timeout-swallow.c
diff --git a/test/Makefile b/test/Makefile
index d6358a93..ae23ef6d 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -293,6 +293,7 @@ test_srcs := \
timerfd-short-read.c \
timeout.c \
timeout-new.c \
+ timeout-swallow.c \
timestamp.c \
timestamp-bug.c \
truncate.c \
diff --git a/test/timeout-swallow.c b/test/timeout-swallow.c
new file mode 100644
index 00000000..9fb4ab01
--- /dev/null
+++ b/test/timeout-swallow.c
@@ -0,0 +1,117 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Description: tests that io_uring_wait_cqes() and variants do not swallow
+ * -ETIME when loop-fetching CQEs if some SQEs were submitted.
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/time.h>
+#include "liburing.h"
+#include "helpers.h"
+
+/*
+ * Test the normal -ETIME swallow path. (line 118 in queue.c)
+ */
+static int test_timeout(struct io_uring *ring)
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ struct __kernel_timespec long_ts = { .tv_sec = 10, .tv_nsec = 0 };
+ struct __kernel_timespec zero_ts = { .tv_sec = 0, .tv_nsec = 0 };
+ int ret;
+
+ if (!(ring->features & IORING_FEAT_EXT_ARG))
+ return T_EXIT_SKIP;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ fprintf(stderr, "get_sqe failed\n");
+ return T_EXIT_FAIL;
+ }
+ /* Long timeout, won't complete immediately */
+ io_uring_prep_timeout(sqe, &long_ts, 1, 0);
+
+ /* Zero timeout forces immediate expiry inside the syscall on first/second pass */
+ ret = io_uring_submit_and_wait_timeout(ring, &cqe, 2, &zero_ts, NULL);
+
+ if (ret == -ETIME) {
+ return T_EXIT_PASS;
+ }
+
+ fprintf(stderr, "test_timeout failed: expected -ETIME, got %d\n", ret);
+ return T_EXIT_FAIL;
+}
+
+/*
+ * Test the registered-wait -ETIME swallow path. (line 113 in queue.c)
+ */
+static int test_timeout_reg(struct io_uring *ring)
+{
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ struct __kernel_timespec long_ts = { .tv_sec = 10, .tv_nsec = 0 };
+ struct io_uring_reg_wait reg = { .ts = { .tv_sec = 0, .tv_nsec = 0 } };
+ int ret;
+
+ if (!(ring->features & IORING_FEAT_EXT_ARG))
+ return T_EXIT_SKIP;
+
+ ret = io_uring_register_wait_reg(ring, ®, 1);
+ if (ret) {
+ /* Not supported on this kernel */
+ return T_EXIT_SKIP;
+ }
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ fprintf(stderr, "get_sqe failed\n");
+ return T_EXIT_FAIL;
+ }
+ io_uring_prep_timeout(sqe, &long_ts, 1, 0);
+
+ ret = io_uring_submit_and_wait_reg(ring, &cqe, 2, 0);
+ if (ret == -ETIME) {
+ return T_EXIT_PASS;
+ }
+
+ fprintf(stderr, "test_timeout_reg failed: expected -ETIME, got %d\n", ret);
+ return T_EXIT_FAIL;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring ring;
+ int ret, ret2, final_ret = T_EXIT_PASS;
+
+ if (argc > 1)
+ return T_EXIT_SKIP;
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ if (ret == -ENOSYS)
+ return T_EXIT_SKIP;
+ fprintf(stderr, "queue_init failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ ret = test_timeout(&ring);
+ if (ret == T_EXIT_FAIL) {
+ fprintf(stderr, "test_timeout failed\n");
+ final_ret = T_EXIT_FAIL;
+ }
+
+ ret2 = test_timeout_reg(&ring);
+ if (ret2 == T_EXIT_FAIL) {
+ fprintf(stderr, "test_timeout_reg failed\n");
+ final_ret = T_EXIT_FAIL;
+ }
+
+ io_uring_queue_exit(&ring);
+
+ if (final_ret == T_EXIT_FAIL)
+ return T_EXIT_FAIL;
+ if (ret == T_EXIT_SKIP && ret2 == T_EXIT_SKIP)
+ return T_EXIT_SKIP;
+ return T_EXIT_PASS;
+}
--
2.43.0
prev parent reply other threads:[~2026-07-12 22:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-12 22:10 [PATCH 1/2] src/queue: don't swallow -ETIME when SQEs were submitted Prateek
2026-07-12 22:12 ` Prateek [this message]
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=20260712221222.535794-1-kprateek283@gmail.com \
--to=kprateek283@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