All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, amitc@mellanox.com, mlxsw@mellanox.com,
	Ido Schimmel <idosch@mellanox.com>
Subject: [PATCH net-next 2/3] selftests: mlxsw: lib.sh: Add wait for dev with timeout
Date: Mon, 10 Jun 2019 11:40:44 +0300	[thread overview]
Message-ID: <20190610084045.6029-3-idosch@idosch.org> (raw)
In-Reply-To: <20190610084045.6029-1-idosch@idosch.org>

From: Amit Cohen <amitc@mellanox.com>

Add a function that waits for device with maximum number of iterations.
It enables to limit the waiting and prevent infinite loop.

This will be used by the subsequent patch which will set two ports to
different speeds in order to make sure they cannot negotiate a link.

Signed-off-by: Amit Cohen <amitc@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 tools/testing/selftests/net/forwarding/lib.sh | 28 +++++++++++++++++--
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index 9385dc971269..cd362d14d6c6 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -18,6 +18,7 @@ NETIF_CREATE=${NETIF_CREATE:=yes}
 MCD=${MCD:=smcrouted}
 MC_CLI=${MC_CLI:=smcroutectl}
 PING_TIMEOUT=${PING_TIMEOUT:=5}
+WAIT_TIMEOUT=${WAIT_TIMEOUT:=20}
 
 relative_path="${BASH_SOURCE%/*}"
 if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
@@ -226,24 +227,45 @@ log_info()
 setup_wait_dev()
 {
 	local dev=$1; shift
+	local wait_time=${1:-$WAIT_TIME}; shift
 
-	while true; do
+	setup_wait_dev_with_timeout "$dev" 600 $wait_time
+
+	if (($?)); then
+		check_err 1
+		log_test setup_wait_dev ": Interface $dev does not come up."
+		exit 0
+	fi
+}
+
+setup_wait_dev_with_timeout()
+{
+	local dev=$1; shift
+	local max_iterations=${1:-$WAIT_TIMEOUT}; shift
+	local wait_time=${1:-$WAIT_TIME}; shift
+	local i
+
+	for ((i = 1; i <= $max_iterations; ++i)); do
 		ip link show dev $dev up \
 			| grep 'state UP' &> /dev/null
 		if [[ $? -ne 0 ]]; then
 			sleep 1
 		else
-			break
+			sleep $wait_time
+			return 0
 		fi
 	done
+
+	return 1
 }
 
 setup_wait()
 {
 	local num_netifs=${1:-$NUM_NETIFS}
+	local i
 
 	for ((i = 1; i <= num_netifs; ++i)); do
-		setup_wait_dev ${NETIFS[p$i]}
+		setup_wait_dev ${NETIFS[p$i]} 0
 	done
 
 	# Make sure links are ready.
-- 
2.20.1


  parent reply	other threads:[~2019-06-10  8:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-10  8:40 [PATCH net-next 0/3] mlxsw: Add speed and auto-negotiation test Ido Schimmel
2019-06-10  8:40 ` [PATCH net-next 1/3] selftests: mlxsw: Add ethtool_lib.sh Ido Schimmel
2019-06-10 13:35   ` Andrew Lunn
2019-06-10 13:56     ` Ido Schimmel
2019-06-10 15:29       ` Florian Fainelli
2019-06-11  6:51         ` Ido Schimmel
2019-06-10 13:59   ` Andrew Lunn
2019-06-10 14:31     ` Ido Schimmel
2019-06-10 14:51       ` Andrew Lunn
2019-06-10  8:40 ` Ido Schimmel [this message]
2019-06-10  8:40 ` [PATCH net-next 3/3] selftests: mlxsw: Add speed and auto-negotiation test Ido Schimmel
2019-06-10 13:48   ` Andrew Lunn
2019-06-10 13:58     ` Ido Schimmel
2019-06-10 14:06       ` Andrew Lunn
2019-06-11  6:35         ` Ido Schimmel
2019-06-11 12:22           ` Andrew Lunn
2019-06-11 13:06             ` Ido Schimmel
2019-06-11 13:30               ` Andrew Lunn

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=20190610084045.6029-3-idosch@idosch.org \
    --to=idosch@idosch.org \
    --cc=amitc@mellanox.com \
    --cc=davem@davemloft.net \
    --cc=idosch@mellanox.com \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.