Skip to content

Commit d56f1e0

Browse files
CanWang001danieldegrasse
authored andcommitted
tests: Bluetooth: BR: Add test suite of bonding for SMP
IUT works as an SM Initiator/Responder. The peer device, SM Responder/Initiator, is a PC running bumble on it. Add shell commands to create and manage L2CAP server and channel with different security level. In the test suite, there are 5 test cases. The test matrix combines each bonding flag: | Test Case ID | Initiator | Responder | Expected Result | |--------------|-----------|-----------|-----------------| | BR_SM_Bonding_INIT_001 | Non-bondable | Non-bondable | Pass | | BR_SM_Bonding_INIT_005 | General Bonding | General Bonding | Pass | | BR_SM_Bonding_RSP_010 | Non-bondable | Non-bondable | Pass | | BR_SM_Bonding_RSP_011 | General Bonding | Non-bondable | Fail | | BR_SM_Bonding_RSP_014 | General Bonding | General Bonding | Pass | Signed-off-by: Can Wang <can.wang@nxp.com>
1 parent 9937be7 commit d56f1e0

File tree

9 files changed

+965
-0
lines changed

9 files changed

+965
-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_smp_bonding_tests:
2+
3+
Bluetooth Classic SMP Bonding 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/smp_bonding -O smp_bonding --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/smp_bonding -O smp_bonding --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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#select NXP NW612 Chipset
2+
CONFIG_BT_NXP_NW612=y
3+
4+
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 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,sram = &dtcm;
10+
};
11+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CONFIG_BT=y
2+
CONFIG_BT_CLASSIC=y
3+
CONFIG_BT_SMP=y
4+
CONFIG_BT_SHELL=y
5+
CONFIG_LOG=y
6+
CONFIG_ZTEST=y
7+
CONFIG_BT_SETTINGS=y
8+
CONFIG_FLASH=y
9+
CONFIG_FLASH_MAP=y
10+
CONFIG_NVS=y
11+
CONFIG_SETTINGS=y
12+
13+
CONFIG_BT_DEVICE_NAME="smp_bonding"
14+
15+
CONFIG_BT_CREATE_CONN_TIMEOUT=30
16+
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 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+
shell.exec_command("bt init")
34+
lines = dut.readlines_until("Settings Loaded")
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+
shell.exec_command("br pscan on")
48+
shell.exec_command("br iscan on")
49+
logger.info('initialized')
50+
return hci, bd_addr
51+
52+
53+
@pytest.fixture
54+
def smp_initiator_dut(initialize):
55+
logger.info('Start running testcase')
56+
yield initialize
57+
logger.info('Done')

0 commit comments

Comments
 (0)