Skip to contentSkip to conversation

selftests: add a generic testsuite for ethernet device

PATCH New Corentin Labbe 2 participants 7 messages Mar 31, 2017 – Apr 4, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: add a generic testsuite for ethernet device

Hello

My original intent was to add network test to the kernelci project. Since they use kselftests, they forwarded me to this.

This patch add a basic network test suite which do:
- bring up netdev
- change mac address
- try some ethtool commands
- bring down netdev

The test is non disruptive, so that an already used network interface will not be modified (mac/IP address for example).

Regards

Corentin Labbe (1):
selftests: add a generic testsuite for ethernet device

 tools/testing/selftests/net/Makefile     |   2 +-
 tools/testing/selftests/net/netdevice.sh | 185 +++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/netdevice.sh
Signature · 1 line
2.10.2
#1 lore raw

PATCH 1/1 selftests: add a generic testsuite for ethernet device

This patch add a generic testsuite for testing ethernet network device driver.

---
 tools/testing/selftests/net/Makefile     |   2 +-
 tools/testing/selftests/net/netdevice.sh | 185 +++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/netdevice.sh
tools/testing/selftests/net/Makefile +1 -1
index fbfe5d0..35cbb4c 100644
@@ -5,7 +5,7 @@ CFLAGS += -I../../../../usr/include/
 
 reuseport_bpf_numa: LDFLAGS += -lnuma
 
-TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh
+TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh
 TEST_GEN_FILES =  socket
 TEST_GEN_FILES += psock_fanout psock_tpacket
 TEST_GEN_FILES += reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
tools/testing/selftests/net/netdevice.sh new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
2.10.2
#2 lore raw
Quoted 28 lines · Corentin Labbe

This patch add a generic testsuite for testing ethernet network device driver.

---
 tools/testing/selftests/net/Makefile     |   2 +-
 tools/testing/selftests/net/netdevice.sh | 185 +++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/netdevice.sh
tools/testing/selftests/net/Makefile +1 -1
index fbfe5d0..35cbb4c 100644
@@ -5,7 +5,7 @@ CFLAGS += -I../../../../usr/include/
 
 reuseport_bpf_numa: LDFLAGS += -lnuma
 
-TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh
+TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh
 TEST_GEN_FILES =  socket
 TEST_GEN_FILES += psock_fanout psock_tpacket
 TEST_GEN_FILES += reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
tools/testing/selftests/net/netdevice.sh new file +0 -0
new file mode 100755
index 0000000..89ba827

tools/testing/selftests/net/netdevice.sh line 9

Quoted 9 lines
tools/testing/selftests/net/netdevice.sh new file +9 -0
@@ -0,0 +1,185 @@
+#!/bin/sh
+#
+# This test is for checking network interface
+# For the moment it tests only ethernet interface (but wifi could be easily added)
+#
+# We assume that all network driver are loaded
+# if not they probably have failed earlier in the boot process and their logged error will be catched by another test
+#
+

Hi Corentin

Nice to see some basic tests.

