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

selftests: net: udpgso_bench: Fix racing bug between the rx/tx programs

"udpgro_bench.sh" invokes udpgso_bench_rx/udpgso_bench_tx programs
subsequently and while doing so, there is a chance that the rx one is not
ready to accept socket connections. This racing bug could fail the test
with at least one of the following:

./udpgso_bench_tx: connect: Connection refused
./udpgso_bench_tx: sendmsg: Connection refused
./udpgso_bench_tx: write: Connection refused

This change addresses this by making udpgro_bench.sh wait for the rx
program to be ready before firing off the tx one - up to a 10s timeout.

Fixes: 3a687bef148d ("selftests: udp gso benchmark")
Signed-off-by: Andrei Gherzan <andrei.gherzan@canonical.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Willem de Bruijn <willemb@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://lore.kernel.org/r/20230201001612.515730-3-andrei.gherzan@canonical.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Andrei Gherzan and committed by
Paolo Abeni
dafe93b9 db9b47ee

+19 -3
+19 -3
tools/testing/selftests/net/udpgso_bench.sh
··· 7 7 readonly YELLOW='\033[0;33m' 8 8 readonly RED='\033[0;31m' 9 9 readonly NC='\033[0m' # No Color 10 + readonly TESTPORT=8000 10 11 11 12 readonly KSFT_PASS=0 12 13 readonly KSFT_FAIL=1 ··· 57 56 58 57 run_one() { 59 58 local -r args=$@ 59 + local nr_socks=0 60 + local i=0 61 + local -r timeout=10 60 62 61 - ./udpgso_bench_rx & 62 - ./udpgso_bench_rx -t & 63 + ./udpgso_bench_rx -p "$TESTPORT" & 64 + ./udpgso_bench_rx -p "$TESTPORT" -t & 63 65 64 - ./udpgso_bench_tx ${args} 66 + # Wait for the above test program to get ready to receive connections. 67 + while [ "$i" -lt "$timeout" ]; do 68 + nr_socks="$(ss -lnHi | grep -c "\*:${TESTPORT}")" 69 + [ "$nr_socks" -eq 2 ] && break 70 + i=$((i + 1)) 71 + sleep 1 72 + done 73 + if [ "$nr_socks" -ne 2 ]; then 74 + echo "timed out while waiting for udpgso_bench_rx" 75 + exit 1 76 + fi 77 + 78 + ./udpgso_bench_tx -p "$TESTPORT" ${args} 65 79 } 66 80 67 81 run_in_netns() {