xref: /linux/tools/perf/tests/shell/addr2line_inlines.sh (revision 1672f3707a6ef4b386c30bb76df2f62e58a39430)
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_inlinedloop() {
25    echo "Inline unwinding verification test"
26    # Record data. Currently only dwarf callchains support inlined functions.
27    perf record --call-graph dwarf -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 verification test [Success]"
38    else
39        echo "Inline unwinding verification test [Failed missing inlined functions]"
40        err=1
41    fi
42}
43
44test_inlinedloop
45
46cleanup
47exit $err
48