btest-gcc.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #!/bin/sh
  2. # Test GCC.
  3. # Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006, 2009, 2012
  4. # Free Software Foundation, Inc.
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program 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
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; see the file COPYING3. If not see
  15. # <http://www.gnu.org/licenses/>.
  16. # INPUT:
  17. # btest <options> <target> <source> <prefix> <state> <build>
  18. add_passes_despite_regression=0
  19. dashj=''
  20. # <options> can be
  21. # --add-passes-despite-regression:
  22. # Add new "PASSes" despite there being some regressions.
  23. # -j<n>:
  24. # Pass '-j<n>' to make.
  25. case "$1" in
  26. --add-passes-despite-regression)
  27. add_passes_despite_regression=1; shift;;
  28. -j*)
  29. dashj=$1; shift;;
  30. -*) echo "Invalid option: $1"; exit 2;;
  31. esac
  32. # TARGET is the target triplet. It should be the same one as used in
  33. # constructing PREFIX. Or it can be the keyword 'native', indicating
  34. # a target of whatever platform the script is running on.
  35. TARGET=$1
  36. # SOURCE is the directory containing the toplevel configure.
  37. SOURCE=$2
  38. # PREFIX is the directory for the --prefix option to configure.
  39. # For cross compilers, it needs to contain header files,
  40. # libraries, and binutils. PATH should probably include
  41. # $PREFIX/bin.
  42. PREFIX=$3
  43. # This script also needs to include the GDB testsuite in
  44. # $PREFIX/share/gdb-testsuite.
  45. GDB_TESTSUITE=$PREFIX/share/gdb-testsuite
  46. # STATE is where the tester maintains its internal state,
  47. # described below.
  48. STATE=$4
  49. # BUILD is a temporary directory that this script will
  50. # delete and recreate, containing the build tree.
  51. BUILD=$5
  52. # you also probably need to set these variables:
  53. # PATH: should contain a native gcc, and a cross gdb.
  54. # DEJAGNU: should point to a site.exp suitable for testing
  55. # the compiler and debugger.
  56. # OUTPUT: in $RESULT, one of the following keywords:
  57. # error the script failed due to
  58. # a misconfiguration or resource limitation
  59. # build the build failed
  60. # regress-<n> the build succeeded, but there were <n>
  61. # testsuite regressions, listed in $REGRESS
  62. # pass build succeeded and there were no regressions
  63. RESULT=$STATE/RESULT
  64. # in BUILD_LOG, the output of the build
  65. BUILD_LOG=$STATE/build_log
  66. # in FAILED, a list of failing testcases
  67. FAILED=$STATE/failed
  68. # in PASSES, the list of testcases we expect to pass
  69. PASSES=$STATE/passes
  70. # in REGRESS, a list of testcases we expected to pass but that failed
  71. REGRESS=$STATE/regress
  72. # Make sure various files exist.
  73. [ -d $STATE ] || mkdir $STATE
  74. [ -f $PASSES ] || touch $PASSES
  75. # These lines should stay in this order, because
  76. # that way if something is badly wrong and $RESULT can't
  77. # be modified then cron will mail the error message.
  78. # The reverse order could lead to the testsuite claiming that
  79. # everything always passes, without running any tests.
  80. echo error > $RESULT || exit 1
  81. exec > $BUILD_LOG 2>&1 || exit 1
  82. set -x
  83. # Nuke $BUILD and recreate it.
  84. rm -rf $BUILD $REGRESS $FAILED
  85. mkdir $BUILD || exit 1
  86. cd $BUILD || exit 1
  87. H_BUILD=`$SOURCE/config.guess || exit 1`
  88. H_HOST=$H_BUILD
  89. if [ $TARGET = native ] ; then
  90. H_TARGET=$H_HOST
  91. else
  92. H_TARGET=$TARGET
  93. fi
  94. H_REAL_TARGET=`$SOURCE/config.sub $H_TARGET || exit 1`
  95. # TESTLOGS is the list of dejagnu .sum files that the tester should
  96. # look at.
  97. TESTLOGS="gcc/testsuite/gcc/gcc.sum
  98. gcc/testsuite/g++/g++.sum
  99. gcc/testsuite/objc/objc.sum"
  100. # Build.
  101. echo build > $RESULT
  102. if [ $H_HOST = $H_TARGET ] ; then
  103. $SOURCE/configure --prefix=$PREFIX --target=$H_TARGET || exit 1
  104. if ! make $dashj bootstrap ; then
  105. [ -s .bad_compare ] || exit 1
  106. cat .bad_compare >> $REGRESS || exit 1
  107. touch compare || exit 1 # Prevent the comparison from running again
  108. make $dashj all || exit 1
  109. fi
  110. else
  111. withopt="--with-gnu-ld --with-gnu-as"
  112. case "$H_TARGET" in
  113. *-linux*) ;;
  114. *) withopt="$withopt --with-newlib";;
  115. esac
  116. $SOURCE/configure --prefix=$PREFIX --target=$H_TARGET $withopt || exit 1
  117. make $dashj || exit 1
  118. fi
  119. echo error > $RESULT || exit 1
  120. # Test GCC against its internal testsuite.
  121. make $dashj -k check
  122. if [ -f gcc/testsuite/gfortran/gfortran.sum ] ; then
  123. TESTLOGS="$TESTLOGS gcc/testsuite/gfortran/gfortran.sum"
  124. fi
  125. if [ -f $BUILD/$H_TARGET/libstdc++-v3/testsuite/libstdc++.sum ] ; then
  126. TESTLOGS="$TESTLOGS $H_TARGET/libstdc++-v3/testsuite/libstdc++.sum"
  127. fi
  128. if [ -f $BUILD/$H_TARGET/libffi/testsuite/libffi.sum ] ; then
  129. TESTLOGS="$TESTLOGS $H_TARGET/libffi/testsuite/libffi.sum"
  130. fi
  131. if [ -f $BUILD/$H_TARGET/libjava/testsuite/libjava.sum ] ; then
  132. TESTLOGS="$TESTLOGS $H_TARGET/libjava/testsuite/libjava.sum"
  133. fi
  134. if [ -f $BUILD/$H_TARGET/libgomp/testsuite/libgomp.sum ] ; then
  135. TESTLOGS="$TESTLOGS $H_TARGET/libgomp/testsuite/libgomp.sum"
  136. fi
  137. if [ -f $BUILD/$H_TARGET/libmudflap/testsuite/libmudflap.sum ] ; then
  138. TESTLOGS="$TESTLOGS $H_TARGET/libmudflap/testsuite/libmudflap.sum"
  139. fi
  140. # Test the just-built GCC with the GDB testsuite.
  141. if [ -d $GDB_TESTSUITE ] ; then
  142. mkdir test-gdb || exit 1
  143. cd $GDB_TESTSUITE || exit 1
  144. for i in gdb.* ; do
  145. if [ -d $i ] ; then
  146. mkdir $BUILD/test-gdb/$i
  147. fi
  148. done
  149. cd $BUILD/test-gdb || exit 1
  150. echo "set host_alias $H_HOST" > site.exp
  151. echo "set host_triplet $H_HOST" >> site.exp
  152. echo "set target_alias $H_TARGET" >> site.exp
  153. echo "set target_triplet $H_REAL_TARGET" >> site.exp
  154. echo "set build_alias $H_BUILD" >> site.exp
  155. echo "set build_triplet $H_BUILD" >> site.exp
  156. echo "set srcdir $GDB_TESTSUITE" >> site.exp
  157. runtest --tool gdb
  158. TESTLOGS="$TESTLOGS test-gdb/gdb.sum"
  159. fi
  160. # Sanity-check the testlogs. They should contain at least one PASS.
  161. cd $BUILD || exit 1
  162. for LOG in $TESTLOGS ; do
  163. if ! grep ^PASS: $LOG > /dev/null ; then
  164. echo build > $RESULT
  165. exit 1
  166. fi
  167. done
  168. # Work out what failed
  169. for LOG in $TESTLOGS ; do
  170. L=`basename $LOG`
  171. awk '/^FAIL: / { print "'$L'",$2; }' $LOG || exit 1
  172. done | sort | uniq > $FAILED || exit 1
  173. comm -12 $FAILED $PASSES >> $REGRESS || exit 1
  174. NUMREGRESS=`wc -l < $REGRESS | tr -d ' '`
  175. if [ $NUMREGRESS -eq 0 ] || [ $add_passes_despite_regression -ne 0 ] ; then
  176. # Update the state.
  177. for LOG in $TESTLOGS ; do
  178. L=`basename $LOG`
  179. awk '/^PASS: / { print "'$L'",$2; }' $LOG || exit 1
  180. done | sort | uniq | comm -23 - $FAILED > ${PASSES}~ || exit 1
  181. [ -s ${PASSES}~ ] || exit 1
  182. if [ $NUMREGRESS -ne 0 ] ; then
  183. # The way we keep track of new PASSes when in "regress-N" for
  184. # --add-passes-despite-regression, is to *add* them to previous
  185. # PASSes. Just as without this option, we don't forget *any* PASS
  186. # lines, because besides the ones in $REGRESS that we definitely
  187. # don't want to lose, their removal or rename may have been a
  188. # mistake (as in, the cause of the "regress-N" state). If they
  189. # come back, we then know they're regressions.
  190. cat ${PASSES}~ ${PASSES} | sort -u > ${PASSES}~~
  191. mv ${PASSES}~~ ${PASSES} || exit 1
  192. rm ${PASSES}~ || exit 1
  193. else
  194. # In contrast to the merging for "regress-N", we just overwrite
  195. # the known PASSes when in the "pass" state, so we get rid of
  196. # stale PASS lines for removed, moved or otherwise changed tests
  197. # which may be added back with a different meaning later on.
  198. mv ${PASSES}~ ${PASSES} || exit 1
  199. fi
  200. fi
  201. if [ $NUMREGRESS -ne 0 ] ; then
  202. echo regress-$NUMREGRESS > $RESULT
  203. exit 1
  204. fi
  205. echo pass > $RESULT
  206. exit 0