Skip to contentSkip to conversation

selftests: drv-net: add checksum tests

PATCH Applied Willem de Bruijn 2 participants 2 messages May 7, 2024 – May 9, 2024

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

PATCH v3 1/1 selftests: drv-net: add checksum tests

From: Willem de Bruijn <[email protected]>

Run tools/testing/selftest/net/csum.c as part of drv-net. This binary covers multiple scenarios, based on arguments given, for both IPv4 and IPv6:

- Accept UDP correct checksum
- Detect UDP invalid checksum
- Accept TCP correct checksum
- Detect TCP invalid checksum

- Transmit UDP: basic checksum offload
- Transmit UDP: zero checksum conversion

The test direction is reversed between receive and transmit tests, so that the NIC under test is always the local machine.

In total this adds up to 12 testcases, with more to follow. For conciseness, I replaced individual functions with a function factory.

Also detect hardware offload feature availability using Ethtool netlink and skip tests when either feature is off. This need may be common for offload feature tests and eventually deserving of a thin wrapper in lib.py.

Missing are the PF_PACKET based send tests ('-P'). These use virtio_net_hdr to program hardware checksum offload. Which requires looking up the local MAC address and (harder) the MAC of the next hop. I'll have to give it some though how to do that robustly and where that code would belong.

Tested:

        make -C tools/testing/selftests/ \
                TARGETS="drivers/net drivers/net/hw" \
                install INSTALL_PATH=/tmp/ksft
        cd /tmp/ksft

	sudo NETIF=ens4 REMOTE_TYPE=ssh \
		REMOTE_ARGS="[email protected]" \
		LOCAL_V4="10.40.0.1" \
		REMOTE_V4="10.40.0.2" \
		./run_kselftest.sh -t drivers/net/hw:csum.py

---

I think we also want the following for correct line breaks?

+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -42,7 +42,7 @@ class cmd:
if len(stderr) > 0 and stderr[-1] == "\n":
stderr = stderr[:-1]
raise Exception("Command failed: %s\nSTDOUT: %s\nSTDERR: %s" %
- (self.proc.args, stdout, stderr))
+ (self.proc.args, self.stdout, self.stderr))

Changes
- v2->v3
- support NETIF_F_IP_CSUM and NETIF_F_IPV6_CSUM
- minor: fix missing backslash in commit message Tested
- minor: fix inconsistent single vs double quotes
- v1->v2
- remove dependency on tools/testing/selftests/net: move csum
- remove test output from git commit message:
has noisy (expected) failures on test platform after bkg changes

---
 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 .../testing/selftests/drivers/net/hw/csum.py  | 122 ++++++++++++++++++
 tools/testing/selftests/net/.gitignore        |   1 -
 tools/testing/selftests/net/Makefile          |   1 -
 tools/testing/selftests/net/lib/.gitignore    |   2 +
 tools/testing/selftests/net/lib/Makefile      |   7 +
 tools/testing/selftests/net/{ => lib}/csum.c  |   0
 7 files changed, 132 insertions(+), 2 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/hw/csum.py
 create mode 100644 tools/testing/selftests/net/lib/.gitignore
 rename tools/testing/selftests/net/{ => lib}/csum.c (100%)
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index 1dd732855d76..4933d045ab66 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0+ OR MIT
 
 TEST_PROGS = \
+	csum.py \
 	devlink_port_split.py \
 	ethtool.sh \
 	ethtool_extended_state.sh \
tools/testing/selftests/drivers/net/hw/csum.py new file +122 -0

122 lines not on this page · raw message

tools/testing/selftests/net/.gitignore +0 -1
index d996a0ab0765..74ae1068229c 100644
@@ -2,7 +2,6 @@
 bind_bhash
 bind_timewait
 bind_wildcard
-csum
 cmsg_sender
 diag_uid
 fin_ack_lat
tools/testing/selftests/net/Makefile +0 -1
index 5befca249452..052c21438dc4 100644
@@ -81,7 +81,6 @@ TEST_PROGS += test_ingress_egress_chaining.sh
 TEST_GEN_PROGS += so_incoming_cpu
 TEST_PROGS += sctp_vrf.sh
 TEST_GEN_FILES += sctp_hello
-TEST_GEN_FILES += csum
 TEST_GEN_FILES += ip_local_port_range
 TEST_GEN_FILES += bind_wildcard
 TEST_PROGS += test_vxlan_mdb.sh
tools/testing/selftests/net/lib/.gitignore new file +2 -0
new file mode 100644
index 000000000000..1ebc6187f421
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+csum
tools/testing/selftests/net/lib/Makefile +7 -0
index 48557e6250dd..82c3264b115e 100644
@@ -1,8 +1,15 @@
 # SPDX-License-Identifier: GPL-2.0
 
+CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g
+CFLAGS += -I../../../../../usr/include/ $(KHDR_INCLUDES)
+# Additional include paths needed by kselftest.h
+CFLAGS += -I../../
+
 TEST_FILES := ../../../../../Documentation/netlink/specs
 TEST_FILES += ../../../../net/ynl
 
+TEST_GEN_FILES += csum
+
 TEST_INCLUDES := $(wildcard py/*.py)
 
 include ../../lib.mk
tools/testing/selftests/net/lib/csum.c renamed from tools/testing/selftests/net/csum.c +0 -0
similarity index 100%
rename from tools/testing/selftests/net/csum.c
rename to tools/testing/selftests/net/lib/csum.c
Signature · 1 line
2.45.0.rc1.225.g2a3ae87e7f-goog
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 6 lines · On Tue, 7 May 2024 11:40:58 -0400 you wrote:

From: Willem de Bruijn <[email protected]>

Run tools/testing/selftest/net/csum.c as part of drv-net. This binary covers multiple scenarios, based on arguments given, for both IPv4 and IPv6:

Quoted 6 lines

- Accept UDP correct checksum
- Detect UDP invalid checksum
- Accept TCP correct checksum
- Detect TCP invalid checksum

[...]

Here is the summary with links:
- [net-next,v3] selftests: drv-net: add checksum tests

    https://git.kernel.org/netdev/net-next/c/1d0dc857b5d8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html