]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test/run-integration-tests.sh: adjust arg processing
authorDan Streetman <ddstreet@canonical.com>
Wed, 18 Nov 2020 12:30:11 +0000 (07:30 -0500)
committerDan Streetman <ddstreet@canonical.com>
Tue, 26 Jan 2021 22:36:53 +0000 (17:36 -0500)
The script currently parses either 'clean' or 'clean-again' as wanting
to clean both before and after running tests. This fixes that to split
the action up; clean runs before tests, clean-again after; and also
verifies the parameter(s) before passing them to make.

test/run-integration-tests.sh

index 34fa4f56a207ea21f3acb6914140c07195fddd2a..036c075eefc214ad5ad60ff6990eb0d4d64a527f 100755 (executable)
@@ -11,12 +11,36 @@ else
 fi
 
 if [ $# -gt 0 ]; then
-    args="$@"
+    args="$*"
 else
     args="setup run clean-again"
 fi
-args_no_clean=$(sed -r 's/\bclean.*\b//g' <<<$args)
-do_clean=$( [ "$args" = "$args_no_clean" ]; echo $? )
+
+VALID_TARGETS="all setup run clean clean-again"
+
+is_valid_target() {
+    for target in $VALID_TARGETS; do
+        [ "$1" = "$target" ] && return 0
+    done
+    return 1
+}
+
+# reject invalid make targets in $args
+for arg in $args; do
+    if ! is_valid_target "$arg"; then
+        echo "Invalid target: $arg" >&2
+        exit 1
+    fi
+done
+
+CLEAN=0
+CLEANAGAIN=0
+
+# separate 'clean' and 'clean-again' operations
+[[ "$args" =~ "clean-again" ]] && CLEANAGAIN=1
+args=${args/clean-again}
+[[ "$args" =~ "clean" ]] && CLEAN=1
+args=${args/clean}
 
 declare -A results
 declare -A times
@@ -26,16 +50,6 @@ FAILURES=0
 
 cd "$(dirname "$0")"
 
-# Let's always do the cleaning operation first, because it destroys the image
-# cache.
-if [ $do_clean = 1 ]; then
-    for TEST in TEST-??-* ; do
-        ( set -x ; make -C "$TEST" clean )
-    done
-
-    [ -n "$args_no_clean" ] || exit 0
-fi
-
 pass_deny_list() {
     for marker in $DENY_LIST_MARKERS $BLACKLIST_MARKERS; do
         if [ -f "$1/$marker" ]; then
@@ -46,26 +60,38 @@ pass_deny_list() {
     return 0
 }
 
-for TEST in TEST-??-* ; do
-    COUNT=$(($COUNT+1))
+# Let's always do the cleaning operation first, because it destroys the image
+# cache.
+if [ $CLEAN = 1 ]; then
+    for TEST in TEST-??-* ; do
+        ( set -x ; make -C "$TEST" clean )
+    done
+fi
 
-    pass_deny_list $TEST || continue
-    start=$(date +%s)
+# Run actual tests (if requested)
+if [[ $args =~ [a-z] ]]; then
+    for TEST in TEST-??-* ; do
+        COUNT=$(($COUNT+1))
 
-    echo -e "\n--x-- Running $TEST --x--"
-    set +e
-    ( set -x ; make -C "$TEST" $args_no_clean )
-    RESULT=$?
-    set -e
-    echo "--x-- Result of $TEST: $RESULT --x--"
+        pass_deny_list $TEST || continue
+        start=$(date +%s)
 
-    results["$TEST"]="$RESULT"
-    times["$TEST"]=$(( $(date +%s) - $start ))
+        echo -e "\n--x-- Running $TEST --x--"
+        set +e
+        ( set -x ; make -C "$TEST" $args )
+        RESULT=$?
+        set -e
+        echo "--x-- Result of $TEST: $RESULT --x--"
 
-    [ "$RESULT" -ne "0" ] && FAILURES=$(($FAILURES+1))
-done
+        results["$TEST"]="$RESULT"
+        times["$TEST"]=$(( $(date +%s) - $start ))
+
+        [ "$RESULT" -ne "0" ] && FAILURES=$(($FAILURES+1))
+    done
+fi
 
-if [ $FAILURES -eq 0 -a $do_clean = 1 ]; then
+# Run clean-again, if requested, and if no tests failed
+if [ $FAILURES -eq 0 -a $CLEANAGAIN = 1 ]; then
     for TEST in ${!results[@]}; do
         ( set -x ; make -C "$TEST" clean-again )
     done