]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: shell: don't rely on writable test directory
authorFlorian Westphal <fw@strlen.de>
Tue, 22 Oct 2024 13:26:54 +0000 (15:26 +0200)
committerFlorian Westphal <fw@strlen.de>
Tue, 29 Oct 2024 20:14:51 +0000 (21:14 +0100)
Running shell tests from a virtme-ng instance with ro mapped test dir
hangs due to runaway 'awk' reading from stdin instead of the intended
$tmpfile (variable is empty), so add quotes where needed.

0002relative_0 wants to check relative includes. It tries to create a
temporary file in the current directory, which fails as thats readonly
inside the virtme vm instance.

[ -w ! $foo ... did not catch this due to missing "".
Add quotes and return the skip retval so the test gets flagged as skipped.

0013input_descriptors_included_files_0 and 0020include_chain_0 are
switched to normal tmpfiles, there is nothing in the test that needs
relative includes.

Also, get rid of some error tests for subsequent mktemp calls for
scripts that already called 'set -e'.

Signed-off-by: Florian Westphal <fw@strlen.de>
tests/shell/testcases/include/0002relative_0
tests/shell/testcases/include/0013input_descriptors_included_files_0
tests/shell/testcases/include/0020include_chain_0

index a91cd8f00047ff0758acd63d90e398f09b76fee2..dbf11e7db1717207de11f8e2cba5a4b396645de9 100755 (executable)
@@ -1,20 +1,16 @@
 #!/bin/bash
 
-set -e
-
 tmpfile1=$(mktemp -p .)
-if [ ! -w $tmpfile1 ] ; then
-        echo "Failed to create tmp file" >&2
-        exit 0
-fi
-
-tmpfile2=$(mktemp -p .)
-if [ ! -w $tmpfile2 ] ; then
-        echo "Failed to create tmp file" >&2
-        exit 0
+if [ ! -w "$tmpfile1" ] ; then
+       # cwd might be readonly, mark as skip.
+       echo "Failed to create tmp file" >&2
+       exit 77
 fi
 
 trap "rm -rf $tmpfile1 $tmpfile2" EXIT # cleanup if aborted
+set -e
+
+tmpfile2=$(mktemp -p .)
 
 RULESET1="add table x"
 RULESET2="include \"$tmpfile1\""
index 03de50b3c4992bb7308d503856d4e657991176f6..af374d661898689584bf83938d168e5777515a48 100755 (executable)
@@ -7,32 +7,32 @@
 # instead of return value of nft.
 
 
-tmpfile1=$(mktemp -p .)
-if [ ! -w $tmpfile1 ] ; then
+tmpfile1=$(mktemp)
+if [ ! -w "$tmpfile1" ] ; then
         echo "Failed to create tmp file" >&2
-        exit 0
+        exit 1
 fi
 
-tmpfile2=$(mktemp -p .)
-if [ ! -w $tmpfile2 ] ; then
+trap "rm -rf $tmpfile1 $tmpfile2 $tmpfile3 $tmpfile4" EXIT # cleanup if aborted
+
+tmpfile2=$(mktemp)
+if [ ! -w "$tmpfile2" ] ; then
         echo "Failed to create tmp file" >&2
-        exit 0
+        exit 1
 fi
 
-tmpfile3=$(mktemp -p .)
-if [ ! -w $tmpfile3 ] ; then
+tmpfile3=$(mktemp)
+if [ ! -w "$tmpfile3" ] ; then
         echo "Failed to create tmp file" >&2
-        exit 0
+        exit 1
 fi
 
-tmpfile4=$(mktemp -p .)
-if [ ! -w $tmpfile4 ]; then
+tmpfile4=$(mktemp)
+if [ ! -w "$tmpfile4" ]; then
         echo "Failed to create tmp file" >&2
-        exit 0
+        exit 1
 fi
 
-trap "rm -rf $tmpfile1 $tmpfile2 $tmpfile3 $tmpfile4" EXIT # cleanup if aborted
-
 RULESET1="include \"$tmpfile2\""
 RULESET2="include \"$tmpfile3\""
 RULESET3="add rule x y anything everything"                    # wrong nft syntax
@@ -44,7 +44,7 @@ echo "$RULESET3" > $tmpfile2
 
 $NFT -f $tmpfile1 2> $tmpfile4
 
-var=$(awk -F: '$4==" Error"{print $1;exit;}' $tmpfile4)
+var=$(awk -F: '$4==" Error"{print $1;exit;}' "$tmpfile4")
 
 if [ $var == "$tmpfile3" ]; then
        echo "E: Test failed" >&2
index 49b6f76c6a8df84bf1a5c2b758ca5d7c2a7a46e1..1501d7191fbf4c8caec95a29e8483f8647cf4630 100755 (executable)
@@ -2,11 +2,7 @@
 
 set -e
 
-tmpfile1=$(mktemp -p .)
-if [ ! -w $tmpfile1 ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
+tmpfile1=$(mktemp)
 
 trap "rm -rf $tmpfile1" EXIT # cleanup if aborted