mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: German Gomez <german.gomez@arm.com>
To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	acme@kernel.org
Cc: German Gomez <german.gomez@arm.com>, Jiri Olsa <jolsa@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>
Subject: [PATCH] perf test: Add shell script test for ARM64 frame-pointer call graphs
Date: Tue, 25 Jan 2022 16:51:32 +0000	[thread overview]
Message-ID: <20220125165133.10198-1-german.gomez@arm.com> (raw)

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


                 reply	other threads:[~2022-01-25 16:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220125165133.10198-1-german.gomez@arm.com \
    --to=german.gomez@arm.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®