Skip to content

Add BabbleSim tests for VS write BD addr functionality#24

Draft
cvinayak with Copilot wants to merge 6 commits into
mainfrom
copilot/add-babble-sim-tests-vs-bd-addr
Draft

Add BabbleSim tests for VS write BD addr functionality#24
cvinayak with Copilot wants to merge 6 commits into
mainfrom
copilot/add-babble-sim-tests-vs-bd-addr

Conversation

Copilot AI commented Feb 10, 2026

Copy link
Copy Markdown

Adds test coverage for setting public address via HCI Vendor-Specific bt_hci_cp_vs_write_bd_addr command during bt_enable(), introduced in zephyrproject-rtos#103753.

Changes

Test Scenario 1: Central with public address

  • test_central_connect_vs_set_public_addr in main.c - Creates public identity with bt_id_create() before bt_enable() to trigger VS write BD addr path, then connects to peripheral with random address
  • tests_scripts/run_central_vs_set_public_addr.sh - BabbleSim test runner

Test Scenario 2: Peripheral with public address

  • test_peripheral_vs_set_public_addr in dummy_peripheral.c - Peripheral creates public identity with bt_id_create() before bt_enable() to trigger VS write BD addr path, then advertises
  • test_central_connect_to_peripheral_public_addr in main.c - Central connects to the peripheral with public address
  • tests_scripts/run_central_connect_to_peripheral_public_addr.sh - BabbleSim test runner

Test infrastructure:

  • Enabled CONFIG_BT_HCI_VS=y in prj.conf

Test flow

Scenario 1 - Central with public address:

/* Central creates public address identity before bt_enable() */
bt_addr_le_t addr = {.type = BT_ADDR_LE_PUBLIC,
                     .a.val = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}};

err = bt_id_create(&addr, NULL);
/* bt_enable() triggers hci_vs_write_bd_addr() internally */
err = bt_enable(NULL);

/* Verify by connecting to peripheral with random address */
err = bt_conn_le_create(&peer, &create_param, ...);

Scenario 2 - Peripheral with public address:

/* Peripheral creates public address identity before bt_enable() */
bt_addr_le_t addr = {.type = BT_ADDR_LE_PUBLIC,
                     .a.val = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}};

err = bt_id_create(&addr, NULL);
/* bt_enable() triggers hci_vs_write_bd_addr() internally */
err = bt_enable(NULL);

/* Central connects to this peripheral */
err = bt_conn_le_create(&peer, &create_param, ...);

Tests registered in test_def[] arrays, following existing BabbleSim test patterns.

Original prompt

Context

PR zephyrproject-rtos#103753 adds support for using the HCI Vendor-Specific command bt_hci_cp_vs_write_bd_addr to set the public address during bt_enable(). This replaces the previous approach of using bt_hci_driver_api::setup which didn't work well in split builds.

The key changes in that PR are:

  1. New macro BT_VS_CMD_WRITE_BD_ADDR(cmd) in include/zephyr/bluetooth/hci_vs.h
  2. New function hci_vs_write_bd_addr() in subsys/bluetooth/host/hci_core.c that sends the VS command
  3. In hci_init(), after hci_vs_init(), if there's a pre-configured public address and the VS write BD addr command is supported, it sends the address via the VS command
  4. bt_id_create() in subsys/bluetooth/host/id.c now allows public addresses when CONFIG_BT_HCI_VS is enabled (not just CONFIG_BT_HCI_SET_PUBLIC_ADDR)

Task

Add new BabbleSIM tests to tests/bsim/bluetooth/host/central/ to verify the VS write BD addr functionality. Take inspiration from the existing run_central_connect_to_existing.sh test and the test infrastructure already in place.

Existing test structure to follow

The test lives in tests/bsim/bluetooth/host/central/ with:

  • src/main.c - Contains test functions and test installer
  • src/dummy_peripheral.c - Contains a simple connectable peripheral
  • tests_scripts/run_central_connect_to_existing.sh - Shell script that runs central + peripheral + PHY simulator
  • prj.conf - Project configuration
  • CMakeLists.txt - Build configuration
  • testcase.yaml - Test case metadata

What to add

  1. New test function in tests/bsim/bluetooth/host/central/src/main.c:

    • Add a new test test_central_connect_vs_set_public_addr that:
      • Creates a public address identity using bt_id_create() with BT_ADDR_LE_PUBLIC type BEFORE calling bt_enable(). Use an address like {.type = BT_ADDR_LE_PUBLIC, .a.val = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}}
      • Calls bt_enable(NULL) - this should trigger the VS write BD addr path internally
      • Connects to the dummy peripheral (similar to test_central_connect_to_existing)
      • Verifies successful connection
      • Passes the test
    • Register the new test in the test_def[] array with test_id = "central_vs_set_public_addr"
  2. New test script tests/bsim/bluetooth/host/central/tests_scripts/run_central_vs_set_public_addr.sh:

    • Follow the exact same pattern as run_central_connect_to_existing.sh:
    #!/usr/bin/env bash
    # Copyright (c) 2026 Nordic Semiconductor
    # SPDX-License-Identifier: Apache-2.0
    
    source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
    
    simulation_id="central_vs_set_public_addr"
    verbosity_level=2
    
    cd ${BSIM_OUT_PATH}/bin
    
    Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_central_prj_conf \
      -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central_vs_set_public_addr
    
    Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_central_prj_conf \
      -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral_dummy
    
    Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \
      -D=2 -sim_length=60e6 $@
    
    wait_for_background_jobs

