xref: /linux/tools/perf/tests/shell/addr2line_inlines.sh (revision c7decec2f2d2ab0366567f9e30c0e1418cece43f)
154a23bffSIan Rogers#!/bin/bash
254a23bffSIan Rogers# test addr2line inline unwinding
354a23bffSIan Rogers# SPDX-License-Identifier: GPL-2.0
454a23bffSIan Rogers
554a23bffSIan Rogersset -e
654a23bffSIan Rogers
754a23bffSIan Rogerserr=0
854a23bffSIan Rogerstest_dir=$(mktemp -d /tmp/perf-test-inline-addr2line.XXXXXXXXXX)
954a23bffSIan Rogersperf_data="${test_dir}/perf.data"
1054a23bffSIan Rogersperf_script_txt="${test_dir}/perf_script.txt"
1154a23bffSIan Rogers
1254a23bffSIan Rogerscleanup() {
1354a23bffSIan Rogers    rm -rf "${test_dir}"
1454a23bffSIan Rogers    trap - EXIT TERM INT
1554a23bffSIan Rogers}
1654a23bffSIan Rogers
1754a23bffSIan Rogerstrap_cleanup() {
1854a23bffSIan Rogers    echo "Unexpected signal in ${FUNCNAME[1]}"
1954a23bffSIan Rogers    cleanup
2054a23bffSIan Rogers    exit 1
2154a23bffSIan Rogers}
2254a23bffSIan Rogerstrap trap_cleanup EXIT TERM INT
2354a23bffSIan Rogers
2428cb835fSIan Rogerstest_fp() {
2528cb835fSIan Rogers    echo "Inline unwinding fp verification test"
2628cb835fSIan Rogers    # Record data. Currently only dwarf callchains support inlined functions.
2728cb835fSIan Rogers    perf record --call-graph fp -e task-clock:u -o "${perf_data}" -- perf test -w inlineloop 1
2828cb835fSIan Rogers
2928cb835fSIan Rogers    # Check output with inline (default) and srcline
3028cb835fSIan Rogers    perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
3128cb835fSIan Rogers
3228cb835fSIan Rogers    # Expect the leaf and middle functions to occur on lines in the 20s, with
3328cb835fSIan Rogers    # the non-inlined parent function on a line in the 30s.
3428cb835fSIan Rogers    if grep -q "inlineloop.c:2. (inlined)" "${perf_script_txt}" &&
3528cb835fSIan Rogers       grep -q "inlineloop.c:3.$" "${perf_script_txt}"
3628cb835fSIan Rogers    then
3728cb835fSIan Rogers        echo "Inline unwinding fp verification test [Success]"
3828cb835fSIan Rogers    else
3928cb835fSIan Rogers        echo "Inline unwinding fp verification test [Failed missing inlined functions]"
4028cb835fSIan Rogers        err=1
4128cb835fSIan Rogers    fi
4228cb835fSIan Rogers}
4328cb835fSIan Rogers
4428cb835fSIan Rogerstest_dwarf() {
4528cb835fSIan Rogers    echo "Inline unwinding dwarf verification test"
4654a23bffSIan Rogers    # Record data. Currently only dwarf callchains support inlined functions.
4754a23bffSIan Rogers    perf record --call-graph dwarf -e task-clock:u -o "${perf_data}" -- perf test -w inlineloop 1
4854a23bffSIan Rogers
4954a23bffSIan Rogers    # Check output with inline (default) and srcline
5054a23bffSIan Rogers    perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
5154a23bffSIan Rogers
5254a23bffSIan Rogers    # Expect the leaf and middle functions to occur on lines in the 20s, with
5354a23bffSIan Rogers    # the non-inlined parent function on a line in the 30s.
5454a23bffSIan Rogers    if grep -q "inlineloop.c:2. (inlined)" "${perf_script_txt}" &&
5554a23bffSIan Rogers       grep -q "inlineloop.c:3.$" "${perf_script_txt}"
5654a23bffSIan Rogers    then
5728cb835fSIan Rogers        echo "Inline unwinding dwarf verification test [Success]"
5854a23bffSIan Rogers    else
5928cb835fSIan Rogers        echo "Inline unwinding dwarf verification test [Failed missing inlined functions]"
6054a23bffSIan Rogers        err=1
6154a23bffSIan Rogers    fi
6254a23bffSIan Rogers}
6354a23bffSIan Rogers
64*446c595dSIan Rogerstest_lbr() {
65*446c595dSIan Rogers    echo "Inline unwinding LBR verification test"
66*446c595dSIan Rogers    if [ ! -f /sys/bus/event_source/devices/cpu/caps/branches ] &&
67*446c595dSIan Rogers       [ ! -f /sys/bus/event_source/devices/cpu_core/caps/branches ]
68*446c595dSIan Rogers    then
69*446c595dSIan Rogers        echo "Skip: only x86 CPUs support LBR"
70*446c595dSIan Rogers        return
71*446c595dSIan Rogers    fi
72*446c595dSIan Rogers
73*446c595dSIan Rogers    # Record data. Currently only dwarf callchains support inlined functions.
74*446c595dSIan Rogers    perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- perf test -w inlineloop 1
75*446c595dSIan Rogers
76*446c595dSIan Rogers    # Check output with inline (default) and srcline
77*446c595dSIan Rogers    perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
78*446c595dSIan Rogers
79*446c595dSIan Rogers    # Expect the leaf and middle functions to occur on lines in the 20s, with
80*446c595dSIan Rogers    # the non-inlined parent function on a line in the 30s.
81*446c595dSIan Rogers    if grep -q "inlineloop.c:2. (inlined)" "${perf_script_txt}" &&
82*446c595dSIan Rogers       grep -q "inlineloop.c:3.$" "${perf_script_txt}"
83*446c595dSIan Rogers    then
84*446c595dSIan Rogers        echo "Inline unwinding lbr verification test [Success]"
85*446c595dSIan Rogers    else
86*446c595dSIan Rogers        echo "Inline unwinding lbr verification test [Failed missing inlined functions]"
87*446c595dSIan Rogers        err=1
88*446c595dSIan Rogers    fi
89*446c595dSIan Rogers}
90*446c595dSIan Rogers
9128cb835fSIan Rogerstest_fp
9228cb835fSIan Rogerstest_dwarf
93*446c595dSIan Rogerstest_lbr
9454a23bffSIan Rogers
9554a23bffSIan Rogerscleanup
9654a23bffSIan Rogersexit $err
97