io_uring READ(V), WRITE(v) operation tests
cover io_uring READ(V), WRITE(v) operation tests
This patch series adds a set of test case to validate IOURING READ & WRITE (io_uring03), READV & WRITEV (io_uring04) operations. The patch also adds a common header file to avoid code duplication.
These patches have been tested successfully on ppc64le arch (fedora and SLES flavours)
Code is available
at https://github.com/sacsant/ltp/tree/uring_fio
Test run:
$ ./io_uring03 tst_tmpdir.c:308: TINFO: Using /tmp/LTP_io_XN0m3T as tmpdir (tmpfs filesystem) tst_test.c:2059: TINFO: LTP version: 20210524-3958-g3203be536 ...... tst_test.c:1887: TINFO: Overall timeout per run is 0h 00m 30s io_uring03.c:195: TINFO: Testing IORING_OP_WRITE io_uring03.c:199: TPASS: IORING_OP_WRITE completed successfully io_uring03.c:205: TINFO: Testing IORING_OP_READ io_uring03.c:210: TPASS: IORING_OP_READ completed successfully io_uring03.c:214: TPASS: Data integrity verified io_uring03.c:236: TINFO: Testing partial I/O operations io_uring03.c:247: TPASS: Partial write (first half) succeeded io_uring03.c:252: TPASS: Partial write (second half) succeeded io_uring03.c:260: TPASS: Full read after partial writes succeeded io_uring03.c:264: TPASS: Partial I/O data integrity verified
Summary:
passed 7 failed 0 broken 0 skipped 0 warnings 0 $ ./io_uring04 tst_tmpdir.c:308: TINFO: Using /tmp/LTP_io_ekmpZP as tmpdir (tmpfs filesystem) tst_test.c:2059: TINFO: LTP version: 20210524-3958-g3203be536 ....... tst_test.c:1887: TINFO: Overall timeout per run is 0h 00m 30s io_uring04.c:218: TINFO: Testing IORING_OP_WRITEV and IORING_OP_READV io_uring04.c:226: TINFO: Writing 4096 bytes using 4 vectors io_uring04.c:230: TPASS: IORING_OP_WRITEV completed successfully io_uring04.c:235: TINFO: Reading 4096 bytes using 4 vectors io_uring04.c:239: TPASS: IORING_OP_READV completed successfully io_uring04.c:258: TPASS: Data integrity verified across all 4 vectors io_uring04.c:270: TINFO: Testing partial vector operations io_uring04.c:284: TPASS: Partial IORING_OP_WRITEV (2 vectors) succeeded io_uring04.c:294: TPASS: Partial IORING_OP_READV (2 vectors) succeeded io_uring04.c:305: TPASS: Partial vector data integrity verified io_uring04.c:319: TINFO: Testing vectors with varying sizes io_uring04.c:352: TPASS: IORING_OP_WRITEV with varying sizes succeeded io_uring04.c:359: TPASS: IORING_OP_READV with varying sizes succeeded io_uring04.c:365: TPASS: Varying size vector data integrity verified
Summary:
passed 9 failed 0 broken 0 skipped 0
warnings 0
$
Sachin Sant (2):
io_uring: Test IORING READ and WRITE operations
io_uring: Test READV and WRITEV operations
runtest/syscalls | 2 + testcases/kernel/syscalls/io_uring/.gitignore | 2 + .../kernel/syscalls/io_uring/io_uring03.c | 145 ++++++++++ .../kernel/syscalls/io_uring/io_uring04.c | 248 ++++++++++++++++++ .../syscalls/io_uring/io_uring_common.h | 227 ++++++++++++++++ 5 files changed, 624 insertions(+) create mode 100644 testcases/kernel/syscalls/io_uring/io_uring03.c create mode 100644 testcases/kernel/syscalls/io_uring/io_uring04.c create mode 100644 testcases/kernel/syscalls/io_uring/io_uring_common.h
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
RFC PATCH 1/2 io_uring: Test IORING READ and WRITE operations
This test validates basic read and write operations using io_uring. It tests:
1. IORING_OP_WRITE - Writing data to a file
2. IORING_OP_READ - Reading data from a file
3. Data integrity verification
This patch also introduces a header file for common functions.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/io_uring/.gitignore | 1 + .../kernel/syscalls/io_uring/io_uring03.c | 145 +++++++++++ .../syscalls/io_uring/io_uring_common.h | 227 ++++++++++++++++++ 4 files changed, 374 insertions(+) create mode 100644 testcases/kernel/syscalls/io_uring/io_uring03.c create mode 100644 testcases/kernel/syscalls/io_uring/io_uring_common.h
runtest/syscalls +1 -0
@@ -1898,6 +1898,7 @@ membarrier01 membarrier01 io_uring01 io_uring01 io_uring02 io_uring02 +io_uring03 io_uring03 # Tests below may cause kernel memory leak perf_event_open03 perf_event_open03
testcases/kernel/syscalls/io_uring/.gitignore +1 -0
@@ -1,2 +1,3 @@ /io_uring01 /io_uring02 +/io_uring03
testcases/kernel/syscalls/io_uring/io_uring03.c new file +145 -0
145 lines not on this page · raw message
testcases/kernel/syscalls/io_uring/io_uring_common.h new file +227 -0
227 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [RFC] [PATCH 1/2] io_uring: Test IORING READ and WRITE operations
Hi!
Quoted 19 lines
# Tests below may cause kernel memory leak
perf_event_open03perf_event_open03testcases/kernel/syscalls/io_uring/.gitignore +1
-0@@ -1,2 +1,3 @@ /io_uring01 /io_uring02 +/io_uring03testcases/kernel/syscalls/io_uring/io_uring03.c new file +3
-0@@ -0,0 +1,145 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2026 IBM
testcases/kernel/syscalls/io_uring/io_uring03.c line 13
Quoted 10 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +10
-0+* Author: Sachin Sant <[email protected]> +* +* Test IORING_OP_READ and IORING_OP_WRITE operations. +* +* This test validates basic read and write operations using io_uring. +* It tests: +* 1. IORING_OP_WRITE - Writing data to a file +* 2. IORING_OP_READ - Reading data from a file +* 3. Data integrity verification +*/
The second half of the comment should be doc comment (starts with /*\) so that it's picked up by the documentation parser and exported into the online documentation.
Quoted 7 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +7
-0+#include "io_uring_common.h" + +#define TEST_FILE "io_uring_test_file" +#define QUEUE_DEPTH 2 +#define BLOCK_SZ 4096 + +static char write_buf[BLOCK_SZ ];
testcases/kernel/syscalls/io_uring/io_uring03.c line 31
Quoted 10 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +10
-0+static char read_buf[BLOCK_SZ ]; +static struct io_uring_submit s; +static sigset_t sig; + +static void test_write_read (void ) +{ +int fd; +size_t i; + +/* Prepare write buffer with pattern */
There a lot of comments like this that are commenting the obvious. Comments that comment obvious does not add any value and shouldn't be added.
testcases/kernel/syscalls/io_uring/io_uring03.c line 33
Quoted 2 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +2
-0+for (i =0 ; i <BLOCK_SZ ; i++) + write_buf[i] ='A' + (i %26 );
This should be done only once in the test setup.
Quoted 27 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +24
-0+/* Open file for writing */ + fd =SAFE_OPEN (TEST_FILE ,O_RDWR |O_CREAT |O_TRUNC ,0644 ); + +/* Test IORING_OP_WRITE */ +tst_res (TINFO ,"Testing IORING_OP_WRITE" ); +io_uring_submit_sqe (&s, fd,IORING_OP_WRITE , write_buf,BLOCK_SZ ,0 ); +if (io_uring_wait_cqe (&s,BLOCK_SZ ,IORING_OP_WRITE , &sig) ==0 ) +tst_res (TPASS ,"IORING_OP_WRITE completed successfully" ); + +/* Sync to ensure data is written */ +SAFE_FSYNC (fd); + +/* Test IORING_OP_READ */ +tst_res (TINFO ,"Testing IORING_OP_READ" ); +memset (read_buf,0 ,BLOCK_SZ ); +io_uring_submit_sqe (&s, fd,IORING_OP_READ , read_buf,BLOCK_SZ ,0 ); + +if (io_uring_wait_cqe (&s,BLOCK_SZ ,IORING_OP_READ , &sig) ==0 ) +tst_res (TPASS ,"IORING_OP_READ completed successfully" ); + +/* Verify data integrity */ +if (memcmp (write_buf, read_buf,BLOCK_SZ ) ==0 ) { +tst_res (TPASS ,"Data integrity verified" ); + }else {
testcases/kernel/syscalls/io_uring/io_uring03.c line 69
Quoted 10 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +10
-0+tst_res (TFAIL ,"Data mismatch after read" ); +for (i =0 ; i <BLOCK_SZ && i <64 ; i++) { +if (write_buf[i] != read_buf[i]) { +tst_res (TINFO ,"First mismatch at offset %zu: " +"wrote 0x%02x, read 0x%02x" , + i, write_buf[i], read_buf[i]); +break ; + } + } + }
This should really be put into a function and used in both test cases.
Quoted 61 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +61
-0+SAFE_CLOSE (fd); +} + +static void test_partial_io (void ) +{ +int fd; +size_t half =BLOCK_SZ /2 ; +size_t i; + +tst_res (TINFO ,"Testing partial I/O operations" ); + +/* Prepare buffer */ +for (i =0 ; i <BLOCK_SZ ; i++) + write_buf[i] ='a' + (i %26 ); + + fd =SAFE_OPEN (TEST_FILE ,O_RDWR |O_CREAT |O_TRUNC ,0644 ); + +/* Write first half */ +io_uring_submit_sqe (&s, fd,IORING_OP_WRITE , write_buf, half,0 ); +if (io_uring_wait_cqe (&s, half,IORING_OP_WRITE , &sig) ==0 ) +tst_res (TPASS ,"Partial write (first half) succeeded" ); + +/* Write second half */ +io_uring_submit_sqe (&s, fd,IORING_OP_WRITE , write_buf + half, + half, half); +if (io_uring_wait_cqe (&s, half,IORING_OP_WRITE , &sig) ==0 ) +tst_res (TPASS ,"Partial write (second half) succeeded" ); + +SAFE_FSYNC (fd); + +/* Read back in one operation */ +memset (read_buf,0 ,BLOCK_SZ ); +io_uring_submit_sqe (&s, fd,IORING_OP_READ , read_buf,BLOCK_SZ ,0 ); +if (io_uring_wait_cqe (&s,BLOCK_SZ ,IORING_OP_READ , &sig) ==0 ) +tst_res (TPASS ,"Full read after partial writes succeeded" ); + +/* Verify */ +if (memcmp (write_buf, read_buf,BLOCK_SZ ) ==0 ) +tst_res (TPASS ,"Partial I/O data integrity verified" ); +else +tst_res (TFAIL ,"Partial I/O data mismatch" ); + +SAFE_CLOSE (fd); +} + +static void run (void ) +{ +io_uring_setup_queue (&s,QUEUE_DEPTH ); +test_write_read (); +test_partial_io (); +io_uring_cleanup_queue (&s,QUEUE_DEPTH ); +} + +static void setup (void ) +{ +io_uring_setup_supported_by_kernel (); +sigemptyset (&sig); +memset (&s,0 ,sizeof (s)); +} + +static struct tst_test test = {
testcases/kernel/syscalls/io_uring/io_uring03.c line 141
Quoted 10 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +10
-0+ .test_all = run, + .setup = setup, + .needs_tmpdir = 1, + .save_restore = (const struct tst_path_val []) { + {"/proc/sys/kernel/io_uring_disabled" ,"0" , +TST_SR_SKIP_MISSING |TST_SR_TCONF_RO }, + {} + }, + .tags = (const struct tst_tag []) { + {"linux-git" ,"5d17b4a4b48c" },
This commit does not appear to exist in linux kernel git tree.
testcases/kernel/syscalls/io_uring/io_uring03.c line 142
Quoted 1 line
testcases/kernel/syscalls/io_uring/io_uring03.c new file +1
-0+ {"linux-git", "2b188cc1bb85"},
And this is a commit that added io_uring. Commit hashes in tests are used only for cases where the test is a regression test for some bug and point to a commit that fixed the problem.
testcases/kernel/syscalls/io_uring/io_uring_common.h
Quoted 4 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +3
-0+ {} + } +};testcases/kernel/syscalls/io_uring/io_uring_common.h +0
-0
Since you are pulling the common code into header it would be nice to convert the io_uring01.c so that it uses the common header as well.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [RFC] [PATCH 1/2] io_uring: Test IORING READ and WRITE operations
Quoted 25 lines · Cyril Hrubis
Hi!
Quoted 24 lines
# Tests below may cause kernel memory leak
perf_event_open03perf_event_open03testcases/kernel/syscalls/io_uring/.gitignore +1
-0@@ -1,2 +1,3 @@ /io_uring01 /io_uring02 +/io_uring03testcases/kernel/syscalls/io_uring/io_uring03.c new file +8
-0@@ -0,0 +1,145 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2026 IBM +* Author: Sachin Sant <[email protected]> +* +* Test IORING_OP_READ and IORING_OP_WRITE operations. +* +* This test validates basic read and write operations using io_uring.
Quoted 8 lines
testcases/kernel/syscalls/io_uring/io_uring03.c line 13
Quoted 5 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +5
-0+* It tests: +* 1. IORING_OP_WRITE - Writing data to a file +* 2. IORING_OP_READ - Reading data from a file +* 3. Data integrity verification +*/ The second half of the comment should be doc comment (starts with /*\) so that it's picked up by the documentation parser and exported into the online documentation.
Ah yes, will modify.
Quoted 12 lines
Quoted 12 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +12
-0+#include "io_uring_common.h" + +#define TEST_FILE "io_uring_test_file" +#define QUEUE_DEPTH 2 +#define BLOCK_SZ 4096 + +static char write_buf[BLOCK_SZ ]; +static char read_buf[BLOCK_SZ ]; +static struct io_uring_submit s; +static sigset_t sig; + +static void test_write_read (void )
Quoted 8 lines
testcases/kernel/syscalls/io_uring/io_uring03.c line 31
Quoted 5 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +5
-0+{ +int fd; +size_t i; + +/* Prepare write buffer with pattern */ There a lot of comments like this that are commenting the obvious. Comments that comment obvious does not add any value and shouldn't be added.
Will revisit the code.
Quoted 3 lines
testcases/kernel/syscalls/io_uring/io_uring03.c line 33
Quoted 2 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +2
-0+for (i =0 ; i <BLOCK_SZ ; i++) + write_buf[i] ='A' + (i %26 );This should be done only once in the test setup.
Will address this in v2.
Quoted 29 lines
Quoted 29 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +27
-0+/* Open file for writing */ + fd =SAFE_OPEN (TEST_FILE ,O_RDWR |O_CREAT |O_TRUNC ,0644 ); + +/* Test IORING_OP_WRITE */ +tst_res (TINFO ,"Testing IORING_OP_WRITE" ); +io_uring_submit_sqe (&s, fd,IORING_OP_WRITE , write_buf,BLOCK_SZ ,0 ); +if (io_uring_wait_cqe (&s,BLOCK_SZ ,IORING_OP_WRITE , &sig) ==0 ) +tst_res (TPASS ,"IORING_OP_WRITE completed successfully" ); + +/* Sync to ensure data is written */ +SAFE_FSYNC (fd); + +/* Test IORING_OP_READ */ +tst_res (TINFO ,"Testing IORING_OP_READ" ); +memset (read_buf,0 ,BLOCK_SZ ); +io_uring_submit_sqe (&s, fd,IORING_OP_READ , read_buf,BLOCK_SZ ,0 ); + +if (io_uring_wait_cqe (&s,BLOCK_SZ ,IORING_OP_READ , &sig) ==0 ) +tst_res (TPASS ,"IORING_OP_READ completed successfully" ); + +/* Verify data integrity */ +if (memcmp (write_buf, read_buf,BLOCK_SZ ) ==0 ) { +tst_res (TPASS ,"Data integrity verified" ); + }else { +tst_res (TFAIL ,"Data mismatch after read" ); +for (i =0 ; i <BLOCK_SZ && i <64 ; i++) { +if (write_buf[i] != read_buf[i]) {
Quoted 8 lines
testcases/kernel/syscalls/io_uring/io_uring03.c line 69
Quoted 7 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +7
-0+tst_res (TINFO ,"First mismatch at offset %zu: " +"wrote 0x%02x, read 0x%02x" , + i, write_buf[i], read_buf[i]); +break ; + } + } + }This should really be put into a function and used in both test cases.
Will address it.
Quoted 64 lines
Quoted 64 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +64
-0+SAFE_CLOSE (fd); +} + +static void test_partial_io (void ) +{ +int fd; +size_t half =BLOCK_SZ /2 ; +size_t i; + +tst_res (TINFO ,"Testing partial I/O operations" ); + +/* Prepare buffer */ +for (i =0 ; i <BLOCK_SZ ; i++) + write_buf[i] ='a' + (i %26 ); + + fd =SAFE_OPEN (TEST_FILE ,O_RDWR |O_CREAT |O_TRUNC ,0644 ); + +/* Write first half */ +io_uring_submit_sqe (&s, fd,IORING_OP_WRITE , write_buf, half,0 ); +if (io_uring_wait_cqe (&s, half,IORING_OP_WRITE , &sig) ==0 ) +tst_res (TPASS ,"Partial write (first half) succeeded" ); + +/* Write second half */ +io_uring_submit_sqe (&s, fd,IORING_OP_WRITE , write_buf + half, + half, half); +if (io_uring_wait_cqe (&s, half,IORING_OP_WRITE , &sig) ==0 ) +tst_res (TPASS ,"Partial write (second half) succeeded" ); + +SAFE_FSYNC (fd); + +/* Read back in one operation */ +memset (read_buf,0 ,BLOCK_SZ ); +io_uring_submit_sqe (&s, fd,IORING_OP_READ , read_buf,BLOCK_SZ ,0 ); +if (io_uring_wait_cqe (&s,BLOCK_SZ ,IORING_OP_READ , &sig) ==0 ) +tst_res (TPASS ,"Full read after partial writes succeeded" ); + +/* Verify */ +if (memcmp (write_buf, read_buf,BLOCK_SZ ) ==0 ) +tst_res (TPASS ,"Partial I/O data integrity verified" ); +else +tst_res (TFAIL ,"Partial I/O data mismatch" ); + +SAFE_CLOSE (fd); +} + +static void run (void ) +{ +io_uring_setup_queue (&s,QUEUE_DEPTH ); +test_write_read (); +test_partial_io (); +io_uring_cleanup_queue (&s,QUEUE_DEPTH ); +} + +static void setup (void ) +{ +io_uring_setup_supported_by_kernel (); +sigemptyset (&sig); +memset (&s,0 ,sizeof (s)); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_tmpdir =1 ,
Quoted 8 lines
testcases/kernel/syscalls/io_uring/io_uring03.c line 141
Quoted 7 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +7
-0+ .save_restore = (const struct tst_path_val[]) { + {"/proc/sys/kernel/io_uring_disabled" ,"0" , +TST_SR_SKIP_MISSING |TST_SR_TCONF_RO }, + {} + }, + .tags = (const struct tst_tag []) { + {"linux-git" ,"5d17b4a4b48c" },This commit does not appear to exist in linux kernel git tree.
I will double check on this. Thanks for the review.
Quoted 5 lines
testcases/kernel/syscalls/io_uring/io_uring03.c line 142
Quoted 2 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +1
-0+ {"linux-git", "2b188cc1bb85"},And this is a commit that added
io_uring. Commit hashes in tests are used only for cases where the test is a regression test for some bug and point to a commit that fixed the problem.
Understood. Based on the review, I will then remove this code since this is a new testcase to improve coverage and not a regression test.
Quoted 8 lines
testcases/kernel/syscalls/io_uring/io_uring_common.h
Quoted 5 lines
testcases/kernel/syscalls/io_uring/io_uring03.c new file +3
-0+ {} + } +};testcases/kernel/syscalls/io_uring/io_uring_common.h +0
-0Since you are pulling the common code into header it would be nice to convert the
io_uring01.cso that it uses the common header as well.
Will address this in V2.
Thanks again for the review.
Signature · 7 lines
Thanks - Sachin -- Mailing list info: https://lists.linux.it/listinfo/ltp
RFC PATCH 2/2 io_uring: Test READV and WRITEV operations
In reply to Sachin SantThis test validates vectored read and write operations using io_uring. It tests:
1. IORING_OP_WRITEV - Writing data using multiple buffers (scatter)
2. IORING_OP_READV - Reading data into multiple buffers (gather)
3. Data integrity verification across multiple iovecs
4. Edge cases with different iovec configurations
--- runtest/syscalls | 1 + testcases/kernel/syscalls/io_uring/.gitignore | 1 + .../kernel/syscalls/io_uring/io_uring04.c | 248 ++++++++++++++++++ 3 files changed, 250 insertions(+) create mode 100644 testcases/kernel/syscalls/io_uring/io_uring04.c
runtest/syscalls +1 -0
@@ -1899,6 +1899,7 @@ membarrier01 membarrier01 io_uring01 io_uring01 io_uring02 io_uring02 io_uring03 io_uring03 +io_uring03 io_uring04 # Tests below may cause kernel memory leak perf_event_open03 perf_event_open03
testcases/kernel/syscalls/io_uring/.gitignore +1 -0
@@ -1,3 +1,4 @@ /io_uring01 /io_uring02 /io_uring03 +/io_uring04
testcases/kernel/syscalls/io_uring/io_uring04.c new file +248 -0
248 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp