Blame SOURCES/0012-tests-shell-Fix-skip-checks-with-host-mode.patch

576484
From bbd2dd9ee6db7d11ab5b2b10a63b3dfd8b8acc9d Mon Sep 17 00:00:00 2001
576484
From: Phil Sutter <phil@nwl.cc>
576484
Date: Wed, 12 Feb 2020 21:26:06 +0100
576484
Subject: [PATCH] tests: shell: Fix skip checks with --host mode
576484
576484
When testing host binaries, XT_MULTI variable contains just the program
576484
name without path component which most skip checks didn't expect. Fix
576484
them, and while being at it also reduce indenting level in two scripts
576484
by moving the skip check up front with an early exit call.
576484
576484
Fixes: 416898e335322 ("tests/shell: Support testing host binaries")
576484
Signed-off-by: Phil Sutter <phil@nwl.cc>
576484
(cherry picked from commit 2b2b7948c1960ba4680677664ff58477be869de6)
576484
Signed-off-by: Phil Sutter <psutter@redhat.com>
576484
---
576484
 .../arptables/0001-arptables-save-restore_0   |   2 +-
576484
 .../0002-arptables-restore-defaults_0         |   2 +-
576484
 .../arptables/0003-arptables-verbose-output_0 |   2 +-
576484
 .../testcases/ebtables/0001-ebtables-basic_0  | 135 +++++++++---------
576484
 .../ebtables/0002-ebtables-save-restore_0     |   2 +-
576484
 .../ebtables/0003-ebtables-restore-defaults_0 |   2 +-
576484
 .../testcases/ebtables/0004-save-counters_0   |   2 +-
576484
 .../testcases/ebtables/0005-ifnamechecks_0    |   2 +-
576484
 .../firewalld-restore/0001-firewalld_0        |   2 +-
576484
 .../testcases/ipt-restore/0004-restore-race_0 |   2 +-
576484
 .../shell/testcases/nft-only/0001compat_0     |  15 +-
576484
 .../shell/testcases/nft-only/0002invflags_0   |   2 +-
576484
 .../nft-only/0003delete-with-comment_0        |   2 +-
576484
 13 files changed, 88 insertions(+), 84 deletions(-)
576484
576484
diff --git a/iptables/tests/shell/testcases/arptables/0001-arptables-save-restore_0 b/iptables/tests/shell/testcases/arptables/0001-arptables-save-restore_0
576484
index bf04dc0a3e15a..e64e9142ee98b 100755
576484
--- a/iptables/tests/shell/testcases/arptables/0001-arptables-save-restore_0
576484
+++ b/iptables/tests/shell/testcases/arptables/0001-arptables-save-restore_0
576484
@@ -4,7 +4,7 @@ set -e
576484
 #set -x
576484
 
576484
 # there is no legacy backend to test
