summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2020-06-14 23:41:37 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2020-06-15 23:58:27 +0200
commit7c8a44b25c22407329e201ed3c7098166a8d9e75 (patch)
treeab59aad56066ee04ebd3d46fc78f93116ceb6cff
parenta9cadde4add151d74b64f92ebbdc56cdb7a64470 (diff)
tests: shell: Allow wrappers to be passed as nft command
The current check on $NFT only allows to directly pass an executable, so I've been commenting it out locally for a while to run tests with valgrind. Instead of using the -x test, run nft without arguments and check the exit status. POSIX.1-2017, Shell and Utilities volume, par. 2.8.2 ("Exit Status for Commands") states: If a command is not found, the exit status shall be 127. If the command name is found, but it is not an executable utility, the exit status shall be 126. Applications that invoke utilities without using the shell should use these exit status values to report similar errors. While this script isn't POSIX-compliant, it requires bash, and any modern version of bash complies with those exit status requirements. Also valgrind complies with this. We need to quote the NFT variable passed to execute the commands in the main loop and adjust error and informational messages, too. This way, for example, export NFT="valgrind nft" can be issued to run tests with valgrind. Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rwxr-xr-xtests/shell/run-tests.sh10
1 files changed, 6 insertions, 4 deletions
diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index 51c90c9b..943f8877 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -32,10 +32,12 @@ fi
shift
[ -z "$NFT" ] && NFT=$SRC_NFT
-if [ ! -x "$NFT" ] ; then
- msg_error "no nft binary!"
+${NFT} > /dev/null 2>&1
+ret=$?
+if [ ${ret} -eq 126 ] || [ ${ret} -eq 127 ]; then
+ msg_error "cannot execute nft command: ${NFT}"
else
- msg_info "using nft binary $NFT"
+ msg_info "using nft command: ${NFT}"
fi
if [ ! -d "$TESTDIR" ] ; then
@@ -110,7 +112,7 @@ do
kernel_cleanup
msg_info "[EXECUTING] $testfile"
- test_output=$(NFT=$NFT DIFF=$DIFF ${testfile} 2>&1)
+ test_output=$(NFT="$NFT" DIFF=$DIFF ${testfile} 2>&1)
rc_got=$?
echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line