2009-02-12 02:36:52 +01:00
|
|
|
#!/bin/bash
|
2008-03-10 04:25:03 +01:00
|
|
|
# Copyright (C) Lumiera.org
|
2008-05-20 13:04:22 +02:00
|
|
|
# 2007 - 2008, Christian Thaeter <ct@pipapo.org>
|
2007-08-12 21:28:21 +02:00
|
|
|
#
|
2007-08-12 21:51:24 +02:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
|
# published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
2007-08-12 21:28:21 +02:00
|
|
|
#
|
2007-08-12 21:51:24 +02:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
2007-08-12 21:28:21 +02:00
|
|
|
#
|
2007-08-12 21:51:24 +02:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2007-08-12 21:28:21 +02:00
|
|
|
|
|
|
|
|
# TESTMODE=FULL yet unimplemented
|
|
|
|
|
# run all tests, PLANNED which fail count as error
|
|
|
|
|
#
|
|
|
|
|
# TESTMODE=FAST
|
|
|
|
|
# run only tests which recently failed
|
2007-08-13 17:22:07 +02:00
|
|
|
#
|
|
|
|
|
# TESTMODE=FIRSTFAIL
|
|
|
|
|
# stop testing on the first failure
|
|
|
|
|
|
|
|
|
|
export LC_ALL=C
|
2009-06-06 15:22:48 +02:00
|
|
|
NOBUG_LOGREGEX='^\(\*\*[0-9]*\*\* \)\?[0-9]\{10,\}: \(TRACE\|INFO\|NOTICE\|WARNING\|ERR\|TODO\|PLANNED\|FIXME\|DEPRECATED\|UNIMPLEMENTED\|NOTREACHED\):'
|
2007-08-12 21:28:21 +02:00
|
|
|
|
|
|
|
|
arg0="$0"
|
2008-04-12 02:07:16 +02:00
|
|
|
srcdir="$(dirname "$arg0")"
|
2007-08-12 21:28:21 +02:00
|
|
|
|
2009-02-12 02:36:52 +01:00
|
|
|
ulimit -S -t 5 -v 524288
|
2007-08-12 21:28:21 +02:00
|
|
|
valgrind=""
|
|
|
|
|
if [ "$VALGRINDFLAGS" = 'DISABLE' ]; then
|
|
|
|
|
echo "valgrind explicit disabled"
|
|
|
|
|
else
|
|
|
|
|
if [ "$(which valgrind)" ]; then
|
2009-02-12 02:36:52 +01:00
|
|
|
ulimit -S -t 20
|
|
|
|
|
if [[ -x 'vgsuppression' ]]; then
|
|
|
|
|
if [[ 'vgsuppression' -nt 'vgsuppression.supp' ]]; then
|
|
|
|
|
echo 'generating valgrind supression file'
|
|
|
|
|
|
|
|
|
|
if [[ -x ".libs/vgsuppression" ]]; then
|
|
|
|
|
./libtool --mode=execute valgrind --leak-check=yes --show-reachable=yes -q --gen-suppressions=all vgsuppression 2>&1 \
|
|
|
|
|
| sed '/^\(==\)\|\(\*\*\)[0-9]*\(==\)\|\(\*\*\)/d;' >vgsuppression.supp
|
|
|
|
|
else
|
|
|
|
|
valgrind --leak-check=yes --show-reachable=yes -q --gen-suppressions=all ./vgsuppression 2>&1 \
|
|
|
|
|
| sed '/^\(==\)\|\(\*\*\)[0-9]*\(==\)\|\(\*\*\)/d;' >vgsuppression.supp
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
valgrind="$(which valgrind) --leak-check=yes --show-reachable=no --suppressions=vgsuppression.supp -q $VALGRINDFLAGS"
|
|
|
|
|
else
|
|
|
|
|
valgrind="$(which valgrind) --leak-check=yes --show-reachable=no -q $VALGRINDFLAGS"
|
|
|
|
|
fi
|
2007-08-12 21:28:21 +02:00
|
|
|
else
|
|
|
|
|
echo "no valgrind found, go without it"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo
|
2008-04-12 02:07:16 +02:00
|
|
|
echo "================ ${0##*/} ================"
|
2007-08-12 21:28:21 +02:00
|
|
|
|
|
|
|
|
TESTCNT=0
|
|
|
|
|
SKIPCNT=0
|
|
|
|
|
FAILCNT=0
|
|
|
|
|
|
2009-02-12 02:36:52 +01:00
|
|
|
|
2007-08-13 17:22:07 +02:00
|
|
|
# the old testlog if existing will be used to check for previous test states
|
2007-08-12 21:28:21 +02:00
|
|
|
if test -f ,testlog; then
|
|
|
|
|
mv ,testlog ,testlog.pre
|
|
|
|
|
else
|
|
|
|
|
touch ,testlog.pre
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
date >,testlog
|
|
|
|
|
|
2009-02-12 02:36:52 +01:00
|
|
|
function compare_regex() # rxfile plainfile
|
|
|
|
|
{
|
|
|
|
|
local regex
|
|
|
|
|
local line
|
|
|
|
|
local miss
|
|
|
|
|
local lineno=1
|
|
|
|
|
local regexno=1
|
|
|
|
|
{
|
|
|
|
|
IFS='' read -u 3 -r regex || return 0
|
|
|
|
|
IFS='' read -u 4 -r line || { echo "no output"; return 1; }
|
|
|
|
|
while true; do
|
|
|
|
|
if [[ $line =~ $regex ]]; then
|
|
|
|
|
IFS='' read -u 4 -r line ||
|
|
|
|
|
if IFS='' read -u 3 -r regex; then
|
|
|
|
|
echo "premature end in output, expecting: '$regex':$regexno"
|
|
|
|
|
return 1
|
|
|
|
|
else
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
: $((++lineno))
|
|
|
|
|
miss=0
|
|
|
|
|
else
|
|
|
|
|
if [[ $((++miss)) -gt 1 ]]; then
|
|
|
|
|
echo -e "'$line':$lineno\ndoes not match\n'$regex':$regexno"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
IFS='' read -u 3 -r regex || { echo "more output than expected: '$line':$lineno"; return 1; }
|
|
|
|
|
: $((++regexno))
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
} 3<"$1" 4<"$2"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-12 21:28:21 +02:00
|
|
|
function TEST()
|
|
|
|
|
{
|
|
|
|
|
name="$1"
|
|
|
|
|
shift
|
2007-08-13 17:22:07 +02:00
|
|
|
rm -f ,send_stdin
|
|
|
|
|
rm -f ,expect_stdout
|
|
|
|
|
rm -f ,expect_stderr
|
|
|
|
|
|
|
|
|
|
while read -r line; do
|
|
|
|
|
cmd="${line%%:*}"
|
2009-02-12 02:36:52 +01:00
|
|
|
arg="${line#*:}"
|
|
|
|
|
arg="${arg:1}"
|
|
|
|
|
if [[ ! "$arg" ]]; then
|
|
|
|
|
arg='^$'
|
|
|
|
|
fi
|
2007-08-13 17:22:07 +02:00
|
|
|
expect_return=0
|
|
|
|
|
|
|
|
|
|
case $cmd in
|
|
|
|
|
'in')
|
|
|
|
|
echo "$arg" >>,send_stdin
|
|
|
|
|
;;
|
|
|
|
|
'out')
|
|
|
|
|
echo "$arg" >>,expect_stdout
|
|
|
|
|
;;
|
|
|
|
|
'err')
|
|
|
|
|
echo "$arg" >>,expect_stderr
|
|
|
|
|
;;
|
|
|
|
|
'return')
|
2008-04-12 02:07:16 +02:00
|
|
|
expect_return="$arg"
|
2007-08-13 17:22:07 +02:00
|
|
|
;;
|
2009-02-12 02:36:52 +01:00
|
|
|
'#'*|'')
|
|
|
|
|
:
|
|
|
|
|
;;
|
2007-08-13 17:22:07 +02:00
|
|
|
*)
|
|
|
|
|
echo "UNKOWN TEST COMMAND '$cmd'" 1>&2
|
|
|
|
|
exit
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
2007-08-12 21:28:21 +02:00
|
|
|
echo -n "TEST $name: "
|
|
|
|
|
echo -en "\nTEST $name: $* " >>,testlog
|
|
|
|
|
|
2008-04-12 02:07:16 +02:00
|
|
|
case "$TESTMODE" in
|
2007-08-12 21:28:21 +02:00
|
|
|
*FAST*)
|
|
|
|
|
if grep "^TEST $name: .* FAILED" ,testlog.pre >&/dev/null; then
|
|
|
|
|
MSGOK=" (fixed)"
|
|
|
|
|
MSGFAIL=" (still broken)"
|
|
|
|
|
elif grep "^TEST $name: .* \\(SKIPPED (ok)\\|OK\\)" ,testlog.pre >&/dev/null; then
|
|
|
|
|
echo ".. SKIPPED (ok)"
|
|
|
|
|
echo ".. SKIPPED (ok)" >>,testlog
|
|
|
|
|
SKIPCNT=$(($SKIPCNT + 1))
|
|
|
|
|
TESTCNT=$(($TESTCNT + 1))
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
MSGOK=" (new)"
|
|
|
|
|
MSGFAIL=" (new)"
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
MSGOK=""
|
|
|
|
|
MSGFAIL=""
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
TESTCNT=$(($TESTCNT + 1))
|
2007-08-13 17:22:07 +02:00
|
|
|
|
|
|
|
|
fails=0
|
|
|
|
|
|
2008-04-12 02:07:16 +02:00
|
|
|
echo -n >,testtmp
|
2007-08-13 17:45:43 +02:00
|
|
|
|
2008-04-12 02:07:16 +02:00
|
|
|
if ! test -x $TESTBIN; then
|
|
|
|
|
echo -n >,stdout
|
|
|
|
|
echo "test binary '$TESTBIN' not found" >,stderr
|
|
|
|
|
((fails+=1))
|
2007-08-13 17:22:07 +02:00
|
|
|
|
2008-04-12 02:07:16 +02:00
|
|
|
else
|
2009-02-12 02:36:52 +01:00
|
|
|
|
2008-04-12 02:07:16 +02:00
|
|
|
if test -f ,send_stdin; then
|
2009-02-12 02:36:52 +01:00
|
|
|
env $TESTBIN_PREFIX $TESTBIN "$@" <,send_stdin 2>,stderr >,stdout
|
2008-04-12 02:07:16 +02:00
|
|
|
else
|
2009-02-12 02:36:52 +01:00
|
|
|
env $TESTBIN_PREFIX $TESTBIN "$@" 2>,stderr >,stdout
|
2008-04-12 02:07:16 +02:00
|
|
|
fi &>/dev/null
|
|
|
|
|
return=$?
|
|
|
|
|
|
|
|
|
|
if test -f ,expect_stdout; then
|
2009-02-12 02:36:52 +01:00
|
|
|
grep -v "$NOBUG_LOGREGEX" <,stdout >,tmp
|
|
|
|
|
if ! compare_regex ,expect_stdout ,tmp >>,cmptmp; then
|
2008-04-12 02:07:16 +02:00
|
|
|
echo "unexpected data on stdout" >>,testtmp
|
2009-02-12 02:36:52 +01:00
|
|
|
cat ,cmptmp >>,testtmp
|
2008-04-12 02:07:16 +02:00
|
|
|
((fails+=1))
|
|
|
|
|
fi
|
2009-02-12 02:36:52 +01:00
|
|
|
rm ,tmp ,cmptmp
|
2008-04-12 02:07:16 +02:00
|
|
|
fi
|
2007-08-13 17:22:07 +02:00
|
|
|
|
2008-04-12 02:07:16 +02:00
|
|
|
if test -f ,expect_stderr; then
|
2009-02-12 02:36:52 +01:00
|
|
|
grep -v "$NOBUG_LOGREGEX" <,stderr >,tmp
|
|
|
|
|
cat ,tmp >>,testtmp
|
|
|
|
|
if ! compare_regex ,expect_stderr ,tmp >>,cmptmp; then
|
2008-04-12 02:07:16 +02:00
|
|
|
echo "unexpected data on stderr" >>,testtmp
|
2009-02-12 02:36:52 +01:00
|
|
|
cat ,cmptmp >>,testtmp
|
2008-04-12 02:07:16 +02:00
|
|
|
((fails+=1))
|
|
|
|
|
fi
|
2009-02-12 02:36:52 +01:00
|
|
|
rm ,tmp ,cmptmp
|
2007-08-13 17:22:07 +02:00
|
|
|
fi
|
|
|
|
|
|
2009-02-12 02:36:52 +01:00
|
|
|
if [[ "${expect_return:0:1}" = '!' ]]; then
|
|
|
|
|
if [[ "${expect_return#\!}" = "$return" ]]; then
|
|
|
|
|
echo "unexpected return value $return, expected $expect_return" >>,testtmp
|
|
|
|
|
((fails+=1))
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
if [[ "${expect_return}" != "$return" ]]; then
|
|
|
|
|
echo "unexpected return value $return, expected $expect_return" >>,testtmp
|
|
|
|
|
((fails+=1))
|
|
|
|
|
fi
|
2007-08-13 17:22:07 +02:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if test $fails -eq 0; then
|
2007-08-12 21:28:21 +02:00
|
|
|
echo ".. OK$MSGOK"
|
|
|
|
|
echo ".. OK$MSGOK" >>,testlog
|
|
|
|
|
else
|
|
|
|
|
echo ".. FAILED$MSGFAIL";
|
|
|
|
|
echo ".. FAILED$MSGFAIL" >>,testlog
|
2007-08-13 17:22:07 +02:00
|
|
|
cat ,testtmp >>,testlog
|
|
|
|
|
rm ,testtmp
|
2007-08-13 17:45:43 +02:00
|
|
|
echo "stderr was:" >>,testlog
|
|
|
|
|
cat ,stderr >>,testlog
|
2007-08-12 21:28:21 +02:00
|
|
|
echo END >>,testlog
|
|
|
|
|
FAILCNT=$(($FAILCNT + 1))
|
|
|
|
|
case $TESTMODE in
|
|
|
|
|
*FIRSTFAIL*)
|
|
|
|
|
break 2
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function PLANNED()
|
|
|
|
|
{
|
|
|
|
|
echo -n "PLANNED $1: "
|
|
|
|
|
echo -en "\nPLANNED $* " >>,testlog
|
|
|
|
|
echo ".. SKIPPED (planned)"
|
|
|
|
|
echo ".. SKIPPED (planned)" >>,testlog
|
|
|
|
|
SKIPCNT=$(($SKIPCNT + 1))
|
|
|
|
|
TESTCNT=$(($TESTCNT + 1))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function RUNTESTS()
|
|
|
|
|
{
|
2007-08-30 01:40:07 +02:00
|
|
|
if test \( ! "${TESTSUITES/*,*/}" \) -a "$TESTSUITES"; then
|
|
|
|
|
TESTSUITES="{$TESTSUITES}"
|
2007-08-12 21:28:21 +02:00
|
|
|
fi
|
2008-04-12 02:07:16 +02:00
|
|
|
for t in $(eval echo "$srcdir/*$TESTSUITES*.tests"); do
|
2007-08-30 00:27:17 +02:00
|
|
|
echo "$t"
|
|
|
|
|
done | sort | uniq | {
|
|
|
|
|
while read i; do
|
2008-10-23 04:53:50 +02:00
|
|
|
echo
|
|
|
|
|
echo "### $i" >&2
|
2007-08-30 01:40:07 +02:00
|
|
|
if test -f $i; then
|
|
|
|
|
source $i
|
|
|
|
|
fi
|
2007-08-30 00:27:17 +02:00
|
|
|
done
|
|
|
|
|
echo
|
|
|
|
|
if [ $FAILCNT = 0 ]; then
|
|
|
|
|
echo " ... PASSED $(($TESTCNT - $SKIPCNT)) TESTS, $SKIPCNT SKIPPED"
|
|
|
|
|
#rm ,testlog
|
|
|
|
|
else
|
|
|
|
|
echo " ... SUCCEDED $(($TESTCNT - $FAILCNT - $SKIPCNT)) TESTS"
|
|
|
|
|
echo " ... FAILED $FAILCNT TESTS"
|
|
|
|
|
echo " ... SKIPPED $SKIPCNT TESTS"
|
|
|
|
|
echo " see ',testlog' for details"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
2007-08-12 21:28:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function TESTING()
|
|
|
|
|
{
|
|
|
|
|
echo
|
|
|
|
|
echo "$1"
|
2009-02-12 02:36:52 +01:00
|
|
|
echo -e "\n#### $1" >>,testlog
|
|
|
|
|
|
|
|
|
|
if [[ -x ".libs/$2" ]]; then
|
|
|
|
|
TESTBIN_PREFIX="./libtool --mode=execute $valgrind"
|
|
|
|
|
else
|
|
|
|
|
TESTBIN_PREFIX="$valgrind"
|
|
|
|
|
fi
|
|
|
|
|
TESTBIN="$2"
|
2007-08-12 21:28:21 +02:00
|
|
|
}
|
|
|
|
|
|
2007-08-30 01:40:07 +02:00
|
|
|
TESTSUITES="${TESTSUITES}${1:+${TESTSUITES:+,}$1}"
|
2007-08-30 00:27:17 +02:00
|
|
|
|
2007-08-12 21:28:21 +02:00
|
|
|
RUNTESTS
|