576484
-[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
 
576484
 # fill arptables manually
576484
 
576484
diff --git a/iptables/tests/shell/testcases/arptables/0002-arptables-restore-defaults_0 b/iptables/tests/shell/testcases/arptables/0002-arptables-restore-defaults_0
576484
index 38d387f327ebb..afd0fcb460d85 100755
576484
--- a/iptables/tests/shell/testcases/arptables/0002-arptables-restore-defaults_0
576484
+++ b/iptables/tests/shell/testcases/arptables/0002-arptables-restore-defaults_0
576484
@@ -3,7 +3,7 @@
576484
 set -e
576484
 
576484
 # there is no legacy backend to test
576484
-[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
 
576484
 # arptables-restore reuses preloaded targets and matches, make sure defaults
576484
 # apply to consecutive rules using the same target/match as a previous one
576484
diff --git a/iptables/tests/shell/testcases/arptables/0003-arptables-verbose-output_0 b/iptables/tests/shell/testcases/arptables/0003-arptables-verbose-output_0
576484
index 10c5ec33ada2c..952cfa7898371 100755
576484
--- a/iptables/tests/shell/testcases/arptables/0003-arptables-verbose-output_0
576484
+++ b/iptables/tests/shell/testcases/arptables/0003-arptables-verbose-output_0
576484
@@ -4,7 +4,7 @@ set -e
576484
 set -x
576484
 
576484
 # there is no legacy backend to test
576484
-[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
 
576484
 $XT_MULTI arptables -N foo
576484
 
576484
diff --git a/iptables/tests/shell/testcases/ebtables/0001-ebtables-basic_0 b/iptables/tests/shell/testcases/ebtables/0001-ebtables-basic_0
576484
index c7f24a383f698..0c1eb4ca66f52 100755
576484
--- a/iptables/tests/shell/testcases/ebtables/0001-ebtables-basic_0
576484
+++ b/iptables/tests/shell/testcases/ebtables/0001-ebtables-basic_0
576484
@@ -1,86 +1,89 @@
576484
 #!/bin/sh
576484
 
576484
+case "$XT_MULTI" in
576484
+*xtables-nft-multi)
576484
+	;;
576484
+*)
576484
+	echo "skip $XT_MULTI"
576484
+	exit 0
576484
+	;;
576484
+esac
576484
+
576484
 get_entries_count() { # (chain)
576484
 	$XT_MULTI ebtables -L $1 | sed -n 's/.*entries: \([0-9]*\).*/\1/p'
576484
 }
576484
 
576484
 set -x
576484
-case "$XT_MULTI" in
576484
-*/xtables-nft-multi)
576484
-	for t in filter nat;do
576484
-		$XT_MULTI ebtables -t $t -L || exit 1
576484
-		$XT_MULTI ebtables -t $t -X || exit 1
576484
-		$XT_MULTI ebtables -t $t -F || exit 1
576484
-	done
576484
-
576484
-	for t in broute foobar ;do
576484
-		$XT_MULTI ebtables -t $t -L &&
576484
-		$XT_MULTI ebtables -t $t -X &&
576484
-		$XT_MULTI ebtables -t $t -F
576484
-		if [ $? -eq 0 ]; then
576484
-			echo "Expect nonzero return for unsupported table"
576484
-			exit 1
576484
-		fi
576484
-	done
576484
 
576484
+for t in filter nat;do
576484
+	$XT_MULTI ebtables -t $t -L || exit 1
576484
+	$XT_MULTI ebtables -t $t -X || exit 1
576484
+	$XT_MULTI ebtables -t $t -F || exit 1
576484
+done
576484
 
576484
-	$XT_MULTI ebtables -t filter -N FOO || exit 1
576484
-	$XT_MULTI ebtables -t filter -N FOO
576484
+for t in broute foobar ;do
576484
+	$XT_MULTI ebtables -t $t -L &&
576484
+	$XT_MULTI ebtables -t $t -X &&
576484
+	$XT_MULTI ebtables -t $t -F
576484
 	if [ $? -eq 0 ]; then
576484
-		echo "Duplicate chain FOO"
576484
-		$XT_MULTI ebtables -t filter -L
576484
+		echo "Expect nonzero return for unsupported table"
576484
 		exit 1
576484
 	fi
576484
+done
576484
 
576484
-	entries=$(get_entries_count FOO)
576484
-	if [ $entries -ne 0 ]; then
576484
-		echo "Unexpected entries count in empty unreferenced chain (expected 0, have $entries)"
576484
-		$XT_MULTI ebtables -L
576484
-		exit 1
576484
-	fi
576484
 
576484
-	$XT_MULTI ebtables -A FORWARD -j FOO
576484
-	entries=$(get_entries_count FORWARD)
576484
-	if [ $entries -ne 1 ]; then
576484
-		echo "Unexpected entries count in FORWARD chain (expected 1, have $entries)"
576484
-		$XT_MULTI ebtables -L
576484
-		exit 1
576484
-	fi
576484
+$XT_MULTI ebtables -t filter -N FOO || exit 1
576484
+$XT_MULTI ebtables -t filter -N FOO
576484
+if [ $? -eq 0 ]; then
576484
+	echo "Duplicate chain FOO"
576484
+	$XT_MULTI ebtables -t filter -L
576484
+	exit 1
576484
+fi
576484
 
