From: Thomas Haller <thaller@redhat.com>
To: NetFilter <netfilter-devel@vger.kernel.org>
Cc: Thomas Haller <thaller@redhat.com>
Subject: [PATCH nft v3 4/6] tools: simplify error handling in "check-tree.sh" by adding msg_err()/msg_warn()
Date: Tue, 14 Nov 2023 17:08:29 +0100 [thread overview]
Message-ID: <20231114160903.409552-3-thaller@redhat.com> (raw)
In-Reply-To: <20231114160903.409552-1-thaller@redhat.com>
msg_err() also sets EXIT_CODE=, so we don't have to duplicate this.
Also add msg_warn() to print non-fatal warnings. Will be used in the
future. As "check-tree.sh" tests the consistency of the source tree, a
warning only makes sense to point something out that really should be
fixed, but is not yet.
Signed-off-by: Thomas Haller <thaller@redhat.com>
---
tools/check-tree.sh | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/tools/check-tree.sh b/tools/check-tree.sh
index e3ddf8bdea58..b16d37c4651b 100755
--- a/tools/check-tree.sh
+++ b/tools/check-tree.sh
@@ -25,6 +25,15 @@ cd "$(dirname "$0")/.."
EXIT_CODE=0
+msg_err() {
+ printf "ERR: %s\n" "$*"
+ EXIT_CODE=1
+}
+
+msg_warn() {
+ printf "WARN: %s\n" "$*"
+}
+
##############################################################################
check_shell_dumps() {
@@ -37,8 +46,7 @@ check_shell_dumps() {
local nodump_name
if [ ! -d "$dir/dumps/" ] ; then
- echo "\"$TEST\" has no \"$dir/dumps/\" directory"
- EXIT_CODE=1
+ msg_err "\"$TEST\" has no \"$dir/dumps/\" directory"
return 0
fi
@@ -49,34 +57,31 @@ check_shell_dumps() {
[ -f "$nodump_name" ] && has_nodump=1
if [ "$has_nft" != 1 -a "$has_nodump" != 1 ] ; then
- echo "\"$TEST\" has no \"$dir/dumps/$base.{nft,nodump}\" file"
- EXIT_CODE=1
+ msg_err "\"$TEST\" has no \"$dir/dumps/$base.{nft,nodump}\" file"
elif [ "$has_nft" == 1 -a "$has_nodump" == 1 ] ; then
- echo "\"$TEST\" has both \"$dir/dumps/$base.{nft,nodump}\" files"
- EXIT_CODE=1
+ msg_err "\"$TEST\" has both \"$dir/dumps/$base.{nft,nodump}\" files"
elif [ "$has_nodump" == 1 -a -s "$nodump_name" ] ; then
- echo "\"$TEST\" has a non-empty \"$dir/dumps/$base.nodump\" file"
- EXIT_CODE=1
+ msg_err "\"$TEST\" has a non-empty \"$dir/dumps/$base.nodump\" file"
fi
}
SHELL_TESTS=( $(find "tests/shell/testcases/" -type f -executable | sort) )
if [ "${#SHELL_TESTS[@]}" -eq 0 ] ; then
- echo "No executable tests under \"tests/shell/testcases/\" found"
- EXIT_CODE=1
+ msg_err "No executable tests under \"tests/shell/testcases/\" found"
fi
for t in "${SHELL_TESTS[@]}" ; do
check_shell_dumps "$t"
- head -n 1 "$t" |grep -q '^#!/bin/sh' && echo "$t uses sh instead of bash" && EXIT_CODE=1
+ if head -n 1 "$t" |grep -q '^#!/bin/sh' ; then
+ msg_err "$t uses #!/bin/sh instead of /bin/bash"
+ fi
done
##############################################################################
SHELL_TESTS2=( $(./tests/shell/run-tests.sh --list-tests) )
if [ "${SHELL_TESTS[*]}" != "${SHELL_TESTS2[*]}" ] ; then
- echo "\`./tests/shell/run-tests.sh --list-tests\` does not list the expected tests"
- EXIT_CODE=1
+ msg_err "\`./tests/shell/run-tests.sh --list-tests\` does not list the expected tests"
fi
##############################################################################
@@ -85,8 +90,7 @@ F=( $(find tests/shell/testcases/ -type f | grep '^tests/shell/testcases/[^/]\+/
IGNORED_FILES=( tests/shell/testcases/bogons/nft-f/* )
for f in "${F[@]}" ; do
if ! array_contains "$f" "${SHELL_TESTS[@]}" "${IGNORED_FILES[@]}" ; then
- echo "Unexpected file \"$f\""
- EXIT_CODE=1
+ msg_err "Unexpected file \"$f\""
fi
done
@@ -97,8 +101,7 @@ FILES=( $(find "tests/shell/testcases/" -type f | sed -n 's#\(tests/shell/testca
for f in "${FILES[@]}" ; do
f2="$(echo "$f" | sed -n 's#\(tests/shell/testcases\(/.*\)\?/\)dumps/\(.*\)\.\(nft\|nodump\)$#\1\3#p')"
if ! array_contains "$f2" "${SHELL_TESTS[@]}" ; then
- echo "\"$f\" has no test \"$f2\""
- EXIT_CODE=1
+ msg_err "\"$f\" has no test \"$f2\""
fi
done
--
2.41.0
next prev parent reply other threads:[~2023-11-14 16:09 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 15:29 [PATCH nft v3 0/6] add and check dump files for JSON in tests/shell Thomas Haller
2023-11-14 15:29 ` [PATCH nft v3 1/6] json: fix use after free in table_flags_json() Thomas Haller
2023-11-15 9:58 ` Pablo Neira Ayuso
2023-11-14 16:08 ` [PATCH nft v3 2/6] tests/shell: check and generate JSON dump files Thomas Haller
2023-11-14 16:08 ` Thomas Haller [this message]
2023-11-14 16:08 ` [PATCH nft v3 5/6] tools: check more strictly for bash shebang in "check-tree.sh" Thomas Haller
2023-11-14 16:08 ` [PATCH nft v3 6/6] tools: check for consistency of .json-nft dumps " Thomas Haller
2023-11-15 8:24 ` [PATCH nft v3 2/6] tests/shell: check and generate JSON dump files Florian Westphal
2023-11-15 9:54 ` Pablo Neira Ayuso
2023-11-15 10:01 ` Florian Westphal
2023-11-15 10:05 ` Pablo Neira Ayuso
2023-11-15 10:10 ` Florian Westphal
2023-11-15 10:26 ` Pablo Neira Ayuso
2023-11-15 10:31 ` Florian Westphal
2023-11-15 10:35 ` Pablo Neira Ayuso
2023-11-15 10:43 ` Pablo Neira Ayuso
2023-11-15 12:21 ` Florian Westphal
2023-11-15 12:30 ` Pablo Neira Ayuso
2023-11-15 12:36 ` Thomas Haller
2023-11-16 16:10 ` Pablo Neira Ayuso
2023-11-16 16:49 ` Thomas Haller
2023-11-16 16:55 ` Thomas Haller
2023-11-16 23:00 ` Florian Westphal
2023-11-16 23:02 ` Florian Westphal
2023-11-17 8:27 ` Pablo Neira Ayuso
2023-11-17 16:16 ` Thomas Haller
2023-11-17 16:36 ` Pablo Neira Ayuso
2023-11-17 16:56 ` Thomas Haller
2023-11-17 16:57 ` Phil Sutter
2023-11-17 17:06 ` Thomas Haller
2023-11-17 17:11 ` Phil Sutter
2023-11-17 17:23 ` Thomas Haller
2023-11-17 22:30 ` Phil Sutter
2023-11-15 10:11 ` Thomas Haller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231114160903.409552-3-thaller@redhat.com \
--to=thaller@redhat.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).