]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests/shell: add "--quick" option to skip slow tests (via NFT_TEST_SKIP_slow=y)
authorThomas Haller <thaller@redhat.com>
Fri, 8 Sep 2023 15:07:25 +0000 (17:07 +0200)
committerFlorian Westphal <fw@strlen.de>
Sat, 9 Sep 2023 14:54:44 +0000 (16:54 +0200)
It's important to run (a part) of the tests in a timely manner.
Add an option to skip long running tests.

Thereby, add a more general NFT_TEST_SKIP_* mechanism.

This is related and inverse from "NFT_TEST_HAVE_json", where a test
can require [ "$NFT_TEST_HAVE_json" != n ] to run, but is skipped when
[ "$NFT_TEST_SKIP_slow" = y ].

Currently only NFT_TEST_SKIP_slow is supported. The user can set such
environment variables (or use the -Q|--quick command line option). The
configuration is printed in the test info.

Tests should check for [ "$NFT_TEST_SKIP_slow" = y ] so that the
variable has to be explicitly set to opt-out. For convenience, tests can
also add a

    # NFT_TEST_SKIP(NFT_TEST_SKIP_slow)

tag, which is evaluated by test-wrapper.sh. Or they can run a quick, reduced
part of the test, but then should still indicate to be skipped.

Mark 8 tests are as slow, that take longer than 5 seconds on my machine.
With this, a parallel wall time for the non-slow tests is only 7 seconds
(on my machine).

The ultimate point is to integrate a call to "tests/shell/run-tests.sh"
in a `make check` target. For development, you can then export
NFT_TEST_SKIP_slow=y and have a fast `make check`.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
tests/shell/helpers/test-wrapper.sh
tests/shell/run-tests.sh
tests/shell/testcases/maps/0004interval_map_create_once_0
tests/shell/testcases/maps/0018map_leak_timeout_0
tests/shell/testcases/maps/vmap_timeout
tests/shell/testcases/sets/0043concatenated_ranges_0
tests/shell/testcases/sets/0044interval_overlap_0
tests/shell/testcases/sets/0044interval_overlap_1
tests/shell/testcases/sets/automerge_0
tests/shell/testcases/transactions/30s-stress

index ffd0fb3ffb4bf2ca038661dbd2c351eaaba58cc6..cd8f480504adf89ec46f804005f54dc28aa36074 100755 (executable)
@@ -54,23 +54,39 @@ TEST_TAGS_PARSED=0
 ensure_TEST_TAGS() {
        if [ "$TEST_TAGS_PARSED" = 0 ] ; then
                TEST_TAGS_PARSED=1
-               TEST_TAGS=( $(sed -n '1,10 { s/^.*\<\(NFT_TEST_REQUIRES\)\>\s*(\s*\(NFT_TEST_HAVE_[a-zA-Z0-9_]\+\)\s*).*$/\1(\2)/p }' "$1" 2>/dev/null || : ) )
+               TEST_TAGS=( $(sed -n '1,10 { s/^.*\<\(NFT_TEST_REQUIRES\|NFT_TEST_SKIP\)\>\s*(\s*\(NFT_TEST_SKIP_[a-zA-Z0-9_]\+\|NFT_TEST_HAVE_[a-zA-Z0-9_]\+\)\s*).*$/\1(\2)/p }' "$1" 2>/dev/null || : ) )
        fi
 }
 
 rc_test=0
 
