Linux Test Project
 help / color / mirror / Atom feed
From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: "Cyril Hrubis" <chrubis@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 5/8] syscalls: Add epoll_wait10
Date: Tue, 28 Apr 2026 07:34:59 +0000	[thread overview]
Message-ID: <69f06327.050a0220.2201aa.058f@mx.google.com> (raw)
In-Reply-To: <20260423120309.18049-6-chrubis@suse.cz>

Hi Cyril,

> Functional test for EPOLLPRI using /proc/mounts that produces POLLPRI
> when a filesystem is mounted/umounted.
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  runtest/syscalls                              |   1 +
>  .../kernel/syscalls/epoll_wait/.gitignore     |   1 +
>  .../kernel/syscalls/epoll_wait/epoll_wait10.c | 107 ++++++++++++++++++
>  3 files changed, 109 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait10.c
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index b302935d5..3fd61b814 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -198,6 +198,7 @@ epoll_wait06 epoll_wait06
>  epoll_wait07 epoll_wait07
>  epoll_wait08 epoll_wait08
>  epoll_wait09 epoll_wait09
> +epoll_wait10 epoll_wait10
>  
>  epoll_pwait01 epoll_pwait01
>  epoll_pwait02 epoll_pwait02
> diff --git a/testcases/kernel/syscalls/epoll_wait/.gitignore b/testcases/kernel/syscalls/epoll_wait/.gitignore
> index f32ec535b..30139375d 100644
> --- a/testcases/kernel/syscalls/epoll_wait/.gitignore
> +++ b/testcases/kernel/syscalls/epoll_wait/.gitignore
> @@ -7,3 +7,4 @@ epoll_wait06
>  epoll_wait07
>  epoll_wait08
>  epoll_wait09
> +epoll_wait10
> diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait10.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait10.c
> new file mode 100644
> index 000000000..82cd8b15e
> --- /dev/null
> +++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait10.c
> @@ -0,0 +1,107 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
> + */
> +
> +/*\
> + * Verify that epoll_wait with EPOLLPRI detects changes to /proc/mounts.
> + *
> + * The kernel generates a poll notification (POLLPRI/EPOLLERR) on
> + * /proc/mounts whenever the mount namespace changes. This test verifies
> + * that epoll can observe these notifications.
> + *
> + * [Algorithm]
> + *
> + * - Open /proc/mounts and register it with an epoll instance for EPOLLPRI.
> + * - Fork a child that mounts and then unmounts a tmpfs filesystem, using
> + *   checkpoints to synchronize with the parent.
> + * - After each mount namespace change the parent calls epoll_wait and verifies
> + *   it returns an event.
> + *
> + * Needs root to call mount/umount.
> + */
> +
> +#include <sys/epoll.h>
> +
> +#include "tst_test.h"
> +#include "tst_epoll.h"
> +
> +#define MNTPOINT "mnt_epoll"
> +
> +static int efd = -1, mnt_fd = -1;
> +
> +static void setup(void)
> +{
> +	SAFE_MKDIR(MNTPOINT, 0777);
> +
> +	mnt_fd = SAFE_OPEN("/proc/mounts", O_RDONLY);
> +
> +	efd = SAFE_EPOLL_CREATE1(0);
> +
> +	struct epoll_event ev = {
> +		.events = EPOLLPRI,
> +		.data.fd = mnt_fd,
> +	};
> +
> +	SAFE_EPOLL_CTL(efd, EPOLL_CTL_ADD, mnt_fd, &ev);
> +}
> +
> +static void check_epoll_event(const char *desc)
> +{
> +	struct epoll_event ret_ev;
> +	char buf[1024];
> +
> +	TEST(epoll_wait(efd, &ret_ev, 1, 1000));
> +	if (TST_RET < 1) {
> +		tst_res(TFAIL | TTERRNO,
> +			"epoll_wait() after %s returned %li", desc, TST_RET);

return; here.

> +	} else if (!(ret_ev.events & (EPOLLPRI | EPOLLERR))) {
> +		tst_res(TFAIL,
> +			"after %s: events %x, expected EPOLLPRI or EPOLLERR",
> +			desc, ret_ev.events);
> +	} else {
> +		tst_res(TPASS,
> +			"epoll_wait() reported event after %s", desc);
> +	}

And here I would use TST_EXP_* instead. But feel free to ignore.

> +
> +	/* Re-read /proc/self/mounts to clear the notification */
> +	SAFE_LSEEK(mnt_fd, 0, SEEK_SET);
> +	while (SAFE_READ(0, mnt_fd, buf, sizeof(buf)) > 0)
> +		;
> +}
> +
> +static void run(void)
> +{
> +	if (!SAFE_FORK()) {
> +		SAFE_MOUNT("none", MNTPOINT, "tmpfs", 0, NULL);
> +		TST_CHECKPOINT_WAKE_AND_WAIT(0);
> +		SAFE_UMOUNT(MNTPOINT);
> +		TST_CHECKPOINT_WAKE(0);
> +		exit(0);
> +	}
> +
> +	TST_CHECKPOINT_WAIT(0);
> +	check_epoll_event("mount");
> +
> +	TST_CHECKPOINT_WAKE_AND_WAIT(0);
> +	check_epoll_event("umount");
> +}
> +
> +static void cleanup(void)
> +{
> +	if (efd != -1)
> +		SAFE_CLOSE(efd);
> +
> +	if (mnt_fd != -1)
> +		SAFE_CLOSE(mnt_fd);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_root = 1,
> +	.forks_child = 1,
> +	.needs_checkpoints = 1,
> +	.needs_tmpdir = 1,
> +};
> -- 
> 2.52.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