576484
-	entries=$(get_entries_count FOO)
576484
-	if [ $entries -ne 0 ]; then
576484
-		echo "Unexpected entries count in empty referenced chain (expected 0, have $entries)"
576484
-		$XT_MULTI ebtables -L
576484
-		exit 1
576484
-	fi
576484
+entries=$(get_entries_count FOO)
576484
+if [ $entries -ne 0 ]; then
576484
+	echo "Unexpected entries count in empty unreferenced chain (expected 0, have $entries)"
576484
+	$XT_MULTI ebtables -L
576484
+	exit 1
576484
+fi
576484
 
576484
-	$XT_MULTI ebtables -A FOO -j ACCEPT
576484
-	entries=$(get_entries_count FOO)
576484
-	if [ $entries -ne 1 ]; then
576484
-		echo "Unexpected entries count in non-empty referenced chain (expected 1, have $entries)"
576484
-		$XT_MULTI ebtables -L
576484
-		exit 1
576484
-	fi
576484
+$XT_MULTI ebtables -A FORWARD -j FOO
576484
+entries=$(get_entries_count FORWARD)
576484
+if [ $entries -ne 1 ]; then
576484
+	echo "Unexpected entries count in FORWARD chain (expected 1, have $entries)"
576484
+	$XT_MULTI ebtables -L
576484
+	exit 1
576484
+fi
576484
 
576484
-	$XT_MULTI ebtables -t filter -N BAR || exit 1
576484
-	$XT_MULTI ebtables -t filter -N BAZ || exit 1
576484
+entries=$(get_entries_count FOO)
576484
+if [ $entries -ne 0 ]; then
576484
+	echo "Unexpected entries count in empty referenced chain (expected 0, have $entries)"
576484
+	$XT_MULTI ebtables -L
576484
+	exit 1
576484
+fi
576484
 
576484
-	$XT_MULTI ebtables -t filter -L | grep -q FOO || exit 1
576484
-	$XT_MULTI ebtables -t filter -L | grep -q BAR || exit 1
576484
-	$XT_MULTI ebtables -t filter -L | grep -q BAZ || exit 1
576484
+$XT_MULTI ebtables -A FOO -j ACCEPT
576484
+entries=$(get_entries_count FOO)
576484
+if [ $entries -ne 1 ]; then
576484
+	echo "Unexpected entries count in non-empty referenced chain (expected 1, have $entries)"
576484
+	$XT_MULTI ebtables -L
576484
+	exit 1
576484
+fi
576484
 
576484
-	$XT_MULTI ebtables -t filter -L BAZ || exit 1
576484
-	$XT_MULTI ebtables -t filter -X BAZ || exit 1
576484
-	$XT_MULTI ebtables -t filter -L BAZ | grep -q BAZ
576484
-	if [ $? -eq 0 ]; then
576484
-		echo "Deleted chain -L BAZ ok, expected failure"
576484
-		$XT_MULTI ebtables -t filter -L
576484
-		exit 1
576484
-	fi
576484
+$XT_MULTI ebtables -t filter -N BAR || exit 1
576484
+$XT_MULTI ebtables -t filter -N BAZ || exit 1
576484
 
