Skip to content

Commit b6effa1

Browse files
committed
fix(bt_scan): fall back to btctl_script for device listing when bluetoothctl is flaky
Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
1 parent db9f23a commit b6effa1

File tree

1 file changed

+20
-27
lines changed
  • Runner/suites/Connectivity/Bluetooth/BT_SCAN

1 file changed

+20
-27
lines changed

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)