summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2012-05-14 11:57:20 +1000
committerMartin Schwenke <martin@meltin.net>2012-05-14 15:02:19 +1000
commit594601bdad81f0211e5c9f844e81262ede06c3b6 (patch)
tree76f77b7cde5d63138180768a352e689540fdbc13
parentb8e9a3e54d5e524df6a1c08a2cbbe1ce894fbf58 (diff)
downloadsamba-594601bdad81f0211e5c9f844e81262ede06c3b6.tar.gz
samba-594601bdad81f0211e5c9f844e81262ede06c3b6.tar.xz
samba-594601bdad81f0211e5c9f844e81262ede06c3b6.zip
tests: Fix wrapper scripts to handle options and tests without breakage
If the -V option is given and no tests are supplied, the "cd" command in run_tests.sh cause scripts/run_tests to interpret the argument to -V incorrectly. Therefore, the wrapper scripts can't use "cd" because they don't know what the options are doing! Instead scripts/run_tests searches for each test relative to the current directory and, if not previously found, then searches relative to the top-level tests directory. This is a much better way of doing things. Given that run_tests.sh and run_cluster_tests.sh were starting to contain duplicate complex logic, remove run_cluster_tests.sh and replace it with a symlink to run_tests.sh. Run_tests.sh checks $0 to see what options/defaults to use. Update INSTALL to deal with this. Signed-off-by: Martin Schwenke <martin@meltin.net> (This used to be ctdb commit ed2db1f4e8d2b222d7f912a4a007ce48a23e83b0)
-rwxr-xr-xctdb/tests/INSTALL10
l---------[-rwxr-xr-x]ctdb/tests/run_cluster_tests.sh32
-rwxr-xr-xctdb/tests/run_tests.sh30
-rwxr-xr-xctdb/tests/scripts/run_tests60
4 files changed, 66 insertions, 66 deletions
diff --git a/ctdb/tests/INSTALL b/ctdb/tests/INSTALL
index 6f43650cce..c67d76dc7d 100755
--- a/ctdb/tests/INSTALL
+++ b/ctdb/tests/INSTALL
@@ -83,9 +83,7 @@ cp -pr "tests/bin/" "${ctdb_libdir}"
ctdb_bindir="${destdir}${bindir}"
echo "Installing wrapper scripts into ${ctdb_bindir}..."
mkdir -p "${ctdb_bindir}"
-for i in tests/run_tests.sh tests/run_cluster_tests.sh ; do
- b=$(basename "$i" ".sh")
- out="${ctdb_bindir}/ctdb_${b}"
- sed -e "s@^test_dir=.*@test_dir=${datarootdir}/ctdb-tests\nexport TEST_BIN_DIR=\"${libdir}/ctdb-tests\"@" "$i" >"${out}"
- chmod 755 "$out"
-done
+out="${ctdb_bindir}/ctdb_run_tests"
+sed -e "s@^test_dir=.*@test_dir=${datarootdir}/ctdb-tests\nexport TEST_BIN_DIR=\"${libdir}/ctdb-tests\"@" "tests/run_tests.sh" >"$out"
+chmod 755 "$out"
+ln -s "ctdb_run_tests" "${ctdb_bindir}/ctdb_run_cluster_tests"
diff --git a/ctdb/tests/run_cluster_tests.sh b/ctdb/tests/run_cluster_tests.sh
index 9cafd50b13..5236e32d82 100755..120000
--- a/ctdb/tests/run_cluster_tests.sh
+++ b/ctdb/tests/run_cluster_tests.sh
@@ -1,31 +1 @@
-#!/bin/sh
-
-test_dir=$(dirname "$0")
-
-# Allow options to be passed to this script. However, if any options
-# are passed there must be a "--" between the options and the tests.
-# This makes it easy to handle options that take arguments.
-opts=""
-case "$1" in
- -*)
- while [ -n "$1" ] ; do
- case "$1" in
- --) shift ; break ;;
- *) opts="$opts $1" ; shift ;;
- esac
- done
-esac
-
-if [ -n "$1" ] ; then
- "${test_dir}/scripts/run_tests" -s $opts "$@" || exit 1
-else
- cd "$test_dir"
-
- # By default, don't bother with unit tests
- dirs="simple complex"
-
- ./scripts/run_tests -s $opts $dirs || exit 1
-fi
-
-echo "All OK"
-exit 0
+run_tests.sh \ No newline at end of file
diff --git a/ctdb/tests/run_tests.sh b/ctdb/tests/run_tests.sh
index cd90bbbb97..50924fcf25 100755
--- a/ctdb/tests/run_tests.sh
+++ b/ctdb/tests/run_tests.sh
@@ -2,10 +2,25 @@
test_dir=$(dirname "$0")
+case $(basename "$0") in
+ *run_cluster_tests*)
+ # Running on a cluster:
+ # * print summary, run any integration tests against cluster
+ # * default to running: all integration tests, no unit tests
+ opts="-s"
+ tests="simple complex"
+ ;;
+ *)
+ # Running on local machine:
+ # * print summary, run any integration tests against local daemons
+ # * default to running: all unit tests, simple integration tests
+ opts="-s -l"
+ tests="onnode takeover tool eventscripts simple"
+esac
+
# Allow options to be passed to this script. However, if any options
# are passed there must be a "--" between the options and the tests.
# This makes it easy to handle options that take arguments.
-opts=""
case "$1" in
-*)
while [ -n "$1" ] ; do
@@ -16,17 +31,10 @@ case "$1" in
done
esac
-if [ -n "$1" ] ; then
- "${test_dir}/scripts/run_tests" -l -s $opts "$@" || exit 1
-else
- cd "$test_dir"
-
- # By default, run all unit tests and the tests against local
- # daemons
- dirs="onnode takeover tool eventscripts simple"
+# If no tests specified them run the defaults.
+[ -n "$1" ] || set -- $tests
- ./scripts/run_tests -l -s $opts $dirs || exit 1
-fi
+"${test_dir}/scripts/run_tests" $opts "$@" || exit 1
echo "All OK"
exit 0
diff --git a/ctdb/tests/scripts/run_tests b/ctdb/tests/scripts/run_tests
index 0ae4cee151..2d3417420e 100755
--- a/ctdb/tests/scripts/run_tests
+++ b/ctdb/tests/scripts/run_tests
@@ -155,23 +155,42 @@ run_one_test ()
[ -x "$_f" ] || die "test \"$_f\" is not executable"
tests_total=$(($tests_total + 1))
- export TEST_SCRIPTS_DIR=$(dirname "$0")
-
ctdb_test_run "$_f" | tee "$tf" | show_progress
status=$?
if $with_summary ; then
if [ $status -eq 0 ] ; then
tests_passed=$(($tests_passed + 1))
- t=" PASSED "
+ _t=" PASSED "
else
- t="*FAILED*"
+ _t="*FAILED*"
tests_failed=$(($tests_failed + 1))
fi
if $with_desc ; then
desc=$(tail -n +4 $tf | head -n 1)
_f="$desc"
fi
- echo "$t $_f" >>"$sf"
+ echo "$_t $_f" >>"$sf"
+ fi
+}
+
+find_and_run_one_test ()
+{
+ _t="$1"
+ _dir="$2"
+
+ _f="${_dir}${_dir:+/}${_t}"
+
+ if [ -d "$_f" ] ; then
+ for _i in $(ls "${_f%/}/"*".sh" 2>/dev/null) ; do
+ run_one_test "$_i"
+ if $exit_on_fail && [ $status -ne 0 ] ; then
+ break
+ fi
+ done
+ elif [ -f "$_f" ] ; then
+ run_one_test "$_f"
+ else
+ status=127
fi
}
@@ -181,21 +200,26 @@ mkdir -p "$TEST_VAR_DIR"
TEST_VAR_DIR=$(cd "$TEST_VAR_DIR"; echo "$PWD")
echo "TEST_VAR_DIR=$TEST_VAR_DIR"
+export TEST_SCRIPTS_DIR=$(dirname "$0")
+
for f ; do
- if [ -d "$f" ] ; then
- for i in $(ls "${f%/}/"*".sh" 2>/dev/null) ; do
- run_one_test "$i"
- if $exit_on_fail && [ $status -ne 0 ] ; then
- break
- fi
- done
- elif [ -f "$f" ] ; then
- run_one_test "$f"
- if $exit_on_fail && [ $status -ne 0 ] ; then
+ find_and_run_one_test "$f"
+
+ if [ $status -eq 127 ] ; then
+ # Find the the top-level tests directory
+ tests_dir=$(dirname $(cd $TEST_SCRIPTS_DIR; echo $PWD))
+ # Strip off current directory from beginning, if there, just
+ # to make paths more friendly.
+ tests_dir=${tests_dir#$PWD/}
+ find_and_run_one_test "$f" "$tests_dir"
+ fi
+
+ if [ $status -eq 127 ] ; then
+ die "test \"$f\" is not recognised"
+ fi
+
+ if $exit_on_fail && [ $status -ne 0 ] ; then
break
- fi
- else
- die "test \"$f\" is not recognised"
fi
done