netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taehee Yoo <ap420073@gmail.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, shuah@kernel.org, netdev@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Cc: ap420073@gmail.com
Subject: [PATCH net] selftests: net: avoid waiting for server in amt.sh forever when it fails.
Date: Wed,  8 May 2024 04:06:43 +0000	[thread overview]
Message-ID: <20240508040643.229383-1-ap420073@gmail.com> (raw)

In the forwarding testcase, it opens a server and a client with the nc.
The server receives the correct message from NC, it prints OK.
The server prints FAIL if it receives the wrong message from the client.

But If the server can't receive any message, it will not close so
the amt.sh waits forever.
There are several reasons.
1. crash of smcrouted.
2. Send a message from the client to the server before the server is up.

To avoid this problem, the server waits only for 10 seconds.
The client sends messages for 10 seconds.
If the server is successfully closed, it kills the client.

Fixes: c08e8baea78e ("selftests: add amt interface selftest script")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
 tools/testing/selftests/net/amt.sh | 63 +++++++++++++++++++-----------
 1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/tools/testing/selftests/net/amt.sh b/tools/testing/selftests/net/amt.sh
index 75528788cb95..16641d3dccce 100755
--- a/tools/testing/selftests/net/amt.sh
+++ b/tools/testing/selftests/net/amt.sh
@@ -77,6 +77,7 @@ readonly LISTENER=$(mktemp -u listener-XXXXXXXX)
 readonly GATEWAY=$(mktemp -u gateway-XXXXXXXX)
 readonly RELAY=$(mktemp -u relay-XXXXXXXX)
 readonly SOURCE=$(mktemp -u source-XXXXXXXX)
+readonly RESULT=$(mktemp -p /tmp amt-XXXXXXXX)
 ERR=4
 err=0
 
@@ -85,6 +86,10 @@ exit_cleanup()
 	for ns in "$@"; do
 		ip netns delete "${ns}" 2>/dev/null || true
 	done
+	rm $RESULT
+	smcpid=$(< $SMCROUTEDIR/amt.pid)
+	kill $smcpid
+	rm -rf $SMCROUTEDIR
 
 	exit $ERR
 }
@@ -167,7 +172,9 @@ setup_iptables()
 
 setup_mcast_routing()
 {
-	ip netns exec "${RELAY}" smcrouted
+	SMCROUTEDIR="$(mktemp -d)"
+
+	ip netns exec "${RELAY}" smcrouted -P $SMCROUTEDIR/amt.pid
 	ip netns exec "${RELAY}" smcroutectl a relay_src \
 		172.17.0.2 239.0.0.1 amtr
 	ip netns exec "${RELAY}" smcroutectl a relay_src \
@@ -210,40 +217,52 @@ check_features()
 
 test_ipv4_forward()
 {
-	RESULT4=$(ip netns exec "${LISTENER}" nc -w 1 -l -u 239.0.0.1 4000)
+	echo "" > $RESULT
+	bash -c "$(ip netns exec "${LISTENER}" \
+		timeout 10s nc -w 1 -l -u 239.0.0.1 4000 > $RESULT)"
+	RESULT4=$(< $RESULT)
 	if [ "$RESULT4" == "172.17.0.2" ]; then
 		printf "TEST: %-60s  [ OK ]\n" "IPv4 amt multicast forwarding"
-		exit 0
 	else
 		printf "TEST: %-60s  [FAIL]\n" "IPv4 amt multicast forwarding"
-		exit 1
 	fi
+
 }
 
 test_ipv6_forward()
 {
-	RESULT6=$(ip netns exec "${LISTENER}" nc -w 1 -l -u ff0e::5:6 6000)
+	echo "" > $RESULT
+	bash -c "$(ip netns exec "${LISTENER}" \
+		timeout 10s nc -w 1 -l -u ff0e::5:6 6000 > $RESULT)"
+	RESULT6=$(< $RESULT)
 	if [ "$RESULT6" == "2001:db8:3::2" ]; then
 		printf "TEST: %-60s  [ OK ]\n" "IPv6 amt multicast forwarding"
-		exit 0
 	else
 		printf "TEST: %-60s  [FAIL]\n" "IPv6 amt multicast forwarding"
-		exit 1
 	fi
+
 }
 
 send_mcast4()
 {
 	sleep 2
-	ip netns exec "${SOURCE}" bash -c \
-		'echo 172.17.0.2 | nc -w 1 -u 239.0.0.1 4000' &
+	for n in {0..10}; do
+		ip netns exec "${SOURCE}" bash -c \
+			'echo 172.17.0.2 | nc -w 1 -u 239.0.0.1 4000'
+		sleep 1
+	done
+
 }
 
 send_mcast6()
 {
 	sleep 2
-	ip netns exec "${SOURCE}" bash -c \
-		'echo 2001:db8:3::2 | nc -w 1 -u ff0e::5:6 6000' &
+	for n in {0..10}; do
+		ip netns exec "${SOURCE}" bash -c \
+			'echo 2001:db8:3::2 | nc -w 1 -u ff0e::5:6 6000'
+		sleep 1
+	done
+
 }
 
 check_features
@@ -259,19 +278,17 @@ setup_iptables
 setup_mcast_routing
 test_remote_ip
 test_ipv4_forward &
-pid=$!
-send_mcast4
-wait $pid || err=$?
-if [ $err -eq 1 ]; then
-	ERR=1
-fi
+spid=$!
+send_mcast4 &
+cpid=$!
+wait $spid
+kill $cpid
 test_ipv6_forward &
-pid=$!
-send_mcast6
-wait $pid || err=$?
-if [ $err -eq 1 ]; then
-	ERR=1
-fi
+spid=$!
+send_mcast6 &
+cpid=$!
+wait $spid
+kill $cpid
 send_mcast_torture4
 printf "TEST: %-60s  [ OK ]\n" "IPv4 amt traffic forwarding torture"
 send_mcast_torture6
-- 
2.34.1


             reply	other threads:[~2024-05-08  4:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08  4:06 Taehee Yoo [this message]
2024-05-09  8:38 ` [PATCH net] selftests: net: avoid waiting for server in amt.sh forever when it fails Simon Horman
2024-05-10  4:57   ` Taehee Yoo
2024-05-09  9:36 ` Paolo Abeni
2024-05-10  5:05   ` Taehee Yoo
2024-05-09 16:22 ` Jakub Kicinski
2024-05-10  5:17   ` Taehee Yoo

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=20240508040643.229383-1-ap420073@gmail.com \
    --to=ap420073@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@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).