Skip to content

Commit ec1b384

Browse files
lylezhu2012kartben
authored andcommitted
tests: Bluetooth: BR: Add test suite sdp_client
IUT works as a SDP Client. The peer device, SDP server, is a PC with running `bumble` on it. Add shell command `discovery` to discover specific SDP record according to specific UUID. In the test suite, there are three groups test cases, Group 1 is for Service Search Attribute transaction. Group 2 is for Service Search transaction. Group 3 is for Service Attribute transaction. For each test group, there are four test cases, Case 1, No SDP record is registered on PC. IUT should not find any SDP record. Case 2, A2DP source SDP record is registered on PC. IUT can find SDP record. And the discovered PSM and version should be same with registered. Case 3, A2DP source and HFP HF SDP Records are registered. IUT can find SDP record. And the discovered RFCOMM channel and HFP version should be same with registered. This case is used to test the "continuation state information". Case 4, Multiple SDP Records are registered. This case is used to test the "continuation state information". And also it used to test the total length exceeds the ACL RX Buffer Size. Signed-off-by: Lyle Zhu <[email protected]>
1 parent bd254ee commit ec1b384

File tree

9 files changed

+1456
-0
lines changed

9 files changed

+1456
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
set(NO_QEMU_SERIAL_BT_SERVER 1)
5+
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7+
project(bluetooth)
8+
9+
FILE(GLOB app_sources src/*.c)
10+
target_sources(app PRIVATE ${app_sources})
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.. _bluetooth_classic_sdp_clinet_tests:
2+
3+
Bluetooth Classic SDP Client Tests
4+
##################################
5+
6+
Overview
7+
********
8+
9+
This test suite uses ``bumble`` for testing Bluetooth Classic communication between a host
10+
PC (running :ref:`Twister <twister_script>`) and a device under test (DUT) running Zephyr.
11+
12+
Prerequisites
13+
*************
14+
15+
The test suite has the following prerequisites:
16+
17+
* The ``bumble`` library installed on the host PC.
18+
The Bluetooth Classic controller on PC side is required. Refer to getting started of `bumble`_
19+
for details.
20+
21+
The HCI transport for ``bumble`` can be configured as follows:
22+
23+
* A specific configuration context can be provided along with the ``usb_hci`` fixture separated by
24+
a ``:`` (i.e. specify fixture ``usb_hci:usb:0`` to use the ``usb:0`` as hci transport for
25+
``bumble``).
26+
* The configuration context can be overridden using the `hci transport`_ can be provided using the
27+
``--hci-transport`` test suite argument (i.e. run ``twister`` with the
28+
``--pytest-args=--hci-transport=usb:0`` argument to use the ``usb:0`` as hci transport for
29+
``bumble``).
30+
31+
Building and Running
32+
********************
33+
34+
Running on mimxrt1170_evk@B/mimxrt1176/cm7
35+
==========================================
36+
37+
Running the test suite on :ref:`mimxrt1170_evk` relies on configuration of ``bumble``.
38+
39+
On the host PC, a HCI transport needs to be required. Refer to `bumble platforms`_ page of
40+
``bumble`` for details.
41+
42+
For example, on windows, a PTS dongle is used. After `WinUSB driver`_ has been installed,
43+
the HCI transport would be USB transport interface ``usb:<index>``.
44+
45+
If the HCI transport is ``usb:0`` and debug console port is ``COM4``, the test suite can be
46+
launched using Twister:
47+
48+
.. code-block:: shell
49+
50+
west twister -v -p mimxrt1170_evk@B/mimxrt1176/cm7 --device-testing --device-serial COM4 -T tests/bluetooth/classic/sdp_c -O sdp_c --force-platform --west-flash --west-runner=jlink -X usb_hci:usb:0
51+
52+
Running on Hardware
53+
===================
54+
55+
Running the test suite on hardware requires a HCI transport connected to the host PC.
56+
57+
The test suite can be launched using Twister. Below is an example for running on the
58+
:zephyr:board:`mimxrt1170_evk@B/mimxrt1176/cm7`:
59+
60+
.. code-block:: shell
61+
62+
west twister -v -p mimxrt1170_evk@B/mimxrt1176/cm7 --device-testing --device-serial COM4 -T tests/bluetooth/classic/sdp_c -O sdp_c --force-platform --west-flash --west-runner=jlink -X usb_hci:usb:0
63+
64+
.. _bumble:
65+
https://google.github.io/bumble/getting_started.html
66+
67+
.. _hci transport:
68+
https://google.github.io/bumble/transports/index.html
69+
70+
.. _bumble platforms:
71+
https://google.github.io/bumble/platforms/index.html
72+
73+
.. _WinUSB driver:
74+
https://google.github.io/bumble/platforms/windows.html
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#select NXP NW612 Chipset
2+
CONFIG_BT_NXP_NW612=y
3+
4+
CONFIG_BT_SETTINGS=n
5+
CONFIG_FLASH=n
6+
CONFIG_FLASH_MAP=n
7+
CONFIG_NVS=n
8+
CONFIG_SETTINGS=n
9+
10+
CONFIG_ENTROPY_GENERATOR=y
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,sram = &dtcm;
10+
};
11+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CONFIG_BT=y
2+
CONFIG_BT_CLASSIC=y
3+
CONFIG_BT_SHELL=y
4+
CONFIG_LOG=y
5+
CONFIG_ZTEST=y
6+
7+
CONFIG_BT_RFCOMM=y
8+
9+
CONFIG_BT_DEVICE_NAME="sdp_client"
10+
11+
CONFIG_BT_CREATE_CONN_TIMEOUT=30
12+
CONFIG_BT_PAGE_TIMEOUT=0xFFFF
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2024 NXP
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import logging
6+
import re
7+
8+
import pytest
9+
from twister_harness import DeviceAdapter, Shell
10+
11+
logger = logging.getLogger(__name__)
12+
13+
14+
def pytest_addoption(parser) -> None:
15+
"""Add local parser options to pytest."""
16+
parser.addoption('--hci-transport', default=None, help='Configuration HCI transport for bumble')
17+
18+
19+
@pytest.fixture(name='initialize', scope='session')
20+
def fixture_initialize(request, shell: Shell, dut: DeviceAdapter):
21+
"""Session initializtion"""
22+
# Get HCI transport for bumble
23+
hci = request.config.getoption('--hci-transport')
24+
25+
if hci is None:
26+
for fixture in dut.device_config.fixtures:
27+
if fixture.startswith('usb_hci:'):
28+
hci = fixture.split(sep=':', maxsplit=1)[1]
29+
break
30+
31+
assert hci is not None
32+
33+
lines = shell.exec_command("bt init")
34+
lines = dut.readlines_until("Bluetooth initialized")
35+
regex = r'Identity: *(?P<bd_addr>(.*?):(.*?):(.*?):(.*?):(.*?):(.*?)*\((.*?)\))'
36+
bd_addr = None
37+
for line in lines:
38+
logger.info(f"Shell log {line}")
39+
m = re.search(regex, line)
40+
if m:
41+
bd_addr = m.group('bd_addr')
42+
43+
if bd_addr is None:
44+
logger.error('Fail to get IUT BD address')
45+
raise AssertionError
46+
47+
lines = shell.exec_command("br pscan on")
48+
lines = shell.exec_command("br iscan on")
49+
logger.info('initialized')
50+
return hci, bd_addr
51+
52+
53+
@pytest.fixture
54+
def sdp_client_dut(initialize):
55+
logger.info('Start running testcase')
56+
yield initialize
57+
logger.info('Done')

0 commit comments

Comments
 (0)