1#!/bin/sh 2 3# Test GCC. 4# Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006, 2009, 2012 5# Free Software Foundation, Inc. 6 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. 11 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. 16 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/>. 20 21# INPUT: 22# btest <options> <target> <source> <prefix> <state> <build> 23 24add_passes_despite_regression=0 25dashj='' 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 33case "$1" in 34 --add-passes-despite-regression) 35 add_passes_despite_regression=1; shift;; 36 -j*) 37 dashj=$1; shift;; 38 -*) echo "Invalid option: $1"; exit 2;; 39esac 40 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. 44TARGET=$1 45# SOURCE is the directory containing the toplevel configure. 46SOURCE=$2 47 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 51# $PREFIX/bin. 52PREFIX=$3 53# This script also needs to include the GDB testsuite in 54# $PREFIX/share/gdb-testsuite. 55GDB_TESTSUITE=$PREFIX/share/gdb-testsuite 56 57# STATE is where the tester maintains its internal state, 58# described below. 59STATE=$4 60 61# BUILD is a temporary directory that this script will 62# delete and recreate, containing the build tree. 63BUILD=$5 64 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. 69 70 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 78RESULT=$STATE/RESULT 79# in BUILD_LOG, the output of the build 80BUILD_LOG=$STATE/build_log 81# in FAILED, a list of failing testcases 82FAILED=$STATE/failed 83# in PASSES, the list of testcases we expect to pass 84PASSES=$STATE/passes 85# in REGRESS, a list of testcases we expected to pass but that failed 86REGRESS=$STATE/regress 87 88# Make sure various files exist. 89[ -d $STATE ] || mkdir $STATE 90[ -f $PASSES ] || touch $PASSES 91 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. 97echo error > $RESULT || exit 1 98exec > $BUILD_LOG 2>&1 || exit 1 99 100set -x 101 102# Nuke $BUILD and recreate it. 103rm -rf $BUILD $REGRESS $FAILED 104mkdir $BUILD || exit 1 105cd $BUILD || exit 1 106 107H_BUILD=`$SOURCE/config.guess || exit 1` 108H_HOST=$H_BUILD 109if [ $TARGET = native ] ; then 110 H_TARGET=$H_HOST 111else 112 H_TARGET=$TARGET 113fi 114H_REAL_TARGET=`$SOURCE/config.sub $H_TARGET || exit 1` 115 116# TESTLOGS is the list of dejagnu .sum files that the tester should 117# look at. 118TESTLOGS="gcc/testsuite/gcc/gcc.sum 119gcc/testsuite/g++/g++.sum 120gcc/testsuite/objc/objc.sum" 121 122# Build. 123echo build > $RESULT 124if [ $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 touch compare || exit 1 # Prevent the comparison from running again 130 make $dashj all || exit 1 131 fi 132else 133 withopt="--with-gnu-ld --with-gnu-as" 134 case "$H_TARGET" in 135 *-linux*) ;; 136 *) withopt="$withopt --with-newlib";; 137 esac 138 $SOURCE/configure --prefix=$PREFIX --target=$H_TARGET $withopt || exit 1 139 make $dashj || exit 1 140fi 141echo error > $RESULT || exit 1 142 143# Test GCC against its internal testsuite. 144make $dashj -k check 145 146if [ -f gcc/testsuite/gfortran/gfortran.sum ] ; then 147 TESTLOGS="$TESTLOGS gcc/testsuite/gfortran/gfortran.sum" 148fi 149 150if [ -f $BUILD/$H_TARGET/libstdc++-v3/testsuite/libstdc++.sum ] ; then 151 TESTLOGS="$TESTLOGS $H_TARGET/libstdc++-v3/testsuite/libstdc++.sum" 152fi 153 154if [ -f $BUILD/$H_TARGET/libffi/testsuite/libffi.sum ] ; then 155 TESTLOGS="$TESTLOGS $H_TARGET/libffi/testsuite/libffi.sum" 156fi 157 158if [ -f $BUILD/$H_TARGET/libjava/testsuite/libjava.sum ] ; then 159 TESTLOGS="$TESTLOGS $H_TARGET/libjava/testsuite/libjava.sum" 160fi 161 162if [ -f $BUILD/$H_TARGET/libgomp/testsuite/libgomp.sum ] ; then 163 TESTLOGS="$TESTLOGS $H_TARGET/libgomp/testsuite/libgomp.sum" 164fi 165 166if [ -f $BUILD/$H_TARGET/libmudflap/testsuite/libmudflap.sum ] ; then 167 TESTLOGS="$TESTLOGS $H_TARGET/libmudflap/testsuite/libmudflap.sum" 168fi 169 170# Test the just-built GCC with the GDB testsuite. 171if [ -d $GDB_TESTSUITE ] ; then 172 mkdir test-gdb || exit 1 173 cd $GDB_TESTSUITE || exit 1 174 for i in gdb.* ; do 175 if [ -d $i ] ; then 176 mkdir $BUILD/test-gdb/$i 177 fi 178 done 179 cd $BUILD/test-gdb || exit 1 180 echo "set host_alias $H_HOST" > site.exp 181 echo "set host_triplet $H_HOST" >> site.exp 182 echo "set target_alias $H_TARGET" >> site.exp 183 echo "set target_triplet $H_REAL_TARGET" >> site.exp 184 echo "set build_alias $H_BUILD" >> site.exp 185 echo "set build_triplet $H_BUILD" >> site.exp 186 echo "set srcdir $GDB_TESTSUITE" >> site.exp 187 runtest --tool gdb 188 TESTLOGS="$TESTLOGS test-gdb/gdb.sum" 189fi 190 191# Sanity-check the testlogs. They should contain at least one PASS. 192cd $BUILD || exit 1 193for LOG in $TESTLOGS ; do 194 if ! grep ^PASS: $LOG > /dev/null ; then 195 echo build > $RESULT 196 exit 1 197 fi 198done 199 200# Work out what failed 201for LOG in $TESTLOGS ; do 202 L=`basename $LOG` 203 awk '/^FAIL: / { print "'$L'",$2; }' $LOG || exit 1 204done | sort | uniq > $FAILED || exit 1 205comm -12 $FAILED $PASSES >> $REGRESS || exit 1 206NUMREGRESS=`wc -l < $REGRESS | tr -d ' '` 207 208if [ $NUMREGRESS -eq 0 ] || [ $add_passes_despite_regression -ne 0 ] ; then 209 # Update the state. 210 for LOG in $TESTLOGS ; do 211 L=`basename $LOG` 212 awk '/^PASS: / { print "'$L'",$2; }' $LOG || exit 1 213 done | sort | uniq | comm -23 - $FAILED > ${PASSES}~ || exit 1 214 [ -s ${PASSES}~ ] || exit 1 215 if [ $NUMREGRESS -ne 0 ] ; then 216 # The way we keep track of new PASSes when in "regress-N" for 217 # --add-passes-despite-regression, is to *add* them to previous 218 # PASSes. Just as without this option, we don't forget *any* PASS 219 # lines, because besides the ones in $REGRESS that we definitely 220 # don't want to lose, their removal or rename may have been a 221 # mistake (as in, the cause of the "regress-N" state). If they 222 # come back, we then know they're regressions. 223 cat ${PASSES}~ ${PASSES} | sort -u > ${PASSES}~~ 224 mv ${PASSES}~~ ${PASSES} || exit 1 225 rm ${PASSES}~ || exit 1 226 else 227 # In contrast to the merging for "regress-N", we just overwrite 228 # the known PASSes when in the "pass" state, so we get rid of 229 # stale PASS lines for removed, moved or otherwise changed tests 230 # which may be added back with a different meaning later on. 231 mv ${PASSES}~ ${PASSES} || exit 1 232 fi 233fi 234 235if [ $NUMREGRESS -ne 0 ] ; then 236 echo regress-$NUMREGRESS > $RESULT 237 exit 1 238fi 239 240echo pass > $RESULT 241exit 0 242