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