linux/tools/testing/selftests/net/forwarding/ethtool_extended_state.sh
Petr Machata 04cfbc1d89 selftests: forwarding: ethtool_extended_state: Convert to busywait
Currently, this script sets up the test scenario, which is supposed to end
in an inability of the system to negotiate a link. It then waits for a bit,
and verifies that the system can diagnose why the link was not established.

The wait time for the scenario where different link speeds are forced on
the two ends of a loopback cable, was set to 4 seconds, which exactly
covered it. As of a recent mlxsw firmware update, this time gets longer,
and this test starts failing.

The time that selftests currently wait for links to be established is
currently $WAIT_TIMEOUT, or 20 seconds. It seems reasonable that if this is
the time necessary to establish and bring up a link, it should also be
enough to determine that a link cannot be established and why.

Therefore in this patch, convert the sleeps to busywaits, so that if a
failure is established sooner (as is expected), the test runs quicker. And
use $WAIT_TIMEOUT as the time to wait.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Amit Cohen <amcohen@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-06-29 14:01:23 +01:00

116 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ALL_TESTS="
autoneg
autoneg_force_mode
no_cable
"
NUM_NETIFS=2
source lib.sh
source ethtool_lib.sh
TIMEOUT=$((WAIT_TIMEOUT * 1000)) # ms
setup_prepare()
{
swp1=${NETIFS[p1]}
swp2=${NETIFS[p2]}
swp3=$NETIF_NO_CABLE
}
ethtool_ext_state()
{
local dev=$1; shift
local expected_ext_state=$1; shift
local expected_ext_substate=${1:-""}; shift
local ext_state=$(ethtool $dev | grep "Link detected" \
| cut -d "(" -f2 | cut -d ")" -f1)
local ext_substate=$(echo $ext_state | cut -sd "," -f2 \
| sed -e 's/^[[:space:]]*//')
ext_state=$(echo $ext_state | cut -d "," -f1)
if [[ $ext_state != $expected_ext_state ]]; then
echo "Expected \"$expected_ext_state\", got \"$ext_state\""
return 1
fi
if [[ $ext_substate != $expected_ext_substate ]]; then
echo "Expected \"$expected_ext_substate\", got \"$ext_substate\""
return 1
fi
}
autoneg()
{
local msg
RET=0
ip link set dev $swp1 up
msg=$(busywait $TIMEOUT ethtool_ext_state $swp1 \
"Autoneg" "No partner detected")
check_err $? "$msg"
log_test "Autoneg, No partner detected"
ip link set dev $swp1 down
}
autoneg_force_mode()
{
local msg
RET=0
ip link set dev $swp1 up
ip link set dev $swp2 up
local -a speeds_arr=($(different_speeds_get $swp1 $swp2 0 0))
local speed1=${speeds_arr[0]}
local speed2=${speeds_arr[1]}
ethtool_set $swp1 speed $speed1 autoneg off
ethtool_set $swp2 speed $speed2 autoneg off
msg=$(busywait $TIMEOUT ethtool_ext_state $swp1 \
"Autoneg" "No partner detected during force mode")
check_err $? "$msg"
msg=$(busywait $TIMEOUT ethtool_ext_state $swp2 \
"Autoneg" "No partner detected during force mode")
check_err $? "$msg"
log_test "Autoneg, No partner detected during force mode"
ethtool -s $swp2 autoneg on
ethtool -s $swp1 autoneg on
ip link set dev $swp2 down
ip link set dev $swp1 down
}
no_cable()
{
local msg
RET=0
ip link set dev $swp3 up
msg=$(busywait $TIMEOUT ethtool_ext_state $swp3 "No cable")
check_err $? "$msg"
log_test "No cable"
ip link set dev $swp3 down
}
setup_prepare
tests_run
exit $EXIT_STATUS