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