[PATCH v11 17/19] perf test: Avoid online CPUs in the offline stat test

From: Arnaldo Carvalho de Melo

Date: Sun Nov 22 2026 - 16:42:01 EST


From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

find_offline_cpu() treats a missing cpuN/online file as an offline CPU,
but kernels without CPU hotplug also lack it for online CPUs. The test
then expects "No supported events found." from a working CPU.

Treat a present CPU as offline only if its online file reads 0. Keep
the absent cpuN case to exercise an invalid CPU, and skip if neither
exists.

Fixes: 5123509628e1ebe7 ("perf tests stat: Add test for error for an offline CPU")
Cc: Ian Rogers <irogers@xxxxxxxxxx>
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/tests/shell/stat.sh | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh
index ac9e031831daca9c..7cd9999fd526bbd6 100755
--- a/tools/perf/tests/shell/stat.sh
+++ b/tools/perf/tests/shell/stat.sh
@@ -43,21 +43,28 @@ test_null_stat() {
}

find_offline_cpu() {
- for i in $(seq 1 4096)
+ for i in $(seq 0 4096)
do
- if [[ ! -f /sys/devices/system/cpu/cpu$i/online || \
- $(cat /sys/devices/system/cpu/cpu$i/online) == "0" ]]
+ if [[ ! -d /sys/devices/system/cpu/cpu$i ]]
then
echo $i
- return
+ return 0
+ elif [[ -f /sys/devices/system/cpu/cpu$i/online && \
+ $(cat /sys/devices/system/cpu/cpu$i/online) == "0" ]]
+ then
+ echo $i
+ return 0
fi
done
- echo "Failed to find offline CPU"
- exit 1
+ return 1
}

test_offline_cpu_stat() {
- cpu=$(find_offline_cpu)
+ if ! cpu=$(find_offline_cpu)
+ then
+ echo "Offline CPU stat command test [Skipped - no offline CPU]"
+ return
+ fi
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
--
2.56.1