From: Matthew Bobrowski via ltp <ltp@lists.linux.it>
To: Petr Vorel <pvorel@suse.cz>
Cc: Jan Kara <jack@suse.cz>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 3/3] fanotify14: Use TST_EXP_FD_ERRNO()
Date: Wed, 7 Sep 2022 07:17:50 +0000 [thread overview]
Message-ID: <YxhFnmERyC1V381+@google.com> (raw)
In-Reply-To: <20220906092615.15116-4-pvorel@suse.cz>
On Tue, Sep 06, 2022 at 11:26:15AM +0200, Petr Vorel wrote:
> That greatly simplifies the code.
This looks OK to me, nice work!
Reviewed-by: Matthew Bobrowski <repnop@google.com>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> .../kernel/syscalls/fanotify/fanotify14.c | 118 +++++-------------
> 1 file changed, 33 insertions(+), 85 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify14.c b/testcases/kernel/syscalls/fanotify/fanotify14.c
> index aa4db586e..47d013c9f 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify14.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify14.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0
> /*
> * Copyright (c) 2018 Matthew Bobrowski. All Rights Reserved.
> + * Copyright (c) Linux Test Project, 2020-2022
> *
> * Started by Matthew Bobrowski <mbobrowski@mbobrowski.org>
> */
> @@ -48,6 +49,7 @@ static int fan_report_target_fid_unsupported;
> static struct test_case_t {
> unsigned int init_flags;
> unsigned int mark_flags;
> + /* zero mask expects to fail on fanotify_init() */
> unsigned long long mask;
> int expected_errno;
> } test_cases[] = {
> @@ -111,7 +113,6 @@ static struct test_case_t {
>
> static void do_test(unsigned int number)
> {
> - int ret;
> struct test_case_t *tc = &test_cases[number];
>
> if (fan_report_target_fid_unsupported && tc->init_flags & FAN_REPORT_TARGET_FID) {
> @@ -120,101 +121,48 @@ static void do_test(unsigned int number)
> return;
> }
>
> - fanotify_fd = fanotify_init(tc->init_flags, O_RDONLY);
> - if (fanotify_fd < 0) {
> - if (errno == tc->expected_errno) {
> - tst_res(TPASS,
> - "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) "
> - "failed with error %d as expected",
> - fanotify_fd,
> - tc->init_flags, tc->expected_errno);
> - return;
> - }
> - tst_brk(TBROK | TERRNO,
> - "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) failed",
> - fanotify_fd,
> - tc->init_flags);
> - }
> + TST_EXP_FD_ERRNO(fanotify_fd = fanotify_init(tc->init_flags, O_RDONLY),
> + !tc->mask && tc->expected_errno ? tc->expected_errno : 0);
>
> - /*
> - * A test case with a mask set to zero indicate that they've been
> - * specifically designed to test and fail on the fanotify_init()
> - * system call.
> - */
> - if (tc->mask == 0) {
> - tst_res(TFAIL,
> - "fanotify_fd=%d fanotify_init(%x, O_RDONLY) "
> - "unexpectedly succeeded when tests with mask 0 are "
> - "expected to fail when calling fanotify_init()",
> - fanotify_fd,
> - tc->init_flags);
> + if (fanotify_fd < 0)
> + return;
> +
> + if (!tc->mask)
> goto out;
> - }
>
> /* Set mark on non-dir only when expecting error ENOTDIR */
> const char *path = tc->expected_errno == ENOTDIR ? FILE1 : MNTPOINT;
>
> - ret = fanotify_mark(fanotify_fd, FAN_MARK_ADD | tc->mark_flags,
> - tc->mask, AT_FDCWD, path);
> - if (ret < 0) {
> - if (errno == tc->expected_errno) {
> - tst_res(TPASS,
> - "ret=%d, fanotify_mark(%d, FAN_MARK_ADD | %x, "
> - "%llx, AT_FDCWD, %s) failed with error %d "
> - "as expected",
> - ret,
> - fanotify_fd,
> - tc->mark_flags,
> - tc->mask,
> - path, tc->expected_errno);
> - /*
> - * ENOTDIR are errors for events/flags not allowed on a non-dir inode.
> - * Try to set an inode mark on a directory and it should succeed.
> - * Try to set directory events in filesystem mark mask on non-dir
> - * and it should succeed.
> - */
> - if (tc->expected_errno == ENOTDIR) {
> - SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags,
> - tc->mask, AT_FDCWD, MNTPOINT);
> - tst_res(TPASS,
> - "Adding an inode mark on directory did not fail with "
> - "ENOTDIR error as on non-dir inode");
> - }
> - if (tc->expected_errno == ENOTDIR &&
> - !(tc->mark_flags & FAN_MARK_ONLYDIR)) {
> - SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags |
> - FAN_MARK_FILESYSTEM, tc->mask,
> - AT_FDCWD, FILE1);
> - tst_res(TPASS,
> - "Adding a filesystem mark on non-dir did not fail with "
> - "ENOTDIR error as with an inode mark");
> - }
> + TST_EXP_FD_ERRNO(fanotify_mark(fanotify_fd, FAN_MARK_ADD | tc->mark_flags,
> + tc->mask, AT_FDCWD, path),
> + tc->expected_errno);
>
> - goto out;
> + /*
> + * ENOTDIR are errors for events/flags not allowed on a non-dir inode.
> + * Try to set an inode mark on a directory and it should succeed.
> + * Try to set directory events in filesystem mark mask on non-dir
> + * and it should succeed.
> + */
> + if (TST_PASS && tc->expected_errno == ENOTDIR) {
> + SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags,
> + tc->mask, AT_FDCWD, MNTPOINT);
> + tst_res(TPASS,
> + "Adding an inode mark on directory did not fail with "
> + "ENOTDIR error as on non-dir inode");
> +
> + if (!(tc->mark_flags & FAN_MARK_ONLYDIR)) {
> + SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags |
> + FAN_MARK_FILESYSTEM, tc->mask,
> + AT_FDCWD, FILE1);
> + tst_res(TPASS,
> + "Adding a filesystem mark on non-dir did not fail with "
> + "ENOTDIR error as with an inode mark");
> }
> - tst_brk(TBROK | TERRNO,
> - "ret=%d, fanotify_mark(%d, FAN_MARK_ADD | %x, %llx, "
> - "AT_FDCWD, %s) failed",
> - ret,
> - fanotify_fd,
> - tc->mark_flags,
> - tc->mask,
> - FILE1);
> }
>
> - tst_res(TFAIL,
> - "fanotify_fd=%d, ret=%d, fanotify_init(%x, O_RDONLY) and "
> - "fanotify_mark(%d, FAN_MARK_ADD | %x, %llx, AT_FDCWD, %s) did "
> - "not return any errors as expected",
> - fanotify_fd,
> - ret,
> - tc->init_flags,
> - fanotify_fd,
> - tc->mark_flags,
> - tc->mask,
> - FILE1);
> out:
> - SAFE_CLOSE(fanotify_fd);
> + if (fanotify_fd > 0)
> + SAFE_CLOSE(fanotify_fd);
> }
>
> static void do_setup(void)
> --
> 2.37.3
>
/M
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-09-07 7:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-06 9:26 [LTP] [PATCH 0/3] fanotify{14,20}: cleanup Petr Vorel
2022-09-06 9:26 ` [LTP] [PATCH 1/3] tst_test_macros: Add TST_EXP_FD_ERRNO Petr Vorel
2022-09-06 9:26 ` [LTP] [PATCH 2/3] fanotify20: Simplify code Petr Vorel
2022-09-06 9:55 ` Amir Goldstein
2022-09-06 15:54 ` Petr Vorel
2022-09-06 16:14 ` Petr Vorel
2022-09-07 7:05 ` Matthew Bobrowski via ltp
2022-09-07 10:49 ` Petr Vorel
2022-09-06 9:26 ` [LTP] [PATCH 3/3] fanotify14: Use TST_EXP_FD_ERRNO() Petr Vorel
2022-09-06 10:13 ` Amir Goldstein
2022-09-06 15:56 ` Petr Vorel
2022-09-07 7:17 ` Matthew Bobrowski via ltp [this message]
2022-09-07 7:24 ` [LTP] [PATCH 0/3] fanotify{14,20}: cleanup Matthew Bobrowski via ltp
2022-09-07 11:05 ` Petr Vorel
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=YxhFnmERyC1V381+@google.com \
--to=ltp@lists.linux.it \
--cc=jack@suse.cz \
--cc=pvorel@suse.cz \
--cc=repnop@google.com \
/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;
as well as URLs for NNTP newsgroup(s).