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