perf tests stat: Add test for error for an offline CPU

Add a test that if an offline CPU is requested perf stat will fail.

  $ perf test -vv "perf stat tests"
  101: perf stat tests:
  --- start ---
  test child forked, pid 46965
  Basic stat command test
  Basic stat command test [Success]
  Null stat command test
  Null stat command test [Success]
  Offline CPU stat command test (cpu 8)
  Offline CPU stat command test [Success]
  stat record and report test
  stat record and report test [Success]
  stat record and script test
  stat record and script test [Success]
  stat repeat weak groups test
  stat repeat weak groups test [Success]
  Topdown event group test
  Topdown event group test [Success]
  Topdown weak groups test
  Topdown weak groups test [Skipped event parsing failed]
  cputype test
  cputype test [Success]
  hybrid test
  hybrid test [Success]
  ---- end(0) ----
  101: perf stat tests                                                 : Ok

Reported-by: Thomas Richter <tmricht@linux.ibm.com>
Closes: https://lore.kernel.org/linux-perf-users/94313b82-888b-4f42-9fb0-4585f9e90080@linux.ibm.com/
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
pull/1354/merge
Ian Rogers 2025-12-03 13:47:05 -08:00 committed by Namhyung Kim
parent c9a8c343ef
commit 5123509628
1 changed files with 27 additions and 0 deletions

View File

@ -27,6 +27,32 @@ test_null_stat() {
echo "Null stat command test [Success]" echo "Null stat command test [Success]"
} }
find_offline_cpu() {
for i in $(seq 1 4096)
do
if [[ ! -f /sys/devices/system/cpu/cpu$i/online || \
$(cat /sys/devices/system/cpu/cpu$i/online) == "0" ]]
then
echo $i
return
fi
done
echo "Failed to find offline CPU"
exit 1
}
test_offline_cpu_stat() {
cpu=$(find_offline_cpu)
echo "Offline CPU stat command test (cpu $cpu)"
if ! perf stat "-C$cpu" -e cycles true 2>&1 | grep -E -q "No supported events found."
then
echo "Offline CPU stat command test [Failed]"
err=1
return
fi
echo "Offline CPU stat command test [Success]"
}
test_stat_record_report() { test_stat_record_report() {
echo "stat record and report test" echo "stat record and report test"
if ! perf stat record -e task-clock -o - true | perf stat report -i - 2>&1 | \ if ! perf stat record -e task-clock -o - true | perf stat report -i - 2>&1 | \
@ -224,6 +250,7 @@ test_hybrid() {
test_default_stat test_default_stat
test_null_stat test_null_stat
test_offline_cpu_stat
test_stat_record_report test_stat_record_report
test_stat_record_script test_stat_record_script
test_stat_repeat_weak_groups test_stat_repeat_weak_groups