]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
wireguard: selftests: limit parallelism to $(nproc) tests at once
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 4 May 2022 20:29:16 +0000 (22:29 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 5 May 2022 00:49:56 +0000 (17:49 -0700)
The parallel tests were added to catch queueing issues from multiple
cores. But what happens in reality when testing tons of processes is
that these separate threads wind up fighting with the scheduler, and we
wind up with contention in places we don't care about that decrease the
chances of hitting a bug. So just do a test with the number of CPU
cores, rather than trying to scale up arbitrarily.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/wireguard/netns.sh

index 8a543200a61adcf5e4157c3129dbd97d3ee9e7ca..69c7796c7ca92e80943210f3c4972f813000dbd9 100755 (executable)
 # interfaces in $ns1 and $ns2. See https://www.wireguard.com/netns/ for further
 # details on how this is accomplished.
 set -e
+shopt -s extglob
 
 exec 3>&1
 export LANG=C
 export WG_HIDE_KEYS=never
+NPROC=( /sys/devices/system/cpu/cpu+([0-9]) ); NPROC=${#NPROC[@]}
 netns0="wg-test-$$-0"
 netns1="wg-test-$$-1"
 netns2="wg-test-$$-2"
@@ -143,17 +145,15 @@ tests() {
        n1 iperf3 -Z -t 3 -b 0 -u -c fd00::2
 
        # TCP over IPv4, in parallel
-       for max in 4 5 50; do
-               local pids=( )
-               for ((i=0; i < max; ++i)) do
-                       n2 iperf3 -p $(( 5200 + i )) -s -1 -B 192.168.241.2 &
-                       pids+=( $! ); waitiperf $netns2 $! $(( 5200 + i ))
-               done
-               for ((i=0; i < max; ++i)) do
-                       n1 iperf3 -Z -t 3 -p $(( 5200 + i )) -c 192.168.241.2 &
-               done
-               wait "${pids[@]}"
+       local pids=( ) i
+       for ((i=0; i < NPROC; ++i)) do
+               n2 iperf3 -p $(( 5200 + i )) -s -1 -B 192.168.241.2 &
+               pids+=( $! ); waitiperf $netns2 $! $(( 5200 + i ))
        done
+       for ((i=0; i < NPROC; ++i)) do
+               n1 iperf3 -Z -t 3 -p $(( 5200 + i )) -c 192.168.241.2 &
+       done
+       wait "${pids[@]}"
 }
 
 [[ $(ip1 link show dev wg0) =~ mtu\ ([0-9]+) ]] && orig_mtu="${BASH_REMATCH[1]}"