summaryrefslogtreecommitdiffstats
path: root/tester
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2014-10-24 14:29:35 +0200
committerPavel Raiskup <praiskup@redhat.com>2014-10-24 14:29:35 +0200
commit2a6faa0853239377f191cdd72efc60f1df684ebd (patch)
tree2c8180a86ee2a289c6d8a6ff37b764624352af2f /tester
parentf9ec27bd843e40f89ace7705a075e938aa3a9409 (diff)
downloadpostgresql-setup-tests-2a6faa0853239377f191cdd72efc60f1df684ebd.tar.gz
postgresql-setup-tests-2a6faa0853239377f191cdd72efc60f1df684ebd.tar.xz
postgresql-setup-tests-2a6faa0853239377f191cdd72efc60f1df684ebd.zip
tester/run: better define API
Define test return values and its calling. Do not split the testcase into configuration and running script, rather use one file and wrap the script by run() method. This is still very easy to run without running whole testsuite. * tester/run (DTF_RESULT_*): Return values API. (run): Rename to run_test. Make the function more readable, don't generate xml results (not yet used anyway). * postgresql-tests/config.sh: Do not source the per-testsuite library directly as the configuration script config.h is sourced even by 'run' script itself for --dist option (for that action we actually do not need per-testsuite libraries). * postgresql-tests/tasks/initdb/runtest.sh: New API used. * postgresql-tests/tasks/initdb_old/runtest.sh: Likewise. * postgresql-tests/tasks/upgrade-basic/runtest.sh: Likewise. * postgresql-tests/tasks/upgrade-utf8-syntax/runtest.sh: Likewise. * postgresql-tests/tasks/upgrade-basic/config.sh: Remove. * postgresql-tests/tasks/initdb/config.sh: Remove. * postgresql-tests/tasks/initdb_old/config.sh: Remove. * postgresql-tests/tasks/upgrade-utf8-syntax/config.sh: Remove.
Diffstat (limited to 'tester')
-rwxr-xr-xtester/run144
1 files changed, 82 insertions, 62 deletions
diff --git a/tester/run b/tester/run
index b05c024..4a60518 100755
--- a/tester/run
+++ b/tester/run
@@ -1,8 +1,24 @@
#!/bin/bash
-## CONFIG ##
+### test case return codes ###
-srcdir=$(cd -P -- "$(dirname -- "$0")" && pwd -P) || exit 1
+# basic error codes
+export DTF_RESULT_SUCCES=0
+export DTF_RESULT_FAILURE=1
+export DTF_RESULT_EXP_FAILURE=2
+
+# Inherited from (reserved for) autoconf
+export DTF_RESULT_SKIP=77
+export DTF_RESULT_HARDFAIL=99
+
+# Should not be used from test-cases
+export DTF_RESULT_TS_SKIP=66
+export DTF_RESULT_TS_CONFIG=67
+export DTF_RESULT_USER_ERROR=68
+
+srcdir=$(cd -P -- "$(dirname -- "$0")" && pwd -P) || exit $DTF_RESULT_TS_CONFIG
+
+### paths ###
export DTF_LIBDIR=${DTF_LIBDIR-$srcdir/libdtf}
export DTF_TASKS=${DTF_TASKS-$srcdir/tasks}
@@ -11,16 +27,16 @@ export DTF_RESULTDIR=${DTF_RESULTDIR-/var/tmp/dtf}
# when exists per-testsuite config.sh, source it here
test -r "$srcdir/config.sh" && . "$srcdir/config.sh"
-export dtf_resultxml_file="$DTF_RESULTDIR/dtf.xml"
+### options ###
export dtf_option_verbose=0
export dtf_option_force=0
export dtf_option_testids=""
export dtf_option_listonly=0
-. "$DTF_LIBDIR/libdtf.sh" || exit 1
+. "$DTF_LIBDIR/libdtf.sh" || exit $DTF_RESULT_TS_CONFIG
-## F.DEFS ##
+### function definitions ###
info()
{
@@ -30,7 +46,7 @@ info()
die()
{
echo "$@" >&2
- exit 1
+ exit $DTF_RESULT_TS_CONFIG
}
dist()
@@ -55,68 +71,64 @@ dist()
# run TESTDIR
# -----------
-# source the $TESTDIR/runtest.sh
-run()
-{
- export dtf_workdir=$1
- export dtf_test_id=$(basename "$dtf_workdir")
-
- dtf_resultxml_cache "$( cd "$dtf_workdir"
- . ./config.sh
- echo "<test>"
- echo "<id>$DTF_TEST_ID</id>"
- echo "<description>"
- echo "$DTF_TEST_DESCRIPTION"
- echo "</description>"
- )"
+#
+# Sources the $TESTDIR/runtest.sh and executes the 'run' method from the sourced
+# file. The RUN's exit value is propagated to the caller of RUN_TEST.
- ( cd "$dtf_workdir"
+run_test()
+(
+ cd "$1"
- outlog="$DTF_RESULTDIR/tasks/$dtf_test_id.log"
- output_wrapper="cat > $outlog"
+ test ! -e ./runtest.sh \
+ && echo "runtest.sh not found" \
+ && exit $DTF_RESULT_TS_CONFIG
- test $dtf_option_verbose = 1 \
- && output_wrapper="tee $outlog"
+ . ./runtest.sh
- test ! -e ./config.sh -o ! -e ./config.sh \
- && echo "can not find one of {config,runtest}.sh" \
- && exit 1
+ test -z "$DTF_TEST_ID" && exit $DTF_RESULT_TS_CONFIG
- . ./config.sh
+ result_dir="$DTF_RESULTDIR/tasks/$DTF_TEST_ID"
- if test "$dtf_option_listonly" -eq 1; then
- echo "$DTF_TEST_ID"
- exit 0
- fi
+ mkdir -p "$result_dir" || exit
+ outlog="$result_dir/run.log"
- if test -n "$dtf_option_testids"; then
- [[ "$dtf_option_testids" = *\ $DTF_TEST_ID\ * ]] || exit 0
- fi
+ output_wrapper="cat > $outlog"
+ test $dtf_option_verbose = 1 \
+ && output_wrapper="tee $outlog"
- printf "%-40s" "RUN $DTF_TEST_ID ..."
+ if test "$dtf_option_listonly" -eq 1; then
+ echo "$DTF_TEST_ID"
+ exit $DTF_RESULT_TS_SKIP
+ fi
- set -o pipefail
+ if test -n "$dtf_option_testids"; then
+ [[ "$dtf_option_testids" = *\ $DTF_TEST_ID\ * ]] \
+ || exit $DTF_RESULT_TS_SKIP
+ fi
- ( . ./config.sh
- . ./runtest.sh
- rv=$?
+ printf "%-40s" "RUN $DTF_TEST_ID ..."
- test -n "$DTF_RESULT_TARBALL" \
- && cp "$DTF_RESULT_TARBALL" "$DTF_RESULTDIR/tasks/$dtf_test_id.tar.gz"
+ set -o pipefail
- { echo "---"
- echo "exit_status: $rv"
- echo "finished: \"$(date)\""
- } >> "$DTF_RESULTDIR/tasks/$dtf_test_id.result"
+ (
+ for i in "${dtf_libfiles[@]}"; do
+ . "$i"
+ done
- exit $rv
- ) 2>&1 | eval "$output_wrapper"
+ run
rv=$?
- test $rv -eq 0 && echo "[ OK ]" || echo "[ FAIL ]"
+ test -n "$DTF_RESULT_TARBALL" \
+ && cp "$DTF_RESULT_TARBALL" \
+ "$DTF_RESULTDIR/tasks/$DTF_TEST_ID/output.tar.gz"
+ { echo "---"
+ echo "exit_status: $rv"
+ echo "finished: \"$(date)\""
+ } >> "$DTF_RESULTDIR/tasks/$DTF_TEST_ID.result"
+
exit $rv
- )
-}
+ ) 2>&1 | eval "$output_wrapper"
+)
prepare_resultdir()
{
@@ -150,7 +162,7 @@ longopts="verbose,help,force,testid:,listonly,dist"
ARGS=$(getopt -o "v" -l "$longopts" -n "getopt" -- "$@")
if [ $? -ne 0 ]; then
echo "getopt error"
- exit 1
+ exit $DTF_RESULT_TS_CONFIG
fi
eval set -- "$ARGS"
@@ -188,18 +200,26 @@ done
test $dtf_option_listonly -ne 1 && prepare_resultdir
-dtf_resultxml_init "$dtf_resultxml_file"
result=0
while read i; do
testdir=$(dirname "$i")
- run "$testdir" || result=1
-
- if test $result -eq 0; then
- dtf_resultxml_cache "<result>Success</result></test>"
- else
- dtf_resultxml_cache "<result>Fail</result></test>"
- fi
+ run_test "$testdir"
+ case "$?" in
+ $DTF_RESULT_SUCCES)
+ echo "[ OK ]"
+ ;;
+ $DTF_RESULT_TS_SKIP)
+ ;;
+ $DTF_RESULT_SKIP)
+ echo "[ SKIP ]"
+ ;;
+ $DTF_RESULT_HARDFAIL)
+ die "hard failure"
+ ;;
+ *)
+ result=1
+ ;;
+ esac
done <<<"$(find "$DTF_TASKS" -name runtest.sh)"
-dtf_resultxml_finish
exit $result