576484
-	$XT_MULTI ebtables -t $t -F || exit 0
576484
-	;;
576484
-*)
576484
-	echo "skip $XT_MULTI"
576484
-	;;
576484
-esac
576484
+$XT_MULTI ebtables -t filter -L | grep -q FOO || exit 1
576484
+$XT_MULTI ebtables -t filter -L | grep -q BAR || exit 1
576484
+$XT_MULTI ebtables -t filter -L | grep -q BAZ || exit 1
576484
+
576484
+$XT_MULTI ebtables -t filter -L BAZ || exit 1
576484
+$XT_MULTI ebtables -t filter -X BAZ || exit 1
576484
+$XT_MULTI ebtables -t filter -L BAZ | grep -q BAZ
576484
+if [ $? -eq 0 ]; then
576484
+	echo "Deleted chain -L BAZ ok, expected failure"
576484
+	$XT_MULTI ebtables -t filter -L
576484
+	exit 1
576484
+fi
576484
+
576484
+$XT_MULTI ebtables -t $t -F || exit 0
576484
diff --git a/iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0 b/iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0
576484
index e18d46551509d..b84f63a7c3672 100755
576484
--- a/iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0
576484
+++ b/iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0
576484
@@ -4,7 +4,7 @@ set -e
576484
 #set -x
576484
 
576484
 # there is no legacy backend to test
576484
-[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
 
576484
 # fill ebtables manually
576484
 
576484
diff --git a/iptables/tests/shell/testcases/ebtables/0003-ebtables-restore-defaults_0 b/iptables/tests/shell/testcases/ebtables/0003-ebtables-restore-defaults_0
576484
index 62d224134456b..63891c1bb731a 100755
576484
--- a/iptables/tests/shell/testcases/ebtables/0003-ebtables-restore-defaults_0
576484
+++ b/iptables/tests/shell/testcases/ebtables/0003-ebtables-restore-defaults_0
576484
@@ -3,7 +3,7 @@
576484
 set -e
576484
 
576484
 # there is no legacy backend to test
576484
-[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
 
576484
 # ebtables-restore reuses preloaded targets and matches, make sure defaults
576484
 # apply to consecutive rules using the same target/match as a previous one
576484
diff --git a/iptables/tests/shell/testcases/ebtables/0004-save-counters_0 b/iptables/tests/shell/testcases/ebtables/0004-save-counters_0
576484
index 46966f433139a..d52db900604ef 100755
576484
--- a/iptables/tests/shell/testcases/ebtables/0004-save-counters_0
576484
+++ b/iptables/tests/shell/testcases/ebtables/0004-save-counters_0
576484
@@ -3,7 +3,7 @@
576484
 set -e
576484
 
576484
 # there is no legacy backend to test
576484
-[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
 
576484
 $XT_MULTI ebtables --init-table
576484
 $XT_MULTI ebtables -A FORWARD -i nodev123 -o nodev432 -j ACCEPT
576484
diff --git a/iptables/tests/shell/testcases/ebtables/0005-ifnamechecks_0 b/iptables/tests/shell/testcases/ebtables/0005-ifnamechecks_0
576484
index 2163d364b318b..0b3acfd7613db 100755
576484
--- a/iptables/tests/shell/testcases/ebtables/0005-ifnamechecks_0
576484
+++ b/iptables/tests/shell/testcases/ebtables/0005-ifnamechecks_0
576484
@@ -3,7 +3,7 @@
576484
 set -e
576484
 
576484
 # there is no legacy backend to test
576484
-[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
 
576484
 EXPECT='*filter
576484
 :INPUT ACCEPT
576484
diff --git a/iptables/tests/shell/testcases/firewalld-restore/0001-firewalld_0 b/iptables/tests/shell/testcases/firewalld-restore/0001-firewalld_0
576484
index 8bf0c2c6c194e..0174b03f4ebc7 100755
576484
--- a/iptables/tests/shell/testcases/firewalld-restore/0001-firewalld_0
576484
+++ b/iptables/tests/shell/testcases/firewalld-restore/0001-firewalld_0
576484
@@ -231,7 +231,7 @@ for table in nat mangle raw filter;do
576484
 done
576484
 
576484
 case "$XT_MULTI" in
576484
-*/xtables-nft-multi)
576484
+*xtables-nft-multi)
576484
 	# nft-multi displays chain names in different order, work around this for now
576484
 	tmpfile2=$(mktemp)
576484
 	sort "$tmpfile" > "$tmpfile2"
576484
diff --git a/iptables/tests/shell/testcases/ipt-restore/0004-restore-race_0 b/iptables/tests/shell/testcases/ipt-restore/0004-restore-race_0
576484
index 96a5e66d0ab81..9fc50615b8926 100755
576484
--- a/iptables/tests/shell/testcases/ipt-restore/0004-restore-race_0
576484
+++ b/iptables/tests/shell/testcases/ipt-restore/0004-restore-race_0
576484
@@ -86,7 +86,7 @@ if [ $LINES1 -ne $LINES2 ]; then
576484
 fi
576484
 
576484
 case "$XT_MULTI" in
576484
-*/xtables-nft-multi)
576484
+*xtables-nft-multi)
576484
 	attempts=$((RANDOM%10))
