Linux Test Project
 help / color / mirror / Atom feed
From: "xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH 2/2] syscalls/pidfd_open04: Add new test with PIDFD_NONBLOCK flag
Date: Thu, 10 Feb 2022 01:49:29 +0000	[thread overview]
Message-ID: <62046F52.7000403@fujitsu.com> (raw)
In-Reply-To: <YgPGA4oTD65hw69t@rei>

Hi Cyril
> Hi!
>> diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
>> new file mode 100644
>> index 000000000..436351f23
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
>> @@ -0,0 +1,78 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
>> + * Author: Yang Xu<xuyang2018.jy@fujitsu.com>
>> + */
>> +
>> +/*\
>> + * [Description]
>> + *
>> + * Verify that the PIDFD_NONBLOCK flag works with pidfd_open() and
>> + * that waitid() with a non-blocking pidfd returns EAGAIN.
>> + */
>> +
>> +#include<unistd.h>
>> +#include<fcntl.h>
>> +#include<sys/wait.h>
>> +#include "tst_test.h"
>> +#include "lapi/pidfd_open.h"
>> +
>> +#ifndef PIDFD_NONBLOCK
>> +#define PIDFD_NONBLOCK O_NONBLOCK
>> +#endif
>> +
>> +#ifndef P_PIDFD
>> +#define P_PIDFD  3
>> +#endif
>> +
>> +static void run(void)
>> +{
>> +	int flag, pid, pidfd;
>> +	siginfo_t info;
>> +
>> +	pid = SAFE_FORK();
>> +	if (!pid)
>> +		pause();
>> +
>> +	TST_EXP_PID_SILENT(pidfd_open(pid, PIDFD_NONBLOCK),
>> +				"pidfd_open(%d,  PIDFD_NONBLOCK)", pid);
>
> Here as well FD_SILENT();
Yes.
>
>> +	pidfd = TST_RET;
>> +	flag = fcntl(pidfd, F_GETFL);
>> +	if (flag == -1)
>> +		tst_brk(TFAIL | TERRNO, "fcntl(F_GETFL) failed");
>> +
>> +	if (!(flag&  O_NONBLOCK))
>> +		tst_brk(TFAIL, "pidfd_open(%d, O_NONBLOCK) didn't set O_NONBLOCK flag", pid);
>> +
>> +	tst_res(TPASS, "pidfd_open(%d, O_NONBLOCK) sets O_NONBLOCK flag", pid);
>> +
>> +	TST_EXP_FAIL(waitid(P_PIDFD, pidfd,&info, WEXITED), EAGAIN,
>> +			"waitid(P_PIDFD,...,WEXITED)");
>> +
>> +	SAFE_KILL(pid, SIGTERM);
>> +	SAFE_WAIT(NULL);
>> +	SAFE_CLOSE(pidfd);
>
> I guess that we can also test that the waitid() succeds now, right?
Yes, we can use TST_RETRY_FUNC(waitid(P_PIDFD, pidfd, &info, WEXITED), 
TST_RETVAL_EQ0) in here.

Best Regards
Yang Xu
>
>> +}
>> +
>> +static void setup(void)
>> +{
>> +	pidfd_open_supported();
>> +
>> +	TEST(pidfd_open(getpid(), PIDFD_NONBLOCK));
>> +	if (TST_RET == -1) {
>> +		if (TST_ERR == EINVAL) {
>> +			tst_brk(TCONF, "PIDFD_NONBLOCK was supported since linux 5.10");
>> +			return;
>> +		}
>> +		tst_brk(TFAIL | TTERRNO,
>> +			"pidfd_open(getpid(),PIDFD_NONBLOCK) failed unexpectedly");
>> +	}
>> +}
>> +
>> +static struct tst_test test = {
>> +	.needs_root = 1,
>> +	.forks_child = 1,
>> +	.setup = setup,
>> +	.test_all = run,
>> +};
>

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

  reply	other threads:[~2022-02-10  1:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09  9:42 [LTP] [PATCH 1/2] syscalls/pidfd_open: Simplify code Yang Xu
2022-02-09  9:42 ` [LTP] [PATCH 2/2] syscalls/pidfd_open04: Add new test with PIDFD_NONBLOCK flag Yang Xu
2022-02-09 13:47   ` Cyril Hrubis
2022-02-10  1:49     ` xuyang2018.jy [this message]
2022-02-09 10:00 ` [LTP] [PATCH 1/2] syscalls/pidfd_open: Simplify code xuyang2018.jy
2022-02-09 13:23 ` Cyril Hrubis
2022-02-09 14:19 ` Petr Vorel
2022-02-10  1:50   ` xuyang2018.jy
2022-02-10  3:41   ` [LTP] [PATCH v2 " Yang Xu
2022-02-10  3:41     ` [LTP] [PATCH v2 2/2] syscalls/pidfd_open04: Add new test with PIDFD_NONBLOCK flag Yang Xu
2022-02-10 15:04       ` Cyril Hrubis
2022-02-11  2:00         ` xuyang2018.jy

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=62046F52.7000403@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --cc=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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