trace_exit_race.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. # perf trace exit race
  3. # SPDX-License-Identifier: GPL-2.0
  4. # Check that the last events of a perf trace'd subprocess are not
  5. # lost. Specifically, trace the exiting syscall of "true" 10 times and ensure
  6. # the output contains 10 correct lines.
  7. # shellcheck source=lib/probe.sh
  8. . "$(dirname $0)"/lib/probe.sh
  9. skip_if_no_perf_trace || exit 2
  10. [ "$(id -u)" = 0 ] || exit 2
  11. if [ "$1" = "-v" ]; then
  12. verbose="1"
  13. fi
  14. iter=10
  15. regexp=" +[0-9]+\.[0-9]+ [0-9]+ syscalls:sys_enter_exit_group\(\)$"
  16. trace_shutdown_race() {
  17. for _ in $(seq $iter); do
  18. perf trace --no-comm -e syscalls:sys_enter_exit_group true 2>>$file
  19. done
  20. result="$(grep -c -E "$regexp" $file)"
  21. [ $result = $iter ]
  22. }
  23. file=$(mktemp /tmp/temporary_file.XXXXX)
  24. # Do not use whatever ~/.perfconfig file, it may change the output
  25. # via trace.{show_timestamp,show_prefix,etc}
  26. export PERF_CONFIG=/dev/null
  27. trace_shutdown_race
  28. err=$?
  29. if [ $err != 0 ] && [ "${verbose}" = "1" ]; then
  30. lines_not_matching=$(mktemp /tmp/temporary_file.XXXXX)
  31. if grep -v -E "$regexp" $file > $lines_not_matching ; then
  32. echo "Lines not matching the expected regexp: '$regexp':"
  33. cat $lines_not_matching
  34. else
  35. echo "Missing output, expected $iter but only got $result"
  36. fi
  37. rm -f $lines_not_matching
  38. fi
  39. rm -f ${file}
  40. exit $err