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 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 -I <count> Iterate tests <count> times, exiting on failure (implies -e, -N)
16 -N Don't print summary of tests results after running all tests
17 -q Quiet - don't show tests being run (still displays summary)
18 -S <lib> Use socket wrapper library <lib> for local integration tests
19 -v Verbose - print test output for non-failures (only some tests)
20 -V <dir> Use <dir> as TEST_VAR_DIR
21 -x Trace this script with the -x option
22 -X Trace certain scripts run by tests using -x (only some tests)
27 # Print a message and exit.
30 echo "$1" >&2 ; exit "${2:-1}"
33 ######################################################################
42 export TEST_VERBOSE=false
43 export TEST_COMMAND_TRACE=false
44 export TEST_CAT_RESULTS_OPTS=""
45 export TEST_DIFF_RESULTS=false
46 export TEST_LOCAL_DAEMONS
47 [ -n "$TEST_LOCAL_DAEMONS" ] || TEST_LOCAL_DAEMONS=3
48 export TEST_VAR_DIR=""
49 export TEST_CLEANUP=false
50 export TEST_TIMEOUT=3600
51 export TEST_SOCKET_WRAPPER_SO_PATH=""
53 while getopts "AcCdDehHI:NqS:T:vV:xX?" opt ; do
55 A) TEST_CAT_RESULTS_OPTS="-A" ;;
56 c) TEST_LOCAL_DAEMONS="" ;;
57 C) TEST_CLEANUP=true ;;
58 d) with_desc=true ;; # 4th line of output is description
59 D) TEST_DIFF_RESULTS=true ;;
60 e) exit_on_fail=true ;;
62 I) max_iterations="$OPTARG" ; exit_on_fail=true ; with_summary=false ;;
63 N) with_summary=false ;;
65 S) TEST_SOCKET_WRAPPER_SO_PATH="$OPTARG" ;;
66 T) TEST_TIMEOUT="$OPTARG" ;;
67 v) TEST_VERBOSE=true ;;
68 V) TEST_VAR_DIR="$OPTARG" ;;
70 X) TEST_COMMAND_TRACE=true ;;
76 case $(basename "$0") in
78 # Running on a cluster... same as -c
84 show_progress() { cat >/dev/null ; }
86 show_progress() { cat ; }
89 ######################################################################
95 teststarttime=$(date '+%s')
98 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
99 echo "Running test $name ($(date '+%T'))"
100 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
105 local name="$1" ; shift
106 local status="$1" ; shift
107 # "$@" is command-line
109 local interp="SKIPPED"
110 local statstr=" (reason $*)"
111 if [ -n "$status" ] ; then
112 if [ "$status" -eq 0 ] ; then
116 elif [ "$status" -eq 124 ] ; then
118 statstr=" (status $status)"
121 statstr=" (status $status)"
125 testduration=$(($(date +%s) - teststarttime))
127 echo "=========================================================================="
128 echo "TEST ${interp}: ${name}${statstr} (duration: ${testduration}s)"
129 echo "=========================================================================="
135 local name="$1" ; shift
137 [ -n "$1" ] || set -- "$name"
139 $no_header || ctdb_test_begin "$name"
142 if [ -x "$1" ] ; then
143 timeout "$TEST_TIMEOUT" "$@" || status=$?
145 echo "TEST IS NOT EXECUTABLE"
149 $no_header || ctdb_test_end "$name" "$status" "$*"
154 ######################################################################
160 if ! type mktemp >/dev/null 2>&1 ; then
161 # Not perfect, but it will do...
165 if [ "$1" = "-d" ] ; then
168 local t="${TMPDIR:-/tmp}/tmp.$$.$RANDOM"
181 tf=$(mktemp) || die "mktemp failed for tf - is TMPDIR missing?"
182 sf=$(mktemp) || die "mktemp failed for sf - is TMPDIR missing?"
190 tests_total=$((tests_total + 1))
192 ctdb_test_run "$f" | tee "$tf" | show_progress
194 if [ $status -eq 0 ] ; then
195 tests_passed=$((tests_passed + 1))
197 tests_failed=$((tests_failed + 1))
199 if $with_summary ; then
201 if [ $status -eq 0 ] ; then
207 desc=$(tail -n +4 "$tf" | head -n 1)
214 find_and_run_one_test ()
219 local f="${dir}${dir:+/}${t}"
221 if [ -d "$f" ] ; then
223 for i in "${f%/}/"*".sh" ; do
224 # Only happens if test removed (unlikely) or empty directory
225 if [ ! -f "$i" ] ; then
229 if $exit_on_fail && [ $status -ne 0 ] ; then
233 # No tests found? Not a tests directory! Not found...
234 [ -n "$status" ] || status=127
235 elif [ -f "$f" ] ; then
246 for f in "${tests[@]}" ; do
247 find_and_run_one_test "$f"
249 if [ $status -eq 127 ] ; then
250 # Find the the top-level tests directory
251 d=$(cd "$TEST_SCRIPTS_DIR" && echo "$PWD")
252 if [ -z "$d" ] ; then
253 local t="$TEST_SCRIPTS_DIR"
254 die "Unable to find TEST_SCRIPTS_DIR=\"${t}\""
256 tests_dir=$(dirname "$d")
257 # Strip off current directory from beginning,
258 # if there, just to make paths more friendly.
259 tests_dir="${tests_dir#${PWD}/}"
260 find_and_run_one_test "$f" "$tests_dir"
263 if [ $status -eq 127 ] ; then
264 die "test \"$f\" is not recognised"
267 if $exit_on_fail && [ $status -ne 0 ] ; then
273 export CTDB_TEST_MODE="yes"
275 # Following 2 lines may be modified by installation script
276 CTDB_TESTS_ARE_INSTALLED=false
277 CTDB_TEST_DIR=$(dirname "$0")
278 export CTDB_TESTS_ARE_INSTALLED CTDB_TEST_DIR
280 if [ -z "$TEST_VAR_DIR" ] ; then
281 if $CTDB_TESTS_ARE_INSTALLED ; then
282 TEST_VAR_DIR=$(mktemp -d)
284 TEST_VAR_DIR="${CTDB_TEST_DIR}/var"
287 mkdir -p "$TEST_VAR_DIR"
289 export TEST_SCRIPTS_DIR="${CTDB_TEST_DIR}/scripts"
302 # If no tests specified then run some defaults
303 if [ -z "$1" ] ; then
304 if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
307 set -- simple complex
313 if $TEST_CLEANUP ; then
314 echo "Removing TEST_VAR_DIR=$TEST_VAR_DIR"
315 rm -rf "$TEST_VAR_DIR"
317 echo "Not cleaning up TEST_VAR_DIR=$TEST_VAR_DIR"
321 trap "do_cleanup ; exit 130" SIGINT
322 trap "do_cleanup ; exit 143" SIGTERM
327 if [ "$f" = "UNIT" ] ; then
328 for t in $unit_tests ; do
337 # Special case: -I 0 means iterate forever (until failure)
338 while [ "$max_iterations" -eq 0 ] || [ $iterations -lt "$max_iterations" ] ; do
339 iterations=$((iterations + 1))
341 if [ "$max_iterations" -ne 1 ] ; then
343 echo "##################################################"
344 echo "ITERATION ${iterations}"
345 echo "##################################################"
349 run_tests "${tests[@]}"
352 if [ $status -ne 0 ] ; then
359 if $with_summary ; then
360 if [ $status -eq 0 ] || ! $exit_on_fail ; then
364 echo "${tests_passed}/${tests_total} tests passed"
374 if $no_header || $exit_on_fail ; then
376 elif [ $tests_failed -gt 0 ] ; then