Skip to content

Commit 79c092a

Browse files
committed
WiFi_Manual_IP: Refactor run.sh to use modular helpers, safe cleanup, and trap-based restore
- Switch WiFi_Manual_IP/run.sh to only use modular helper functions from functestlib.sh. - Add 'trap' to always restore original udhcpc script on test exit, ensuring testbed is left clean. - Use wifi_write_wpa_conf for WPA config creation (eliminate code duplication). - Use ensure_udhcpc_script and restore_udhcpc_script for robust script handling. - Harden cleanup and error handling (all exits go through helpers). - Improved logging, POSIX and ShellCheck compliance. - No change in test semantics or interface. Signed-off-by: Srikanth Muppandam <[email protected]>
1 parent 83740c5 commit 79c092a

File tree

8 files changed

+703
-8
lines changed

8 files changed

+703
-8
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2+
SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
# WiFi Connectivity Validation
5+
6+
## 📋 Overview
7+
8+
This test validates WiFi functionality by:
9+
10+
- Connecting to an access point (AP) using either `nmcli` or `wpa_supplicant`.
11+
- Verifying IP acquisition via DHCP.
12+
- Checking internet connectivity with a `ping` test.
13+
- Handling systemd network service status.
14+
- Supporting flexible SSID/password input via arguments, environment, or file.
15+
16+
## ✅ SSID/PASSWORD Input Priority (Hybrid Approach)
17+
18+
1. **Command-line arguments**:
19+
```sh
20+
./run.sh "MySSID" "MyPassword"
21+
```
22+
23+
2. **Environment variables**:
24+
```sh
25+
SSID_ENV=MySSID PASSWORD_ENV=MyPassword ./run.sh
26+
```
27+
28+
3. **Fallback to `ssid_list.txt` file** (if above not set):
29+
```txt
30+
MySSID MyPassword
31+
```
32+
33+
## ⚙️ Supported Tools
34+
35+
- Primary: `nmcli`
36+
- Fallback: `wpa_supplicant`, `udhcpc`, `ifconfig`
37+
38+
Ensure these tools are available in the system before running the test. Missing tools are detected and logged as skipped/failure.
39+
40+
## 🧪 Test Flow
41+
42+
1. **Dependency check** – verifies necessary binaries are present.
43+
2. **Systemd services check** – attempts to start network services if inactive.
44+
3. **WiFi connect (nmcli or wpa_supplicant)** – based on tool availability.
45+
4. **IP assignment check** – validates `ifconfig wlan0` output.
46+
5. **Internet test** – pings `8.8.8.8` to confirm outbound reachability.
47+
6. **Result logging** – writes `.res` file and logs all actions.
48+
49+
## 🧾 Output
50+
51+
- `WiFi_Connectivity.res`: Contains `WiFi_Connectivity PASS` or `FAIL`.
52+
- Logs are printed using `log_info`, `log_pass`, and `log_fail` from `functestlib.sh`.
53+
54+
## 📂 Directory Structure
55+
56+
```
57+
WiFi/
58+
├── run.sh
59+
├── ssid_list.txt (optional)
60+
├── README.md
61+
```
62+
63+
## 🌐 Integration (meta-qcom_PreMerge.yaml)
64+
65+
Add this test with SSID parameters as follows:
66+
67+
```yaml
68+
- name: WiFi_Connectivity
69+
path: Runner/suites/Connectivity/WiFi
70+
timeout:
71+
minutes: 5
72+
params:
73+
SSID_ENV: "xxxx"
74+
PASSWORD_ENV: "xxxx"
75+
```
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
# Robustly find and source init_env
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
INIT_ENV=""
9+
SEARCH="$SCRIPT_DIR"
10+
while [ "$SEARCH" != "/" ]; do
11+
if [ -f "$SEARCH/init_env" ]; then
12+
INIT_ENV="$SEARCH/init_env"
13+
break
14+
fi
15+
SEARCH=$(dirname "$SEARCH")
16+
done
17+
18+
if [ -z "$INIT_ENV" ]; then
19+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20+
exit 1
21+
fi
22+
23+
# shellcheck disable=SC1090
24+
if [ -z "$__INIT_ENV_LOADED" ]; then
25+
. "$INIT_ENV"
26+
fi
27+
28+
# shellcheck disable=SC1090,SC1091
29+
. "$TOOLS/functestlib.sh"
30+
31+
TESTNAME="WiFi_Dynamic_IP"
32+
#res_file="./$TESTNAME.res"
33+
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
36+
log_info "-------------------------------------------------------------"
37+
log_info "------------------- Starting $TESTNAME Test -----------------"
38+
39+
# Credential extraction
40+
creds=$(get_wifi_credentials "$1" "$2") || log_skip_exit "$TESTNAME" "WiFi: SSID and/or password missing. Skipping test." wifi_cleanup ""
41+
SSID=$(echo "$creds" | awk '{print $1}')
42+
PASSWORD=$(echo "$creds" | awk '{print $2}')
43+
log_info "Using SSID='$SSID' and PASSWORD='[hidden]'"
44+
45+
check_dependencies iw ping
46+
47+
# If not a kernel-only/minimal build, systemd is checked, else skipped automatically
48+
check_systemd_services systemd-networkd.service || log_fail_exit "$TESTNAME" "Network services check failed" wifi_cleanup ""
49+
50+
WIFI_IFACE=$(get_wifi_interface) || log_fail_exit "$TESTNAME" "No WiFi interface found" wifi_cleanup ""
51+
log_info "Using WiFi interface: $WIFI_IFACE"
52+
53+
# nmcli with retry
54+
if wifi_connect_nmcli "$WIFI_IFACE" "$SSID" "$PASSWORD"; then
55+
IP=$(wifi_get_ip "$WIFI_IFACE")
56+
[ -z "$IP" ] && log_fail_exit "$TESTNAME" "No IP after nmcli" wifi_cleanup "$WIFI_IFACE"
57+
if retry_command "ping -I \"$WIFI_IFACE\" -c 3 -W 2 8.8.8.8 >/dev/null 2>&1" 3 3; then
58+
log_pass_exit "$TESTNAME" "Internet connectivity verified via ping" wifi_cleanup "$WIFI_IFACE"
59+
else
60+
log_fail_exit "$TESTNAME" "Ping test failed after nmcli connection" wifi_cleanup "$WIFI_IFACE"
61+
fi
62+
fi
63+
64+
# wpa_supplicant+udhcpc with retry
65+
if wifi_connect_wpa_supplicant "$WIFI_IFACE" "$SSID" "$PASSWORD"; then
66+
IP=$(wifi_get_ip "$WIFI_IFACE")
67+
[ -z "$IP" ] && log_fail_exit "$TESTNAME" "No IP after wpa_supplicant" wifi_cleanup "$WIFI_IFACE"
68+
if retry_command "ping -I \"$WIFI_IFACE\" -c 3 -W 2 8.8.8.8 >/dev/null 2>&1" 3 3; then
69+
log_pass_exit "$TESTNAME" "Internet connectivity verified via ping" wifi_cleanup "$WIFI_IFACE"
70+
else
71+
log_fail_exit "$TESTNAME" "Ping test failed after wpa_supplicant connection" wifi_cleanup "$WIFI_IFACE"
72+
fi
73+
fi
74+
75+
log_fail_exit "$TESTNAME" "All WiFi connection methods failed for $WIFI_IFACE (SSID: $SSID)" wifi_cleanup "$WIFI_IFACE"

