~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/drivers/net/hw/ethtool_extended_state.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 ALL_TESTS="
  5         autoneg
  6         autoneg_force_mode
  7         no_cable
  8 "
  9 
 10 NUM_NETIFS=2
 11 lib_dir=$(dirname "$0")
 12 source "$lib_dir"/../../../net/forwarding/lib.sh
 13 source ethtool_lib.sh
 14 
 15 TIMEOUT=$((WAIT_TIMEOUT * 1000)) # ms
 16 
 17 setup_prepare()
 18 {
 19         swp1=${NETIFS[p1]}
 20         swp2=${NETIFS[p2]}
 21         swp3=$NETIF_NO_CABLE
 22 }
 23 
 24 ethtool_ext_state()
 25 {
 26         local dev=$1; shift
 27         local expected_ext_state=$1; shift
 28         local expected_ext_substate=${1:-""}; shift
 29 
 30         local ext_state=$(ethtool $dev | grep "Link detected" \
 31                 | cut -d "(" -f2 | cut -d ")" -f1)
 32         local ext_substate=$(echo $ext_state | cut -sd "," -f2 \
 33                 | sed -e 's/^[[:space:]]*//')
 34         ext_state=$(echo $ext_state | cut -d "," -f1)
 35 
 36         if [[ $ext_state != $expected_ext_state ]]; then
 37                 echo "Expected \"$expected_ext_state\", got \"$ext_state\""
 38                 return 1
 39         fi
 40         if [[ $ext_substate != $expected_ext_substate ]]; then
 41                 echo "Expected \"$expected_ext_substate\", got \"$ext_substate\""
 42                 return 1
 43         fi
 44 }
 45 
 46 autoneg()
 47 {
 48         local msg
 49 
 50         RET=0
 51 
 52         ip link set dev $swp1 up
 53 
 54         msg=$(busywait $TIMEOUT ethtool_ext_state $swp1 \
 55                         "Autoneg" "No partner detected")
 56         check_err $? "$msg"
 57 
 58         log_test "Autoneg, No partner detected"
 59 
 60         ip link set dev $swp1 down
 61 }
 62 
 63 autoneg_force_mode()
 64 {
 65         local msg
 66 
 67         RET=0
 68 
 69         ip link set dev $swp1 up
 70         ip link set dev $swp2 up
 71 
 72         local -a speeds_arr=($(different_speeds_get $swp1 $swp2 0 0))
 73         local speed1=${speeds_arr[0]}
 74         local speed2=${speeds_arr[1]}
 75 
 76         ethtool_set $swp1 speed $speed1 autoneg off
 77         ethtool_set $swp2 speed $speed2 autoneg off
 78 
 79         msg=$(busywait $TIMEOUT ethtool_ext_state $swp1 \
 80                         "Autoneg" "No partner detected during force mode")
 81         check_err $? "$msg"
 82 
 83         msg=$(busywait $TIMEOUT ethtool_ext_state $swp2 \
 84                         "Autoneg" "No partner detected during force mode")
 85         check_err $? "$msg"
 86 
 87         log_test "Autoneg, No partner detected during force mode"
 88 
 89         ethtool -s $swp2 autoneg on
 90         ethtool -s $swp1 autoneg on
 91 
 92         ip link set dev $swp2 down
 93         ip link set dev $swp1 down
 94 }
 95 
 96 no_cable()
 97 {
 98         local msg
 99 
100         RET=0
101 
102         ip link set dev $swp3 up
103 
104         msg=$(busywait $TIMEOUT ethtool_ext_state $swp3 "No cable")
105         check_err $? "$msg"
106 
107         log_test "No cable"
108 
109         ip link set dev $swp3 down
110 }
111 
112 setup_prepare
113 
114 tests_run
115 
116 exit $EXIT_STATUS

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php