Skip to content

Commit 0b23a47

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 05db8dd commit 0b23a47

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

0 commit comments

Comments
 (0)