Skip to contentSkip to conversation

nftables: Fix ptest output format issues

PATCH New [email protected] 1 participant 3 messages Apr 2, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 nftables: Fix ptest output format issues

From: William Lyu <[email protected]>

Fix the following ptest output format issues:

- For "sed" command, change "-e" option to "-E" option. I believe the
previous "-e" option is a typo based on the manual page of "sed":

-e script, --expression=script
add the script to the commands to be executed

"-E" option, on the other hand, makes "sed" "use extended regular expressions in the script" according to the manual page.

- The test result summary line is being treated as both a passed
testcase and a failed testcase due to this line containing substring "[OK]" and "[FAILED]". The following is a sample test result summary line:

I: results: [OK] 379 [SKIPPED] 1 [FAILED] 0 [TOTAL] 380

The fix is to change run-ptest to look for "I: [OK]" and "W: [FAILED]" when determining which lines correspond to passed/failed testcases.

- Previously, only "W: [FAILED]" out of the following testcase failure
prompts is parsed:

W: [CHK DUMP]
W: [VALGRIND]
W: [TAINTED]
W: [DUMP FAIL]
W: [FAILED]

Adding parsing for all testcase failure prompts.

---
 meta-networking/recipes-filter/nftables/nftables/run-ptest | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta-networking/recipes-filter/nftables/nftables/run-ptest +1 -1
index 27d780ace..3217c743d 100644
@@ -4,7 +4,7 @@ NFTABLESLIB=@libdir@/nftables
 cd ${NFTABLESLIB}/ptest
 
 LOG="${NFTABLESLIB}/ptest/nftables_ptest_$(date +%Y%m%d-%H%M%S).log"
-tests/shell/run-tests.sh -v | sed  -e '/OK/ s/^/PASS: / ; /FAILED/ s/^/FAIL: /' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | tee -a ${LOG}
+tests/shell/run-tests.sh -v | sed -E '/I: \[OK\]/ s/^/PASS: / ; /W: \[(CHK DUMP|VALGRIND|TAINTED|DUMP FAIL|FAILED)\]/ s/^/FAIL: /' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | tee -a ${LOG}
 
 passed=`grep PASS: ${LOG}|wc -l`
 failed=`grep FAIL: ${LOG}|wc -l`
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/3 nftables: Fix ShellCheck violations in ptest wrapper script "run-ptest"

From: William Lyu <[email protected]>

The following ShellCheck violations in "run-ptest" are fixed:
- line 4:

    SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

- line 7:
SC2086: Double quote to prevent globbing and word splitting.
- line 9:
SC2006: Use $(...) notation instead of legacy backticks ....
SC2086: Double quote to prevent globbing and word splitting.
SC2126: Consider using 'grep -c' instead of 'grep|wc -l'.
- line 10:
SC2006: Use $(...) notation instead of legacy backticks ....
SC2086: Double quote to prevent globbing and word splitting.
SC2126: Consider using 'grep -c' instead of 'grep|wc -l'.
- line 17:
SC2086: Double quote to prevent globbing and word splitting.

---
 .../recipes-filter/nftables/nftables/run-ptest         | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
meta-networking/recipes-filter/nftables/nftables/run-ptest +5 -5
index 3217c743d..363a1ee25 100644
@@ -1,17 +1,17 @@
 #!/bin/sh
 
 NFTABLESLIB=@libdir@/nftables
-cd ${NFTABLESLIB}/ptest
+cd ${NFTABLESLIB}/ptest || exit 1
 
 LOG="${NFTABLESLIB}/ptest/nftables_ptest_$(date +%Y%m%d-%H%M%S).log"
-tests/shell/run-tests.sh -v | sed -E '/I: \[OK\]/ s/^/PASS: / ; /W: \[(CHK DUMP|VALGRIND|TAINTED|DUMP FAIL|FAILED)\]/ s/^/FAIL: /' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | tee -a ${LOG}
+tests/shell/run-tests.sh -v | sed -E '/I: \[OK\]/ s/^/PASS: / ; /W: \[(CHK DUMP|VALGRIND|TAINTED|DUMP FAIL|FAILED)\]/ s/^/FAIL: /' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | tee -a "${LOG}"
 
-passed=`grep PASS: ${LOG}|wc -l`
-failed=`grep FAIL: ${LOG}|wc -l`
+passed=$(grep -c PASS: "${LOG}")
+failed=$(grep -c FAIL: "${LOG}")
 all=$((passed + failed))
 
 (   echo "=== Test Summary ==="
     echo "TOTAL: ${all}"
     echo "PASSED: ${passed}"
     echo "FAILED: ${failed}"
-) | tee -a ${LOG}
+) | tee -a "${LOG}"
Signature · 1 line
2.43.0
#2 lore raw

PATCH 3/3 nftables: Fix failed ptest testcases

In reply to [email protected]

From: William Lyu <[email protected]>

