summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/dtf-gen103
-rwxr-xr-xdtf-gen6
-rw-r--r--share/dtf/lib/default93
-rw-r--r--share/dtf/tpl/run.tpl46
4 files changed, 248 insertions, 0 deletions
diff --git a/bin/dtf-gen b/bin/dtf-gen
new file mode 100755
index 0000000..19393fe
--- /dev/null
+++ b/bin/dtf-gen
@@ -0,0 +1,103 @@
+#! /bin/bash
+
+## Some important facts about this code.
+##
+## - it's enough to do 'false' within test and it is failure.
+## - each subdirectory file is self-standing
+## - each test might have several tags -- future dependencies
+
+DTF_OUTPUT=DTF_OUTPUT
+
+
+# config
+: ${outputdir=$PWD/$DTF_OUTPUT}
+: ${toporigdir=$PWD}
+: ${libdir=/usr/lib}
+: ${datadir=/usr/share}
+
+: ${dtfdatadir=$datadir/dtf}
+: ${dtflibdir=$dtfdatadir/lib}
+: ${dtftpldir=$dtfdatadir/tpl}
+
+. "$dtflibdir/default" || exit 1
+
+
+info ()
+{
+ echo " * $*"
+}
+
+
+generate_wrapper ()
+{
+ _run_cmd=$outputdir/$1/run
+ # TODO: This is not portable.
+
+ fix_testname=$1
+ test "$fix_testname" = '.' && fix_testname=ROOT
+ fix_testname=${fix_testname##./}
+
+ echo '#! /bin/bash
+
+: ${__DTF_TOP_TEST=:}
+
+$__DTF_TOP_TEST && exec 3>&1 4>&2
+
+abs_dirname ()
+{
+ abs_dirname_result=`cd "$1" && pwd`
+}
+abs_dirname "`dirname $0`"
+srcdir=$abs_dirname_result
+' > "$_run_cmd"
+
+ cat >> "$_run_cmd" <<EOF
+export top_srcdir=\$srcdir/$(printf %q "$2")
+export testname=$(printf %q "$fix_testname")
+EOF
+
+ cat "$dtftpldir/run.tpl" >> "$_run_cmd"
+
+ chmod +x "$_run_cmd"
+}
+
+
+# count_recursive_walk SUBDIR SRCDIR TOP_SRCDIR
+# ---------------------------------------------
+count_recursive_walk ()
+{
+ cd "$1"
+
+ info "directory: $2"
+
+ mkdir -p "$outputdir/$2"
+
+ generate_wrapper "$2" "$3"
+ test -f testcase \
+ && cp testcase "$outputdir/$2"
+ test -f library && cat library >> "$outputdir/library"
+
+ for _rw_i in *
+ do
+ __dtf_is_testdir "$_rw_i" || continue
+ _rw_fulldir="$2/$_rw_i"
+
+ mkdir -p "$outputdir/$_rw_fulldir" || exit 1
+
+ count_recursive_walk "$_rw_i" "$2/$_rw_i" "$3/.."
+ done
+ cd ..
+}
+
+
+test -d "$outputdir" && {
+ chmod u+w "$outputdir" -R
+ /bin/rm -rf "$outputdir"
+}
+
+mkdir -p "$outputdir"
+cat "$dtflibdir/default" > "$outputdir/library"
+count_recursive_walk "$toporigdir" . .
+
+# Protect sources!
+chmod a-w "$outputdir" -R
diff --git a/dtf-gen b/dtf-gen
new file mode 100755
index 0000000..0a5b1f2
--- /dev/null
+++ b/dtf-gen
@@ -0,0 +1,6 @@
+#! /bin/sh
+
+srcdir=`dirname "$0"`
+export bindir=$srcdir/bin
+export datadir=$srcdir/share
+$bindir/dtf-gen
diff --git a/share/dtf/lib/default b/share/dtf/lib/default
new file mode 100644
index 0000000..6c53c40
--- /dev/null
+++ b/share/dtf/lib/default
@@ -0,0 +1,93 @@
+#! /bin/bash
+
+# Global library file. Methods prefixed by '__dtf_' are internal, for example
+# __dtf_is_testdir. Other methods prefixed by 'dtf_' are API.
+
+: ${SHELL=/bin/bash}
+
+
+__dtf_is_testdir ()
+{
+ test -d "$1" || return 1
+ case "$1" in
+ DTF_OUTPUT|DTF_RESULT|library)
+ return 1
+ ;;
+ esac
+ :
+}
+
+
+__dtf_run_testcase ()
+{
+ resultdir="$outputdir/$testname"
+ $__DTF_TOP_TEST && resultdir="$outputdir"
+
+ stdout="$resultdir/stdout"
+ stderr="$resultdir/stderr"
+
+ mkdir -p "$resultdir" && cd "$resultdir"
+
+ set dummy \
+ __DTF_TOP_TEST=false \
+ outputdir="$outputdir" \
+ "$@"
+ shift
+
+ if $__DTF_TOP_TEST; then
+ eval "$@" 4>&2 3>&1 \
+ 2>> "$stderr" \
+ 1>> "$stdout"
+ else
+ # TODO: avoid bashishm
+ eval "$@" \
+ 2> >(tee -a "$stderr" >&2) \
+ 1> >(tee -a "$stdout")
+ fi
+
+ case $? in
+ 0|77)
+ return 0
+ ;;
+ *)
+ __dtf_rc=1
+ return 1
+ ;;
+ esac
+}
+
+
+__dtf_control_msg ()
+{
+ echo >&4 "$*"
+}
+
+
+__dtf_nl_control_msg ()
+{
+ __dtf_control_msg "
+ ** $* **
+"
+}
+
+
+__dtf_top_control_msg ()
+{
+ $__DTF_TOP_TEST && return
+ __dtf_nl_control_msg "$*"
+}
+
+
+__dtf_toplevel_result_msg ()
+{
+ $__DTF_TOP_TEST || return
+
+ case $1 in
+ 0)
+ __dtf_nl_control_msg "Success."
+ ;;
+ *)
+ __dtf_nl_control_msg "Fail."
+ ;;
+ esac
+}
diff --git a/share/dtf/tpl/run.tpl b/share/dtf/tpl/run.tpl
new file mode 100644
index 0000000..663e302
--- /dev/null
+++ b/share/dtf/tpl/run.tpl
@@ -0,0 +1,46 @@
+#! /bin/bash -x
+# vi: ft=sh
+
+test -z "$outputdir" && outputdir="$PWD/DTF_RESULT"
+
+. "$top_srcdir/library"
+
+__dtf_rc=0
+
+
+# Gather sub-tests.
+sub_tests=
+for __dtf_sub_test in $srcdir/*
+do
+ __dtf_is_testdir "$__dtf_sub_test" || continue
+ sub_tests="$sub_tests
+$__dtf_sub_test/run"
+done
+
+#
+# Execute the testcase, when available.
+#
+
+test -f $srcdir/testcase && {
+ __dtf_control_msg " $testname"
+ __dtf_run_testcase "$SHELL" "$srcdir"/testcase
+}
+
+#
+# Execute sub-tests.
+#
+
+if test -n "$sub_tests"; then
+ __dtf_top_control_msg "going to $testname"
+
+ for subtest in $sub_tests
+ do
+ __dtf_run_testcase "$SHELL" "$subtest"
+ done
+ result=Ok.
+ test "$__dtf_rc" -eq 0 || result=Fail.
+ __dtf_top_control_msg "group $testname: $result"
+fi
+
+__dtf_toplevel_result_msg "$__dtf_rc"
+exit $__dtf_rc