OSDN Git Service

selftests: net: udpgso_bench: Fix racing bug between the rx/tx programs
authorAndrei Gherzan <andrei.gherzan@canonical.com>
Wed, 1 Feb 2023 00:16:14 +0000 (00:16 +0000)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 2 Feb 2023 12:29:51 +0000 (13:29 +0100)
"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>
tools/testing/selftests/net/udpgso_bench.sh

index dc932fd..640bc43 100755 (executable)
@@ -7,6 +7,7 @@ readonly GREEN='\033[0;92m'
 readonly YELLOW='\033[0;33m'
 readonly RED='\033[0;31m'
 readonly NC='\033[0m' # No Color
+readonly TESTPORT=8000
 
 readonly KSFT_PASS=0
 readonly KSFT_FAIL=1
@@ -56,11 +57,26 @@ trap wake_children EXIT
 
 run_one() {
        local -r args=$@
+       local nr_socks=0
+       local i=0
+       local -r timeout=10
+
+       ./udpgso_bench_rx -p "$TESTPORT" &
+       ./udpgso_bench_rx -p "$TESTPORT" -t &
+
+       # Wait for the above test program to get ready to receive connections.
+       while [ "$i" -lt "$timeout" ]; do
+               nr_socks="$(ss -lnHi | grep -c "\*:${TESTPORT}")"
+               [ "$nr_socks" -eq 2 ] && break
+               i=$((i + 1))
+               sleep 1
+       done
+       if [ "$nr_socks" -ne 2 ]; then
+               echo "timed out while waiting for udpgso_bench_rx"
+               exit 1
+       fi
 
-       ./udpgso_bench_rx &
-       ./udpgso_bench_rx -t &
-
-       ./udpgso_bench_tx ${args}
+       ./udpgso_bench_tx -p "$TESTPORT" ${args}
 }
 
 run_in_netns() {