5 Usage: $0 [OPTIONS] [TESTS]
8 -A Use "cat -A" to print test output (only some tests)
9 -c Run integration tests on a cluster
10 -C Clean up - kill daemons and remove TEST_VAR_DIR when done
11 -d Print descriptions of tests instead of filenames (dodgy!)
12 -D Show diff between failed/expected test output (some tests only)
13 -e Exit on the first test failure
14 -H No headers - for running single test with other wrapper
15 -N Don't print summary of tests results after running all tests
16 -q Quiet - don't show tests being run (hint: use with -s)
17 -S <lib> Use socket wrapper library <lib> for local integration tests
18 -v Verbose - print test output for non-failures (only some tests)
19 -V <dir> Use <dir> as TEST_VAR_DIR
20 -x Trace this script with the -x option
21 -X Trace certain scripts run by tests using -x (only some tests)
26 # Print a message and exit.
29 echo "$1" >&2 ; exit ${2:-1}
32 # Print a message and return failure
35 echo "$1" >&2 ; return ${2:-1}
38 ######################################################################
46 export TEST_VERBOSE=false
47 export TEST_COMMAND_TRACE=false
48 export TEST_CAT_RESULTS_OPTS=""
49 export TEST_DIFF_RESULTS=false
50 export TEST_LOCAL_DAEMONS
51 [ -n "$TEST_LOCAL_DAEMONS" ] || TEST_LOCAL_DAEMONS=3
52 export TEST_VAR_DIR=""
53 export TEST_CLEANUP=false
54 export TEST_TIMEOUT=3600
55 export TEST_SOCKET_WRAPPER_SO_PATH=""
57 temp=$(getopt -n "$prog" -o "AcCdDehHNqS:T:vV:xX" -l help -- "$@")
65 -A) TEST_CAT_RESULTS_OPTS="-A" ; shift ;;
66 -c) TEST_LOCAL_DAEMONS="" ; shift ;;
67 -C) TEST_CLEANUP=true ; shift ;;
68 -d) with_desc=true ; shift ;; # 4th line of output is description
69 -D) TEST_DIFF_RESULTS=true ; shift ;;
70 -e) exit_on_fail=true ; shift ;;
71 -H) no_header=true ; shift ;;
72 -N) with_summary=false ; shift ;;
73 -q) quiet=true ; shift ;;
74 -S) TEST_SOCKET_WRAPPER_SO_PATH="$2" ; shift 2 ;;
75 -T) TEST_TIMEOUT="$2" ; shift 2 ;;
76 -v) TEST_VERBOSE=true ; shift ;;
77 -V) TEST_VAR_DIR="$2" ; shift 2 ;;
79 -X) TEST_COMMAND_TRACE=true ; shift ;;
85 case $(basename "$0") in
87 # Running on a cluster... same as -c
93 show_progress() { cat >/dev/null ; }
95 show_progress() { cat ; }
98 ######################################################################
104 teststarttime=$(date '+%s')
107 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
108 echo "Running test $name ($(date '+%T'))"
109 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
114 local name="$1" ; shift
115 local status="$1" ; shift
116 # "$@" is command-line
118 local interp="SKIPPED"
119 local statstr=" (reason $*)"
120 if [ -n "$status" ] ; then
121 if [ $status -eq 0 ] ; then
125 elif [ $status -eq 124 ] ; then
127 statstr=" (status $status)"
130 statstr=" (status $status)"
134 testduration=$(($(date +%s)-$teststarttime))
136 echo "=========================================================================="
137 echo "TEST ${interp}: ${name}${statstr} (duration: ${testduration}s)"
138 echo "=========================================================================="
144 local name="$1" ; shift
146 [ -n "$1" ] || set -- "$name"
148 $no_header || ctdb_test_begin "$name"
151 timeout $TEST_TIMEOUT "$@" || status=$?
153 $no_header || ctdb_test_end "$name" "$status" "$*"
158 ######################################################################
165 if ! which mktemp >/dev/null 2>&1 ; then
166 # Not perfect, but it will do...
170 if [ "$1" = "-d" ] ; then
173 local t="${TMPDIR:-/tmp}/tmp.$$.$RANDOM"
186 tf=$(mktemp) || die "mktemp failed for tf - is TMPDIR missing?"
187 sf=$(mktemp) || die "mktemp failed for sf - is TMPDIR missing?"
195 tests_total=$(($tests_total + 1))
197 if [ -x "$f" ] ; then
198 ctdb_test_run "$f" | tee "$tf" | show_progress
200 ctdb_test_run "$f" fail "TEST NOT EXECUTABLE"
203 if [ $status -eq 0 ] ; then
204 tests_passed=$(($tests_passed + 1))
206 tests_failed=$(($tests_failed + 1))
208 if $with_summary ; then
210 if [ $status -eq 0 ] ; then
216 desc=$(tail -n +4 $tf | head -n 1)
223 find_and_run_one_test ()
228 local f="${dir}${dir:+/}${t}"
230 if [ -d "$f" ] ; then
232 for i in $(ls "${f%/}/"*".sh" 2>/dev/null) ; do
234 if $exit_on_fail && [ $status -ne 0 ] ; then
238 # No tests found? Not a tests directory! Not found...
239 [ -n "$status" ] || status=127
240 elif [ -f "$f" ] ; then
247 export CTDB_TEST_MODE="yes"
249 # Following 2 lines may be modified by installation script
250 export CTDB_TESTS_ARE_INSTALLED=false
251 export CTDB_TEST_DIR=$(dirname "$0")
253 if [ -z "$TEST_VAR_DIR" ] ; then
254 if $CTDB_TESTS_ARE_INSTALLED ; then
255 TEST_VAR_DIR=$(mktemp -d)
257 TEST_VAR_DIR="${CTDB_TEST_DIR}/var"
260 mkdir -p "$TEST_VAR_DIR"
263 TEST_VAR_DIR=$(cd "$TEST_VAR_DIR"; echo "$PWD")
264 echo "TEST_VAR_DIR=$TEST_VAR_DIR"
266 export TEST_SCRIPTS_DIR="${CTDB_TEST_DIR}/scripts"
279 # If no tests specified then run some defaults
280 if [ -z "$1" ] ; then
281 if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
284 set -- simple complex
290 if $TEST_CLEANUP ; then
291 echo "Removing TEST_VAR_DIR=$TEST_VAR_DIR"
292 rm -rf "$TEST_VAR_DIR"
294 echo "Not cleaning up TEST_VAR_DIR=$TEST_VAR_DIR"
300 if $TEST_CLEANUP ; then
301 if [ -n "$TEST_LOCAL_DAEMONS" -a "$f" = "simple" ] ; then
302 echo "***** shutting down daemons *****"
303 find_and_run_one_test simple/99_daemons_shutdown.sh "$tests_dir"
309 trap cleanup_handler SIGINT SIGTERM
314 if [ "$f" = "UNIT" ] ; then
315 for t in $unit_tests ; do
323 for f in "${tests[@]}" ; do
324 find_and_run_one_test "$f"
326 if [ $status -eq 127 ] ; then
327 # Find the the top-level tests directory
328 tests_dir=$(dirname $(cd $TEST_SCRIPTS_DIR; echo $PWD))
329 # Strip off current directory from beginning, if there, just
330 # to make paths more friendly.
331 tests_dir=${tests_dir#$PWD/}
332 find_and_run_one_test "$f" "$tests_dir"
335 if [ $status -eq 127 ] ; then
336 die "test \"$f\" is not recognised"
339 if $exit_on_fail && [ $status -ne 0 ] ; then
346 if $with_summary ; then
350 echo "${tests_passed}/${tests_total} tests passed"
359 if $no_header || $exit_on_fail ; then
361 elif [ $tests_failed -gt 0 ] ; then