lkml.org 
[lkml]   [2022]   [Jan]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] perf test: Add shell script test for ARM64 frame-pointer call graphs
Date
In the commit in [1], the frame-pointer call-graphs were fixed in ARM64.
So add a test to avoid future regressions.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b9f6fbb3b2c29736970ae9fcc0e82b0bd459442b

Suggested-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: German Gomez <german.gomez@arm.com>
---
.../tests/shell/test_arm_fp_call_graph.sh | 74 +++++++++++++++++++
1 file changed, 74 insertions(+)
create mode 100755 tools/perf/tests/shell/test_arm_fp_call_graph.sh

diff --git a/tools/perf/tests/shell/test_arm_fp_call_graph.sh b/tools/perf/tests/shell/test_arm_fp_call_graph.sh
new file mode 100755
index 000000000000..4ba17163b320
--- /dev/null
+++ b/tools/perf/tests/shell/test_arm_fp_call_graph.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+# Check frame pointer call-graphs are correct on Arm64
+
+# SPDX-License-Identifier: GPL-2.0
+# German Gomez <german.gomez@arm.com>, 2022
+
+# This test checks that the perf tool injects the missing caller of a
+# leaf function on Arm64 when unwinding using frame pointers.
+# See: https://lore.kernel.org/r/20211217154521.80603-7-german.gomez@arm.com
+
+# Only run this test on Arm64
+lscpu | grep -q "aarch64" || return 2
+
+if ! [ -x "$(command -v cc)" ]; then
+ echo "failed: no compiler, install gcc"
+ exit 2
+fi
+
+PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+TEST_PROGRAM_SOURCE=$(mktemp /tmp/test_program.XXXXX.c)
+TEST_PROGRAM=$(mktemp /tmp/test_program.XXXXX)
+SCRIPT_FILE=$(mktemp /tmp/perf.script.XXXXX)
+
+cleanup_files() {
+ rm -f $PERF_DATA*
+ rm -f $TEST_PROGRAM_SOURCE
+ rm -f $TEST_PROGRAM
+ rm -f $SCRIPT_FILE
+}
+
+trap cleanup_files exit term int
+
+# compile test program
+cat << EOF > $TEST_PROGRAM_SOURCE
+int a = 0;
+void leaf(void) {
+ for (int i = 0; i < 10000000; i++)
+ a *= a;
+}
+void parent(void) {
+ leaf();
+}
+int main(void) {
+ parent();
+ return 0;
+}
+EOF
+
+CFLAGS="-O0 -fno-inline -fno-omit-frame-pointer"
+cc $CFLAGS $TEST_PROGRAM_SOURCE -o $TEST_PROGRAM || exit 1
+
+perf record --call-graph fp -o $PERF_DATA -- $TEST_PROGRAM
+
+# search for the following pattern in perf-script output
+# 734 leaf+0x18 (...)
+# 78b parent+0xb (...)
+# 7a4 main+0xc (...)
+
+perf script -i $PERF_DATA | egrep "[0-9a-f]+ +leaf" -A2 -m1 > $SCRIPT_FILE
+
+egrep -q " +leaf\+0x[0-9a-f]+" $SCRIPT_FILE && \
+egrep -q " +parent\+0x[0-9a-f]+" $SCRIPT_FILE && \
+egrep -q " +main\+0x[0-9a-f]+" $SCRIPT_FILE
+err=$?
+
+echo -n "Check frame pointer call-graphs on Arm64: "
+if [ $err != 0 ]; then
+ echo "FAIL"
+ exit 1
+else
+ echo "PASS"
+fi
+
+exit 0
--
2.25.1
\
 
 \ /
  Last update: 2022-01-25 18:00    [W:0.029 / U:1.320 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site