Linux Test Project
 help / color / mirror / Atom feed
From: "xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com>
To: Petr Vorel <pvorel@suse.cz>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH 5/5] syscalls/pidfd_getfd02: add basic error test
Date: Fri, 18 Feb 2022 03:49:19 +0000	[thread overview]
Message-ID: <620F1768.7060100@fujitsu.com> (raw)
In-Reply-To: <Yg6oZLaYz6Dj1FY4@pevik>

Hi Petr
> Hi Xu,
>
> Reviewed-by: Petr Vorel<pvorel@suse.cz>
>
> Thanks! Few comments below, can be fixed before merge.
>
>> +++ b/testcases/kernel/syscalls/pidfd_getfd/.gitignore
>> @@ -1 +1,2 @@
>>   pidfd_getfd01
>> +pidfd_getfd02
> Again /pidfd_getfd02
>
>> diff --git a/testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd02.c b/testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd02.c
> ...
>> +/*\
>> + * [Description]
>> + *
>> + * Tests basic error handling of the pidfd_open syscall.
>> + *
>> + * - EBADF pidfd is not a valid PID file descriptor
>> + * - EBADF targetfd is not an open file descriptor in the process referred
>> + *   to by pidfd
>> + * - EINVAL flags is not 0
>> + * - ESRCH the process referred to by pidfd does not exist(it has terminated and
>> + *   been waited on))
>
> nit: add space and remove redundant bracket
>   * - ESRCH the process referred to by pidfd does not exist (it has terminated and
>   *   been waited on)
OK.
>
>> + * - EPERM the calling process doesn't have PTRACE_MODE_ATTACH_REALCREDS permissions
>> + *   over the process referred to by pidfd
>
> +1 (only ENFILE "The system-wide limit on the total number of open files has been
> reached." which is probably not worth of implementing).
> ...
>
>> +static void setup(void)
>> +{
>> +	struct passwd *pw;
>> +
>> +	pw = SAFE_GETPWNAM("nobody");
>> +	uid = pw->pw_uid;
>> +
>> +	pidfd_open_supported();
>> +	pidfd_getfd_supported();
> nit: I'd put these before SAFE_GETPWNAM().
OK.
>
>> +
>> +	TST_EXP_FD_SILENT(pidfd_open(getpid(), 0), "pidfd_open");
> If you wait for Cyril's patch adding auto stringification
> https://lore.kernel.org/ltp/20220217142730.19726-1-chrubis@suse.cz/
>
> you can use just:
> TST_EXP_FD_SILENT(pidfd_open(getpid(), 0));
>
> and get more info.
I will look Cyril's patch and wait.
>
>> +	if (!TST_PASS)
>> +		tst_brk(TFAIL | TTERRNO, "pidfd_open failed");
>
> @Cyril: would it be possible to to allow using also tst_brk() in macros in
> tst_test_macros.h?
>
Maybe can add SAFE_PIDFD_OPEN.
> Having TST_*_BRK() (i.e. TST_EXP_FD_SILENT_BRK()) looks too complicated
>
>> +	valid_pidfd = TST_RET;
>> +}
>> +
>> +static void run(unsigned int n)
>> +{
>> +	struct tcase *tc =&tcases[n];
>> +	int pid;
>> +
>> +	switch (tc->exp_errno) {
>> +	case EPERM:
>> +		pid = SAFE_FORK();
> SAFE_FORK() can be before switch.
>
>> +		if (!pid) {
>> +			SAFE_SETUID(uid);
>> +			TST_EXP_FAIL2(pidfd_getfd(valid_pidfd, tc->targetfd, tc->flags),
>> +				tc->exp_errno, "pidfd_getfd(%d, %d, %d) with %s",
>> +				valid_pidfd, tc->targetfd, tc->flags, tc->name);
>> +			TST_CHECKPOINT_WAKE(0);
>> +			exit(0);
>> +		}
>> +		TST_CHECKPOINT_WAIT(0);
>> +		SAFE_WAIT(NULL);
>> +		return;
>> +	break;
>> +	case ESRCH:
>> +		pid = SAFE_FORK();
>> +		if (!pid) {
>> +			TST_CHECKPOINT_WAIT(0);
>> +			exit(0);
>> +		}
>> +		TST_EXP_FD_SILENT(pidfd_open(pid, 0), "pidfd_open");
>> +		*tc->pidfd = TST_RET;
>> +		TST_CHECKPOINT_WAKE(0);
>> +		SAFE_WAIT(NULL);
>> +	break;
>> +	default:
>> +	break;
>> +	};
>
> IMHO more readable would be instead of switch use if/else if or 2 functions.
>
Will try.

Best Regards
Yang Xu
>
> Kind regards,
> Petr
>
>> +
>> +	TST_EXP_FAIL2(pidfd_getfd(*tc->pidfd, tc->targetfd, tc->flags),
>> +		tc->exp_errno, "pidfd_getfd(%d, %d, %d) with %s",
>> +		*tc->pidfd, tc->targetfd, tc->flags, tc->name);
>> +}

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

  reply	other threads:[~2022-02-18  3:49 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-16 10:04 [LTP] [PATCH 1/5] kcmp.h: move it to ltp include/lapi directory Yang Xu
2022-02-16 10:04 ` [LTP] [PATCH 2/5] lapi/kcmp.h: Replace GPL with SPDX-License-Identifier Yang Xu
2022-02-16 14:05   ` Petr Vorel
2022-02-17 18:52   ` Petr Vorel
2022-02-18  2:13     ` xuyang2018.jy
2022-02-18  8:28       ` Petr Vorel
2022-02-16 10:04 ` [LTP] [PATCH 3/5] pidfd_getfd.h: add fallback Yang Xu
2022-02-16 14:09   ` Petr Vorel
2022-02-18  2:14     ` xuyang2018.jy
2022-02-16 10:04 ` [LTP] [PATCH 4/5] Add pidfd_getfd01 test Yang Xu
2022-02-17 19:20   ` Petr Vorel
2022-02-18  3:24     ` xuyang2018.jy
2022-02-18  7:02       ` Petr Vorel
2022-02-21 10:03         ` Richard Palethorpe
2022-02-21 12:42           ` Petr Vorel
2022-02-21 13:49             ` Richard Palethorpe
2022-02-18  8:57       ` Petr Vorel
2022-02-18  9:56         ` xuyang2018.jy
2022-02-18 10:15           ` Petr Vorel
2022-02-22  2:29             ` xuyang2018.jy
2022-02-17 19:28   ` Petr Vorel
2022-02-18  3:37     ` xuyang2018.jy
2022-02-18  6:59       ` Petr Vorel
2022-02-16 10:04 ` [LTP] [PATCH 5/5] syscalls/pidfd_getfd02: add basic error test Yang Xu
2022-02-17 19:56   ` Petr Vorel
2022-02-18  3:49     ` xuyang2018.jy [this message]
2022-02-18  6:50       ` Petr Vorel
2022-02-18  7:03         ` xuyang2018.jy
2022-02-18 10:58       ` Petr Vorel
2022-02-22  2:49         ` xuyang2018.jy
2022-02-16 14:02 ` [LTP] [PATCH 1/5] kcmp.h: move it to ltp include/lapi directory 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=620F1768.7060100@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@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