1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

tests - move functions only used by scripts/run_tests into that script

Along with minor logic tweaks and removal of test_exit().

Signed-off-by: Martin Schwenke <martin@meltin.net>

(This used to be ctdb commit 00713eb46cce638339845799bba2da041b3d02fb)
This commit is contained in:
Martin Schwenke 2012-04-16 14:48:49 +10:00
parent f6178fcc9d
commit fec6fe6287
2 changed files with 62 additions and 62 deletions

View File

@ -8,51 +8,6 @@ fail ()
######################################################################
ctdb_test_begin ()
{
local name="$1"
teststarttime=$(date '+%s')
testduration=0
echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
echo "Running test $name ($(date '+%T'))"
echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
}
ctdb_test_end ()
{
local name="$1" ; shift
local status="$1" ; shift
# "$@" is command-line
local interp="SKIPPED"
local statstr=" (reason $*)"
if [ -n "$status" ] ; then
if [ $status -eq 0 ] ; then
interp="PASSED"
statstr=""
echo "ALL OK: $*"
else
interp="FAILED"
statstr=" (status $status)"
testfailures=$(($testfailures+1))
fi
fi
testduration=$(($(date +%s)-$teststarttime))
echo "=========================================================================="
echo "TEST ${interp}: ${name}${statstr} (duration: ${testduration}s)"
echo "=========================================================================="
}
test_exit ()
{
exit $(($testfailures+0))
}
ctdb_check_time_logs ()
{
local threshold=20
@ -144,22 +99,6 @@ ctdb_test_exit_hook_add ()
ctdb_test_exit_hook="${ctdb_test_exit_hook}${ctdb_test_exit_hook:+ ; }$*"
}
ctdb_test_run ()
{
local name="$1" ; shift
[ -n "$1" ] || set -- "$name"
ctdb_test_begin "$name"
local status=0
"$@" || status=$?
ctdb_test_end "$name" "$status" "$*"
return $status
}
ctdb_test_usage()
{
local status=${1:-2}

View File

@ -46,8 +46,66 @@ fi
######################################################################
ctdb_test_begin ()
{
local name="$1"
teststarttime=$(date '+%s')
testduration=0
echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
echo "Running test $name ($(date '+%T'))"
echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
}
ctdb_test_end ()
{
local name="$1" ; shift
local status="$1" ; shift
# "$@" is command-line
local interp="SKIPPED"
local statstr=" (reason $*)"
if [ -n "$status" ] ; then
if [ $status -eq 0 ] ; then
interp="PASSED"
statstr=""
echo "ALL OK: $*"
else
interp="FAILED"
statstr=" (status $status)"
fi
fi
testduration=$(($(date +%s)-$teststarttime))
echo "=========================================================================="
echo "TEST ${interp}: ${name}${statstr} (duration: ${testduration}s)"
echo "=========================================================================="
}
ctdb_test_run ()
{
local name="$1" ; shift
[ -n "$1" ] || set -- "$name"
ctdb_test_begin "$name"
local status=0
"$@" || status=$?
ctdb_test_end "$name" "$status" "$*"
return $status
}
######################################################################
tests_total=0
tests_passed=0
tests_failed=0
summary=""
rows=$(if tty -s ; then stty size ; else echo x 80 ; fi | sed -e 's@.* @@' -e 's@^0$@80@')
@ -69,6 +127,7 @@ for f; do
t=" PASSED "
else
t="*FAILED*"
tests_failed=$(($tests_failed + 1))
fi
if $with_desc ; then
desc=$(tail -n +4 $tf | head -n 1)
@ -89,4 +148,6 @@ fi
rm -f "$sf"
test_exit
if [ $tests_failed -gt 0 ] ; then
exit 1
fi