There are 2 failed ptest testcases. They fail because they are broken, but the fix from the upstream is not yet available in version 1.0.9. These testcases are:
- tests/shell/testcases/sets/reset_command_0
Fix from the upstream:
https://git.netfilter.org/nftables/commit/?id=7a6089a400a573b9a4fd92f29c00a6be7b8ef269
- tests/shell/testcases/json/0005secmark_objref_0
Fix from the upstream:
https://git.netfilter.org/nftables/commit/?id=fff913c1eefbc84eb2d9c52038ef29fe881e9ee9

---
 ...sets-reset_command_0-for-current-ker.patch | 53 +++++++++++++++++++
 ...-secmark-tests-if-kernel-does-not-su.patch | 46 ++++++++++++++++
 .../recipes-filter/nftables/nftables_1.0.9.bb |  2 +
 3 files changed, 101 insertions(+)
 create mode 100644 meta-networking/recipes-filter/nftables/nftables/0001-tests-shell-Fix-sets-reset_command_0-for-current-ker.patch
 create mode 100644 meta-networking/recipes-filter/nftables/nftables/0001-tests-shell-skip-secmark-tests-if-kernel-does-not-su.patch
meta-networking/recipes-filter/nftables/nftables/0001-tests-shell-Fix-sets-reset_command_0-for-current-ker.patch new file +53 -0
new file mode 100644
index 000000000..164182bb1
@@ -0,0 +1,53 @@
+From 7a6089a400a573b9a4fd92f29c00a6be7b8ef269 Mon Sep 17 00:00:00 2001
+From: Phil Sutter <[email protected]>
+Date: Thu, 2 Nov 2023 16:02:14 +0100
+Subject: [PATCH] tests: shell: Fix sets/reset_command_0 for current kernels
+
+Since kernel commit 4c90bba60c26 ("netfilter: nf_tables: do not refresh
+timeout when resetting element"), element reset won't touch expiry
+anymore. Invert the one check to make sure it remains unaltered, drop
+the other testing behaviour for per-element timeouts.
+
+Signed-off-by: Phil Sutter <[email protected]>
+
+Upstream-Status: Backport
+[https://git.netfilter.org/nftables/commit/?id=7a6089a400a573b9a4fd92f29c00a6be7b8ef269]
+
+Signed-off-by: William Lyu <[email protected]>
+---
+ tests/shell/testcases/sets/reset_command_0 | 10 ++--------
+ 1 file changed, 2 insertions(+), 8 deletions(-)
+
+diff --git a/tests/shell/testcases/sets/reset_command_0 b/tests/shell/testcases/sets/reset_command_0
+index e663dac8..d38ddb3f 100755
+--- a/tests/shell/testcases/sets/reset_command_0
++++ b/tests/shell/testcases/sets/reset_command_0
+@@ -44,10 +44,10 @@ elem='element t s { 1.0.0.1 . udp . 53 }'
+ 	grep 'elements = ' | drop_seconds | uniq | wc -l) == 1 ]]
+ echo OK
+ 
+-echo -n "counters and expiry are reset: "
++echo -n "counters are reset, expiry left alone: "
+ NEW=$($NFT "get $elem")
+ grep -q 'counter packets 0 bytes 0' <<< "$NEW"
+-[[ $(expires_minutes <<< "$NEW") -gt 20 ]]
++[[ $(expires_minutes <<< "$NEW") -lt 20 ]]
+ echo OK
+ 
+ echo -n "get map elem matches reset map elem: "
+@@ -80,12 +80,6 @@ OUT=$($NFT reset map t m)
+ $DIFF -u <(echo "$EXP") <(echo "$OUT")
+ echo OK
+ 
+-echo -n "reset command respects per-element timeout: "
+-VAL=$($NFT get element t s '{ 2.0.0.2 . tcp . 22 }' | expires_minutes)
+-[[ $VAL -lt 15 ]]	# custom timeout applies
+-[[ $VAL -gt 10 ]]	# expires was reset
+-echo OK
+-
+ echo -n "remaining elements are reset: "
+ OUT=$($NFT list ruleset)
+ grep -q '2.0.0.2 . tcp . 22 counter packets 0 bytes 0' <<< "$OUT"
+-- 
+2.43.0
+
meta-networking/recipes-filter/nftables/nftables/0001-tests-shell-skip-secmark-tests-if-kernel-does-not-su.patch new file +46 -0

46 lines not on this page · raw message

meta-networking/recipes-filter/nftables/nftables_1.0.9.bb +2 -0
index 906d1b4f6..ad99a80a6 100644
@@ -12,6 +12,8 @@ DEPENDS = "libmnl libnftnl bison-native \
            ${@bb.utils.contains('PACKAGECONFIG', 'mini-gmp', '', 'gmp', d)}"
 
 SRC_URI = "http://www.netfilter.org/projects/nftables/files/${BP}.tar.xz \
+           file://0001-tests-shell-Fix-sets-reset_command_0-for-current-ker.patch \
+           file://0001-tests-shell-skip-secmark-tests-if-kernel-does-not-su.patch \
            file://run-ptest \
           "
 SRC_URI[sha256sum] = "a3c304cd9ba061239ee0474f9afb938a9bb99d89b960246f66f0c3a0a85e14cd"
Signature · 1 line
2.43.0