From: Joshua Watt <jpewhacker@gmail.com>
To: yocto@lists.yoctoproject.org
Cc: Joshua Watt <JPEWhacker@gmail.com>
Subject: [ptest-runner][PATCH 2/4] Recreate pipe for each test
Date: Mon, 17 Jul 2023 08:28:29 -0600 [thread overview]
Message-ID: <20230717142831.1634172-3-JPEWhacker@gmail.com> (raw)
In-Reply-To: <20230717142831.1634172-1-JPEWhacker@gmail.com>
The write end of the pipe has to be closed by ptest-runner to make sure
that it will get EOF when the child process is done with it. This means
that a new pipe needs to be opened for each child so that the write ends
can be passed to it.
Fixes the problem where tests would be reported with no output when
ptest-runner was told to run multiple tests because they were passed
invalid stdin/stderr pipes.
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
utils.c | 45 ++++++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/utils.c b/utils.c
index 6a6e848..c1188dd 100644
--- a/utils.c
+++ b/utils.c
@@ -61,7 +61,6 @@ static struct {
unsigned int timeout;
int timeouted;
- pid_t pid;
int padding1;
} _child_reader;
@@ -414,8 +413,8 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
char stime[GET_STIME_BUF_SIZE];
pid_t child;
- int pipefd_stdout[2];
- int pipefd_stderr[2];
+ int pipefd_stdout[2] = {-1, -1};
+ int pipefd_stderr[2] = {-1, -1};
time_t sttime, entime;
time_t duration;
int slave;
@@ -429,28 +428,22 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
do
{
- if ((rc = pipe2(pipefd_stdout, 0)) == -1)
- break;
-
- if ((rc = pipe2(pipefd_stderr, 0)) == -1) {
- close(pipefd_stdout[0]);
- close(pipefd_stdout[1]);
- break;
- }
-
if (isatty(0) && ioctl(0, TIOCNOTTY) == -1) {
fprintf(fp, "ERROR: Unable to detach from controlling tty, %s\n", strerror(errno));
}
- _child_reader.fds[0] = pipefd_stdout[0];
- _child_reader.fds[1] = pipefd_stderr[0];
- _child_reader.fps[0] = fp;
- _child_reader.fps[1] = fp_stderr;
- _child_reader.timeout = opts.timeout;
- _child_reader.timeouted = 0;
fprintf(fp, "START: %s\n", progname);
PTEST_LIST_ITERATE_START(head, p)
+ if ((rc = pipe2(pipefd_stdout, 0)) == -1)
+ break;
+
+ if ((rc = pipe2(pipefd_stderr, 0)) == -1) {
+ close(pipefd_stdout[0]);
+ close(pipefd_stdout[1]);
+ break;
+ }
+
char *ptest_dir = strdup(p->run_ptest);
if (ptest_dir == NULL) {
rc = -1;
@@ -497,7 +490,12 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
do_close(&pipefd_stdout[1]);
do_close(&pipefd_stderr[1]);
- _child_reader.pid = child;
+ _child_reader.fds[0] = pipefd_stdout[0];
+ _child_reader.fds[1] = pipefd_stderr[0];
+ _child_reader.fps[0] = fp;
+ _child_reader.fps[1] = fp_stderr;
+ _child_reader.timeout = opts.timeout;
+ _child_reader.timeouted = 0;
if (setpgid(child, pgid) == -1) {
fprintf(fp, "ERROR: setpgid() failed, %s\n", strerror(errno));
}
@@ -543,7 +541,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
* the pipes until EOF to make
* sure we get all the output
*/
- kill(-_child_reader.pid, SIGKILL);
+ kill(-child, SIGKILL);
_child_reader.timeouted = 1;
}
@@ -585,7 +583,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
* dead
*/
if (!_child_reader.timeouted) {
- kill(-_child_reader.pid, SIGKILL);
+ kill(-child, SIGKILL);
}
status = wait_child(child);
@@ -607,6 +605,11 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, entime));
}
free(ptest_dir);
+ do_close(&pipefd_stdout[0]);
+ do_close(&pipefd_stdout[1]);
+ do_close(&pipefd_stderr[0]);
+ do_close(&pipefd_stderr[1]);
+
PTEST_LIST_ITERATE_END
fprintf(fp, "STOP: %s\n", progname);
--
2.33.0
next prev parent reply other threads:[~2023-07-17 14:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-17 14:28 [ptest-runner][PATCH 0/4] Stop running ptests in parallel Joshua Watt
2023-07-17 14:28 ` [ptest-runner][PATCH 1/4] Revert "runner: Correctly handle running parallel tests" Joshua Watt
2023-07-17 14:28 ` Joshua Watt [this message]
2023-07-17 14:28 ` [ptest-runner][PATCH 3/4] Report if child dies from a signal Joshua Watt
2023-07-17 14:28 ` [ptest-runner][PATCH 4/4] Change test timeout to be total elapsed time Joshua Watt
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=20230717142831.1634172-3-JPEWhacker@gmail.com \
--to=jpewhacker@gmail.com \
--cc=yocto@lists.yoctoproject.org \
/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