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
41 #config HEAD- Configuration; configuration; configure tests
43 #config PARA LOGSUPPRESS; LOGSUPPRESS; suppress certain lines from stderr
44 #config LOGSUPPRESS='^\(\*\*[0-9]*\*\* \)\?[0-9]\{10,\}: \(TRACE\|INFO\|NOTICE\|WARNING\|ERR\):'
46 #config Programms sometimes emit additional diagnostics on stderr which is volatile and not necessary for
47 #config validating the output the `LOGSUPRESS` variable can be set to a regex to filter this things out.
48 #config The default as shown above filters some NoBug annotations and non fatal logging out.
50 LOGSUPPRESS
='^\(\*\*[0-9]*\*\* \)\?[0-9]\{10,\}: \(TRACE\|INFO\|NOTICE\|WARNING\|ERR\):'
52 #config PARA Resource Limits; ulimit; constrain resource limits
53 #config It is possible to set some limits for tests to protect the system against really broken cases.
54 #config Since running under valgrind takes consinderable more resources there are separate variants for
55 #config limits when running under valgrind.
58 #config Maximal CPU time the test may take after it will be killed with SIGXCPU. This protects agaist Lifelocks.
61 #config Maximal wall-time a test may take after this it will be killed with SIGKILL. Protects against Deadlocks.
63 #config LIMIT_VSZ=524288
64 #config Maximal virtual memory size the process may map, allocations/mappings will fail when this limit is reached.
65 #config Protects against memory leaks.
67 #config LIMIT_VG_CPU=20
68 #config LIMIT_VG_TIME=30
69 #config LIMIT_VG_VSZ=524288
70 #config Same variables again with limits when running under valgrind.
80 #configf HEAD~ Configuration Files; configuration files; define variables to configure the test
82 #configf `test.sh` reads config files from the following location if they are exist
83 #configf * 'test.conf' from the current directory
84 #configf * '$srcdir/test.conf' `$srcdir` is set by autotools
85 #configf * '$TEST_CONF' a user defineable variable to point to a config file
87 test -f 'test.conf' && source test.conf
88 test "$srcdir" -a -f '$srcdir/test.conf' && source "$srcdir/test.conf"
89 test "$TEST_CONF" -a -f "$TEST_CONF" && source "$TEST_CONF"
92 TESTDIR
="$(dirname "$arg0")"
95 #libtool HEAD Libtool; libtool; support for libtool
96 #libtool When test.sh detects the presence of './libtool' it runs all tests with
97 #libtool `./libtool --mode=execute`.
100 if test -x .
/libtool
; then
101 LIBTOOL_EX
="./libtool --mode=execute"
104 #valgrind HEAD- Valgrind; valgrind; valgrind support
105 #valgrind Test are run under valgrind supervision by default, if not disabled.
107 #valgrind PARA VALGRINDFLAGS; VALGRINDFLAGS; control valgrind options
108 #valgrind VALGRINDFLAGS="--leak-check=yes --show-reachable=yes"
110 #valgrind `VALGRINDFLAGS` define the options which are passed to valgrind. This can be used to override
111 #valgrind the defaults or switching the valgrind tool. The special case `VALGRINDFLAGS=DISABLE` will disable
112 #valgrind valgrind for the tests.
114 #valgrind HEAD~ Generating Valgrind Suppression Files; vgsuppression; ignore false positives
115 #valgrind When there is a 'vgsuppression' executable in the current dir (build by something external) then
116 #valgrind test.sh uses this to generate a local 'vgsuppression.supp' file and uses that to suppress
117 #valgrind all errors generated by 'vgsuppression'. The Idea here is that one adds code which triggers known
118 #valgrind false positives in 'vgsuppression'. Care must be taken that this file is simple and does
119 #valgrind not generate true positives.
121 ulimit -S -t ${LIMIT_CPU:-5} -v ${LIMIT_VSZ:-524288}
123 LIMIT_TIME_REAL
="$LIMIT_TIME"
124 if [ "$VALGRINDFLAGS" = 'DISABLE' ]; then
125 echo "valgrind explicit disabled"
127 if [ "$(which valgrind)" ]; then
128 ulimit -S -t ${ULIMIT_VG_CPU:-20} -v ${ULIMIT_VG_VSZ:-524288}
129 LIMIT_TIME_REAL
="$LIMIT_VG_TIME"
130 if [[ -x 'vgsuppression' ]]; then
131 if [[ 'vgsuppression' -nt 'vgsuppression.supp' ]]; then
132 echo 'generating valgrind supression file'
134 $LIBTOOL_EX $
(which valgrind
) ${VALGRINDFLAGS:---leak-check=yes --show-reachable=yes} -q --gen-suppressions=all vgsuppression
2>&1 \
135 |
awk '/^{/ {i = 1;} /^}/ {i = 0; print $0;} {if (i == 1) print $0;}' >vgsuppression.supp
137 valgrind
="$(which valgrind) ${VALGRINDFLAGS:---leak-check=yes --show-reachable=no} --suppressions=vgsuppression.supp -q"
139 valgrind
="$(which valgrind) ${VALGRINDFLAGS:---leak-check=yes --show-reachable=no -q}"
142 echo "no valgrind found, go without it"
147 echo "================ ${0##*/} ================"
154 # the old testlog if existing will be used to check for previous test states
155 if test -f ,testlog
; then
156 mv ,testlog
,testlog.pre
163 function compare_template
() # template plainfile
171 IFS
='' read -u 3 -r template ||
return 0
172 IFS
='' read -u 4 -r line ||
{ echo "no output"; return 1; }
174 local cmd
="${template%%:*}:"
175 local arg
="${template#*: }"
179 if [[ $line =~
$arg ]]; then
180 IFS
='' read -u 4 -r line ||
181 if IFS
='' read -u 3 -r template
; then
182 echo "premature end in output, expecting $template:$templateno"
190 if [[ $
((++miss
)) -gt 1 ]]; then
191 echo -e "'$line':$lineno\ndoes not match\n$template:$templateno"
194 IFS
='' read -u 3 -r template ||
{ echo "more output than expected: '$line':$lineno"; return 1; }
199 if [[ "$line" = "$arg" ]]; then
200 IFS
='' read -u 3 -r template
&& IFS
='' read -u 4 -r line ||
{
204 echo -e "'$line':$lineno\ndoes not match\n$template:$templateno"
209 echo "UNKOWN MATCH COMMAND '$cmd'" 1>&2
217 #tests HEAD- Writing Tests; tests; how to write testsuites
242 echo -e "\n#### $1" >>,testlog
261 local valgrind
="$valgrind"
262 if [ "$VALGRINDFLAGS" = 'DISABLE' ]; then
267 while read -r line
; do
268 local cmd
="${line%%:*}:"
269 local arg
="${line#*: }"
271 if [[ ! "$arg" ]]; then
278 condstack
="1$condstack"
280 condstack
="0$condstack"
284 if [[ "${condstack:0:1}" = "1" ]]; then
285 condstack
="0${condstack:1}"
287 condstack
="1${condstack:1}"
291 if [[ "${condstack:0:1}" = "0" ]] && $arg; then
292 condstack
="1${condstack:1}"
294 condstack
="0${condstack:1}"
298 condstack
="${condstack:1}"
301 if [[ "${condstack:0:1}" = "1" ]]; then
304 echo "$arg" >>,send_stdin
307 echo "regex_cont: $arg" >>,expect_stdout
310 echo "regex_cont: $arg" >>,expect_stderr
313 echo "literal: $arg" >>,expect_stdout
316 echo "literal: $arg" >>,expect_stderr
325 echo "UNKOWN TEST COMMAND '$cmd'" 1>&2
333 echo -n "TEST $name: "
334 echo -en "\nTEST $name: $* " >>,testlog
338 if grep "^TEST $name: .* FAILED" ,testlog.pre
>&/dev
/null
; then
340 MSGFAIL
=" (still broken)"
341 elif grep "^TEST $name: .* \\(SKIPPED (ok)\\|OK\\)" ,testlog.pre
>&/dev
/null
; then
342 echo ".. SKIPPED (ok)"
343 echo ".. SKIPPED (ok)" >>,testlog
344 SKIPCNT
=$
(($SKIPCNT + 1))
345 TESTCNT
=$
(($TESTCNT + 1))
358 TESTCNT
=$
(($TESTCNT + 1))
365 if declare -F |
grep $TESTBIN >&/dev
/null
; then
367 elif test -x $TESTBIN; then
368 CALL
="env $LIBTOOL_EX $valgrind"
372 echo "test binary '$TESTBIN' not found" >,stderr
376 if test "$CALL" != '-'; then
377 if test -f ,send_stdin
; then
379 $CALL $TESTBIN "$@" <,send_stdin
2>,stderr
>,stdout
384 $CALL $TESTBIN "$@" 2>,stderr
>,stdout
391 ( sleep $LIMIT_TIME_REAL && kill -KILL $pid ) &>/dev
/null
&
395 if test -f ,expect_stdout
; then
396 grep -v "$LOGSUPPRESS" <,stdout
>,tmp
397 if ! compare_template
,expect_stdout
,tmp
>>,cmptmp
; then
398 echo "unexpected data on stdout" >>,testtmp
399 cat ,cmptmp
>>,testtmp
405 if test -f ,expect_stderr
; then
406 grep -v "$LOGSUPPRESS" <,stderr
>,tmp
408 if ! compare_template
,expect_stderr
,tmp
>>,cmptmp
; then
409 echo "unexpected data on stderr" >>,testtmp
410 cat ,cmptmp
>>,testtmp
416 if [[ "${expect_return:0:1}" = '!' ]]; then
417 if [[ "${expect_return#\!}" = "$return" ]]; then
418 echo "unexpected return value $return, expected $expect_return" >>,testtmp
422 if [[ "${expect_return}" != "$return" ]]; then
423 echo "unexpected return value $return, expected $expect_return" >>,testtmp
429 if test $fails -eq 0; then
431 echo ".. OK$MSGOK" >>,testlog
433 echo ".. FAILED$MSGFAIL";
434 echo ".. FAILED$MSGFAIL" >>,testlog
435 cat ,testtmp
>>,testlog
437 echo "stderr was:" >>,testlog
438 cat ,stderr
>>,testlog
440 FAILCNT
=$
(($FAILCNT + 1))
451 echo -n "PLANNED $1: "
452 echo -en "\nPLANNED $* " >>,testlog
453 echo ".. SKIPPED (planned)"
454 echo ".. SKIPPED (planned)" >>,testlog
455 SKIPCNT
=$
(($SKIPCNT + 1))
456 TESTCNT
=$
(($TESTCNT + 1))
461 if test \
( ! "${TESTSUITES/*,*/}" \
) -a "$TESTSUITES"; then
462 TESTSUITES
="{$TESTSUITES}"
464 for t
in $
(eval echo "$TESTDIR/*$TESTSUITES*.tests"); do
466 done |
sort |
uniq |
{
475 if [ $FAILCNT = 0 ]; then
476 echo " ... PASSED $(($TESTCNT - $SKIPCNT)) TESTS, $SKIPCNT SKIPPED"
479 echo " ... SUCCEDED $(($TESTCNT - $FAILCNT - $SKIPCNT)) TESTS"
480 echo " ... FAILED $FAILCNT TESTS"
481 echo " ... SKIPPED $SKIPCNT TESTS"
482 echo " see ',testlog' for details"
488 TESTSUITES
="${TESTSUITES}${1:+${TESTSUITES:+,}$1}"