From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/pipe13: Add regression test for pipe to wake up all readers
Date: Mon, 24 Feb 2020 13:58:02 +0100 [thread overview]
Message-ID: <20200224125802.GA30073@rei.lan> (raw)
In-Reply-To: <1582537946-22098-1-git-send-email-xuyang2018.jy@cn.fujitsu.com>
Hi!
> +static void verify_pipe(void)
> +{
> + int fds[2];
> + int status1, status2;
> + pid_t p1, p2;
> + int ret;
> +
> + SAFE_PIPE(fds);
> +
> + p1 = SAFE_FORK();
> + if (p1 == 0) {
> + SAFE_CLOSE(fds[1]);
> + SAFE_READ(0, fds[0], &status1, sizeof(status1));
^
Why status1 here?
can't we just pass a dummy
char buf; and size 1 here?
It's not being written to
anyways.
> + exit(0);
> + }
> + p2 = SAFE_FORK();
> + if (p2 == 0) {
> + SAFE_CLOSE(fds[1]);
> + SAFE_READ(0, fds[0], &status2, sizeof(status2));
^
Here as well.
> + exit(0);
> + }
> +
> + sleep(1);
This sleep here has to be replaced by a proper synchronization given
that it's here to make sure both of the readers sleep on the pipe we
should:
* Use checkpoints to make sure both of the children have managed
to get before the SAFE_READ().
* The the parent should use the TST_PROCESS_STATE_WAIT() to make sure
both of the chidlren are sleeping
> + SAFE_CLOSE(fds[1]);
> +
> + SAFE_WAITPID(p1, &status1, 0);
> + ret = waitpid(p2, &status2, WNOHANG);
We should just use waitpid with -1 as a pid here and WNOHANG twice,
because if one of the children hangs it's not guaranteed in any way
which one would that be.
> + if (ret == p2) {
> + tst_res(TPASS, "pipe wakes up everybody when last write closes");
> + } else {
> + tst_res(TFAIL, "pipe doesn't wake up every body when last write closes");
> + SAFE_KILL(p2, SIGKILL);
> + SAFE_WAIT(&status2);
> + }
> +}
> +
> +static struct tst_test test = {
> + .test_all = verify_pipe,
> + .forks_child = 1,
> + .tags = (const struct tst_tag[]) {
> + {"linux-git", "6551d5c56eb"},
> + {}
> + }
> +};
> --
> 2.18.0
>
>
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2020-02-24 12:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 9:52 [LTP] [PATCH] syscalls/pipe13: Add regression test for pipe to wake up all readers Yang Xu
2020-02-24 12:58 ` Cyril Hrubis [this message]
2020-02-25 9:07 ` Yang Xu
2020-02-25 10:28 ` Cyril Hrubis
2020-02-26 1:27 ` Yang Xu
2020-02-26 3:06 ` [LTP] [PATCH v3] " Yang Xu
2020-02-26 13:56 ` Cyril Hrubis
2020-02-25 9:57 ` [LTP] [PATCH v2] " Yang Xu
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=20200224125802.GA30073@rei.lan \
--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