Skip to content

Commit f9cea63

Browse files
Andries Kruithofkartben
authored andcommitted
Bluetooth: Audio: add babblesim tests for CAP distribute broadcastcode
Adding a babblesim test for the distribute broadcastcode CAP procedure Signed-off-by: Andries Kruithof <[email protected]>
1 parent 86ab272 commit f9cea63

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/bsim/bluetooth/audio/src/cap_acceptor_test.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ static void broadcast_code_cb(struct bt_conn *conn,
400400
{
401401
printk("Broadcast code received for %p\n", recv_state);
402402

403+
if (memcmp(broadcast_code, BROADCAST_CODE, sizeof(BROADCAST_CODE)) != 0) {
404+
FAIL("Failed to receive correct broadcast code\n");
405+
return;
406+
}
407+
403408
SET_FLAG(flag_broadcast_code);
404409
}
405410

@@ -996,6 +1001,12 @@ static void base_wait_for_metadata_update(void)
9961001
backchannel_sync_send_all(); /* let others know we have received a metadata update */
9971002
}
9981003

1004+
static void wait_for_broadcast_code(void)
1005+
{
1006+
printk("Waiting for broadcast code\n");
1007+
WAIT_FOR_FLAG(flag_broadcast_code);
1008+
}
1009+
9991010
static void wait_for_streams_stop(int stream_count)
10001011
{
10011012
/* The order of PA sync lost and BIG Sync lost is irrelevant
@@ -1046,6 +1057,7 @@ static void test_cap_acceptor_broadcast_reception(void)
10461057

10471058
create_and_sync_sink(bap_streams, &stream_count);
10481059

1060+
wait_for_broadcast_code();
10491061
sink_wait_for_data();
10501062

10511063
/* Since we are re-using the BAP broadcast source test

tests/bsim/bluetooth/audio/src/cap_commander_test.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "bstests.h"
3636
#include "common.h"
37+
#include "bap_common.h"
3738

3839
#if defined(CONFIG_BT_CAP_COMMANDER)
3940

@@ -1056,6 +1057,27 @@ static void test_broadcast_reception_stop(size_t acceptor_count)
10561057
WAIT_FOR_FLAG(flag_broadcast_reception_stop);
10571058
}
10581059

1060+
static void test_distribute_broadcast_code(size_t acceptor_count)
1061+
{
1062+
struct bt_cap_commander_distribute_broadcast_code_param distribute_broadcast_code_param = {
1063+
0};
1064+
struct bt_cap_commander_distribute_broadcast_code_member_param param[CONFIG_BT_MAX_CONN] = {
1065+
0};
1066+
1067+
distribute_broadcast_code_param.type = BT_CAP_SET_TYPE_AD_HOC;
1068+
distribute_broadcast_code_param.param = param;
1069+
distribute_broadcast_code_param.count = acceptor_count;
1070+
memcpy(distribute_broadcast_code_param.broadcast_code, BROADCAST_CODE,
1071+
sizeof(BROADCAST_CODE));
1072+
for (size_t i = 0; i < acceptor_count; i++) {
1073+
1074+
distribute_broadcast_code_param.param[i].member.member = connected_conns[i];
1075+
distribute_broadcast_code_param.param[i].src_id = src_id[i];
1076+
}
1077+
1078+
bt_cap_commander_distribute_broadcast_code(&distribute_broadcast_code_param);
1079+
}
1080+
10591081
static void test_main_cap_commander_capture_and_render(void)
10601082
{
10611083
const size_t acceptor_cnt = get_dev_cnt() - 1; /* Assume all other devices are acceptors
@@ -1133,6 +1155,8 @@ static void test_main_cap_commander_broadcast_reception(void)
11331155

11341156
test_broadcast_reception_start(acceptor_count);
11351157

1158+
test_distribute_broadcast_code(acceptor_count);
1159+
11361160
backchannel_sync_wait_any(); /* wait for the acceptor to receive data */
11371161

11381162
backchannel_sync_wait_any(); /* wait for the acceptor to receive a metadata update */

0 commit comments

Comments
 (0)