Skip to content

Commit 1c0d981

Browse files
captain5050namhyung
authored andcommitted
perf test: Add a runs-per-test flag
To detect flakes it is useful to run tests more than once. Add a runs-per-test flag that will run each test multiple times. Example output: ``` $ perf test -r 3 lbr -v 122: perf record LBR tests : Ok 122: perf record LBR tests : Ok 122: perf record LBR tests : Ok ``` Update the documentation for the runs-per-test option. Signed-off-by: Ian Rogers <irogers@google.com> Reviewed-by: Namhyung Kim <namhyung@kernel.org> Cc: James Clark <james.clark@linaro.org> Link: https://lore.kernel.org/r/20250110045736.598281-5-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent 4dd8bc4 commit 1c0d981

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

tools/perf/Documentation/perf-test.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ OPTIONS
3737
tests are run sequentially, but other tests are run in
3838
parallel to speed execution.
3939

40+
-r::
41+
--runs-per-test::
42+
Run each test the given number of times, by default once. This
43+
option can be useful to determine if a test is flaky.
44+
4045
-F::
4146
--dont-fork::
4247
Do not fork child for each test, run all tests within single process, this

tools/perf/tests/builtin-test.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
static bool dont_fork;
4343
/* Fork the tests in parallel and wait for their completion. */
4444
static bool sequential;
45+
/* Number of times each test is run. */
46+
static unsigned int runs_per_test = 1;
4547
const char *dso_to_test;
4648
const char *test_objdump_path = "objdump";
4749

@@ -485,7 +487,7 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
485487
len = strlen(test_description(*t, i));
486488
if (width < len)
487489
width = len;
488-
num_tests++;
490+
num_tests += runs_per_test;
489491
}
490492
}
491493
child_tests = calloc(num_tests, sizeof(*child_tests));
@@ -549,16 +551,18 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
549551
continue;
550552
}
551553

552-
test_suite__for_each_test_case(*t, curr_test_case) {
553-
if (!perf_test__matches(test_description(*t, curr_test_case),
554-
curr_suite, argc, argv))
555-
continue;
556-
557-
err = start_test(*t, curr_suite, curr_test_case,
558-
&child_tests[child_test_num++],
559-
width, pass);
560-
if (err)
561-
goto err_out;
554+
for (unsigned int run = 0; run < runs_per_test; run++) {
555+
test_suite__for_each_test_case(*t, curr_test_case) {
556+
if (!perf_test__matches(test_description(*t, curr_test_case),
557+
curr_suite, argc, argv))
558+
continue;
559+
560+
err = start_test(*t, curr_suite, curr_test_case,
561+
&child_tests[child_test_num++],
562+
width, pass);
563+
if (err)
564+
goto err_out;
565+
}
562566
}
563567
}
564568
if (!sequential) {
@@ -698,6 +702,8 @@ int cmd_test(int argc, const char **argv)
698702
"Do not fork for testcase"),
699703
OPT_BOOLEAN('S', "sequential", &sequential,
700704
"Run the tests one after another rather than in parallel"),
705+
OPT_UINTEGER('r', "runs-per-test", &runs_per_test,
706+
"Run each test the given number of times, default 1"),
701707
OPT_STRING('w', "workload", &workload, "work", "workload to run for testing, use '--list-workloads' to list the available ones."),
702708
OPT_BOOLEAN(0, "list-workloads", &list_workloads, "List the available builtin workloads to use with -w/--workload"),
703709
OPT_STRING(0, "dso", &dso_to_test, "dso", "dso to test"),

0 commit comments

Comments
 (0)