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 ######################################################################
40 export TEST_VERBOSE=false
41 export TEST_COMMAND_TRACE=false
42 export TEST_CAT_RESULTS_OPTS=""
43 export TEST_DIFF_RESULTS=false
44 export TEST_LOCAL_DAEMONS
45 [ -n "$TEST_LOCAL_DAEMONS" ] || TEST_LOCAL_DAEMONS=3
46 export TEST_VAR_DIR=""
47 export TEST_CLEANUP=false
48 export TEST_TIMEOUT=600
49 export TEST_SOCKET_WRAPPER_SO_PATH=""
51 temp=$(getopt -n "$prog" -o "AcCdDehHNqS:T:vV:xX" -l help -- "$@")
59 -A) TEST_CAT_RESULTS_OPTS="-A" ; shift ;;
60 -c) TEST_LOCAL_DAEMONS="" ; shift ;;
61 -C) TEST_CLEANUP=true ; shift ;;
62 -d) with_desc=true ; shift ;; # 4th line of output is description
63 -D) TEST_DIFF_RESULTS=true ; shift ;;
64 -e) exit_on_fail=true ; shift ;;
65 -H) no_header=true ; shift ;;
66 -N) with_summary=false ; shift ;;
67 -q) quiet=true ; shift ;;
68 -S) TEST_SOCKET_WRAPPER_SO_PATH="$2" ; shift 2 ;;
69 -T) TEST_TIMEOUT="$2" ; shift 2 ;;
70 -v) TEST_VERBOSE=true ; shift ;;
71 -V) TEST_VAR_DIR="$2" ; shift 2 ;;
73 -X) TEST_COMMAND_TRACE=true ; shift ;;
79 case $(basename "$0") in
81 # Running on a cluster... same as -c
87 show_progress() { cat >/dev/null ; }
89 show_progress() { cat ; }
92 ######################################################################
98 teststarttime=$(date '+%s')
101 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
102 echo "Running test $name ($(date '+%T'))"
103 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
108 local name="$1" ; shift
109 local status="$1" ; shift
110 # "$@" is command-line
112 local interp="SKIPPED"
113 local statstr=" (reason $*)"
114 if [ -n "$status" ] ; then
115 if [ $status -eq 0 ] ; then
119 elif [ $status -eq 124 ] ; then
121 statstr=" (status $status)"
124 statstr=" (status $status)"
128 testduration=$(($(date +%s)-$teststarttime))
130 echo "=========================================================================="
131 echo "TEST ${interp}: ${name}${statstr} (duration: ${testduration}s)"
132 echo "=========================================================================="
138 local name="$1" ; shift
140 [ -n "$1" ] || set -- "$name"
142 $no_header || ctdb_test_begin "$name"
145 timeout $TEST_TIMEOUT "$@" || status=$?
147 $no_header || ctdb_test_end "$name" "$status" "$*"
152 ######################################################################
159 if ! which mktemp >/dev/null 2>&1 ; then
160 # Not perfect, but it will do...
164 if [ "$1" = "-d" ] ; then
167 local t="${TMPDIR:-/tmp}/tmp.$$.$RANDOM"
180 tf=$(mktemp) || die "mktemp failed for tf - is TMPDIR missing?"
181 sf=$(mktemp) || die "mktemp failed for sf - is TMPDIR missing?"
189 [ -x "$f" ] || die "test \"$f\" is not executable"
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 $(ls "${f%/}/"*".sh" 2>/dev/null) ; do
225 if $exit_on_fail && [ $status -ne 0 ] ; then
229 # No tests found? Not a tests directory! Not found...
230 [ -n "$status" ] || status=127
231 elif [ -f "$f" ] ; then
238 # Following 2 lines may be modified by installation script
239 export CTDB_TESTS_ARE_INSTALLED=false
240 export CTDB_TEST_DIR=$(dirname "$0")
242 if [ -z "$TEST_VAR_DIR" ] ; then
243 if $CTDB_TESTS_ARE_INSTALLED ; then
244 TEST_VAR_DIR=$(mktemp -d)
246 TEST_VAR_DIR="${CTDB_TEST_DIR}/var"
249 mkdir -p "$TEST_VAR_DIR"
252 TEST_VAR_DIR=$(cd "$TEST_VAR_DIR"; echo "$PWD")
253 echo "TEST_VAR_DIR=$TEST_VAR_DIR"
255 export TEST_SCRIPTS_DIR="${CTDB_TEST_DIR}/scripts"
257 # If no tests specified then run some defaults
258 if [ -z "$1" ] ; then
259 if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
260 set -- onnode takeover takeover_helper tool eventscripts \
261 cunit eventd shellcheck simple
263 set -- simple complex
269 if $TEST_CLEANUP ; then
270 echo "Removing TEST_VAR_DIR=$TEST_VAR_DIR"
271 rm -rf "$TEST_VAR_DIR"
273 echo "Not cleaning up TEST_VAR_DIR=$TEST_VAR_DIR"
279 if $TEST_CLEANUP ; then
280 if [ -n "$TEST_LOCAL_DAEMONS" -a "$f" = "simple" ] ; then
281 echo "***** shutting down daemons *****"
282 find_and_run_one_test simple/99_daemons_shutdown.sh "$tests_dir"
288 trap cleanup_handler SIGINT SIGTERM
291 find_and_run_one_test "$f"
293 if [ $status -eq 127 ] ; then
294 # Find the the top-level tests directory
295 tests_dir=$(dirname $(cd $TEST_SCRIPTS_DIR; echo $PWD))
296 # Strip off current directory from beginning, if there, just
297 # to make paths more friendly.
298 tests_dir=${tests_dir#$PWD/}
299 find_and_run_one_test "$f" "$tests_dir"
302 if [ $status -eq 127 ] ; then
303 die "test \"$f\" is not recognised"
306 if $exit_on_fail && [ $status -ne 0 ] ; then
313 if $with_summary ; then
317 echo "${tests_passed}/${tests_total} tests passed"
326 if $no_header || $exit_on_fail ; then
328 elif [ $tests_failed -gt 0 ] ; then