[PATCH 1/2] perf test: Factor out the --skip check and its output
From: James Clark
Date: Fri Oct 23 2026 - 05:09:36 EST
__cmd_test() checks the --skip list and prints the "Skip (user
override)" line and its junit entry inline, and
perf_test__shares_mlock_budget() repeats the check, with the list passed
to both from cmd_test().
Make the list static, like the other options, check it in
perf_test__skip_suite() and move the output to
print_suite_user_override(), so that the --skip-name option added next
can hook into the same places.
No functional changes intended.
Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
---
tools/perf/tests/builtin-test.c | 83 +++++++++++++++++++++--------------------
1 file changed, 43 insertions(+), 40 deletions(-)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 880eece0bc12..cd0fc3dedc3e 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -68,6 +68,8 @@ static bool list_requisites;
static unsigned int runs_per_test = 1;
/* Number of lines to include in failure snippet. */
static unsigned int failure_snippet_lines = 10;
+/* Numbers of the test suites to skip, from --skip. */
+static struct intlist *skiplist;
/*
* The tests mapping ring buffers take turns using their share of
* kernel.perf_event_mlock_kb via this mutex, shared with the forked test
@@ -342,6 +344,11 @@ static bool test_exclusive(const struct test_suite *t, int test_case)
return t->test_cases[test_case].exclusive;
}
+static bool perf_test__skip_suite(int suite_num)
+{
+ return intlist__find(skiplist, suite_num + 1) != NULL;
+}
+
static bool perf_test__matches(const char *desc, int suite_num, int argc, const char *argv[])
{
int i;
@@ -1358,8 +1365,33 @@ static void print_tests_summary(void)
strbuf_release(&summary_failed_tests_buf);
}
-static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
- struct intlist *skiplist)
+static void print_suite_user_override(struct test_suite *t, int curr_suite, int width)
+{
+ int pad_width = get_max_desc_width(width);
+ int term_width = get_term_width();
+
+ pr_info("%3d: %-*.*s:", curr_suite + 1, pad_width, term_width,
+ test_description(t, -1));
+ color_fprintf(debug_file(), PERF_COLOR_YELLOW, " Skip (user override)\n");
+ summary_tests_skipped++;
+ if (junit_filename) {
+ char *escaped_class = xml_escape(test_description(t, -1));
+ char *escaped_test = xml_escape("override");
+ char *escaped_reason = xml_escape("user override");
+
+ strbuf_addf(&junit_xml_buf,
+ " <testcase classname=\"%s\" name=\"%s\" time=\"0.000\">\n",
+ escaped_class, escaped_test);
+ strbuf_addf(&junit_xml_buf, " <skipped message=\"%s\"/>\n",
+ escaped_reason);
+ strbuf_addstr(&junit_xml_buf, " </testcase>\n");
+ free(escaped_reason);
+ free(escaped_test);
+ free(escaped_class);
+ }
+}
+
+static int __cmd_test(struct test_suite **suites, int argc, const char *argv[])
{
static int width = 0;
int err = 0;
@@ -1434,37 +1466,9 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
suite_matched = true;
}
- if (intlist__find(skiplist, curr_suite + 1)) {
- if (pass == 1) {
- int pad_width = get_max_desc_width(width);
- int term_width = get_term_width();
-
- pr_info("%3d: %-*.*s:", curr_suite + 1,
- pad_width, term_width,
- test_description(*t, -1));
- color_fprintf(debug_file(), PERF_COLOR_YELLOW,
- " Skip (user override)\n");
- summary_tests_skipped++;
- if (junit_filename) {
- char *escaped_class =
- xml_escape((const char *)
- test_description(*t, -1));
- char *escaped_test = xml_escape("override");
- char *escaped_reason =
- xml_escape("user override");
-
- strbuf_addf(&junit_xml_buf,
- " <testcase classname=\"%s\" name=\"%s\" time=\"0.000\">\n",
- escaped_class, escaped_test);
- strbuf_addf(&junit_xml_buf,
- " <skipped message=\"%s\"/>\n",
- escaped_reason);
- strbuf_addstr(&junit_xml_buf, " </testcase>\n");
- free(escaped_reason);
- free(escaped_test);
- free(escaped_class);
- }
- }
+ if (perf_test__skip_suite(curr_suite)) {
+ if (pass == 1)
+ print_suite_user_override(*t, curr_suite, width);
continue;
}
@@ -1817,7 +1821,7 @@ static struct test_suite **build_suites(void)
}
static bool perf_test__shares_mlock_budget(struct test_suite **suites, int argc,
- const char *argv[], struct intlist *skiplist)
+ const char *argv[])
{
int sharing = 0;
@@ -1827,7 +1831,7 @@ static bool perf_test__shares_mlock_budget(struct test_suite **suites, int argc,
int curr_test_case;
bool suite_matched;
- if (!t->needs_mlock || intlist__find(skiplist, curr_suite + 1))
+ if (!t->needs_mlock || perf_test__skip_suite(curr_suite))
continue;
suite_matched = perf_test__matches(test_description(t, /*test_case=*/-1),
@@ -1865,7 +1869,7 @@ static bool perf_test__mlock_budget_exhaustible(void)
}
static void perf_test__setup_mlock_budget(struct test_suite **suites, int argc,
- const char *argv[], struct intlist *skiplist)
+ const char *argv[])
{
/* Nothing can be denied the budget, nothing to take turns for. */
if (!perf_test__mlock_budget_exhaustible()) {
@@ -1874,7 +1878,7 @@ static void perf_test__setup_mlock_budget(struct test_suite **suites, int argc,
}
/* Nothing runs at the same time, nothing to share the budget with. */
- if (sequential || !perf_test__shares_mlock_budget(suites, argc, argv, skiplist))
+ if (sequential || !perf_test__shares_mlock_budget(suites, argc, argv))
return;
mlock_budget = mmap(NULL, sizeof(*mlock_budget), PROT_READ | PROT_WRITE,
@@ -1936,7 +1940,6 @@ int cmd_test(int argc, const char **argv)
OPT_END()
};
const char * const test_subcommands[] = { "list", "requisites", NULL };
- struct intlist *skiplist = NULL;
struct test_suite **suites;
int ret;
@@ -2010,8 +2013,8 @@ int cmd_test(int argc, const char **argv)
intlist__delete(skiplist);
return err ? -err : -ENOMEM;
}
- perf_test__setup_mlock_budget(suites, argc, argv, skiplist);
- ret = __cmd_test(suites, argc, argv, skiplist);
+ perf_test__setup_mlock_budget(suites, argc, argv);
+ ret = __cmd_test(suites, argc, argv);
perf_test__teardown_mlock_budget();
free(suites);
intlist__delete(skiplist);
--
2.43.0