Skip to content

Add WiFi Connectivity Validation with Hybrid nmcli and wpa_supplicant Support #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
SPDX-License-Identifier: BSD-3-Clause-Clear

# WiFi Connectivity Validation

## 📋 Overview

This test validates WiFi functionality by:

- Connecting to an access point (AP) using either `nmcli` or `wpa_supplicant`.
- Verifying IP acquisition via DHCP.
- Checking internet connectivity with a `ping` test.
- Handling systemd network service status.
- Supporting flexible SSID/password input via arguments, environment, or file.

## ✅ SSID/PASSWORD Input Priority (Hybrid Approach)

1. **Command-line arguments**:
```sh
./run.sh "MySSID" "MyPassword"
```

2. **Environment variables**:
```sh
SSID_ENV=MySSID PASSWORD_ENV=MyPassword ./run.sh
```

3. **Fallback to `ssid_list.txt` file** (if above not set):
```txt
MySSID MyPassword
```

## ⚙️ Supported Tools

- Primary: `nmcli`
- Fallback: `wpa_supplicant`, `udhcpc`, `ifconfig`

Ensure these tools are available in the system before running the test. Missing tools are detected and logged as skipped/failure.

## 🧪 Test Flow

1. **Dependency check** – verifies necessary binaries are present.
2. **Systemd services check** – attempts to start network services if inactive.
3. **WiFi connect (nmcli or wpa_supplicant)** – based on tool availability.
4. **IP assignment check** – validates `ifconfig wlan0` output.
5. **Internet test** – pings `8.8.8.8` to confirm outbound reachability.
6. **Result logging** – writes `.res` file and logs all actions.

## 🧾 Output

- `WiFi_Connectivity.res`: Contains `WiFi_Connectivity PASS` or `FAIL`.
- Logs are printed using `log_info`, `log_pass`, and `log_fail` from `functestlib.sh`.

## 📂 Directory Structure

```
WiFi/
├── run.sh
├── ssid_list.txt (optional)
├── README.md
```

## 🌐 Integration (meta-qcom_PreMerge.yaml)

Add this test with SSID parameters as follows:

```yaml
- name: WiFi_Connectivity
path: Runner/suites/Connectivity/WiFi
timeout:
minutes: 5
params:
SSID_ENV: "xxxx"
PASSWORD_ENV: "xxxx"
```
75 changes: 75 additions & 0 deletions Runner/suites/Connectivity/WiFi/WiFi_Dynamic_IP/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/sh

# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear

# Robustly find and source init_env
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"
while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

# shellcheck disable=SC1090
if [ -z "$__INIT_ENV_LOADED" ]; then
. "$INIT_ENV"
fi

# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="WiFi_Dynamic_IP"
#res_file="./$TESTNAME.res"
test_path=$(find_test_case_by_name "$TESTNAME")
cd "$test_path" || exit 1

log_info "-------------------------------------------------------------"
log_info "------------------- Starting $TESTNAME Test -----------------"

# Credential extraction
creds=$(get_wifi_credentials "$1" "$2") || log_skip_exit "$TESTNAME" "WiFi: SSID and/or password missing. Skipping test." wifi_cleanup ""
SSID=$(echo "$creds" | awk '{print $1}')
PASSWORD=$(echo "$creds" | awk '{print $2}')
log_info "Using SSID='$SSID' and PASSWORD='[hidden]'"

check_dependencies iw ping

# If not a kernel-only/minimal build, systemd is checked, else skipped automatically
check_systemd_services systemd-networkd.service || log_fail_exit "$TESTNAME" "Network services check failed" wifi_cleanup ""

WIFI_IFACE=$(get_wifi_interface) || log_fail_exit "$TESTNAME" "No WiFi interface found" wifi_cleanup ""
log_info "Using WiFi interface: $WIFI_IFACE"

