test-trace.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. 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 , <${tmp} | awk '/traced function calls/ { diff = $1 - upto; upto = $1; printf "%d ", diff < 0 ? -1 : (diff > 0 ? 1 : 0)}')"
  41. if [ "${counts}" != "1 1 0 1 " ]; then
  42. fail "trace collection error: ${counts}"
  43. fi
  44. }
  45. echo "Simple trace test / sanity check using sandbox"
  46. echo
  47. tmp="$(tempfile)"
  48. build_uboot "${TRACE_OPT}"
  49. run_trace >${tmp}
  50. check_results ${tmp}
  51. rm ${tmp}
  52. echo "Test passed"