tst-gmon-gprof.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. # Check the output of gprof against a carfully crafted binary.
  3. # Copyright (C) 2017-2026 Free Software Foundation, Inc.
  4. # This file is part of the GNU C Library.
  5. # The GNU C Library is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 2.1 of the License, or (at your option) any later version.
  9. # The GNU C Library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. # You should have received a copy of the GNU Lesser General Public
  14. # License along with the GNU C Library; if not, see
  15. # <https://www.gnu.org/licenses/>.
  16. LC_ALL=C
  17. export LC_ALL
  18. set -e
  19. exec 2>&1
  20. GPROF="$1"
  21. program="$2"
  22. data="$3"
  23. actual=$(mktemp)
  24. expected=$(mktemp)
  25. expected_dot=$(mktemp)
  26. cleanup () {
  27. rm -f "$actual"
  28. rm -f "$expected"
  29. rm -f "$expected_dot"
  30. }
  31. trap cleanup 0
  32. cat > "$expected" <<EOF
  33. f1 2000
  34. f2 1000
  35. f3 1
  36. EOF
  37. # Special version for powerpc with function descriptors.
  38. cat > "$expected_dot" <<EOF
  39. .f1 2000
  40. .f2 1000
  41. .f3 1
  42. EOF
  43. "$GPROF" -C "$program" "$data" \
  44. | awk -F '[(): ]' '/executions/{print $5, $8}' \
  45. | sort > "$actual"
  46. if cmp -s "$actual" "$expected_dot" \
  47. || diff -u --label expected "$expected" --label actual "$actual" ; then
  48. echo "PASS"
  49. else
  50. echo "FAIL"
  51. exit 1
  52. fi