|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 4 | +# SPDX-License-Identifier: BSD-3-Clause-Clear |
| 5 | + |
| 6 | +# Source init_env and functestlib.sh |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 8 | +INIT_ENV="" |
| 9 | +SEARCH="$SCRIPT_DIR" |
| 10 | +while [ "$SEARCH" != "/" ]; do |
| 11 | + if [ -f "$SEARCH/init_env" ]; then |
| 12 | + INIT_ENV="$SEARCH/init_env" |
| 13 | + break |
| 14 | + fi |
| 15 | + SEARCH=$(dirname "$SEARCH") |
| 16 | +done |
| 17 | + |
| 18 | +if [ -z "$INIT_ENV" ]; then |
| 19 | + echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +# shellcheck disable=SC1090 |
| 24 | +. "$INIT_ENV" |
| 25 | + |
| 26 | +# shellcheck disable=SC1090,SC1091 |
| 27 | +. "$TOOLS/functestlib.sh" |
| 28 | + |
| 29 | +TESTNAME="Bluetooth" |
| 30 | +test_path=$(find_test_case_by_name "$TESTNAME") || { |
| 31 | + log_fail "$TESTNAME : Test directory not found." |
| 32 | + echo "$TESTNAME FAIL" > "./$TESTNAME.res" |
| 33 | + exit 1 |
| 34 | +} |
| 35 | + |
| 36 | +cd "$test_path" || exit 1 |
| 37 | +res_file="./$TESTNAME.res" |
| 38 | +rm -f "$res_file" |
| 39 | + |
| 40 | +log_info "-----------------------------------------------------------------------------------------" |
| 41 | +log_info "-------------------Starting $TESTNAME Testcase----------------------------" |
| 42 | +log_info "Checking dependency: bluetoothctl" |
| 43 | +check_dependencies bluetoothctl |
| 44 | + |
| 45 | +log_info "Checking if bluetoothd is running..." |
| 46 | +MAX_RETRIES=3 |
| 47 | +RETRY_DELAY=5 |
| 48 | +retry=0 |
| 49 | + |
| 50 | +while [ "$retry" -lt "$MAX_RETRIES" ]; do |
| 51 | + if pgrep bluetoothd >/dev/null 2>&1; then |
| 52 | + log_info "bluetoothd is running" |
| 53 | + break |
| 54 | + fi |
| 55 | + log_warn "bluetoothd not running, retrying in ${RETRY_DELAY}s..." |
| 56 | + sleep "$RETRY_DELAY" |
| 57 | + retry=$((retry + 1)) |
| 58 | +done |
| 59 | + |
| 60 | +if [ "$retry" -eq "$MAX_RETRIES" ]; then |
| 61 | + log_fail "Bluetooth daemon not detected after ${MAX_RETRIES} attempts." |
| 62 | + echo "$TESTNAME FAIL" > "$res_file" |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +log_info "Powering off Bluetooth controller..." |
| 67 | +poweroff_output=$(bluetoothctl power off 2>&1) |
| 68 | +if echo "$poweroff_output" | grep -q "Changing power off succeeded"; then |
| 69 | + log_pass "Bluetooth powered off successfully" |
| 70 | +else |
| 71 | + log_warn "Power off result: $poweroff_output" |
| 72 | + log_fail "Bluetooth power off failed" |
| 73 | + echo "$TESTNAME FAIL" > "$res_file" |
| 74 | + exit 1 |
| 75 | +fi |
| 76 | + |
| 77 | +log_info "Powering on Bluetooth controller..." |
| 78 | +poweron_output=$(bluetoothctl power on 2>&1) |
| 79 | +if echo "$poweron_output" | grep -q "Changing power on succeeded"; then |
| 80 | + log_pass "Bluetooth powered on successfully" |
| 81 | + echo "$TESTNAME PASS" > "$res_file" |
| 82 | + exit 0 |
| 83 | +else |
| 84 | + log_warn "Power on result: $poweron_output" |
| 85 | + log_fail "Bluetooth power on failed" |
| 86 | + echo "$TESTNAME FAIL" > "$res_file" |
| 87 | + exit 1 |
| 88 | +fi |
| 89 | + |
0 commit comments