WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / ethtool_extended_state.sh
blob4b42dfd4efd1a05bd51738831cac7faf6c30d576
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="
5 autoneg
6 autoneg_force_mode
7 no_cable
10 NUM_NETIFS=2
11 source lib.sh
12 source ethtool_lib.sh
14 setup_prepare()
16 swp1=${NETIFS[p1]}
17 swp2=${NETIFS[p2]}
18 swp3=$NETIF_NO_CABLE
21 ethtool_extended_state_check()
23 local dev=$1; shift
24 local expected_ext_state=$1; shift
25 local expected_ext_substate=${1:-""}; shift
27 local ext_state=$(ethtool $dev | grep "Link detected" \
28 | cut -d "(" -f2 | cut -d ")" -f1)
29 local ext_substate=$(echo $ext_state | cut -sd "," -f2 \
30 | sed -e 's/^[[:space:]]*//')
31 ext_state=$(echo $ext_state | cut -d "," -f1)
33 [[ $ext_state == $expected_ext_state ]]
34 check_err $? "Expected \"$expected_ext_state\", got \"$ext_state\""
36 [[ $ext_substate == $expected_ext_substate ]]
37 check_err $? "Expected \"$expected_ext_substate\", got \"$ext_substate\""
40 autoneg()
42 RET=0
44 ip link set dev $swp1 up
46 sleep 4
47 ethtool_extended_state_check $swp1 "Autoneg" "No partner detected"
49 log_test "Autoneg, No partner detected"
51 ip link set dev $swp1 down
54 autoneg_force_mode()
56 RET=0
58 ip link set dev $swp1 up
59 ip link set dev $swp2 up
61 local -a speeds_arr=($(different_speeds_get $swp1 $swp2 0 0))
62 local speed1=${speeds_arr[0]}
63 local speed2=${speeds_arr[1]}
65 ethtool_set $swp1 speed $speed1 autoneg off
66 ethtool_set $swp2 speed $speed2 autoneg off
68 sleep 4
69 ethtool_extended_state_check $swp1 "Autoneg" \
70 "No partner detected during force mode"
72 ethtool_extended_state_check $swp2 "Autoneg" \
73 "No partner detected during force mode"
75 log_test "Autoneg, No partner detected during force mode"
77 ethtool -s $swp2 autoneg on
78 ethtool -s $swp1 autoneg on
80 ip link set dev $swp2 down
81 ip link set dev $swp1 down
84 no_cable()
86 RET=0
88 ip link set dev $swp3 up
90 sleep 1
91 ethtool_extended_state_check $swp3 "No cable"
93 log_test "No cable"
95 ip link set dev $swp3 down
98 setup_prepare
100 tests_run
102 exit $EXIT_STATUS