Skip to contentSkip to conversation

selftests: net: move amt to socat for better compatibility

PATCH Applied Jakub Kicinski 4 participants 5 messages May 9, 2024 – May 11, 2024

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 selftests: net: move amt to socat for better compatibility

The test seems to expect that nc will exit after the first received message. This is not the case with Ncat 7.94. There are multiple versions of nc out there, switch to socat for better compatibility.

Tell socat to exit after 128 bytes and pad the message.

Since the test sets -e make sure we don't set exit code (|| true) and print the pass / fail rather then silently moving over the test and just setting non-zero exit code with no output indicating what failed.

Fixes c08e8baea78e ("selftests: add amt interface selftest script")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 tools/testing/selftests/net/amt.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/net/amt.sh +6 -6
index 75528788cb95..5175a42cbe8a 100755
@@ -210,8 +210,8 @@ check_features()
 
 test_ipv4_forward()
 {
-	RESULT4=$(ip netns exec "${LISTENER}" nc -w 1 -l -u 239.0.0.1 4000)
-	if [ "$RESULT4" == "172.17.0.2" ]; then
+	RESULT4=$(ip netns exec "${LISTENER}" timeout 15 socat - UDP4-LISTEN:4000,readbytes=128 || true)
+	if echo "$RESULT4" | grep -q "172.17.0.2"; then
 		printf "TEST: %-60s  [ OK ]\n" "IPv4 amt multicast forwarding"
 		exit 0
 	else
@@ -222,8 +222,8 @@ test_ipv4_forward()
 
 test_ipv6_forward()
 {
-	RESULT6=$(ip netns exec "${LISTENER}" nc -w 1 -l -u ff0e::5:6 6000)
-	if [ "$RESULT6" == "2001:db8:3::2" ]; then
+	RESULT6=$(ip netns exec "${LISTENER}" timeout 15 socat - UDP6-LISTEN:6000,readbytes=128 || true)
+	if echo "$RESULT6" | grep -q "2001:db8:3::2"; then
 		printf "TEST: %-60s  [ OK ]\n" "IPv6 amt multicast forwarding"
 		exit 0
 	else
@@ -236,14 +236,14 @@ send_mcast4()
 {
 	sleep 2
 	ip netns exec "${SOURCE}" bash -c \
-		'echo 172.17.0.2 | nc -w 1 -u 239.0.0.1 4000' &
+		'printf "%s %128s" 172.17.0.2 | nc -w 1 -u 239.0.0.1 4000' &
 }
 
 send_mcast6()
 {
 	sleep 2
 	ip netns exec "${SOURCE}" bash -c \
-		'echo 2001:db8:3::2 | nc -w 1 -u ff0e::5:6 6000' &
+		'printf "%s %128s" 2001:db8:3::2 | nc -w 1 -u ff0e::5:6 6000' &
 }
 
 check_features
Signature · 1 line
2.45.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 38 lines · Jakub Kicinski

The test seems to expect that nc will exit after the first received message. This is not the case with Ncat 7.94. There are multiple versions of nc out there, switch to socat for better compatibility.

Tell socat to exit after 128 bytes and pad the message.

Since the test sets -e make sure we don't set exit code (|| true) and print the pass / fail rather then silently moving over the test and just setting non-zero exit code with no output indicating what failed.

Fixes c08e8baea78e ("selftests: add amt interface selftest script")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 tools/testing/selftests/net/amt.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/net/amt.sh +2 -2
index 75528788cb95..5175a42cbe8a 100755
@@ -210,8 +210,8 @@ check_features()
 
 test_ipv4_forward()
 {
-	RESULT4=$(ip netns exec "${LISTENER}" nc -w 1 -l -u 239.0.0.1 4000)
-	if [ "$RESULT4" == "172.17.0.2" ]; then
+	RESULT4=$(ip netns exec "${LISTENER}" timeout 15 socat - UDP4-LISTEN:4000,readbytes=128 || true)
+	if echo "$RESULT4" | grep -q "172.17.0.2"; then
 		printf "TEST: %-60s  [ OK ]\n" "IPv4 amt multicast forwarding"
 		exit 0
 	else

tools/testing/selftests/net/amt.sh test_ipv4_forward() · line 226

Quoted 7 lines
tools/testing/selftests/net/amt.sh +2 -2
@@ -222,8 +222,8 @@ test_ipv4_forward()
 
 test_ipv6_forward()
 {
-	RESULT6=$(ip netns exec "${LISTENER}" nc -w 1 -l -u ff0e::5:6 6000)
-	if [ "$RESULT6" == "2001:db8:3::2" ]; then
+	RESULT6=$(ip netns exec "${LISTENER}" timeout 15 socat - UDP6-LISTEN:6000,readbytes=128 || true)
+	if echo "$RESULT6" | grep -q "2001:db8:3::2"; then

The patch LGTM:

As a minor note, shell variable expansion should already trim all the trailing/leading spaces from the socat command output, so it should not be necessary replace the string comparison with the grep command:

	RESULT6=$(ip netns exec "${LISTENER}" timeout 15 socat - UDP6-LISTEN:6000,readbytes=128 || true)
	if [ "$RESULT6" == "2001:db8:3::2" ]; then

Should work

Cheers,

Paolo

author maintainer
#2 lore raw
Quoted 1 line · On Thu, 09 May 2024 19:39:36 +0200 Paolo Abeni wrote:

Thanks!

Quoted 6 lines

As a minor note, shell variable expansion should already trim all the trailing/leading spaces from the socat command output, so it should not be necessary replace the string comparison with the grep command:

	RESULT6=$(ip netns exec "${LISTENER}" timeout 15 socat - UDP6-LISTEN:6000,readbytes=128 || true)
	if [ "$RESULT6" == "2001:db8:3::2" ]; then

99% sure I tried that exact thing, but it wasn't enough.

$ msg=$(socat - UDP4-LISTEN:1234,readbytes=128)
$ echo ">$msg<"
Quoted 1 line

127.0.0.1 <

$ msg=$msg
$ echo ">$msg<"
Quoted 1 line

127.0.0.1 <

$ msg=$(echo $msg)
$ echo ">$msg<"
Quoted 1 line

127.0.0.1<

IOW we'd need to feed it thru an echo or some such. Possibly something like: [ $(echo $msg) == "127.0.0.1" ] But I personally find that a touch too magical. The grep works 🤷️

Tested-by on v1 1/1
#3 lore raw
In reply to Jakub Kicinski
Quoted 1 line · Jakub Kicinski

Hi Jakub,
Thanks a lot for this work!

Quoted 66 lines

The test seems to expect that nc will exit after the first received message. This is not the case with Ncat 7.94. There are multiple versions of nc out there, switch to socat for better compatibility.

Tell socat to exit after 128 bytes and pad the message.

Since the test sets -e make sure we don't set exit code (|| true) and print the pass / fail rather then silently moving over the test and just setting non-zero exit code with no output indicating what failed.

Fixes c08e8baea78e ("selftests: add amt interface selftest script")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 tools/testing/selftests/net/amt.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/net/amt.sh +6 -7
index 75528788cb95..5175a42cbe8a 100755
@@ -210,8 +210,8 @@ check_features()
 
 test_ipv4_forward()
 {
-       RESULT4=$(ip netns exec "${LISTENER}" nc -w 1 -l -u 239.0.0.1 4000)
-       if [ "$RESULT4" == "172.17.0.2" ]; then
+       RESULT4=$(ip netns exec "${LISTENER}" timeout 15 socat - UDP4-LISTEN:4000,readbytes=128 || true)
+       if echo "$RESULT4" | grep -q "172.17.0.2"; then
                printf "TEST: %-60s  [ OK ]\n" "IPv4 amt multicast forwarding"
                exit 0
        else
@@ -222,8 +222,8 @@ test_ipv4_forward()
 
 test_ipv6_forward()
 {
-       RESULT6=$(ip netns exec "${LISTENER}" nc -w 1 -l -u ff0e::5:6 6000)
-       if [ "$RESULT6" == "2001:db8:3::2" ]; then
+       RESULT6=$(ip netns exec "${LISTENER}" timeout 15 socat - UDP6-LISTEN:6000,readbytes=128 || true)
+       if echo "$RESULT6" | grep -q "2001:db8:3::2"; then
                printf "TEST: %-60s  [ OK ]\n" "IPv6 amt multicast forwarding"
                exit 0
        else
@@ -236,14 +236,14 @@ send_mcast4()
 {
        sleep 2
        ip netns exec "${SOURCE}" bash -c \
-               'echo 172.17.0.2 | nc -w 1 -u 239.0.0.1 4000' &
+               'printf "%s %128s" 172.17.0.2 | nc -w 1 -u 239.0.0.1 4000' &
 }
 
 send_mcast6()
 {
        sleep 2
        ip netns exec "${SOURCE}" bash -c \
-               'echo 2001:db8:3::2 | nc -w 1 -u ff0e::5:6 6000' &
+               'printf "%s %128s" 2001:db8:3::2 | nc -w 1 -u ff0e::5:6 6000' &
 }
 
 check_features
--
Quoted 2 lines

2.45.0

#4 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 9 May 2024 09:19:52 -0700 you wrote:

The test seems to expect that nc will exit after the first received message. This is not the case with Ncat 7.94. There are multiple versions of nc out there, switch to socat for better compatibility.

Tell socat to exit after 128 bytes and pad the message.

[...]

Here is the summary with links:
- [net] selftests: net: move amt to socat for better compatibility

    https://git.kernel.org/netdev/net/c/4c639b6a7b9d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html