[LTP] [PATCH v3] io_submit04: Add test case for RWF_NOWAIT flag
Wei Gao
wegao@suse.com
Tue Jan 6 07:26:56 CET 2026
On Mon, Jan 05, 2026 at 01:53:50PM +0100, Andrea Cervesato wrote:
> Hi!
>
> On Wed Dec 24, 2025 at 9:49 AM CET, Wei Gao wrote:
> > 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 | 86 +++++++++++++++++++
> > 5 files changed, 133 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 a0ebbb34d..ee46e3f24 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..bd8c2965b
> > --- /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 a1ef7548b..18182a2d6 100644
> > --- a/runtest/syscalls
> > +++ b/runtest/syscalls
> > @@ -696,6 +696,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..bae89828a
> > --- /dev/null
> > +++ b/testcases/kernel/syscalls/io_submit/io_submit04.c
> > @@ -0,0 +1,86 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * Copyright (c) 2025 Wei Gao <wegao@suse.com>
> > + */
> > +
> > +/*\
> > + * Test iocb RWF_* flags support: RWF_NOWAIT
> > + *
> > + * Checks if an asynchronous read operation with RWF_NOWAIT on a blocking
> > + * resource (empty pipe) fails immediately with -EAGAIN.
>
> We can write it better:
>
> /*\
> * 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"
> > +
> > +static int fd[2];
> > +static char buf[100];
> > +
> > +static aio_context_t ctx;
> > +static iocb cb;
> > +static iocb *iocbs[] = {&cb};
>
> Data that is passed to syscalls should be initialized via tst_test.bufs
>
> > +
> > +static inline void io_prep_option(iocb *cb, int fd, void *buf,
> > + size_t count, long long offset, unsigned int opcode)
> > +{
> > + memset(cb, 0, sizeof(*cb));
> > + cb->aio_fildes = fd;
> > + cb->aio_lio_opcode = opcode;
> > + cb->aio_buf = (uint64_t)buf;
> > + cb->aio_offset = offset;
> > + cb->aio_nbytes = count;
> > + cb->aio_rw_flags = RWF_NOWAIT;
> > +}
> > +
> > +static void setup(void)
> > +{
> > + TST_EXP_PASS_SILENT(tst_syscall(__NR_io_setup, 1, &ctx));
> > + SAFE_PIPE(fd);
> > + io_prep_option(&cb, fd[0], buf, sizeof(buf), 0, IOCB_CMD_PREAD);
> > +}
> > +
> > +static void cleanup(void)
> > +{
> > + if (fd[0])
> > + SAFE_CLOSE(fd[0]);
> > +
> > + if (fd[1])
> > + SAFE_CLOSE(fd[1]);
> > +
> > + 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 == nr)
> > + tst_res(TPASS, "io_submit() pass");
> > + else
> > + tst_res(TFAIL | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);
>
> Our goal is to verify that io_getevents() returns EAGAIN, so we can just:
>
> if (TST_RET != nr) {
> tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);
> return;
> }
>
> We return because if io_submit() fails there's nothing to do more.
tst_res(TBROK will trigger error such as :
make[1]: Leaving directory '/home/wegao/ltp/lib'
In file included from ../../../../include/tst_test.h:20,
from io_submit04.c:14:
io_submit04.c: In function ‘run’:
../../../../include/tst_common.h:80:32: error: size of unnamed array is negative
80 | do { ((void)sizeof(char[1 - 2 * !!(condition)])); } while (0)
| ^
../../../../include/tst_common.h:83:9: note: in expansion of macro ‘TST_BUILD_BUG_ON’
83 | TST_BUILD_BUG_ON(condition)
| ^~~~~~~~~~~~~~~~
../../../../include/tst_test.h:71:17: note: in expansion of macro ‘TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN’
71 | TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN(\
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
io_submit04.c:63:17: note: in expansion of macro ‘tst_res’
63 | tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
| ^~~~~~~
make: *** [../../../../include/mk/rules.mk:48: io_submit04] Error 1
-bash: ./io_submit04: No such file or directory
So i suppose we need use "tst_brk(TBROK" without return, correct?
>
> > +
> > + tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout);
> > +
> > + if (evbuf.res == -EAGAIN)
> > + tst_res(TINFO, "io_submit RWF_NOWAIT flag check pass");
>
> Why TINFO if we are testing this feature? Also the message is not giving
> any information of io_getevents(). We can just (look below)...
>
> > + else
> > + tst_res(TFAIL | TTERRNO, "io_submit expect EAGAIN, but get %s", strerror(-evbuf.res));
> > +
> > +}
>
> if (evbuf.res == -EAGAIN)
> tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
> else
> tst_res(TFAIL | TTERRNO, "io_getevents() returned with %s instead of EAGAIN", strerror(-evbuf.res));
>
> > +
> > +static struct tst_test test = {
> > + .test_all = run,
> > + .needs_kconfigs = (const char *[]) {
> > + "CONFIG_AIO=y",
> > + NULL
> > + },
> > + .setup = setup,
> > + .cleanup = cleanup,
> > +};
>
> --
> Andrea Cervesato
> SUSE QE Automation Engineer Linux
> andrea.cervesato@suse.com
>
More information about the ltp
mailing list