Skip to content

Commit d35285c

Browse files
committed
Adding Bluetooth validation test case
This test validates the Bluetooth controller by checking for the presence of bluetoothctl, ensuring bluetoothd is running, and toggling the controller power state using bluetoothctl. - Compliant with qcom-linux-testkit structure - Generates .res file for CI/CD - Uses functestlib logging and dependency checks Signed-off-by: Anil Yadav <[email protected]>
1 parent 11665e9 commit d35285c

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2+
SPDX-License-Identifier: BSD-3-Clause-Clear
3+
4+
# Bluetooth Validation Test
5+
6+
## Overview
7+
8+
This test case validates the basic functionality of the Bluetooth controller on the device. It checks for:
9+
10+
- Presence of `bluetoothctl`
11+
- Running status of `bluetoothd`
12+
- Power state toggling of the Bluetooth controller
13+
14+
## Usage
15+
16+
Instructions:
17+
18+
1. Copy repo to Target Device: Use scp to transfer the scripts from the host to the target device. The scripts should be copied to any directory on the target device.
19+
2. Verify Transfer: Ensure that the repo have been successfully copied to any directory on the target device.
20+
3. Run Scripts: Navigate to the directory where these files are copied on the target device and execute the scripts as needed.
21+
22+
Run a Connectivity Bluetooth test using:
23+
---
24+
#### Quick Example
25+
```
26+
git clone <this-repo>
27+
cd <this-repo>
28+
scp -r common Runner user@target_device_ip:<Path in device>
29+
ssh user@target_device_ip
30+
cd <Path in device>/Runner && ./run-test.sh Bluetooth
31+
```
32+
33+
## Prerequisites
34+
- bluez package must be installed (provides bluetoothctl)
35+
- bluetoothd daemon must be running
36+
- Root access may be required for complete validation
37+
38+
## Result Format
39+
40+
Test result will be saved in Bluetooth.res as:
41+
#### Pass Criteria
42+
- bluetoothctl is available
43+
- bluetoothd is running
44+
- Power on command returns success
45+
- Bluetooth controller powered on successfully. – if all validations pass
46+
<!-- -->
47+
#### Fail Criteria
48+
- bluetoothctl not found
49+
- bluetoothd not running
50+
- Power on command fails
51+
- Failed to power on Bluetooth controller. – if any check fails
52+
53+
54+
## Output
55+
A .res file is generated in the same directory:
56+
57+
`PASS Bluetooth` OR `FAIL Bluetooth`
58+
59+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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

Comments
 (0)