1#!/bin/bash 2# perf all PMU test (exclusive) 3# SPDX-License-Identifier: GPL-2.0 4 5err=0 6result="" 7 8trap_cleanup() { 9 echo "Unexpected signal in ${FUNCNAME[1]}" 10 echo "$result" 11 exit 1 12} 13trap trap_cleanup EXIT TERM INT 14 15# Test all PMU events; however exclude parameterized ones (name contains '?') 16for p in $(perf list --raw-dump pmu | sed 's/[[:graph:]]\+?[[:graph:]]\+[[:space:]]//g') 17do 18 echo -n "Testing $p -- " 19 output=$(perf stat -e "$p" true 2>&1) 20 stat_result=$? 21 if echo "$output" | grep -q "$p" 22 then 23 # Event seen in output. 24 if [ $stat_result -eq 0 ] && ! echo "$output" | grep -q "<not supported>" 25 then 26 # Event supported. 27 echo "supported" 28 continue 29 elif echo "$output" | grep -q "<not supported>" 30 then 31 # Event not supported, so ignore. 32 echo "not supported" 33 continue 34 elif echo "$output" | grep -q "No permission to enable" 35 then 36 # No permissions, so ignore. 37 echo "no permission to enable" 38 continue 39 elif echo "$output" | grep -q "Bad event name" 40 then 41 # Non-existent event. 42 echo "Error: Bad event name" 43 echo "$output" 44 err=1 45 continue 46 fi 47 fi 48 49 if echo "$output" | grep -q "Access to performance monitoring and observability operations is limited." 50 then 51 # Access is limited, so ignore. 52 echo "access limited" 53 continue 54 fi 55 56 # We failed to see the event and it is supported. Possibly the workload was 57 # too small so retry with something longer. 58 output=$(perf stat -e "$p" perf bench internals synthesize 2>&1) 59 if echo "$output" | grep -q "$p" 60 then 61 # Event seen in output. 62 echo "supported" 63 continue 64 fi 65 echo "Error: event '$p' not printed in:" 66 echo "$output" 67 err=1 68done 69 70trap - EXIT TERM INT 71exit $err 72