All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft] tests: shell: Allow wrappers to be passed as nft command
@ 2020-06-14 21:41 Stefano Brivio
  2020-06-15 22:00 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Stefano Brivio @ 2020-06-14 21:41 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

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>
---
 tests/shell/run-tests.sh | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index 26f8f46d95a0..94115066b1bf 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -23,10 +23,12 @@ if [ "$(id -u)" != "0" ] ; then
 fi
 
 [ -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
@@ -101,7 +103,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
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH nft] tests: shell: Allow wrappers to be passed as nft command
  2020-06-14 21:41 [PATCH nft] tests: shell: Allow wrappers to be passed as nft command Stefano Brivio
@ 2020-06-15 22:00 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2020-06-15 22:00 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: netfilter-devel

On Sun, Jun 14, 2020 at 11:41:37PM +0200, Stefano Brivio wrote:
> 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.

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-15 22:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-14 21:41 [PATCH nft] tests: shell: Allow wrappers to be passed as nft command Stefano Brivio
2020-06-15 22:00 ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.