#!/bin/sh
#
-# Run specific build tests for a given OS environment.
+# Run all or some build tests for a given OS environment.
#
+top=`dirname $0`
+
+globalResult=0
cleanup="no"
-if test "${1}" = "--cleanup" ; then
+verbose="no"
+keepGoing="no"
+while [ $# -ge 1 ]; do
+ case "$1" in
+ --cleanup)
cleanup="yes"
shift
-fi
+ ;;
+ --verbose)
+ verbose="yes"
+ shift
+ ;;
+ --keep-going)
+ keepGoing="yes"
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
-# Things to catch
-errors="^ERROR|\ error:|\ Error\ |No\ such|assertion\ failed|FAIL:"
-
-# Run a single test build by name
-tmp="${1}"
-if test -e ./test-suite/buildtests/${tmp}.opts ; then
- echo "TESTING: ${tmp}"
- rm -f -r bt${tmp} && mkdir bt${tmp} && cd bt${tmp}
- ../test-suite/buildtest.sh ../test-suite/buildtests/${tmp}
- grep -E "${errors}" buildtest_*.log && exit 1
- cd ..
- exit 0
-fi
+logtee() {
+ if [ $verbose = yes ]; then
+ tee $1
+ else
+ cat >$1
+ 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 ./test-suite/buildtests/layer*.opts` ; do
- layer=`echo "${f}" | grep -o -E "layer-[0-9]*-[^\.]*"`
- rm -f -r bt${layer} && mkdir bt${layer} && cd bt${layer}
- arg=`echo "${f}" | sed s/\\.opts//`
- echo "TESTING: ${arg}"
- ../test-suite/buildtest.sh ".${arg}"
- grep -E "${errors}" buildtest_*.log && exit 1
- result=`tail -2 buildtest_*.log | head -1`
- test "${result}" = "Build Successful." || ( tail -1 buildtest_*.log ; exit 1 )
- cd ..
- if test "${cleanup}" = "yes" ; then
- echo "REMOVE: bt${layer}"
- rm -f -r bt${layer}
+buildtest() {
+ opts=$1
+ layer=`basename ${opts} .opts`
+ btlayer="bt${layer}"
+ log=${btlayer}.log
+ echo "TESTING: ${layer}"
+ chmod -R 777 ${btlayer}
+ rm -f -r ${btlayer} && mkdir ${btlayer}
+ {
+ result=255
+ cd ${btlayer}
+ if test -e $top/test-suite/buildtest.sh ; then
+ $top/test-suite/buildtest.sh ${opts} 2>&1
+ result=$?
+ elif test -e ../$top/test-suite/buildtest.sh ; then
+ ../$top/test-suite/buildtest.sh ../${opts} 2>&1
+ result=$?
+ else
+ echo "Error: cannot find $top/test-suite/buildtest.sh script"
+ result=1
fi
+
+ # 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
+
+ # 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}
+
+ if test "${cleanup}" = "yes" ; then
+ echo "REMOVE DATA: ${btlayer}"
+ chmod -R 777 ${btlayer}
+ rm -f -r ${btlayer}
+ fi
+
+ if test $result -eq 0; then
+ # successful execution
+ if test "$verbose" = yes; then
+ echo "Build OK. Global result is $globalResult."
+ fi
+ else
+ echo "Build Failed. Last log lines are:"
+ tail -20 ${log}
+ globalResult=1
+ fi
+
+ if test "${cleanup}" = "yes" ; then
+ echo "REMOVE LOG: ${log}"
+ rm -f -r ${log}
+ fi
+}
+
+# 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
+
+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
+
+exit $globalResult
# Should be run from the source package root directory with paths relative to there.
#
-dist="${1}"
-
-# Figure out where to log the test output
-log=`echo "${dist}" | sed s/..test-suite.buildtests.//g `
-
-# ... and send everything there...
-{
+config="${1}"
+base="`dirname ${0}`"
+
+#if we are on Linux, let's try parallelizing
+pjobs="" #default
+if [ -e /proc/cpuinfo ]; then
+ ncpus=`grep '^processor' /proc/cpuinfo | tail -1|awk '{print $3}'`
+ ncpus=`expr ${ncpus} + 1`
+ pjobs="-j${ncpus}"
+fi
-if test -e ${dist%%.opts}.opts ; then
- echo "BUILD: ${dist%%.opts}.opts"
- . ./${dist%%.opts}.opts
+if test -e ${config} ; then
+ echo "BUILD: ${config}"
+ . ${config}
else
- echo "BUILD: DEFAULT"
- OPTS=""
- FLAGS=""
+ echo -n "BUILD ERROR: Unable to locate test configuration '${config}' from " && pwd
+ exit 1;
fi
#
# empty all the existing code, reconfigure and builds test code
-
-make -k distclean || echo "distclean done. errors are unwanted but okay here."
+# but skip if we have no files to remove.
+FILECOUNT=`ls -1 | grep -c .`
+if test "${FILECOUNT}" != "0" ; then
+ make -k distclean || echo "distclean done. errors are unwanted but okay here."
+ rm -f -r src/fs/aufs/.deps src/fs/diskd/.deps
+fi
#
# above command currently encounters dependancy problems on cleanup.
#
-rm -f -r src/fs/aufs/.deps src/fs/diskd/.deps &&
- ../configure --silent ${OPTS} 2>&1 &&
- make check 2>&1 &&
- make 2>&1
-
-} 2>&1 > ./buildtest_${log}.log
-
# do not build any of the install's ...
+ $base/../configure ${OPTS} 2>&1 &&
+ make ${pjobs} ${MAKETEST} 2>&1
+
+# Remember and then explicitly return the result of the last command
+# to the script caller. Probably not needed on most or all platforms.
+result=$?
+exit ${result}