xref: /linux/tools/perf/tests/shell/annotate.sh (revision 22c55fb9eb92395d999b8404d73e58540d11bdd8)
1#!/bin/bash
2# perf annotate basic tests
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7shelldir=$(dirname "$0")
8
9# shellcheck source=lib/perf_has_symbol.sh
10. "${shelldir}"/lib/perf_has_symbol.sh
11
12testsym="noploop"
13
14skip_test_missing_symbol ${testsym}
15
16err=0
17perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
18perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX)
19testprog="perf test -w noploop"
20# disassembly format: "percent : offset: instruction (operands ...)"
21disasm_regex="[0-9]*\.[0-9]* *: *\w*: *\w*"
22
23cleanup() {
24  rm -rf "${perfdata}" "${perfout}"
25  rm -rf "${perfdata}".old
26
27  trap - EXIT TERM INT
28}
29
30trap_cleanup() {
31  echo "Unexpected signal in ${FUNCNAME[1]}"
32  cleanup
33  exit 1
34}
35trap trap_cleanup EXIT TERM INT
36
37test_basic() {
38  mode=$1
39  echo "${mode} perf annotate test"
40  if [ "x${mode}" == "xBasic" ]
41  then
42    perf record -o "${perfdata}" ${testprog} 2> /dev/null
43  else
44    perf record -o - ${testprog} 2> /dev/null > "${perfdata}"
45  fi
46  if [ "x$?" != "x0" ]
47  then
48    echo "${mode} annotate [Failed: perf record]"
49    err=1
50    return
51  fi
52
53  # Generate the annotated output file
54  if [ "x${mode}" == "xBasic" ]
55  then
56    perf annotate --no-demangle -i "${perfdata}" --stdio --percent-limit 10 2> /dev/null > "${perfout}"
57  else
58    perf annotate --no-demangle -i - --stdio 2> /dev/null --percent-limit 10 < "${perfdata}" > "${perfout}"
59  fi
60
61  # check if it has the target symbol
62  if ! grep -q "${testsym}" "${perfout}"
63  then
64    echo "${mode} annotate [Failed: missing target symbol]"
65    cat "${perfout}"
66    err=1
67    return
68  fi
69
70  # check if it has the disassembly lines
71  if ! grep -q "${disasm_regex}" "${perfout}"
72  then
73    echo "${mode} annotate [Failed: missing disasm output from default disassembler]"
74    err=1
75    return
76  fi
77
78  # check again with a target symbol name
79  if [ "x${mode}" == "xBasic" ]
80  then
81    perf annotate --no-demangle -i "${perfdata}" "${testsym}" 2> /dev/null > "${perfout}"
82  else
83    perf annotate --no-demangle -i - "${testsym}" 2> /dev/null < "${perfdata}" > "${perfout}"
84  fi
85
86  if ! head -250 "${perfout}"| grep -q -m 3 "${disasm_regex}"
87  then
88    echo "${mode} annotate [Failed: missing disasm output when specifying the target symbol]"
89    err=1
90    return
91  fi
92
93  # check one more with external objdump tool (forced by --objdump option)
94  if [ "x${mode}" == "xBasic" ]
95  then
96    perf annotate --no-demangle -i "${perfdata}" --percent-limit 10 --objdump=objdump 2> /dev/null > "${perfout}"
97  else
98    perf annotate --no-demangle -i - "${testsym}" --percent-limit 10 --objdump=objdump 2> /dev/null < "${perfdata}" > "${perfout}"
99  fi
100  if ! grep -q -m 3 "${disasm_regex}" "${perfout}"
101  then
102    echo "${mode} annotate [Failed: missing disasm output from non default disassembler (using --objdump)]"
103    err=1
104    return
105  fi
106  echo "${mode} annotate test [Success]"
107}
108
109test_basic Basic
110test_basic Pipe
111
112cleanup
113exit $err
114