From 26c3927e75710d51ea6091c5caa607787b94efff Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Mon, 21 Apr 2025 13:54:02 -0500 Subject: [PATCH] Improve iperf3 error handling in runtest.sh by capturing stderr and logging detailed error messages --- runtest.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/runtest.sh b/runtest.sh index 419aa9a..ed0b0fb 100755 --- a/runtest.sh +++ b/runtest.sh @@ -110,23 +110,25 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do packet_loss=$(ping -c $PING_COUNT -q $PING_TARGET | grep -oP '\d+(?=% packet loss)') jitter=$(ping -c $PING_COUNT $PING_TARGET | grep "time=" | awk '{print $(NF-1)}' | sed 's/time=//g' | awk '{sum+=$1; sumsq+=$1*$1} END {if (NR>1) print sqrt(sumsq/NR - (sum/NR)**2); else print 0}') - # iperf3 function run_iperf() { 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 - + + local tmp_err + tmp_err=$(mktemp) + local result - result=$(iperf3 "${args[@]}" 2>/dev/null | jq -r ' + result=$(iperf3 "${args[@]}" 2>"$tmp_err" | jq -r ' if .error then "iperf3-error" elif has("end") | not then @@ -138,15 +140,19 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do else "unexpected-format" end' || echo "execution-failed") - + if [[ "$result" == "iperf3-error" || "$result" == "no-end" || "$result" == "unexpected-format" || "$result" == "execution-failed" ]]; then echo "$(date -Iseconds),iperf $mode $direction to $target failed with '$result'" >> "$FAILURE_LOG" - echo "0" # Fallback value for CSV + echo "[stderr] $(cat "$tmp_err")" >> "$FAILURE_LOG" + echo "0" else echo "$result" fi + + rm -f "$tmp_err" } + echo " Running iperf3 tests..." # Run them all. These are in bits per second, convert as needed later.