annotate.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. echo "Basic perf annotate test"
  29. if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null
  30. then
  31. echo "Basic annotate [Failed: perf record]"
  32. err=1
  33. return
  34. fi
  35. # Generate the annotated output file
  36. perf annotate -i "${perfdata}" --stdio 2> /dev/null > "${perfout}"
  37. # check if it has the target symbol
  38. if ! grep "${testsym}" "${perfout}"
  39. then
  40. echo "Basic annotate [Failed: missing target symbol]"
  41. err=1
  42. return
  43. fi
  44. # check if it has the disassembly lines
  45. if ! grep "${disasm_regex}" "${perfout}"
  46. then
  47. echo "Basic annotate [Failed: missing disasm output from default disassembler]"
  48. err=1
  49. return
  50. fi
  51. # check again with a target symbol name
  52. if ! perf annotate -i "${perfdata}" "${testsym}" 2> /dev/null | \
  53. grep -m 3 "${disasm_regex}"
  54. then
  55. echo "Basic annotate [Failed: missing disasm output when specifying the target symbol]"
  56. err=1
  57. return
  58. fi
  59. # check one more with external objdump tool (forced by --objdump option)
  60. if ! perf annotate -i "${perfdata}" --objdump=objdump 2> /dev/null | \
  61. grep -m 3 "${disasm_regex}"
  62. then
  63. echo "Basic annotate [Failed: missing disasm output from non default disassembler (using --objdump)]"
  64. err=1
  65. return
  66. fi
  67. echo "Basic annotate test [Success]"
  68. }
  69. test_basic
  70. cleanup
  71. exit $err