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
8 changes: 6 additions & 2 deletions Runner/suites/Connectivity/Bluetooth/BT_ON_OFF/BT_ON_OFF.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
metadata:
name: bt-on-off
format: "Lava-Test Test Definition 1.0"
description: "Toggle Bluetooth on/off using qcom-linux-testkit BT_ON_FF"
description: "Toggle Bluetooth on/off using qcom-linux-testkit BT_ON_OFF"
os:
- linux
scope:
- functional

params:
BT_ADAPTER: ""
BT_POWER_CYCLE_DELAY: "10"
BT_POWER_ON_ATTEMPTS: "2"
BT_POWER_ON_RETRY_DELAY: "10"
BT_RESTART_SERVICE_ON_RETRY: "1"

run:
steps:
- REPO_PATH=$PWD
- cd Runner/suites/Connectivity/Bluetooth/BT_ON_OFF
- ./run.sh --adapter "${BT_ADAPTER}" || true
- ./run.sh --adapter "${BT_ADAPTER}" --power-cycle-delay "${BT_POWER_CYCLE_DELAY}" --power-on-attempts "${BT_POWER_ON_ATTEMPTS}" --power-on-retry-delay "${BT_POWER_ON_RETRY_DELAY}" --restart-service-on-retry "${BT_RESTART_SERVICE_ON_RETRY}" || true
- $REPO_PATH/Runner/utils/send-to-lava.sh BT_ON_OFF.res
153 changes: 132 additions & 21 deletions Runner/suites/Connectivity/Bluetooth/BT_ON_OFF/run.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/sh

# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause# BT_ON_OFF - Basic Bluetooth power toggle validation (non-expect version)
# SPDX-License-Identifier: BSD-3-Clause
# 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
cd "$(dirname "$0")" || exit 1
pwd
)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"
Expand Down Expand Up @@ -39,19 +41,72 @@ fi
# BT_ADAPTER can be set from CLI via --adapter or from environment.
BT_ADAPTER="${BT_ADAPTER-}"

# QCA/WCN UART controllers may need a short settle window after Powered=no
# before a new Powered=yes request. Defaults are CI-safe but overridable.
BT_POWER_CYCLE_DELAY="${BT_POWER_CYCLE_DELAY:-10}"
BT_POWER_ON_ATTEMPTS="${BT_POWER_ON_ATTEMPTS:-2}"
BT_POWER_ON_RETRY_DELAY="${BT_POWER_ON_RETRY_DELAY:-10}"
BT_RESTART_SERVICE_ON_RETRY="${BT_RESTART_SERVICE_ON_RETRY:-1}"

while [ "$#" -gt 0 ]; do
case "$1" in
--adapter)
BT_ADAPTER="$2"
shift 2
;;
--power-cycle-delay)
BT_POWER_CYCLE_DELAY="$2"
shift 2
;;
--power-on-attempts)
BT_POWER_ON_ATTEMPTS="$2"
shift 2
;;
--power-on-retry-delay)
BT_POWER_ON_RETRY_DELAY="$2"
shift 2
;;
--restart-service-on-retry)
BT_RESTART_SERVICE_ON_RETRY="$2"
shift 2
;;
*)
log_warn "Unknown argument ignored: $1"
shift 1
;;
esac
done

case "$BT_POWER_CYCLE_DELAY" in
''|*[!0-9]*)
BT_POWER_CYCLE_DELAY=10
;;
esac

case "$BT_POWER_ON_ATTEMPTS" in
''|*[!0-9]*)
BT_POWER_ON_ATTEMPTS=2
;;
esac

case "$BT_POWER_ON_RETRY_DELAY" in
''|*[!0-9]*)
BT_POWER_ON_RETRY_DELAY=10
;;
esac

case "$BT_RESTART_SERVICE_ON_RETRY" in
0|1)
;;
*)
BT_RESTART_SERVICE_ON_RETRY=1
;;
esac

if [ "$BT_POWER_ON_ATTEMPTS" -lt 1 ] 2>/dev/null; then
BT_POWER_ON_ATTEMPTS=1
fi

