[PATCH 6.9 003/374] perf test: Use a single fd for the child process out/err

Greg Kroah-Hartman
2024-06-06T14:08:15Z

From: Ian Rogers <irogers@google.com>

[ Upstream commit e120f7091a25460a19967380725558c36bca7c6c ]

Switch from dumping err then out, to a single file descriptor for both
of them. This allows the err and output to be correctly interleaved in
verbose output.

Fixes: b482f5f8e0168f1e ("perf tests: Add option to run tests in parallel")
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Disha Goel <disgoel@linux.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Link: https://lore.kernel.org/r/20240301074639.2260708-3-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
tools/perf/tests/builtin-test.c | 37 ++++++---------------------------
1 file changed, 6 insertions(+), 31 deletions(-)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index d13ee7683d9d8..e05b370b1e2b1 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -274,11 +274,8 @@ static int finish_test(struct child_test *child_test, int width)
struct test_suite *t = child_test->test;
int i = child_test->test_num;
int subi = child_test->subtest;
- int out = child_test->process.out;
int err = child_test->process.err;
- bool out_done = out <= 0;
bool err_done = err <= 0;
- struct strbuf out_output = STRBUF_INIT;
struct strbuf err_output = STRBUF_INIT;
int ret;

@@ -290,11 +287,9 @@ static int finish_test(struct child_test *child_test, int width)
pr_info("%3d: %-*s:\n", i + 1, width, test_description(t, -1));

/*
- * Busy loop reading from the child's stdout and stderr that are set to
- * be non-blocking until EOF.
+ * Busy loop reading from the child's stdout/stderr that are set to be
+ * non-blocking until EOF.
*/
- if (!out_done)
- fcntl(out, F_SETFL, O_NONBLOCK);
if (!err_done)
fcntl(err, F_SETFL, O_NONBLOCK);
if (verbose > 1) {
@@ -303,11 +298,8 @@ static int finish_test(struct child_test *child_test, int width)
else
pr_info("%3d: %s:\n", i + 1, test_description(t, -1));
}
- while (!out_done || !err_done) {
- struct pollfd pfds[2] = {
- { .fd = out,
- .events = POLLIN | POLLERR | POLLHUP | POLLNVAL,
- },
+ while (!err_done) {
+ struct pollfd pfds[1] = {
{ .fd = err,
.events = POLLIN | POLLERR | POLLHUP | POLLNVAL,
},
@@ -317,21 +309,7 @@ static int finish_test(struct child_test *child_test, int width)

/* Poll to avoid excessive spinning, timeout set for 1000ms. */
poll(pfds, ARRAY_SIZE(pfds), /*timeout=*/1000);
- if (!out_done && pfds[0].revents) {
- errno = 0;
- len = read(out, buf, sizeof(buf) - 1);
-
- if (len <= 0) {
- out_done = errno != EAGAIN;
- } else {
- buf[len] = '\0';
- if (verbose > 1)
- fprintf(stdout, "%s", buf);
- else
- strbuf_addstr(&out_output, buf);
- }
- }
- if (!err_done && pfds[1].revents) {
+ if (!err_done && pfds[0].revents) {
errno = 0;
len = read(err, buf, sizeof(buf) - 1);

@@ -354,14 +332,10 @@ static int finish_test(struct child_test *child_test, int width)
pr_info("%3d.%1d: %s:\n", i + 1, subi + 1, test_description(t, subi));
else
pr_info("%3d: %s:\n", i + 1, test_description(t, -1));
- fprintf(stdout, "%s", out_output.buf);
fprintf(stderr, "%s", err_output.buf);
}
- strbuf_release(&out_output);
strbuf_release(&err_output);
print_test_result(t, i, subi, ret, width);
- if (out > 0)
- close(out);
if (err > 0)
close(err);
return 0;
@@ -394,6 +368,7 @@ static int start_test(struct test_suite *test, int i, int subi, struct child_tes
(*child)->process.no_stdout = 1;
(*child)->process.no_stderr = 1;
} else {
+ (*child)->process.stdout_to_stderr = 1;
(*child)->process.out = -1;
(*child)->process.err = -1;
}
--
2.43.0