Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 210 additions & 0 deletions Runner/suites/Connectivity/Bluetooth/BT_FW_KMD_Service/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
# BT_FW_KMD_Service - Bluetooth FW + KMD + service + controller infra validation
# Non-expect version, using lib_bluetooth.sh helpers.

# ---------- init_env + tools ----------
SCRIPT_DIR="$(
cd "$(dirname "$0")" || exit 1
pwd
)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"

while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

if [ -z "${__INIT_ENV_LOADED:-}" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
__INIT_ENV_LOADED=1
fi

# shellcheck disable=SC1091
. "$TOOLS/functestlib.sh"
# shellcheck disable=SC1091
. "$TOOLS/lib_bluetooth.sh"

# ---------- CLI / env parameters ----------
BT_ADAPTER="${BT_ADAPTER-}"

while [ "$#" -gt 0 ]; do
case "$1" in
--adapter)
BT_ADAPTER="$2"
shift 2
;;
*)
log_warn "Unknown argument ignored: $1"
shift 1
;;
esac
done

TESTNAME="BT_FW_KMD_Service"
testpath="$(find_test_case_by_name "$TESTNAME")" || {
log_fail "$TESTNAME : Test directory not found."
echo "$TESTNAME FAIL" > "./$TESTNAME.res"
exit 1
}

cd "$testpath" || exit 1
RES_FILE="./${TESTNAME}.res"
rm -f "$RES_FILE"

FAIL_COUNT=0
WARN_COUNT=0

inc_fail() { FAIL_COUNT=$((FAIL_COUNT + 1)); }
inc_warn() { WARN_COUNT=$((WARN_COUNT + 1)); }

log_info "------------------------------------------------------------"
log_info "Starting $TESTNAME"

log_info "Checking dependencies: bluetoothctl hciconfig dmesg lsmod"
check_dependencies bluetoothctl hciconfig dmesg lsmod

# ---------- Bluetooth service / daemon ----------
log_info "Checking if bluetoothd (or bluetooth.service) is running..."
if btsvcactive; then
log_pass "Bluetooth service/daemon active."
else
log_fail "Bluetooth service/daemon NOT active."
inc_fail
fi

# ---------- DT node / compatible ----------
BT_COMPAT_LIST="
qcom,wcn7850-bt
qcom,wcn6855-bt
qcom,bluetooth
"

if dt_confirm_node_or_compatible_all "BT" "$BT_COMPAT_LIST"; then
log_pass "DT node/compatible for BT present (at least one entry matched)."
else
log_fail "DT node/compatible for BT NOT found."
inc_fail
fi

# ---------- Firmware presence ----------
if fw_dir="$(btfwpresent 2>/dev/null)"; then
log_pass "Firmware present in: $fw_dir"
else
log_warn "No BT firmware matching msbtfw*/msnv* found under standard firmware paths."
inc_warn
fi

# ---------- Firmware load dmesg ----------
if btfwloaded; then
log_pass "Firmware load/setup appears completed (dmesg)."
else
log_fail "Firmware load/setup does NOT look clean (see recent Bluetooth/QCA/WCN dmesg lines above)."
inc_fail
fi

# ---------- Kernel modules / KMD ----------
if btkmdpresent; then
log_pass "Kernel BT driver stack present (bluetooth/hci_uart/btqca or built-in)."
else
log_fail "Kernel BT driver stack not detected (no bluetooth/hci_uart/btqca in sysfs/dmesg)."
inc_fail
fi

# ---------- HCI presence ----------
if bthcipresent; then
log_pass "HCI present in /sys/class/bluetooth."
else
log_fail "No /sys/class/bluetooth/hci* found (HCI not up)."
inc_fail
fi

# --- Bluetooth service / daemon check via btsvcactive() ---
if btsvcactive; then
log_pass "Bluetooth service active (systemd bluetooth.service or bluetoothd)."
else
log_warn "Bluetooth service is not active (bluetooth.service inactive and bluetoothd not running)."
inc_warn
fi

# -----------------------------
# Detect adapter (CLI/ENV > auto-detect)
# -----------------------------
if [ -n "$BT_ADAPTER" ]; then
ADAPTER="$BT_ADAPTER"
log_info "Using adapter from BT_ADAPTER/CLI: $ADAPTER"
elif findhcisysfs >/dev/null 2>&1; then
ADAPTER="$(findhcisysfs 2>/dev/null || true)"
else
ADAPTER=""
fi

if [ -z "$ADAPTER" ]; then
log_warn "No HCI adapter found; skipping BT FW/KMD test."
echo "$TESTNAME SKIP" > "./$TESTNAME.res"
exit 0
fi

# ---------- BD address sanity check ----------
if [ -n "$ADAPTER" ]; then
if btbdok "$ADAPTER"; then
log_pass "BD address sane for $ADAPTER (not all zeros)."
else
log_fail "BD address invalid or all zeros for $ADAPTER."
inc_fail
fi
fi

# ---------- Controller visibility (bluetoothctl list + public-addr path) ----------
if [ -n "$ADAPTER" ]; then
if bt_ensure_controller_visible "$ADAPTER"; then
# We don't need to log here bt_ensure_controller_visible already logs.
:
else
# For this infra test we treat this as WARN, not FAIL:
# stack is otherwise OK (firmware, KMD, HCI, BD).
log_warn "No controller in 'bluetoothctl list' (controller not fully instantiated)."
inc_warn
fi
else
log_warn "Controller visibility not checked (no adapter determined)."
inc_warn
fi

