param: Rename variable used for lp_client_plaintext_auth bClientPlaintextAuth
[Samba.git] / ctdb / tests / run_tests.sh
blob2ff11ff35aa4ca5719fc3434777d533b2e037529
1 #!/bin/bash
3 usage() {
4 cat <<EOF
5 Usage: $0 [OPTIONS] [TESTS]
7 Options:
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)
22 EOF
23 exit 1
26 # Print a message and exit.
27 die ()
29 echo "$1" >&2 ; exit ${2:-1}
32 ######################################################################
34 with_summary=true
35 with_desc=false
36 quiet=false
37 exit_on_fail=false
38 no_header=false
39 socket_wrapper=false
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 -- "$@")
52 [ $? != 0 ] && usage
54 eval set -- "$temp"
56 while true ; do
57 case "$1" in
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 ;;
70 -x) set -x; shift ;;
71 -X) TEST_COMMAND_TRACE=true ; shift ;;
72 --) shift ; break ;;
73 *) usage ;;
74 esac
75 done
77 case $(basename "$0") in
78 *run_cluster_tests*)
79 # Running on a cluster... same as -c
80 TEST_LOCAL_DAEMONS=""
82 esac
84 if $quiet ; then
85 show_progress() { cat >/dev/null ; }
86 else
87 show_progress() { cat ; }
90 ######################################################################
92 ctdb_test_begin ()
94 local name="$1"
96 teststarttime=$(date '+%s')
97 testduration=0
99 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
100 echo "Running test $name ($(date '+%T'))"
101 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
104 ctdb_test_end ()
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
114 interp="PASSED"
115 statstr=""
116 echo "ALL OK: $*"
117 else
118 interp="FAILED"
119 statstr=" (status $status)"
123 testduration=$(($(date +%s)-$teststarttime))
125 echo "=========================================================================="
126 echo "TEST ${interp}: ${name}${statstr} (duration: ${testduration}s)"
127 echo "=========================================================================="
131 ctdb_test_run ()
133 local name="$1" ; shift
135 [ -n "$1" ] || set -- "$name"
137 $no_header || ctdb_test_begin "$name"
139 local status=0
140 "$@" || status=$?
142 $no_header || ctdb_test_end "$name" "$status" "$*"
144 return $status
147 ######################################################################
149 tests_total=0
150 tests_passed=0
151 tests_failed=0
152 summary=""
154 if ! which mktemp >/dev/null 2>&1 ; then
155 # Not perfect, but it will do...
156 mktemp ()
158 _dir=false
159 if [ "$1" = "-d" ] ; then
160 _dir=true
162 _t="${TMPDIR:-/tmp}/tmp.$$.$RANDOM"
164 umask 077
165 if $_dir ; then
166 mkdir "$_t"
167 else
168 >"$_t"
171 echo "$_t"
175 tf=$(mktemp)
176 sf=$(mktemp)
178 set -o pipefail
180 run_one_test ()
182 _f="$1"
184 [ -x "$_f" ] || die "test \"$_f\" is not executable"
185 tests_total=$(($tests_total + 1))
187 ctdb_test_run "$_f" | tee "$tf" | show_progress
188 status=$?
189 if [ $status -eq 0 ] ; then
190 tests_passed=$(($tests_passed + 1))
191 else
192 tests_failed=$(($tests_failed + 1))
194 if $with_summary ; then
195 if [ $status -eq 0 ] ; then
196 _t=" PASSED "
197 else
198 _t="*FAILED*"
200 if $with_desc ; then
201 desc=$(tail -n +4 $tf | head -n 1)
202 _f="$desc"
204 echo "$_t $_f" >>"$sf"
208 find_and_run_one_test ()
210 _t="$1"
211 _dir="$2"
213 _f="${_dir}${_dir:+/}${_t}"
215 if [ -d "$_f" ] ; then
216 for _i in $(ls "${_f%/}/"*".sh" 2>/dev/null) ; do
217 run_one_test "$_i"
218 if $exit_on_fail && [ $status -ne 0 ] ; then
219 break
221 done
222 # No tests found? Not a tests directory! Not found...
223 [ -n "$status" ] || status=127
224 elif [ -f "$_f" ] ; then
225 run_one_test "$_f"
226 else
227 status=127
231 # Following 2 lines may be modified by installation script
232 export CTDB_TESTS_ARE_INSTALLED=false
233 test_dir=$(dirname "$0")
235 if [ -z "$TEST_VAR_DIR" ] ; then
236 if $CTDB_TESTS_ARE_INSTALLED ; then
237 TEST_VAR_DIR=$(mktemp -d)
238 else
239 TEST_VAR_DIR="${test_dir}/var"
242 mkdir -p "$TEST_VAR_DIR"
244 # Must be absolute
245 TEST_VAR_DIR=$(cd "$TEST_VAR_DIR"; echo "$PWD")
246 echo "TEST_VAR_DIR=$TEST_VAR_DIR"
248 if $socket_wrapper ; then
249 export SOCKET_WRAPPER_DIR="${TEST_VAR_DIR}/sw"
250 mkdir -p "$SOCKET_WRAPPER_DIR"
253 export TEST_SCRIPTS_DIR="${test_dir}/scripts"
255 # If no tests specified then run some defaults
256 if [ -z "$1" ] ; then
257 if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
258 set -- onnode takeover tool eventscripts simple
259 else
260 set -- simple complex
264 for f ; do
265 find_and_run_one_test "$f"
267 if [ $status -eq 127 ] ; then
268 # Find the the top-level tests directory
269 tests_dir=$(dirname $(cd $TEST_SCRIPTS_DIR; echo $PWD))
270 # Strip off current directory from beginning, if there, just
271 # to make paths more friendly.
272 tests_dir=${tests_dir#$PWD/}
273 find_and_run_one_test "$f" "$tests_dir"
276 if [ $status -eq 127 ] ; then
277 die "test \"$f\" is not recognised"
280 if $exit_on_fail && [ $status -ne 0 ] ; then
281 break
283 done
285 rm -f "$tf"
287 if $with_summary ; then
288 echo
289 cat "$sf"
290 echo
291 echo "${tests_passed}/${tests_total} tests passed"
294 rm -f "$sf"
296 echo
298 if $TEST_CLEANUP ; then
299 echo "Removing TEST_VAR_DIR=$TEST_VAR_DIR"
300 rm -rf "$TEST_VAR_DIR"
301 else
302 echo "Not cleaning up TEST_VAR_DIR=$TEST_VAR_DIR"
305 if $no_header || $exit_on_fail ; then
306 exit $status
307 elif [ $tests_failed -gt 0 ] ; then
308 exit 1
309 else
310 exit 0