2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking network interface
5 # For the moment it tests only ethernet interface (but wifi could be easily added)
7 # We assume that all network driver are loaded
8 # if not they probably have failed earlier in the boot process and their logged error will be catched by another test
11 # this function will try to up the interface
12 # if already up, nothing done
13 # arg1: network interface name
18 ip link show
"$netdev" |
grep -q UP
20 echo "SKIP: $netdev: interface already up"
24 ip link
set "$netdev" up
26 echo "FAIL: $netdev: Fail to up interface"
29 echo "PASS: $netdev: set interface up"
35 # this function will try to setup an IP and MAC address on a network interface
36 # Doing nothing if the interface was already up
37 # arg1: network interface name
42 # do nothing if the interface was already up
43 if [ $NETDEV_STARTED -eq 0 ];then
47 MACADDR
='02:03:04:05:06:07'
48 ip link
set dev
$netdev address
"$MACADDR"
50 echo "FAIL: $netdev: Cannot set MAC address"
52 ip link show
$netdev |
grep -q "$MACADDR"
54 echo "PASS: $netdev: set MAC address"
56 echo "FAIL: $netdev: Cannot set MAC address"
60 #check that the interface did not already have an IP
61 ip address show
"$netdev" |
grep '^[[:space:]]*inet'
63 echo "SKIP: $netdev: already have an IP"
67 # TODO what ipaddr to set ? DHCP ?
68 echo "SKIP: $netdev: set IP address"
72 # test an ethtool command
73 # arg1: return code for not supported (see ethtool code source)
74 # arg2: summary of the command
75 # arg3: command to execute
76 kci_netdev_ethtool_test
()
79 echo "SKIP: $netdev: ethtool: invalid number of arguments"
84 if [ $ret -ne 0 ];then
85 if [ $ret -eq "$1" ];then
86 echo "SKIP: $netdev: ethtool $2 not supported"
88 echo "FAIL: $netdev: ethtool $2"
92 echo "PASS: $netdev: ethtool $2"
97 # test ethtool commands
98 # arg1: network interface name
103 #check presence of ethtool
104 ethtool
--version 2>/dev
/null
>/dev
/null
106 echo "SKIP: ethtool not present"
110 TMP_ETHTOOL_FEATURES
="$(mktemp)"
111 if [ ! -e "$TMP_ETHTOOL_FEATURES" ];then
112 echo "SKIP: Cannot create a tmp file"
116 ethtool
-k "$netdev" > "$TMP_ETHTOOL_FEATURES"
118 echo "FAIL: $netdev: ethtool list features"
119 rm "$TMP_ETHTOOL_FEATURES"
122 echo "PASS: $netdev: ethtool list features"
123 #TODO for each non fixed features, try to turn them on/off
124 rm "$TMP_ETHTOOL_FEATURES"
126 kci_netdev_ethtool_test
74 'dump' "ethtool -d $netdev"
127 kci_netdev_ethtool_test
94 'stats' "ethtool -S $netdev"
132 # arg1: network interface name
137 if [ $NETDEV_STARTED -eq 0 ];then
138 echo "SKIP: $netdev: interface kept up"
142 ip link
set "$netdev" down
144 echo "FAIL: $netdev: stop interface"
147 echo "PASS: $netdev: stop interface"
151 # run all test on a netdev
152 # arg1: network interface name
158 #check for VLAN interface
159 MASTER_IFACE
="$(echo $1 | cut -d@ -f2)"
160 if [ ! -z "$MASTER_IFACE" ];then
161 IFACE_TO_UPDOWN
="$MASTER_IFACE"
162 IFACE_TO_TEST
="$(echo $1 | cut -d@ -f1)"
166 kci_net_start
"$IFACE_TO_UPDOWN"
168 kci_net_setup
"$IFACE_TO_TEST"
170 kci_netdev_ethtool
"$IFACE_TO_TEST"
172 kci_netdev_stop
"$IFACE_TO_UPDOWN"
176 #check for needed privileges
177 if [ "$(id -u)" -ne 0 ];then
178 echo "SKIP: Need root privileges"
182 ip link show
2>/dev
/null
>/dev
/null
184 echo "SKIP: Could not run test without the ip tool"
188 TMP_LIST_NETDEV
="$(mktemp)"
189 if [ ! -e "$TMP_LIST_NETDEV" ];then
190 echo "FAIL: Cannot create a tmp file"
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"
197 kci_test_netdev
"$netdev"
198 done < "$TMP_LIST_NETDEV"
200 rm "$TMP_LIST_NETDEV"