Skip to contentSkip to conversation

selftests: drv-net: add checksum tests

PATCH Superseded Willem de Bruijn 2 participants 4 messages May 1, 2024 – May 2, 2024

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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. It saves a lot of boilerplate, but is a little harder to follow, so partially here as a point for discussion.

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 on Google cloud:

        make -C tools/testing/selftests/ \
                TARGETS="drivers/net drivers/net/hw net" \
                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" \
		LOCAL_V6="<REDACTED>" \
		REMOTE_V6="<REDACTED>" \
		./run_kselftest.sh -t drivers/net/hw:csum.py

	TAP version 13
	1..1
	# timeout set to 0
	# selftests: drivers/net/hw: csum.py
	# KTAP version 1
	# 1..12
	# ok 1 csum.ipv4_rx_tcp
	# ok 2 csum.ipv4_rx_tcp_invalid
	# ok 3 csum.ipv4_rx_udp
	# ok 4 csum.ipv4_rx_udp_invalid
	# ok 5 csum.ipv4_tx_udp_csum_offload
	# ok 6 csum.ipv4_tx_udp_zero_checksum
	# ok 7 csum.ipv6_rx_tcp
	# ok 8 csum.ipv6_rx_tcp_invalid
	# ok 9 csum.ipv6_rx_udp
	# ok 10 csum.ipv6_rx_udp_invalid
	# ok 11 csum.ipv6_tx_udp_csum_offload
	# ok 12 csum.ipv6_tx_udp_zero_checksum
	# # Totals: pass:12 fail:0 xfail:0 xpass:0 skip:0 error:0
	ok 1 selftests: drivers/net/hw: csum.py

Warning that for now transmit errors are not detected, as for those the receiver runs remotely and failures with bkg are ignored.

---
 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 .../testing/selftests/drivers/net/hw/csum.py  | 114 ++++++++++++++++++
 2 files changed, 115 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/hw/csum.py
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 +114 -0

114 lines not on this page · raw message

Signature · 1 line
2.45.0.rc1.225.g2a3ae87e7f-goog
maintainer
#1 lore raw

Great! I run it on a couple of older machines.

mlx5:

TAP version 13
1..1

# timeout set to 0
# selftests: drivers/net/hw: csum.py
# KTAP version 1
# 1..12
# ok 1 csum.ipv4_rx_tcp # SKIP Test requires IPv4 connectivity
# ok 2 csum.ipv4_rx_tcp_invalid # SKIP Test requires IPv4 connectivity
# ok 3 csum.ipv4_rx_udp # SKIP Test requires IPv4 connectivity
# ok 4 csum.ipv4_rx_udp_invalid # SKIP Test requires IPv4 connectivity
# ok 5 csum.ipv4_tx_udp_csum_offload # SKIP Test requires IPv4 connectivity
# ok 6 csum.ipv4_tx_udp_zero_checksum # SKIP Test requires IPv4 connectivity
# ok 7 csum.ipv6_rx_tcp
# ok 8 csum.ipv6_rx_tcp_invalid
# ok 9 csum.ipv6_rx_udp
# ok 10 csum.ipv6_rx_udp_invalid
# ok 11 csum.ipv6_tx_udp_csum_offload
# ok 12 csum.ipv6_tx_udp_zero_checksum
# # Totals: pass:6 fail:0 xfail:0 xpass:0 skip:6 error:0
ok 1 selftests: drivers/net/hw: csum.py

bnxt:

TAP version 13
1..1

# timeout set to 0
# selftests: drivers/net/hw: csum.py
# KTAP version 1
# 1..12
# ok 1 csum.ipv4_rx_tcp # SKIP Test requires IPv4 connectivity
# ok 2 csum.ipv4_rx_tcp_invalid # SKIP Test requires IPv4 connectivity
# ok 3 csum.ipv4_rx_udp # SKIP Test requires IPv4 connectivity
# ok 4 csum.ipv4_rx_udp_invalid # SKIP Test requires IPv4 connectivity
# ok 5 csum.ipv4_tx_udp_csum_offload # SKIP Test requires IPv4 connectivity
# ok 6 csum.ipv4_tx_udp_zero_checksum # SKIP Test requires IPv4 connectivity
# ok 7 csum.ipv6_rx_tcp
# ok 8 csum.ipv6_rx_tcp_invalid
# ok 9 csum.ipv6_rx_udp
# ok 10 csum.ipv6_rx_udp_invalid
# ok 11 csum.ipv6_tx_udp_csum_offload # SKIP Test requires tx checksum offload on eth0
# ok 12 csum.ipv6_tx_udp_zero_checksum # SKIP Test requires tx checksum offload on eth0
# # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:8 error:0
ok 1 selftests: drivers/net/hw: csum.py
Quoted 3 lines · On Wed, 1 May 2024 14:51:34 -0400 Willem de Bruijn wrote:

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:

The use of csum.c is the only real concern I have. Could you move it to net/lib? I made net/lib into an automatically included target in commit b86761ff6374 ("selftests: net: add scaffolding for Netlink tests in Python").

It has a makefile like any selftest directory, so you should be able to do a simple move and minor path adjustments.