Besides these observations:

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

  reply	other threads:[~2026-04-28  7:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23 12:03 [LTP] [PATCH v2 0/8] Add more epoll tests Cyril Hrubis
2026-04-23 12:03 ` [LTP] [PATCH v2 1/8] syscalls: Add epoll_create03 Cyril Hrubis
2026-04-23 12:41   ` Petr Vorel
2026-04-23 13:43   ` [LTP] " linuxtestproject.agent
2026-04-28  7:25   ` [LTP] [PATCH v2 1/8] " Andrea Cervesato via ltp
2026-04-23 12:03 ` [LTP] [PATCH v2 2/8] syscalls: Add epoll_wait08 Cyril Hrubis
2026-04-28  7:38   ` Andrea Cervesato via ltp
2026-04-23 12:03 ` [LTP] [PATCH v2 3/8] syscalls: Add epoll_wait09 Cyril Hrubis
2026-04-28  7:36   ` Andrea Cervesato via ltp
2026-04-23 12:03 ` [LTP] [PATCH v2 4/8] syscalls: Add epoll_ctl06 Cyril Hrubis
2026-04-27  2:26   ` Li Wang
2026-04-23 12:03 ` [LTP] [PATCH v2 5/8] syscalls: Add epoll_wait10 Cyril Hrubis
2026-04-28  7:34   ` Andrea Cervesato via ltp [this message]
2026-04-23 12:03 ` [LTP] [PATCH v2 6/8] syscalls: Add epoll_wait11 Cyril Hrubis
2026-04-28  7:54   ` Andrea Cervesato via ltp
2026-04-23 12:03 ` [LTP] [PATCH v2 7/8] syscalls: Add epoll_wait12 Cyril Hrubis
2026-04-28  7:31   ` Andrea Cervesato via ltp
2026-04-23 12:03 ` [LTP] [PATCH v2 8/8] syscalls: Remove old epoll-ltp test Cyril Hrubis
2026-05-07 13:20   ` Andrea Cervesato via ltp
2026-04-28  7:42 ` [LTP] [PATCH v2 0/8] Add more epoll tests Andrea Cervesato via ltp
2026-04-28  9:43   ` Cyril Hrubis

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=69f06327.050a0220.2201aa.058f@mx.google.com \
    --to=ltp@lists.linux.it \
    --cc=andrea.cervesato@suse.com \
    --cc=chrubis@suse.cz \
    /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