perf test: Skip data_type_profiling when the PMU cannot record memory events

The test's only guard matches "failed: no PMU supports the memory
events", but a PMU that has memory events and refuses them per-thread,
such as AMD IBS on kernels without the swfilt filter, falls through:
the script runs under 'set -e' and the bare 'perf mem record' aborts it
through the EXIT trap, reporting a signal that never happened and
turning "this PMU cannot record these events" into a test failure.

Skip when a trivial per-thread 'perf mem record' fails, and put the
record and annotate calls in the condition of an 'if', where 'set -e'
leaves them alone, so the remaining cases report their own failures
instead of the first one aborting the run.

Fixes: f60a5c2296 ("perf tests: Test annotate with data type profiling and rust")
Acked-by: Namhyung Kim <namhyung@kernel.org>
Assisted-by: LLM
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2026-09-08 11:03:44 -03:00
parent 91b0782fc9
commit 29f320d221

View File

@ -19,6 +19,15 @@ perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX)
perf mem record -o /dev/null -- true 2>&1 | \
grep -q "failed: no PMU supports the memory events" && exit 2
# Skip if per-thread mem record is not supported on this PMU (e.g. AMD IBS
# needs system-wide '-a'): it is what the test records with below, and a
# failing record must not be reported as a test failure.
if ! perf mem record -o /dev/null -- true 2>/dev/null
then
echo "Skip: cannot record memory events on this PMU"
exit 2
fi
cleanup() {
rm -rf "${perfdata}" "${perfout}"
rm -rf "${perfdata}".old
@ -52,25 +61,42 @@ test_basic_annotate() {
index=1 ;;
esac
# Under 'set -e' a bare failing command aborts the script through the EXIT
# trap, so the commands that report a failure have to be the condition of
# an 'if' for that reporting to ever happen.
if [ "x${mode}" == "xBasic" ]
then
perf mem record -o "${perfdata}" ${testprogs[$index]} 2> /dev/null
if ! perf mem record -o "${perfdata}" ${testprogs[$index]} 2> /dev/null
then
echo "${mode} annotate [Failed: perf record]"
err=1
return
fi
else
perf mem record -o - ${testprogs[$index]} 2> /dev/null > "${perfdata}"
fi
if [ "x$?" != "x0" ]
then
echo "${mode} annotate [Failed: perf record]"
err=1
return
if ! perf mem record -o - ${testprogs[$index]} 2> /dev/null > "${perfdata}"
then
echo "${mode} annotate [Failed: perf record]"
err=1
return
fi
fi
# Generate the annotated output file
if [ "x${mode}" == "xBasic" ]
then
perf annotate --code-with-type -i "${perfdata}" --stdio --percent-limit 1 2> /dev/null > "${perfout}"
if ! perf annotate --code-with-type -i "${perfdata}" --stdio --percent-limit 1 2> /dev/null > "${perfout}"
then
echo "${mode} annotate [Failed: perf annotate]"
err=1
return
fi
else
perf annotate --code-with-type -i - --stdio 2> /dev/null --percent-limit 1 < "${perfdata}" > "${perfout}"
if ! perf annotate --code-with-type -i - --stdio 2> /dev/null --percent-limit 1 < "${perfdata}" > "${perfout}"
then
echo "${mode} annotate [Failed: perf annotate]"
err=1
return
fi
fi
# check if it has the target data type