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 Enable socket wrapper
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 ######################################################################
41 export TEST_VERBOSE
=false
42 export TEST_COMMAND_TRACE
=false
43 export TEST_CAT_RESULTS_OPTS
=""
44 export TEST_DIFF_RESULTS
=false
45 export TEST_LOCAL_DAEMONS
46 [ -n "$TEST_LOCAL_DAEMONS" ] || TEST_LOCAL_DAEMONS
=3
47 export TEST_VAR_DIR
=""
48 export TEST_CLEANUP
=false
50 temp
=$
(getopt
-n "$prog" -o "AcCdDehHNqSvV:xX" -l help -- "$@")
58 -A) TEST_CAT_RESULTS_OPTS
="-A" ; shift ;;
59 -c) TEST_LOCAL_DAEMONS
="" ; shift ;;
60 -C) TEST_CLEANUP
=true
; shift ;;
61 -d) with_desc
=true
; shift ;; # 4th line of output is description
62 -D) TEST_DIFF_RESULTS
=true
; shift ;;
63 -e) exit_on_fail
=true
; shift ;;
64 -H) no_header
=true
; shift ;;
65 -N) with_summary
=false
; shift ;;
66 -q) quiet
=true
; shift ;;
67 -S) socket_wrapper
=true
; shift ;;
68 -v) TEST_VERBOSE
=true
; shift ;;
69 -V) TEST_VAR_DIR
="$2" ; shift 2 ;;
71 -X) TEST_COMMAND_TRACE
=true
; shift ;;
77 case $
(basename "$0") in
79 # Running on a cluster... same as -c
85 show_progress
() { cat >/dev
/null
; }
87 show_progress
() { cat ; }
90 ######################################################################
96 teststarttime
=$
(date '+%s')
99 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
100 echo "Running test $name ($(date '+%T'))"
101 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
106 local name
="$1" ; shift
107 local status
="$1" ; shift
108 # "$@" is command-line
110 local interp
="SKIPPED"
111 local statstr
=" (reason $*)"
112 if [ -n "$status" ] ; then
113 if [ $status -eq 0 ] ; then
119 statstr
=" (status $status)"
123 testduration
=$
(($
(date +%s
)-$teststarttime))
125 echo "=========================================================================="
126 echo "TEST ${interp}: ${name}${statstr} (duration: ${testduration}s)"
127 echo "=========================================================================="
133 local name
="$1" ; shift
135 [ -n "$1" ] ||
set -- "$name"
137 $no_header || ctdb_test_begin
"$name"
142 $no_header || ctdb_test_end
"$name" "$status" "$*"
147 ######################################################################
154 if ! which mktemp
>/dev
/null
2>&1 ; then
155 # Not perfect, but it will do...
159 if [ "$1" = "-d" ] ; then
162 local t
="${TMPDIR:-/tmp}/tmp.$$.$RANDOM"
175 tf
=$
(mktemp
) || die
"mktemp failed for tf - is TMPDIR missing?"
176 sf
=$
(mktemp
) || die
"mktemp failed for sf - is TMPDIR missing?"
184 [ -x "$f" ] || die
"test \"$f\" is not executable"
185 tests_total
=$
(($tests_total + 1))
187 ctdb_test_run
"$f" |
tee "$tf" | show_progress
189 if [ $status -eq 0 ] ; then
190 tests_passed
=$
(($tests_passed + 1))
192 tests_failed
=$
(($tests_failed + 1))
194 if $with_summary ; then
196 if [ $status -eq 0 ] ; then
202 desc
=$
(tail -n +4 $tf |
head -n 1)
209 find_and_run_one_test
()
214 local f
="${dir}${dir:+/}${t}"
216 if [ -d "$f" ] ; then
218 for i
in $
(ls "${f%/}/"*".sh" 2>/dev
/null
) ; do
220 if $exit_on_fail && [ $status -ne 0 ] ; then
224 # No tests found? Not a tests directory! Not found...
225 [ -n "$status" ] || status
=127
226 elif [ -f "$f" ] ; then
233 # Following 2 lines may be modified by installation script
234 export CTDB_TESTS_ARE_INSTALLED
=false
235 test_dir
=$
(dirname "$0")
237 if [ -z "$TEST_VAR_DIR" ] ; then
238 if $CTDB_TESTS_ARE_INSTALLED ; then
239 TEST_VAR_DIR
=$
(mktemp
-d)
241 TEST_VAR_DIR
="${test_dir}/var"
244 mkdir
-p "$TEST_VAR_DIR"
247 TEST_VAR_DIR
=$
(cd "$TEST_VAR_DIR"; echo "$PWD")
248 echo "TEST_VAR_DIR=$TEST_VAR_DIR"
250 if $socket_wrapper ; then
251 export SOCKET_WRAPPER_DIR
="${TEST_VAR_DIR}/sw"
252 mkdir
-p "$SOCKET_WRAPPER_DIR"
255 export TEST_SCRIPTS_DIR
="${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