summaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/shell/annotate.sh
blob: 1db1e8113d9943a6e4cab65454df858e2e049367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
# perf annotate basic tests
# SPDX-License-Identifier: GPL-2.0

set -e

shelldir=$(dirname "$0")

# shellcheck source=lib/perf_has_symbol.sh
. "${shelldir}"/lib/perf_has_symbol.sh

testsym="noploop"

skip_test_missing_symbol ${testsym}

err=0
perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
testprog="perf test -w noploop"
# disassembly format: "percent : offset: instruction (operands ...)"
disasm_regex="[0-9]*\.[0-9]* *: *\w*: *\w*"

cleanup() {
  rm -rf "${perfdata}"
  rm -rf "${perfdata}".old

  trap - EXIT TERM INT
}

trap_cleanup() {
  cleanup
  exit 1
}
trap trap_cleanup EXIT TERM INT

test_basic() {
  echo "Basic perf annotate test"
  if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null
  then
    echo "Basic annotate [Failed: perf record]"
    err=1
    return
  fi

  # check if it has the target symbol
  if ! perf annotate -i "${perfdata}" 2> /dev/null | grep "${testsym}"
  then
    echo "Basic annotate [Failed: missing target symbol]"
    err=1
    return
  fi

  # check if it has the disassembly lines
  if ! perf annotate -i "${perfdata}" 2> /dev/null | grep "${disasm_regex}"
  then
    echo "Basic annotate [Failed: missing disasm output from default disassembler]"
    err=1
    return
  fi

  # check again with a target symbol name
  if ! perf annotate -i "${perfdata}" "${testsym}" 2> /dev/null | \
	  grep -m 3 "${disasm_regex}"
  then
    echo "Basic annotate [Failed: missing disasm output when specifying the target symbol]"
    err=1
    return
  fi

  # check one more with external objdump tool (forced by --objdump option)
  if ! perf annotate -i "${perfdata}" --objdump=objdump 2> /dev/null | \
	  grep -m 3 "${disasm_regex}"
  then
    echo "Basic annotate [Failed: missing disasm output from non default disassembler (using --objdump)]"
    err=1
    return
  fi
  echo "Basic annotate test [Success]"
}

test_basic

cleanup
exit $err