|
1 | 1 | #!/bin/sh |
2 | 2 | # 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 | + |
4 | 6 | # ---------- Repo env + helpers ---------- |
5 | 7 | SCRIPT_DIR="$( |
6 | 8 | cd "$(dirname "$0")" || exit 1 |
@@ -68,9 +70,12 @@ rm -f "$res_file" |
68 | 70 |
|
69 | 71 | log_info "------------------------------------------------------------" |
70 | 72 | log_info "Starting $TESTNAME Testcase" |
71 | | -log_info "Checking dependency: bluetoothctl" |
| 73 | +log_info "Checking dependencies: bluetoothctl pgrep" |
72 | 74 |
|
73 | | -check_dependencies bluetoothctl pgrep |
| 75 | +if ! check_dependencies bluetoothctl pgrep; then |
| 76 | + echo "$TESTNAME SKIP" > "$res_file" |
| 77 | + exit 0 |
| 78 | +fi |
74 | 79 |
|
75 | 80 | # ----------------------------- |
76 | 81 | # 1. Ensure bluetoothd is running |
@@ -167,10 +172,12 @@ log_info "Discovering state after scan ON window: $dstate_on" |
167 | 172 |
|
168 | 173 | # ----------------------------- |
169 | 174 | # 7. Get devices list after scan ON |
| 175 | +# - Try non-interactive bluetoothctl first |
| 176 | +# - If empty/flaky, fallback to btctl_script "devices" "quit" |
170 | 177 | # ----------------------------- |
171 | 178 | devices_out="$( |
172 | | - bluetoothctl devices 2>/dev/null \ |
173 | | - | sanitize_bt_output |
| 179 | + bt_list_devices_raw 2>/dev/null \ |
| 180 | + | grep '^Device ' || true |
174 | 181 | )" |
175 | 182 |
|
176 | 183 | if [ -n "$TARGET_MAC" ]; then |
|
204 | 211 | # ----------------------------- |
205 | 212 | log_info "Testing scan OFF..." |
206 | 213 | 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." |
208 | 216 | fi |
209 | 217 |
|
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." |
230 | 222 | 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)." |
232 | 225 | fi |
233 | 226 |
|
234 | 227 | echo "$TESTNAME PASS" > "$res_file" |
|
0 commit comments