Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/net: allow GRO coalesce test on veth

This change extends the existing GRO coalesce test to
allow running on top of a veth pair, so that no H/W dep
is required to run them.

By default gro.sh will use the veth backend, and will try
to use exiting H/W in loopback mode if a specific device
name is provided with the '-i' command line option.

No functional change is intended for the loopback-based
tests, just move all the relevant initialization/cleanup
code into the related script.

Introduces a new initialization helper script for the
veth backend, and plugs the correct helper script according
to the provided command line.

Additionally, enable veth-based tests by default.

v1 -> v2:
- drop unused code in setup_veth_ns() - Willem

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Paolo Abeni and committed by
David S. Miller
9af771d2 8b325d2a

+86 -37
+1
tools/testing/selftests/net/Makefile
··· 26 26 TEST_PROGS += udpgro_fwd.sh 27 27 TEST_PROGS += veth.sh 28 28 TEST_PROGS += ioam6.sh 29 + TEST_PROGS += gro.sh 29 30 TEST_PROGS_EXTENDED := in_netns.sh 30 31 TEST_GEN_FILES = socket nettest 31 32 TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
+7 -36
tools/testing/selftests/net/gro.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 - source setup_loopback.sh 5 4 readonly SERVER_MAC="aa:00:00:00:00:02" 6 5 readonly CLIENT_MAC="aa:00:00:00:00:01" 7 6 readonly TESTS=("data" "ack" "flags" "tcp" "ip" "large") 8 7 readonly PROTOS=("ipv4" "ipv6") 9 - dev="eth0" 8 + dev="" 10 9 test="all" 11 10 proto="ipv4" 12 - 13 - setup_interrupt() { 14 - # Use timer on host to trigger the network stack 15 - # Also disable device interrupt to not depend on NIC interrupt 16 - # Reduce test flakiness caused by unexpected interrupts 17 - echo 100000 >"${FLUSH_PATH}" 18 - echo 50 >"${IRQ_PATH}" 19 - } 20 - 21 - setup_ns() { 22 - # Set up server_ns namespace and client_ns namespace 23 - setup_macvlan_ns "${dev}" server_ns server "${SERVER_MAC}" 24 - setup_macvlan_ns "${dev}" client_ns client "${CLIENT_MAC}" 25 - } 26 - 27 - cleanup_ns() { 28 - cleanup_macvlan_ns server_ns server client_ns client 29 - } 30 - 31 - setup() { 32 - setup_loopback_environment "${dev}" 33 - setup_interrupt 34 - } 35 - 36 - cleanup() { 37 - cleanup_loopback "${dev}" 38 - 39 - echo "${FLUSH_TIMEOUT}" >"${FLUSH_PATH}" 40 - echo "${HARD_IRQS}" >"${IRQ_PATH}" 41 - } 42 11 43 12 run_test() { 44 13 local server_pid=0 ··· 84 115 esac 85 116 done 86 117 87 - readonly FLUSH_PATH="/sys/class/net/${dev}/gro_flush_timeout" 88 - readonly IRQ_PATH="/sys/class/net/${dev}/napi_defer_hard_irqs" 89 - readonly FLUSH_TIMEOUT="$(< ${FLUSH_PATH})" 90 - readonly HARD_IRQS="$(< ${IRQ_PATH})" 118 + if [ -n "$dev" ]; then 119 + source setup_loopback.sh 120 + else 121 + source setup_veth.sh 122 + fi 123 + 91 124 setup 92 125 trap cleanup EXIT 93 126 if [[ "${test}" == "all" ]]; then
+37 -1
tools/testing/selftests/net/setup_loopback.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 + 4 + readonly FLUSH_PATH="/sys/class/net/${dev}/gro_flush_timeout" 5 + readonly IRQ_PATH="/sys/class/net/${dev}/napi_defer_hard_irqs" 6 + readonly FLUSH_TIMEOUT="$(< ${FLUSH_PATH})" 7 + readonly HARD_IRQS="$(< ${IRQ_PATH})" 8 + 3 9 netdev_check_for_carrier() { 4 10 local -r dev="$1" 5 11 ··· 24 18 25 19 # Assumes that there is no existing ipvlan device on the physical device 26 20 setup_loopback_environment() { 27 - local dev="$1" 21 + local dev="$1" 28 22 29 23 # Fail hard if cannot turn on loopback mode for current NIC 30 24 ethtool -K "${dev}" loopback on || exit 1 ··· 85 79 echo "setup_loopback_environment failed" 86 80 exit 1 87 81 fi 82 + } 83 + 84 + setup_interrupt() { 85 + # Use timer on host to trigger the network stack 86 + # Also disable device interrupt to not depend on NIC interrupt 87 + # Reduce test flakiness caused by unexpected interrupts 88 + echo 100000 >"${FLUSH_PATH}" 89 + echo 50 >"${IRQ_PATH}" 90 + } 91 + 92 + setup_ns() { 93 + # Set up server_ns namespace and client_ns namespace 94 + setup_macvlan_ns "${dev}" server_ns server "${SERVER_MAC}" 95 + setup_macvlan_ns "${dev}" client_ns client "${CLIENT_MAC}" 96 + } 97 + 98 + cleanup_ns() { 99 + cleanup_macvlan_ns server_ns server client_ns client 100 + } 101 + 102 + setup() { 103 + setup_loopback_environment "${dev}" 104 + setup_interrupt 105 + } 106 + 107 + cleanup() { 108 + cleanup_loopback "${dev}" 109 + 110 + echo "${FLUSH_TIMEOUT}" >"${FLUSH_PATH}" 111 + echo "${HARD_IRQS}" >"${IRQ_PATH}" 88 112 }
+41
tools/testing/selftests/net/setup_veth.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + setup_veth_ns() { 5 + local -r link_dev="$1" 6 + local -r ns_name="$2" 7 + local -r ns_dev="$3" 8 + local -r ns_mac="$4" 9 + 10 + [[ -e /var/run/netns/"${ns_name}" ]] || ip netns add "${ns_name}" 11 + echo 100000 > "/sys/class/net/${ns_dev}/gro_flush_timeout" 12 + ip link set dev "${ns_dev}" netns "${ns_name}" mtu 65535 13 + ip -netns "${ns_name}" link set dev "${ns_dev}" up 14 + 15 + ip netns exec "${ns_name}" ethtool -K "${ns_dev}" gro on tso off 16 + } 17 + 18 + setup_ns() { 19 + # Set up server_ns namespace and client_ns namespace 20 + ip link add name server type veth peer name client 21 + 22 + setup_veth_ns "${dev}" server_ns server "${SERVER_MAC}" 23 + setup_veth_ns "${dev}" client_ns client "${CLIENT_MAC}" 24 + } 25 + 26 + cleanup_ns() { 27 + local ns_name 28 + 29 + for ns_name in client_ns server_ns; do 30 + [[ -e /var/run/netns/"${ns_name}" ]] && ip netns del "${ns_name}" 31 + done 32 + } 33 + 34 + setup() { 35 + # no global init setup step needed 36 + : 37 + } 38 + 39 + cleanup() { 40 + cleanup_ns 41 + }