Runner/suites/Connectivity/WiFi/WiFi_Dynamic_IP/ssid_list.txt

Whitespace-only changes.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
# SPDX-License-Identifier: BSD-3-Clause-Clear
5+
6+
# Robustly find and source init_env
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
INIT_ENV=""
9+
SEARCH="$SCRIPT_DIR"
10+
while [ "$SEARCH" != "/" ]; do
11+
if [ -f "$SEARCH/init_env" ]; then
12+
INIT_ENV="$SEARCH/init_env"
13+
break
14+
fi
15+
SEARCH=$(dirname "$SEARCH")
16+
done
17+
18+
if [ -z "$INIT_ENV" ]; then
19+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
20+
exit 1
21+
fi
22+
23+
# Only source if not already loaded (idempotent)
24+
if [ -z "$__INIT_ENV_LOADED" ]; then
25+
# shellcheck disable=SC1090
26+
. "$INIT_ENV"
27+
fi
28+
# Always source functestlib.sh, using $TOOLS exported by init_env
29+
# shellcheck disable=SC1090,SC1091
30+
. "$TOOLS/functestlib.sh"
31+
32+
TESTNAME="WiFi_Firmware_Driver"
33+
test_path=$(find_test_case_by_name "$TESTNAME")
34+
cd "$test_path" || exit 1
35+
36+
log_info "--------------------------------------------------------------------------"
37+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
38+
log_info "=== Test Initialization ==="
39+
40+
check_dependencies find grep modprobe lsmod cat
41+
42+
# Detect SoC from /proc/device-tree/model
43+
if [ -f /proc/device-tree/model ]; then
44+
read -r soc_model < /proc/device-tree/model
45+
else
46+
soc_model="Unknown"
47+
fi
48+
log_info "Detected SoC model: $soc_model"
49+
50+
# Scan firmware
51+
log_info "Scanning for WiFi firmware under /lib/firmware/ath11k/..."
52+
fwfile=""
53+
if find /lib/firmware/ath11k/ -type f -name "amss.bin" -print -quit 2>/dev/null | grep -q .; then
54+
fwfile=$(find /lib/firmware/ath11k/ -type f -name "amss.bin" -print -quit 2>/dev/null)
55+
elif find /lib/firmware/ath11k/ -type f -name "wpss.mbn" -print -quit 2>/dev/null | grep -q .; then
56+
fwfile=$(find /lib/firmware/ath11k/ -type f -name "wpss.mbn" -print -quit 2>/dev/null)
57+
fi
58+
59+
if [ -z "$fwfile" ]; then
60+
log_skip_exit "$TESTNAME" "No WiFi firmware (amss.bin or wpss.mbn) found under /lib/firmware/ath11k/"
61+
fi
62+
63+
size=$(stat -c%s "$fwfile" 2>/dev/null)
64+
basename=$(basename "$fwfile")
65+
log_info "Detected firmware [$basename]: $fwfile (size: $size bytes)"
66+
67+
case "$basename" in
68+
wpss.mbn)
69+
log_info "Platform using wpss.mbn firmware (e.g., Kodiak)"
70+
if validate_remoteproc_running "wpss"; then
71+
log_info "Remoteproc 'wpss' is active and validated."
72+
else
73+
log_fail_exit "$TESTNAME" "Remoteproc 'wpss' validation failed."
74+
fi
75+
log_info "No module load needed for wpss-based platform (e.g., Kodiak)."
76+
;;
77+
amss.bin)
78+
log_info "amss.bin firmware detected (e.g., WCN6855 - Lemans/Monaco)"
79+
if ! modprobe ath11k_pci 2>/dev/null; then
80+
log_fail_exit "$TESTNAME" "Failed to load ath11k_pci module."
81+
fi
82+
;;
83+
*)
84+
log_skip_exit "$TESTNAME" "Unsupported firmware type: $basename"
85+
;;
86+
esac
87+
88+
log_info "Checking active ath11k-related kernel modules via lsmod..."
89+
if lsmod | grep -Eq '^ath11k(_.*)?\s'; then
90+
lsmod | grep -E '^ath11k(_.*)?\s' | while read -r mod_line; do
91+
log_info " Module loaded: $mod_line"
92+
done
93+
else
94+
log_fail_exit "$TESTNAME" "No ath11k-related kernel module detected via lsmod"
95+
fi
96+
97+
log_pass_exit "$TESTNAME" "WiFi firmware and driver validation successful."
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/sh
2+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
5+
# Robustly find and source init_env
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
INIT_ENV=""
8+
SEARCH="$SCRIPT_DIR"
9+
while [ "$SEARCH" != "/" ]; do
10+
if [ -f "$SEARCH/init_env" ]; then
11+
INIT_ENV="$SEARCH/init_env"
12+
break
13+
fi
14+
SEARCH=$(dirname "$SEARCH")
15+
done
16+
17+
if [ -z "$INIT_ENV" ]; then
18+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
19+
exit 1
20+
fi
21+
22+
# Only source if not already loaded (idempotent)
23+
if [ -z "$__INIT_ENV_LOADED" ]; then
24+
# shellcheck disable=SC1090
25+
. "$INIT_ENV"
26+
fi
27+
# Always source functestlib.sh, using $TOOLS exported by init_env
28+
# shellcheck disable=SC1090,SC1091
29+
. "$TOOLS/functestlib.sh"
30+
31+
TESTNAME="WiFi_Manual_IP"
32+
test_path=$(find_test_case_by_name "$TESTNAME")
33+
cd "$test_path" || exit 1
34+
35+
log_info "--------------------------------------------------------------------------"
36+
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
37+
log_info "=== Test Initialization ==="
38+
39+
# Trap to always restore udhcpc script
40+
trap 'restore_udhcpc_script' EXIT
41+
42+
# Credential extraction (from arguments, env, or ssid_list.txt)
43+
if ! CRED=$(get_wifi_credentials "$1" "$2") || [ -z "$CRED" ]; then
44+
log_skip_exit "$TESTNAME" "WiFi: SSID and/or password missing. Skipping test."
45+
fi
46+
47+
SSID=$(echo "$CRED" | awk '{print $1}')
48+
PASSWORD=$(echo "$CRED" | awk '{print $2}')
49+
log_info "Using SSID='$SSID' and PASSWORD='[hidden]'"
50+
51+
check_dependencies iw wpa_supplicant udhcpc ip
52+
53+
WIFI_IF=$(get_wifi_interface)
54+
[ -z "$WIFI_IF" ] && log_fail_exit "$TESTNAME" "No WiFi interface detected."
55+
56+
UDHCPC_SCRIPT=$(ensure_udhcpc_script)
57+
[ ! -x "$UDHCPC_SCRIPT" ] && log_fail_exit "$TESTNAME" "Failed to create udhcpc script."
58+
59+
wifi_cleanup() {
60+
killall -q wpa_supplicant 2>/dev/null
61+
rm -f /tmp/wpa_supplicant.conf wpa.log
62+
ip link set "$WIFI_IF" down 2>/dev/null
63+
}
64+
65+
# Generate WPA config using helper (no duplicate code!)
66+
WPA_CONF="$(wifi_write_wpa_conf "$WIFI_IF" "$SSID" "$PASSWORD")"
67+
if [ ! -f "$WPA_CONF" ]; then
68+
log_fail_exit "$TESTNAME" "Failed to create WPA config" wifi_cleanup
69+
fi
70+
71+
killall -q wpa_supplicant 2>/dev/null
72+
wpa_supplicant -B -i "$WIFI_IF" -c "$WPA_CONF" 2>&1 | tee wpa.log
73+
sleep 4
74+
75+
# Run udhcpc with the script
76+
udhcpc -i "$WIFI_IF" -s "$UDHCPC_SCRIPT" -n -q &
77+
sleep 8
78+
79+
IP=$(ip addr show "$WIFI_IF" | awk '/inet / {print $2}' | cut -d/ -f1)
80+
if [ -n "$IP" ]; then
81+
log_info "WiFi got IP: $IP (manual DHCP via udhcpc)"
82+
if ping -I "$WIFI_IF" -c 3 -W 2 8.8.8.8 >/dev/null 2>&1; then
83+
log_pass_exit "$TESTNAME" "WiFi: Internet connectivity verified via ping" wifi_cleanup
84+
else
85+
log_fail_exit "$TESTNAME" "WiFi: Ping test failed after DHCP/manual IP" wifi_cleanup
86+
fi
87+
else
88+
log_fail_exit "$TESTNAME" "Failed to acquire IP via udhcpc" wifi_cleanup
89+
fi

Runner/suites/Connectivity/WiFi/WiFi_Manual_IP/ssid_list.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)