Without this if someone builds and deploys just the drivers/net{,/hw} targets the csum binary won't be there :( We could auto-include all of net but using the lib target felt a little cleaner.

Quoted 8 lines

- 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

Quoted 7 lines

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. It saves a lot of boilerplate, but is a little harder to follow, so partially here as a point for discussion.

LGTM, FWIW, but let's hear if anyone feels it's too magical.

Quoted 2 lines

Warning that for now transmit errors are not detected, as for those the receiver runs remotely and failures with bkg are ignored.

Should I send a fix for that?

#2 lore raw
Quoted 39 lines · Jakub Kicinski

Great! I run it on a couple of older machines.

mlx5:

TAP version 13
1..1

# timeout set to 0
# selftests: drivers/net/hw: csum.py
# KTAP version 1
# 1..12
# ok 1 csum.ipv4_rx_tcp # SKIP Test requires IPv4 connectivity
# ok 2 csum.ipv4_rx_tcp_invalid # SKIP Test requires IPv4 connectivity
# ok 3 csum.ipv4_rx_udp # SKIP Test requires IPv4 connectivity
# ok 4 csum.ipv4_rx_udp_invalid # SKIP Test requires IPv4 connectivity
# ok 5 csum.ipv4_tx_udp_csum_offload # SKIP Test requires IPv4 connectivity
# ok 6 csum.ipv4_tx_udp_zero_checksum # SKIP Test requires IPv4 connectivity
# ok 7 csum.ipv6_rx_tcp
# ok 8 csum.ipv6_rx_tcp_invalid
# ok 9 csum.ipv6_rx_udp
# ok 10 csum.ipv6_rx_udp_invalid
# ok 11 csum.ipv6_tx_udp_csum_offload
# ok 12 csum.ipv6_tx_udp_zero_checksum
# # Totals: pass:6 fail:0 xfail:0 xpass:0 skip:6 error:0
ok 1 selftests: drivers/net/hw: csum.py

bnxt:

TAP version 13
1..1

# timeout set to 0
# selftests: drivers/net/hw: csum.py
# KTAP version 1
# 1..12
# ok 1 csum.ipv4_rx_tcp # SKIP Test requires IPv4 connectivity
# ok 2 csum.ipv4_rx_tcp_invalid # SKIP Test requires IPv4 connectivity
# ok 3 csum.ipv4_rx_udp # SKIP Test requires IPv4 connectivity
# ok 4 csum.ipv4_rx_udp_invalid # SKIP Test requires IPv4 connectivity
# ok 5 csum.ipv4_tx_udp_csum_offload # SKIP Test requires IPv4 connectivity
# ok 6 csum.ipv4_tx_udp_zero_checksum # SKIP Test requires IPv4 connectivity
Quoted 8 lines
# ok 7 csum.ipv6_rx_tcp
# ok 8 csum.ipv6_rx_tcp_invalid
# ok 9 csum.ipv6_rx_udp
# ok 10 csum.ipv6_rx_udp_invalid
# ok 11 csum.ipv6_tx_udp_csum_offload # SKIP Test requires tx checksum offload on eth0
# ok 12 csum.ipv6_tx_udp_zero_checksum # SKIP Test requires tx checksum offload on eth0
# # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:8 error:0
ok 1 selftests: drivers/net/hw: csum.py

Nice, thanks for testing!

Quoted 9 lines · On Wed, 1 May 2024 14:51:34 -0400 Willem de Bruijn wrote:
Quoted 3 lines

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:

The use of csum.c is the only real concern I have. Could you move it to net/lib? I made net/lib into an automatically included target in commit b86761ff6374 ("selftests: net: add scaffolding for Netlink tests in Python").

Quoted 6 lines

It has a makefile like any selftest directory, so you should be able to do a simple move and minor path adjustments.

Without this if someone builds and deploys just the drivers/net{,/hw} targets the csum binary won't be there :( We could auto-include all of net but using the lib target felt a little cleaner.

Can do.

A few more may be in scope eventually: toeplitz, udpgso_bench, gro, so_txtime. Move them on a case-by-case basis?

Quoted 16 lines
Quoted 8 lines

- 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

Quoted 7 lines

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. It saves a lot of boilerplate, but is a little harder to follow, so partially here as a point for discussion.

Quoted 6 lines

LGTM, FWIW, but let's hear if anyone feels it's too magical.

Quoted 2 lines

Warning that for now transmit errors are not detected, as for those the receiver runs remotely and failures with bkg are ignored.

Should I send a fix for that?

Please do. I did not grasp your suggestion well enough to take a stab. I may have already spotted the zero conversion test returning success, while explicit logging of the stderr output shows otherwise.

maintainer
#3 lore raw
Quoted 2 lines · On Wed, 01 May 2024 21:38:24 -0400 Willem de Bruijn wrote:

A few more may be in scope eventually: toeplitz, udpgso_bench, gro, so_txtime. Move them on a case-by-case basis?

If you plan to use them all in hw tests - no preference, you can move them all in one fell swoop if you prefer.

Quoted 5 lines
Quoted 1 line

Should I send a fix for that?

Please do. I did not grasp your suggestion well enough to take a stab. I may have already spotted the zero conversion test returning success, while explicit logging of the stderr output shows otherwise.

On it..