]> git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/regression/btest-gcc.sh
Update copyright years.
[thirdparty/gcc.git] / contrib / regression / btest-gcc.sh
1 #!/bin/sh
2
3 # Test GCC.
4 # Copyright (C) 1999-2023 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 3 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; see the file COPYING3. If not see
18 # <http://www.gnu.org/licenses/>.
19
20 # INPUT:
21 # btest <options> <target> <source> <prefix> <state> <build>
22
23 add_passes_despite_regression=0
24 dashj=''
25
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.
31
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
39
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
46
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
55
56 # STATE is where the tester maintains its internal state,
57 # described below.
58 STATE=$4
59
60 # BUILD is a temporary directory that this script will
61 # delete and recreate, containing the build tree.
62 BUILD=$5
63
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.
68
69
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
86
87 # Make sure various files exist.
88 [ -d $STATE ] || mkdir $STATE
89 [ -f $PASSES ] || touch $PASSES
90
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
98
99 set -x
100
101 # Nuke $BUILD and recreate it.
102 rm -rf $BUILD $REGRESS $FAILED
103 mkdir $BUILD || exit 1
104 cd $BUILD || exit 1
105
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
112 fi
113 H_REAL_TARGET=`$SOURCE/config.sub $H_TARGET || exit 1`
114
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/objc/objc.sum"
120
121 # Build.
122 echo build > $RESULT
123 if [ $H_HOST = $H_TARGET ] ; then
124 $SOURCE/configure --prefix=$PREFIX --target=$H_TARGET || exit 1
125 if ! make $dashj bootstrap ; then
126 [ -s .bad_compare ] || exit 1
127 cat .bad_compare >> $REGRESS || exit 1
128 touch compare || exit 1 # Prevent the comparison from running again
129 make $dashj all || exit 1
130 fi
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
139 fi
140 echo error > $RESULT || exit 1
141
142 # Test GCC against its internal testsuite.
143 make $dashj -k check
144
145 if [ -f gcc/testsuite/gfortran/gfortran.sum ] ; then
146 TESTLOGS="$TESTLOGS gcc/testsuite/gfortran/gfortran.sum"
147 fi
148
149 if [ -f $BUILD/$H_TARGET/libstdc++-v3/testsuite/libstdc++.sum ] ; then
150 TESTLOGS="$TESTLOGS $H_TARGET/libstdc++-v3/testsuite/libstdc++.sum"
151 fi
152
153 if [ -f $BUILD/$H_TARGET/libffi/testsuite/libffi.sum ] ; then
154 TESTLOGS="$TESTLOGS $H_TARGET/libffi/testsuite/libffi.sum"
155 fi
156
157 if [ -f $BUILD/$H_TARGET/libjava/testsuite/libjava.sum ] ; then
158 TESTLOGS="$TESTLOGS $H_TARGET/libjava/testsuite/libjava.sum"
159 fi
160
161 if [ -f $BUILD/$H_TARGET/libgomp/testsuite/libgomp.sum ] ; then
162 TESTLOGS="$TESTLOGS $H_TARGET/libgomp/testsuite/libgomp.sum"
163 fi
164
165 if [ -f $BUILD/$H_TARGET/libmudflap/testsuite/libmudflap.sum ] ; then
166 TESTLOGS="$TESTLOGS $H_TARGET/libmudflap/testsuite/libmudflap.sum"
167 fi
168
169 # Test the just-built GCC with the GDB testsuite.
170 if [ -d $GDB_TESTSUITE ] ; then
171 mkdir test-gdb || exit 1
172 cd $GDB_TESTSUITE || exit 1
173 for i in gdb.* ; do
174 if [ -d $i ] ; then
175 mkdir $BUILD/test-gdb/$i
176 fi
177 done
178 cd $BUILD/test-gdb || exit 1
179 echo "set host_alias $H_HOST" > site.exp
180 echo "set host_triplet $H_HOST" >> site.exp
181 echo "set target_alias $H_TARGET" >> site.exp
182 echo "set target_triplet $H_REAL_TARGET" >> site.exp
183 echo "set build_alias $H_BUILD" >> site.exp
184 echo "set build_triplet $H_BUILD" >> site.exp
185 echo "set srcdir $GDB_TESTSUITE" >> site.exp
186 runtest --tool gdb
187 TESTLOGS="$TESTLOGS test-gdb/gdb.sum"
188 fi
189
190 # Sanity-check the testlogs. They should contain at least one PASS.
191 cd $BUILD || exit 1
192 for LOG in $TESTLOGS ; do
193 if ! grep ^PASS: $LOG > /dev/null ; then
194 echo build > $RESULT
195 exit 1
196 fi
197 done
198
199 # Work out what failed
200 for LOG in $TESTLOGS ; do
201 L=`basename $LOG`
202 awk '/^FAIL: / { print "'$L'",$2; }' $LOG || exit 1
203 done | sort | uniq > $FAILED || exit 1
204 comm -12 $FAILED $PASSES >> $REGRESS || exit 1
205 NUMREGRESS=`wc -l < $REGRESS | tr -d ' '`
206
207 if [ $NUMREGRESS -eq 0 ] || [ $add_passes_despite_regression -ne 0 ] ; then
208 # Update the state.
209 for LOG in $TESTLOGS ; do
210 L=`basename $LOG`
211 awk '/^PASS: / { print "'$L'",$2; }' $LOG || exit 1
212 done | sort | uniq | comm -23 - $FAILED > ${PASSES}~ || exit 1
213 [ -s ${PASSES}~ ] || exit 1
214 if [ $NUMREGRESS -ne 0 ] ; then
215 # The way we keep track of new PASSes when in "regress-N" for
216 # --add-passes-despite-regression, is to *add* them to previous
217 # PASSes. Just as without this option, we don't forget *any* PASS
218 # lines, because besides the ones in $REGRESS that we definitely
219 # don't want to lose, their removal or rename may have been a
220 # mistake (as in, the cause of the "regress-N" state). If they
221 # come back, we then know they're regressions.
222 cat ${PASSES}~ ${PASSES} | sort -u > ${PASSES}~~
223 mv ${PASSES}~~ ${PASSES} || exit 1
224 rm ${PASSES}~ || exit 1
225 else
226 # In contrast to the merging for "regress-N", we just overwrite
227 # the known PASSes when in the "pass" state, so we get rid of
228 # stale PASS lines for removed, moved or otherwise changed tests
229 # which may be added back with a different meaning later on.
230 mv ${PASSES}~ ${PASSES} || exit 1
231 fi
232 fi
233
234 if [ $NUMREGRESS -ne 0 ] ; then
235 echo regress-$NUMREGRESS > $RESULT
236 exit 1
237 fi
238
239 echo pass > $RESULT
240 exit 0