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 when done by removing test state directory (see -V)
11 -D Show diff between failed/expected test output (some tests only)
12 -e Exit on the first test failure
13 -H No headers - for running single test with other wrapper
14 -I <count> Iterate tests <count> times, exiting on failure (implies -e, -N)
15 -l <count> Use <count> daemons for local daemon integration tests
16 -L Print daemon logs on test failure (only some tests)
17 -N Don't print summary of tests results after running all tests
18 -q Quiet - don't show tests being run (still displays summary)
19 -S <lib> Use socket wrapper library <lib> for local integration tests
20 -v Verbose - print test output for non-failures (only some tests)
21 -V <dir> Use <dir> as test state directory
22 -x Trace this script with the -x option
23 -X Trace certain scripts run by tests using -x (only some tests)
28 # Print a message and exit.
31 echo "$1" >&2 ; exit "${2:-1}"
34 ######################################################################
45 export CTDB_TEST_VERBOSE=false
46 export CTDB_TEST_COMMAND_TRACE=false
47 export CTDB_TEST_CAT_RESULTS_OPTS=""
48 export CTDB_TEST_DIFF_RESULTS=false
49 export CTDB_TEST_PRINT_LOGS_ON_ERROR=false
50 export CTDB_TEST_LOCAL_DAEMONS=3
51 export CTDB_TEST_SWRAP_SO_PATH=""
53 while getopts "AcCDehHI:l:LNqS:T:vV:xX?" opt ; do
55 A) CTDB_TEST_CAT_RESULTS_OPTS="-A" ;;
56 c) CTDB_TEST_LOCAL_DAEMONS="" ;;
58 D) CTDB_TEST_DIFF_RESULTS=true ;;
59 e) exit_on_fail=true ;;
61 I) max_iterations="$OPTARG" ; exit_on_fail=true ; with_summary=false ;;
62 l) CTDB_TEST_LOCAL_DAEMONS="$OPTARG" ;;
63 L) CTDB_TEST_PRINT_LOGS_ON_ERROR=true ;;
64 N) with_summary=false ;;
66 S) CTDB_TEST_SWRAP_SO_PATH="$OPTARG" ;;
67 T) test_time_limit="$OPTARG" ;;
68 v) CTDB_TEST_VERBOSE=true ;;
69 V) test_state_dir="$OPTARG" ;;
71 X) CTDB_TEST_COMMAND_TRACE=true ;;
77 case $(basename "$0") in
79 # Running on a cluster... same as -c
80 CTDB_TEST_LOCAL_DAEMONS=""
85 show_progress() { cat >/dev/null ; }
87 show_progress() { cat ; }
90 ######################################################################
96 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
97 echo "Running test $name ($(date '+%T'))"
98 echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
109 if [ "$status" -eq 0 ] ; then
112 statstr=" (status $status)"
115 echo "=========================================================================="
116 echo "TEST ${interp}: ${f}${statstr} (duration: ${duration}s)"
117 echo "=========================================================================="
124 $no_header || test_header "$f"
129 start_time=$(date '+%s')
131 if [ -x "$f" ] ; then
132 timeout "$test_time_limit" "$f" </dev/null | show_progress
135 echo "TEST IS NOT EXECUTABLE"
139 local duration=$(($(date +%s) - start_time))
141 tests_total=$((tests_total + 1))
147 tests_passed=$((tests_passed + 1))
151 tests_skipped=$((tests_skipped + 1))
155 tests_failed=$((tests_failed + 1))
159 tests_failed=$((tests_failed + 1))
163 tests_failed=$((tests_failed + 1))
167 $no_header || test_footer "$f" "$status" "$interp" "$duration"
169 if $with_summary ; then
171 if [ $status -eq 0 ] ; then
176 printf '%-10s %s\n' "$t" "$f" >>"$summary_file"
182 ######################################################################
189 if ! type mktemp >/dev/null 2>&1 ; then
190 # Not perfect, but it will do...
194 if [ "$1" = "-d" ] ; then
197 local t="${TMPDIR:-/tmp}/tmp.$$.$RANDOM"
216 CTDB_TEST_SUITE_DIR=$(dirname "$f")
217 export CTDB_TEST_SUITE_DIR
218 # This expands the most probable problem cases like "." and "..".
219 if [ "$(dirname "$CTDB_TEST_SUITE_DIR")" = "." ] ; then
220 CTDB_TEST_SUITE_DIR=$(cd "$CTDB_TEST_SUITE_DIR" && pwd)
223 # Set CTDB_TEST_TMP_DIR
225 # Determine the relative test suite subdirectory. The top-level
226 # test directory needs to be a prefix of the test suite directory,
227 # so make absolute versions of both.
228 local test_dir test_suite_dir reldir
229 test_dir=$(cd "$CTDB_TEST_DIR" && pwd)
230 test_suite_dir=$(cd "$CTDB_TEST_SUITE_DIR" && pwd)
231 reldir="${test_suite_dir#${test_dir}/}"
233 export CTDB_TEST_TMP_DIR="${test_state_dir}/${reldir}"
234 rm -rf "$CTDB_TEST_TMP_DIR"
235 mkdir -p "$CTDB_TEST_TMP_DIR"
247 */README|*/README.md)
252 if [ ! -e "$f" ] ; then
253 # Can't find it? Check relative to CTDB_TEST_DIR.
254 # Strip off current directory from beginning,
255 # if there, just to make paths more friendly.
256 f="${CTDB_TEST_DIR#${PWD}/}/${f}"
259 if [ -d "$f" ] ; then
260 local test_dir dir reldir subtests
262 test_dir=$(cd "$CTDB_TEST_DIR" && pwd)
263 dir=$(cd "$f" && pwd)
264 reldir="${dir#${test_dir}/}"
268 die "test \"$f\" is not recognised"
271 # This is a test suite
272 subtests=$(echo "${f%/}/"*".sh")
273 if [ "$subtests" = "${f%/}/*.sh" ] ; then
274 # Probably empty directory
275 die "test \"$f\" is not recognised"
278 CLUSTER|INTEGRATION|UNIT)
279 # A collection of test suites
280 subtests=$(echo "${f%/}/"*)
283 die "test \"$f\" is not recognised"
286 # Recurse - word-splitting wanted
287 # shellcheck disable=SC2086
289 elif [ -f "$f" ] ; then
293 die "test \"$f\" is not recognised"
296 if $exit_on_fail && [ $status -ne 0 ] ; then
302 export CTDB_TEST_MODE="yes"
304 # Following 2 lines may be modified by installation script
305 CTDB_TESTS_ARE_INSTALLED=false
306 CTDB_TEST_DIR=$(dirname "$0")
307 export CTDB_TESTS_ARE_INSTALLED CTDB_TEST_DIR
309 if [ -z "$test_state_dir" ] ; then
310 if $CTDB_TESTS_ARE_INSTALLED ; then
311 test_state_dir=$(mktemp -d)
313 test_state_dir="${CTDB_TEST_DIR}/var"
316 mkdir -p "$test_state_dir"
318 summary_file="${test_state_dir}/.summary"
321 export TEST_SCRIPTS_DIR="${CTDB_TEST_DIR}/scripts"
323 # If no tests specified then run some defaults
324 if [ -z "$1" ] ; then
325 if [ -n "$CTDB_TEST_LOCAL_DAEMONS" ] ; then
326 set -- UNIT INTEGRATION
328 set -- INTEGRATION CLUSTER
335 echo "Removing test state directory: ${test_state_dir}"
336 rm -rf "$test_state_dir"
338 echo "Not cleaning up test state directory: ${test_state_dir}"
342 trap "do_cleanup ; exit 130" SIGINT
343 trap "do_cleanup ; exit 143" SIGTERM
346 # Special case: -I 0 means iterate forever (until failure)
347 while [ "$max_iterations" -eq 0 ] || [ $iterations -lt "$max_iterations" ] ; do
348 iterations=$((iterations + 1))
350 if [ "$max_iterations" -ne 1 ] ; then
352 echo "##################################################"
353 echo "ITERATION ${iterations}"
354 echo "##################################################"
361 if [ $status -ne 0 ] ; then
366 if $with_summary ; then
367 if [ $status -eq 0 ] || ! $exit_on_fail ; then
372 tests_run=$((tests_total - tests_skipped))
373 printf '%d/%d tests passed' $tests_passed $tests_run
374 if [ $tests_skipped -gt 0 ] ; then
375 printf ' (%d skipped)' $tests_skipped
380 rm -f "$summary_file"
386 if $no_header || $exit_on_fail ; then
388 elif [ $tests_failed -gt 0 ] ; then