summaryrefslogtreecommitdiffstats
path: root/tools/check-tree.sh
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-11-14 17:08:31 +0100
committerFlorian Westphal <fw@strlen.de>2023-11-15 13:12:06 +0100
commit2f1050a6b30b41f4125ab6f0da7ea5255090ccce (patch)
treea7bbaea314cbca277cb8d2d11fdd742c0d489569 /tools/check-tree.sh
parent6834658132a65e53e19aa217b12f1d01d93238b4 (diff)
tools: check for consistency of .json-nft dumps in "check-tree.sh"
Add checks for the newly introduced .json-nft dump files. Optimally, every test that has a .nft dump should also have a .json-nft dump, and vice versa. However, currently some JSON tests fail to validate, and are missing. Only flag those missing files as warning, without failing the script. The reason to warn about this, is that we really should fix those tests, and having a annoying warning increases the pressure and makes it discoverable. Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'tools/check-tree.sh')
-rwxr-xr-xtools/check-tree.sh21
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/check-tree.sh b/tools/check-tree.sh
index 4be874fc..e358c957 100755
--- a/tools/check-tree.sh
+++ b/tools/check-tree.sh
@@ -41,6 +41,7 @@ check_shell_dumps() {
local base="$(basename "$TEST")"
local dir="$(dirname "$TEST")"
local has_nft=0
+ local has_jnft=0
local has_nodump=0
local nft_name
local nodump_name
@@ -51,9 +52,11 @@ check_shell_dumps() {
fi
nft_name="$dir/dumps/$base.nft"
+ jnft_name="$dir/dumps/$base.json-nft"
nodump_name="$dir/dumps/$base.nodump"
[ -f "$nft_name" ] && has_nft=1
+ [ -f "$jnft_name" ] && has_jnft=1
[ -f "$nodump_name" ] && has_nodump=1
if [ "$has_nft" != 1 -a "$has_nodump" != 1 ] ; then
@@ -63,6 +66,22 @@ check_shell_dumps() {
elif [ "$has_nodump" == 1 -a -s "$nodump_name" ] ; then
msg_err "\"$TEST\" has a non-empty \"$dir/dumps/$base.nodump\" file"
fi
+ if [ "$has_jnft" = 1 -a "$has_nft" != 1 ] ; then
+ msg_err "\"$TEST\" has a JSON dump file \"$jnft_name\" but lacks a dump \"$nft_name\""
+ fi
+ if [ "$has_nft" = 1 -a "$has_jnft" != 1 ] ; then
+ # it's currently known that `nft -j --check` cannot parse all dumped rulesets.
+ # Accept having no JSON dump file.
+ #
+ # This should be fixed. Currently this is only a warning.
+ msg_warn "\"$TEST\" has a dump file \"$nft_name\" but lacks a JSON dump \"$jnft_name\""
+ fi
+
+ if [ "$has_jnft" = 1 ] && command -v jq &>/dev/null ; then
+ if ! jq empty < "$jnft_name" &>/dev/null ; then
+ msg_err "\"$TEST\" has a JSON dump file \"$jnft_name\" that does not validate with \`jq empty < \"$jnft_name\"\`"
+ fi
+ fi
}
SHELL_TESTS=( $(find "tests/shell/testcases/" -type f -executable | sort) )
@@ -91,7 +110,7 @@ fi
##############################################################################
#
-F=( $(find tests/shell/testcases/ -type f | grep '^tests/shell/testcases/[^/]\+/dumps/[^/]\+\.\(nft\|nodump\)$' -v | sort) )
+F=( $(find tests/shell/testcases/ -type f | grep '^tests/shell/testcases/[^/]\+/dumps/[^/]\+\.\(json-nft\|nft\|nodump\)$' -v | sort) )
IGNORED_FILES=( tests/shell/testcases/bogons/nft-f/* )
for f in "${F[@]}" ; do
if ! array_contains "$f" "${SHELL_TESTS[@]}" "${IGNORED_FILES[@]}" ; then