Skip to content

Commit c5e8533

Browse files
committed
tests: Bluetooth: BR: Add GAP Server role test suite
IUT works as a GAP Server (Peripheral) in the Bluetooth system. The peer device, GAP Client, is a PC running Bumble as a test tool. This test suite implements the following test cases: Case 1, Non-connectable Mode Testing. Verifies DUT can operate in non-connectable mode without allowing connections. Case 2, Connectable Non-discoverable Mode with Active Disconnection. Verifies DUT can accept connections and initiate disconnection. Case 3, Connectable Non-discoverable Mode with Passive Disconnection. Verifies DUT can accept connections and handle passive disconnection. Case 4, Connectable Non-discoverable Mode with Connection Rejection. Verifies DUT can reject connection requests. Case 5, Limited Discoverable Mode with Active Disconnection. Verifies DUT in limited discoverable mode can be discovered, accept connections and initiate disconnection. Case 6, Limited Discoverable Mode with Passive Disconnection. Verifies DUT can be discovered, accept connections and handle passive disconnection. Case 7, Limited Discoverable Mode with Connection Rejection. Verifies DUT can be discovered but reject connection requests. Case 8, General Discoverable Mode with Active Disconnection. Verifies DUT in general discoverable mode can be discovered, accept connections and initiate disconnection. Case 9, General Discoverable Mode with Passive Disconnection. Verifies DUT can be discovered, accept connections and handle passive disconnection. Case 10, General Discoverable Mode with Connection Rejection. Verifies DUT can be discovered but reject connection requests. Signed-off-by: Jiawei Yang <[email protected]>
1 parent e41909a commit c5e8533

File tree

9 files changed

+1001
-0
lines changed

9 files changed

+1001
-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_gap_server_tests:
2+
3+
Bluetooth Classic gap server 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/gap_s -O gap_s --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/gap_s -O gap_s --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="gap_s"
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>(.*?):(.*?):(.*?):(.*?):(.*?):(.*?) *\((.*?)\))'
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)