[PATCH 33/34] perf test cs-etm: Test decoding of kernel modules

James Clark james.clark at linaro.org
Wed Nov 18 08:29:55 PST 2026


If kernel symbols are available, test that recording the kernel results
in etm4_enable* and etm4_disable* symbols. Use these symbols because
they will always be present when using trace.

Signed-off-by: James Clark <james.clark at linaro.org>
---
 tools/perf/tests/shell/coresight/kernel_module.sh | 54 +++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/tools/perf/tests/shell/coresight/kernel_module.sh b/tools/perf/tests/shell/coresight/kernel_module.sh
new file mode 100755
index 000000000000..96bacb02b1fb
--- /dev/null
+++ b/tools/perf/tests/shell/coresight/kernel_module.sh
@@ -0,0 +1,54 @@
+#!/bin/bash -e
+# CoreSight kernel module decode (exclusive)
+
+# SPDX-License-Identifier: GPL-2.0
+
+# If CoreSight is not available, skip the test
+perf list pmu | grep -q cs_etm || exit 2
+
+if [ "$(id -u)" != 0 ]; then
+	# Requires root for kernel trace and symbols
+	echo "[Skip] No root permission"
+	exit 2
+fi
+
+if ! perf probe --dry-run --module coresight_etm4x \
+	--add etm4_enable_trace_unit > /dev/null 2>&1 &&
+   ! perf probe --dry-run --add etm4_enable_trace_unit > /dev/null 2>&1; then
+	echo "[Skip] Kernel debug symbols for Coresight aren't available"
+	exit 2
+fi
+
+tmpdir=$(mktemp -d /tmp/__perf_test.coresight_kernel_module.XXXXX)
+
+cleanup() {
+	rm -rf "${tmpdir}"
+	trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+	cleanup
+	exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+if ! perf record -o "$tmpdir/data" -e cs_etm//k -- true > /dev/null 2>&1; then
+	echo "[Fail] Failed to record kernel ETM trace"
+	cleanup
+	exit 1
+fi
+
+perf script -i "$tmpdir/data" --itrace=b -F ip,sym \
+	> "$tmpdir/script" 2>/dev/null
+
+# enable_* and disable_* functions always run so check they were decoded
+for symbol in etm4_enable etm4_disable; do
+	if ! grep -q "$symbol" "$tmpdir/script"; then
+		echo "No branches decoded in $symbol"
+		cleanup
+		exit 1
+	fi
+done
+
+cleanup
+exit 0

-- 
2.43.0




More information about the linux-arm-kernel mailing list