~ [ 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 (Architecture mips) and /tools/testing/selftests/net/netdevice.sh (Architecture m68k)


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