Skip to content

Commit e72e837

Browse files
Thalleydkalowsk
authored andcommitted
tests: Bluetooth: Tester: VCP BSIM test
Adds BSIM testing of the VCP features of the BT Tester. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent a53582d commit e72e837

File tree

9 files changed

+420
-0
lines changed

9 files changed

+420
-0
lines changed

MAINTAINERS.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ Bluetooth Host:
480480
- tests/bsim/bluetooth/hci_uart/
481481
- tests/bsim/bluetooth/ll/
482482
- tests/bsim/bluetooth/mesh/
483+
- tests/bsim/bluetooth/tester/src/audio/
483484
labels:
484485
- "area: Bluetooth Host"
485486
- "area: Bluetooth"
@@ -534,6 +535,7 @@ Bluetooth Audio:
534535
- tests/bluetooth/audio/
535536
- tests/bsim/bluetooth/audio/
536537
- tests/bsim/bluetooth/audio_samples/
538+
- tests/bsim/bluetooth/tester/src/audio/
537539
- tests/bluetooth/shell/audio.conf
538540
- tests/bluetooth/tester/overlay-le-audio.conf
539541
- tests/bluetooth/tester/overlay-bt_ll_sw_split.conf

tests/bluetooth/tester/testcase.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ tests:
6161
tags: bluetooth
6262
harness: bluetooth
6363
sysbuild: true
64+
bluetooth.general.tester_le_audio_bsim:
65+
build_only: true
66+
platform_allow:
67+
- nrf52_bsim/native
68+
- nrf5340bsim/nrf5340/cpuapp
69+
extra_args:
70+
- EXTRA_CONF_FILE="overlay-le-audio.conf"
71+
harness: bsim
72+
harness_config:
73+
bsim_exe_name: tests_bluetooth_tester_le_audio_prj_conf
74+
sysbuild: true
6475
bluetooth.general.tester_mesh:
6576
build_only: true
6677
platform_allow:

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/vcp_central.c
28+
src/audio/vcp_peripheral.c
2729
src/host/gap_central.c
2830
src/host/gap_peripheral.c
2931
)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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_vcp_central, CONFIG_BSIM_BTTESTER_LOG_LEVEL);
22+
23+
static void test_vcp_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_VCP);
34+
bsim_btp_core_register(BTP_SERVICE_ID_VOCS);
35+
bsim_btp_core_register(BTP_SERVICE_ID_AICS);
36+
37+
bsim_btp_gap_start_discovery(BTP_GAP_DISCOVERY_FLAG_LE);
38+
bsim_btp_wait_for_gap_device_found(&remote_addr);
39+
bt_addr_le_to_str(&remote_addr, addr_str, sizeof(addr_str));
40+
LOG_INF("Found remote device %s", addr_str);
41+
42+
bsim_btp_gap_stop_discovery();
43+
bsim_btp_gap_connect(&remote_addr, BTP_GAP_ADDR_TYPE_IDENTITY);
44+
bsim_btp_wait_for_gap_device_connected(NULL);
45+
LOG_INF("Device %s connected", addr_str);
46+
47+
bsim_btp_gap_pair(&remote_addr);
48+
bsim_btp_wait_for_gap_sec_level_changed(NULL, NULL);
49+
50+
bsim_btp_vcp_discover(&remote_addr);
51+
bsim_btp_wait_for_vcp_discovered(NULL);
52+
53+
const uint8_t new_vol = 123;
54+
uint8_t ev_vol;
55+
56+
bsim_btp_vcp_ctlr_set_vol(&remote_addr, new_vol);
57+
bsim_btp_wait_for_vcp_state(NULL, &ev_vol);
58+
TEST_ASSERT(ev_vol == new_vol, "%u != %u", ev_vol, new_vol);
59+
60+
const int16_t new_offset = -5;
61+
int16_t ev_offset;
62+
63+
bsim_btp_vocs_state_set(&remote_addr, new_offset);
64+
bsim_btp_wait_for_vocs_state(NULL, &ev_offset);
65+
TEST_ASSERT(ev_offset == new_offset, "%d != %d", ev_offset, new_offset);
66+
67+
const int8_t new_gain = 5;
68+
int8_t ev_gain;
69+
70+
bsim_btp_aics_set_gain(&remote_addr, new_gain);
71+
bsim_btp_wait_for_aics_state(NULL, &ev_gain);
72+
TEST_ASSERT(ev_gain == new_gain, "%d != %d", ev_gain, new_gain);
73+
74+
bsim_btp_gap_disconnect(&remote_addr);
75+
bsim_btp_wait_for_gap_device_disconnected(NULL);
76+
LOG_INF("Device %s disconnected", addr_str);
77+
78+
TEST_PASS("PASSED\n");
79+
}
80+
81+
static const struct bst_test_instance test_sample[] = {
82+
{
83+
.test_id = "vcp_central",
84+
.test_descr = "Smoketest for the VCP central BT Tester behavior",
85+
.test_main_f = test_vcp_central,
86+
},
87+
BSTEST_END_MARKER,
88+
};
89+
90+
struct bst_test_list *test_vcp_central_install(struct bst_test_list *tests)
91+
{
92+
return bst_add_tests(tests, test_sample);
93+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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_vcp_peripheral, CONFIG_BSIM_BTTESTER_LOG_LEVEL);
22+
23+
static void test_vcp_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_VCS);
34+
bsim_btp_core_register(BTP_SERVICE_ID_VOCS);
35+
bsim_btp_core_register(BTP_SERVICE_ID_AICS);
36+
37+
bsim_btp_gap_set_discoverable(BTP_GAP_GENERAL_DISCOVERABLE);
38+
bsim_btp_gap_start_advertising(0U, 0U, NULL, BT_HCI_OWN_ADDR_PUBLIC);
39+
bsim_btp_wait_for_gap_device_connected(&remote_addr);
40+
bt_addr_le_to_str(&remote_addr, addr_str, sizeof(addr_str));
41+
LOG_INF("Device %s connected", addr_str);
42+
bsim_btp_wait_for_gap_device_disconnected(NULL);
43+
LOG_INF("Device %s disconnected", addr_str);
44+
45+
TEST_PASS("PASSED\n");
46+
}
47+
48+
static const struct bst_test_instance test_sample[] = {
49+
{
50+
.test_id = "vcp_peripheral",
51+
.test_descr = "Smoketest for the VCP peripheral BT Tester behavior",
52+
.test_main_f = test_vcp_peripheral,
53+
},
54+
BSTEST_END_MARKER,
55+
};
56+
57+
struct bst_test_list *test_vcp_peripheral_install(struct bst_test_list *tests)
58+
{
59+
return bst_add_tests(tests, test_sample);
60+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ static bool is_valid_gap_packet_len(const struct btp_hdr *hdr, struct net_buf_si
192192
}
193193
case BTP_GAP_EV_PERIODIC_TRANSFER_RECEIVED:
194194
return buf_simple->len == sizeof(struct btp_gap_ev_periodic_transfer_received_ev);
195+
case BTP_GAP_EV_ENCRYPTION_CHANGE:
196+
return buf_simple->len == sizeof(struct btp_gap_encryption_change_ev);
195197
default:
196198
LOG_ERR("Unhandled opcode 0x%02X", hdr->opcode);
197199
return false;

0 commit comments

Comments
 (0)