Skip to content

Commit 79af154

Browse files
Thalleyfabiobaltieri
authored andcommitted
tests: bsim: Bluetooth: CAP broadcast AC testing
Add testing of the Audio Configurations from the BAP spec using the CAP API. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 9310b34 commit 79af154

12 files changed

+558
-36
lines changed

subsys/bluetooth/audio/shell/cap_initiator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,9 +1134,9 @@ static int cmd_cap_ac_13(const struct shell *sh, size_t argc, char **argv)
11341134
static int cmd_cap_ac_14(const struct shell *sh, size_t argc, char **argv)
11351135
{
11361136
const struct bap_broadcast_ac_param param = {
1137-
.name = "AC_13",
1137+
.name = "AC_14",
11381138
.stream_cnt = 2U,
1139-
.chan_cnt = 1U,
1139+
.chan_cnt = 2U,
11401140
};
11411141

11421142
return cap_ac_broadcast(sh, argc, argv, &param);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ static void recv_cb(struct bt_bap_stream *stream,
277277
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
278278

279279
if ((test_stream->rx_cnt % 100U) == 0U) {
280-
printk("Incoming audio on stream %p len %u and ts %u\n", stream, buf->len,
281-
info->ts);
280+
printk("[%zu]: Incoming audio on stream %p len %u and ts %u\n", test_stream->rx_cnt,
281+
stream, buf->len, info->ts);
282282
}
283283

284284
if (test_stream->rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
@@ -313,7 +313,7 @@ static void recv_cb(struct bt_bap_stream *stream,
313313
SET_FLAG(flag_received);
314314
}
315315
} else {
316-
FAIL("Unexpected data received");
316+
FAIL("Unexpected data received\n");
317317
}
318318
}
319319

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
121121
{
122122
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
123123

124-
printk("Incoming audio on stream %p len %u and ts %u\n", stream, buf->len, info->ts);
124+
if ((test_stream->rx_cnt % 100U) == 0U) {
125+
printk("[%zu]: Incoming audio on stream %p len %u and ts %u\n", test_stream->rx_cnt,
126+
stream, buf->len, info->ts);
127+
}
125128

126129
if (test_stream->rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
127130
FAIL("Duplicated timestamp received: %u\n", test_stream->last_info.ts);
@@ -146,7 +149,7 @@ static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
146149
if (memcmp(buf->data, mock_iso_data, buf->len) == 0) {
147150
test_stream->rx_cnt++;
148151
} else {
149-
FAIL("Unexpected data received");
152+
FAIL("Unexpected data received\n");
150153
}
151154
}
152155

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
254254
{
255255
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
256256

257-
printk("Incoming audio on stream %p len %u and ts %u\n", stream, buf->len, info->ts);
257+
if ((test_stream->rx_cnt % 100U) == 0U) {
258+
printk("[%zu]: Incoming audio on stream %p len %u and ts %u\n", test_stream->rx_cnt,
259+
stream, buf->len, info->ts);
260+
}
258261

259262
if (test_stream->rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
260263
FAIL("Duplicated timestamp received: %u\n", test_stream->last_info.ts);
@@ -279,7 +282,7 @@ static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
279282
if (memcmp(buf->data, mock_iso_data, buf->len) == 0) {
280283
test_stream->rx_cnt++;
281284
} else {
282-
FAIL("Unexpected data received");
285+
FAIL("Unexpected data received\n");
283286
}
284287
}
285288

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

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static struct bt_le_scan_recv_info broadcaster_info;
3333
static bt_addr_le_t broadcaster_addr;
3434
static struct bt_le_per_adv_sync *pa_sync;
3535
static uint32_t broadcaster_broadcast_id;
36-
static struct bt_cap_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
36+
static struct audio_test_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
3737

3838
static const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
3939
BT_AUDIO_CODEC_LC3_FREQ_ANY, BT_AUDIO_CODEC_LC3_DURATION_ANY,
@@ -260,7 +260,47 @@ static void stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
260260
static void recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info,
261261
struct net_buf *buf)
262262
{
263-
SET_FLAG(flag_received);
263+
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
264+
265+
if ((test_stream->rx_cnt % 100U) == 0U) {
266+
printk("[%zu]: Incoming audio on stream %p len %u and ts %u\n", test_stream->rx_cnt,
267+
stream, buf->len, info->ts);
268+
}
269+
270+
if (test_stream->rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
271+
FAIL("Duplicated timestamp received: %u\n", test_stream->last_info.ts);
272+
return;
273+
}
274+
275+
if (test_stream->rx_cnt > 0U && info->seq_num == test_stream->last_info.seq_num) {
276+
FAIL("Duplicated PSN received: %u\n", test_stream->last_info.seq_num);
277+
return;
278+
}
279+
280+
if (info->flags & BT_ISO_FLAGS_ERROR) {
281+
/* Fail the test if we have not received what we expected */
282+
if (!TEST_FLAG(flag_received)) {
283+
FAIL("ISO receive error\n");
284+
}
285+
286+
return;
287+
}
288+
289+
if (info->flags & BT_ISO_FLAGS_LOST) {
290+
FAIL("ISO receive lost\n");
291+
return;
292+
}
293+
294+
if (memcmp(buf->data, mock_iso_data, buf->len) == 0) {
295+
test_stream->rx_cnt++;
296+
297+
if (test_stream->rx_cnt >= MIN_SEND_COUNT) {
298+
/* We set the flag is just one stream has received the expected */
299+
SET_FLAG(flag_received);
300+
}
301+
} else {
302+
FAIL("Unexpected data received\n");
303+
}
264304
}
265305

266306
static struct bt_bap_stream_ops broadcast_stream_ops = {
@@ -604,8 +644,9 @@ static void init(void)
604644
UNSET_FLAG(flag_pa_synced);
605645

606646
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) {
607-
bt_cap_stream_ops_register(&broadcast_sink_streams[i],
608-
&broadcast_stream_ops);
647+
bt_cap_stream_ops_register(
648+
cap_stream_from_audio_test_stream(&broadcast_sink_streams[i]),
649+
&broadcast_stream_ops);
609650
}
610651
}
611652

@@ -678,6 +719,7 @@ static int pa_sync_create(void)
678719
static void test_cap_acceptor_broadcast(void)
679720
{
680721
static struct bt_bap_stream *bap_streams[ARRAY_SIZE(broadcast_sink_streams)];
722+
size_t stream_count;
681723
int err;
682724

683725
init();
@@ -724,24 +766,32 @@ static void test_cap_acceptor_broadcast(void)
724766
WAIT_FOR_FLAG(flag_syncable);
725767

726768
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) {
727-
bap_streams[i] = &broadcast_sink_streams[i].bap_stream;
769+
bap_streams[i] = bap_stream_from_audio_test_stream(&broadcast_sink_streams[i]);
728770
}
729771

730772
printk("Syncing the sink\n");
773+
stream_count = 0;
774+
for (int i = 1; i < BT_ISO_MAX_GROUP_ISO_COUNT; i++) {
775+
if ((bis_index_bitfield & BIT(i)) != 0) {
776+
stream_count++;
777+
}
778+
}
779+
731780
err = bt_bap_broadcast_sink_sync(g_broadcast_sink, bis_index_bitfield, bap_streams, NULL);
732781
if (err != 0) {
733782
FAIL("Unable to sync the sink: %d\n", err);
734783
return;
735784
}
736785

737786
/* Wait for all to be started */
738-
printk("Waiting for broadcast_sink_streams to be started\n");
739-
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) {
787+
printk("Waiting for %zu streams to be started\n", stream_count);
788+
for (size_t i = 0U; i < stream_count; i++) {
740789
k_sem_take(&sem_broadcast_started, K_FOREVER);
741790
}
742791

743792
printk("Waiting for data\n");
744793
WAIT_FOR_FLAG(flag_received);
794+
backchannel_sync_send_all(); /* let other devices know we have received what we wanted */
745795

746796
/* The order of PA sync lost and BIG Sync lost is irrelevant
747797
* and depend on timeout parameters. We just wait for PA first, but
@@ -750,8 +800,8 @@ static void test_cap_acceptor_broadcast(void)
750800
printk("Waiting for PA disconnected\n");
751801
WAIT_FOR_FLAG(flag_pa_sync_lost);
752802

753-
printk("Waiting for streams to be stopped\n");
754-
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) {
803+
printk("Waiting for %zu streams to be stopped\n", stream_count);
804+
for (size_t i = 0U; i < stream_count; i++) {
755805
k_sem_take(&sem_broadcast_stopped, K_FOREVER);
756806
}
757807

0 commit comments

Comments
 (0)