4 # Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006, 2009
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/>.
22 # btest <options> <target> <source> <prefix> <state> <build>
24 add_passes_despite_regression=0
28 # --add-passes-despite-regression:
29 # Add new "PASSes" despite there being some regressions.
31 # Pass '-j<n>' to make.
34 --add-passes-despite-regression)
35 add_passes_despite_regression=1; shift;;
38 -*) echo "Invalid option: $1"; exit 2;;
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.
45 # SOURCE is the directory containing the toplevel configure.
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
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,
61 # BUILD is a temporary directory that this script will
62 # delete and recreate, containing the build tree.
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
79 # in BUILD_LOG, the output of the build
80 BUILD_LOG=$STATE/build_log
81 # in FAILED, a list of failing testcases
83 # in PASSES, the list of testcases we expect to pass
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
102 # Nuke $BUILD and recreate it.
103 rm -rf $BUILD $REGRESS $FAILED
104 mkdir $BUILD || exit 1
107 H_BUILD=`$SOURCE/config.guess || exit 1`
109 if [ $TARGET = native ] ; then
114 H_REAL_TARGET=`$SOURCE/config.sub $H_TARGET || exit 1`
116 # TESTLOGS is the list of dejagnu .sum files that the tester should
118 TESTLOGS="gcc/testsuite/gcc/gcc.sum
119 gcc/testsuite/g++/g++.sum
120 gcc/testsuite/gfortran/gfortran.sum
121 gcc/testsuite/objc/objc.sum"
125 if [ $H_HOST = $H_TARGET ] ; then
126 $SOURCE/configure --prefix=$PREFIX --target=$H_TARGET || exit 1
127 if ! make $dashj bootstrap ; then
128 [ -s .bad_compare ] || exit 1
129 cat .bad_compare >> $REGRESS || exit 1
130 touch compare || exit 1 # Prevent the comparison from running again
131 make $dashj all || exit 1
134 withopt="--with-gnu-ld --with-gnu-as"
137 *) withopt="$withopt --with-newlib";;
139 $SOURCE/configure --prefix=$PREFIX --target=$H_TARGET $withopt || exit 1
140 make $dashj || exit 1
142 echo error > $RESULT || exit 1
144 # Test GCC against its internal testsuite.
147 if [ -f $BUILD/$H_TARGET/libstdc++-v3/testsuite/libstdc++.sum ] ; then
148 TESTLOGS="$TESTLOGS $H_TARGET/libstdc++-v3/testsuite/libstdc++.sum"
151 if [ -f $BUILD/$H_TARGET/libffi/testsuite/libffi.sum ] ; then
152 TESTLOGS="$TESTLOGS $H_TARGET/libffi/testsuite/libffi.sum"
155 if [ -f $BUILD/$H_TARGET/libjava/testsuite/libjava.sum ] ; then
156 TESTLOGS="$TESTLOGS $H_TARGET/libjava/testsuite/libjava.sum"
159 if [ -f $BUILD/$H_TARGET/libgomp/testsuite/libgomp.sum ] ; then
160 TESTLOGS="$TESTLOGS $H_TARGET/libgomp/testsuite/libgomp.sum"
163 # Test the just-built GCC with the GDB testsuite.
164 if [ -d $GDB_TESTSUITE ] ; then
165 mkdir test-gdb || exit 1
166 cd $GDB_TESTSUITE || exit 1
169 mkdir $BUILD/test-gdb/$i
172 cd $BUILD/test-gdb || exit 1
173 echo "set host_alias $H_HOST" > site.exp
174 echo "set host_triplet $H_HOST" >> site.exp
175 echo "set target_alias $H_TARGET" >> site.exp
176 echo "set target_triplet $H_REAL_TARGET" >> site.exp
177 echo "set build_alias $H_BUILD" >> site.exp
178 echo "set build_triplet $H_BUILD" >> site.exp
179 echo "set srcdir $GDB_TESTSUITE" >> site.exp
181 TESTLOGS="$TESTLOGS test-gdb/gdb.sum"
184 # Sanity-check the testlogs. They should contain at least one PASS.
186 for LOG in $TESTLOGS ; do
187 if ! grep ^PASS: $LOG > /dev/null ; then
193 # Work out what failed
194 for LOG in $TESTLOGS ; do
196 awk '/^FAIL: / { print "'$L'",$2; }' $LOG || exit 1
197 done | sort | uniq > $FAILED || exit 1
198 comm -12 $FAILED $PASSES >> $REGRESS || exit 1
199 NUMREGRESS=`wc -l < $REGRESS | tr -d ' '`
201 if [ $NUMREGRESS -eq 0 ] || [ $add_passes_despite_regression -ne 0 ] ; then
203 for LOG in $TESTLOGS ; do
205 awk '/^PASS: / { print "'$L'",$2; }' $LOG || exit 1
206 done | sort | uniq | comm -23 - $FAILED > ${PASSES}~ || exit 1
207 [ -s ${PASSES}~ ] || exit 1
208 if [ $NUMREGRESS -ne 0 ] ; then
209 # The way we keep track of new PASSes when in "regress-N" for
210 # --add-passes-despite-regression, is to *add* them to previous
211 # PASSes. Just as without this option, we don't forget *any* PASS
212 # lines, because besides the ones in $REGRESS that we definitely
213 # don't want to lose, their removal or rename may have been a
214 # mistake (as in, the cause of the "regress-N" state). If they
215 # come back, we then know they're regressions.
216 cat ${PASSES}~ ${PASSES} | sort -u > ${PASSES}~~
217 mv ${PASSES}~~ ${PASSES} || exit 1
218 rm ${PASSES}~ || exit 1
220 # In contrast to the merging for "regress-N", we just overwrite
221 # the known PASSes when in the "pass" state, so we get rid of
222 # stale PASS lines for removed, moved or otherwise changed tests
223 # which may be added back with a different meaning later on.
224 mv ${PASSES}~ ${PASSES} || exit 1
228 if [ $NUMREGRESS -ne 0 ] ; then
229 echo regress-$NUMREGRESS > $RESULT