incremental_test.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. # incremental_test.sh -- test that incremental linking information is correct.
  3. # Copyright (C) 2009-2015 Free Software Foundation, Inc.
  4. # Written by Rafael Avila de Espindola <espindola@google.com>
  5. # and Cary Coutant <ccoutant@google.com>
  6. # This file is part of gold.
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or
  10. # (at your option) any later version.
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. check_cmp()
  20. {
  21. if ! cmp -s "$1" "$2"
  22. then
  23. echo "Actual output differs from expected:"
  24. echo "diff $1 $2"
  25. diff $1 $2
  26. exit 1
  27. fi
  28. }
  29. check()
  30. {
  31. if ! grep -q "$2" "$1"
  32. then
  33. echo "Did not find expected output in $1:"
  34. echo " $2"
  35. echo ""
  36. echo "Actual output below:"
  37. cat "$1"
  38. exit 1
  39. fi
  40. }
  41. # Extract actual command line from linker's -v output.
  42. cat incremental_test.cmdline |
  43. grep "gcctestdir/ld " |
  44. sed "s/--incremental[-a-z]* //g" |
  45. cut -d ' ' -f 2- > actual
  46. # Extract recorded command line from dump of the output file.
  47. cat incremental_test.stdout |
  48. grep "Link command line" |
  49. cut -d : -f 2- |
  50. cut -d ' ' -f 3- |
  51. sed "s/'//g" > recorded
  52. # Verify that the command line was recorded correctly.
  53. check_cmp actual recorded
  54. rm -f actual recorded
  55. # Filter the incremental-dump output into a format that can be grepped
  56. # more easily.
  57. awk '
  58. /^[A-Za-z][A-Za-z ]+:$/ { section = $0; }
  59. /^[[]/ { subsection = $0; }
  60. /^ / { print section, subsection, $0; }
  61. ' < incremental_test.stdout > incremental_test.dump
  62. check incremental_test.dump "Input sections: .* incremental_test_1.o *1 "
  63. check incremental_test.dump "Input sections: .* incremental_test_2.o *1 "
  64. check incremental_test.dump "Global symbol table: .* main .* relocation type "
  65. check incremental_test.dump "Global symbol table: .* a *incremental_test_1.o "
  66. check incremental_test.dump "Global symbol table: .* a .* relocation type "
  67. check incremental_test.dump "Global symbol table: .* b *incremental_test_2.o "
  68. check incremental_test.dump "Global symbol table: .* b .* relocation type "
  69. check incremental_test.dump "Global symbol table: .* t1 *incremental_test_2.o "
  70. check incremental_test.dump "Global symbol table: .* t1 .* relocation type "
  71. rm -f incremental_test.dump
  72. exit 0