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
=3600
49 export TEST_SOCKET_WRAPPER_SO_PATH
=""
51 while getopts "AcCdDehHNqS:T:vV:xX?" opt
; do
53 A
) TEST_CAT_RESULTS_OPTS
="-A" ;;
54 c
) TEST_LOCAL_DAEMONS
="" ;;
55 C
) TEST_CLEANUP
=true
;;
56 d
) with_desc
=true
;; # 4th line of output is description
57 D
) TEST_DIFF_RESULTS
=true
;;
58 e
) exit_on_fail
=true
;;
60 N
) with_summary
=false
;;
62 S
) TEST_SOCKET_WRAPPER_SO_PATH
="$OPTARG" ;;
63 T
) TEST_TIMEOUT
="$OPTARG" ;;
64 v
) TEST_VERBOSE
=true
;;
65 V
) TEST_VAR_DIR
="$OPTARG" ;;
67 X
) TEST_COMMAND_TRACE
=true
;;
73 case $
(basename "$0") in
75 # Running on a cluster... same as -c
81 show_progress
() { cat >/dev
/null
; }
83 show_progress
() { cat ; }
86 ######################################################################
92 teststarttime
=$
(date '+%s')
95 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
96 echo "Running test $name ($(date '+%T'))"
97 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
102 local name
="$1" ; shift
103 local status
="$1" ; shift
104 # "$@" is command-line
106 local interp
="SKIPPED"
107 local statstr
=" (reason $*)"
108 if [ -n "$status" ] ; then
109 if [ $status -eq 0 ] ; then
113 elif [ $status -eq 124 ] ; then
115 statstr
=" (status $status)"
118 statstr
=" (status $status)"
122 testduration
=$
(($
(date +%s
)-$teststarttime))
124 echo "=========================================================================="
125 echo "TEST ${interp}: ${name}${statstr} (duration: ${testduration}s)"
126 echo "=========================================================================="
132 local name
="$1" ; shift
134 [ -n "$1" ] ||
set -- "$name"
136 $no_header || ctdb_test_begin
"$name"
139 if [ -x "$1" ] ; then
140 timeout
$TEST_TIMEOUT "$@" || status
=$?
142 echo "TEST IS NOT EXECUTABLE"
146 $no_header || ctdb_test_end
"$name" "$status" "$*"
151 ######################################################################
158 if ! which mktemp
>/dev
/null
2>&1 ; then
159 # Not perfect, but it will do...
163 if [ "$1" = "-d" ] ; then
166 local t
="${TMPDIR:-/tmp}/tmp.$$.$RANDOM"
179 tf
=$
(mktemp
) || die
"mktemp failed for tf - is TMPDIR missing?"
180 sf
=$
(mktemp
) || die
"mktemp failed for sf - is TMPDIR missing?"
188 tests_total
=$
(($tests_total + 1))
190 ctdb_test_run
"$f" |
tee "$tf" | show_progress
192 if [ $status -eq 0 ] ; then
193 tests_passed
=$
(($tests_passed + 1))
195 tests_failed
=$
(($tests_failed + 1))
197 if $with_summary ; then
199 if [ $status -eq 0 ] ; then
205 desc
=$
(tail -n +4 $tf |
head -n 1)
212 find_and_run_one_test
()
217 local f
="${dir}${dir:+/}${t}"
219 if [ -d "$f" ] ; then
221 for i
in $
(ls "${f%/}/"*".sh" 2>/dev
/null
) ; do
223 if $exit_on_fail && [ $status -ne 0 ] ; then
227 # No tests found? Not a tests directory! Not found...
228 [ -n "$status" ] || status
=127
229 elif [ -f "$f" ] ; then
236 export CTDB_TEST_MODE
="yes"
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"
268 # If no tests specified then run some defaults
269 if [ -z "$1" ] ; then
270 if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
273 set -- simple complex
279 if $TEST_CLEANUP ; then
280 echo "Removing TEST_VAR_DIR=$TEST_VAR_DIR"
281 rm -rf "$TEST_VAR_DIR"
283 echo "Not cleaning up TEST_VAR_DIR=$TEST_VAR_DIR"
289 if $TEST_CLEANUP ; then
290 if [ -n "$TEST_LOCAL_DAEMONS" -a "$f" = "simple" ] ; then
291 echo "***** shutting down daemons *****"
292 find_and_run_one_test simple
/99_daemons_shutdown.sh
"$tests_dir"
298 trap cleanup_handler SIGINT SIGTERM
303 if [ "$f" = "UNIT" ] ; then
304 for t
in $unit_tests ; do
312 for f
in "${tests[@]}" ; do
313 find_and_run_one_test
"$f"
315 if [ $status -eq 127 ] ; then
316 # Find the the top-level tests directory
317 tests_dir
=$
(dirname $
(cd $TEST_SCRIPTS_DIR; echo $PWD))
318 # Strip off current directory from beginning, if there, just
319 # to make paths more friendly.
320 tests_dir
=${tests_dir#$PWD/}
321 find_and_run_one_test
"$f" "$tests_dir"
324 if [ $status -eq 127 ] ; then
325 die
"test \"$f\" is not recognised"
328 if $exit_on_fail && [ $status -ne 0 ] ; then
335 if $with_summary ; then
339 echo "${tests_passed}/${tests_total} tests passed"
348 if $no_header ||
$exit_on_fail ; then
350 elif [ $tests_failed -gt 0 ] ; then