Skip to content

Commit c89441a

Browse files
jerryyang35fabiobaltieri
authored andcommitted
tests: Bluetooth: BR: Add test suite RFCOMM_client
IUT works as an RFCOMM Client. The peer device, RFCOMM server, is a PC running bumble. In the test suite, there are five test cases: Case 1, RFCOMM Client with Command Responses. Tests that the client can establish a DLC, respond to various commands (RLS, RPN, Test), send NSC responses, and properly handle DLC disconnection and RFCOMM session shutdown. Case 2, RFCOMM Client with Credit Based Flow Control. Tests that the client can establish a DLC, perform information transfer with credit based flow control, initiate disconnection, and shutdown the RFCOMM session. Case 3, RFCOMM Client with BR Connection Disconnection. Tests that the client correctly handles scenarios where the BR connection is disconnected during DLC establishment. Case 4, RFCOMM Client with Aggregate Flow Control. Tests that the client can establish a DLC, perform information transfer with aggregate flow control, and properly handle disconnection and session shutdown. Case 5, RFCOMM Client with Failed PN Response. Tests that the client correctly handles scenarios where it fails to receive a PN response when establishing a DLC. Signed-off-by: Jiawei Yang <jiawei.yang_1@nxp.com>
1 parent b63b993 commit c89441a

File tree

10 files changed

+1633
-0
lines changed

10 files changed

+1633
-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_rfcomm_client_tests:
2+
3+
Bluetooth Classic rfcomm 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/rfcomm_c -O rfcomm_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/rfcomm_c -O rfcomm_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="rfcomm_c"
10+
11+
CONFIG_BT_CREATE_CONN_TIMEOUT=30
12+
CONFIG_BT_PAGE_TIMEOUT=0xFFFF
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2025 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>([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}) *\((.*?)\))'
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+
logger.info('initialized')
48+
return hci, bd_addr
49+
50+
51+
@pytest.fixture
52+
def device_under_test(initialize):
53+
logger.info('Start running testcase')
54+
yield initialize
55+
logger.info('Done')

0 commit comments

Comments
 (0)