auth: Fix CID 1615191 Uninitialized scalar variable
[vlendec/samba-autobuild/.git] / ctdb / tests / run_tests.sh
index 8304443b1962ef8e1589f982c23a67aff001396b..dfe2a9ab36437f43247e07b2e5c545644437e92c 100755 (executable)
@@ -12,6 +12,7 @@ Options:
   -e           Exit on the first test failure
   -H           No headers - for running single test with other wrapper
   -I <count>    Iterate tests <count> times, exiting on failure (implies -e, -N)
+  -l <count>    Use <count> daemons for local daemon integration tests
   -L            Print daemon logs on test failure (only some tests)
   -N           Don't print summary of tests results after running all tests
   -q           Quiet - don't show tests being run (still displays summary)
@@ -41,33 +42,33 @@ test_state_dir=""
 cleanup=false
 test_time_limit=3600
 
-export TEST_VERBOSE=false
-export TEST_COMMAND_TRACE=false
-export TEST_CAT_RESULTS_OPTS=""
-export TEST_DIFF_RESULTS=false
+export CTDB_TEST_VERBOSE=false
+export CTDB_TEST_COMMAND_TRACE=false
+export CTDB_TEST_CAT_RESULTS_OPTS=""
+export CTDB_TEST_DIFF_RESULTS=false
 export CTDB_TEST_PRINT_LOGS_ON_ERROR=false
-export TEST_LOCAL_DAEMONS
-[ -n "$TEST_LOCAL_DAEMONS" ] || TEST_LOCAL_DAEMONS=3
-export TEST_SOCKET_WRAPPER_SO_PATH=""
+export CTDB_TEST_LOCAL_DAEMONS=3
+export CTDB_TEST_SWRAP_SO_PATH=""
 
-while getopts "AcCDehHI:LNqS:T:vV:xX?" opt ; do
+while getopts "AcCDehHI:l:LNqS:T:vV:xX?" opt ; do
        case "$opt" in
-       A) TEST_CAT_RESULTS_OPTS="-A" ;;
-       c) TEST_LOCAL_DAEMONS="" ;;
+       A) CTDB_TEST_CAT_RESULTS_OPTS="-A" ;;
+       c) CTDB_TEST_LOCAL_DAEMONS="" ;;
        C) cleanup=true ;;
-       D) TEST_DIFF_RESULTS=true ;;
+       D) CTDB_TEST_DIFF_RESULTS=true ;;
        e) exit_on_fail=true ;;
        H) no_header=true ;;
        I) max_iterations="$OPTARG" ; exit_on_fail=true ; with_summary=false ;;
+       l) CTDB_TEST_LOCAL_DAEMONS="$OPTARG" ;;
        L) CTDB_TEST_PRINT_LOGS_ON_ERROR=true ;;
        N) with_summary=false ;;
        q) quiet=true ;;
-       S) TEST_SOCKET_WRAPPER_SO_PATH="$OPTARG" ;;
+       S) CTDB_TEST_SWRAP_SO_PATH="$OPTARG" ;;
        T) test_time_limit="$OPTARG" ;;
-       v) TEST_VERBOSE=true ;;
+       v) CTDB_TEST_VERBOSE=true ;;
        V) test_state_dir="$OPTARG" ;;
        x) set -x ;;
-       X) TEST_COMMAND_TRACE=true ;;
+       X) CTDB_TEST_COMMAND_TRACE=true ;;
        \?|h) usage ;;
        esac
 done
@@ -76,7 +77,7 @@ shift $((OPTIND - 1))
 case $(basename "$0") in
     *run_cluster_tests*)
        # Running on a cluster...  same as -c
-       TEST_LOCAL_DAEMONS=""
+       CTDB_TEST_LOCAL_DAEMONS=""
        ;;
 esac
 
@@ -128,7 +129,7 @@ ctdb_test_run ()
        start_time=$(date '+%s')
 
        if [ -x "$f" ] ; then
-               timeout "$test_time_limit" "$f" | show_progress
+               timeout "$test_time_limit" "$f" </dev/null | show_progress
                status=$?
        else
                echo "TEST IS NOT EXECUTABLE"
@@ -175,6 +176,13 @@ ctdb_test_run ()
                printf '%-10s %s\n' "$t" "$f" >>"$summary_file"
        fi
 
+       # Skipped tests should not cause failure
+       case "$status" in
+       77)
+               status=0
+               ;;
+       esac
+
        return $status
 }
 
@@ -227,7 +235,7 @@ run_one_test ()
     local test_dir test_suite_dir reldir
     test_dir=$(cd "$CTDB_TEST_DIR" && pwd)
     test_suite_dir=$(cd "$CTDB_TEST_SUITE_DIR" && pwd)
-    reldir="${test_suite_dir#${test_dir}/}"
+    reldir="${test_suite_dir#"${test_dir}"/}"
 
     export CTDB_TEST_TMP_DIR="${test_state_dir}/${reldir}"
     rm -rf "$CTDB_TEST_TMP_DIR"
@@ -252,7 +260,7 @@ run_tests ()
                        # Can't find it?  Check relative to CTDB_TEST_DIR.
                        # Strip off current directory from beginning,
                        # if there, just to make paths more friendly.
-                       f="${CTDB_TEST_DIR#${PWD}/}/${f}"
+                       f="${CTDB_TEST_DIR#"${PWD}"/}/${f}"
                fi
 
                if [ -d "$f" ] ; then
@@ -260,7 +268,7 @@ run_tests ()
 
                        test_dir=$(cd "$CTDB_TEST_DIR" && pwd)
                        dir=$(cd "$f" && pwd)
-                       reldir="${dir#${test_dir}/}"
+                       reldir="${dir#"${test_dir}"/}"
 
                        case "$reldir" in
                        */*/*)
@@ -292,8 +300,8 @@ run_tests ()
                        die "test \"$f\" is not recognised"
                fi
 
-               if $exit_on_fail && [ $status -ne 0 ] ; then
-                       return $status
+               if $exit_on_fail && [ "$status" -ne 0 ] ; then
+                       return "$status"
                fi
        done
 }
@@ -321,7 +329,7 @@ export TEST_SCRIPTS_DIR="${CTDB_TEST_DIR}/scripts"
 
 # If no tests specified then run some defaults
 if [ -z "$1" ] ; then
-       if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
+       if [ -n "$CTDB_TEST_LOCAL_DAEMONS" ] ; then
                set -- UNIT INTEGRATION
        else
                set -- INTEGRATION CLUSTER
@@ -363,7 +371,7 @@ while [ "$max_iterations" -eq 0 ] || [ $iterations -lt "$max_iterations" ] ; do
 done
 
 if $with_summary ; then
-       if [ $status -eq 0 ] || ! $exit_on_fail ; then
+       if [ "$status" -eq 0 ] || ! $exit_on_fail ; then
                echo
                cat "$summary_file"
 
@@ -383,7 +391,7 @@ echo
 do_cleanup
 
 if $no_header || $exit_on_fail ; then
-    exit $status
+    exit "$status"
 elif [ $tests_failed -gt 0 ] ; then
     exit 1
 else