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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/netdevice.sh

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/net/netdevice.sh (Version linux-6.11.5) and /tools/testing/selftests/net/netdevice.sh (Version linux-4.17.19)


  1 #!/bin/sh                                           1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3 #                                                   3 #
  4 # This test is for checking network interface       4 # This test is for checking network interface
  5 # For the moment it tests only ethernet interf      5 # For the moment it tests only ethernet interface (but wifi could be easily added)
  6 #                                                   6 #
  7 # We assume that all network driver are loaded      7 # We assume that all network driver are loaded
  8 # if not they probably have failed earlier in       8 # if not they probably have failed earlier in the boot process and their logged error will be catched by another test
  9 #                                                   9 #
 10                                                    10 
 11 # Kselftest framework requirement - SKIP code  << 
 12 ksft_skip=4                                    << 
 13                                                << 
 14 # this function will try to up the interface       11 # this function will try to up the interface
 15 # if already up, nothing done                      12 # if already up, nothing done
 16 # arg1: network interface name                     13 # arg1: network interface name
 17 kci_net_start()                                    14 kci_net_start()
 18 {                                                  15 {
 19         netdev=$1                                  16         netdev=$1
 20                                                    17 
 21         ip link show "$netdev" |grep -q UP         18         ip link show "$netdev" |grep -q UP
 22         if [ $? -eq 0 ];then                       19         if [ $? -eq 0 ];then
 23                 echo "SKIP: $netdev: interface     20                 echo "SKIP: $netdev: interface already up"
 24                 return $ksft_skip              !!  21                 return 0
 25         fi                                         22         fi
 26                                                    23 
 27         ip link set "$netdev" up                   24         ip link set "$netdev" up
 28         if [ $? -ne 0 ];then                       25         if [ $? -ne 0 ];then
 29                 echo "FAIL: $netdev: Fail to u     26                 echo "FAIL: $netdev: Fail to up interface"
 30                 return 1                           27                 return 1
 31         else                                       28         else
 32                 echo "PASS: $netdev: set inter     29                 echo "PASS: $netdev: set interface up"
 33                 NETDEV_STARTED=1                   30                 NETDEV_STARTED=1
 34         fi                                         31         fi
 35         return 0                                   32         return 0
 36 }                                                  33 }
 37                                                    34 
 38 # this function will try to setup an IP and MA     35 # this function will try to setup an IP and MAC address on a network interface
 39 # Doing nothing if the interface was already u     36 # Doing nothing if the interface was already up
 40 # arg1: network interface name                     37 # arg1: network interface name
 41 kci_net_setup()                                    38 kci_net_setup()
 42 {                                                  39 {
 43         netdev=$1                                  40         netdev=$1
 44                                                    41 
 45         # do nothing if the interface was alre     42         # do nothing if the interface was already up
 46         if [ $NETDEV_STARTED -eq 0 ];then          43         if [ $NETDEV_STARTED -eq 0 ];then
 47                 return 0                           44                 return 0
 48         fi                                         45         fi
 49                                                    46 
 50         MACADDR='02:03:04:05:06:07'                47         MACADDR='02:03:04:05:06:07'
 51         ip link set dev $netdev address "$MACA     48         ip link set dev $netdev address "$MACADDR"
 52         if [ $? -ne 0 ];then                       49         if [ $? -ne 0 ];then
 53                 echo "FAIL: $netdev: Cannot se     50                 echo "FAIL: $netdev: Cannot set MAC address"
 54         else                                       51         else
 55                 ip link show $netdev |grep -q      52                 ip link show $netdev |grep -q "$MACADDR"
 56                 if [ $? -eq 0 ];then               53                 if [ $? -eq 0 ];then
 57                         echo "PASS: $netdev: s     54                         echo "PASS: $netdev: set MAC address"
 58                 else                               55                 else
 59                         echo "FAIL: $netdev: C     56                         echo "FAIL: $netdev: Cannot set MAC address"
 60                 fi                                 57                 fi
 61         fi                                         58         fi
 62                                                    59 
 63         #check that the interface did not alre     60         #check that the interface did not already have an IP
 64         ip address show "$netdev" |grep '^[[:s     61         ip address show "$netdev" |grep '^[[:space:]]*inet'
 65         if [ $? -eq 0 ];then                       62         if [ $? -eq 0 ];then
 66                 echo "SKIP: $netdev: already h     63                 echo "SKIP: $netdev: already have an IP"
 67                 return $ksft_skip              !!  64                 return 0
 68         fi                                         65         fi
 69                                                    66 
 70         # TODO what ipaddr to set ? DHCP ?         67         # TODO what ipaddr to set ? DHCP ?
 71         echo "SKIP: $netdev: set IP address"       68         echo "SKIP: $netdev: set IP address"
 72         return $ksft_skip                      !!  69         return 0
 73 }                                                  70 }
 74                                                    71 
 75 # test an ethtool command                          72 # test an ethtool command
 76 # arg1: return code for not supported (see eth     73 # arg1: return code for not supported (see ethtool code source)
 77 # arg2: summary of the command                     74 # arg2: summary of the command
 78 # arg3: command to execute                         75 # arg3: command to execute
 79 kci_netdev_ethtool_test()                          76 kci_netdev_ethtool_test()
 80 {                                                  77 {
 81         if [ $# -le 2 ];then                       78         if [ $# -le 2 ];then
 82                 echo "SKIP: $netdev: ethtool:      79                 echo "SKIP: $netdev: ethtool: invalid number of arguments"
 83                 return 1                           80                 return 1
 84         fi                                         81         fi
 85         $3 >/dev/null                              82         $3 >/dev/null
 86         ret=$?                                     83         ret=$?
 87         if [ $ret -ne 0 ];then                     84         if [ $ret -ne 0 ];then
 88                 if [ $ret -eq "$1" ];then          85                 if [ $ret -eq "$1" ];then
 89                         echo "SKIP: $netdev: e     86                         echo "SKIP: $netdev: ethtool $2 not supported"
 90                         return $ksft_skip      << 
 91                 else                               87                 else
 92                         echo "FAIL: $netdev: e     88                         echo "FAIL: $netdev: ethtool $2"
 93                         return 1                   89                         return 1
 94                 fi                                 90                 fi
 95         else                                       91         else
 96                 echo "PASS: $netdev: ethtool $     92                 echo "PASS: $netdev: ethtool $2"
 97         fi                                         93         fi
 98         return 0                                   94         return 0
 99 }                                                  95 }
100                                                    96 
101 # test ethtool commands                            97 # test ethtool commands
102 # arg1: network interface name                     98 # arg1: network interface name
103 kci_netdev_ethtool()                               99 kci_netdev_ethtool()
104 {                                                 100 {
105         netdev=$1                                 101         netdev=$1
106                                                   102 
107         #check presence of ethtool                103         #check presence of ethtool
108         ethtool --version 2>/dev/null >/dev/nu    104         ethtool --version 2>/dev/null >/dev/null
109         if [ $? -ne 0 ];then                      105         if [ $? -ne 0 ];then
110                 echo "SKIP: ethtool not presen    106                 echo "SKIP: ethtool not present"
111                 return $ksft_skip              !! 107                 return 1
112         fi                                        108         fi
113                                                   109 
114         TMP_ETHTOOL_FEATURES="$(mktemp)"          110         TMP_ETHTOOL_FEATURES="$(mktemp)"
115         if [ ! -e "$TMP_ETHTOOL_FEATURES" ];th    111         if [ ! -e "$TMP_ETHTOOL_FEATURES" ];then
116                 echo "SKIP: Cannot create a tm    112                 echo "SKIP: Cannot create a tmp file"
117                 return 1                          113                 return 1
118         fi                                        114         fi
119                                                   115 
120         ethtool -k "$netdev" > "$TMP_ETHTOOL_F    116         ethtool -k "$netdev" > "$TMP_ETHTOOL_FEATURES"
121         if [ $? -ne 0 ];then                      117         if [ $? -ne 0 ];then
122                 echo "FAIL: $netdev: ethtool l    118                 echo "FAIL: $netdev: ethtool list features"
123                 rm "$TMP_ETHTOOL_FEATURES"        119                 rm "$TMP_ETHTOOL_FEATURES"
124                 return 1                          120                 return 1
125         fi                                        121         fi
126         echo "PASS: $netdev: ethtool list feat    122         echo "PASS: $netdev: ethtool list features"
127         #TODO for each non fixed features, try    123         #TODO for each non fixed features, try to turn them on/off
128         rm "$TMP_ETHTOOL_FEATURES"                124         rm "$TMP_ETHTOOL_FEATURES"
129                                                   125 
130         kci_netdev_ethtool_test 74 'dump' "eth    126         kci_netdev_ethtool_test 74 'dump' "ethtool -d $netdev"
131         kci_netdev_ethtool_test 94 'stats' "et    127         kci_netdev_ethtool_test 94 'stats' "ethtool -S $netdev"
132         return 0                                  128         return 0
133 }                                                 129 }
134                                                   130 
135 # stop a netdev                                   131 # stop a netdev
136 # arg1: network interface name                    132 # arg1: network interface name
137 kci_netdev_stop()                                 133 kci_netdev_stop()
138 {                                                 134 {
139         netdev=$1                                 135         netdev=$1
140                                                   136 
141         if [ $NETDEV_STARTED -eq 0 ];then         137         if [ $NETDEV_STARTED -eq 0 ];then
142                 echo "SKIP: $netdev: interface    138                 echo "SKIP: $netdev: interface kept up"
143                 return 0                          139                 return 0
144         fi                                        140         fi
145                                                   141 
146         ip link set "$netdev" down                142         ip link set "$netdev" down
147         if [ $? -ne 0 ];then                      143         if [ $? -ne 0 ];then
148                 echo "FAIL: $netdev: stop inte    144                 echo "FAIL: $netdev: stop interface"
149                 return 1                          145                 return 1
150         fi                                        146         fi
151         echo "PASS: $netdev: stop interface"      147         echo "PASS: $netdev: stop interface"
152         return 0                                  148         return 0
153 }                                                 149 }
154                                                   150 
155 # run all test on a netdev                        151 # run all test on a netdev
156 # arg1: network interface name                    152 # arg1: network interface name
157 kci_test_netdev()                                 153 kci_test_netdev()
158 {                                                 154 {
159         NETDEV_STARTED=0                          155         NETDEV_STARTED=0
160         IFACE_TO_UPDOWN="$1"                      156         IFACE_TO_UPDOWN="$1"
161         IFACE_TO_TEST="$1"                        157         IFACE_TO_TEST="$1"
162         #check for VLAN interface                 158         #check for VLAN interface
163         MASTER_IFACE="$(echo $1 | cut -d@ -f2)    159         MASTER_IFACE="$(echo $1 | cut -d@ -f2)"
164         if [ ! -z "$MASTER_IFACE" ];then          160         if [ ! -z "$MASTER_IFACE" ];then
165                 IFACE_TO_UPDOWN="$MASTER_IFACE    161                 IFACE_TO_UPDOWN="$MASTER_IFACE"
166                 IFACE_TO_TEST="$(echo $1 | cut    162                 IFACE_TO_TEST="$(echo $1 | cut -d@ -f1)"
167         fi                                        163         fi
168                                                   164 
169         NETDEV_STARTED=0                          165         NETDEV_STARTED=0
170         kci_net_start "$IFACE_TO_UPDOWN"          166         kci_net_start "$IFACE_TO_UPDOWN"
171                                                   167 
172         kci_net_setup "$IFACE_TO_TEST"            168         kci_net_setup "$IFACE_TO_TEST"
173                                                   169 
174         kci_netdev_ethtool "$IFACE_TO_TEST"       170         kci_netdev_ethtool "$IFACE_TO_TEST"
175                                                   171 
176         kci_netdev_stop "$IFACE_TO_UPDOWN"        172         kci_netdev_stop "$IFACE_TO_UPDOWN"
177         return 0                                  173         return 0
178 }                                                 174 }
179                                                   175 
180 #check for needed privileges                      176 #check for needed privileges
181 if [ "$(id -u)" -ne 0 ];then                      177 if [ "$(id -u)" -ne 0 ];then
182         echo "SKIP: Need root privileges"         178         echo "SKIP: Need root privileges"
183         exit $ksft_skip                        !! 179         exit 0
184 fi                                                180 fi
185                                                   181 
186 ip link show 2>/dev/null >/dev/null               182 ip link show 2>/dev/null >/dev/null
187 if [ $? -ne 0 ];then                              183 if [ $? -ne 0 ];then
188         echo "SKIP: Could not run test without    184         echo "SKIP: Could not run test without the ip tool"
189         exit $ksft_skip                        !! 185         exit 0
190 fi                                                186 fi
191                                                   187 
192 TMP_LIST_NETDEV="$(mktemp)"                       188 TMP_LIST_NETDEV="$(mktemp)"
193 if [ ! -e "$TMP_LIST_NETDEV" ];then               189 if [ ! -e "$TMP_LIST_NETDEV" ];then
194         echo "FAIL: Cannot create a tmp file"     190         echo "FAIL: Cannot create a tmp file"
195         exit 1                                    191         exit 1
196 fi                                                192 fi
197                                                   193 
198 ip link show |grep '^[0-9]' | grep -oE '[[:spa    194 ip link show |grep '^[0-9]' | grep -oE '[[:space:]].*eth[0-9]*:|[[:space:]].*enp[0-9]s[0-9]:' | cut -d\  -f2 | cut -d: -f1> "$TMP_LIST_NETDEV"
199 while read netdev                                 195 while read netdev
200 do                                                196 do
201         kci_test_netdev "$netdev"                 197         kci_test_netdev "$netdev"
202 done < "$TMP_LIST_NETDEV"                         198 done < "$TMP_LIST_NETDEV"
203                                                   199 
204 rm "$TMP_LIST_NETDEV"                             200 rm "$TMP_LIST_NETDEV"
205 exit 0                                            201 exit 0
                                                      

~ [ 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