Reference: Existing run_central_connect_to_existing.sh

#!/usr/bin/env bash
# Copyright (c) 2024 Nordic Semiconductor
# SPDX-License-Identifier: Apache-2.0

source ${ZEPHYR_BASE}/tests/bsim/sh_common.source

simulation_id="central_connect_timeout_to_existing"
verbosity_level=2

cd ${BSIM_OUT_PATH}/bin

Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_central_prj_conf \
  -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central_connect_to_existing

Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_central_prj_conf \
  -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral_dummy

Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \
  -D=2 -sim_length=60e6 $@

wait_for_background_jobs

Reference: Existing src/main.c (relevant parts)

#include "bstests.h"
#include "babblekit/testcase.h"
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h>
#include "common/hci_common_internal.h"
#include "host/conn_internal.h"

struct bst_test_list *test_peripheral_install(struct bst_test_list *tests);

static K_SEM_DEFINE(sem_failed_to_connect, 0, 1);
static K_SEM_DEFINE(sem_connected, 0, 1);

static void connected_cb(struct bt_conn *conn, uint8_t err)
{
	TEST_ASSERT(conn);
	TEST_ASSERT(err == BT_HCI_ERR_SUCCESS, "Expected connection establishment");
	k_sem_give(&sem_connected);
	bt_conn_unref(conn);
}

static struct bt_conn_cb conn_cb = {
	.connected = connected_cb,
};

// ... existing test functions ...

static void test_central_connect_to_existing(void)
{
	int err;
	bt_conn_cb_register(&conn_cb);
	err = bt_enable(NULL);
	TEST_ASSERT(err == 0, "Can't enable Bluetooth (err %d)", err);

	struct bt_conn *conn;
	bt_addr_le_t peer = {.type = BT_ADDR_LE_RANDOM,
			     .a.val = {0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI changed the title [WIP] Add BabbleSIM tests for VS write BD addr functionality Add BabbleSim tests for VS write BD addr functionality Feb 10, 2026
Copilot AI requested a review from cvinayak February 10, 2026 09:22
@cvinayak

Copy link
Copy Markdown
Owner

@copilot add a new test in dummy_peripheral.c file too where in public address is used by peripheral and central connects to it.

Copilot AI commented Feb 10, 2026

Copy link
Copy Markdown
Author

@copilot add a new test in dummy_peripheral.c file too where in public address is used by peripheral and central connects to it.

Added new tests:

  1. test_peripheral_vs_set_public_addr in dummy_peripheral.c - Peripheral uses public address via VS write BD addr
  2. test_central_connect_to_peripheral_public_addr in main.c - Central connects to peripheral with public address
  3. New test script run_central_connect_to_peripheral_public_addr.sh to run both tests together

The peripheral creates a public address {0x11, 0x22, 0x33, 0x44, 0x55, 0x66} before bt_enable() and the central successfully connects to it.

Committed in 81db14a and 3288bbc.

hermabe and others added 6 commits February 10, 2026 13:07
The current way of setting the public address using
`bt_hci_driver_api::setup` does not work well in split builds
where host and controller runs on different cores/socs/boards.
This approach requires each HCI driver and each `hci_<transport>`
application to implement the setup and pass the information on
to the next layer.

Zephyr already defines a vendor-specific command that can be used
to set the public address (`bt_hci_cp_vs_write_bd_addr`).
Use this in `bt_enable` after opening the HCI transport and before
initializing the id module. This makes the setup independent of
hci transport and only depends on a controller that implements the
Zephyr HCI VS commands.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
Co-authored-by: cvinayak <6350656+cvinayak@users.noreply.github.com>
Co-authored-by: cvinayak <6350656+cvinayak@users.noreply.github.com>
Co-authored-by: cvinayak <6350656+cvinayak@users.noreply.github.com>
Added compile script, Kconfig, Kconfig.sysbuild and sysbuild.cmake
for testing on nrf5340bsim/nrf5340/cpuapp.
@cvinayak cvinayak force-pushed the copilot/add-babble-sim-tests-vs-bd-addr branch from 3288bbc to e298ddf Compare February 10, 2026 12:07
@cvinayak

Copy link
Copy Markdown
Owner

@copilot i have now updated the pull request (force pushed). I added scripts et al to be able to test on nrf5340bsim/nrf5340/cpuapp

Copilot AI commented Feb 10, 2026

Copy link
Copy Markdown
Author

@copilot i have now updated the pull request (force pushed). I added scripts et al to be able to test on nrf5340bsim/nrf5340/cpuapp

Acknowledged. I can see the new files added in e298ddf:

  • Kconfig - Kernel configuration
  • Kconfig.sysbuild - Sysbuild configuration for nrf5340bsim
  • compile.sh - Compilation script
  • sysbuild.cmake - Sysbuild CMake configuration for HCI IPC network core

The test infrastructure I added (test functions and scripts) is still intact and will now work with nrf5340bsim/nrf5340/cpuapp builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants