diff options
author | Florian Westphal <fw@strlen.de> | 2024-10-22 15:26:54 +0200 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2024-10-29 21:14:51 +0100 |
commit | 3c469ce4db19775a970064879a36daebde5ae668 (patch) | |
tree | 49d4754aafa47658a330dac404395a543de3a70e /tests/shell/testcases | |
parent | 68d2de3ca6c6eb18f5b32f7b4324a85c9c6c358e (diff) |
tests: shell: don't rely on writable test directory
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>
Diffstat (limited to 'tests/shell/testcases')
-rwxr-xr-x | tests/shell/testcases/include/0002relative_0 | 18 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0013input_descriptors_included_files_0 | 30 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0020include_chain_0 | 6 |
3 files changed, 23 insertions, 31 deletions
diff --git a/tests/shell/testcases/include/0002relative_0 b/tests/shell/testcases/include/0002relative_0 index a91cd8f0..dbf11e7d 100755 --- a/tests/shell/testcases/include/0002relative_0 +++ b/tests/shell/testcases/include/0002relative_0 @@ -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\"" diff --git a/tests/shell/testcases/include/0013input_descriptors_included_files_0 b/tests/shell/testcases/include/0013input_descriptors_included_files_0 index 03de50b3..af374d66 100755 --- a/tests/shell/testcases/include/0013input_descriptors_included_files_0 +++ b/tests/shell/testcases/include/0013input_descriptors_included_files_0 @@ -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 diff --git a/tests/shell/testcases/include/0020include_chain_0 b/tests/shell/testcases/include/0020include_chain_0 index 49b6f76c..1501d719 100755 --- a/tests/shell/testcases/include/0020include_chain_0 +++ b/tests/shell/testcases/include/0020include_chain_0 @@ -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 |