summaryrefslogtreecommitdiffstats
path: root/ctdb/tests/scripts/common.sh
blob: 287fb71fd1d76e259e123d6a58117f4931691234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Hey Emacs, this is a -*- shell-script -*- !!!  :-)

# Common variables and functions for all CTDB tests.

# This expands the most probable problem cases like "." and "..".
TEST_SUBDIR=$(dirname "$0")
if [ $(dirname "$TEST_SUBDIR") = "." ] ; then
    TEST_SUBDIR=$(cd "$TEST_SUBDIR" ; pwd)
fi

_test_dir=$(dirname "$TEST_SUBDIR")

# If we are running from within the source tree then, depending on the
# tests that we're running, we may need to add the top level bin/ and
# tools/ subdirectories to $PATH.  This means we need a way of
# determining if we're running from within the source tree.  There is
# no use looking outside the tests/ subdirectory because anything
# above that level may be meaningless and outside our control.
# Therefore, we'll use existence of $_test_dir/run_tests.sh to
# indicate that we're running in-tree - on a system where the tests
# have been installed, this file will be absent (renamed and placed in
# some bin/ directory).
if [ -f "${_test_dir}/run_tests.sh" ] ; then
    ctdb_dir=$(dirname "$_test_dir")

    _tools_dir="${ctdb_dir}/tools"
    if [ -d "$_tools_dir" ] ; then
	PATH="${_tools_dir}:$PATH"
    fi
fi

_test_bin_dir="${TEST_BIN_DIR:-${ctdb_dir}/bin}"
case "$_test_bin_dir" in
    /*) : ;;
    *) _test_bin_dir="${PWD}/${_test_bin_dir}" ;;
esac
if [ -d "$_test_bin_dir" ] ; then
    PATH="${_test_bin_dir}:$PATH"
fi

# Print a message and exit.
die ()
{
    echo "$1" >&2 ; exit ${2:-1}
}