Skip to contentSkip to conversation

selftest: netfilter: small test tweaks

PATCH In review Boris Sukholitko 2 participants 6 messages May 4, 2023 – May 10, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover selftest: netfilter: small test tweaks

Hi,

These patches allow nft_flowtable.sh test script to work in busybox environment (patches 1-2).

More exact wait for netcat running in the background is in patch 3.

Small adaptive sleep optimization (patch 4) helps with running on busy servers and cuts default sleep time a bit.

Thanks,
Boris.

- v2:
- extracted from controversial dscp offload series
- added Acked-by: Florian Westphal <fw.de> on patch 4

Boris Sukholitko (4):
selftest: netfilter: use /proc for pid checking
selftest: netfilter: no need for ps -x option
selftest: netfilter: wait for specific nc pids
selftest: netfilter: monitor result file sizes

 .../selftests/netfilter/nft_flowtable.sh      | 21 +++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

base-commit: 19c60fdee5db881a99a9c39fb31942a530d20c63

Signature · 1 line
2.32.0
#1 lore raw

PATCH v2 1/4 selftest: netfilter: use /proc for pid checking

Some ps commands (e.g. busybox derived) have no -p option. Use /proc for pid existence check.

---
 tools/testing/selftests/netfilter/nft_flowtable.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/netfilter/nft_flowtable.sh +2 -2
index 7060bae04ec8..4d8bc51b7a7b 100755
@@ -288,11 +288,11 @@ test_tcp_forwarding_ip()
 
 	sleep 3
 
-	if ps -p $lpid > /dev/null;then
+	if test -d /proc/"$lpid"/; then
 		kill $lpid
 	fi
 
-	if ps -p $cpid > /dev/null;then
+	if test -d /proc/"$cpid"/; then
 		kill $cpid
 	fi
 
Signature · 1 line
2.32.0
#2 lore raw

PATCH v2 2/4 selftest: netfilter: no need for ps -x option

In reply to Boris Sukholitko

Some ps commands (e.g. busybox derived) have no -x option. For the purposes of hash calculation of the list of processes this option is inessential.

---
 tools/testing/selftests/netfilter/nft_flowtable.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/netfilter/nft_flowtable.sh +2 -2
index 4d8bc51b7a7b..3cf20e9bd3a6 100755
@@ -489,8 +489,8 @@ ip -net $nsr1 addr add 10.0.1.1/24 dev veth0
 ip -net $nsr1 addr add dead:1::1/64 dev veth0
 ip -net $nsr1 link set up dev veth0
 
-KEY_SHA="0x"$(ps -xaf | sha1sum | cut -d " " -f 1)
-KEY_AES="0x"$(ps -xaf | md5sum | cut -d " " -f 1)
+KEY_SHA="0x"$(ps -af | sha1sum | cut -d " " -f 1)
+KEY_AES="0x"$(ps -af | md5sum | cut -d " " -f 1)
 SPI1=$RANDOM
 SPI2=$RANDOM
 
Signature · 1 line
2.32.0
#3 lore raw

PATCH v2 3/4 selftest: netfilter: wait for specific nc pids

In reply to Boris Sukholitko

Doing wait with no parameters may interfere with some of the tests having their own background processes.

Although no such test is currently present, the cleanup is useful to rely on the nft_flowtable.sh for local development (e.g. running background tcpdump command during the tests).

---
 tools/testing/selftests/netfilter/nft_flowtable.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/netfilter/nft_flowtable.sh +2 -1
index 3cf20e9bd3a6..92bc308bf168 100755
@@ -296,7 +296,8 @@ test_tcp_forwarding_ip()
 		kill $cpid
 	fi
 
-	wait
+	wait $lpid
+	wait $cpid
 
 	if ! check_transfer "$nsin" "$ns2out" "ns1 -> ns2"; then
 		lret=1
Signature · 1 line
2.32.0
#4 lore raw

PATCH v2 4/4 selftest: netfilter: monitor result file sizes

In reply to Boris Sukholitko

When running nft_flowtable.sh in VM on a busy server we've found that the time of the netcat file transfers vary wildly.

Therefore replace hardcoded 3 second sleep with the loop checking for a change in the file sizes. Once no change in detected we test the results.

Nice side effect is that we shave 1 second sleep in the fast case (hard-coded 3 second sleep vs two 1 second sleeps).

---
 tools/testing/selftests/netfilter/nft_flowtable.sh | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/testing/selftests/netfilter/nft_flowtable.sh +9 -1
index 92bc308bf168..51f986f19fee 100755
@@ -286,7 +286,15 @@ test_tcp_forwarding_ip()
 	ip netns exec $nsa nc -w 4 "$dstip" "$dstport" < "$nsin" > "$ns1out" &
 	cpid=$!
 
-	sleep 3
+	sleep 1
+
+	prev="$(ls -l $ns1out $ns2out)"
+	sleep 1
+
+	while [[ "$prev" != "$(ls -l $ns1out $ns2out)" ]]; do
+		sleep 1;
+		prev="$(ls -l $ns1out $ns2out)"
+	done
 
 	if test -d /proc/"$lpid"/; then
 		kill $lpid
Signature · 1 line
2.32.0
#5 lore raw
In reply to Boris Sukholitko
Quoted 9 lines · Boris Sukholitko

Hi,

These patches allow nft_flowtable.sh test script to work in busybox environment (patches 1-2).

More exact wait for netcat running in the background is in patch 3.

Small adaptive sleep optimization (patch 4) helps with running on busy servers and cuts default sleep time a bit.

Thanks, I am going to route this batch through nf.git instead, I think it is good to get this selftests updates there.