[LTP] [PATCH v7] io_submit04: Add test case for RWF_NOWAIT flag

Wei Gao wegao@suse.com
Thu Apr 9 04:26:07 CEST 2026


On Wed, Apr 08, 2026 at 05:11:03PM +0200, Cyril Hrubis wrote:
> Hi!
> > --- /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()
> > + * :manpage:`io_getevents(2)` 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");
> 
> Sorry if that was asked in previous reviews. Why are we using
> tst_syscall() instead of the libaio functions like we do in the rest of
> the tests?

No one asked in previous reviews.

For io_submit0* test group, ONLY io_submit01.c use libaio function,
io_submit02.c and io_submit03.c use tst_syscall. I guess io_submit01.c is explicitly
designed to test the libaio library wrapper. Its documentation states: 
"Test io_submit() invoked via libaio".

I prefer io_submit04.c use tst_syscall instead of libaio since no dependency with libaio-devel
and makes the test more portable.

If you are agree then i will send next patch with s/strerror/tst_strerrno fix.
Thanks.

> 
> > +	SAFE_PIPE(fd);
> > +
> > +	cb->aio_fildes = fd[0];
> > +	cb->aio_lio_opcode = IOCB_CMD_PREAD;
> > +	cb->aio_buf = TST_PTR_TO_UINT(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 && 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));
>                             ^
> 			    tst_strerrno()
> 
> Other than these two minor issues I do not see any problems in the code,
> the rest looks fine.
> 
> -- 
> Cyril Hrubis
> chrubis@suse.cz


More information about the ltp mailing list