Skip to content

Commit 9af771d

Browse files
Paolo Abenidavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8b325d2 commit 9af771d

File tree

4 files changed

+86
-37
lines changed

4 files changed

+86
-37
lines changed

tools/testing/selftests/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ TEST_PROGS += unicast_extensions.sh
2626
TEST_PROGS += udpgro_fwd.sh
2727
TEST_PROGS += veth.sh
2828
TEST_PROGS += ioam6.sh
29+
TEST_PROGS += gro.sh
2930
TEST_PROGS_EXTENDED := in_netns.sh
3031
TEST_GEN_FILES = socket nettest
3132
TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any

tools/testing/selftests/net/gro.sh

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,14 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
source setup_loopback.sh
54
readonly SERVER_MAC="aa:00:00:00:00:02"
65
readonly CLIENT_MAC="aa:00:00:00:00:01"
76
readonly TESTS=("data" "ack" "flags" "tcp" "ip" "large")
87
readonly PROTOS=("ipv4" "ipv6")
9-
dev="eth0"
8+
dev=""
109
test="all"
1110
proto="ipv4"
1211

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-
4312
run_test() {
4413
local server_pid=0
4514
local exit_code=0
@@ -115,10 +84,12 @@ while getopts "i:t:p:" opt; do
11584
esac
11685
done
11786

118-
readonly FLUSH_PATH="/sys/class/net/${dev}/gro_flush_timeout"
119-
readonly IRQ_PATH="/sys/class/net/${dev}/napi_defer_hard_irqs"
120-
readonly FLUSH_TIMEOUT="$(< ${FLUSH_PATH})"
121-
readonly HARD_IRQS="$(< ${IRQ_PATH})"
87+
if [ -n "$dev" ]; then
88+
source setup_loopback.sh
89+
else
90+
source setup_veth.sh
91+
fi
92+
12293
setup
12394
trap cleanup EXIT
12495
if [[ "${test}" == "all" ]]; then

tools/testing/selftests/net/setup_loopback.sh

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/bash
22
# 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+
39
netdev_check_for_carrier() {
410
local -r dev="$1"
511

@@ -18,7 +24,7 @@ netdev_check_for_carrier() {
1824

1925
# Assumes that there is no existing ipvlan device on the physical device
2026
setup_loopback_environment() {
21-
local dev="$1"
27+
local dev="$1"
2228

2329
# Fail hard if cannot turn on loopback mode for current NIC
2430
ethtool -K "${dev}" loopback on || exit 1
@@ -80,3 +86,33 @@ cleanup_loopback(){
8086
exit 1
8187
fi
8288
}
89+
90+
setup_interrupt() {
91+
# Use timer on host to trigger the network stack
92+
# Also disable device interrupt to not depend on NIC interrupt
93+
# Reduce test flakiness caused by unexpected interrupts
94+
echo 100000 >"${FLUSH_PATH}"
95+
echo 50 >"${IRQ_PATH}"
96+
}
97+
98+
setup_ns() {
99+
# Set up server_ns namespace and client_ns namespace
100+
setup_macvlan_ns "${dev}" server_ns server "${SERVER_MAC}"
101+
setup_macvlan_ns "${dev}" client_ns client "${CLIENT_MAC}"
102+
}
103+
104+
cleanup_ns() {
105+
cleanup_macvlan_ns server_ns server client_ns client
106+
}
107+
108+
setup() {
109+
setup_loopback_environment "${dev}"
110+
setup_interrupt
111+
}
112+
113+
cleanup() {
114+
cleanup_loopback "${dev}"
115+
116+
echo "${FLUSH_TIMEOUT}" >"${FLUSH_PATH}"
117+
echo "${HARD_IRQS}" >"${IRQ_PATH}"
118+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

0 commit comments

Comments
 (0)