Skip to content

Commit 07120e7

Browse files
committed
perf test stat_all_pmu.sh: Correctly check 'perf stat' result
JIRA: https://issues.redhat.com/browse/RHEL-77936 upstream ======== commit 02ba09c Author: Veronika Molnarova <[email protected]> Date: Sat Nov 23 00:12:33 2024 +0100 description =========== 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: 7e73ea4 ("perf test: Ignore security failures in all PMU test") Signed-off-by: Veronika Molnarova <[email protected]> Tested-by: Qiao Zhao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]> Signed-off-by: Michael Petlan <[email protected]>
1 parent 2cb7379 commit 07120e7

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

tools/perf/tests/shell/stat_all_pmu.sh

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# perf all PMU test (exclusive)
33
# SPDX-License-Identifier: GPL-2.0
44

5-
set -e
65
err=0
76
result=""
87

@@ -16,34 +15,55 @@ trap trap_cleanup EXIT TERM INT
1615
# Test all PMU events; however exclude parameterized ones (name contains '?')
1716
for p in $(perf list --raw-dump pmu | sed 's/[[:graph:]]\+?[[:graph:]]\+[[:space:]]//g')
1817
do
19-
echo "Testing $p"
20-
result=$(perf stat -e "$p" true 2>&1)
21-
if echo "$result" | grep -q "$p"
18+
echo -n "Testing $p -- "
19+
output=$(perf stat -e "$p" true 2>&1)
20+
stat_result=$?
21+
if echo "$output" | grep -q "$p"
2222
then
2323
# Event seen in output.
24-
continue
25-
fi
26-
if echo "$result" | grep -q "<not supported>"
27-
then
28-
# Event not supported, so ignore.
29-
continue
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
3047
fi
31-
if echo "$result" | grep -q "Access to performance monitoring and observability operations is limited."
48+
49+
if echo "$output" | grep -q "Access to performance monitoring and observability operations is limited."
3250
then
3351
# Access is limited, so ignore.
52+
echo "access limited"
3453
continue
3554
fi
3655

3756
# We failed to see the event and it is supported. Possibly the workload was
3857
# too small so retry with something longer.
39-
result=$(perf stat -e "$p" perf bench internals synthesize 2>&1)
40-
if echo "$result" | grep -q "$p"
58+
output=$(perf stat -e "$p" perf bench internals synthesize 2>&1)
59+
if echo "$output" | grep -q "$p"
4160
then
4261
# Event seen in output.
62+
echo "supported"
4363
continue
4464
fi
4565
echo "Error: event '$p' not printed in:"
46-
echo "$result"
66+
echo "$output"
4767
err=1
4868
done
4969

0 commit comments

Comments
 (0)