-for KEY in $(compgen -v | grep '^NFT_TEST_HAVE_') ; do
-       if [ "${!KEY}" != n ]; then
-               continue
-       fi
-       ensure_TEST_TAGS "$TEST"
-       if array_contains "NFT_TEST_REQUIRES($KEY)" "${TEST_TAGS[@]}" ; then
-               echo "Test skipped due to $KEY=n (test has \"NFT_TEST_REQUIRES($KEY)\" tag)" >> "$NFT_TEST_TESTTMPDIR/testout.log"
-               rc_test=77
-               break
-       fi
-done
+if [ "$rc_test" -eq 0 ] ; then
+       for KEY in $(compgen -v | grep '^NFT_TEST_HAVE_') ; do
+               if [ "${!KEY}" != n ]; then
+                       continue
+               fi
+               ensure_TEST_TAGS "$TEST"
+               if array_contains "NFT_TEST_REQUIRES($KEY)" "${TEST_TAGS[@]}" ; then
+                       echo "Test skipped due to $KEY=n (test has \"NFT_TEST_REQUIRES($KEY)\" tag)" >> "$NFT_TEST_TESTTMPDIR/testout.log"
+                       rc_test=77
+                       break
+               fi
+       done
+fi
+
+if [ "$rc_test" -eq 0 ] ; then
+       for KEY in $(compgen -v | grep '^NFT_TEST_SKIP_') ; do
+               if [ "${!KEY}" != y ]; then
+                       continue
+               fi
+               ensure_TEST_TAGS "$TEST"
+               if array_contains "NFT_TEST_SKIP($KEY)" "${TEST_TAGS[@]}" ; then
+                       echo "Test skipped due to $KEY=y (test has \"NFT_TEST_SKIP($KEY)\" tag)" >> "$NFT_TEST_TESTTMPDIR/testout.log"
+                       rc_test=77
+                       break
+               fi
+       done
+fi
 
 if [ "$rc_test" -eq 0 ] ; then
        "$TEST" &>> "$NFT_TEST_TESTTMPDIR/testout.log" || rc_test=$?
index 51d285e3d9f42f2acb1bbc9e6ac47ca5f94d66ae..f20a2bec9e9b2223fc0881df4c11e8fa79f152a0 100755 (executable)
@@ -118,6 +118,7 @@ usage() {
        echo " -U|--no-unshare : Sets NFT_TEST_UNSHARE_CMD=\"\"."
        echo " -k|--keep-logs  : Sets NFT_TEST_KEEP_LOGS=y."
        echo " -s|--sequential : Sets NFT_TEST_JOBS=0, which also enables global cleanups."
+       echo " -Q|--quick      : Sets NFT_TEST_SKIP_slow=y."
        echo " --              : Separate options from tests."
        echo " [TESTS...]      : Other options are treated as test names,"
        echo "                   that is, executables that are run by the runner."
@@ -174,6 +175,8 @@ usage() {
        echo " NFT_TEST_HAVE_<FEATURE>=*|y: Some tests requires certain features or will be skipped."
        echo "                 The features are autodetected, but you can force it by setting the variable."
        echo "                 Supported <FEATURE>s are: ${_HAVE_OPTS[@]}."
+       echo " NFT_TEST_SKIP_<OPTION>=*|y: if set, certain tests are skipped."
+       echo "                 Supported <OPTION>s are: ${_SKIP_OPTS[@]}."
 }
 
 NFT_TEST_BASEDIR="$(dirname "$0")"
@@ -188,6 +191,13 @@ for KEY in $(compgen -v | grep '^NFT_TEST_HAVE_' | sort) ; do
        fi
 done
 
+_SKIP_OPTS=( slow )
+for KEY in $(compgen -v | grep '^NFT_TEST_SKIP_' | sort) ; do
+       if ! array_contains "${KEY#NFT_TEST_SKIP_}" "${_SKIP_OPTS[@]}" ; then
+               unset "$KEY"
+       fi
+done
+
 _NFT_TEST_JOBS_DEFAULT="$(nproc)"
 [ "$_NFT_TEST_JOBS_DEFAULT" -gt 0 ] 2>/dev/null || _NFT_TEST_JOBS_DEFAULT=1
 _NFT_TEST_JOBS_DEFAULT="$(( _NFT_TEST_JOBS_DEFAULT + (_NFT_TEST_JOBS_DEFAULT + 1) / 2 ))"
@@ -199,6 +209,7 @@ KMEMLEAK="$(bool_y "$KMEMLEAK")"
 NFT_TEST_KEEP_LOGS="$(bool_y "$NFT_TEST_KEEP_LOGS")"
 NFT_TEST_HAS_REALROOT="$NFT_TEST_HAS_REALROOT"
 NFT_TEST_JOBS="${NFT_TEST_JOBS:-$_NFT_TEST_JOBS_DEFAULT}"
+NFT_TEST_SKIP_slow="$(bool_y "$NFT_TEST_SKIP_slow")"
 DO_LIST_TESTS=
 
 TESTS=()
@@ -238,6 +249,9 @@ while [ $# -gt 0 ] ; do
                -s|--sequential)
                        NFT_TEST_JOBS=0
                        ;;
+               -Q|--quick)
+                       NFT_TEST_SKIP_slow=y
+                       ;;
                --)
                        TESTS+=( "$@" )
                        shift $#
