[PATCH v2 09/12] perf tests: Fix flakiness in branch stack sampling tests
From: Ian Rogers
Date: Tue Jun 16 2026 - 02:14:43 EST
The branch stack sampling test (test 130) runs short iteration-based
workloads to verify syscall, kernel, and trap branch stack sampling.
Specifically, `test_syscall()` and `test_kernel_branches()` run
`perf bench syscall basic` with loop counts of 8000 and 1000, and
`test_trap_eret_branches()` runs `traploop` with 1000 iterations.
Because these loop limits are extremely small, the total benchmark runtimes
last only a few milliseconds (or less). Under high load, virtualization,
or coarse sampling conditions, PMU cycle sampling fails to capture enough
samples inside the brief benchmark loops. This leads to false negatives
where the script output lacks the expected syscall, kernel, or trap branch
entries (e.g. "ERROR: Branches missing getppid[^ ]*/SYSCALL/").
Fix this by increasing the workload loop counts to 100,000 across all
three test sections. Running 100,000 loops still finishes virtually
instantaneously (less than 0.1 seconds), but generates enough iterations
to guarantee robust branch stack capture.
Fixes: b55878c90ab9 ("perf test: Add test for branch stack sampling")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/tests/shell/test_brstack.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
index eb5837f82e39..be46a68daf76 100755
--- a/tools/perf/tests/shell/test_brstack.sh
+++ b/tools/perf/tests/shell/test_brstack.sh
@@ -112,7 +112,7 @@ test_trap_eret_branches() {
start_err=$err
err=0
perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u,k -- \
- perf test -w traploop 1000 > "$TMPDIR/record.txt" 2>&1
+ perf test -w traploop 100000 > "$TMPDIR/record.txt" 2>&1
perf script -i $TMPDIR/perf.data --fields brstacksym | \
tr ' ' '\n' > $TMPDIR/perf.script
@@ -137,7 +137,7 @@ test_kernel_branches() {
start_err=$err
err=0
perf record -o $TMPDIR/perf.data --branch-filter any,k -- \
- perf bench syscall basic --loop 1000 > "$TMPDIR/record.txt" 2>&1
+ perf bench syscall basic --loop 100000 > "$TMPDIR/record.txt" 2>&1
perf script -i $TMPDIR/perf.data --fields brstack | \
tr ' ' '\n' > $TMPDIR/perf.script
@@ -209,7 +209,7 @@ test_syscall() {
err=0
perf record -o $TMPDIR/perf.data --branch-filter \
any_call,save_type,u,k -c 10007 -- \
- perf bench syscall basic --loop 8000 > "$TMPDIR/record.txt" 2>&1
+ perf bench syscall basic --loop 100000 > "$TMPDIR/record.txt" 2>&1
perf script -i $TMPDIR/perf.data --fields brstacksym | \
tr ' ' '\n' > $TMPDIR/perf.script
--
2.54.0.1136.gdb2ca164c4-goog