# nmcli with retry
if wifi_connect_nmcli "$WIFI_IFACE" "$SSID" "$PASSWORD"; then
IP=$(wifi_get_ip "$WIFI_IFACE")
[ -z "$IP" ] && log_fail_exit "$TESTNAME" "No IP after nmcli" wifi_cleanup "$WIFI_IFACE"
if retry_command "ping -I \"$WIFI_IFACE\" -c 3 -W 2 8.8.8.8 >/dev/null 2>&1" 3 3; then
log_pass_exit "$TESTNAME" "Internet connectivity verified via ping" wifi_cleanup "$WIFI_IFACE"
else
log_fail_exit "$TESTNAME" "Ping test failed after nmcli connection" wifi_cleanup "$WIFI_IFACE"
fi
fi

# wpa_supplicant+udhcpc with retry
if wifi_connect_wpa_supplicant "$WIFI_IFACE" "$SSID" "$PASSWORD"; then
IP=$(wifi_get_ip "$WIFI_IFACE")
[ -z "$IP" ] && log_fail_exit "$TESTNAME" "No IP after wpa_supplicant" wifi_cleanup "$WIFI_IFACE"
if retry_command "ping -I \"$WIFI_IFACE\" -c 3 -W 2 8.8.8.8 >/dev/null 2>&1" 3 3; then
log_pass_exit "$TESTNAME" "Internet connectivity verified via ping" wifi_cleanup "$WIFI_IFACE"
else
log_fail_exit "$TESTNAME" "Ping test failed after wpa_supplicant connection" wifi_cleanup "$WIFI_IFACE"
fi
fi

log_fail_exit "$TESTNAME" "All WiFi connection methods failed for $WIFI_IFACE (SSID: $SSID)" wifi_cleanup "$WIFI_IFACE"
Empty file.
68 changes: 68 additions & 0 deletions Runner/suites/Connectivity/WiFi/WiFi_Firmware_Driver/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear

# Robustly find and source init_env
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"
while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

