[LTP] [PATCH 5/5] fanotify21: Test reporting fd open errors with FAN_REPORT_FD_ERROR

Petr Vorel pvorel@suse.cz
Fri Jan 24 09:09:03 CET 2025


Hi Amir,

> Expect to get -EROFS as event->fd.
> Expect to get -ESRCH instead of FAN_NOPIDFD.

Reviewed-by: Petr Vorel <pvorel@suse.cz>
LGTM.

> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  .../kernel/syscalls/fanotify/fanotify21.c     | 61 ++++++++++++++++---
>  1 file changed, 51 insertions(+), 10 deletions(-)

> diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
> index 4324019fa..8765767f2 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify21.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
> @@ -57,7 +57,7 @@ static struct test_case_t {
>  	{
>  		"return invalid pidfd for event created by terminated child",
>  		1,
> -		FAN_NOPIDFD,
> +		1,
>  		0,
>  	},
>  	{
> @@ -72,6 +72,8 @@ static int fanotify_fd;
>  static char event_buf[BUF_SZ];
>  static struct pidfd_fdinfo_t *self_pidfd_fdinfo;

> +static int fd_error_unsupported;
> +
>  static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
>  {
>  	char *fdinfo_path;
> @@ -121,6 +123,15 @@ static void do_fork(void)
>  static void do_setup(void)
>  {
>  	int pidfd;
> +	int init_flags = FAN_REPORT_PIDFD;
> +
> +	if (tst_variant) {
> +		fanotify_fd = -1;
> +		fd_error_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_FD_ERROR, ".");
> +		if (fd_error_unsupported)
> +			return;
> +		init_flags |= FAN_REPORT_FD_ERROR;
> +	}

>  	SAFE_TOUCH(TEST_FILE, 0666, NULL);

> @@ -132,7 +143,7 @@ static void do_setup(void)
>  	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_PIDFD,
>  						    TEST_FILE);

> -	fanotify_fd = SAFE_FANOTIFY_INIT(FAN_REPORT_PIDFD, O_RDWR);
> +	fanotify_fd = SAFE_FANOTIFY_INIT(init_flags, O_RDWR);
>  	SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD, FAN_OPEN, AT_FDCWD,
>  			   TEST_FILE);

> @@ -150,8 +161,17 @@ static void do_test(unsigned int num)
>  {
>  	int i = 0, len;
>  	struct test_case_t *tc = &test_cases[num];
> +	int nopidfd_err = tc->want_pidfd_err ?
> +			  (tst_variant ? -ESRCH : FAN_NOPIDFD) : 0;
> +	int fd_err = (tc->remount_ro && tst_variant) ? -EROFS : 0;

> -	tst_res(TINFO, "Test #%d: %s", num, tc->name);
> +	tst_res(TINFO, "Test #%d.%d: %s %s", num, tst_variant, tc->name,
> +			tst_variant ? "(FAN_REPORT_FD_ERROR)" : "");
Thanks for printing also tst_variant, it helps reviewing the test
(number of the results increased from 20 to 110).

...

Kind regards,
Petr


More information about the ltp mailing list