[Libguestfs] [libnbd PATCH 17/20] ci: Add support for test skipping

Martin Kletzander mkletzan at redhat.com
Tue Jun 8 07:53:58 UTC 2021


Some tests cannot be ran successfully and/or cannot properly probe for all their
dependency configurations.  This allows for skipping of individual test cases
based on the OS and its version.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 ci/build_script.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/ci/build_script.sh b/ci/build_script.sh
index cecbbba0bbc0..36bd51eb8522 100755
--- a/ci/build_script.sh
+++ b/ci/build_script.sh
@@ -32,7 +32,65 @@ main() {
         return 0
     fi
 
-    $MAKE check
+    # Add a way to run all the tests, even the skipped ones, with an environment
+    # variable, so that it can be set fora branch or fork in GitLab.
+    if test "$SKIPPED_TESTS" != "force"
+    then
+        # Skip tests from ci/skipped_tests if this is the right OS version
+        # The file
+        local os_id
+        os_id="$(sh -c '. /etc/os-release; echo "${NAME}-${VERSION_ID}"')"
+
+        echo OS ID: $os_id
+
+        # Skips comments and empty lines
+        grep '^[^#]' ci/skipped_tests | while read skipper
+        do
+            local regex="${skipper%%;*}"
+            local tests="${skipper#*;}"
+
+            echo SKIPPER: "$skipper"
+            echo REGEX: "$regex"
+            echo TESTS: "$tests"
+
+            # Ignore lines not meant for current $os_id
+            if ! echo "$os_id" | grep -q "$regex"; then echo NOPE; continue; fi
+
+            echo SKIPPING $tests
+
+            for test_case in $tests
+            do
+                local test_case_bckup="${test_case}_skipped_test"
+                if ! git ls-files "$test_case" | grep -q "$test_case"
+                then
+                    make -C "$(dirname "$test_case")" "$(basename "$test_case")" 2>/dev/null || :
+                fi
+                echo Backing up "$test_case" to "${test_case_bckup}"
+                cp "$test_case" "${test_case_bckup}"
+
+                echo 'echo "Test skipped based on ci/skipped_tests file"'> "$test_case"
+                echo 'exit 77'>> "$test_case"
+                chmod +x "$test_case"
+            done
+        done
+    fi
+
+    # We do not want the check to cause complete failure as we need to clean up
+    # the skipped test cases
+    local failed=0
+    $MAKE check || failed=1
+
+    find . -name '*_skipped_test' -print | while read test_case_bckup
+    do
+        local test_case="${test_case_bckup%_skipped_test}"
+
+        echo Moving "${test_case_bckup}" back to "${test_case}"
+        rm -f "${test_case}"
+        mv -f "${test_case_bckup}" "${test_case}"
+    done
+
+    # Now it is safe to fail
+    test "$failed" -eq 0
 
     if test "$CHECK_VALGRIND" = "force"
     then
-- 
2.31.1




More information about the Libguestfs mailing list