]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
tests/shell: Support testing host binaries
authorPhil Sutter <phil@nwl.cc>
Tue, 19 Feb 2019 19:39:50 +0000 (20:39 +0100)
committerFlorian Westphal <fw@strlen.de>
Fri, 22 Feb 2019 15:54:52 +0000 (16:54 +0100)
Add -H/--host parameter to run the testsuite against host system's
binaries.

While being at it, rewrite parameter parsing:

* Parse all parameters in a loop, this frees any ordering constraints.
* Set extglob option so strict pattern matching for single testcase mode
  can be done via bash globbing.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
iptables/tests/shell/run-tests.sh

index b6eb01c6e0102d97c8c9570fdf8d0e4d063182bb..7bef09f74643d8275a92e947a9b08380e063765c 100755 (executable)
@@ -3,10 +3,6 @@
 #configuration
 TESTDIR="./$(dirname $0)/"
 RETURNCODE_SEPARATOR="_"
-XTABLES_NFT_MULTI="$(dirname $0)/../../xtables-nft-multi"
-XTABLES_LEGACY_MULTI="$(dirname $0)/../../xtables-legacy-multi"
-
-export XTABLES_LIBDIR=${TESTDIR}/../../../extensions
 
 msg_error() {
         echo "E: $1 ..." >&2
@@ -29,20 +25,40 @@ if [ ! -d "$TESTDIR" ] ; then
         msg_error "missing testdir $TESTDIR"
 fi
 
-if [ "$1" == "-v" ] ; then
-        VERBOSE=y
-        shift
-fi
-
-for arg in "$@"; do
-        if grep ^.*${RETURNCODE_SEPARATOR}[0-9]\\+$ <<< $arg >/dev/null ; then
-                SINGLE+=" $arg"
-                VERBOSE=y
-        else
-                msg_error "unknown parameter '$arg'"
-        fi
+# support matching repeated pattern in SINGLE check below
+shopt -s extglob
+
+while [ -n "$1" ]; do
+       case "$1" in
+       -v|--verbose)
+               VERBOSE=y
+               shift
+               ;;
+       -H|--host)
+               HOST=y
+               shift
+               ;;
+       *${RETURNCODE_SEPARATOR}+([0-9]))
+               SINGLE+=" $1"
+               VERBOSE=y
+               shift
+               ;;
+       *)
+               msg_error "unknown parameter '$1'"
+               ;;
+       esac
 done
 
+if [ "$HOST" != "y" ]; then
+       XTABLES_NFT_MULTI="$(dirname $0)/../../xtables-nft-multi"
+       XTABLES_LEGACY_MULTI="$(dirname $0)/../../xtables-legacy-multi"
+
+       export XTABLES_LIBDIR=${TESTDIR}/../../../extensions
+else
+       XTABLES_NFT_MULTI="xtables-nft-multi"
+       XTABLES_LEGACY_MULTI="xtables-legacy-multi"
+fi
+
 find_tests() {
         if [ ! -z "$SINGLE" ] ; then
                 echo $SINGLE