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..ffccea45 100755 --- a/Runner/utils/lib_connectivity.sh +++ b/Runner/utils/lib_connectivity.sh @@ -19,39 +19,68 @@ wait_for_wifi_interface() { sleep_step="${2:-2}" waited=0 iface="" - + settle_done=0 + case "$max_wait" in ''|*[!0-9]*) max_wait=30 ;; esac - + case "$sleep_step" in ''|*[!0-9]*) sleep_step=2 ;; esac - + if [ "$max_wait" -le 0 ] 2>/dev/null; then max_wait=30 fi if [ "$sleep_step" -le 0 ] 2>/dev/null; then sleep_step=2 fi - - 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 - - sleep "$sleep_step" - waited=$((waited + sleep_step)) - done - + + # Keep stdout reserved for the detected interface name. This helper is + # commonly used through command substitution, so all diagnostics from the + # wait loop must go to stderr. The final interface is printed through fd 3, + # which preserves the caller's original stdout. + { + log_info "Waiting up to ${max_wait}s for WiFi interface creation" + + 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" >&3 + 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 uevents and waiting for udev settle" + udevadm trigger --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" >&3 + 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" + fi + done + } 3>&1 1>&2 + return 1 }