1#!/bin/bash 2# perf all metrics test 3# SPDX-License-Identifier: GPL-2.0 4 5ParanoidAndNotRoot() 6{ 7 [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] 8} 9 10test_prog="sleep 0.01" 11system_wide_flag="-a" 12if ParanoidAndNotRoot 0 13then 14 system_wide_flag="" 15 test_prog="perf test -w noploop" 16fi 17 18skip=0 19err=3 20for m in $(perf list --raw-dump metrics); do 21 echo "Testing $m" 22 result=$(perf stat -M "$m" $system_wide_flag -- $test_prog 2>&1) 23 result_err=$? 24 if [[ $result_err -eq 0 && "$result" =~ ${m:0:50} ]] 25 then 26 # No error result and metric shown. 27 if [[ "$err" -ne 1 ]] 28 then 29 err=0 30 fi 31 continue 32 fi 33 if [[ "$result" =~ "Cannot resolve IDs for" || "$result" =~ "No supported events found" ]] 34 then 35 if [[ $(perf list --raw-dump $m) == "Default"* ]] 36 then 37 echo "[Ignored $m] failed but as a Default metric this can be expected" 38 echo $result 39 continue 40 fi 41 echo "[Failed $m] Metric contains missing events" 42 echo $result 43 err=1 # Fail 44 continue 45 elif [[ "$result" =~ \ 46 "Access to performance monitoring and observability operations is limited" ]] 47 then 48 echo "[Skipped $m] Permission failure" 49 echo $result 50 if [[ $err -eq 0 ]] 51 then 52 skip=1 53 fi 54 continue 55 elif [[ "$result" =~ "in per-thread mode, enable system wide" ]] 56 then 57 echo "[Skipped $m] Permissions - need system wide mode" 58 echo $result 59 if [[ $err -eq 0 ]] 60 then 61 skip=1 62 fi 63 continue 64 elif [[ "$result" =~ "<not supported>" ]] 65 then 66 if [[ $(perf list --raw-dump $m) == "Default"* ]] 67 then 68 echo "[Ignored $m] failed but as a Default metric this can be expected" 69 echo $result 70 continue 71 fi 72 echo "[Skipped $m] Not supported events" 73 echo $result 74 if [[ $err -eq 0 ]] 75 then 76 skip=1 77 fi 78 continue 79 elif [[ "$result" =~ "<not counted>" ]] 80 then 81 echo "[Skipped $m] Not counted events" 82 echo $result 83 if [[ $err -eq 0 ]] 84 then 85 skip=1 86 fi 87 continue 88 elif [[ "$result" =~ "FP_ARITH" || "$result" =~ "AMX" ]] 89 then 90 echo "[Skipped $m] FP issues" 91 echo $result 92 if [[ $err -eq 0 ]] 93 then 94 skip=1 95 fi 96 continue 97 elif [[ "$result" =~ "PMM" ]] 98 then 99 echo "[Skipped $m] Optane memory issues" 100 echo $result 101 if [[ $err -eq 0 ]] 102 then 103 skip=1 104 fi 105 continue 106 fi 107 108 # Failed, possibly the workload was too small so retry with something longer. 109 result=$(perf stat -M "$m" $system_wide_flag -- perf bench internals synthesize 2>&1) 110 result_err=$? 111 if [[ $result_err -eq 0 && "$result" =~ ${m:0:50} ]] 112 then 113 # No error result and metric shown. 114 if [[ "$err" -ne 1 ]] 115 then 116 err=0 117 fi 118 continue 119 fi 120 echo "[Failed $m] has non-zero error '$result_err' or not printed in:" 121 echo "$result" 122 err=1 123done 124 125# return SKIP only if no success returned 126if [[ "$err" -eq 3 && "$skip" -eq 1 ]] 127then 128 err=2 129fi 130 131exit "$err" 132