1 # Hey Emacs, this is a -*- shell-script -*- !!! :-)
3 # Common variables and functions for all CTDB tests.
5 # Print a message and exit.
8 echo "$1" >&2 ; exit ${2:-1}
11 # This expands the most probable problem cases like "." and "..".
12 TEST_SUBDIR=$(dirname "$0")
13 if [ $(dirname "$TEST_SUBDIR") = "." ] ; then
14 TEST_SUBDIR=$(cd "$TEST_SUBDIR" ; pwd)
17 # If we are running from within the source tree then, depending on the
18 # tests that we're running, we may need to add the top level bin/ and
19 # tools/ subdirectories to $PATH. In this case, sanity check that
20 # run_tests.sh is in the expected place. If the tests are installed
21 # then sanity check that TEST_BIN_DIR is set.
22 if $CTDB_TESTS_ARE_INSTALLED ; then
23 if [ -z "$TEST_BIN_DIR" ] ; then
24 die "CTDB_TESTS_ARE_INSTALLED but TEST_BIN_DIR not set"
27 _test_bin_dir="$TEST_BIN_DIR"
29 if [ ! -f "${CTDB_TEST_DIR}/run_tests.sh" ] ; then
30 die "Tests not installed but can't find run_tests.sh"
33 ctdb_dir=$(dirname "$CTDB_TEST_DIR")
35 _tools_dir="${ctdb_dir}/tools"
36 if [ -d "$_tools_dir" ] ; then
37 PATH="${_tools_dir}:$PATH"
40 _test_bin_dir="${ctdb_dir}/bin"
43 case "$_test_bin_dir" in
45 *) _test_bin_dir="${PWD}/${_test_bin_dir}" ;;
47 if [ -d "$_test_bin_dir" ] ; then
48 PATH="${_test_bin_dir}:$PATH"
51 # Wait until either timeout expires or command succeeds. The command
52 # will be tried once per second, unless timeout has format T/I, where
53 # I is the recheck interval.
56 local timeout="$1" ; shift # "$@" is the command...
61 interval="${timeout#*/}"
62 timeout="${timeout%/*}"
66 if [ "$1" = "!" ] ; then
71 echo -n "<${timeout}|"
73 while [ $t -gt 0 ] ; do
76 if { ! $negate && [ $rc -eq 0 ] ; } || \
77 { $negate && [ $rc -ne 0 ] ; } ; then
78 echo "|$(($timeout - $t))|"
83 for i in $(seq 1 $interval) ; do