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
39
runtest.sh
39
runtest.sh
|
@ -1,6 +1,9 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set x
|
||||||
set -euo pipefail
|
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'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
source settings.env
|
source settings.env
|
||||||
|
@ -113,23 +116,35 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
||||||
local mode="$2"
|
local mode="$2"
|
||||||
local direction="$3"
|
local direction="$3"
|
||||||
local args=("-c" "$target" "-J" "-t" "10")
|
local args=("-c" "$target" "-J" "-t" "10")
|
||||||
|
|
||||||
if [ "$mode" = "udp" ]; then
|
if [ "$mode" = "udp" ]; then
|
||||||
args+=("-u")
|
args+=("-u")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$direction" = "down" ]; then
|
if [ "$direction" = "down" ]; then
|
||||||
args+=("--reverse")
|
args+=("--reverse")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
iperf3 "${args[@]}" 2>/dev/null | jq -r '
|
local result
|
||||||
if .error then "0" else
|
result=$(iperf3 "${args[@]}" 2>/dev/null | jq -r '
|
||||||
if .end then
|
if .error then
|
||||||
if .end.sum_received then .end.sum_received.bits_per_second
|
"iperf3-error"
|
||||||
elif .end.sum then .end.sum.bits_per_second
|
elif has("end") | not then
|
||||||
else "0" end
|
"no-end"
|
||||||
else "0" end
|
elif .end | has("sum_received") then
|
||||||
end' || echo "0"
|
.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..."
|
echo " Running iperf3 tests..."
|
||||||
|
@ -149,7 +164,7 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
||||||
|
|
||||||
# Log everything
|
# 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"
|
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
|
if [ "$COUNTER" -lt "$NUM_TESTS" ]; then
|
||||||
echo "Dozing off for $TIME_BETWEEN..."
|
echo "Dozing off for $TIME_BETWEEN..."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue