annotate.sh 2.8 KB

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