2 # Copyright (C) Lumiera.org
3 # 2007 - 2008, Christian Thaeter <ct@pipapo.org>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # TESTMODE=FULL yet unimplemented
20 # run all tests, PLANNED which fail count as error
23 # run only tests which recently failed
26 # stop testing on the first failure
29 NOBUG_LOGREGEX
='^\(\*\*[0-9]*\*\* \)\?[0-9]\{10,\}: \(TRACE\|INFO\|NOTICE\|WARNING\|ERR\):'
32 srcdir
="$(dirname "$arg0")"
34 ulimit -S -t 5 -v 524288
36 if [ "$VALGRINDFLAGS" = 'DISABLE' ]; then
37 echo "valgrind explicit disabled"
39 if [ "$(which valgrind)" ]; then
41 if [[ -x 'vgsuppression' ]]; then
42 if [[ 'vgsuppression' -nt 'vgsuppression.supp' ]]; then
43 echo 'generating valgrind supression file'
45 if [[ -x ".libs/vgsuppression" ]]; then
46 .
/libtool
--mode=execute valgrind
${VALGRINDFLAGS:---leak-check=yes --show-reachable=yes} -q --gen-suppressions=all vgsuppression
2>&1 \
47 |
awk '/^{/ {i = 1;} /^}/ {i = 0; print $0;} {if (i == 1) print $0;}' >vgsuppression.supp
49 valgrind
${VALGRINDFLAGS:---leak-check=yes --show-reachable=yes} -q --gen-suppressions=all .
/vgsuppression
2>&1 \
50 |
awk '/^{/ {i = 1;} /^}/ {i = 0; print $0;} {if (i == 1) print $0;}' >vgsuppression.supp
53 valgrind
="$(which valgrind) ${VALGRINDFLAGS:---leak-check=yes --show-reachable=no } --suppressions=vgsuppression.supp -q"
55 valgrind
="$(which valgrind) ${VALGRINDFLAGS:---leak-check=yes --show-reachable=no -q}"
58 echo "no valgrind found, go without it"
63 echo "================ ${0##*/} ================"
70 # the old testlog if existing will be used to check for previous test states
71 if test -f ,testlog
; then
72 mv ,testlog
,testlog.pre
79 function compare_regex
() # rxfile plainfile
87 IFS
='' read -u 3 -r regex ||
return 0
88 IFS
='' read -u 4 -r line ||
{ echo "no output"; return 1; }
90 if [[ $line =~
$regex ]]; then
91 IFS
='' read -u 4 -r line ||
92 if IFS
='' read -u 3 -r regex
; then
93 echo "premature end in output, expecting: '$regex':$regexno"
101 if [[ $
((++miss
)) -gt 1 ]]; then
102 echo -e "'$line':$lineno\ndoes not match\n'$regex':$regexno"
105 IFS
='' read -u 3 -r regex ||
{ echo "more output than expected: '$line':$lineno"; return 1; }
122 local valgrind
="$valgrind"
123 if [ "$VALGRINDFLAGS" = 'DISABLE' ]; then
127 while read -r line
; do
131 if [[ ! "$arg" ]]; then
137 echo "$arg" >>,send_stdin
140 echo "$arg" >>,expect_stdout
143 echo "$arg" >>,expect_stderr
152 echo "UNKOWN TEST COMMAND '$cmd'" 1>&2
157 echo -n "TEST $name: "
158 echo -en "\nTEST $name: $* " >>,testlog
162 if grep "^TEST $name: .* FAILED" ,testlog.pre
>&/dev
/null
; then
164 MSGFAIL
=" (still broken)"
165 elif grep "^TEST $name: .* \\(SKIPPED (ok)\\|OK\\)" ,testlog.pre
>&/dev
/null
; then
166 echo ".. SKIPPED (ok)"
167 echo ".. SKIPPED (ok)" >>,testlog
168 SKIPCNT
=$
(($SKIPCNT + 1))
169 TESTCNT
=$
(($TESTCNT + 1))
182 TESTCNT
=$
(($TESTCNT + 1))
189 if declare -F |
grep $TESTBIN >&/dev
/null
; then
191 elif test -x $TESTBIN; then
192 CALL
="env $TESTBIN_PREFIX $valgrind"
196 echo "test binary '$TESTBIN' not found" >,stderr
200 if test "$CALL" != '-'; then
202 if test -f ,send_stdin
; then
203 $CALL $TESTBIN "$@" <,send_stdin
2>,stderr
>,stdout
205 $CALL $TESTBIN "$@" 2>,stderr
>,stdout
209 if test -f ,expect_stdout
; then
210 grep -v "$NOBUG_LOGREGEX" <,stdout
>,tmp
211 if ! compare_regex
,expect_stdout
,tmp
>>,cmptmp
; then
212 echo "unexpected data on stdout" >>,testtmp
213 cat ,cmptmp
>>,testtmp
219 if test -f ,expect_stderr
; then
220 grep -v "$NOBUG_LOGREGEX" <,stderr
>,tmp
222 if ! compare_regex
,expect_stderr
,tmp
>>,cmptmp
; then
223 echo "unexpected data on stderr" >>,testtmp
224 cat ,cmptmp
>>,testtmp
230 if [[ "${expect_return:0:1}" = '!' ]]; then
231 if [[ "${expect_return#\!}" = "$return" ]]; then
232 echo "unexpected return value $return, expected $expect_return" >>,testtmp
236 if [[ "${expect_return}" != "$return" ]]; then
237 echo "unexpected return value $return, expected $expect_return" >>,testtmp
243 if test $fails -eq 0; then
245 echo ".. OK$MSGOK" >>,testlog
247 echo ".. FAILED$MSGFAIL";
248 echo ".. FAILED$MSGFAIL" >>,testlog
249 cat ,testtmp
>>,testlog
251 echo "stderr was:" >>,testlog
252 cat ,stderr
>>,testlog
254 FAILCNT
=$
(($FAILCNT + 1))
265 echo -n "PLANNED $1: "
266 echo -en "\nPLANNED $* " >>,testlog
267 echo ".. SKIPPED (planned)"
268 echo ".. SKIPPED (planned)" >>,testlog
269 SKIPCNT
=$
(($SKIPCNT + 1))
270 TESTCNT
=$
(($TESTCNT + 1))
275 if test \
( ! "${TESTSUITES/*,*/}" \
) -a "$TESTSUITES"; then
276 TESTSUITES
="{$TESTSUITES}"
278 for t
in $
(eval echo "$srcdir/*$TESTSUITES*.tests"); do
280 done |
sort |
uniq |
{
289 if [ $FAILCNT = 0 ]; then
290 echo " ... PASSED $(($TESTCNT - $SKIPCNT)) TESTS, $SKIPCNT SKIPPED"
293 echo " ... SUCCEDED $(($TESTCNT - $FAILCNT - $SKIPCNT)) TESTS"
294 echo " ... FAILED $FAILCNT TESTS"
295 echo " ... SKIPPED $SKIPCNT TESTS"
296 echo " see ',testlog' for details"
306 echo -e "\n#### $1" >>,testlog
308 if [[ -x ".libs/$2" ]]; then
309 TESTBIN_PREFIX
="./libtool --mode=execute"
316 TESTSUITES
="${TESTSUITES}${1:+${TESTSUITES:+,}$1}"