1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-04 17:47:26 +03:00
Martin Schwenke 21b2190751 tests: Remove ctdb_test_env
Move the contents to integration.bash and run_tests as appropriate.

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

(This used to be ctdb commit 6136ab02db261b26a2a58b526c913e37e8146841)
2012-04-27 15:40:43 +10:00

192 lines
4.0 KiB
Bash
Executable File

#!/bin/bash
usage() {
cat <<EOF
Usage: run_tests [OPTIONS] [TESTS]
Options:
-s Print a summary of tests results after running all tests
-l Use local daemons for integration tests
-v Verbose - print test output for non-failures (only some tests)
-A Use "cat -A" to print test output (only some tests)
-D Show diff between failed/expected test output (some tests only)
-X Trace certain scripts run by tests using -x (only some tests)
-d Print descriptions of tests instead of filenames (dodgy!)
-q Quiet - don't show tests being run (hint: use with -s)
-x Trace this script with the -x option
EOF
exit 1
}
# Print a message and exit.
die ()
{
echo "$1" >&2 ; exit ${2:-1}
}
######################################################################
with_summary=false
with_desc=false
quiet=false
export TEST_VERBOSE=false
export TEST_COMMAND_TRACE=""
export TEST_CAT_RESULTS_OPTS=""
export TEST_DIFF_RESULTS=false
export TEST_LOCAL_DAEMONS # No default, developer can "override"!
temp=$(getopt -n "$prog" -o "xdhlqsvXAD" -l help -- "$@")
[ $? != 0 ] && usage
eval set -- "$temp"
while true ; do
case "$1" in
-x) set -x; shift ;;
-d) with_desc=true ; shift ;; # 4th line of output is description
-l) TEST_LOCAL_DAEMONS="3" ; shift ;;
-q) quiet=true ; shift ;;
-s) with_summary=true ; shift ;;
-v) TEST_VERBOSE=true ; shift ;;
-X) TEST_COMMAND_TRACE="sh -x" ; shift ;;
-A) TEST_CAT_RESULTS_OPTS="-A" ; shift ;;
-D) TEST_DIFF_RESULTS=true ; shift ;;
--) shift ; break ;;
*) usage ;;
esac
done
if $quiet ; then
show_progress() { cat >/dev/null ; }
else
show_progress() { cat ; }
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@')
ww=$((rows - 7))
tf=$(mktemp)
sf=$(mktemp)
set -o pipefail
run_one_test ()
{
_f="$1"
[ -x "$_f" ] || die "test \"$_f\" is not executable"
tests_total=$(($tests_total + 1))
export TEST_SCRIPTS_DIR=$(dirname "$0")
ctdb_test_run "$_f" | tee "$tf" | show_progress
status=$?
if $with_summary ; then
if [ $status -eq 0 ] ; then
tests_passed=$(($tests_passed + 1))
t=" PASSED "
else
t="*FAILED*"
tests_failed=$(($tests_failed + 1))
fi
if $with_desc ; then
desc=$(tail -n +4 $tf | head -n 1)
_f="$desc"
fi
echo "$t $_f" >>"$sf"
fi
}
for f ; do
if [ -d "$f" ] ; then
for i in $(ls "${f%/}/"*".sh" 2>/dev/null) ; do
run_one_test "$i"
done
elif [ -f "$f" ] ; then
run_one_test "$f"
else
die "test \"$f\" is not recognised"
fi
done
rm -f "$tf"
if $with_summary ; then
echo
cat "$sf"
echo
echo "${tests_passed}/${tests_total} tests passed"
fi
rm -f "$sf"
if [ $tests_failed -gt 0 ] ; then
exit 1
fi