Skip to content

Commit a9fe7d5

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 3cadc86 commit a9fe7d5

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-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: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 "FAIL $TESTNAME" > "./$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+
43+
log_info "Checking if dependency: bluez is available"
44+
check_dependencies bluez
45+
46+
log_info "Starting Bluetooth Test..."
47+
48+
# Check if bluetoothctl is available
49+
if ! command -v bluetoothctl >/dev/null 2>&1; then
50+
log_fail "bluetoothctl not found. Please install bluez."
51+
echo "FAIL $TESTNAME" > "$res_file"
52+
exit 1
53+
fi
54+
55+
# Check if bluetoothd is running
56+
MAX_RETRIES=3
57+
RETRY_DELAY=10 # seconds
58+
retry=0
59+
60+
while [ "$retry" -lt "$MAX_RETRIES" ]; do
61+
if pgrep bluetoothd >/dev/null; then
62+
break
63+
fi
64+
log_info "Bluetooth daemon not found, retrying in ${RETRY_DELAY} seconds..."
65+
sleep "$RETRY_DELAY"
66+
retry=$((retry + 1))
67+
done
68+
69+
if [ "$retry" -eq "$MAX_RETRIES" ]; then
70+
log_fail "Failed to start bluetoothd after ${MAX_RETRIES} retries. Aborting test."
71+
echo "FAIL $TESTNAME" > "$res_file"
72+
exit 1
73+
else
74+
log_info "Bluetooth daemon started successfully."
75+
fi
76+
77+
# Power off Bluetooth controller
78+
log_info "Powering off Bluetooth controller..."
79+
bluetoothctl power off
80+
81+
# Power on Bluetooth controller
82+
log_info "Powering on Bluetooth controller..."
83+
output=$(bluetoothctl power on)
84+
85+
# Check for success message
86+
if echo "$output" | grep -q "Changing power on succeeded"; then
87+
log_pass "Bluetooth controller powered on successfully."
88+
echo "PASS $TESTNAME" > "$res_file"
89+
else
90+
log_fail "Failed to power on Bluetooth controller."
91+
echo "FAIL $TESTNAME" > "$res_file"
92+
fi
93+
94+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
95+
96+

0 commit comments

Comments
 (0)