# ---------- Optional: dump some useful diagnostics ----------
log_info "=== hciconfig -a (if available) ==="
if command -v hciconfig >/dev/null 2>&1; then
hciconfig -a || true
else
log_warn "hciconfig command not available."
inc_warn
fi

log_info "=== bluetoothctl list (controllers) ==="
bluetoothctl list 2>/dev/null || true

log_info "=== lsmod (subset: BT stack) ==="
lsmod 2>/dev/null | grep -E '^(bluetooth|hci_uart|btqca|btbcm|rfkill|cfg80211)\b' || true

# ---------- Final result ----------
log_info "Completed with WARN=${WARN_COUNT}, FAIL=${FAIL_COUNT}"

if [ "$FAIL_COUNT" -gt 0 ]; then
echo "$TESTNAME FAIL" > "$RES_FILE"
else
echo "$TESTNAME PASS" > "$RES_FILE"
fi

exit 0
165 changes: 165 additions & 0 deletions Runner/suites/Connectivity/Bluetooth/BT_ON_OFF/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear
# BT_ON_OFF - Basic Bluetooth power toggle validation (non-expect version)

# Robustly find and source init_env
SCRIPT_DIR="$(
cd "$(dirname "$0")" || exit 1
pwd
)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"

while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

# Only source once (idempotent)
if [ -z "${__INIT_ENV_LOADED:-}" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
__INIT_ENV_LOADED=1
fi

# shellcheck disable=SC1091
. "$TOOLS/functestlib.sh"
# shellcheck disable=SC1091
. "$TOOLS/lib_bluetooth.sh"

# ---------- CLI / env parameters ----------
# BT_ADAPTER can be set from CLI via --adapter or from environment.
BT_ADAPTER="${BT_ADAPTER-}"

while [ "$#" -gt 0 ]; do
case "$1" in
--adapter)
BT_ADAPTER="$2"
shift 2
;;
*)
log_warn "Unknown argument ignored: $1"
shift 1
;;
esac
done

TESTNAME="BT_ON_OFF"
testpath="$(find_test_case_by_name "$TESTNAME")" || {
log_fail "$TESTNAME : Test directory not found."
echo "$TESTNAME FAIL" > "./$TESTNAME.res"
exit 1
}

cd "$testpath" || exit 1
res_file="./$TESTNAME.res"
rm -f "$res_file"

log_info "------------------------------------------------------------"
log_info "Starting $TESTNAME Testcase"
log_info "Checking dependency: bluetoothctl"

# verify that all necessary dependencies
check_dependencies bluetoothctl pgrep

log_info "Checking if bluetoothd is running..."
MAX_RETRIES=3
RETRY_DELAY=5
retry=0

while [ "$retry" -lt "$MAX_RETRIES" ]; do
if pgrep bluetoothd >/dev/null 2>&1; then
log_info "bluetoothd is running"
break
fi
log_warn "bluetoothd not running, retrying in ${RETRY_DELAY}s..."
sleep "$RETRY_DELAY"
retry=$((retry + 1))
done

if [ "$retry" -eq "$MAX_RETRIES" ]; then
log_fail "Bluetooth daemon not detected after ${MAX_RETRIES} attempts."
echo "$TESTNAME FAIL" > "$res_file"
exit 0
fi

# -----------------------------
# Detect adapter with precedence: CLI/ENV > auto-detect
# -----------------------------
if [ -n "$BT_ADAPTER" ]; then
ADAPTER="$BT_ADAPTER"
log_info "Using adapter from BT_ADAPTER/CLI: $ADAPTER"
elif findhcisysfs >/dev/null 2>&1; then
ADAPTER="$(findhcisysfs 2>/dev/null || true)"
else
ADAPTER=""
fi

if [ -n "$ADAPTER" ]; then
log_info "Using adapter: $ADAPTER"
else
log_warn "No HCI adapter found; skipping test."
echo "$TESTNAME SKIP" > "./$TESTNAME.res"
exit 0
fi

# Ensure controller is visible to bluetoothctl (try public-addr if needed)
if ! bt_ensure_controller_visible "$ADAPTER"; then
log_warn "SKIP — no controller visible to bluetoothctl (HCI RAW/DOWN or attach incomplete)."
echo "$TESTNAME SKIP" > "$res_file"
exit 0
fi

# Read initial power state
initial_power="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
[ -z "$initial_power" ] && initial_power="unknown"
log_info "Initial Powered = $initial_power"

# ---- Power OFF test ----
log_info "Powering OFF..."
if ! btpower "$ADAPTER" off; then
log_fail "btpower($ADAPTER, off) failed (command-level error)."
echo "$TESTNAME FAIL" > "$res_file"
exit 0
fi

after_off="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
[ -z "$after_off" ] && after_off="unknown"

if [ "$after_off" = "no" ]; then
log_pass "Post-OFF verification: Powered=no (as expected)."
else
log_fail "Post-OFF verification failed (Powered=$after_off)."
echo "$TESTNAME FAIL" > "$res_file"
exit 0
fi

# ---- Power ON test ----
log_info "Powering ON..."
if ! btpower "$ADAPTER" on; then
log_fail "btpower($ADAPTER, on) failed (command-level error)."
echo "$TESTNAME FAIL" > "$res_file"
exit 0
fi

after_on="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
[ -z "$after_on" ] && after_on="unknown"

if [ "$after_on" = "yes" ]; then
log_pass "Post-ON verification: Powered=yes (as expected)."
echo "$TESTNAME PASS" > "$res_file"
exit 0
fi

log_fail "Post-ON verification failed (Powered=$after_on)."
echo "$TESTNAME FAIL" > "$res_file"
exit 0
Loading
Loading