From 2a6faa0853239377f191cdd72efc60f1df684ebd Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 24 Oct 2014 14:29:35 +0200 Subject: 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. --- postgresql-tests/config.sh | 8 +- postgresql-tests/tasks/initdb/config.sh | 4 - postgresql-tests/tasks/initdb/runtest.sh | 29 +++-- postgresql-tests/tasks/initdb_old/config.sh | 4 - postgresql-tests/tasks/initdb_old/runtest.sh | 18 ++- postgresql-tests/tasks/upgrade-basic/config.sh | 2 - postgresql-tests/tasks/upgrade-basic/runtest.sh | 14 +- .../tasks/upgrade-utf8-syntax/config.sh | 3 - .../tasks/upgrade-utf8-syntax/runtest.sh | 29 +++-- tester/run | 144 ++++++++++++--------- 10 files changed, 146 insertions(+), 109 deletions(-) delete mode 100644 postgresql-tests/tasks/initdb/config.sh mode change 100755 => 100644 postgresql-tests/tasks/initdb/runtest.sh delete mode 100644 postgresql-tests/tasks/initdb_old/config.sh mode change 100755 => 100644 postgresql-tests/tasks/initdb_old/runtest.sh delete mode 100644 postgresql-tests/tasks/upgrade-basic/config.sh delete mode 100644 postgresql-tests/tasks/upgrade-utf8-syntax/config.sh diff --git a/postgresql-tests/config.sh b/postgresql-tests/config.sh index 6650ed2..6dc859a 100644 --- a/postgresql-tests/config.sh +++ b/postgresql-tests/config.sh @@ -1,7 +1,4 @@ -# include PostgreSQL specific test-library -. "$srcdir/lib_pgsql.sh" || exit 1 - -export dtf_dataurls +export dtf_dataurls dtf_libfiles # this is needed for some tests dtf_dataurls[0]=http://172.16.125.10/root-tests/data/postgresql/ @@ -11,3 +8,6 @@ dtf_cb_dist_tasks() { tar -ch "$dir" --exclude gen-data } + +# include PostgreSQL specific test-library +dtf_libfiles[0]="$srcdir/lib_pgsql.sh" diff --git a/postgresql-tests/tasks/initdb/config.sh b/postgresql-tests/tasks/initdb/config.sh deleted file mode 100644 index c7f6619..0000000 --- a/postgresql-tests/tasks/initdb/config.sh +++ /dev/null @@ -1,4 +0,0 @@ -DTF_TEST_ID="initdb-basic" -DTF_TEST_DESCRIPTION="\ -Check that the syntax 'postgresql-setup --initdb' works together with following -'service start postgresql'." diff --git a/postgresql-tests/tasks/initdb/runtest.sh b/postgresql-tests/tasks/initdb/runtest.sh old mode 100755 new mode 100644 index ee520d6..f8cf3a5 --- a/postgresql-tests/tasks/initdb/runtest.sh +++ b/postgresql-tests/tasks/initdb/runtest.sh @@ -1,11 +1,20 @@ -dtf_postgresql_test_init -if rlIsFedora 18 19 20 21 || rlIsRHEL 5 6 7; then - # This syntaxe is not supported on oler systems. - : -else - rlRun "postgresql-setup --initdb" - rlServiceStart postgresql - dtf_postgresql_check_started -fi +export DTF_TEST_ID="initdb-basic" +export DTF_TEST_DESCRIPTION="\ +Check that the syntax 'postgresql-setup --initdb' works together with following +'service start postgresql'." + +run() +{ + dtf_postgresql_test_init + if rlIsFedora 18 19 20 21 || rlIsRHEL 5 6 7; then + # This syntaxe is not supported on oler systems. + : + else + rlRun "postgresql-setup --initdb" + rlServiceStart postgresql + dtf_postgresql_check_started + fi + + dtf_postgresql_test_finish +} -dtf_postgresql_test_finish diff --git a/postgresql-tests/tasks/initdb_old/config.sh b/postgresql-tests/tasks/initdb_old/config.sh deleted file mode 100644 index 2386677..0000000 --- a/postgresql-tests/tasks/initdb_old/config.sh +++ /dev/null @@ -1,4 +0,0 @@ -DTF_TEST_ID="initdb-old-syntax" -DTF_TEST_DESCRIPTION="\ -Check that the old syntax 'postgresql-setup initdb' works together with -following 'service start postgresql'." diff --git a/postgresql-tests/tasks/initdb_old/runtest.sh b/postgresql-tests/tasks/initdb_old/runtest.sh old mode 100755 new mode 100644 index 6a8d63c..1cd77f4 --- a/postgresql-tests/tasks/initdb_old/runtest.sh +++ b/postgresql-tests/tasks/initdb_old/runtest.sh @@ -1,5 +1,13 @@ -dtf_postgresql_test_init -rlRun "postgresql-setup initdb" -rlServiceStart postgresql -dtf_postgresql_check_started -dtf_postgresql_test_finish +export DTF_TEST_ID="initdb-old-syntax" +export DTF_TEST_DESCRIPTION="\ +Check that the old syntax 'postgresql-setup initdb' works together with +following 'service start postgresql'." + +run() +{ + dtf_postgresql_test_init + rlRun "postgresql-setup initdb" + rlServiceStart postgresql + dtf_postgresql_check_started + dtf_postgresql_test_finish +} diff --git a/postgresql-tests/tasks/upgrade-basic/config.sh b/postgresql-tests/tasks/upgrade-basic/config.sh deleted file mode 100644 index a1d4a2f..0000000 --- a/postgresql-tests/tasks/upgrade-basic/config.sh +++ /dev/null @@ -1,2 +0,0 @@ -export DTF_TEST_ID="basic-upgrade" -export DTF_TEST_DESCRIPTION="Check postgresql-setup [--]upgrade" diff --git a/postgresql-tests/tasks/upgrade-basic/runtest.sh b/postgresql-tests/tasks/upgrade-basic/runtest.sh index 37af60e..7952fe0 100644 --- a/postgresql-tests/tasks/upgrade-basic/runtest.sh +++ b/postgresql-tests/tasks/upgrade-basic/runtest.sh @@ -1,6 +1,12 @@ -dtf_postgresql_test_init +export DTF_TEST_ID="basic-upgrade" +export DTF_TEST_DESCRIPTION="Check postgresql-setup [--]upgrade" -dtf_postgresql_upgrade_tour "$(dtf_postgresql_data_mirror)" basic.tar.gz -rlAssert0 "test wrapper should finish successfully" $? +run() +{ + dtf_postgresql_test_init -dtf_postgresql_test_finish + dtf_postgresql_upgrade_tour "$(dtf_postgresql_data_mirror)" basic.tar.gz + rlAssert0 "test wrapper should finish successfully" $? + + dtf_postgresql_test_finish +} diff --git a/postgresql-tests/tasks/upgrade-utf8-syntax/config.sh b/postgresql-tests/tasks/upgrade-utf8-syntax/config.sh deleted file mode 100644 index bed95ad..0000000 --- a/postgresql-tests/tasks/upgrade-utf8-syntax/config.sh +++ /dev/null @@ -1,3 +0,0 @@ -export DTF_TEST_ID="basic-locale-utf8-syntax" -export DTF_TEST_DESCRIPTION="Check postgresql-setup --upgrade works even when \ -the system locale changed from xx_XX.utf8 to xx_XX.UTF-8" diff --git a/postgresql-tests/tasks/upgrade-utf8-syntax/runtest.sh b/postgresql-tests/tasks/upgrade-utf8-syntax/runtest.sh index cc8f8c4..c14a34e 100644 --- a/postgresql-tests/tasks/upgrade-utf8-syntax/runtest.sh +++ b/postgresql-tests/tasks/upgrade-utf8-syntax/runtest.sh @@ -1,15 +1,22 @@ -dtf_postgresql_test_init +export DTF_TEST_ID="basic-locale-utf8-syntax" +export DTF_TEST_DESCRIPTION="Check postgresql-setup --upgrade works even when \ +the system locale changed from xx_XX.utf8 to xx_XX.UTF-8" -dtf_postgresql_cb_upgrade_select() +run() { - if rlIsFedora 20 21 22; then - cat - else - cat >/dev/null - fi -} + dtf_postgresql_test_init + + dtf_postgresql_cb_upgrade_select() + { + if rlIsFedora 20 21 22; then + cat + else + cat >/dev/null + fi + } -dtf_postgresql_upgrade_tour "$(dtf_postgresql_data_mirror)" locale-utf-typo.tar.gz -rlAssert0 "test wrapper should finish successfully" $? + dtf_postgresql_upgrade_tour "$(dtf_postgresql_data_mirror)" locale-utf-typo.tar.gz + rlAssert0 "test wrapper should finish successfully" $? -dtf_postgresql_test_finish + dtf_postgresql_test_finish +} 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 "" - echo "$DTF_TEST_ID" - echo "" - echo "$DTF_TEST_DESCRIPTION" - echo "" - )" +# +# 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 "Success" - else - dtf_resultxml_cache "Fail" - 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 -- cgit