Skip to content

Commit ca5d886

Browse files
authored
Merge pull request #276 from smuppand/Bluetooth-fix
treat transient BT firmware dmesg errors as WARN when recovery succeeds
2 parents 8322bc9 + e5772c0 commit ca5d886

2 files changed

Lines changed: 91 additions & 43 deletions

File tree

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ log_info "------------------------------------------------------------"
7474
log_info "Starting $TESTNAME"
7575

7676
log_info "Checking dependencies: bluetoothctl hciconfig dmesg lsmod"
77-
check_dependencies bluetoothctl hciconfig dmesg lsmod
78-
77+
if ! check_dependencies bluetoothctl hciconfig dmesg lsmod; then
78+
echo "$TESTNAME SKIP" > "$RES_FILE"
79+
exit 0
80+
fi
7981
# ---------- Bluetooth service / daemon ----------
8082
log_info "Checking if bluetoothd (or bluetooth.service) is running..."
8183
if btsvcactive; then
@@ -108,11 +110,26 @@ else
108110
fi
109111

110112
# ---------- Firmware load dmesg ----------
111-
if btfwloaded; then
112-
log_pass "Firmware load/setup appears completed (dmesg)."
113+
if command -v btfwloaded >/dev/null 2>&1; then
114+
btfwloaded
115+
rc=$?
116+
case "$rc" in
117+
0)
118+
log_pass "Firmware load/setup appears completed (dmesg)."
119+
;;
120+
2)
121+
log_warn "Firmware load/setup completed after retry, transient errors seen earlier (dmesg)."
122+
inc_warn
123+
;;
124+
*)
125+
log_fail "Firmware load/setup does NOT look clean (see recent Bluetooth/QCA/WCN dmesg lines above)."
126+
inc_fail
127+
;;
128+
esac
113129
else
114-
log_fail "Firmware load/setup does NOT look clean (see recent Bluetooth/QCA/WCN dmesg lines above)."
115-
inc_fail
130+
# No SKIP: continue test, just warn.
131+
log_warn "btfwloaded() helper not available firmware-load dmesg validation not performed."
132+
inc_warn
116133
fi
117134

118135
# ---------- Kernel modules / KMD ----------

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)