Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 3bdd9fd

Browse files
lkarpins-rhdavem330
authored andcommitted
selftests/net: synchronize udpgro tests' tx and rx connection
The sockets used by udpgso_bench_tx aren't always ready when udpgso_bench_tx transmits packets. This issue is more prevalent in -rt kernels, but can occur in both. Replace the hacky sleep calls with a function that checks whether the ports in the namespace are ready for use. Suggested-by: Paolo Abeni <[email protected]> Signed-off-by: Lucas Karpinski <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e47ef9e commit 3bdd9fd

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Helper functions
5+
6+
wait_local_port_listen()
7+
{
8+
local listener_ns="${1}"
9+
local port="${2}"
10+
local protocol="${3}"
11+
local port_hex
12+
local i
13+
14+
port_hex="$(printf "%04X" "${port}")"
15+
for i in $(seq 10); do
16+
if ip netns exec "${listener_ns}" cat /proc/net/"${protocol}"* | \
17+
grep -q "${port_hex}"; then
18+
break
19+
fi
20+
sleep 0.1
21+
done
22+
}

tools/testing/selftests/net/udpgro.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# Run a series of udpgro functional tests.
55

6+
source net_helper.sh
7+
68
readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"
79

810
BPF_FILE="../bpf/xdp_dummy.bpf.o"
@@ -51,8 +53,7 @@ run_one() {
5153
echo "ok" || \
5254
echo "failed" &
5355

54-
# Hack: let bg programs complete the startup
55-
sleep 0.2
56+
wait_local_port_listen ${PEER_NS} 8000 udp
5657
./udpgso_bench_tx ${tx_args}
5758
ret=$?
5859
wait $(jobs -p)
@@ -97,7 +98,7 @@ run_one_nat() {
9798
echo "ok" || \
9899
echo "failed"&
99100

100-
sleep 0.1
101+
wait_local_port_listen "${PEER_NS}" 8000 udp
101102
./udpgso_bench_tx ${tx_args}
102103
ret=$?
103104
kill -INT $pid
@@ -118,11 +119,9 @@ run_one_2sock() {
118119
echo "ok" || \
119120
echo "failed" &
120121

121-
# Hack: let bg programs complete the startup
122-
sleep 0.2
122+
wait_local_port_listen "${PEER_NS}" 12345 udp
123123
./udpgso_bench_tx ${tx_args} -p 12345
124-
sleep 0.1
125-
# first UDP GSO socket should be closed at this point
124+
wait_local_port_listen "${PEER_NS}" 8000 udp
126125
./udpgso_bench_tx ${tx_args}
127126
ret=$?
128127
wait $(jobs -p)

tools/testing/selftests/net/udpgro_bench.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# Run a series of udpgro benchmarks
55

6+
source net_helper.sh
7+
68
readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"
79

810
BPF_FILE="../bpf/xdp_dummy.bpf.o"
@@ -40,8 +42,7 @@ run_one() {
4042
ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r &
4143
ip netns exec "${PEER_NS}" ./udpgso_bench_rx -t ${rx_args} -r &
4244

43-
# Hack: let bg programs complete the startup
44-
sleep 0.2
45+
wait_local_port_listen "${PEER_NS}" 8000 udp
4546
./udpgso_bench_tx ${tx_args}
4647
}
4748

tools/testing/selftests/net/udpgro_frglist.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# Run a series of udpgro benchmarks
55

6+
source net_helper.sh
7+
68
readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"
79

810
BPF_FILE="../bpf/xdp_dummy.bpf.o"
@@ -45,8 +47,7 @@ run_one() {
4547
echo ${rx_args}
4648
ip netns exec "${PEER_NS}" ./udpgso_bench_rx ${rx_args} -r &
4749

48-
# Hack: let bg programs complete the startup
49-
sleep 0.2
50+
wait_local_port_listen "${PEER_NS}" 8000 udp
5051
./udpgso_bench_tx ${tx_args}
5152
}
5253

0 commit comments

Comments
 (0)