Commit 8f72a9cf authored by Amit Cohen's avatar Amit Cohen Committed by David S. Miller

selftests: forwarding: lib.sh: Add wait for dev with timeout

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.

Waiting for all the setup is limited with 10 minutes for each device.
Signed-off-by: default avatarAmit Cohen <amitc@mellanox.com>
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 646cf7ed
...@@ -18,6 +18,8 @@ NETIF_CREATE=${NETIF_CREATE:=yes} ...@@ -18,6 +18,8 @@ NETIF_CREATE=${NETIF_CREATE:=yes}
MCD=${MCD:=smcrouted} MCD=${MCD:=smcrouted}
MC_CLI=${MC_CLI:=smcroutectl} MC_CLI=${MC_CLI:=smcroutectl}
PING_TIMEOUT=${PING_TIMEOUT:=5} PING_TIMEOUT=${PING_TIMEOUT:=5}
WAIT_TIMEOUT=${WAIT_TIMEOUT:=20}
INTERFACE_TIMEOUT=${INTERFACE_TIMEOUT:=600}
relative_path="${BASH_SOURCE%/*}" relative_path="${BASH_SOURCE%/*}"
if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
...@@ -226,24 +228,45 @@ log_info() ...@@ -226,24 +228,45 @@ log_info()
setup_wait_dev() setup_wait_dev()
{ {
local dev=$1; shift local dev=$1; shift
local wait_time=${1:-$WAIT_TIME}; shift
while true; do setup_wait_dev_with_timeout "$dev" $INTERFACE_TIMEOUT $wait_time
if (($?)); then
check_err 1
log_test setup_wait_dev ": Interface $dev does not come up."
exit 1
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 \ ip link show dev $dev up \
| grep 'state UP' &> /dev/null | grep 'state UP' &> /dev/null
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
sleep 1 sleep 1
else else
break sleep $wait_time
return 0
fi fi
done done
return 1
} }
setup_wait() setup_wait()
{ {
local num_netifs=${1:-$NUM_NETIFS} local num_netifs=${1:-$NUM_NETIFS}
local i
for ((i = 1; i <= num_netifs; ++i)); do for ((i = 1; i <= num_netifs; ++i)); do
setup_wait_dev ${NETIFS[p$i]} setup_wait_dev ${NETIFS[p$i]} 0
done done
# Make sure links are ready. # Make sure links are ready.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment