| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Test GCC. |
| 4 |
# Copyright (C) 1999-2025 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 |
handle_xpass_as_fail=false |
| 26 |
|
| 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. |
| 32 |
# --handle-xpass-as-fail: |
| 33 |
# Count XPASS as a FAIL (default ignored). |
| 34 |
|
| 35 |
while : ; do |
| 36 |
case "$1" in |
| 37 |
--add-passes-despite-regression) |
| 38 |
add_passes_despite_regression=1;; |
| 39 |
--handle-xpass-as-fail) |
| 40 |
handle_xpass_as_fail=true;; |
| 41 |
-j*) |
| 42 |
dashj=$1;; |
| 43 |
-*) echo "Invalid option: $1"; exit 2;; |
| 44 |
*) break;; |
| 45 |
esac |
| 46 |
shift |
| 47 |
done |
| 48 |
|
| 49 |
# TARGET is the target triplet. It should be the same one as used in |
| 50 |
# constructing PREFIX. Or it can be the keyword 'native', indicating |
| 51 |
# a target of whatever platform the script is running on. |
| 52 |
TARGET=$1 |
| 53 |
# SOURCE is the directory containing the toplevel configure. |
| 54 |
SOURCE=$2 |
| 55 |
|
| 56 |
# PREFIX is the directory for the --prefix option to configure. |
| 57 |
# For cross compilers, it needs to contain header files, |
| 58 |
# libraries, and binutils. PATH should probably include |
| 59 |
# $PREFIX/bin. |
| 60 |
PREFIX=$3 |
| 61 |
# This script also needs to include the GDB testsuite in |
| 62 |
# $PREFIX/share/gdb-testsuite. |
| 63 |
GDB_TESTSUITE=$PREFIX/share/gdb-testsuite |
| 64 |
|
| 65 |
# STATE is where the tester maintains its internal state, |
| 66 |
# described below. |
| 67 |
STATE=$4 |
| 68 |
|
| 69 |
# BUILD is a temporary directory that this script will |
| 70 |
# delete and recreate, containing the build tree. |
| 71 |
BUILD=$5 |
| 72 |
|
| 73 |
# you also probably need to set these variables: |
| 74 |
# PATH: should contain a native gcc, and a cross gdb. |
| 75 |
# DEJAGNU: should point to a site.exp suitable for testing |
| 76 |
# the compiler and debugger. |
| 77 |
|
| 78 |
|
| 79 |
# OUTPUT: in $RESULT, one of the following keywords: |
| 80 |
# error the script failed due to |
| 81 |
# a misconfiguration or resource limitation |
| 82 |
# build the build failed |
| 83 |
# regress-<n> the build succeeded, but there were <n> |
| 84 |
# testsuite regressions, listed in $REGRESS |
| 85 |
# pass build succeeded and there were no regressions |
| 86 |
RESULT=$STATE/RESULT |
| 87 |
# in BUILD_LOG, the output of the build |
| 88 |
BUILD_LOG=$STATE/build_log |
| 89 |
# in FAILED, a list of failing testcases |
| 90 |
FAILED=$STATE/failed |
| 91 |
# in PASSES, the list of testcases we expect to pass |
| 92 |
PASSES=$STATE/passes |
| 93 |
# in REGRESS, a list of testcases we expected to pass but that failed |
| 94 |
REGRESS=$STATE/regress |
| 95 |
|
| 96 |
# Make sure various files exist. |
| 97 |
[ -d $STATE ] || mkdir $STATE |
| 98 |
[ -f $PASSES ] || touch $PASSES |
| 99 |
|
| 100 |
# These lines should stay in this order, because |
| 101 |
# that way if something is badly wrong and $RESULT can't |
| 102 |
# be modified then cron will mail the error message. |
| 103 |
# The reverse order could lead to the testsuite claiming that |
| 104 |
# everything always passes, without running any tests. |
| 105 |
echo error > $RESULT || exit 1 |
| 106 |
exec > $BUILD_LOG 2>&1 || exit 1 |
| 107 |
|
| 108 |
set -x |
| 109 |
|
| 110 |
# Nuke $BUILD and recreate it. |
| 111 |
rm -rf $BUILD $REGRESS $FAILED |
| 112 |
mkdir $BUILD || exit 1 |
| 113 |
cd $BUILD || exit 1 |
| 114 |
|
| 115 |
H_BUILD=`$SOURCE/config.guess || exit 1` |
| 116 |
H_HOST=$H_BUILD |
| 117 |
if [ $TARGET = native ] ; then |
| 118 |
H_TARGET=$H_HOST |
| 119 |
else |
| 120 |
H_TARGET=$TARGET |
| 121 |
fi |
| 122 |
H_REAL_TARGET=`$SOURCE/config.sub $H_TARGET || exit 1` |
| 123 |
|
| 124 |
# TESTLOGS is the list of dejagnu .sum files that the tester should |
| 125 |
# look at. |
| 126 |
TESTLOGS="gcc/testsuite/gcc/gcc.sum |
| 127 |
gcc/testsuite/g++/g++.sum |
| 128 |
gcc/testsuite/objc/objc.sum" |
| 129 |
|
| 130 |
# Build. |
| 131 |
echo build > $RESULT |
| 132 |
if [ $H_HOST = $H_TARGET ] ; then |
| 133 |
$SOURCE/configure --prefix=$PREFIX --target=$H_TARGET || exit 1 |
| 134 |
if ! make $dashj bootstrap ; then |
| 135 |
[ -s .bad_compare ] || exit 1 |
| 136 |
cat .bad_compare >> $REGRESS || exit 1 |
| 137 |
touch compare || exit 1 # Prevent the comparison from running again |
| 138 |
make $dashj all || exit 1 |
| 139 |
fi |
| 140 |
else |
| 141 |
withopt="--with-gnu-ld --with-gnu-as" |
| 142 |
case "$H_TARGET" in |
| 143 |
*-linux*) ;; |
| 144 |
*) withopt="$withopt --with-newlib";; |
| 145 |
esac |
| 146 |
$SOURCE/configure --prefix=$PREFIX --target=$H_TARGET $withopt || exit 1 |
| 147 |
make $dashj || exit 1 |
| 148 |
fi |
| 149 |
echo error > $RESULT || exit 1 |
| 150 |
|
| 151 |
# Test GCC against its internal testsuite. |
| 152 |
make $dashj -k check |
| 153 |
|
| 154 |
if [ -f gcc/testsuite/gfortran/gfortran.sum ] ; then |
| 155 |
TESTLOGS="$TESTLOGS gcc/testsuite/gfortran/gfortran.sum" |
| 156 |
fi |
| 157 |
|
| 158 |
if [ -f $BUILD/$H_TARGET/libstdc++-v3/testsuite/libstdc++.sum ] ; then |
| 159 |
TESTLOGS="$TESTLOGS $H_TARGET/libstdc++-v3/testsuite/libstdc++.sum" |
| 160 |
fi |
| 161 |
|
| 162 |
if [ -f $BUILD/$H_TARGET/libffi/testsuite/libffi.sum ] ; then |
| 163 |
TESTLOGS="$TESTLOGS $H_TARGET/libffi/testsuite/libffi.sum" |
| 164 |
fi |
| 165 |
|
| 166 |
if [ -f $BUILD/$H_TARGET/libjava/testsuite/libjava.sum ] ; then |
| 167 |
TESTLOGS="$TESTLOGS $H_TARGET/libjava/testsuite/libjava.sum" |
| 168 |
fi |
| 169 |
|
| 170 |
if [ -f $BUILD/$H_TARGET/libgomp/testsuite/libgomp.sum ] ; then |
| 171 |
TESTLOGS="$TESTLOGS $H_TARGET/libgomp/testsuite/libgomp.sum" |
| 172 |
fi |
| 173 |
|
| 174 |
if [ -f $BUILD/$H_TARGET/libmudflap/testsuite/libmudflap.sum ] ; then |
| 175 |
TESTLOGS="$TESTLOGS $H_TARGET/libmudflap/testsuite/libmudflap.sum" |
| 176 |
fi |
| 177 |
|
| 178 |
# Test the just-built GCC with the GDB testsuite. |
| 179 |
if [ -d $GDB_TESTSUITE ] ; then |
| 180 |
mkdir test-gdb || exit 1 |
| 181 |
cd $GDB_TESTSUITE || exit 1 |
| 182 |
for i in gdb.* ; do |
| 183 |
if [ -d $i ] ; then |
| 184 |
mkdir $BUILD/test-gdb/$i |
| 185 |
fi |
| 186 |
done |
| 187 |
cd $BUILD/test-gdb || exit 1 |
| 188 |
echo "set host_alias $H_HOST" > site.exp |
| 189 |
echo "set host_triplet $H_HOST" >> site.exp |
| 190 |
echo "set target_alias $H_TARGET" >> site.exp |
| 191 |
echo "set target_triplet $H_REAL_TARGET" >> site.exp |
| 192 |
echo "set build_alias $H_BUILD" >> site.exp |
| 193 |
echo "set build_triplet $H_BUILD" >> site.exp |
| 194 |
echo "set srcdir $GDB_TESTSUITE" >> site.exp |
| 195 |
runtest --tool gdb |
| 196 |
TESTLOGS="$TESTLOGS test-gdb/gdb.sum" |
| 197 |
fi |
| 198 |
|
| 199 |
# Sanity-check the testlogs. They should contain at least one PASS. |
| 200 |
cd $BUILD || exit 1 |
| 201 |
for LOG in $TESTLOGS ; do |
| 202 |
if ! grep ^PASS: $LOG > /dev/null ; then |
| 203 |
echo build > $RESULT |
| 204 |
exit 1 |
| 205 |
fi |
| 206 |
done |
| 207 |
|
| 208 |
# Work out what failed |
| 209 |
for LOG in $TESTLOGS ; do |
| 210 |
L=`basename $LOG` |
| 211 |
if $handle_xpass_as_fail ; then |
| 212 |
awk '/^(FAIL|XPASS): / { print "'$L'",$2; }' $LOG || exit 1 |
| 213 |
else |
| 214 |
awk '/^FAIL: / { print "'$L'",$2; }' $LOG || exit 1 |
| 215 |
fi |
| 216 |
done | sort | uniq > $FAILED || exit 1 |
| 217 |
comm -12 $FAILED $PASSES >> $REGRESS || exit 1 |
| 218 |
NUMREGRESS=`wc -l < $REGRESS | tr -d ' '` |
| 219 |
|
| 220 |
if [ $NUMREGRESS -eq 0 ] || [ $add_passes_despite_regression -ne 0 ] ; then |
| 221 |
# Update the state. |
| 222 |
for LOG in $TESTLOGS ; do |
| 223 |
L=`basename $LOG` |
| 224 |
awk '/^PASS: / { print "'$L'",$2; }' $LOG || exit 1 |
| 225 |
done | sort | uniq | comm -23 - $FAILED > ${PASSES}~ || exit 1 |
| 226 |
[ -s ${PASSES}~ ] || exit 1 |
| 227 |
if [ $NUMREGRESS -ne 0 ] ; then |
| 228 |
# The way we keep track of new PASSes when in "regress-N" for |
| 229 |
# --add-passes-despite-regression, is to *add* them to previous |
| 230 |
# PASSes. Just as without this option, we don't forget *any* PASS |
| 231 |
# lines, because besides the ones in $REGRESS that we definitely |
| 232 |
# don't want to lose, their removal or rename may have been a |
| 233 |
# mistake (as in, the cause of the "regress-N" state). If they |
| 234 |
# come back, we then know they're regressions. |
| 235 |
cat ${PASSES}~ ${PASSES} | sort -u > ${PASSES}~~ |
| 236 |
mv ${PASSES}~~ ${PASSES} || exit 1 |
| 237 |
rm ${PASSES}~ || exit 1 |
| 238 |
else |
| 239 |
# In contrast to the merging for "regress-N", we just overwrite |
| 240 |
# the known PASSes when in the "pass" state, so we get rid of |
| 241 |
# stale PASS lines for removed, moved or otherwise changed tests |
| 242 |
# which may be added back with a different meaning later on. |
| 243 |
mv ${PASSES}~ ${PASSES} || exit 1 |
| 244 |
fi |
| 245 |
fi |
| 246 |
|
| 247 |
if [ $NUMREGRESS -ne 0 ] ; then |
| 248 |
echo regress-$NUMREGRESS > $RESULT |
| 249 |
exit 1 |
| 250 |
fi |
| 251 |
|
| 252 |
echo pass > $RESULT |
| 253 |
exit 0 |