summaryrefslogtreecommitdiff
path: root/tools/perf/tests
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-05-18 18:41:06 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-05-22 21:39:28 -0300
commitf83deb058025d1b6eb0ff297422634a5a11ef87b (patch)
treeea5c1b5607e2fb7859c1cff8eb097ff57ec19b8e /tools/perf/tests
parent0b18bced5444f4fc54ba4500c377f2e88d31ea09 (diff)
downloadlinux-next-f83deb058025d1b6eb0ff297422634a5a11ef87b.tar.gz
linux-next-f83deb058025d1b6eb0ff297422634a5a11ef87b.zip
perf tests: Add test for stat delay option with duration_time
Add a new test case `test_stat_delay` to `stat.sh` to verify that `duration_time` correctly excludes the delay period when using the delay option (-D). The test runs `perf stat -D 1000 -e duration_time sleep 2` and verifies that `duration_time` is ~1s (excluding the 1s delay), not ~2s. Assisted-by: Antigravity:gemini-3-flash Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Francesco Nigro <nigro.fra@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests')
-rwxr-xr-xtools/perf/tests/shell/stat.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh
index 4edb04039036..1e17bee026bd 100755
--- a/tools/perf/tests/shell/stat.sh
+++ b/tools/perf/tests/shell/stat.sh
@@ -483,6 +483,58 @@ test_stat_pid() {
wait $pid 2>/dev/null || true
}
+test_stat_delay() {
+ echo "stat -D test"
+ if ! env LC_ALL=C perf stat -D 1000 -e duration_time sleep 2 > "${stat_output}" 2>&1
+ then
+ echo "stat -D test [Failed - command failed]"
+ cat "${stat_output}"
+ err=1
+ return
+ fi
+
+ duration=$(grep "duration_time" "${stat_output}" | awk '{print $1}' | tr -d ',')
+ elapsed=$(grep "seconds time elapsed" "${stat_output}" | awk '{print $1}')
+
+ if [ -z "$duration" ] || [ -z "$elapsed" ]
+ then
+ echo "stat -D test [Failed - failed to find duration_time or time elapsed in output]"
+ cat "${stat_output}"
+ err=1
+ return
+ fi
+
+ # Compare duration (ns) and elapsed (s) using awk to handle float and allow tolerance.
+ if ! awk -v d="$duration" -v e="$elapsed" '
+ BEGIN {
+ diff = d - (e * 1e9);
+ if (diff < 0) diff = -diff;
+ # Allow 200ms tolerance (200,000,000 ns) for loaded CI machines.
+ if (diff > 200000000) {
+ printf "Fail: duration (%d ns) and elapsed (%f s) mismatch (diff %d ns)\n", d, e, diff;
+ exit 1;
+ }
+ # Lower bound check: must be at least 0.5s.
+ if (d < 500000000) {
+ printf "Fail: duration (%d ns) is abnormally small\n", d;
+ exit 1;
+ }
+ # Upper bound check: must be strictly less than 1.7s (proving delay was excluded).
+ if (d > 1700000000) {
+ printf "Fail: duration (%d ns) is too large (delay might not be excluded)\n", d;
+ exit 1;
+ }
+ exit 0;
+ }'
+ then
+ echo "stat -D test [Failed - validation failed]"
+ cat "${stat_output}"
+ err=1
+ return
+ fi
+ echo "stat -D test [Success]"
+}
+
test_default_stat
test_null_stat
test_offline_cpu_stat
@@ -498,6 +550,7 @@ test_stat_no_aggr
test_stat_detailed
test_stat_repeat
test_stat_pid
+test_stat_delay
cleanup
exit $err