From 50000ac5c271c20cb7dfb8c1c5dbd94b1ee49b22 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Mon, 21 Apr 2025 13:09:52 -0500 Subject: [PATCH] Refactor iperf3 function in runtest.sh for improved argument handling and readability --- runtest.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/runtest.sh b/runtest.sh index a86ca26..c99b9a5 100755 --- a/runtest.sh +++ b/runtest.sh @@ -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..."