]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - tools/testing/selftests/net/netdevice.sh
3 # This test is for checking network interface
4 # For the moment it tests only ethernet interface (but wifi could be easily added)
6 # We assume that all network driver are loaded
7 # if not they probably have failed earlier in the boot process and their logged error will be catched by another test
10 # this function will try to up the interface
11 # if already up, nothing done
12 # arg1: network interface name
17 ip link show
"$netdev" |
grep -q UP
19 echo "SKIP: $netdev: interface already up"
23 ip link
set "$netdev" up
25 echo "FAIL: $netdev: Fail to up interface"
28 echo "PASS: $netdev: set interface up"
34 # this function will try to setup an IP and MAC address on a network interface
35 # Doing nothing if the interface was already up
36 # arg1: network interface name
41 # do nothing if the interface was already up
42 if [ $NETDEV_STARTED -eq 0 ];then
46 MACADDR
='02:03:04:05:06:07'
47 ip link
set dev
$netdev address
"$MACADDR"
49 echo "FAIL: $netdev: Cannot set MAC address"
51 ip link show
$netdev |
grep -q "$MACADDR"
53 echo "PASS: $netdev: set MAC address"
55 echo "FAIL: $netdev: Cannot set MAC address"
59 #check that the interface did not already have an IP
60 ip address show
"$netdev" |
grep '^[[:space:]]*inet'
62 echo "SKIP: $netdev: already have an IP"
66 # TODO what ipaddr to set ? DHCP ?
67 echo "SKIP: $netdev: set IP address"
71 # test an ethtool command
72 # arg1: return code for not supported (see ethtool code source)
73 # arg2: summary of the command
74 # arg3: command to execute
75 kci_netdev_ethtool_test
()
78 echo "SKIP: $netdev: ethtool: invalid number of arguments"
83 if [ $ret -ne 0 ];then
84 if [ $ret -eq "$1" ];then
85 echo "SKIP: $netdev: ethtool $2 not supported"
87 echo "FAIL: $netdev: ethtool $2"
91 echo "PASS: $netdev: ethtool $2"
96 # test ethtool commands
97 # arg1: network interface name
102 #check presence of ethtool
103 ethtool
--version 2>/dev
/null
>/dev
/null
105 echo "SKIP: ethtool not present"
109 TMP_ETHTOOL_FEATURES
="$(mktemp)"
110 if [ ! -e "$TMP_ETHTOOL_FEATURES" ];then
111 echo "SKIP: Cannot create a tmp file"
115 ethtool
-k "$netdev" > "$TMP_ETHTOOL_FEATURES"
117 echo "FAIL: $netdev: ethtool list features"
118 rm "$TMP_ETHTOOL_FEATURES"
121 echo "PASS: $netdev: ethtool list features"
122 #TODO for each non fixed features, try to turn them on/off
123 rm "$TMP_ETHTOOL_FEATURES"
125 kci_netdev_ethtool_test
74 'dump' "ethtool -d $netdev"
126 kci_netdev_ethtool_test
94 'stats' "ethtool -S $netdev"
131 # arg1: network interface name
136 if [ $NETDEV_STARTED -eq 0 ];then
137 echo "SKIP: $netdev: interface kept up"
141 ip link
set "$netdev" down
143 echo "FAIL: $netdev: stop interface"
146 echo "PASS: $netdev: stop interface"
150 # run all test on a netdev
151 # arg1: network interface name
157 #check for VLAN interface
158 MASTER_IFACE
="$(echo $1 | cut -d@ -f2)"
159 if [ ! -z "$MASTER_IFACE" ];then
160 IFACE_TO_UPDOWN
="$MASTER_IFACE"
161 IFACE_TO_TEST
="$(echo $1 | cut -d@ -f1)"
165 kci_net_start
"$IFACE_TO_UPDOWN"
167 kci_net_setup
"$IFACE_TO_TEST"
169 kci_netdev_ethtool
"$IFACE_TO_TEST"
171 kci_netdev_stop
"$IFACE_TO_UPDOWN"
175 #check for needed privileges
176 if [ "$(id -u)" -ne 0 ];then
177 echo "SKIP: Need root privileges"
181 ip link show
2>/dev
/null
>/dev
/null
183 echo "SKIP: Could not run test without the ip tool"
187 TMP_LIST_NETDEV
="$(mktemp)"
188 if [ ! -e "$TMP_LIST_NETDEV" ];then
189 echo "FAIL: Cannot create a tmp file"
193 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"
196 kci_test_netdev
"$netdev"
197 done < "$TMP_LIST_NETDEV"
199 rm "$TMP_LIST_NETDEV"