@@ -438,6 +452,10 @@ msg_info "conf: NFT_TEST_KEEP_LOGS=$(printf '%q' "$NFT_TEST_KEEP_LOGS")"
 msg_info "conf: NFT_TEST_JOBS=$NFT_TEST_JOBS"
 msg_info "conf: TMPDIR=$(printf '%q' "$_TMPDIR")"
 echo
+for KEY in $(compgen -v | grep '^NFT_TEST_SKIP_' | sort) ; do
+       msg_info "conf: $KEY=$(printf '%q' "${!KEY}")"
+       export "$KEY"
+done
 for KEY in $(compgen -v | grep '^NFT_TEST_HAVE_' | sort) ; do
        msg_info "conf: $KEY=$(printf '%q' "${!KEY}")"
        export "$KEY"
index 3de0c9de4f9347df910ab9475c2b74d70eba732f..64f434ad6b0020c4dd86c58a24f2b67502b80627 100755 (executable)
@@ -5,6 +5,10 @@
 
 HOWMANY=63
 
+if [ "$NFT_TEST_SKIP_slow" = y ] ; then
+       HOWMANY=5
+fi
+
 tmpfile=$(mktemp)
 if [ ! -w $tmpfile ] ; then
        echo "Failed to create tmp file" >&2
@@ -64,3 +68,7 @@ if [ "$EXPECTED" != "$GET" ] ; then
        exit 1
 fi
 
+if [ "$HOWMANY" != 63 ] ; then
+       echo "Run a partial test due to NFT_TEST_SKIP_slow=y. Skip"
+       exit 77
+fi
index 5a07ec7477d9bcacf402a56fd2dda12a02f32636..09db315a885524e596be51d799bc53d819937133 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# NFT_TEST_SKIP(NFT_TEST_SKIP_slow)
+
 set -e
 
 RULESET="table ip t {
index e59d37ab40480c294e864d007ea19defc727e9c8..43d031979cb34cd6ee7067131167041a97a9386f 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# NFT_TEST_SKIP(NFT_TEST_SKIP_slow)
+
 set -e
 
 dumpfile=$(dirname $0)/dumps/$(basename $0).nft
index 90ee6a82dbed939accce39736e1cbbb80a174738..4165b2f5f7114fe4bc513aee85b255de53276bf9 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/sh -e
 #
+# NFT_TEST_SKIP(NFT_TEST_SKIP_slow)
+#
 # 0043concatenated_ranges_0 - Add, get, list, timeout for concatenated ranges
 #
 # Cycle over supported data types, forming concatenations of three fields, for
index face90f2e9ae2ac4aa4aba1bdc9e86720c8a9194..19aa6f5ed081c897bccb2a2e05ee15a64ee4304d 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/sh -e
 #
+# NFT_TEST_SKIP(NFT_TEST_SKIP_slow)
+#
 # 0044interval_overlap_0 - Add overlapping and non-overlapping intervals
 #
 # Check that adding overlapping intervals to a set returns an error, unless:
index eeea1943ee55b0f9bb9a80ad5ee530dfa4b402bc..905e6d5a0348d1d7b57a02c630eef340e8a25b69 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/sh -e
 #
+# NFT_TEST_SKIP(NFT_TEST_SKIP_slow)
+#
 # 0044interval_overlap_1 - Single-sized intervals can never overlap partially
 #
 # Check that inserting, deleting, and inserting single-sized intervals again
index fc34f8865fb3ae1eef9225ae86e5e5f231a6e986..170c38651de0cc95ef49700dbd952b6b4c704510 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# NFT_TEST_SKIP(NFT_TEST_SKIP_slow)
+
 set -e
 
 RULESET="table inet x {
index 757e7639b5e9a35f76306ef75d9cc51e7e8cabd4..4d5d1d8bface0d426178411d6d422250e0bfa950 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# NFT_TEST_SKIP(NFT_TEST_SKIP_slow)
+
 runtime=30
 
 # allow stand-alone execution as well, e.g. '$0 3600'