1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

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)
This commit is contained in:
Martin Schwenke 2012-05-14 11:57:20 +10:00
parent b8e9a3e54d
commit 594601bdad
4 changed files with 66 additions and 66 deletions

View File

@ -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"

View File

@ -1,31 +0,0 @@
#!/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

View File

@ -0,0 +1 @@
run_tests.sh

View File

@ -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"
# If no tests specified them run the defaults.
[ -n "$1" ] || set -- $tests
# By default, run all unit tests and the tests against local
# daemons
dirs="onnode takeover tool eventscripts simple"
./scripts/run_tests -l -s $opts $dirs || exit 1
fi
"${test_dir}/scripts/run_tests" $opts "$@" || exit 1
echo "All OK"
exit 0

View File

@ -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