Skip to content

Commit

Permalink
selftests: ethtool: add a netdevsim FEC test
Browse files Browse the repository at this point in the history
Test FEC settings, iterate over configs.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed Mar 31, 2021
1 parent 0d7f76d commit 1da07e5
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ function check {
local code=$1
local str=$2
local exp_str=$3
local exp_fail=$4

if [ $code -ne 0 ]; then
[ -z "$exp_fail" ] && cop="-ne" || cop="-eq"

if [ $code $cop 0 ]; then
((num_errors++))
return
fi
Expand Down
110 changes: 110 additions & 0 deletions tools/testing/selftests/drivers/net/netdevsim/ethtool-fec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only

source ethtool-common.sh

NSIM_NETDEV=$(make_netdev)
[ a$ETHTOOL == a ] && ETHTOOL=ethtool

set -o pipefail

# netdevsim starts out with None/None
s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2)
check $? "$s" "Configured FEC encodings: None
Active FEC encoding: None"

# Test Auto
$ETHTOOL --set-fec $NSIM_NETDEV encoding auto
check $?
s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2)
check $? "$s" "Configured FEC encodings: Auto
Active FEC encoding: Off"

# Test case in-sensitivity
for o in off Off OFF; do
$ETHTOOL --set-fec $NSIM_NETDEV encoding $o
check $?
s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2)
check $? "$s" "Configured FEC encodings: Off
Active FEC encoding: Off"
done

for o in BaseR baser BAser; do
$ETHTOOL --set-fec $NSIM_NETDEV encoding $o
check $?
s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2)
check $? "$s" "Configured FEC encodings: BaseR
Active FEC encoding: BaseR"
done

for o in llrs rs; do
$ETHTOOL --set-fec $NSIM_NETDEV encoding $o
check $?
s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2)
check $? "$s" "Configured FEC encodings: ${o^^}
Active FEC encoding: ${o^^}"
done

# Test mutliple bits
$ETHTOOL --set-fec $NSIM_NETDEV encoding rs llrs
check $?
s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2)
check $? "$s" "Configured FEC encodings: RS LLRS
Active FEC encoding: LLRS"

$ETHTOOL --set-fec $NSIM_NETDEV encoding rs off auto
check $?
s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2)
check $? "$s" "Configured FEC encodings: Auto Off RS
Active FEC encoding: RS"

# Make sure other link modes are rejected
$ETHTOOL --set-fec $NSIM_NETDEV encoding FIBRE 2>/dev/null
check $? '' '' 1

$ETHTOOL --set-fec $NSIM_NETDEV encoding bla-bla-bla 2>/dev/null
check $? '' '' 1

# Try JSON
$ETHTOOL --json --show-fec $NSIM_NETDEV | jq empty >>/dev/null 2>&1
if [ $? -eq 0 ]; then
$ETHTOOL --set-fec $NSIM_NETDEV encoding auto
check $?

s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].config[]')
check $? "$s" '"Auto"'
s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].active[]')
check $? "$s" '"Off"'

$ETHTOOL --set-fec $NSIM_NETDEV encoding auto RS
check $?

s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].config[]')
check $? "$s" '"Auto"
"RS"'
s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].active[]')
check $? "$s" '"RS"'
fi

# Test error injection
echo 11 > $NSIM_DEV_DFS/ethtool/get_err

$ETHTOOL --show-fec $NSIM_NETDEV >>/dev/null 2>&1
check $? '' '' 1

echo 0 > $NSIM_DEV_DFS/ethtool/get_err
echo 11 > $NSIM_DEV_DFS/ethtool/set_err

$ETHTOOL --show-fec $NSIM_NETDEV >>/dev/null 2>&1
check $?

$ETHTOOL --set-fec $NSIM_NETDEV encoding RS 2>/dev/null
check $? '' '' 1

if [ $num_errors -eq 0 ]; then
echo "PASSED all $((num_passes)) checks"
exit 0
else
echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
exit 1
fi

0 comments on commit 1da07e5

Please sign in to comment.