From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
James Clark <james.clark@linaro.org>,
Howard Chu <howardchu95@gmail.com>,
Athira Jajeev <atrajeev@linux.vnet.ibm.com>,
Michael Petlan <mpetlan@redhat.com>,
Veronika Molnarova <vmolnaro@redhat.com>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Thomas Richter <tmricht@linux.ibm.com>,
Ilya Leoshkevich <iii@linux.ibm.com>,
Colin Ian King <colin.i.king@gmail.com>,
Weilin Wang <weilin.wang@intel.com>,
Andi Kleen <ak@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v1 7/8] perf test: Run parallel tests in two passes
Date: Fri, 11 Oct 2024 00:35:58 -0700 [thread overview]
Message-ID: <20241011073559.431302-8-irogers@google.com> (raw)
In-Reply-To: <20241011073559.431302-1-irogers@google.com>
In pass 1 run all tests that succeed when run in parallel. In pass 2
sequentially run all remaining tests that are flagged as
"exclusive". Sequential and dont_fork tests keep to run in pass 1. Add
error handling to finish tests if starting a test fails.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/tests/builtin-test.c | 149 +++++++++++++++++++------------
tools/perf/tests/tests-scripts.c | 5 ++
tools/perf/tests/tests.h | 1 +
3 files changed, 96 insertions(+), 59 deletions(-)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 45a31376fdb0..fd6b50f4d145 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -239,7 +239,7 @@ static int run_test_child(struct child_process *process)
const int signals[] = {
SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGINT, SIGPIPE, SIGQUIT, SIGSEGV, SIGTERM,
};
- static struct child_test *child;
+ struct child_test *child = container_of(process, struct child_test, process);
int err;
err = sigsetjmp(run_test_jmp_buf, 1);
@@ -249,7 +249,6 @@ static int run_test_child(struct child_process *process)
goto err_out;
}
- child = container_of(process, struct child_test, process);
for (size_t i = 0; i < ARRAY_SIZE(signals); i++)
signal(signals[i], child_test_sig_handler);
@@ -302,19 +301,25 @@ static int print_test_result(struct test_suite *t, int i, int subtest, int resul
return 0;
}
-static int finish_test(struct child_test **child_tests, int running_test, int child_test_num,
- int width)
+static void finish_test(struct child_test **child_tests, int running_test, int child_test_num,
+ int width)
{
struct child_test *child_test = child_tests[running_test];
- struct test_suite *t = child_test->test;
- int i = child_test->test_num;
- int subi = child_test->subtest;
- int err = child_test->process.err;
+ struct test_suite *t;
+ int i, subi, err;
bool err_done = false;
struct strbuf err_output = STRBUF_INIT;
int last_tests_in_progress = -1;
int ret;
+ if (child_test == NULL) {
+ /* Test wasn't started. */
+ return;
+ }
+ t = child_test->test;
+ i = child_test->test_num;
+ subi = child_test->subtest;
+ err = child_test->process.err;
/*
* For test suites with subtests, display the suite name ahead of the
* sub test names.
@@ -344,6 +349,8 @@ static int finish_test(struct child_test **child_tests, int running_test, int ch
int tests_in_progress = running_test;
for (int y = running_test; y < child_test_num; y++) {
+ if (child_tests[y] == NULL)
+ continue;
if (check_if_command_finished(&child_tests[y]->process))
tests_in_progress++;
}
@@ -397,23 +404,32 @@ static int finish_test(struct child_test **child_tests, int running_test, int ch
print_test_result(t, i, subi, ret, width, /*remaining=*/0);
if (err > 0)
close(err);
- return 0;
+ zfree(&child_tests[running_test]);
}
static int start_test(struct test_suite *test, int i, int subi, struct child_test **child,
- int width)
+ int width, int pass)
{
int err;
*child = NULL;
if (dont_fork) {
- pr_debug("--- start ---\n");
- err = test_function(test, subi)(test, subi);
- pr_debug("---- end ----\n");
- print_test_result(test, i, subi, err, width, /*remaining=*/0);
+ if (pass == 1) {
+ pr_debug("--- start ---\n");
+ err = test_function(test, subi)(test, subi);
+ pr_debug("---- end ----\n");
+ print_test_result(test, i, subi, err, width, /*remaining=*/0);
+ }
+ return 0;
+ }
+ if (pass == 1 && !sequential && test->exclusive) {
+ /* When parallel, skip exclusive tests on the first pass. */
+ return 0;
+ }
+ if (pass != 1 && (sequential || !test->exclusive)) {
+ /* Sequential and non-exclusive tests were run on the first pass. */
return 0;
}
-
*child = zalloc(sizeof(**child));
if (!*child)
return -ENOMEM;
@@ -432,10 +448,14 @@ static int start_test(struct test_suite *test, int i, int subi, struct child_tes
(*child)->process.err = -1;
}
(*child)->process.no_exec_cmd = run_test_child;
- err = start_command(&(*child)->process);
- if (err || !sequential)
- return err;
- return finish_test(child, /*running_test=*/0, /*child_test_num=*/1, width);
+ if (sequential || pass == 2) {
+ err = start_command(&(*child)->process);
+ if (err)
+ return err;
+ finish_test(child, /*running_test=*/0, /*child_test_num=*/1, width);
+ return 0;
+ }
+ return start_command(&(*child)->process);
}
#define for_each_test(j, k, t) \
@@ -445,12 +465,11 @@ static int start_test(struct test_suite *test, int i, int subi, struct child_tes
static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
{
struct test_suite *t;
- unsigned int j, k;
- int i = 0;
int width = 0;
+ unsigned int j, k;
size_t num_tests = 0;
struct child_test **child_tests;
- int child_test_num = 0;
+ int err = 0;
for_each_test(j, k, t) {
int len = strlen(test_description(t, -1));
@@ -473,62 +492,73 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
if (!child_tests)
return -ENOMEM;
- for_each_test(j, k, t) {
- int curr = i++;
-
- if (!perf_test__matches(test_description(t, -1), curr, argc, argv)) {
- bool skip = true;
+ /*
+ * In parallel mode pass 1 runs non-exclusive tests in parallel, pass 2
+ * runs the exclusive tests sequentially. In other modes all tests are
+ * run in pass 1.
+ */
+ for (int pass = 1; pass <= 2; pass++) {
+ int child_test_num = 0;
+ int i = 0;
+
+ for_each_test(j, k, t) {
+ int curr = i++;
+
+ if (!perf_test__matches(test_description(t, -1), curr, argc, argv)) {
+ /*
+ * Test suite shouldn't be run based on
+ * description. See if subtest should.
+ */
+ bool skip = true;
+
+ for (int subi = 0, subn = num_subtests(t); subi < subn; subi++) {
+ if (perf_test__matches(test_description(t, subi),
+ curr, argc, argv))
+ skip = false;
+ }
- for (int subi = 0, subn = num_subtests(t); subi < subn; subi++) {
- if (perf_test__matches(test_description(t, subi),
- curr, argc, argv))
- skip = false;
+ if (skip)
+ continue;
}
- if (skip)
+ if (intlist__find(skiplist, i)) {
+ pr_info("%3d: %-*s:", curr + 1, width, test_description(t, -1));
+ color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
continue;
- }
-
- if (intlist__find(skiplist, i)) {
- pr_info("%3d: %-*s:", curr + 1, width, test_description(t, -1));
- color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
- continue;
- }
-
- if (!has_subtests(t)) {
- int err = start_test(t, curr, -1, &child_tests[child_test_num++], width);
+ }
- if (err) {
- /* TODO: if !sequential waitpid the already forked children. */
- free(child_tests);
- return err;
+ if (!has_subtests(t)) {
+ err = start_test(t, curr, -1, &child_tests[child_test_num++],
+ width, pass);
+ if (err)
+ goto err_out;
+ continue;
}
- } else {
for (int subi = 0, subn = num_subtests(t); subi < subn; subi++) {
- int err;
-
if (!perf_test__matches(test_description(t, subi),
curr, argc, argv))
continue;
err = start_test(t, curr, subi, &child_tests[child_test_num++],
- width);
+ width, pass);
if (err)
- return err;
+ goto err_out;
}
}
- }
- for (i = 0; i < child_test_num; i++) {
if (!sequential) {
- int ret = finish_test(child_tests, i, child_test_num, width);
-
- if (ret)
- return ret;
+ /* Parallel mode starts tests but doesn't finish them. Do that now. */
+ for (size_t x = 0; x < num_tests; x++)
+ finish_test(child_tests, x, num_tests, width);
}
- free(child_tests[i]);
+ }
+err_out:
+ if (err) {
+ pr_err("Internal test harness failure. Completing any started tests:\n:");
+ for (size_t x = 0; x < num_tests; x++)
+ finish_test(child_tests, x, num_tests, width);
}
free(child_tests);
- return 0;
+ return err;
}
static int perf_test__list(int argc, const char **argv)
@@ -638,6 +668,7 @@ int cmd_test(int argc, const char **argv)
symbol_conf.priv_size = sizeof(int);
symbol_conf.try_vmlinux_path = true;
+
if (symbol__init(NULL) < 0)
return -1;
diff --git a/tools/perf/tests/tests-scripts.c b/tools/perf/tests/tests-scripts.c
index ed114b044293..443b55b0e05c 100644
--- a/tools/perf/tests/tests-scripts.c
+++ b/tools/perf/tests/tests-scripts.c
@@ -203,6 +203,11 @@ static void append_script(int dir_fd, const char *name, char *desc,
test_suite->desc = desc;
test_suite->test_cases = tests;
test_suite->priv = strdup_check(filename);
+ /*
+ * Note, tests with lots of stdout can't be exclusive as if they block
+ * then the file lock is held and no one makes progress.
+ */
+ test_suite->exclusive = strstr(desc, "(exclusive)") != NULL;
/* Realloc is good enough, though we could realloc by chunks, not that
* anyone will ever measure performance here */
result_tmp = realloc(*result, (*result_sz + 1) * sizeof(*result_tmp));
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 6ea2be86b7bf..1d3e1f91871c 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -42,6 +42,7 @@ struct test_suite {
const char *desc;
struct test_case *test_cases;
void *priv;
+ bool exclusive;
};
#define DECLARE_SUITE(name) \
--
2.47.0.rc1.288.g06298d1525-goog
next prev parent reply other threads:[~2024-10-11 7:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-11 7:35 [PATCH v1 0/8] Run tests in parallel showing number of tests running Ian Rogers
2024-10-11 7:35 ` [PATCH v1 1/8] tools subcmd: Add non-waitpid check_if_command_finished() Ian Rogers
2024-10-11 7:35 ` [PATCH v1 2/8] perf test: Display number of remaining tests Ian Rogers
2024-10-11 7:35 ` [PATCH v1 3/8] perf test: Reduce scope of parallel variable Ian Rogers
2024-10-11 7:35 ` [PATCH v1 4/8] perf test: Avoid list test blocking on writing to stdout Ian Rogers
2024-10-11 7:35 ` [PATCH v1 5/8] perf test: Tag parallel failing shell tests with "(exclusive)" Ian Rogers
2024-10-11 10:01 ` James Clark
2024-10-11 10:29 ` James Clark
2024-10-11 16:52 ` Ian Rogers
2024-10-11 7:35 ` [PATCH v1 6/8] perf test: Add a signal handler around running a test Ian Rogers
2024-10-11 7:35 ` Ian Rogers [this message]
2024-10-11 7:35 ` [PATCH v1 8/8] perf test: Make parallel testing the default Ian Rogers
2024-10-11 10:03 ` [PATCH v1 0/8] Run tests in parallel showing number of tests running James Clark
2024-10-11 16:26 ` Ian Rogers
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=20241011073559.431302-8-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=atrajeev@linux.vnet.ibm.com \
--cc=colin.i.king@gmail.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=howardchu95@gmail.com \
--cc=iii@linux.ibm.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=mpetlan@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tmricht@linux.ibm.com \
--cc=vmolnaro@redhat.com \
--cc=weilin.wang@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).