test-trace.sh 1.4 KB

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