From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/2] syscalls/pidfd_open
Date: Tue, 21 Jan 2020 16:39:28 +0100 [thread overview]
Message-ID: <20200121153928.GA12370@rei> (raw)
In-Reply-To: <4dd4dabd2cd574dc2657c5926e8e3d1a0c8a8ae6.1579259595.git.viresh.kumar@linaro.org>
Hi!
> diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c
> new file mode 100644
> index 000000000000..b67393bcafa2
> --- /dev/null
> +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c
> @@ -0,0 +1,68 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
> + *
> + * Description:
> + * This program opens the PID file descriptor of the child process created with
> + * fork(). It then uses poll to monitor the file descriptor for process exit, as
> + * indicated by an EPOLLIN event.
> + */
> +#include <poll.h>
> +#include <sys/types.h>
> +#include <sys/syscall.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +#include "tst_test.h"
> +#include "lapi/pidfd_open.h"
> +#include "lapi/syscalls.h"
> +
> +static void run(void)
> +{
> + struct pollfd pollfd;
> + int p_id, fd, ready;
> +
> + TEST(fork());
> +
> + if (TST_RET == -1) {
> + tst_res(TFAIL, "fork() Failed");
> + tst_res(TBROK, "unable to continue");
> + }
We do have SAFE_FORK() make use of that one instead.
> + if (TST_RET == 0) {
> + /* child */
> + usleep(1000);
This is inherently racy, the process should not exit until the parent
has called pidfd_open().
We do have a checkpoints in the test library that can synchronize
between processes, generally it should look like:
child:
checkpoint_wait()
exit()
parent:
pidfd_open()
checkpoint_wake()
> + exit(EXIT_SUCCESS);
> + } else {
> + /* parent */
> + p_id = TST_RET;
> +
> + TEST(pidfd_open(p_id, 0));
> +
> + fd = TST_RET;
> + if (fd == -1) {
> + tst_res(TFAIL, "Cannot retrieve file descriptor to the child process");
^
tst_res(TFAIL | TTERRNO, "pidfd_open() failed");
> + return;
> + }
> +
> + pollfd.fd = fd;
> + pollfd.events = POLLIN;
> +
> + ready = poll(&pollfd, 1, -1);
> + if (ready == -1) {
> + tst_res(TFAIL, "poll() Failed");
> + tst_res(TBROK, "unable to continue");
There is absolutely no need to print two messages on a failure, so this
should just be tst_brk(TBROK | TERRNO, "poll() failed");
Also note that tst_brk() _EXITS_ the test, which is what you want here.
> + }
> +
> + printf("Events (0x%x): POLLIN is %sset\n", pollfd.revents,
> + (pollfd.revents & POLLIN) ? "" : "not ");
No printf in tests, use tst_res(TINFO, ...) instead.
Also we should check here that we got the event and that the child is
dead at this point, or something along these lines.
There does not seem to be single TPASS in this tests, which itself will
report that the test is broken when it's executed.
> + SAFE_CLOSE(fd);
> + }
> +}
> +
> +static struct tst_test test = {
> + .min_kver = "5.3",
> + .test_all = run,
> +};
And we are also missing third test here, that checks various error
condigitions such as flags != 0, invalid pid, etc.
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2020-01-21 15:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-17 11:15 [LTP] [PATCH 1/2] Add Syscall numbers for pidfd_open Viresh Kumar
2020-01-17 11:15 ` [LTP] [PATCH 2/2] syscalls/pidfd_open Viresh Kumar
2020-01-21 15:39 ` Cyril Hrubis [this message]
2020-01-22 5:12 ` Viresh Kumar
2020-01-22 8:36 ` Viresh Kumar
2020-01-23 14:52 ` 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=20200121153928.GA12370@rei \
--to=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