test-trace.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (c) 2013 The Chromium OS Authors.
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License as
  5. # published by the Free Software Foundation; either version 2 of
  6. # the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  16. # MA 02111-1307 USA
  17. #
  18. # Simple test script for tracing with sandbox
  19. OUTPUT_DIR=sandbox
  20. TRACE_OPT="FTRACE=1"
  21. fail() {
  22. echo "Test failed: $1"
  23. if [ -n ${tmp} ]; then
  24. rm ${tmp}
  25. fi
  26. exit 1
  27. }
  28. build_uboot() {
  29. echo "Build sandbox"
  30. OPTS="O=${OUTPUT_DIR} ${TRACE_OPT}"
  31. NUM_CPUS=$(grep -c processor /proc/cpuinfo)
  32. make ${OPTS} sandbox_config
  33. make ${OPTS} -s -j${NUM_CPUS}
  34. }
  35. run_trace() {
  36. echo "Run trace"
  37. ./${OUTPUT_DIR}/u-boot <<END
  38. trace stats
  39. hash sha256 0 10000
  40. trace pause
  41. trace stats
  42. hash sha256 0 10000
  43. trace stats
  44. trace resume
  45. hash sha256 0 10000
  46. trace pause
  47. trace stats
  48. reset
  49. END
  50. }
  51. check_results() {
  52. echo "Check results"
  53. # Expect sha256 to run 3 times, so we see the string 6 times
  54. if [ $(grep -c sha256 ${tmp}) -ne 6 ]; then
  55. fail "sha256 error"
  56. fi
  57. # 4 sets of results (output of 'trace stats')
  58. if [ $(grep -c "traced function calls" ${tmp}) -ne 4 ]; then
  59. fail "trace output error"
  60. fi
  61. # Check trace counts. We expect to see an increase in the number of
  62. # traced function calls between each 'trace stats' command, except
  63. # between calls 2 and 3, where tracing is paused.
  64. # This code gets the sign of the difference between each number and
  65. # its predecessor.
  66. counts="$(tr -d , <${tmp} | awk '/traced function calls/ { diff = $1 - upto; upto = $1; printf "%d ", diff < 0 ? -1 : (diff > 0 ? 1 : 0)}')"
  67. if [ "${counts}" != "1 1 0 1 " ]; then
  68. fail "trace collection error: ${counts}"
  69. fi
  70. }
  71. echo "Simple trace test / sanity check using sandbox"
  72. echo
  73. tmp="$(tempfile)"
  74. build_uboot
  75. run_trace >${tmp}
  76. check_results ${tmp}
  77. rm ${tmp}
  78. echo "Test passed"