OSDN Git Service

2003-09-18 Andreas Tobler <a.tobler@schweiz.ch>
[pf3gnuchains/gcc-fork.git] / contrib / regression / btest-gcc.sh
1 #!/bin/sh
2
3 #  Test GCC.
4 #  Copyright (C) 1999, 2000, 2001, 2002  Free Software Foundation, Inc.
5
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.
10
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
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 # INPUT:
21 # btest <target> <source> <prefix> <state> <build>
22 # TARGET is the target triplet.  It should be the same one as used in
23 # constructing PREFIX.  Or it can be the keyword 'native', indicating
24 # a target of whatever platform the script is running on.
25 TARGET=$1
26 # SOURCE is the directory containing the toplevel configure.
27 SOURCE=$2
28
29 # PREFIX is the directory for the --prefix option to configure.
30 #   For cross compilers, it needs to contain header files,
31 #   libraries, and binutils.  PATH should probably include
32 #   $PREFIX/bin.  
33 PREFIX=$3
34 # This script also needs to include the GDB testsuite in
35 #   $PREFIX/share/gdb-testsuite.
36 GDB_TESTSUITE=$PREFIX/share/gdb-testsuite
37
38 # STATE is where the tester maintains its internal state,
39 #   described below.
40 STATE=$4
41
42 # BUILD is a temporary directory that this script will
43 #   delete and recreate, containing the build tree.
44 BUILD=$5
45
46 # you also probably need to set these variables:
47 # PATH: should contain a native gcc, and a cross gdb.
48 # DEJAGNU: should point to a site.exp suitable for testing
49 #   the compiler and debugger.
50
51
52 # OUTPUT: in $RESULT, one of the following keywords:
53 #   error       the script failed due to
54 #               a misconfiguration or resource limitation
55 #   build       the build failed
56 #   regress-<n> the build succeeded, but there were <n>
57 #               testsuite regressions, listed in $REGRESS
58 #   pass        build succeeded and there were no regressions
59 RESULT=$STATE/RESULT
60 # in BUILD_LOG, the output of the build
61 BUILD_LOG=$STATE/build_log
62 # in FAILED, a list of failing testcases
63 FAILED=$STATE/failed
64 # in PASSES, the list of testcases we expect to pass
65 PASSES=$STATE/passes
66 # in REGRESS, a list of testcases we expected to pass but that failed
67 REGRESS=$STATE/regress
68
69 # Make sure various files exist.
70 [ -d $STATE ] || mkdir $STATE
71 [ -f $PASSES ] || touch $PASSES
72
73 # These lines should stay in this order, because
74 # that way if something is badly wrong and $RESULT can't
75 # be modified then cron will mail the error message.
76 # The reverse order could lead to the testsuite claiming that
77 # everything always passes, without running any tests.
78 echo error > $RESULT || exit 1
79 exec > $BUILD_LOG 2>&1 || exit 1
80
81 set -x
82
83 # Nuke $BUILD and recreate it.
84 rm -rf $BUILD $REGRESS $FAILED
85 mkdir $BUILD || exit 1
86 cd $BUILD || exit 1
87
88 H_BUILD=`$SOURCE/config.guess || exit 1`
89 H_HOST=$H_BUILD
90 if [ $TARGET = native ] ; then
91   H_TARGET=$H_HOST
92 else
93   H_TARGET=$TARGET
94 fi
95 H_REAL_TARGET=`$SOURCE/config.sub $H_TARGET || exit 1`
96
97 # TESTLOGS is the list of dejagnu .sum files that the tester should
98 # look at.
99 TESTLOGS="gcc/testsuite/gcc.sum
100 gcc/testsuite/g++.sum
101 gcc/testsuite/g77.sum
102 gcc/testsuite/objc.sum"
103 # $H_TARGET/libstdc++-v3/testsuite/libstdc++-v3.sum
104 # $H_TARGET/libjava/testsuite/libjava.sum
105 # $H_TARGET/libffi/testsuite/libffi.sum
106
107 # Build.
108 echo build > $RESULT
109 if [ $H_HOST = $H_TARGET ] ; then
110   $SOURCE/configure --prefix=$PREFIX --target=$H_TARGET || exit 1
111   if ! make bootstrap ; then
112     [ -s gcc/.bad_compare ] || exit 1
113     cat gcc/.bad_compare >> $REGRESS || exit 1
114     make all || exit 1
115   fi
116 else
117   $SOURCE/configure --prefix=$PREFIX --target=$H_TARGET \
118     --with-gnu-ld --with-gnu-as --with-newlib || exit 1
119   make || exit 1
120 fi
121 echo error > $RESULT || exit 1
122
123 # Test GCC against its internal testsuite.
124 make -k check-gcc
125
126 # Test libstd++-v3
127 make check-target-libstdc++-v3
128
129 # Test libffi
130 make check-target-libffi
131
132 # Test libjava
133 make check-target-libjava
134
135 # Test the just-built GCC with the GDB testsuite.
136 if [ -d $GDB_TESTSUITE ] ; then
137   mkdir test-gdb || exit 1
138   cd $GDB_TESTSUITE || exit 1
139   for i in gdb.* ; do
140     if [ -d $i ] ; then
141       mkdir $BUILD/test-gdb/$i
142     fi
143   done
144   cd $BUILD/test-gdb || exit 1
145   echo "set host_alias $H_HOST" > site.exp
146   echo "set host_triplet $H_HOST" >> site.exp
147   echo "set target_alias $H_TARGET" >> site.exp
148   echo "set target_triplet $H_REAL_TARGET" >> site.exp
149   echo "set build_alias $H_BUILD" >> site.exp
150   echo "set build_triplet $H_BUILD" >> site.exp
151   echo "set srcdir $GDB_TESTSUITE" >> site.exp
152   runtest --tool gdb
153   TESTLOGS="$TESTLOGS test-gdb/gdb.sum"
154 fi
155
156 # Sanity-check the testlogs.  They should contain at least one PASS.
157 cd $BUILD || exit 1
158 for LOG in $TESTLOGS ; do
159   if ! grep ^PASS: $LOG > /dev/null ; then
160     echo build > $RESULT
161     exit 1
162   fi
163 done
164
165 # Work out what failed
166 for LOG in $TESTLOGS ; do
167   L=`basename $LOG`
168   awk '/^FAIL: / { print "'$L'",$2; }' $LOG || exit 1
169 done | sort | uniq > $FAILED || exit 1
170 comm -12 $FAILED $PASSES >> $REGRESS || exit 1
171 NUMREGRESS=`wc -l < $REGRESS | tr -d ' '`
172 if [ $NUMREGRESS -ne 0 ] ; then
173   echo regress-$NUMREGRESS > $RESULT
174   exit 1
175 fi
176
177 # It passed.  Update the state.
178 for LOG in $TESTLOGS ; do
179   L=`basename $LOG`
180   awk '/^PASS: / { print "'$L'",$2; }' $LOG || exit 1
181 done | sort | uniq | comm -23 - $FAILED > ${PASSES}~ || exit 1
182 [ -s ${PASSES}~ ] || exit 1
183 mv ${PASSES}~ ${PASSES} || exit 1
184 echo pass > $RESULT
185 exit 0