summaryrefslogtreecommitdiffstats
path: root/tester
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2014-10-22 08:54:05 +0200
committerPavel Raiskup <praiskup@redhat.com>2014-10-22 08:54:05 +0200
commit2422a081a5be0d5ac5afb122361bc283da67341f (patch)
treecb255582060af6547dd9318c56ba0e8c761846a1 /tester
parent922089746e1029de9be986672fcdeb6bc82e18d7 (diff)
downloadpostgresql-setup-tests-2422a081a5be0d5ac5afb122361bc283da67341f.tar.gz
postgresql-setup-tests-2422a081a5be0d5ac5afb122361bc283da67341f.tar.xz
postgresql-setup-tests-2422a081a5be0d5ac5afb122361bc283da67341f.zip
big reorg: prepare for generalization
Try to split into three separate components -> controller, tester, and 'tasks' (postgresql-tasks in our case). The controller component is the main part which is able to run the task remotely. Tester is more-like library for 'tasks' component (should be reusable on the raw git level). * controller: Almost separated component. * postgresql-tasks: Likewise. * tester: Likewise.
Diffstat (limited to 'tester')
-rwxr-xr-xtester/dtf-prepare-testsuite8
-rw-r--r--tester/libdtf/libdtf.sh47
-rwxr-xr-xtester/run205
3 files changed, 260 insertions, 0 deletions
diff --git a/tester/dtf-prepare-testsuite b/tester/dtf-prepare-testsuite
new file mode 100755
index 0000000..76031a9
--- /dev/null
+++ b/tester/dtf-prepare-testsuite
@@ -0,0 +1,8 @@
+#!/bin/bash -x
+
+tasks_srcdir="$1"
+
+srcdir=$(cd -P -- "$(dirname -- "$0")" && pwd -P) || exit 1
+
+ln -sf "$srcdir/run" "$tasks_srcdir"
+ln -sf "$srcdir/libdtf" "$tasks_srcdir"
diff --git a/tester/libdtf/libdtf.sh b/tester/libdtf/libdtf.sh
new file mode 100644
index 0000000..5724404
--- /dev/null
+++ b/tester/libdtf/libdtf.sh
@@ -0,0 +1,47 @@
+# package-agnostic function library. The "dtf_" prefix stands for
+# "destructive test framework".
+
+dtf_die() { echo >&2 "$@"; exit 1; }
+
+dtf_generate_results_tarball()
+{
+ local dir="$(dirname "$1")"
+ local name="$(basename "$1")"
+
+ local tarball=$dir/$name.tar.gz
+
+ pushd "$dir" >/dev/null
+
+ local oumask="$(umask)"
+ umask 0077
+ tar -czf "$tarball" "$name"
+ umask "$oumask"
+
+ export DTF_RESULT_TARBALL=$tarball
+}
+
+dtf_resultxml_cache()
+{
+ ___dtf_resultxml_cache+="$@
+"
+}
+
+dtf_resultxml_init()
+{
+ ___dtf_resultxml_cache=""
+ ___dtf_resultxml_file="$1"
+ dtf_resultxml_cache "<run><date>$(date --rfc-3339=seconds)</date>"
+
+ if test ! -f "$___dtf_resultxml_file"; then
+ echo '<?xml version="1.0" encoding="utf-8"?>' > "$___dtf_resultxml_file" \
+ || dtf_die "can not create '$___dtf_resultxml_file'"
+ fi
+}
+
+dtf_resultxml_finish()
+{
+ dtf_resultxml_cache "</run>"
+
+ echo "$___dtf_resultxml_cache" >> "$___dtf_resultxml_file" \
+ || dtf_die "can not write to $___dtf_resultxml_file"
+}
diff --git a/tester/run b/tester/run
new file mode 100755
index 0000000..55b87b8
--- /dev/null
+++ b/tester/run
@@ -0,0 +1,205 @@
+#!/bin/bash
+
+## CONFIG ##
+
+srcdir=$(cd -P -- "$(dirname -- "$0")" && pwd -P) || exit 1
+
+export DTF_LIBDIR=${DTF_LIBDIR-$srcdir/libdtf}
+export DTF_TASKS=${DTF_TASKS-$srcdir/tasks}
+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=/var/tmp/dtf.xml
+
+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
+
+## F.DEFS ##
+
+info()
+{
+ echo " * $@"
+}
+
+die()
+{
+ echo "$@" >&2
+ exit 1
+}
+
+dist()
+(
+ cd "$srcdir/../"
+ dir="$(basename "$srcdir")"
+ test -t 1 && die "can't put tarball to stdout"
+
+ if test -f "$dir/dist.include"; then
+ cmd="tar -ch"
+ while read line; do
+ cmd+=" $dir/$line"
+ done <"$srcdir/dist.include"
+
+ $cmd
+ elif declare -f "dtf_cb_dist_tasks" >/dev/null; then
+ dtf_cb_dist_tasks
+ else
+ tar -ch "$dir"
+ fi
+)
+
+# 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>"
+ )"
+
+ ( cd "$dtf_workdir"
+
+ outlog="$DTF_RESULTDIR/$dtf_test_id.log"
+ output_wrapper="cat > $outlog"
+
+ test $dtf_option_verbose = 1 \
+ && output_wrapper="tee $outlog"
+
+ test ! -e ./config.sh -o ! -e ./config.sh \
+ && echo "can not find one of {config,runtest}.sh" \
+ && exit 1
+
+ . ./config.sh
+
+ if test "$dtf_option_listonly" -eq 1; then
+ echo "$DTF_TEST_ID"
+ exit 0
+ fi
+
+ if test -n "$dtf_option_testids"; then
+ [[ "$dtf_option_testids" = *\ $DTF_TEST_ID\ * ]] || exit 0
+ fi
+
+ printf "%-40s" "RUN $DTF_TEST_ID ..."
+
+ set -o pipefail
+
+ ( . ./config.sh
+ . ./runtest.sh
+ rv=$?
+
+ test -n "$DTF_RESULT_TARBALL" \
+ && cp "$DTF_RESULT_TARBALL" "$DTF_RESULTDIR/$dtf_test_id.tar.gz"
+
+ { echo "---"
+ echo "exit_status: $rv"
+ echo "finished: \"$(date)\""
+ } >> "$DTF_RESULTDIR/$dtf_test_id.result"
+
+ exit $rv
+ ) 2>&1 | eval "$output_wrapper"
+ rv=$?
+
+ test $rv -eq 0 && echo "[ OK ]" || echo "[ FAIL ]"
+ exit $rv
+ )
+}
+
+prepare_resultdir()
+{
+ if test -e "$DTF_RESULTDIR"; then
+ test $dtf_option_force -eq 0 && die "result dir $DTF_RESULTDIR exits"
+
+ rm -rf "$DTF_RESULTDIR" || die "can not remove $DTF_RESULTDIR"
+ fi
+
+ mkdir -p "$DTF_RESULTDIR" || die "can not create $DTF_RESULTDIR"
+}
+
+show_help()
+{
+cat <<EOHELP >&2
+Usage: $0 [OPTIONS]
+
+Script is aimed to perform set of tests in subdirectories.
+
+Options:
+ --force Overwrite result dir if exists
+ --listonly List the available test ids
+ --testid=TESTID Perform this test only
+ --verbose Show complete output from each test
+ --help Show this help
+EOHELP
+test -n "$1" && exit "$1"
+}
+
+longopts="verbose,help,force,testid:,listonly,dist"
+ARGS=$(getopt -o "v" -l "$longopts" -n "getopt" -- "$@")
+if [ $? -ne 0 ]; then
+ echo "getopt error"
+ exit 1
+fi
+eval set -- "$ARGS"
+
+while true; do
+ case "$1" in
+ --verbose)
+ dtf_option_verbose=1
+ shift
+ ;;
+ --force)
+ dtf_option_force=1
+ shift
+ ;;
+ --listonly)
+ dtf_option_listonly=1
+ shift
+ ;;
+ --testid)
+ dtf_option_testids="$dtf_option_testids $2 "
+ shift 2
+ ;;
+ --help)
+ show_help 0
+ ;;
+ --dist)
+ dist
+ exit $?
+ ;;
+ --)
+ shift
+ break
+ ;;
+ esac
+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
+done <<<"$(find "$DTF_TASKS" -name runtest.sh)"
+dtf_resultxml_finish
+
+exit $result