Skip to content

Commit b7b6d39

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

File tree

6 files changed

+231
-0
lines changed

6 files changed

+231
-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/hap_central.c
28+
src/audio/hap_peripheral.c
2729
src/audio/micp_central.c
2830
src/audio/micp_peripheral.c
2931
src/audio/vcp_central.c
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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_hap_central, CONFIG_BSIM_BTTESTER_LOG_LEVEL);
22+
23+
static void test_hap_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_HAP);
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_hauc_init();
49+
bsim_btp_hauc_discover(&remote_addr);
50+
bsim_btp_wait_for_hauc_discovery_complete(NULL);
51+
52+
bsim_btp_gap_disconnect(&remote_addr);
53+
bsim_btp_wait_for_gap_device_disconnected(NULL);
54+
LOG_INF("Device %s disconnected", addr_str);
55+
56+
TEST_PASS("PASSED\n");
57+
}
58+
59+
static const struct bst_test_instance test_sample[] = {
60+
{
61+
.test_id = "hap_central",
62+
.test_descr = "Smoketest for the HAP central BT Tester behavior",
63+
.test_main_f = test_hap_central,
64+
},
65+
BSTEST_END_MARKER,
66+
};
67+
68+
struct bst_test_list *test_hap_central_install(struct bst_test_list *tests)
69+
{
70+
return bst_add_tests(tests, test_sample);
71+
}
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/audio/has.h>
11+
#include <zephyr/bluetooth/gap.h>
12+
#include <zephyr/bluetooth/hci_types.h>
13+
#include <zephyr/logging/log.h>
14+
#include <zephyr/sys/util_macro.h>
15+
16+
#include "babblekit/testcase.h"
17+
#include "bstests.h"
18+
19+
#include "btp/btp.h"
20+
#include "bsim_btp.h"
21+
22+
LOG_MODULE_REGISTER(bsim_hap_peripheral, CONFIG_BSIM_BTTESTER_LOG_LEVEL);
23+
24+
static void test_hap_peripheral(void)
25+
{
26+
char addr_str[BT_ADDR_LE_STR_LEN];
27+
bt_addr_le_t remote_addr;
28+
29+
bsim_btp_uart_init();
30+
31+
bsim_btp_wait_for_evt(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, NULL);
32+
33+
bsim_btp_core_register(BTP_SERVICE_ID_GAP);
34+
bsim_btp_core_register(BTP_SERVICE_ID_HAS);
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 = "hap_peripheral",
50+
.test_descr = "Smoketest for the HAP peripheral BT Tester behavior",
51+
.test_main_f = test_hap_peripheral,
52+
},
53+
BSTEST_END_MARKER,
54+
};
55+
56+
struct bst_test_list *test_hap_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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,60 @@ static inline void bsim_btp_wait_for_gap_sec_level_changed(bt_addr_le_t *address
244244
net_buf_unref(buf);
245245
}
246246

247+
static inline void bsim_btp_hauc_init(void)
248+
{
249+
struct btp_hdr *cmd_hdr;
250+
251+
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU);
252+
253+
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr));
254+
cmd_hdr->service = BTP_SERVICE_ID_HAP;
255+
cmd_hdr->opcode = BTP_HAP_HAUC_INIT;
256+
cmd_hdr->index = BTP_INDEX;
257+
258+
/* command is empty */
259+
260+
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr);
261+
262+
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len);
263+
}
264+
265+
static inline void bsim_btp_hauc_discover(const bt_addr_le_t *address)
266+
{
267+
struct btp_hap_hauc_discover_cmd *cmd;
268+
struct btp_hdr *cmd_hdr;
269+
270+
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU);
271+
272+
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr));
273+
cmd_hdr->service = BTP_SERVICE_ID_HAP;
274+
cmd_hdr->opcode = BTP_HAP_HAUC_DISCOVER;
275+
cmd_hdr->index = BTP_INDEX;
276+
cmd = net_buf_simple_add(&cmd_buffer, sizeof(*cmd));
277+
bt_addr_le_copy(&cmd->address, address);
278+
279+
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr);
280+
281+
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len);
282+
}
283+
284+
static inline void bsim_btp_wait_for_hauc_discovery_complete(bt_addr_le_t *address)
285+
{
286+
struct btp_hap_hauc_discovery_complete_ev *ev;
287+
struct net_buf *buf;
288+
289+
bsim_btp_wait_for_evt(BTP_SERVICE_ID_HAP, BT_HAP_EV_HAUC_DISCOVERY_COMPLETE, &buf);
290+
ev = net_buf_pull_mem(buf, sizeof(*ev));
291+
292+
TEST_ASSERT(ev->status == BT_ATT_ERR_SUCCESS);
293+
294+
if (address != NULL) {
295+
bt_addr_le_copy(address, &ev->address);
296+
}
297+
298+
net_buf_unref(buf);
299+
}
300+
247301
static inline void bsim_btp_vcp_discover(const bt_addr_le_t *address)
248302
{
249303
struct btp_vcp_discover_cmd *cmd;

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

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

1010
extern struct bst_test_list *test_gap_central_install(struct bst_test_list *tests);
1111
extern struct bst_test_list *test_gap_peripheral_install(struct bst_test_list *tests);
12+
extern struct bst_test_list *test_hap_central_install(struct bst_test_list *tests);
13+
extern struct bst_test_list *test_hap_peripheral_install(struct bst_test_list *tests);
1214
extern struct bst_test_list *test_micp_central_install(struct bst_test_list *tests);
1315
extern struct bst_test_list *test_micp_peripheral_install(struct bst_test_list *tests);
1416
extern struct bst_test_list *test_vcp_central_install(struct bst_test_list *tests);
@@ -17,6 +19,8 @@ extern struct bst_test_list *test_vcp_peripheral_install(struct bst_test_list *t
1719
bst_test_install_t test_installers[] = {
1820
test_gap_central_install,
1921
test_gap_peripheral_install,
22+
test_hap_central_install,
23+
test_hap_peripheral_install,
2024
test_micp_central_install,
2125
test_micp_peripheral_install,
2226
test_vcp_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 HAP BTP commands with the BT tester
6+
7+
simulation_id="tester_hap"
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=hap_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=hap_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)