diff mbox series

[2/2] iptables: tests: shell: Add testcase and update shell test-suite

Message ID 1530178540-4120-2-git-send-email-arushisinghal19971997@gmail.com
State Changes Requested
Delegated to: Florian Westphal
Headers show
Series [1/2] iptables: tests: shell: Add README | expand

Commit Message

Arushi Singhal June 28, 2018, 9:35 a.m. UTC
Test is added for iptables-restore with no option.
Shell test-suite is updated for new tests.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
---
 iptables/tests/shell/run-tests.sh                  |  8 ++++--
 .../save-restore/0001_restore_no_option_0          | 30 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100755 iptables/tests/shell/testcases/save-restore/0001_restore_no_option_0
diff mbox series

Patch

diff --git a/iptables/tests/shell/run-tests.sh b/iptables/tests/shell/run-tests.sh
index cf5cbdc..2cfa79d 100755
--- a/iptables/tests/shell/run-tests.sh
+++ b/iptables/tests/shell/run-tests.sh
@@ -5,6 +5,7 @@  TESTDIR="./$(dirname $0)/"
 RETURNCODE_SEPARATOR="_"
 XTABLES_MULTI="$(dirname $0)/../../xtables-multi"
 DIFF=$(which diff)
+RETURNCODE_SEPARATOR="_"
 
 msg_error() {
         echo "E: $1 ..." >&2
@@ -96,11 +97,14 @@  do
 
 	for it in iptables ip6tables; do
 		kernel_cleanup
-		rc_spec=`echo $(basename ${testfile}) | cut -d _ -f2-`
+		rc_spec=$(awk -F${RETURNCODE_SEPARATOR} '{print $NF}' <<< $testfile)
+
 		IPTABLES="$XTABLES_MULTI $it"
+		IPTABLES_SAVE="$XTABLES_MULTI "$it"-save"
+		IPTABLES_RESTORE="$XTABLES_MULTI "$it"-restore"
 
 		msg_info "[EXECUTING]   $testfile"
-		test_output=$(IPTABLES=$IPTABLES ${testfile} 2>&1)
+		test_output=$(IPTABLES=$IPTABLES IPTABLES_SAVE=$IPTABLES_SAVE IPTABLES_RESTORE=$IPTABLES_RESTORE ${testfile} 2>&1)
 		rc_got=$?
 		echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line
 
diff --git a/iptables/tests/shell/testcases/save-restore/0001_restore_no_option_0 b/iptables/tests/shell/testcases/save-restore/0001_restore_no_option_0
new file mode 100755
index 0000000..4de285b
--- /dev/null
+++ b/iptables/tests/shell/testcases/save-restore/0001_restore_no_option_0
@@ -0,0 +1,30 @@ 
+#!/bin/bash
+
+set -e
+
+DIFF=$(which diff)
+
+$IPTABLES -N FOO
+$IPTABLES -I INPUT
+$IPTABLES -I FOO
+$IPTABLES -I FOO
+$IPTABLES -L > temp
+$IPTABLES_SAVE > A
+$IPTABLES_RESTORE < A
+$IPTABLES -N BAR
+$IPTABLES -A BAR
+$IPTABLES_RESTORE  < A
+$IPTABLES -L > temp1
+
+if $DIFF temp temp1 >/dev/null ; then
+	rm -f temp
+	rm -f temp1
+	rm -f A
+	exit 0
+else
+	echo "$test_output"
+	rm -f temp
+	rm -f temp1
+	rm -f A
+	exit 1
+fi