Skip to content

Commit 55b6669

Browse files
committed
fix(lib_bluetooth): avoid false FAIL when FW bring-up retries succeed
Some platforms log transient QCA/BT errors (e.g. tx timeout / version read failed) before a successful "Retry BT power ON" and later "setup on UART is completed". Update btfwloaded() to base the result on the final observed state and avoid failing the test due to transient pre-retry errors. Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
1 parent 8322bc9 commit 55b6669

1 file changed

Lines changed: 68 additions & 37 deletions

File tree

Runner/utils/lib_bluetooth.sh

Lines changed: 68 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,54 +1696,85 @@ btfwpresent() {
16961696
}
16971697

16981698
btfwloaded() {
1699-
# Look at recent Bluetooth/QCA/WCN messages only, to keep noise low.
1700-
# Tune tail -n if needed.
1699+
# ---- Configurable patterns (override via env if needed) ----
1700+
# "Final success" (strongest marker that FW+UART setup completed)
1701+
success_re="${BTFW_SUCCESS_RE:-setup on UART is completed|setup on uart is completed}"
1702+
1703+
# "Fatal-ish" errors: these should FAIL only if they occur after the final success,
1704+
# otherwise they indicate transient issues during bring-up -> WARN.
1705+
fatal_re="${BTFW_FATAL_RE:-tx timeout|Reading QCA version information failed|failed to open firmware|firmware file.*not found|download.*firmware.*failed|failed to download.*firmware|timeout waiting for firmware|firmware.*load.*failed}"
1706+
1707+
# Retry/transient hints: if success exists and we see these, we likely want WARN.
1708+
transient_re="${BTFW_TRANSIENT_RE:-Retry BT power ON|retry bt power on|reset|re-init|reinit|failed.*\\(-110\\)}"
1709+
1710+
# ---- Collect recent relevant dmesg ----
1711+
# Filter for BT/QCA/WCN related lines; keep a reasonable window.
17011712
out="$(
17021713
dmesg 2>/dev/null \
1703-
| grep -i -E 'Bluetooth|hci[0-9]|QCA|wcn' \
1704-
| tail -n 400
1714+
| grep -i -E 'Bluetooth|hci[0-9]|QCA|wcn|btqca|WCN' \
1715+
| tail -n "${BTFW_DMESG_TAIL:-600}"
17051716
)"
1706-
1707-
# If we see nothing at all, be conservative and say "not loaded".
1717+
17081718
if [ -z "$out" ]; then
17091719
log_warn "btfwloaded: no recent Bluetooth/QCA/WCN messages in dmesg."
17101720
return 1
17111721
fi
1712-
1713-
ok=0
1714-
1715-
# --- Success patterns ---
1716-
# Try to catch typical QCA / UART setup success messages.
1717-
if printf '%s\n' "$out" | grep -qi -E \
1718-
'setup on UART is completed|setup on uart is completed'; then
1719-
ok=1
1720-
fi
1721-
1722-
if printf '%s\n' "$out" | grep -qi -E \
1723-
'QCA controller.*initialized|QCA controller.*setup|Bluetooth: hci[0-9]:.*QCA'; then
1724-
ok=1
1722+
1723+
# ---- Find last success line number and last fatal line number ----
1724+
# We use line order within $out (monotonic, no need for real timestamps).
1725+
last_success="$(
1726+
printf '%s\n' "$out" \
1727+
| awk -v IGNORECASE=1 -v re="$success_re" '
1728+
$0 ~ re { n=NR }
1729+
END { if (n>0) print n; else print 0 }
1730+
'
1731+
)"
1732+
1733+
last_fatal="$(
1734+
printf '%s\n' "$out" \
1735+
| awk -v IGNORECASE=1 -v re="$fatal_re" '
1736+
$0 ~ re { n=NR }
1737+
END { if (n>0) print n; else print 0 }
1738+
'
1739+
)"
1740+
1741+
# Also note if we saw any explicit transient/retry indicator
1742+
saw_transient="$(
1743+
printf '%s\n' "$out" \
1744+
| awk -v IGNORECASE=1 -v re="$transient_re" '
1745+
$0 ~ re { found=1; exit }
1746+
END { if (found) print 1; else print 0 }
1747+
'
1748+
)"
1749+
1750+
# ---- Decision tree ----
1751+
if [ "$last_success" -eq 0 ]; then
1752+
log_warn "btfwloaded: no final success marker found (pattern: $success_re). Recent tail:"
1753+
printf '%s\n' "$out" | tail -n 30 >&2
1754+
return 1
17251755
fi
1726-
1727-
# Some stacks log generic "firmware loaded" style messages:
1728-
if printf '%s\n' "$out" | grep -qi -E \
1729-
'firmware.*loaded|firmware.*downloaded|download of.*firmware completed'; then
1730-
ok=1
1756+
1757+
# Fatal after success => FAIL (setup looked done, but then errors happened later)
1758+
if [ "$last_fatal" -gt "$last_success" ]; then
1759+
log_warn "btfwloaded: fatal BT/QCA errors occurred after final setup marker; treating as FAIL."
1760+
printf '%s\n' "$out" | tail -n 40 >&2
1761+
return 1
17311762
fi
1732-
1733-
# --- Failure / warning patterns ---
1734-
# Any of these will force a "not OK" verdict even if we saw a success marker.
1735-
if printf '%s\n' "$out" | grep -qi -E \
1736-
'tx timeout|Reading QCA version information failed|failed to open firmware|firmware file.*not found|no such file or directory.*firmware|download.*firmware.*failed|failed to download.*firmware|timeout waiting for firmware|firmware.*load.*failed'; then
1737-
ok=0
1763+
1764+
# Fatal before success OR transient hints => WARN (retry scenario)
1765+
if [ "$last_fatal" -gt 0 ] && [ "$last_fatal" -lt "$last_success" ]; then
1766+
log_warn "btfwloaded: transient errors occurred before final setup marker; treating as WARN."
1767+
printf '%s\n' "$out" | tail -n 30 >&2
1768+
return 2
17381769
fi
1739-
1740-
if [ "$ok" -ne 1 ]; then
1741-
log_warn "btfwloaded: firmware load **not** considered successful. Recent BT dmesg tail:"
1742-
printf '%s\n' "$out" | tail -n 20 >&2
1743-
return 1
1770+
1771+
if [ "$saw_transient" -eq 1 ]; then
1772+
log_warn "btfwloaded: retry/transient indicators seen; final setup marker present; treating as WARN."
1773+
printf '%s\n' "$out" | tail -n 30 >&2
1774+
return 2
17441775
fi
1745-
1746-
log_info "btfwloaded: firmware load appears successful (no fatal errors in recent dmesg)."
1776+
1777+
log_info "btfwloaded: firmware load/setup completed cleanly (no fatal errors after final setup marker)."
17471778
return 0
17481779
}
17491780

0 commit comments

Comments
 (0)