576484
 	attempts=$((attempts+1))
576484
 	;;
576484
diff --git a/iptables/tests/shell/testcases/nft-only/0001compat_0 b/iptables/tests/shell/testcases/nft-only/0001compat_0
576484
index 4319ea5a6a797..a617c52f53695 100755
576484
--- a/iptables/tests/shell/testcases/nft-only/0001compat_0
576484
+++ b/iptables/tests/shell/testcases/nft-only/0001compat_0
576484
@@ -5,17 +5,18 @@
576484
 # xtables: avoid bogus 'is incompatible' warning
576484
 
576484
 case "$XT_MULTI" in
576484
-*/xtables-nft-multi)
576484
-	nft -v >/dev/null || exit 0
576484
-	nft 'add table ip nft-test; add chain ip nft-test foobar { type filter hook forward priority 42;  }' || exit 1
576484
-	nft 'add table ip6 nft-test; add chain ip6 nft-test foobar { type filter hook forward priority 42;  }' || exit 1
576484
-
576484
-	$XT_MULTI iptables -L -t filter || exit 1
576484
-	$XT_MULTI ip6tables -L -t filter || exit 1
576484
+*xtables-nft-multi)
576484
 	;;
576484
 *)
576484
 	echo skip $XT_MULTI
576484
+	exit 0
576484
 	;;
576484
 esac
576484
 
576484
+nft -v >/dev/null || exit 0
576484
+nft 'add table ip nft-test; add chain ip nft-test foobar { type filter hook forward priority 42;  }' || exit 1
576484
+nft 'add table ip6 nft-test; add chain ip6 nft-test foobar { type filter hook forward priority 42;  }' || exit 1
576484
+
576484
+$XT_MULTI iptables -L -t filter || exit 1
576484
+$XT_MULTI ip6tables -L -t filter || exit 1
576484
 exit 0
576484
diff --git a/iptables/tests/shell/testcases/nft-only/0002invflags_0 b/iptables/tests/shell/testcases/nft-only/0002invflags_0
576484
index 406b6081a98a4..fe33874dde7f2 100755
576484
--- a/iptables/tests/shell/testcases/nft-only/0002invflags_0
576484
+++ b/iptables/tests/shell/testcases/nft-only/0002invflags_0
576484
@@ -2,7 +2,7 @@
576484
 
576484
 set -e
576484
 
576484
-[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
 
576484
 $XT_MULTI iptables -A INPUT -p tcp --dport 53 ! -s 192.168.0.1 -j ACCEPT
576484
 $XT_MULTI ip6tables -A INPUT -p tcp --dport 53 ! -s feed:babe::1 -j ACCEPT
576484
diff --git a/iptables/tests/shell/testcases/nft-only/0003delete-with-comment_0 b/iptables/tests/shell/testcases/nft-only/0003delete-with-comment_0
576484
index 67af9fd897410..ccb009e469076 100755
576484
--- a/iptables/tests/shell/testcases/nft-only/0003delete-with-comment_0
576484
+++ b/iptables/tests/shell/testcases/nft-only/0003delete-with-comment_0
576484
@@ -2,7 +2,7 @@
576484
 
576484
 set -e
576484
 
576484
-[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
576484
 
576484
 comment1="foo bar"
576484
 comment2="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
576484
-- 
576484
2.24.1
576484