CVE-2018-1057: s4:dsdb/acl: add check for DSDB_CONTROL_PASSWORD_HASH_VALUES_OID control
[Samba.git] / ctdb / tests / run_tests.sh
bloba7ca44e863eeb4c3e59708d0c0a5b1f5613c7489
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 <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)
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
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 temp=$(getopt -n "$prog" -o "AcCdDehHNqS:T:vV:xX" -l help -- "$@")
53 [ $? != 0 ] && usage
55 eval set -- "$temp"
57 while true ; do
58 case "$1" in
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 ;;
72 -x) set -x; shift ;;
73 -X) TEST_COMMAND_TRACE=true ; shift ;;
74 --) shift ; break ;;
75 *) usage ;;
76 esac
77 done
79 case $(basename "$0") in
80 *run_cluster_tests*)
81 # Running on a cluster... same as -c
82 TEST_LOCAL_DAEMONS=""
84 esac
86 if $quiet ; then
87 show_progress() { cat >/dev/null ; }
88 else
89 show_progress() { cat ; }
92 ######################################################################
94 ctdb_test_begin ()
96 local name="$1"
98 teststarttime=$(date '+%s')
99 testduration=0
101 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
102 echo "Running test $name ($(date '+%T'))"
103 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
106 ctdb_test_end ()
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
116 interp="PASSED"
117 statstr=""
118 echo "ALL OK: $*"
119 elif [ $status -eq 124 ] ; then
120 interp="TIMEOUT"
121 statstr=" (status $status)"
122 else
123 interp="FAILED"
124 statstr=" (status $status)"
128 testduration=$(($(date +%s)-$teststarttime))
130 echo "=========================================================================="
131 echo "TEST ${interp}: ${name}${statstr} (duration: ${testduration}s)"
132 echo "=========================================================================="
136 ctdb_test_run ()
138 local name="$1" ; shift
140 [ -n "$1" ] || set -- "$name"
142 $no_header || ctdb_test_begin "$name"
144 local status=0
145 timeout $TEST_TIMEOUT "$@" || status=$?
147 $no_header || ctdb_test_end "$name" "$status" "$*"
149 return $status
152 ######################################################################
154 tests_total=0
155 tests_passed=0
156 tests_failed=0
157 summary=""
159 if ! which mktemp >/dev/null 2>&1 ; then
160 # Not perfect, but it will do...
161 mktemp ()
163 local dir=false
164 if [ "$1" = "-d" ] ; then
165 dir=true
167 local t="${TMPDIR:-/tmp}/tmp.$$.$RANDOM"
169 umask 077
170 if $dir ; then
171 mkdir "$t"
172 else
173 >"$t"
176 echo "$t"
180 tf=$(mktemp) || die "mktemp failed for tf - is TMPDIR missing?"
181 sf=$(mktemp) || die "mktemp failed for sf - is TMPDIR missing?"
183 set -o pipefail
185 run_one_test ()
187 local f="$1"
189 [ -x "$f" ] || die "test \"$f\" is not executable"
190 tests_total=$(($tests_total + 1))
192 ctdb_test_run "$f" | tee "$tf" | show_progress
193 status=$?
194 if [ $status -eq 0 ] ; then
195 tests_passed=$(($tests_passed + 1))
196 else
197 tests_failed=$(($tests_failed + 1))
199 if $with_summary ; then
200 local t
201 if [ $status -eq 0 ] ; then
202 t=" PASSED "
203 else
204 t="*FAILED*"
206 if $with_desc ; then
207 desc=$(tail -n +4 $tf | head -n 1)
208 f="$desc"
210 echo "$t $f" >>"$sf"
214 find_and_run_one_test ()
216 local t="$1"
217 local dir="$2"
219 local f="${dir}${dir:+/}${t}"
221 if [ -d "$f" ] ; then
222 local i
223 for i in $(ls "${f%/}/"*".sh" 2>/dev/null) ; do
224 run_one_test "$i"
225 if $exit_on_fail && [ $status -ne 0 ] ; then
226 break
228 done
229 # No tests found? Not a tests directory! Not found...
230 [ -n "$status" ] || status=127
231 elif [ -f "$f" ] ; then
232 run_one_test "$f"
233 else
234 status=127
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)
245 else
246 TEST_VAR_DIR="${CTDB_TEST_DIR}/var"
249 mkdir -p "$TEST_VAR_DIR"
251 # Must be absolute
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 unit_tests="
258 cunit
259 eventd
260 eventscripts
261 onnode
262 shellcheck
263 takeover
264 takeover_helper
265 tool
268 # If no tests specified then run some defaults
269 if [ -z "$1" ] ; then
270 if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
271 set -- UNIT simple
272 else
273 set -- simple complex
277 do_cleanup ()
279 if $TEST_CLEANUP ; then
280 echo "Removing TEST_VAR_DIR=$TEST_VAR_DIR"
281 rm -rf "$TEST_VAR_DIR"
282 else
283 echo "Not cleaning up TEST_VAR_DIR=$TEST_VAR_DIR"
287 cleanup_handler ()
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"
295 do_cleanup
298 trap cleanup_handler SIGINT SIGTERM
300 declare -a tests
302 for f ; do
303 if [ "$f" = "UNIT" ] ; then
304 for t in $unit_tests ; do
305 tests[i++]="$t"
306 done
307 else
308 tests[i++]="$f"
310 done
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
329 break
331 done
333 rm -f "$tf"
335 if $with_summary ; then
336 echo
337 cat "$sf"
338 echo
339 echo "${tests_passed}/${tests_total} tests passed"
342 rm -f "$sf"
344 echo
346 do_cleanup
348 if $no_header || $exit_on_fail ; then
349 exit $status
350 elif [ $tests_failed -gt 0 ] ; then
351 exit 1
352 else
353 exit 0