diff options
Diffstat (limited to 'tester')
-rwxr-xr-x | tester/run | 144 |
1 files changed, 82 insertions, 62 deletions
@@ -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 |