Refactor iperf3 function in runtest.sh for improved argument handling and readability

This commit is contained in:
Yaro Kasear 2025-04-21 13:09:52 -05:00
parent e3c3647a7e
commit 50000ac5c2

View file

@ -109,23 +109,27 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
# iperf3 function # iperf3 function
run_iperf() { run_iperf() {
local target=$1 local target="$1"
local mode=$2 # tcp or udp local mode="$2"
local direction=$3 # up or down local direction="$3"
local args=("-c" "$target" "-J" "-t" "10")
local args="-c $target -J -t $IPERF_DURATION" if [ "$mode" = "udp" ]; then
[ "$mode" = "udp" ] && args="$args -u -b 10M" args+=("-u")
fi
[ "$direction" = "down" ] && args="$args -R" if [ "$direction" = "down" ]; then
args+=("--reverse")
fi
iperf3 $args 2>/dev/null | jq -r ' iperf3 "${args[@]}" 2>/dev/null | jq -r '
if .error then "0" else if .error then "0" else
if .end then if .end then
if .end.sum_received then .end.sum_received.bits_per_second if .end.sum_received then .end.sum_received.bits_per_second
elif .end.sum then .end.sum.bits_per_second elif .end.sum then .end.sum.bits_per_second
else "0" end else "0" end
else "0" end else "0" end
end' end' || echo "0"
} }
echo " Running iperf3 tests..." echo " Running iperf3 tests..."