Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: ethtool: add a netdevsim FEC test

Test FEC settings, iterate over configs.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
1da07e5d 0d7f76dc

+114 -1
+4 -1
tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
··· 24 24 local code=$1 25 25 local str=$2 26 26 local exp_str=$3 27 + local exp_fail=$4 27 28 28 - if [ $code -ne 0 ]; then 29 + [ -z "$exp_fail" ] && cop="-ne" || cop="-eq" 30 + 31 + if [ $code $cop 0 ]; then 29 32 ((num_errors++)) 30 33 return 31 34 fi
+110
tools/testing/selftests/drivers/net/netdevsim/ethtool-fec.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + source ethtool-common.sh 5 + 6 + NSIM_NETDEV=$(make_netdev) 7 + [ a$ETHTOOL == a ] && ETHTOOL=ethtool 8 + 9 + set -o pipefail 10 + 11 + # netdevsim starts out with None/None 12 + s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 13 + check $? "$s" "Configured FEC encodings: None 14 + Active FEC encoding: None" 15 + 16 + # Test Auto 17 + $ETHTOOL --set-fec $NSIM_NETDEV encoding auto 18 + check $? 19 + s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 20 + check $? "$s" "Configured FEC encodings: Auto 21 + Active FEC encoding: Off" 22 + 23 + # Test case in-sensitivity 24 + for o in off Off OFF; do 25 + $ETHTOOL --set-fec $NSIM_NETDEV encoding $o 26 + check $? 27 + s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 28 + check $? "$s" "Configured FEC encodings: Off 29 + Active FEC encoding: Off" 30 + done 31 + 32 + for o in BaseR baser BAser; do 33 + $ETHTOOL --set-fec $NSIM_NETDEV encoding $o 34 + check $? 35 + s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 36 + check $? "$s" "Configured FEC encodings: BaseR 37 + Active FEC encoding: BaseR" 38 + done 39 + 40 + for o in llrs rs; do 41 + $ETHTOOL --set-fec $NSIM_NETDEV encoding $o 42 + check $? 43 + s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 44 + check $? "$s" "Configured FEC encodings: ${o^^} 45 + Active FEC encoding: ${o^^}" 46 + done 47 + 48 + # Test mutliple bits 49 + $ETHTOOL --set-fec $NSIM_NETDEV encoding rs llrs 50 + check $? 51 + s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 52 + check $? "$s" "Configured FEC encodings: RS LLRS 53 + Active FEC encoding: LLRS" 54 + 55 + $ETHTOOL --set-fec $NSIM_NETDEV encoding rs off auto 56 + check $? 57 + s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 58 + check $? "$s" "Configured FEC encodings: Auto Off RS 59 + Active FEC encoding: RS" 60 + 61 + # Make sure other link modes are rejected 62 + $ETHTOOL --set-fec $NSIM_NETDEV encoding FIBRE 2>/dev/null 63 + check $? '' '' 1 64 + 65 + $ETHTOOL --set-fec $NSIM_NETDEV encoding bla-bla-bla 2>/dev/null 66 + check $? '' '' 1 67 + 68 + # Try JSON 69 + $ETHTOOL --json --show-fec $NSIM_NETDEV | jq empty >>/dev/null 2>&1 70 + if [ $? -eq 0 ]; then 71 + $ETHTOOL --set-fec $NSIM_NETDEV encoding auto 72 + check $? 73 + 74 + s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].config[]') 75 + check $? "$s" '"Auto"' 76 + s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].active[]') 77 + check $? "$s" '"Off"' 78 + 79 + $ETHTOOL --set-fec $NSIM_NETDEV encoding auto RS 80 + check $? 81 + 82 + s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].config[]') 83 + check $? "$s" '"Auto" 84 + "RS"' 85 + s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].active[]') 86 + check $? "$s" '"RS"' 87 + fi 88 + 89 + # Test error injection 90 + echo 11 > $NSIM_DEV_DFS/ethtool/get_err 91 + 92 + $ETHTOOL --show-fec $NSIM_NETDEV >>/dev/null 2>&1 93 + check $? '' '' 1 94 + 95 + echo 0 > $NSIM_DEV_DFS/ethtool/get_err 96 + echo 11 > $NSIM_DEV_DFS/ethtool/set_err 97 + 98 + $ETHTOOL --show-fec $NSIM_NETDEV >>/dev/null 2>&1 99 + check $? 100 + 101 + $ETHTOOL --set-fec $NSIM_NETDEV encoding RS 2>/dev/null 102 + check $? '' '' 1 103 + 104 + if [ $num_errors -eq 0 ]; then 105 + echo "PASSED all $((num_passes)) checks" 106 + exit 0 107 + else 108 + echo "FAILED $num_errors/$((num_errors+num_passes)) checks" 109 + exit 1 110 + fi