Skip to content

Commit 161d8a2

Browse files
Thalleykartben
authored andcommitted
tests: Bluetooth: Tester: CSIP BSIM test
Adds BSIM testing of the CSIP features of the BT Tester. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 8753fef commit 161d8a2

File tree

6 files changed

+247
-0
lines changed

6 files changed

+247
-0
lines changed

tests/bsim/bluetooth/tester/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ zephyr_include_directories(
2424
target_sources(app PRIVATE
2525
src/bsim_btp.c
2626
src/test_main.c
27+
src/audio/csip_central.c
28+
src/audio/csip_peripheral.c
2729
src/audio/hap_central.c
2830
src/audio/hap_peripheral.c
2931
src/audio/micp_central.c
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <stddef.h>
7+
#include <stdint.h>
8+
9+
#include <zephyr/bluetooth/addr.h>
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/logging/log.h>
12+
#include <zephyr/net_buf.h>
13+
#include <zephyr/sys/util_macro.h>
14+
15+
#include "babblekit/testcase.h"
16+
#include "bstests.h"
17+
18+
#include "btp/btp.h"
19+
#include "bsim_btp.h"
20+
21+
LOG_MODULE_REGISTER(bsim_csip_central, CONFIG_BSIM_BTTESTER_LOG_LEVEL);
22+
23+
static void test_csip_central(void)
24+
{
25+
char addr_str[BT_ADDR_LE_STR_LEN];
26+
bt_addr_le_t remote_addr;
27+
28+
bsim_btp_uart_init();
29+
30+
bsim_btp_wait_for_evt(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, NULL);
31+
32+
bsim_btp_core_register(BTP_SERVICE_ID_GAP);
33+
bsim_btp_core_register(BTP_SERVICE_ID_CSIP);
34+
35+
bsim_btp_gap_start_discovery(BTP_GAP_DISCOVERY_FLAG_LE);
36+
bsim_btp_wait_for_gap_device_found(&remote_addr);
37+
bt_addr_le_to_str(&remote_addr, addr_str, sizeof(addr_str));
38+
LOG_INF("Found remote device %s", addr_str);
39+
40+
bsim_btp_gap_stop_discovery();
41+
bsim_btp_gap_connect(&remote_addr, BTP_GAP_ADDR_TYPE_IDENTITY);
42+
bsim_btp_wait_for_gap_device_connected(NULL);
43+
LOG_INF("Device %s connected", addr_str);
44+
45+
bsim_btp_gap_pair(&remote_addr);
46+
bsim_btp_wait_for_gap_sec_level_changed(NULL, NULL);
47+
48+
bsim_btp_csip_discover(&remote_addr);
49+
bsim_btp_wait_for_csip_discovered(NULL);
50+
51+
bsim_btp_csip_set_coordinator_lock();
52+
bsim_btp_wait_for_lock();
53+
54+
bsim_btp_gap_disconnect(&remote_addr);
55+
bsim_btp_wait_for_gap_device_disconnected(NULL);
56+
LOG_INF("Device %s disconnected", addr_str);
57+
58+
TEST_PASS("PASSED\n");
59+
}
60+
61+
static const struct bst_test_instance test_sample[] = {
62+
{
63+
.test_id = "csip_central",
64+
.test_descr = "Smoketest for the CSIP central BT Tester behavior",
65+
.test_main_f = test_csip_central,
66+
},
67+
BSTEST_END_MARKER,
68+
};
69+
70+
struct bst_test_list *test_csip_central_install(struct bst_test_list *tests)
71+
{
72+
return bst_add_tests(tests, test_sample);
73+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <stddef.h>
7+
#include <stdint.h>
8+
9+
#include <zephyr/bluetooth/addr.h>
10+
#include <zephyr/bluetooth/gap.h>
11+
#include <zephyr/bluetooth/hci_types.h>
12+
#include <zephyr/logging/log.h>
13+
#include <zephyr/sys/util_macro.h>
14+
15+
#include "babblekit/testcase.h"
16+
#include "bstests.h"
17+
18+
#include "btp/btp.h"
19+
#include "bsim_btp.h"
20+
21+
LOG_MODULE_REGISTER(bsim_csip_peripheral, CONFIG_BSIM_BTTESTER_LOG_LEVEL);
22+
23+
static void test_csip_peripheral(void)
24+
{
25+
char addr_str[BT_ADDR_LE_STR_LEN];
26+
bt_addr_le_t remote_addr;
27+
28+
bsim_btp_uart_init();
29+
30+
bsim_btp_wait_for_evt(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, NULL);
31+
32+
bsim_btp_core_register(BTP_SERVICE_ID_GAP);
33+
bsim_btp_core_register(BTP_SERVICE_ID_CSIP);
34+
bsim_btp_core_register(BTP_SERVICE_ID_CSIS);
35+
36+
bsim_btp_gap_set_discoverable(BTP_GAP_GENERAL_DISCOVERABLE);
37+
bsim_btp_gap_start_advertising(0U, 0U, NULL, BT_HCI_OWN_ADDR_PUBLIC);
38+
bsim_btp_wait_for_gap_device_connected(&remote_addr);
39+
bt_addr_le_to_str(&remote_addr, addr_str, sizeof(addr_str));
40+
LOG_INF("Device %s connected", addr_str);
41+
bsim_btp_wait_for_gap_device_disconnected(NULL);
42+
LOG_INF("Device %s disconnected", addr_str);
43+
44+
TEST_PASS("PASSED\n");
45+
}
46+
47+
static const struct bst_test_instance test_sample[] = {
48+
{
49+
.test_id = "csip_peripheral",
50+
.test_descr = "Smoketest for the CSIP peripheral BT Tester behavior",
51+
.test_main_f = test_csip_peripheral,
52+
},
53+
BSTEST_END_MARKER,
54+
};
55+
56+
struct bst_test_list *test_csip_peripheral_install(struct bst_test_list *tests)
57+
{
58+
return bst_add_tests(tests, test_sample);
59+
}

tests/bsim/bluetooth/tester/src/bsim_btp.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,74 @@ static inline void bsim_btp_core_register(uint8_t id)
4141
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len);
4242
}
4343

44+
static inline void bsim_btp_csip_discover(const bt_addr_le_t *address)
45+
{
46+
struct btp_csip_discover_cmd *cmd;
47+
struct btp_hdr *cmd_hdr;
48+
49+
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU);
50+
51+
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr));
52+
cmd_hdr->service = BTP_SERVICE_ID_CSIP;
53+
cmd_hdr->opcode = BTP_CSIP_DISCOVER;
54+
cmd_hdr->index = BTP_INDEX;
55+
cmd = net_buf_simple_add(&cmd_buffer, sizeof(*cmd));
56+
bt_addr_le_copy(&cmd->address, address);
57+
58+
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr);
59+
60+
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len);
61+
}
62+
63+
static inline void bsim_btp_csip_set_coordinator_lock(void)
64+
{
65+
struct btp_csip_set_coordinator_lock_cmd *cmd;
66+
struct btp_hdr *cmd_hdr;
67+
68+
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU);
69+
70+
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr));
71+
cmd_hdr->service = BTP_SERVICE_ID_CSIP;
72+
cmd_hdr->opcode = BTP_CSIP_SET_COORDINATOR_LOCK;
73+
cmd_hdr->index = BTP_INDEX;
74+
cmd = net_buf_simple_add(&cmd_buffer, sizeof(*cmd));
75+
cmd->addr_cnt = 0U; /* Zephyr BT Tester only supports this value being 0 */
76+
77+
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr);
78+
79+
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len);
80+
}
81+
82+
static inline void bsim_btp_wait_for_csip_discovered(bt_addr_le_t *address)
83+
{
84+
struct btp_csip_discovered_ev *ev;
85+
struct net_buf *buf;
86+
87+
bsim_btp_wait_for_evt(BTP_SERVICE_ID_CSIP, BTP_CSIP_DISCOVERED_EV, &buf);
88+
ev = net_buf_pull_mem(buf, sizeof(*ev));
89+
90+
TEST_ASSERT(ev->status == BT_ATT_ERR_SUCCESS);
91+
92+
if (address != NULL) {
93+
bt_addr_le_copy(address, &ev->address);
94+
}
95+
96+
net_buf_unref(buf);
97+
}
98+
99+
static inline void bsim_btp_wait_for_lock(void)
100+
{
101+
struct btp_csip_lock_ev *ev;
102+
struct net_buf *buf;
103+
104+
bsim_btp_wait_for_evt(BTP_SERVICE_ID_CSIP, BTP_CSIP_LOCK_EV, &buf);
105+
ev = net_buf_pull_mem(buf, sizeof(*ev));
106+
107+
TEST_ASSERT(ev->status == BT_ATT_ERR_SUCCESS);
108+
109+
net_buf_unref(buf);
110+
}
111+
44112
static inline void bsim_btp_gap_set_discoverable(uint8_t discoverable)
45113
{
46114
struct btp_gap_set_discoverable_cmd *cmd;

tests/bsim/bluetooth/tester/src/test_main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "bstests.h"
99

10+
extern struct bst_test_list *test_csip_central_install(struct bst_test_list *tests);
11+
extern struct bst_test_list *test_csip_peripheral_install(struct bst_test_list *tests);
1012
extern struct bst_test_list *test_gap_central_install(struct bst_test_list *tests);
1113
extern struct bst_test_list *test_gap_peripheral_install(struct bst_test_list *tests);
1214
extern struct bst_test_list *test_hap_central_install(struct bst_test_list *tests);
@@ -17,6 +19,8 @@ extern struct bst_test_list *test_vcp_central_install(struct bst_test_list *test
1719
extern struct bst_test_list *test_vcp_peripheral_install(struct bst_test_list *tests);
1820

1921
bst_test_install_t test_installers[] = {
22+
test_csip_central_install,
23+
test_csip_peripheral_install,
2024
test_gap_central_install,
2125
test_gap_peripheral_install,
2226
test_hap_central_install,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Nordic Semiconductor ASA
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Smoketest for CSIP BTP commands with the BT tester
6+
7+
simulation_id="tester_csip"
8+
verbosity_level=2
9+
EXECUTE_TIMEOUT=100
10+
11+
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
12+
13+
cd ${BSIM_OUT_PATH}/bin
14+
15+
UART_DIR=/tmp/bs_${USER}/${simulation_id}/
16+
UART_PER=${UART_DIR}/peripheral
17+
UART_CEN=${UART_DIR}/central
18+
19+
# Central BT Tester
20+
Execute ./bs_${BOARD_TS}_tests_bluetooth_tester_le_audio_prj_conf \
21+
-v=${verbosity_level} -s=${simulation_id} -rs=10 -d=0 -RealEncryption=1 \
22+
-uart0_fifob_rxfile=${UART_CEN}.tx -uart0_fifob_txfile=${UART_CEN}.rx
23+
24+
# Central Upper Tester
25+
Execute ./bs_nrf52_bsim_native_tests_bsim_bluetooth_tester_prj_conf \
26+
-v=${verbosity_level} -s=${simulation_id} -rs=21 -d=10 -RealEncryption=1 -testid=csip_central \
27+
-nosim -uart0_fifob_rxfile=${UART_CEN}.rx -uart0_fifob_txfile=${UART_CEN}.tx
28+
29+
# Peripheral BT Tester
30+
Execute ./bs_${BOARD_TS}_tests_bluetooth_tester_le_audio_prj_conf \
31+
-v=${verbosity_level} -s=${simulation_id} -rs=32 -d=1 -RealEncryption=1 \
32+
-uart0_fifob_rxfile=${UART_PER}.tx -uart0_fifob_txfile=${UART_PER}.rx
33+
34+
# Peripheral Upper Tester
35+
Execute ./bs_nrf52_bsim_native_tests_bsim_bluetooth_tester_prj_conf \
36+
-v=${verbosity_level} -s=${simulation_id} -rs=43 -d=11 -RealEncryption=1 -testid=csip_peripheral \
37+
-nosim -uart0_fifob_rxfile=${UART_PER}.rx -uart0_fifob_txfile=${UART_PER}.tx
38+
39+
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} -D=2 -sim_length=20e6 $@
40+
41+
wait_for_background_jobs # Wait for all programs in background and return != 0 if any fails

0 commit comments

Comments
 (0)