test-trace.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (c) 2013 The Chromium OS Authors.
  2. #
  3. # SPDX-License-Identifier: GPL-2.0+
  4. #
  5. # Simple test script for tracing with sandbox
  6. OUTPUT_DIR=sandbox
  7. TRACE_OPT="FTRACE=1"
  8. fail() {
  9. echo "Test failed: $1"
  10. if [ -n ${tmp} ]; then
  11. rm ${tmp}
  12. fi
  13. exit 1
  14. }
  15. build_uboot() {
  16. echo "Build sandbox"
  17. OPTS="O=${OUTPUT_DIR} ${TRACE_OPT}"
  18. NUM_CPUS=$(grep -c processor /proc/cpuinfo)
  19. make ${OPTS} sandbox_config
  20. make ${OPTS} -s -j${NUM_CPUS}
  21. }
  22. run_trace() {
  23. echo "Run trace"
  24. ./${OUTPUT_DIR}/u-boot <<END
  25. trace stats
  26. hash sha256 0 10000
  27. trace pause
  28. trace stats
  29. hash sha256 0 10000
  30. trace stats
  31. trace resume
  32. hash sha256 0 10000
  33. trace pause
  34. trace stats
  35. reset
  36. END
  37. }
  38. check_results() {
  39. echo "Check results"
  40. # Expect sha256 to run 3 times, so we see the string 6 times
  41. if [ $(grep -c sha256 ${tmp}) -ne 6 ]; then
  42. fail "sha256 error"
  43. fi
  44. # 4 sets of results (output of 'trace stats')
  45. if [ $(grep -c "traced function calls" ${tmp}) -ne 4 ]; then
  46. fail "trace output error"
  47. fi
  48. # Check trace counts. We expect to see an increase in the number of
  49. # traced function calls between each 'trace stats' command, except
  50. # between calls 2 and 3, where tracing is paused.
  51. # This code gets the sign of the difference between each number and
  52. # its predecessor.
  53. counts="$(tr -d , <${tmp} | awk '/traced function calls/ { diff = $1 - upto; upto = $1; printf "%d ", diff < 0 ? -1 : (diff > 0 ? 1 : 0)}')"
  54. if [ "${counts}" != "1 1 0 1 " ]; then
  55. fail "trace collection error: ${counts}"
  56. fi
  57. }
  58. echo "Simple trace test / sanity check using sandbox"
  59. echo
  60. tmp="$(tempfile)"
  61. build_uboot
  62. run_trace >${tmp}
  63. check_results ${tmp}
  64. rm ${tmp}
  65. echo "Test passed"