diff --git a/runtest.sh b/runtest.sh index c99b9a5..419aa9a 100755 --- a/runtest.sh +++ b/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 @@ -113,23 +116,35 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do 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' || 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..."