xref: /linux/tools/perf/tests/shell/addr2line_inlines.sh (revision e716e69cf67bb45c49653b884f88d8e97f454f50)
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_fp
65test_dwarf
66
67cleanup
68exit $err
69