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

Configure Feed

Select the types of activity you want to include in your feed.

perf test stat_all_pmu.sh: Correctly check 'perf stat' result

Test case "stat_all_pmu.sh" is not correctly checking 'perf stat' output
due to a poor design. Firstly, having the 'set -e' option with a trap
catching the sigexit causes the shell to exit immediately if 'perf stat' ends
with any non-zero value, which is then caught by the trap reporting an
unexpected signal. This causes events that should be parsed by the if-else
statement to be caught by the trap handler and are reported as errors:

$ perf test -vv "perf all pmu"
Testing i915/actual-frequency/
Unexpected signal in main
Error:
Access to performance monitoring and observability operations is limited.

Secondly, the if-else branches are not exclusive as the checking if the
event is present in the output log covers also the "<not supported>"
events, which should be accepted, and also the "Bad name events", which
should be rejected.

Remove the "set -e" option from the test case, correctly parse the
"perf stat" output log and check its return value. Add the missing
outputs for the 'perf stat' result and also add logs messages to
report the branch that parsed the event for more info.

Fixes: 7e73ea40295620e7 ("perf test: Ignore security failures in all PMU test")
Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Tested-by: Qiao Zhao <qzhao@redhat.com>
Link: https://lore.kernel.org/r/20241122231233.79509-1-vmolnaro@redhat.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Veronika Molnarova and committed by
Namhyung Kim
02ba09c8 fa9bc517

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