|
| 1 | +#!/bin/sh |
| 2 | +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause-Clear |
| 4 | +# |
| 5 | +# BT_FW_KMD_Service - Bluetooth FW + KMD + service + controller infra validation |
| 6 | +# Non-expect version, using lib_bluetooth.sh helpers. |
| 7 | + |
| 8 | +# ---------- init_env + tools ---------- |
| 9 | +SCRIPT_DIR="$( |
| 10 | + cd "$(dirname "$0")" || exit 1 |
| 11 | + pwd |
| 12 | +)" |
| 13 | +INIT_ENV="" |
| 14 | +SEARCH="$SCRIPT_DIR" |
| 15 | + |
| 16 | +while [ "$SEARCH" != "/" ]; do |
| 17 | + if [ -f "$SEARCH/init_env" ]; then |
| 18 | + INIT_ENV="$SEARCH/init_env" |
| 19 | + break |
| 20 | + fi |
| 21 | + SEARCH=$(dirname "$SEARCH") |
| 22 | +done |
| 23 | + |
| 24 | +if [ -z "$INIT_ENV" ]; then |
| 25 | + echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +if [ -z "${__INIT_ENV_LOADED:-}" ]; then |
| 30 | + # shellcheck disable=SC1090 |
| 31 | + . "$INIT_ENV" |
| 32 | + __INIT_ENV_LOADED=1 |
| 33 | +fi |
| 34 | + |
| 35 | +# shellcheck disable=SC1091 |
| 36 | +. "$TOOLS/functestlib.sh" |
| 37 | +# shellcheck disable=SC1091 |
| 38 | +. "$TOOLS/lib_bluetooth.sh" |
| 39 | + |
| 40 | +# ---------- CLI / env parameters ---------- |
| 41 | +BT_ADAPTER="${BT_ADAPTER-}" |
| 42 | + |
| 43 | +while [ "$#" -gt 0 ]; do |
| 44 | + case "$1" in |
| 45 | + --adapter) |
| 46 | + BT_ADAPTER="$2" |
| 47 | + shift 2 |
| 48 | + ;; |
| 49 | + *) |
| 50 | + log_warn "Unknown argument ignored: $1" |
| 51 | + shift 1 |
| 52 | + ;; |
| 53 | + esac |
| 54 | +done |
| 55 | + |
| 56 | +TESTNAME="BT_FW_KMD_Service" |
| 57 | +testpath="$(find_test_case_by_name "$TESTNAME")" || { |
| 58 | + log_fail "$TESTNAME : Test directory not found." |
| 59 | + echo "$TESTNAME FAIL" > "./$TESTNAME.res" |
| 60 | + exit 1 |
| 61 | +} |
| 62 | + |
| 63 | +cd "$testpath" || exit 1 |
| 64 | +RES_FILE="./${TESTNAME}.res" |
| 65 | +rm -f "$RES_FILE" |
| 66 | + |
| 67 | +FAIL_COUNT=0 |
| 68 | +WARN_COUNT=0 |
| 69 | + |
| 70 | +inc_fail() { FAIL_COUNT=$((FAIL_COUNT + 1)); } |
| 71 | +inc_warn() { WARN_COUNT=$((WARN_COUNT + 1)); } |
| 72 | + |
| 73 | +log_info "------------------------------------------------------------" |
| 74 | +log_info "Starting $TESTNAME" |
| 75 | + |
| 76 | +log_info "Checking dependencies: bluetoothctl hciconfig dmesg lsmod" |
| 77 | +check_dependencies bluetoothctl hciconfig dmesg lsmod |
| 78 | + |
| 79 | +# ---------- Bluetooth service / daemon ---------- |
| 80 | +log_info "Checking if bluetoothd (or bluetooth.service) is running..." |
| 81 | +if btsvcactive; then |
| 82 | + log_pass "Bluetooth service/daemon active." |
| 83 | +else |
| 84 | + log_fail "Bluetooth service/daemon NOT active." |
| 85 | + inc_fail |
| 86 | +fi |
| 87 | + |
| 88 | +# ---------- DT node / compatible ---------- |
| 89 | +BT_COMPAT_LIST=" |
| 90 | +qcom,wcn7850-bt |
| 91 | +qcom,wcn6855-bt |
| 92 | +qcom,bluetooth |
| 93 | +" |
| 94 | + |
| 95 | +if dt_confirm_node_or_compatible_all "BT" "$BT_COMPAT_LIST"; then |
| 96 | + log_pass "DT node/compatible for BT present (at least one entry matched)." |
| 97 | +else |
| 98 | + log_fail "DT node/compatible for BT NOT found." |
| 99 | + inc_fail |
| 100 | +fi |
| 101 | + |
| 102 | +# ---------- Firmware presence ---------- |
| 103 | +if fw_dir="$(btfwpresent 2>/dev/null)"; then |
| 104 | + log_pass "Firmware present in: $fw_dir" |
| 105 | +else |
| 106 | + log_warn "No BT firmware matching msbtfw*/msnv* found under standard firmware paths." |
| 107 | + inc_warn |
| 108 | +fi |
| 109 | + |
| 110 | +# ---------- Firmware load dmesg ---------- |
| 111 | +if btfwloaded; then |
| 112 | + log_pass "Firmware load/setup appears completed (dmesg)." |
| 113 | +else |
| 114 | + log_fail "Firmware load/setup does NOT look clean (see recent Bluetooth/QCA/WCN dmesg lines above)." |
| 115 | + inc_fail |
| 116 | +fi |
| 117 | + |
| 118 | +# ---------- Kernel modules / KMD ---------- |
| 119 | +if btkmdpresent; then |
| 120 | + log_pass "Kernel BT driver stack present (bluetooth/hci_uart/btqca or built-in)." |
| 121 | +else |
| 122 | + log_fail "Kernel BT driver stack not detected (no bluetooth/hci_uart/btqca in sysfs/dmesg)." |
| 123 | + inc_fail |
| 124 | +fi |
| 125 | + |
| 126 | +# ---------- HCI presence ---------- |
| 127 | +if bthcipresent; then |
| 128 | + log_pass "HCI present in /sys/class/bluetooth." |
| 129 | +else |
| 130 | + log_fail "No /sys/class/bluetooth/hci* found (HCI not up)." |
| 131 | + inc_fail |
| 132 | +fi |
| 133 | + |
| 134 | +# --- Bluetooth service / daemon check via btsvcactive() --- |
| 135 | +if btsvcactive; then |
| 136 | + log_pass "Bluetooth service active (systemd bluetooth.service or bluetoothd)." |
| 137 | +else |
| 138 | + log_warn "Bluetooth service is not active (bluetooth.service inactive and bluetoothd not running)." |
| 139 | + inc_warn |
| 140 | +fi |
| 141 | + |
| 142 | +# ----------------------------- |
| 143 | +# Detect adapter (CLI/ENV > auto-detect) |
| 144 | +# ----------------------------- |
| 145 | +if [ -n "$BT_ADAPTER" ]; then |
| 146 | + ADAPTER="$BT_ADAPTER" |
| 147 | + log_info "Using adapter from BT_ADAPTER/CLI: $ADAPTER" |
| 148 | +elif findhcisysfs >/dev/null 2>&1; then |
| 149 | + ADAPTER="$(findhcisysfs 2>/dev/null || true)" |
| 150 | +else |
| 151 | + ADAPTER="" |
| 152 | +fi |
| 153 | + |
| 154 | +if [ -z "$ADAPTER" ]; then |
| 155 | + log_warn "No HCI adapter found; skipping BT FW/KMD test." |
| 156 | + echo "$TESTNAME SKIP" > "./$TESTNAME.res" |
| 157 | + exit 0 |
| 158 | +fi |
| 159 | + |
| 160 | +# ---------- BD address sanity check ---------- |
| 161 | +if [ -n "$ADAPTER" ]; then |
| 162 | + if btbdok "$ADAPTER"; then |
| 163 | + log_pass "BD address sane for $ADAPTER (not all zeros)." |
| 164 | + else |
| 165 | + log_fail "BD address invalid or all zeros for $ADAPTER." |
| 166 | + inc_fail |
| 167 | + fi |
| 168 | +fi |
| 169 | + |
| 170 | +# ---------- Controller visibility (bluetoothctl list + public-addr path) ---------- |
| 171 | +if [ -n "$ADAPTER" ]; then |
| 172 | + if bt_ensure_controller_visible "$ADAPTER"; then |
| 173 | + # We don't need to log here bt_ensure_controller_visible already logs. |
| 174 | + : |
| 175 | + else |
| 176 | + # For this infra test we treat this as WARN, not FAIL: |
| 177 | + # stack is otherwise OK (firmware, KMD, HCI, BD). |
| 178 | + log_warn "No controller in 'bluetoothctl list' (controller not fully instantiated)." |
| 179 | + inc_warn |
| 180 | + fi |
| 181 | +else |
| 182 | + log_warn "Controller visibility not checked (no adapter determined)." |
| 183 | + inc_warn |
| 184 | +fi |
| 185 | + |
| 186 | +# ---------- Optional: dump some useful diagnostics ---------- |
| 187 | +log_info "=== hciconfig -a (if available) ===" |
| 188 | +if command -v hciconfig >/dev/null 2>&1; then |
| 189 | + hciconfig -a || true |
| 190 | +else |
| 191 | + log_warn "hciconfig command not available." |
| 192 | + inc_warn |
| 193 | +fi |
| 194 | + |
| 195 | +log_info "=== bluetoothctl list (controllers) ===" |
| 196 | +bluetoothctl list 2>/dev/null || true |
| 197 | + |
| 198 | +log_info "=== lsmod (subset: BT stack) ===" |
| 199 | +lsmod 2>/dev/null | grep -E '^(bluetooth|hci_uart|btqca|btbcm|rfkill|cfg80211)\b' || true |
| 200 | + |
| 201 | +# ---------- Final result ---------- |
| 202 | +log_info "Completed with WARN=${WARN_COUNT}, FAIL=${FAIL_COUNT}" |
| 203 | + |
| 204 | +if [ "$FAIL_COUNT" -gt 0 ]; then |
| 205 | + echo "$TESTNAME FAIL" > "$RES_FILE" |
| 206 | +else |
| 207 | + echo "$TESTNAME PASS" > "$RES_FILE" |
| 208 | +fi |
| 209 | + |
| 210 | +exit 0 |
0 commit comments