Enhance iperf3 error handling in runtest.sh for improved reliability and logging
This commit is contained in:
parent
50000ac5c2
commit
cb3278b280
1 changed files with 27 additions and 12 deletions
33
runtest.sh
33
runtest.sh
|
@ -1,6 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
set x
|
||||
set -euo pipefail
|
||||
trap 'echo "[✖] Execution halted at line $LINENO. An unexpected error occurred. Please contact your nearest bash therapist." >&2' ERR
|
||||
|
||||
IFS=$'\n\t'
|
||||
|
||||
source settings.env
|
||||
|
@ -122,14 +125,26 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
|||
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' || echo "0"
|
||||
local result
|
||||
result=$(iperf3 "${args[@]}" 2>/dev/null | jq -r '
|
||||
if .error then
|
||||
"iperf3-error"
|
||||
elif has("end") | not then
|
||||
"no-end"
|
||||
elif .end | has("sum_received") then
|
||||
.end.sum_received.bits_per_second
|
||||
elif .end | has("sum") then
|
||||
.end.sum.bits_per_second
|
||||
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
|
||||
else
|
||||
echo "$result"
|
||||
fi
|
||||
}
|
||||
|
||||
echo " Running iperf3 tests..."
|
||||
|
@ -149,7 +164,7 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
|||
|
||||
# Log everything
|
||||
echo "$START_TIME,$END_TIME,$link_level_noise,$bssid_and_bitrate,$speed_results,$FAILED_DELTA,$channel,$freq,$packet_loss,$jitter,$LocalTCPUp,$LocalTCPDown,$LocalUDPUp,$LocalUDPDown,$RemoteTCPUp,$RemoteTCPDown,$RemoteUDPUp,$RemoteUDPDown" >> "$TEST_FILE"
|
||||
done
|
||||
done LocalTCPUp, LocalTCPDown, LocalUDPUp, LocalUDPDown, RemoteTCPUp, RemoteTCPDown ,RemoteUDPUp, RemoteUDPDown
|
||||
|
||||
if [ "$COUNTER" -lt "$NUM_TESTS" ]; then
|
||||
echo "Dozing off for $TIME_BETWEEN..."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue