[LTP] [PATCH 3/4] io_uring: Add test for varying buffer sizes with zero-length buffer
Sachin Sant
sachinp@linux.ibm.com
Wed May 6 20:37:49 CEST 2026
Add io_uring06 test to validate vectored I/O operations (IORING_OP_READV
and IORING_OP_WRITEV) with non-uniform buffer sizes including a
zero-length buffer.
The test verifies:
- Writing data using iovec with varying sizes (512, 0, 1024, 256 bytes)
- Reading data back into buffers of the same varying sizes
- Data integrity verification with zero-length buffer handling
- Proper handling of iovec arrays with mixed buffer sizes
This test ensures the kernel correctly handles zero-length buffers in
vectored I/O operations, which is important for applications that may
dynamically construct iovec arrays.
Signed-off-by: Sachin Sant <sachinp@linux.ibm.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/io_uring/.gitignore | 1 +
.../kernel/syscalls/io_uring/io_uring06.c | 97 +++++++++++++++++++
3 files changed, 99 insertions(+)
create mode 100644 testcases/kernel/syscalls/io_uring/io_uring06.c
diff --git a/runtest/syscalls b/runtest/syscalls
index bab0e8f3b..fc4892221 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1906,6 +1906,7 @@ io_uring02 io_uring02
io_uring03 io_uring03
io_uring04 io_uring04
io_uring05 io_uring05
+io_uring06 io_uring06
# Tests below may cause kernel memory leak
perf_event_open03 perf_event_open03
diff --git a/testcases/kernel/syscalls/io_uring/.gitignore b/testcases/kernel/syscalls/io_uring/.gitignore
index bce7048cd..dfe7cca5a 100644
--- a/testcases/kernel/syscalls/io_uring/.gitignore
+++ b/testcases/kernel/syscalls/io_uring/.gitignore
@@ -3,3 +3,4 @@
/io_uring03
/io_uring04
/io_uring05
+/io_uring06
diff --git a/testcases/kernel/syscalls/io_uring/io_uring06.c b/testcases/kernel/syscalls/io_uring/io_uring06.c
new file mode 100644
index 000000000..82e47a4e4
--- /dev/null
+++ b/testcases/kernel/syscalls/io_uring/io_uring06.c
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 IBM
+ * Author: Sachin Sant <sachinp@linux.ibm.com>
+ */
+/*\
+ *
+ * Test varying buffer sizes including zero-length buffers with
+ * IORING_OP_READV and IORING_OP_WRITEV.
+ *
+ * This test validates vectored I/O operations with non-uniform buffer
+ * sizes including a zero-length buffer. It tests:
+ * 1. IORING_OP_WRITEV - Writing data using buffers of varying sizes
+ * (512, 0, 1024, 256 bytes)
+ * 2. IORING_OP_READV - Reading data into buffers of varying sizes
+ * 3. Data integrity verification with zero-length buffer handling
+ * 4. Proper handling of iovec arrays with mixed buffer sizes
+ */
+
+#include "io_uring_common.h"
+
+#define TEST_FILE "io_uring_test_file"
+#define QUEUE_DEPTH 2
+#define NUM_VECS 4
+#define VAR_BUF1_SIZE 512
+#define VAR_BUF2_SIZE 1024
+#define VAR_BUF3_SIZE 256
+
+static struct iovec *write_iovs, *read_iovs;
+static struct io_uring_submit s;
+static sigset_t sig;
+
+static void run(void)
+{
+ int fd = -1;
+ int expected_size = VAR_BUF1_SIZE + VAR_BUF2_SIZE + VAR_BUF3_SIZE;
+
+ tst_res(TINFO,
+ "Testing vectors with varying sizes including zero-length buffer");
+
+ io_uring_init_iovec_pattern(write_iovs, NUM_VECS, 'X', 0);
+ io_uring_clear_iovec(read_iovs, NUM_VECS);
+
+ fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT | O_TRUNC, 0644);
+
+ tst_res(TINFO,
+ "Writing %d bytes using buffers of sizes: 512, 0, 1024, 256",
+ expected_size);
+ io_uring_do_vec_io_op(&s, fd, IORING_OP_WRITEV, write_iovs, NUM_VECS,
+ 0, expected_size, &sig);
+
+ SAFE_FSYNC(fd);
+
+ tst_res(TINFO,
+ "Reading %d bytes using buffers of sizes: 512, 0, 1024, 256",
+ expected_size);
+ io_uring_do_vec_io_op(&s, fd, IORING_OP_READV, read_iovs, NUM_VECS, 0,
+ expected_size, &sig);
+
+ io_uring_verify_iovec(write_iovs, read_iovs, NUM_VECS);
+
+ SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+ io_uring_setup_supported_by_kernel();
+ sigemptyset(&sig);
+ memset(&s, 0, sizeof(s));
+ io_uring_setup_queue(&s, QUEUE_DEPTH, 0);
+}
+
+static void cleanup(void)
+{
+ io_uring_cleanup_queue(&s, QUEUE_DEPTH);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+ .bufs = (struct tst_buffers []) {
+ {&write_iovs, .iov_sizes = (int[]){VAR_BUF1_SIZE, 0,
+ VAR_BUF2_SIZE,
+ VAR_BUF3_SIZE, -1}},
+ {&read_iovs, .iov_sizes = (int[]){VAR_BUF1_SIZE, 0,
+ VAR_BUF2_SIZE,
+ VAR_BUF3_SIZE, -1}},
+ {}
+ },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/kernel/io_uring_disabled", "0",
+ TST_SR_SKIP_MISSING | TST_SR_TCONF_RO},
+ {}
+ }
+};
--
2.39.1
More information about the ltp
mailing list