Skip to content

Commit 40b09f4

Browse files
authored
Merge pull request #305 from smuppand/bt-scan-fix
Bluetooth: BT_SCAN reuse lib_bluetooth scan helpers and de-noise stdout
2 parents 1605411 + b6effa1 commit 40b09f4

File tree

4 files changed

+469
-226
lines changed

4 files changed

+469
-226
lines changed

Runner/suites/Connectivity/Bluetooth/BT_FW_KMD_Service/run.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,18 @@ else
209209
fi
210210

211211
log_info "=== bluetoothctl list (controllers) ==="
212-
bluetoothctl list 2>/dev/null || true
212+
213+
out="$(bluetoothctl list 2>/dev/null | sanitize_bt_output || true)"
214+
if printf '%s\n' "$out" | grep -qi '^[[:space:]]*Controller[[:space:]]'; then
215+
# Non-interactive worked print what we got
216+
printf '%s\n' "$out"
217+
else
218+
# Non-interactive printed no controllers → retry using interactive method
219+
log_warn "bluetoothctl list returned no controllers in non-interactive mode, retrying interactive list."
220+
221+
log_info "=== bluetoothctl list (controllers) ==="
222+
btctl_script "list" "quit" | sanitize_bt_output || true
223+
fi
213224

214225
log_info "=== lsmod (subset: BT stack) ==="
215226
lsmod 2>/dev/null | grep -E '^(bluetooth|hci_uart|btqca|btbcm|rfkill|cfg80211)\b' || true

Runner/suites/Connectivity/Bluetooth/BT_ON_OFF/run.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ elif findhcisysfs >/dev/null 2>&1; then
102102
else
103103
ADAPTER=""
104104
fi
105-
105+
106106
if [ -n "$ADAPTER" ]; then
107107
log_info "Using adapter: $ADAPTER"
108108
else
@@ -111,8 +111,13 @@ else
111111
exit 0
112112
fi
113113

114+
# --- NEW: warn/diag if non-interactive "bluetoothctl list" is empty (non-fatal) ---
115+
btwarniflistempty "$ADAPTER" || true
116+
114117
# Ensure controller is visible to bluetoothctl (try public-addr if needed)
115118
if ! bt_ensure_controller_visible "$ADAPTER"; then
119+
# --- NEW: print diagnostics before skipping ---
120+
btloghcidiag "$ADAPTER"
116121
log_warn "SKIP — no controller visible to bluetoothctl (HCI RAW/DOWN or attach incomplete)."
117122
echo "$TESTNAME SKIP" > "$res_file"
118123
exit 0
@@ -154,6 +159,9 @@ after_on="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
154159
[ -z "$after_on" ] && after_on="unknown"
155160

156161
if [ "$after_on" = "yes" ]; then
162+
# --- NEW: post-check (covers your "list is empty after run" symptom) ---
163+
btwarniflistempty "$ADAPTER" || true
164+
157165
log_pass "Post-ON verification: Powered=yes (as expected)."
158166
echo "$TESTNAME PASS" > "$res_file"
159167
exit 0

Runner/suites/Connectivity/Bluetooth/BT_SCAN/run.sh

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3-
# SPDX-License-Identifier: BSD-3-Clause# BT_SCAN – Bluetooth scanning validation (non-expect version)
3+
# SPDX-License-Identifier: BSD-3-Clause#
4+
# BT_SCAN – Bluetooth scanning validation (non-expect version)
5+
46
# ---------- Repo env + helpers ----------
57
SCRIPT_DIR="$(
68
cd "$(dirname "$0")" || exit 1
@@ -68,9 +70,12 @@ rm -f "$res_file"
6870

6971
log_info "------------------------------------------------------------"
7072
log_info "Starting $TESTNAME Testcase"
71-
log_info "Checking dependency: bluetoothctl"
73+
log_info "Checking dependencies: bluetoothctl pgrep"
7274

73-
check_dependencies bluetoothctl pgrep
75+
if ! check_dependencies bluetoothctl pgrep; then
76+
echo "$TESTNAME SKIP" > "$res_file"
77+
exit 0
78+
fi
7479

7580
# -----------------------------
7681
# 1. Ensure bluetoothd is running
@@ -167,10 +172,12 @@ log_info "Discovering state after scan ON window: $dstate_on"
167172

168173
# -----------------------------
169174
# 7. Get devices list after scan ON
175+
# - Try non-interactive bluetoothctl first
176+
# - If empty/flaky, fallback to btctl_script "devices" "quit"
170177
# -----------------------------
171178
devices_out="$(
172-
bluetoothctl devices 2>/dev/null \
173-
| sanitize_bt_output
179+
bt_list_devices_raw 2>/dev/null \
180+
| grep '^Device ' || true
174181
)"
175182

176183
if [ -n "$TARGET_MAC" ]; then
@@ -204,31 +211,17 @@ fi
204211
# -----------------------------
205212
log_info "Testing scan OFF..."
206213
if ! bt_set_scan off "$ADAPTER"; then
207-
log_warn "bt_set_scan(off) returned non-zero continuing with Discovering check."
214+
# bt_set_scan(off) can be flaky on minimal images; rely on poll helper
215+
log_warn "bt_set_scan(off) returned non-zero; continuing with scan-off polling."
208216
fi
209217

210-
SCAN_OFF_OK=0
211-
ITER=10
212-
i=1
213-
while [ "$i" -le "$ITER" ]; do
214-
dstate_off="$(bt_get_discovering 2>/dev/null || true)"
215-
[ -z "$dstate_off" ] && dstate_off="unknown"
216-
217-
log_info "Discovering state during scan OFF wait (iteration $i/$ITER): $dstate_off"
218-
219-
if [ "$dstate_off" = "no" ]; then
220-
SCAN_OFF_OK=1
221-
break
222-
fi
223-
224-
sleep 2
225-
i=$((i + 1))
226-
done
227-
228-
if [ "$SCAN_OFF_OK" -eq 1 ]; then
229-
log_pass "Discovering=no observed after scan OFF polling."
218+
# Use lib helper to avoid repetitive log spam and handle 'unknown' cleanly.
219+
if bt_scan_poll_off 10 1; then
220+
# On minimal/ramdisk images bt_scan_poll_off may treat persistent 'unknown' as non-fatal.
221+
log_pass "Scan OFF cleanup completed."
230222
else
231-
log_warn "Discovering did not transition to 'no' after scan OFF window."
223+
# If you keep bt_scan_poll_off strict, this may still warn; not a test failure.
224+
log_warn "Scan OFF cleanup did not confirm Discovering=no (non-fatal)."
232225
fi
233226

234227
echo "$TESTNAME PASS" > "$res_file"

0 commit comments

Comments
 (0)