TESTNAME="BT_ON_OFF"
testpath="$(find_test_case_by_name "$TESTNAME")" || {
log_fail "$TESTNAME : Test directory not found."
Expand All @@ -65,9 +120,10 @@ rm -f "$res_file"

log_info "------------------------------------------------------------"
log_info "Starting $TESTNAME Testcase"
log_info "Config: BT_POWER_CYCLE_DELAY=${BT_POWER_CYCLE_DELAY}s BT_POWER_ON_ATTEMPTS=$BT_POWER_ON_ATTEMPTS BT_POWER_ON_RETRY_DELAY=${BT_POWER_ON_RETRY_DELAY}s BT_RESTART_SERVICE_ON_RETRY=$BT_RESTART_SERVICE_ON_RETRY"
log_info "Checking dependency: bluetoothctl"

# verify that all necessary dependencies
# Verify that all necessary dependencies are available.
check_dependencies bluetoothctl pgrep

log_info "Checking if bluetoothd is running..."
Expand All @@ -80,6 +136,7 @@ while [ "$retry" -lt "$MAX_RETRIES" ]; do
log_info "bluetoothd is running"
break
fi

log_warn "bluetoothd not running, retrying in ${RETRY_DELAY}s..."
sleep "$RETRY_DELAY"
retry=$((retry + 1))
Expand All @@ -97,7 +154,7 @@ fi
if [ -n "$BT_ADAPTER" ]; then
ADAPTER="$BT_ADAPTER"
log_info "Using adapter from BT_ADAPTER/CLI: $ADAPTER"

if command -v bt_adapter_is_usable >/dev/null 2>&1; then
if ! bt_adapter_is_usable "$ADAPTER"; then
log_warn "Requested adapter '$ADAPTER' is not currently UP/RUNNING with a valid BD address."
Expand All @@ -106,7 +163,7 @@ if [ -n "$BT_ADAPTER" ]; then
fi
else
bt_log_hci_candidates || true

if command -v bt_select_usable_adapter >/dev/null 2>&1; then
ADAPTER="$(bt_select_usable_adapter 2>/dev/null || true)"
elif findhcisysfs >/dev/null 2>&1; then
Expand All @@ -115,19 +172,19 @@ else
ADAPTER=""
fi
fi
# --- NEW: warn/diag if non-interactive "bluetoothctl list" is empty (non-fatal) ---

# Warn/diag if non-interactive "bluetoothctl list" is empty. This is non-fatal.
btwarniflistempty "$ADAPTER" || true

# Ensure controller is visible to bluetoothctl (try public-addr if needed)
# Ensure controller is visible to bluetoothctl, trying public-addr if needed.
if ! bt_ensure_controller_visible "$ADAPTER"; then
# --- NEW: print diagnostics before skipping ---
btloghcidiag "$ADAPTER"
btloghcidiag "$ADAPTER" failure "$testpath" || true
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
# Read initial power state.
initial_power="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
[ -z "$initial_power" ] && initial_power="unknown"
log_info "Initial Powered = $initial_power"
Expand All @@ -136,6 +193,7 @@ log_info "Initial Powered = $initial_power"
log_info "Powering OFF..."
if ! btpower "$ADAPTER" off; then
log_fail "btpower($ADAPTER, off) failed (command-level error)."
btloghcidiag "$ADAPTER" failure "$testpath" || true
echo "$TESTNAME FAIL" > "$res_file"
exit 0
fi
Expand All @@ -147,30 +205,83 @@ if [ "$after_off" = "no" ]; then
log_pass "Post-OFF verification: Powered=no (as expected)."
else
log_fail "Post-OFF verification failed (Powered=$after_off)."
btloghcidiag "$ADAPTER" failure "$testpath" || true
echo "$TESTNAME FAIL" > "$res_file"
exit 0
fi

# ---- Power ON test ----
log_info "Waiting ${BT_POWER_CYCLE_DELAY}s before Powering ON..."
sleep "$BT_POWER_CYCLE_DELAY"

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
on_attempt=1
on_success=0

after_on="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
[ -z "$after_on" ] && after_on="unknown"
while [ "$on_attempt" -le "$BT_POWER_ON_ATTEMPTS" ]; do
log_info "Power ON attempt $on_attempt/$BT_POWER_ON_ATTEMPTS"

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

if [ "$after_on" = "yes" ]; then
on_success=1
break
fi

log_warn "Power ON command returned success, but post-check Powered=$after_on"
else
log_warn "btpower($ADAPTER, on) failed on attempt $on_attempt"
fi

log_warn "Collecting Bluetooth diagnostics after failed Power ON attempt $on_attempt"
btloghcidiag "$ADAPTER" failure "$testpath" || true

if [ "$on_attempt" -lt "$BT_POWER_ON_ATTEMPTS" ]; then
log_warn "Preparing controlled Power ON retry after ${BT_POWER_ON_RETRY_DELAY}s"
sleep "$BT_POWER_ON_RETRY_DELAY"

if command -v rfkill >/dev/null 2>&1; then
log_info "Running rfkill unblock bluetooth before retry"
rfkill unblock bluetooth >/dev/null 2>&1 || true
elif command -v rfkillunblocksysfs >/dev/null 2>&1; then
log_info "Running rfkillunblocksysfs before retry"
rfkillunblocksysfs >/dev/null 2>&1 || true
else
log_warn "No rfkill unblock helper available before retry"
fi

if [ "$BT_RESTART_SERVICE_ON_RETRY" -eq 1 ] 2>/dev/null && command -v systemctl >/dev/null 2>&1; then
log_info "Restarting bluetooth.service before retry"
systemctl restart bluetooth >/dev/null 2>&1 || log_warn "systemctl restart bluetooth failed"
sleep 3
fi

if command -v bt_ensure_controller_visible >/dev/null 2>&1; then
bt_ensure_controller_visible "$ADAPTER" || log_warn "Controller visibility check failed before retry"
fi
fi

on_attempt=$((on_attempt + 1))
done

if [ "$on_success" -eq 1 ]; then
if [ "$on_attempt" -gt 1 ]; then
log_warn "Power ON recovered on attempt $on_attempt/$BT_POWER_ON_ATTEMPTS"
fi

if [ "$after_on" = "yes" ]; then
# --- NEW: post-check (covers your "list is empty after run" symptom) ---
btwarniflistempty "$ADAPTER" || true

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)."
after_on="$(btgetpower "$ADAPTER" 2>/dev/null || true)"
[ -z "$after_on" ] && after_on="unknown"

log_fail "Post-ON verification failed after $BT_POWER_ON_ATTEMPTS attempt(s) (Powered=$after_on)."
btloghcidiag "$ADAPTER" failure "$testpath" || true
echo "$TESTNAME FAIL" > "$res_file"
exit 0
Loading
Loading