xref: /linux/tools/perf/tests/shell/addr2line_inlines.sh (revision bf4afc53b77aeaa48b5409da5c8da6bb4eff7f43)
1#!/bin/bash
2# test addr2line inline unwinding
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7err=0
8test_dir=$(mktemp -d /tmp/perf-test-inline-addr2line.XXXXXXXXXX)
9perf_data="${test_dir}/perf.data"
10perf_script_txt="${test_dir}/perf_script.txt"
11
12cleanup() {
13    rm -rf "${test_dir}"
14    trap - EXIT TERM INT
15}
16
17trap_cleanup() {
18    echo "Unexpected signal in ${FUNCNAME[1]}"
19    cleanup
20    exit 1
21}
22trap trap_cleanup EXIT TERM INT
23
24test_fp() {
25    echo "Inline unwinding fp verification test"
26    # Record data. Currently only dwarf callchains support inlined functions.
27    perf record --call-graph fp -e task-clock:u -o "${perf_data}" -- perf test -w inlineloop 1
28
29    # Check output with inline (default) and srcline
30    perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
31
32    # Expect the leaf and middle functions to occur on lines in the 20s, with
33    # the non-inlined parent function on a line in the 30s.
34    if grep -q "inlineloop.c:2. (inlined)" "${perf_script_txt}" &&
35       grep -q "inlineloop.c:3.$" "${perf_script_txt}"
36    then
37        echo "Inline unwinding fp verification test [Success]"
38    else
39        echo "Inline unwinding fp verification test [Failed missing inlined functions]"
40        err=1
41    fi
42}
43
44test_dwarf() {
45    echo "Inline unwinding dwarf verification test"
46    # Record data. Currently only dwarf callchains support inlined functions.
47    perf record --call-graph dwarf -e task-clock:u -o "${perf_data}" -- perf test -w inlineloop 1
48
49    # Check output with inline (default) and srcline
50    perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
51
52    # Expect the leaf and middle functions to occur on lines in the 20s, with
53    # the non-inlined parent function on a line in the 30s.
54    if grep -q "inlineloop.c:2. (inlined)" "${perf_script_txt}" &&
55       grep -q "inlineloop.c:3.$" "${perf_script_txt}"
56    then
57        echo "Inline unwinding dwarf verification test [Success]"
58    else
59        echo "Inline unwinding dwarf verification test [Failed missing inlined functions]"
60        err=1
61    fi
62}
63
64test_lbr() {
65    echo "Inline unwinding LBR verification test"
66    if [ ! -f /sys/bus/event_source/devices/cpu/caps/branches ] &&
67       [ ! -f /sys/bus/event_source/devices/cpu_core/caps/branches ]
68    then
69        echo "Skip: only x86 CPUs support LBR"
70        return
71    fi
72
73    # Record data. Currently only dwarf callchains support inlined functions.
74    perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- perf test -w inlineloop 1
75
76    # Check output with inline (default) and srcline
77    perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
78
79    # Expect the leaf and middle functions to occur on lines in the 20s, with
80    # the non-inlined parent function on a line in the 30s.
81    if grep -q "inlineloop.c:2. (inlined)" "${perf_script_txt}" &&
82       grep -q "inlineloop.c:3.$" "${perf_script_txt}"
83    then
84        echo "Inline unwinding lbr verification test [Success]"
85    else
86        echo "Inline unwinding lbr verification test [Failed missing inlined functions]"
87        err=1
88    fi
89}
90
91test_fp
92test_dwarf
93test_lbr
94
95cleanup
96exit $err
97