[PATCH ipset 6/7] tests: make setlist_resize.sh more verbose on error

Florian Westphal <[email protected]>
Newsgroups gmane.comp.security.firewalls.netfilter.devel
Message-ID <[email protected]>
Instead of just existing, tell where we failed.
Use -x and take advantage of $IPSET_TMP to capture the
full output.

On success, remove the file.
cleanup handler will dump the content in case we failed somewhere.

Signed-off-by: Florian Westphal <[email protected]>
---
 tests/setlist_resize.sh | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/tests/setlist_resize.sh b/tests/setlist_resize.sh
index db347ca06517..393048adac38 100755
--- a/tests/setlist_resize.sh
+++ b/tests/setlist_resize.sh
@@ -1,22 +1,41 @@
 #!/bin/sh
 
 set -e
-# set -x
-# exec > setlist.res
-# exec 2>&1
+
+cleanup() {
+	exec 1>&3
+	exec 2>&4
+	if [ -r "$IPSET_TMP/setlist.res" ]; then
+		cat "$IPSET_TMP/setlist.res"
+		rm -f "$IPSET_TMP/setlist.res"
+	fi
+}
+trap cleanup EXIT
+
+exec 3>&1
+exec 4>&2
+exec > "$IPSET_TMP/setlist.res" 2>&1
+
+set -x
 
 ipset=${IPSET_BIN:-../src/ipset}
 
 loop=8
 
+fail() {
+	echo "FAILED: $0 $@"
+	exit 1
+}
+
 n=0
 while [ $n -le 9 ]; do
     egrep '^(ip_set_|xt_set)' /proc/modules | while read x y; do
-    	rmmod $x >/dev/null 2>&1
+    	rmmod $x || :
     done
     if [ "`egrep '^(ip_set_|xt_set)' /proc/modules`" ]; then
     	sleep 1s
     else
+    	echo "Modules unloaded after $n attempts."
     	n=10
     fi
 done
@@ -35,7 +54,7 @@ for x in `seq 1 $loop`; do
     create 1 &
     create 2 &
     wait
-    test `$ipset l -n | wc -l` -eq 1024 || exit 1
+    test `$ipset l -n | wc -l` -eq 1024 || fail "expected 1024 sets"
     $ipset x
     # Wait for destroy to be finished and reference counts releases
     n=0
@@ -53,7 +72,10 @@ for x in `seq 1 $loop`; do
     	lsmod
     	echo $ref
     fi
-    test "$ref" -eq 0 || exit 1
+    test "$ref" -eq 0 || fail "ref was $ref"
     rmmod ip_set_hash_ip >/dev/null 2>&1
     rmmod ip_set >/dev/null 2>&1
 done
+
+rm -f "$IPSET_TMP/setlist.res"
+cleanup
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.