pipe_test.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. # perf pipe recording and injection test
  3. # SPDX-License-Identifier: GPL-2.0
  4. shelldir=$(dirname "$0")
  5. # shellcheck source=lib/perf_has_symbol.sh
  6. . "${shelldir}"/lib/perf_has_symbol.sh
  7. sym="noploop"
  8. skip_test_missing_symbol ${sym}
  9. data=$(mktemp /tmp/perf.data.XXXXXX)
  10. data2=$(mktemp /tmp/perf.data2.XXXXXX)
  11. prog="perf test -w noploop"
  12. err=0
  13. set -e
  14. cleanup() {
  15. rm -rf "${data}"
  16. rm -rf "${data}".old
  17. rm -rf "${data2}"
  18. rm -rf "${data2}".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_record_report() {
  28. echo
  29. echo "Record+report pipe test"
  30. task="perf"
  31. if ! perf record -e task-clock:u -o - ${prog} | perf report -i - --task | grep -q ${task}
  32. then
  33. echo "Record+report pipe test [Failed - cannot find the test file in the perf report #1]"
  34. err=1
  35. return
  36. fi
  37. if ! perf record -g -e task-clock:u -o - ${prog} | perf report -i - --task | grep -q ${task}
  38. then
  39. echo "Record+report pipe test [Failed - cannot find the test file in the perf report #2]"
  40. err=1
  41. return
  42. fi
  43. perf record -g -e task-clock:u -o - ${prog} > ${data}
  44. if ! perf report -i ${data} --task | grep -q ${task}
  45. then
  46. echo "Record+report pipe test [Failed - cannot find the test file in the perf report #3]"
  47. err=1
  48. return
  49. fi
  50. echo "Record+report pipe test [Success]"
  51. }
  52. test_inject_bids() {
  53. inject_opt=$1
  54. echo
  55. echo "Inject ${inject_opt} build-ids test"
  56. if ! perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt}| perf report -i - | grep -q ${sym}
  57. then
  58. echo "Inject build-ids test [Failed - cannot find noploop function in pipe #1]"
  59. err=1
  60. return
  61. fi
  62. if ! perf record -g -e task-clock:u -o - ${prog} | perf inject ${inject_opt} | perf report -i - | grep -q ${sym}
  63. then
  64. echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #2]"
  65. err=1
  66. return
  67. fi
  68. perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt} -o ${data}
  69. if ! perf report -i ${data} | grep -q ${sym}; then
  70. echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #3]"
  71. err=1
  72. return
  73. fi
  74. perf record -e task-clock:u -o ${data} ${prog}
  75. if ! perf inject ${inject_opt} -i ${data} | perf report -i - | grep -q ${sym}; then
  76. echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #4]"
  77. err=1
  78. return
  79. fi
  80. perf record -e task-clock:u -o - ${prog} > ${data}
  81. if ! perf inject ${inject_opt} -i ${data} | perf report -i - | grep -q ${sym}; then
  82. echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #5]"
  83. err=1
  84. return
  85. fi
  86. perf record -e task-clock:u -o - ${prog} > ${data}
  87. perf inject ${inject_opt} -i ${data} -o ${data2}
  88. if ! perf report -i ${data2} | grep -q ${sym}; then
  89. echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #6]"
  90. err=1
  91. return
  92. fi
  93. echo "Inject ${inject_opt} build-ids test [Success]"
  94. }
  95. test_record_report
  96. test_inject_bids -B
  97. test_inject_bids -b
  98. test_inject_bids --buildid-all
  99. test_inject_bids --mmap2-buildid-all
  100. cleanup
  101. exit $err