Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: Be more tolerant of metricgroup failures

Previously "set -e" meant any non-zero exit code from perf stat would
cause a test failure. As a non-zero exit happens when there aren't
sufficient permissions, check for this case and make the exit code
2/skip for it.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Link: https://lore.kernel.org/r/20240502223115.2357499-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
c940a66b 1de5b5dc

+30 -6
+30 -6
tools/perf/tests/shell/stat_all_metricgroups.sh
··· 1 - #!/bin/sh 1 + #!/bin/bash 2 2 # perf all metricgroups test 3 3 # SPDX-License-Identifier: GPL-2.0 4 - 5 - set -e 6 4 7 5 ParanoidAndNotRoot() 8 6 { ··· 12 14 then 13 15 system_wide_flag="" 14 16 fi 15 - 17 + err=0 16 18 for m in $(perf list --raw-dump metricgroups) 17 19 do 18 20 echo "Testing $m" 19 - perf stat -M "$m" $system_wide_flag sleep 0.01 21 + result=$(perf stat -M "$m" $system_wide_flag sleep 0.01 2>&1) 22 + result_err=$? 23 + if [[ $result_err -gt 0 ]] 24 + then 25 + if [[ "$result" =~ \ 26 + "Access to performance monitoring and observability operations is limited" ]] 27 + then 28 + echo "Permission failure" 29 + echo $result 30 + if [[ $err -eq 0 ]] 31 + then 32 + err=2 # Skip 33 + fi 34 + elif [[ "$result" =~ "in per-thread mode, enable system wide" ]] 35 + then 36 + echo "Permissions - need system wide mode" 37 + echo $result 38 + if [[ $err -eq 0 ]] 39 + then 40 + err=2 # Skip 41 + fi 42 + else 43 + echo "Metric group $m failed" 44 + echo $result 45 + err=1 # Fail 46 + fi 47 + fi 20 48 done 21 49 22 - exit 0 50 + exit $err