[LTP] [PATCH 2/2] Add regression test for epoll_pwait2() timeout

Andrea Cervesato andrea.cervesato@suse.com
Tue Jun 3 16:33:51 CEST 2025


Hi!

On 6/3/25 16:13, Martin Doucha wrote:
> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
> ---
>
> Note: The test will get killed by SIGALRM on failure.
>
>   runtest/syscalls                              |  1 +
>   .../kernel/syscalls/epoll_pwait/.gitignore    |  1 +
>   .../syscalls/epoll_pwait/epoll_pwait06.c      | 86 +++++++++++++++++++
>   3 files changed, 88 insertions(+)
>   create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index e7bc7b27b..2a968099a 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -192,6 +192,7 @@ epoll_pwait02 epoll_pwait02
>   epoll_pwait03 epoll_pwait03
>   epoll_pwait04 epoll_pwait04
>   epoll_pwait05 epoll_pwait05
> +epoll_pwait06 epoll_pwait06
>   
>   eventfd01 eventfd01
>   eventfd02 eventfd02
> diff --git a/testcases/kernel/syscalls/epoll_pwait/.gitignore b/testcases/kernel/syscalls/epoll_pwait/.gitignore
> index fafb2d782..81e77b8d0 100644
> --- a/testcases/kernel/syscalls/epoll_pwait/.gitignore
> +++ b/testcases/kernel/syscalls/epoll_pwait/.gitignore
> @@ -3,3 +3,4 @@ epoll_pwait02
>   epoll_pwait03
>   epoll_pwait04
>   epoll_pwait05
> +epoll_pwait06
> diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c
> new file mode 100644
> index 000000000..487992744
> --- /dev/null
> +++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c
> @@ -0,0 +1,86 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2025 SUSE LLC <mdoucha@suse.cz>
> + */
> +
> +/*\
> + * Verify that various timeout values don't get misinterpreted as infinity
> + * by epoll_pwait() and epoll_pwait2()
It would be nice to give the reference of the commit which introduced 
the bug in the tst_test structure.
> + */
> +
> +#include <sys/epoll.h>

#include "tst_epoll.h" instead, since we are already including 
"sys/epoll.h" while including "epoll_pwait_var.h".

and then we can use SAFE_EPOLL_* macros. Check below

> +
> +#include "tst_test.h"
> +#include "tst_timer.h"
> +#include "epoll_pwait_var.h"
> +
> +static int efd;
> +
> +static void run(void)
> +{
> +	struct timespec timeout = {};
> +	struct epoll_event e = {};
> +	int ret;
> +
> +	e.events = EPOLLIN;
> +
> +	TST_FD_FOREACH(fd_in) {
> +		/* File descriptor types not supported by epoll */
> +		switch (fd_in.type) {
> +		case TST_FD_FILE:
> +		case TST_FD_PATH:
> +		case TST_FD_DIR:
> +		case TST_FD_DEV_ZERO:
> +		case TST_FD_PROC_MAPS:
> +		case TST_FD_FSOPEN:
> +		case TST_FD_FSPICK:
> +		case TST_FD_OPEN_TREE:
> +		case TST_FD_MEMFD:
> +		case TST_FD_MEMFD_SECRET:
> +			continue;
> +		default:
> +			break;
> +		}
> +
> +		tst_res(TINFO, "Testing %s", tst_fd_desc(&fd_in));
> +		timeout.tv_nsec = 1000000000;
> +		ret = epoll_ctl(efd, EPOLL_CTL_ADD, fd_in.fd, &e);
> +
> +		if (ret)
> +			tst_brk(TBROK | TERRNO, "epoll_ctl(EPOLL_CTL_ADD)");
SAFE_EPOLL_CTL()
> +
> +		do {
> +			alarm(1);
> +			timeout.tv_nsec /= 10;
> +			do_epoll_pwait(efd, &e, 1, &timeout, NULL);
> +			alarm(0);
What about adding a TINFO here? It should be shown around 10 times, but 
eventually we would have some debugging data on console to use just in 
case the test stuck.
> +		} while (timeout.tv_nsec);
> +
> +		if (epoll_ctl(efd, EPOLL_CTL_DEL, fd_in.fd, &e))
> +			tst_brk(TBROK | TERRNO, "epoll_ctl(EPOLL_CTL_DEL)");
SAFE_EPOLL_CTL()
> +	}
> +
> +	tst_res(TPASS, "Timeout works correctly");
> +}
> +
> +static void setup(void)
> +{
> +	epoll_pwait_init();
> +	efd = epoll_create(1);
SAFE_EPOLL_CREATE1()
> +
> +	if (efd == -1)
> +		tst_brk(TBROK | TERRNO, "epoll_create()");
> +}
> +
> +static void cleanup(void)
> +{
> +	if (efd > 0)
> +		SAFE_CLOSE(efd);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_variants = TEST_VARIANTS,
It's worth to add a timeout for the test, since it's a test which is 
testing timeout limits.
> +};

Also we might move the run() inside a process and check if it eventually 
gets killed from the parent due to SIGALARM and not other signals.

- Andrea



More information about the ltp mailing list