# Only source if not already loaded (idempotent)
if [ -z "$__INIT_ENV_LOADED" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
fi
# Always source functestlib.sh, using $TOOLS exported by init_env
# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="WiFi_Firmware_Driver"
test_path=$(find_test_case_by_name "$TESTNAME")
cd "$test_path" || exit 1

log_info "--------------------------------------------------------------------------"
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
log_info "=== Test Initialization ==="

# Paths for both targets
KODIAK_FW="/lib/firmware/ath11k/WCN6750/hw1.0/qcm6490/wpss.mbn"
LEMANS_FW="/lib/firmware/ath11k/WCN6855/hw2.1/amss.bin"

# Check firmware presence
if [ -f "$KODIAK_FW" ]; then
log_info "Kodiak firmware detected: $KODIAK_FW"
RPROC_PATH="$(find /sys/class/remoteproc/ -maxdepth 1 -name 'remoteproc*' | grep -E '[3-9]$' | head -n1)"
[ -z "$RPROC_PATH" ] && log_fail_exit "$TESTNAME" "Remoteproc node not found for Kodiak"
state=$(cat "$RPROC_PATH/state" 2>/dev/null)
if [ "$state" != "running" ]; then
log_info "Starting remoteproc: $RPROC_PATH"
echo start > "$RPROC_PATH/state"
sleep 2
state=$(cat "$RPROC_PATH/state" 2>/dev/null)
[ "$state" != "running" ] && log_fail_exit "$TESTNAME" "Failed to start remoteproc $RPROC_PATH"
fi
log_info "Remoteproc is running for Kodiak."
elif [ -f "$LEMANS_FW" ]; then
log_info "Lemans firmware detected: $LEMANS_FW"
if ! modprobe ath11k_pci; then
log_fail_exit "$TESTNAME" "Failed to load ath11k_pci module."
fi
lsmod | grep -q ath11k_pci || log_fail_exit "$TESTNAME" "ath11k_pci module not loaded."
log_info "ath11k_pci module loaded for Lemans."
else
log_skip_exit "$TESTNAME" "WiFi firmware not found for known targets."
fi

log_pass_exit "$TESTNAME" "WiFi firmware and driver validation successful."
89 changes: 89 additions & 0 deletions Runner/suites/Connectivity/WiFi/WiFi_Manual_IP/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear

# Robustly find and source init_env
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"
while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

# Only source if not already loaded (idempotent)
if [ -z "$__INIT_ENV_LOADED" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
fi
# Always source functestlib.sh, using $TOOLS exported by init_env
# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="WiFi_Manual_IP"
test_path=$(find_test_case_by_name "$TESTNAME")
cd "$test_path" || exit 1

log_info "--------------------------------------------------------------------------"
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
log_info "=== Test Initialization ==="

# Trap to always restore udhcpc script
trap 'restore_udhcpc_script' EXIT

# Credential extraction (from arguments, env, or ssid_list.txt)
if ! CRED=$(get_wifi_credentials "$1" "$2") || [ -z "$CRED" ]; then
log_skip_exit "$TESTNAME" "WiFi: SSID and/or password missing. Skipping test."
fi

SSID=$(echo "$CRED" | awk '{print $1}')
PASSWORD=$(echo "$CRED" | awk '{print $2}')
log_info "Using SSID='$SSID' and PASSWORD='[hidden]'"

check_dependencies iw wpa_supplicant udhcpc ip

WIFI_IF=$(get_wifi_interface)
[ -z "$WIFI_IF" ] && log_fail_exit "$TESTNAME" "No WiFi interface detected."

UDHCPC_SCRIPT=$(ensure_udhcpc_script)
[ ! -x "$UDHCPC_SCRIPT" ] && log_fail_exit "$TESTNAME" "Failed to create udhcpc script."

wifi_cleanup() {
killall -q wpa_supplicant 2>/dev/null
rm -f /tmp/wpa_supplicant.conf wpa.log
ip link set "$WIFI_IF" down 2>/dev/null
}

# Generate WPA config using helper (no duplicate code!)
WPA_CONF="$(wifi_write_wpa_conf "$WIFI_IF" "$SSID" "$PASSWORD")"
if [ ! -f "$WPA_CONF" ]; then
log_fail_exit "$TESTNAME" "Failed to create WPA config" wifi_cleanup
fi

killall -q wpa_supplicant 2>/dev/null
wpa_supplicant -B -i "$WIFI_IF" -c "$WPA_CONF" 2>&1 | tee wpa.log
sleep 4

# Run udhcpc with the script
udhcpc -i "$WIFI_IF" -s "$UDHCPC_SCRIPT" -n -q &
sleep 8

IP=$(ip addr show "$WIFI_IF" | awk '/inet / {print $2}' | cut -d/ -f1)
if [ -n "$IP" ]; then
log_info "WiFi got IP: $IP (manual DHCP via udhcpc)"
if ping -I "$WIFI_IF" -c 3 -W 2 8.8.8.8 >/dev/null 2>&1; then
log_pass_exit "$TESTNAME" "WiFi: Internet connectivity verified via ping" wifi_cleanup
else
log_fail_exit "$TESTNAME" "WiFi: Ping test failed after DHCP/manual IP" wifi_cleanup
fi
else
log_fail_exit "$TESTNAME" "Failed to acquire IP via udhcpc" wifi_cleanup
fi
Empty file.
61 changes: 61 additions & 0 deletions Runner/suites/Connectivity/WiFi/WiFi_OnOff/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear

# Robustly find and source init_env
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"
while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

# Only source if not already loaded (idempotent)
if [ -z "$__INIT_ENV_LOADED" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
fi
# Always source functestlib.sh, using $TOOLS exported by init_env
# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="WiFi_OnOff"
test_path=$(find_test_case_by_name "$TESTNAME")
cd "$test_path" || exit 1

log_info "-----------------------------------------------------------------------------------------"
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
log_info "=== Test Initialization ==="

check_dependencies ip iw

wifi_iface="$(get_wifi_interface)"
if [ -z "$wifi_iface" ]; then
log_skip_exit "$TESTNAME" "No WiFi interface found. Skipping." ""
fi

# Bring WiFi down
if bring_interface_up_down "$wifi_iface" down; then
log_info "Brought $wifi_iface down successfully."
else
log_fail_exit "$TESTNAME" "Failed to bring $wifi_iface down." ""
fi

sleep 2

# Bring WiFi up
if bring_interface_up_down "$wifi_iface" up; then
log_info "Brought $wifi_iface up successfully."
log_pass_exit "$TESTNAME" "$wifi_iface toggled up/down successfully." ""
else
log_fail_exit "$TESTNAME" "Failed to bring $wifi_iface up after down." ""
fi
Loading
Loading