perf test: Record only user callchains on the "Check Arm64 callgraphs are complete...
[linux-2.6-block.git] / tools / perf / tests / shell / test_arm_callgraph_fp.sh
1 #!/bin/sh
2 # Check Arm64 callgraphs are complete in fp mode
3 # SPDX-License-Identifier: GPL-2.0
4
5 lscpu | grep -q "aarch64" || exit 2
6
7 if ! [ -x "$(command -v cc)" ]; then
8         echo "failed: no compiler, install gcc"
9         exit 2
10 fi
11
12 PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
13 TEST_PROGRAM_SOURCE=$(mktemp /tmp/test_program.XXXXX.c)
14 TEST_PROGRAM=$(mktemp /tmp/test_program.XXXXX)
15
16 cleanup_files()
17 {
18         rm -f $PERF_DATA
19         rm -f $TEST_PROGRAM_SOURCE
20         rm -f $TEST_PROGRAM
21 }
22
23 trap cleanup_files exit term int
24
25 cat << EOF > $TEST_PROGRAM_SOURCE
26 int a = 0;
27 void leaf(void) {
28   for (;;)
29     a += a;
30 }
31 void parent(void) {
32   leaf();
33 }
34 int main(void) {
35   parent();
36   return 0;
37 }
38 EOF
39
40 echo " + Compiling test program ($TEST_PROGRAM)..."
41
42 CFLAGS="-g -O0 -fno-inline -fno-omit-frame-pointer"
43 cc $CFLAGS $TEST_PROGRAM_SOURCE -o $TEST_PROGRAM || exit 1
44
45 # Add a 1 second delay to skip samples that are not in the leaf() function
46 perf record -o $PERF_DATA --call-graph fp -e cycles//u -D 1000 --user-callchains -- $TEST_PROGRAM 2> /dev/null &
47 PID=$!
48
49 echo " + Recording (PID=$PID)..."
50 sleep 2
51 echo " + Stopping perf-record..."
52
53 kill $PID
54 wait $PID
55
56 # expected perf-script output:
57 #
58 # program
59 #       728 leaf
60 #       753 parent
61 #       76c main
62 # ...
63
64 perf script -i $PERF_DATA -F comm,ip,sym | head -n4
65 perf script -i $PERF_DATA -F comm,ip,sym | head -n4 | \
66         awk '{ if ($2 != "") sym[i++] = $2 } END { if (sym[0] != "leaf" ||
67                                                        sym[1] != "parent" ||
68                                                        sym[2] != "main") exit 1 }'