public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v6] io_submit04: Add test case for RWF_NOWAIT flag
Date: Tue, 17 Mar 2026 11:46:16 +0000	[thread overview]
Message-ID: <20260317114635.944-1-wegao@suse.com> (raw)
In-Reply-To: <20260317074340.589-1-wegao@suse.com>

v5-v6:
- Changed fd checks to != -1 in cleanup function
- Replaced errno with TST_ERR for LTP macro consistency
- cleanup format issue for aio_abi.h

Fixes: #467
Signed-off-by: Wei Gao <wegao@suse.com>
---
 configure.ac                                  |  1 +
 include/lapi/aio_abi.h                        | 44 +++++++++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 99 +++++++++++++++++++
 5 files changed, 146 insertions(+)
 create mode 100644 include/lapi/aio_abi.h
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c

diff --git a/configure.ac b/configure.ac
index 7fa614dcb..61462d192 100644
--- a/configure.ac
+++ b/configure.ac
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
diff --git a/include/lapi/aio_abi.h b/include/lapi/aio_abi.h
new file mode 100644
index 000000000..ac78e5500
--- /dev/null
+++ b/include/lapi/aio_abi.h
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <wegao@suse.com>
+ */
+
+#ifndef LAPI_AIO_ABI_H__
+#define LAPI_AIO_ABI_H__
+
+#include <endian.h>
+#include <linux/aio_abi.h>
+
+#ifndef RWF_NOWAIT
+# define RWF_NOWAIT 0x00000008
+#endif
+
+struct iocb_fallback {
+	uint64_t aio_data;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+	uint32_t   aio_key;
+	uint32_t aio_rw_flags;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+	uint32_t aio_rw_flags;
+	uint32_t   aio_key;
+#else
+#error edit for your odd byteorder.
+#endif
+	uint16_t   aio_lio_opcode;
+	int16_t   aio_reqprio;
+	uint32_t   aio_fildes;
+	uint64_t   aio_buf;
+	uint64_t   aio_nbytes;
+	int64_t   aio_offset;
+	uint64_t   aio_reserved2;
+	uint32_t   aio_flags;
+	uint32_t   aio_resfd;
+};
+
+#ifndef HAVE_STRUCT_IOCB_AIO_RW_FLAGS
+typedef struct iocb_fallback iocb;
+#else
+typedef struct iocb iocb;
+#endif
+
+#endif /* LAPI_AIO_ABI_H__ */
diff --git a/runtest/syscalls b/runtest/syscalls
index 2179e007c..9812b1bfe 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -699,6 +699,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
diff --git a/testcases/kernel/syscalls/io_submit/.gitignore b/testcases/kernel/syscalls/io_submit/.gitignore
index 60b07970a..abe962e1c 100644
--- a/testcases/kernel/syscalls/io_submit/.gitignore
+++ b/testcases/kernel/syscalls/io_submit/.gitignore
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
diff --git a/testcases/kernel/syscalls/io_submit/io_submit04.c b/testcases/kernel/syscalls/io_submit/io_submit04.c
new file mode 100644
index 000000000..3b8842da0
--- /dev/null
+++ b/testcases/kernel/syscalls/io_submit/io_submit04.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <wegao@suse.com>
+ */
+
+/*\
+ * Test RWF_NOWAIT support in io_submit(), verifying that an
+ * asynchronous read operation on a blocking resource (empty pipe)
+ * will cause -EAGAIN. This is done by checking that io_getevents()
+ * syscall returns immediately and io_event.res is equal to -EAGAIN.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/aio_abi.h"
+
+#define BUF_SIZE 100
+
+static int fd[2] = {-1, -1};
+static aio_context_t ctx;
+static char *buf;
+static iocb *cb;
+static iocb **iocbs;
+
+static void setup(void)
+{
+	if (tst_syscall(__NR_io_setup, 1, &ctx))
+		tst_brk(TBROK | TERRNO, "io_setup failed");
+
+	SAFE_PIPE(fd);
+
+	cb->aio_fildes = fd[0];
+	cb->aio_lio_opcode = IOCB_CMD_PREAD;
+	cb->aio_buf = (uint64_t)buf;
+	cb->aio_offset = 0;
+	cb->aio_nbytes = BUF_SIZE;
+	cb->aio_rw_flags = RWF_NOWAIT;
+
+	iocbs[0] = cb;
+}
+
+static void cleanup(void)
+{
+	if (fd[0] != -1)
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1] != -1)
+		SAFE_CLOSE(fd[1]);
+
+	if (ctx)
+		if (tst_syscall(__NR_io_destroy, ctx))
+			tst_brk(TBROK | TERRNO, "io_destroy() failed");
+}
+
+static void run(void)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long nr = 1;
+
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) {
+		tst_brk(TCONF, "RWF_NOWAIT not supported by kernel");
+	} else if (TST_RET != nr) {
+		tst_brk(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
+				TST_RET, nr);
+	}
+
+	TEST(tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout));
+
+	if (TST_RET != 1) {
+		tst_res(TFAIL | TTERRNO, "io_getevents() failed to get 1 event");
+		return;
+	}
+
+	if (evbuf.res == -EAGAIN)
+		tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
+	else
+		tst_res(TFAIL, "io_getevents() returned with %s instead of EAGAIN",
+			strerror(-evbuf.res));
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&buf, .size = BUF_SIZE},
+		{&cb, .size = sizeof(iocb)},
+		{&iocbs, .size = sizeof(iocb *)},
+		{},
+	}
+};
-- 
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2026-03-17 11:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-29  1:27 [LTP] [PATCH v1] io_submit04: Add test case for RWF_NOWAIT flag Wei Gao via ltp
2024-02-06 15:59 ` Petr Vorel
2025-10-22  2:05 ` [LTP] [PATCH v2] " Wei Gao via ltp
2025-12-18 13:21   ` Andrea Cervesato via ltp
2025-12-24  8:49   ` [LTP] [PATCH v3] " Wei Gao via ltp
2026-01-05 12:53     ` Andrea Cervesato via ltp
2026-01-06  6:26       ` Wei Gao via ltp
2026-01-06  8:39         ` Andrea Cervesato via ltp
2026-01-06  8:39         ` Petr Vorel
2026-01-07  8:53           ` Jan Stancek via ltp
2026-01-07  6:10     ` [LTP] [PATCH v4] " Wei Gao via ltp
2026-02-18 12:21       ` Andrea Cervesato via ltp
2026-03-05  4:41         ` Wei Gao via ltp
2026-03-17  7:43       ` [LTP] [PATCH v5] " Wei Gao via ltp
2026-03-17  9:54         ` Andrea Cervesato via ltp
2026-03-17 11:46         ` Wei Gao via ltp [this message]
2026-03-20 12:54           ` [LTP] [PATCH v6] " Andrea Cervesato via ltp
2026-03-27 18:17           ` Petr Vorel
2026-03-30  8:08             ` Wei Gao via ltp
2026-04-04  1:00             ` Wei Gao via ltp
2026-03-31 11:18           ` [LTP] [PATCH v7] fanotify22.c: handle multiple asynchronous error events Wei Gao via ltp
2026-04-04  1:13           ` [LTP] [PATCH v7] io_submit04: Add test case for RWF_NOWAIT flag Wei Gao via ltp

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=20260317114635.944-1-wegao@suse.com \
    --to=ltp@lists.linux.it \
    --cc=wegao@suse.com \
    /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