Skip to content

Commit 599b560

Browse files
authored
Merge pull request #214 from smuppand/bt-scan-fix
Bluetooth test robustness: reuse lib helpers and harden scan/firmware checks
2 parents 2709798 + 42fdf10 commit 599b560

File tree

5 files changed

+2209
-371
lines changed

5 files changed

+2209
-371
lines changed
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#!/bin/sh
2+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
#
5+
# BT_FW_KMD_Service - Bluetooth FW + KMD + service + controller infra validation
6+
# Non-expect version, using lib_bluetooth.sh helpers.
7+
8+
# ---------- init_env + tools ----------
9+
SCRIPT_DIR="$(
10+
cd "$(dirname "$0")" || exit 1
11+
pwd
12+
)"
13+
INIT_ENV=""
14+
SEARCH="$SCRIPT_DIR"
15+
16+
while [ "$SEARCH" != "/" ]; do
17+
if [ -f "$SEARCH/init_env" ]; then
18+
INIT_ENV="$SEARCH/init_env"
19+
break
20+
fi
21+
SEARCH=$(dirname "$SEARCH")
22+
done
23+
24+
if [ -z "$INIT_ENV" ]; then
25+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
26+
exit 1
27+
fi
28+
29+
if [ -z "${__INIT_ENV_LOADED:-}" ]; then
30+
# shellcheck disable=SC1090
31+
. "$INIT_ENV"
32+
__INIT_ENV_LOADED=1
33+
fi
34+
35+
# shellcheck disable=SC1091
36+
. "$TOOLS/functestlib.sh"
37+
# shellcheck disable=SC1091
38+
. "$TOOLS/lib_bluetooth.sh"
39+
40+
# ---------- CLI / env parameters ----------
41+
BT_ADAPTER="${BT_ADAPTER-}"
42+
43+
while [ "$#" -gt 0 ]; do
44+
case "$1" in
45+
--adapter)
46+
BT_ADAPTER="$2"
47+
shift 2
48+
;;
49+
*)
50+
log_warn "Unknown argument ignored: $1"
51+
shift 1
52+
;;
53+
esac
54+
done
55+
56+
TESTNAME="BT_FW_KMD_Service"
57+
testpath="$(find_test_case_by_name "$TESTNAME")" || {
58+
log_fail "$TESTNAME : Test directory not found."
59+
echo "$TESTNAME FAIL" > "./$TESTNAME.res"
60+
exit 1
61+
}
62+
63+
cd "$testpath" || exit 1
64+
RES_FILE="./${TESTNAME}.res"
65+
rm -f "$RES_FILE"
66+
67+
FAIL_COUNT=0
68+
WARN_COUNT=0
69+
70+
inc_fail() { FAIL_COUNT=$((FAIL_COUNT + 1)); }
71+
inc_warn() { WARN_COUNT=$((WARN_COUNT + 1)); }
72+
73+
log_info "------------------------------------------------------------"
74+
log_info "Starting $TESTNAME"
75+
76+
log_info "Checking dependencies: bluetoothctl hciconfig dmesg lsmod"
77+
check_dependencies bluetoothctl hciconfig dmesg lsmod
78+
79+
# ---------- Bluetooth service / daemon ----------
80+
log_info "Checking if bluetoothd (or bluetooth.service) is running..."
81+
if btsvcactive; then
82+
log_pass "Bluetooth service/daemon active."
83+
else
84+
log_fail "Bluetooth service/daemon NOT active."
85+
inc_fail
86+
fi
87+
88+
# ---------- DT node / compatible ----------
89+
BT_COMPAT_LIST="
90+
qcom,wcn7850-bt
91+
qcom,wcn6855-bt
92+
qcom,bluetooth
93+
"
94+
95+
if dt_confirm_node_or_compatible_all "BT" "$BT_COMPAT_LIST"; then
96+
log_pass "DT node/compatible for BT present (at least one entry matched)."
97+
else
98+
log_fail "DT node/compatible for BT NOT found."
99+
inc_fail
100+
fi
101+
102+
# ---------- Firmware presence ----------
103+
if fw_dir="$(btfwpresent 2>/dev/null)"; then
104+
log_pass "Firmware present in: $fw_dir"
105+
else
106+
log_warn "No BT firmware matching msbtfw*/msnv* found under standard firmware paths."
107+
inc_warn
108+
fi
109+
110+
# ---------- Firmware load dmesg ----------
111+
if btfwloaded; then
112+
log_pass "Firmware load/setup appears completed (dmesg)."
113+
else
114+
log_fail "Firmware load/setup does NOT look clean (see recent Bluetooth/QCA/WCN dmesg lines above)."
115+
inc_fail
116+
fi
117+
118+
# ---------- Kernel modules / KMD ----------
119+
if btkmdpresent; then
120+
log_pass "Kernel BT driver stack present (bluetooth/hci_uart/btqca or built-in)."
121+
else
122+
log_fail "Kernel BT driver stack not detected (no bluetooth/hci_uart/btqca in sysfs/dmesg)."
123+
inc_fail
124+
fi
125+
126+
# ---------- HCI presence ----------
127+
if bthcipresent; then
128+
log_pass "HCI present in /sys/class/bluetooth."
129+
else
130+
log_fail "No /sys/class/bluetooth/hci* found (HCI not up)."
131+
inc_fail
132+
fi
133+
134+
# --- Bluetooth service / daemon check via btsvcactive() ---
135+
if btsvcactive; then
136+
log_pass "Bluetooth service active (systemd bluetooth.service or bluetoothd)."
137+
else
138+
log_warn "Bluetooth service is not active (bluetooth.service inactive and bluetoothd not running)."
139+
inc_warn
140+
fi
141+
142+
# -----------------------------
143+
# Detect adapter (CLI/ENV > auto-detect)
144+
# -----------------------------
145+
if [ -n "$BT_ADAPTER" ]; then
146+
ADAPTER="$BT_ADAPTER"
147+
log_info "Using adapter from BT_ADAPTER/CLI: $ADAPTER"
148+
elif findhcisysfs >/dev/null 2>&1; then
149+
ADAPTER="$(findhcisysfs 2>/dev/null || true)"
150+
else
151+
ADAPTER=""
152+
fi
153+
154+
if [ -z "$ADAPTER" ]; then
155+
log_warn "No HCI adapter found; skipping BT FW/KMD test."
156+
echo "$TESTNAME SKIP" > "./$TESTNAME.res"
157+
exit 0
158+
fi
159+
160+
# ---------- BD address sanity check ----------
161+
if [ -n "$ADAPTER" ]; then
162+
if btbdok "$ADAPTER"; then
163+
log_pass "BD address sane for $ADAPTER (not all zeros)."
164+
else
165+
log_fail "BD address invalid or all zeros for $ADAPTER."
166+
inc_fail
167+
fi
168+
fi
169+
170+
# ---------- Controller visibility (bluetoothctl list + public-addr path) ----------
171+
if [ -n "$ADAPTER" ]; then
172+
if bt_ensure_controller_visible "$ADAPTER"; then
173+
# We don't need to log here bt_ensure_controller_visible already logs.
174+
:
175+
else
176+
# For this infra test we treat this as WARN, not FAIL:
177+
# stack is otherwise OK (firmware, KMD, HCI, BD).
178+
log_warn "No controller in 'bluetoothctl list' (controller not fully instantiated)."
179+
inc_warn
180+
fi
181+
else
182+
log_warn "Controller visibility not checked (no adapter determined)."
183+
inc_warn
184+
fi
185+
186+
# ---------- Optional: dump some useful diagnostics ----------
187+
log_info "=== hciconfig -a (if available) ==="
188+
if command -v hciconfig >/dev/null 2>&1; then
189+
hciconfig -a || true
190+
else
191+
log_warn "hciconfig command not available."
192+
inc_warn
193+
fi
194+
195+
log_info "=== bluetoothctl list (controllers) ==="
196+
bluetoothctl list 2>/dev/null || true
197+
198+
log_info "=== lsmod (subset: BT stack) ==="
199+
lsmod 2>/dev/null | grep -E '^(bluetooth|hci_uart|btqca|btbcm|rfkill|cfg80211)\b' || true
200+
201+
# ---------- Final result ----------
202+
log_info "Completed with WARN=${WARN_COUNT}, FAIL=${FAIL_COUNT}"
203+
204+
if [ "$FAIL_COUNT" -gt 0 ]; then
205+
echo "$TESTNAME FAIL" > "$RES_FILE"
206+
else
207+
echo "$TESTNAME PASS" > "$RES_FILE"
208+
fi
209+
210+
exit 0
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/bin/sh
2+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
# BT_ON_OFF - Basic Bluetooth power toggle validation (non-expect version)
5+
6+
# Robustly find and source init_env
7+
SCRIPT_DIR="$(
8+
cd "$(dirname "$0")" || exit 1
9+
pwd
10+
)"
11+
INIT_ENV=""
12+
SEARCH="$SCRIPT_DIR"
13+
14+
while [ "$SEARCH" != "/" ]; do
15+
if [ -f "$SEARCH/init_env" ]; then
16+
INIT_ENV="$SEARCH/init_env"
17+
break
18+
fi
19+
SEARCH=$(dirname "$SEARCH")
20+
done
21+
22+
if [ -z "$INIT_ENV" ]; then
23+
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
24+
exit 1
25+
fi
26+
27+
# Only source once (idempotent)
28+
if [ -z "${__INIT_ENV_LOADED:-}" ]; then
29+
# shellcheck disable=SC1090
30+
. "$INIT_ENV"
31+
__INIT_ENV_LOADED=1
32+
fi
33+
34+
# shellcheck disable=SC1091
35+
. "$TOOLS/functestlib.sh"
36+
# shellcheck disable=SC1091
37+
. "$TOOLS/lib_bluetooth.sh"
38+
39+
# ---------- CLI / env parameters ----------
40+
# BT_ADAPTER can be set from CLI via --adapter or from environment.
41+
BT_ADAPTER="${BT_ADAPTER-}"
42+
43+
while [ "$#" -gt 0 ]; do
44+
case "$1" in
45+
--adapter)
46+
BT_ADAPTER="$2"
47+
shift 2
48+
;;
49+
*)
50+
log_warn "Unknown argument ignored: $1"
51+
shift 1
52+
;;
53+
esac
54+
done
55+
56+
TESTNAME="BT_ON_OFF"
57+
testpath="$(find_test_case_by_name "$TESTNAME")" || {
58+
log_fail "$TESTNAME : Test directory not found."
59+
echo "$TESTNAME FAIL" > "./$TESTNAME.res"
60+
exit 1
61+
}
62+
63+
cd "$testpath" || exit 1
64+
res_file="./$TESTNAME.res"
65+
rm -f "$res_file"
66+
67+
log_info "------------------------------------------------------------"
68+
log_info "Starting $TESTNAME Testcase"
69+
log_info "Checking dependency: bluetoothctl"
70+
71+
# verify that all necessary dependencies
72+
check_dependencies bluetoothctl pgrep
73+
74+
log_info "Checking if bluetoothd is running..."
75+
MAX_RETRIES=3
76+
RETRY_DELAY=5
77+
retry=0
78+
79+
while [ "$retry" -lt "$MAX_RETRIES" ]; do
80+
if pgrep bluetoothd >/dev/null 2>&1; then
81+
log_info "bluetoothd is running"
82+
break
83+
fi
84+
log_warn "bluetoothd not running, retrying in ${RETRY_DELAY}s..."
85+
sleep "$RETRY_DELAY"
86+
retry=$((retry + 1))
87+
done
88+
89+
if [ "$retry" -eq "$MAX_RETRIES" ]; then
90+
log_fail "Bluetooth daemon not detected after ${MAX_RETRIES} attempts."
91+
echo "$TESTNAME FAIL" > "$res_file"
92+
exit 0
93+
fi
94+
95+
# -----------------------------
96+
# Detect adapter with precedence: CLI/ENV > auto-detect
97+
# -----------------------------
98+
if [ -n "$BT_ADAPTER" ]; then
99+
ADAPTER="$BT_ADAPTER"
100+
log_info "Using adapter from BT_ADAPTER/CLI: $ADAPTER"
101+
elif findhcisysfs >/dev/null 2>&1; then
102+
ADAPTER="$(findhcisysfs 2>/dev/null || true)"
103+
else
104+
ADAPTER=""
105+
fi
106+
107+
if [ -n "$ADAPTER" ]; then
108+
log_info "Using adapter: $ADAPTER"
109+
else
110+
log_warn "No HCI adapter found; skipping test."
111+
echo "$TESTNAME SKIP" > "./$TESTNAME.res"
112+
exit 0
113+
fi
114+
115+
# Ensure controller is visible to bluetoothctl (try public-addr if needed)
116+
if ! bt_ensure_controller_visible "$ADAPTER"; then
117+
log_warn "SKIP — no controller visible to bluetoothctl (HCI RAW/DOWN or attach incomplete)."
118+
echo "$TESTNAME SKIP" > "$res_file"
119+
exit 0
120+
fi
121+
122+
# Read initial power state
123+
initial_power="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
124+
[ -z "$initial_power" ] && initial_power="unknown"
125+
log_info "Initial Powered = $initial_power"
126+
127+
# ---- Power OFF test ----
128+
log_info "Powering OFF..."
129+
if ! btpower "$ADAPTER" off; then
130+
log_fail "btpower($ADAPTER, off) failed (command-level error)."
131+
echo "$TESTNAME FAIL" > "$res_file"
132+
exit 0
133+
fi
134+
135+
after_off="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
136+
[ -z "$after_off" ] && after_off="unknown"
137+
138+
if [ "$after_off" = "no" ]; then
139+
log_pass "Post-OFF verification: Powered=no (as expected)."
140+
else
141+
log_fail "Post-OFF verification failed (Powered=$after_off)."
142+
echo "$TESTNAME FAIL" > "$res_file"
143+
exit 0
144+
fi
145+
146+
# ---- Power ON test ----
147+
log_info "Powering ON..."
148+
if ! btpower "$ADAPTER" on; then
149+
log_fail "btpower($ADAPTER, on) failed (command-level error)."
150+
echo "$TESTNAME FAIL" > "$res_file"
151+
exit 0
152+
fi
153+
154+
after_on="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
155+
[ -z "$after_on" ] && after_on="unknown"
156+
157+
if [ "$after_on" = "yes" ]; then
158+
log_pass "Post-ON verification: Powered=yes (as expected)."
159+
echo "$TESTNAME PASS" > "$res_file"
160+
exit 0
161+
fi
162+
163+
log_fail "Post-ON verification failed (Powered=$after_on)."
164+
echo "$TESTNAME FAIL" > "$res_file"
165+
exit 0

0 commit comments

Comments
 (0)