diff --git a/Runner/suites/Connectivity/WiFi/WiFi_OnOff/run.sh b/Runner/suites/Connectivity/WiFi/WiFi_OnOff/run.sh index d3358bbf..8d805898 100755 --- a/Runner/suites/Connectivity/WiFi/WiFi_OnOff/run.sh +++ b/Runner/suites/Connectivity/WiFi/WiFi_OnOff/run.sh @@ -65,7 +65,7 @@ mhi EOF )" -WIFI_WAIT_SECS="${WIFI_WAIT_SECS:-30}" +WIFI_WAIT_SECS="${WIFI_WAIT_SECS:-60}" WIFI_WAIT_STEP_SECS="${WIFI_WAIT_STEP_SECS:-2}" WIFI_PROBE_LOG_DIR="${WIFI_PROBE_LOG_DIR:-./wifi_onoff_dmesg}" WIFI_PROBE_LOG_TAG="${WIFI_PROBE_LOG_TAG:-${TESTNAME}/probe}" diff --git a/Runner/utils/lib_connectivity.sh b/Runner/utils/lib_connectivity.sh index 2a32a473..d657cbd2 100755 --- a/Runner/utils/lib_connectivity.sh +++ b/Runner/utils/lib_connectivity.sh @@ -15,43 +15,73 @@ wifi_unblock_rfkill() { # Retry WiFi interface discovery for a bounded time while unblocking rfkill. # Prints interface name on success and returns non-zero on timeout. wait_for_wifi_interface() { - max_wait="${1:-30}" + max_wait="${1:-60}" sleep_step="${2:-2}" waited=0 iface="" - + settle_done=0 + case "$max_wait" in ''|*[!0-9]*) - max_wait=30 + max_wait=60 ;; esac - + case "$sleep_step" in ''|*[!0-9]*) sleep_step=2 ;; esac - + if [ "$max_wait" -le 0 ] 2>/dev/null; then - max_wait=30 + max_wait=60 fi + if [ "$sleep_step" -le 0 ] 2>/dev/null; then sleep_step=2 fi - + + # Keep stdout reserved only for the detected interface name because callers + # commonly use command substitution: + # wifi_iface="$(wait_for_wifi_interface ...)" + # + # All diagnostics must go to stderr to avoid contaminating the returned + # interface name. + log_info "Waiting up to ${max_wait}s for WiFi interface creation" >&2 + while [ "$waited" -lt "$max_wait" ]; do wifi_unblock_rfkill - + iface="$(get_wifi_interface 2>/dev/null || true)" if [ -n "$iface" ]; then printf '%s\n' "$iface" return 0 fi - + + if [ "$settle_done" -eq 0 ]; then + settle_done=1 + + if command -v udevadm >/dev/null 2>&1; then + log_info "No WiFi interface yet; triggering net add uevents and waiting for udev settle" >&2 + udevadm trigger --action=add --subsystem-match=net >/dev/null 2>&1 || true + udevadm settle --timeout=5 >/dev/null 2>&1 || true + + iface="$(get_wifi_interface 2>/dev/null || true)" + if [ -n "$iface" ]; then + printf '%s\n' "$iface" + return 0 + fi + fi + fi + sleep "$sleep_step" waited=$((waited + sleep_step)) + + if [ "$waited" -gt 0 ] && [ $((waited % 10)) -eq 0 ]; then + log_info "Still waiting for WiFi interface... waited=${waited}s/${max_wait}s" >&2 + fi done - + return 1 }