[PATCH v2 2/2] test/timeout-swallow: verify -ETIME is not swallowed
Prateek <[email protected]> Tue, 14 Jul 2026 22:27:02 +0530
| Newsgroups | org.kernel.vger.io-uring |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> Reviewed-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Prateek <[email protected]> --- 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..d08365da --- /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. + */ +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. + */ +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