From: Thomas Haller <thaller@redhat.com>
To: NetFilter <netfilter-devel@vger.kernel.org>
Cc: Thomas Haller <thaller@redhat.com>
Subject: [PATCH nft 6/6] tools: add "tools/check-tree.sh" script to check consistency of nft dumps
Date: Wed, 13 Sep 2023 19:05:09 +0200 [thread overview]
Message-ID: <20230913170649.439394-7-thaller@redhat.com> (raw)
In-Reply-To: <20230913170649.439394-1-thaller@redhat.com>
The script performs some checks on the source tree, and fails if
any problems are found.
Currently it only checks for the dumps files, but it shall be extended
to perform various consistency checks of the source tree.
This script was already successful at finding issues with the dumps.
Running it helps to make sure we don't make mistakes.
Later it should also integrate with `make check` and/or be called
from CI.
Signed-off-by: Thomas Haller <thaller@redhat.com>
---
tools/check-tree.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
create mode 100755 tools/check-tree.sh
diff --git a/tools/check-tree.sh b/tools/check-tree.sh
new file mode 100755
index 000000000000..ede3e6998ecc
--- /dev/null
+++ b/tools/check-tree.sh
@@ -0,0 +1,91 @@
+#!/bin/bash -e
+
+# Preform various consistency checks of the source tree.
+
+die() {
+ printf '%s\n' "$*"
+ exit 1
+}
+
+array_contains() {
+ local needle="$1"
+ local a
+ shift
+ for a; do
+ [ "$a" = "$needle" ] && return 0
+ done
+ return 1
+}
+
+cd "$(dirname "$0")/.."
+
+EXIT_CODE=0
+
+##############################################################################
+
+check_shell_dumps() {
+ local TEST="$1"
+ local base="$(basename "$TEST")"
+ local dir="$(dirname "$TEST")"
+ local has_nft=0
+ local has_nodump=0
+ local nft_name
+ local nodump_name
+
+ if [ ! -d "$dir/dumps/" ] ; then
+ echo "\"$TEST\" has no \"$dir/dumps/\" directory"
+ EXIT_CODE=1
+ return 0
+ fi
+
+ nft_name="$dir/dumps/$base.nft"
+ nodump_name="$dir/dumps/$base.nodump"
+
+ [ -f "$nft_name" ] && has_nft=1
+ [ -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
+ elif [ "$has_nft" == 1 -a "$has_nodump" == 1 ] ; then
+ echo "\"$TEST\" has both \"$dir/dumps/$base.{nft,nodump}\" files"
+ EXIT_CODE=1
+ elif [ "$has_nodump" == 1 -a -s "$nodump_name" ] ; then
+ echo "\"$TEST\" has a non-empty \"$dir/dumps/$base.nodump\" file"
+ EXIT_CODE=1
+ fi
+}
+
+SHELL_TESTS=( $(find "tests/shell/testcases/" -type f -executable | LANG=C sort) )
+
+if [ "${#SHELL_TESTS[@]}" -eq 0 ] ; then
+ echo "No executable tests under \"tests/shell/testcases/\" found"
+ EXIT_CODE=1
+fi
+for t in "${SHELL_TESTS[@]}" ; do
+ check_shell_dumps "$t"
+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
+fi
+
+##############################################################################
+
+FILES=( $(find "tests/shell/testcases/" -type f | sed -n 's#\(tests/shell/testcases\(/.*\)\?/\)dumps/\(.*\)\.\(nft\|nodump\)$#\0#p' | LANG=C sort) )
+
+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
+ fi
+done
+
+##############################################################################
+
+exit "$EXIT_CODE"
--
2.41.0
prev parent reply other threads:[~2023-09-13 17:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 17:05 [PATCH nft 0/6] adjust nft dump files and add check-tree script Thomas Haller
2023-09-13 17:05 ` [PATCH nft 1/6] tests/shell: remove spurious .nft dump files Thomas Haller
2023-09-13 17:05 ` [PATCH nft 2/6] tests/shell: drop unstable dump for "transactions/0051map_0" test Thomas Haller
2023-09-13 17:05 ` [PATCH nft 3/6] tests/shell: add missing nft/nodump files for tests Thomas Haller
2023-09-13 17:05 ` [PATCH nft 4/6] tests/shell: special handle base path starting with "./" Thomas Haller
2023-09-13 17:05 ` [PATCH nft 5/6] tests/shell: in find_tests() use C locale for sorting tests names Thomas Haller
2023-09-13 17:05 ` Thomas Haller [this message]
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=20230913170649.439394-7-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).