Quoted 11 lines
tools/testing/selftests/net/netdevice.sh new file +11 -0
+# this function will try to up the interface
+# if already up, nothing done
+# arg1: network interface name
+kci_net_start()
+{
+	netdev=$1
+
+	ip link show "$netdev" |grep -q UP
+	if [ $? -eq 0 ];then
+		echo "SKIP: interface $netdev already up"
+		return 0

tools/testing/selftests/net/netdevice.sh line 30

Quoted 10 lines
tools/testing/selftests/net/netdevice.sh new file +10 -0
+	fi
+
+	ip link set "$netdev" up
+	if [ $? -ne 0 ];then
+		echo "FAIL: Fail to up $netdev"
+		return 1
+	else
+		echo "PASS: set interface $netdev up"
+		NETDEV_STARTED=1
+	fi

This is going to be problematic.

3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000

    link/ether 8e:01:30:d5:63:ff brd ff:ff:ff:ff:ff:ff
4: lan1@eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 8e:01:30:d5:63:ff brd ff:ff:ff:ff:ff:ff

lan1 has eth1 as its master interface. If you try to up lan1 while eth1 is down:

# ip link set lan1 up
RTNETLINK answers: Network is down

tools/testing/selftests/net/netdevice.sh line 182

Quoted 6 lines
tools/testing/selftests/net/netdevice.sh new file +6 -0
+
+ls /sys/class/net/ |grep -vE '^lo|^tun' | grep -E '^eth|enp[0-9]s[0-9]' > "$TMP_LIST_NETDEV"
+while read netdev
+do
+	kci_test_netdev "$netdev"
+done < "$TMP_LIST_NETDEV"

Because of the grep, on this board, you won't actually test lan1. Which is a shame. It would be nice to test it, and the other interfaces like it.

Rather than going on the order ls gives you, could you order it based on the ifnum? The master has to exist before a slave can be created. Hence the master has a lower ifnum than the slave. So bring the interfaces up in ifnum order, and down in reverse order.

Thanks
Andrew

#3 lore raw
Quoted 88 lines · Andrew Lunn
Quoted 28 lines · Corentin Labbe

This patch add a generic testsuite for testing ethernet network device driver.

---
 tools/testing/selftests/net/Makefile     |   2 +-
 tools/testing/selftests/net/netdevice.sh | 185 +++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/netdevice.sh
tools/testing/selftests/net/Makefile +1 -1
index fbfe5d0..35cbb4c 100644
@@ -5,7 +5,7 @@ CFLAGS += -I../../../../usr/include/
 
 reuseport_bpf_numa: LDFLAGS += -lnuma
 
-TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh
+TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh
 TEST_GEN_FILES =  socket
 TEST_GEN_FILES += psock_fanout psock_tpacket
 TEST_GEN_FILES += reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
tools/testing/selftests/net/netdevice.sh new file +0 -0
new file mode 100755
index 0000000..89ba827

tools/testing/selftests/net/netdevice.sh line 9

Quoted 9 lines
tools/testing/selftests/net/netdevice.sh new file +9 -0
@@ -0,0 +1,185 @@
+#!/bin/sh
+#
+# This test is for checking network interface
+# For the moment it tests only ethernet interface (but wifi could be easily added)
+#
+# We assume that all network driver are loaded
+# if not they probably have failed earlier in the boot process and their logged error will be catched by another test
+#
+

Hi Corentin

Nice to see some basic tests.

Quoted 11 lines
tools/testing/selftests/net/netdevice.sh new file +11 -0
+# this function will try to up the interface
+# if already up, nothing done
+# arg1: network interface name
+kci_net_start()
+{
+	netdev=$1
+
+	ip link show "$netdev" |grep -q UP
+	if [ $? -eq 0 ];then
+		echo "SKIP: interface $netdev already up"
+		return 0

tools/testing/selftests/net/netdevice.sh line 30

Quoted 10 lines
tools/testing/selftests/net/netdevice.sh new file +10 -0
+	fi
+
+	ip link set "$netdev" up
+	if [ $? -ne 0 ];then
+		echo "FAIL: Fail to up $netdev"
+		return 1
+	else
+		echo "PASS: set interface $netdev up"
+		NETDEV_STARTED=1
+	fi

This is going to be problematic.

3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000

    link/ether 8e:01:30:d5:63:ff brd ff:ff:ff:ff:ff:ff
4: lan1@eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 8e:01:30:d5:63:ff brd ff:ff:ff:ff:ff:ff

lan1 has eth1 as its master interface. If you try to up lan1 while eth1 is down:

# ip link set lan1 up
RTNETLINK answers: Network is down

tools/testing/selftests/net/netdevice.sh line 182

Quoted 6 lines
tools/testing/selftests/net/netdevice.sh new file +6 -0
+
+ls /sys/class/net/ |grep -vE '^lo|^tun' | grep -E '^eth|enp[0-9]s[0-9]' > "$TMP_LIST_NETDEV"
+while read netdev
+do
+	kci_test_netdev "$netdev"
+done < "$TMP_LIST_NETDEV"

Because of the grep, on this board, you won't actually test lan1. Which is a shame. It would be nice to test it, and the other interfaces like it.

Quoted 7 lines

Rather than going on the order ls gives you, could you order it based on the ifnum? The master has to exist before a slave can be created. Hence the master has a lower ifnum than the slave. So bring the interfaces up in ifnum order, and down in reverse order.

Thanks
Andrew

By ifnum, you mean by the order that "ip link" gives ?

Regards

#4 lore raw
Quoted 1 line

By ifnum, you mean by the order that "ip link" gives ?

I've not checked if it remains in order as interfaces are hot plugged/unplugged. But i guess you are running tests direct after boot, and unplugs/replugs are unlikely?

Andrew

#5 lore raw
Quoted 6 lines · Andrew Lunn
Quoted 1 line

By ifnum, you mean by the order that "ip link" gives ?

I've not checked if it remains in order as interfaces are hot plugged/unplugged. But i guess you are running tests direct after boot, and unplugs/replugs are unlikely?

Yes the ideal run is just after boot, but the test need to succeed in all case.

For handling vlan, I think the best way is to detect the master interface by looking the "@master". So when testing a vlan interface, the test would just up also the masteri interface.

So I will drop using "ls /sys/clas/net/" and directly use output of ip

Regards

#6 lore raw
Quoted 11 lines · Corentin Labbe
Quoted 6 lines · Andrew Lunn
Quoted 1 line

By ifnum, you mean by the order that "ip link" gives ?

I've not checked if it remains in order as interfaces are hot plugged/unplugged. But i guess you are running tests direct after boot, and unplugs/replugs are unlikely?

Yes the ideal run is just after boot, but the test need to succeed in all case.

For handling vlan, I think the best way is to detect the master interface by looking the "@master".

Hi Corentin

In my case, these are DSA interfaces. Documentation/networking/dsa/dsa.txt

Quoted 1 line

So when testing a vlan interface, the test would just up also the masteri interface.

That will work for DSA.

I know kernelci.org has at least two boards with Ethernet switches that will have such interfaces. So it is great to test them.

Thanks
Andrew