#!/bin/sh
#
-# Run specific build tests for a given OS environment.
+##
+## Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+##
+## Squid software is distributed under GPLv2+ license and includes
+## contributions from numerous individuals and organizations.
+## Please see the COPYING and CONTRIBUTORS files for details.
+##
+# Run all or some build tests for a given OS environment.
#
top=`dirname $0`
+globalResult=0
+
cleanup="no"
verbose="no"
+keepGoing="no"
+remove_cache_file="true"
while [ $# -ge 1 ]; do
case "$1" in
--cleanup)
verbose="yes"
shift
;;
+ --keep-going)
+ keepGoing="yes"
+ shift
+ ;;
+ --use-config-cache)
+ #environment variable will be picked up by buildtest.sh
+ cache_file=/tmp/config.cache.$$
+ export cache_file
+ shift
+ ;;
+ --aggressively-use-config-cache)
+ #environment variable will be picked up by buildtest.sh
+ #note: use ONLY if you know what you're doing
+ cache_file=/tmp/config.cache
+ remove_cache_file="false"
+ export cache_file
+ shift
+ ;;
*)
break
;;
esac
done
-# Things to catch
-errors="^ERROR|\ error:|\ Error\ |No\ such|assertion\ failed|FAIL:"
-
logtee() {
if [ $verbose = yes ]; then
tee $1
buildtest() {
opts=$1
- layer=`basename $opts .opts`
- btlayer="bt$layer"
+ layer=`basename ${opts} .opts`
+ btlayer="bt${layer}"
log=${btlayer}.log
echo "TESTING: ${layer}"
- rm -f -r ${btlayer} && mkdir ${btlayer}
+ if test -e ${btlayer}; then
+ chmod -R 777 ${btlayer};
+ fi
+ rm -f -r ${btlayer} || ( echo "FATAL: Failed to prepare test build sandpit." ; exit 1 )
+ mkdir ${btlayer}
+ if test "${verbose}" = "yes" ; then
+ ls -la ${btlayer}
+ fi
{
+ result=255
cd ${btlayer}
if test -e $top/test-suite/buildtest.sh ; then
- $top/test-suite/buildtest.sh $opts
+ $top/test-suite/buildtest.sh ${opts} 2>&1
+ result=$?
elif test -e ../$top/test-suite/buildtest.sh ; then
- ../$top/test-suite/buildtest.sh $opts
+ ../$top/test-suite/buildtest.sh ../${opts} 2>&1
+ result=$?
+ else
+ echo "Error: cannot find $top/test-suite/buildtest.sh script"
+ result=1
fi
- } 2>&1 | logtee $log
- grep -E "${errors}" $log && exit 1
- if test "${cleanup}" = "yes" ; then
- echo "REMOVE: ${btlayer}"
- rm -f -r ${btlayer} $log
+
+ # log the result for the outer script to notice
+ echo "buildtest.sh result is $result";
+ } 2>&1 | logtee ${log}
+
+ result=1 # failure by default
+ if grep -q '^buildtest.sh result is 0$' ${log}; then
+ result=0
fi
- result=`tail -2 $log | head -1`
- test "${result}" = "Build Successful." || ( tail -5 $log ; exit 1 )
-}
-# Run a single test build by name or opts file
-if [ -e "$1" ]; then
+ # Display BUILD parameters to double check that we are building the
+ # with the right parameters. TODO: Make less noisy.
+ grep -E "BUILD" ${log}
+
+ errors="^ERROR|\ error:|\ Error\ |No\ such|assertion\ failed|FAIL:|:\ undefined"
+ grep -E "${errors}" ${log}
- buildtest $1
- exit 0
+ if test $result -eq 0; then
+ # successful execution
+ if test "${verbose}" = "yes"; then
+ echo "Build OK. Global result is $globalResult."
+ fi
+ if test "${cleanup}" = "yes" ; then
+ echo "REMOVE DATA: ${btlayer}"
+ chmod -R 777 ${btlayer}
+ rm -f -r ${btlayer}
+ echo "REMOVE LOG: ${log}"
+ rm -f -r ${log}
+ fi
+ else
+ if test "${verbose}" != "yes" ; then
+ echo "Build Failed. Last log lines are:"
+ tail -20 ${log}
+ else
+ echo "Build FAILED."
+ fi
+ globalResult=1
+ fi
+}
+
+# if using cache, make sure to clear it up first
+if [ -n "$cache_file" -a -e "$cache_file" -a "$remove_cache_file" = "true" ]; then
+ rm $cache_file
fi
-tmp=`basename "${1}" .opts`
-if test -e $top/test-suite/buildtests/${tmp}.opts ; then
- buildtest $top/test-suite/buildtests/${tmp}.opts
- exit 0
+
+# Decide what tests to run, $* contains test spec names or filenames.
+# Use all knows specs if $* is empty or a special macro called 'all'.
+if test -n "$*" -a "$*" != all; then
+ tests="$*"
+else
+ tests=`ls -1 $top/test-suite/buildtests/layer*.opts`
fi
-#
-# Run specific tests for each combination of configure-time
-# Options.
-#
-# These layers are constructed from detailed knowledge of
-# component dependencies.
-#
-for f in `ls -1 $top/test-suite/buildtests/layer*.opts` ; do
- buildtest $f
+for t in $tests; do
+ if test -e "$t"; then
+ # A configuration file
+ cfg="$t"
+ elif test -e "$top/test-suite/buildtests/${t}.opts"; then
+ # A well-known configuration name
+ cfg="$top/test-suite/buildtests/${t}.opts"
+ else
+ echo "Error: Unknown test specs '$t'"
+ cfg=''
+ globalResult=1
+ fi
+
+ # run the test, if any
+ if test -n "$cfg"; then
+ buildtest $cfg
+ fi
+
+ # quit on errors unless we should $keepGoing
+ if test $globalResult -ne 0 -a $keepGoing != yes; then
+ exit $globalResult
+ fi
done
+
+# if using cache, make sure to clear it up first
+if [ -n "$cache_file" -a -e "$cache_file" -a "$remove_cache_file" = "true" ]; then
+ rm $cache_file
+fi
+
+exit $globalResult