Skip to content

Commit

Permalink
tests: bsim: Bluetooth: CAP broadcast AC testing
Browse files Browse the repository at this point in the history
Add testing of the Audio Configurations from the BAP spec using
the CAP API.

(cherry picked from commit 79af154)

Original-Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
GitOrigin-RevId: 79af154
Change-Id: Iff57dd268210c8621b0bdfc26e08dea6707c39cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5192494
Reviewed-by: Tristan Honscheid <honscheid@google.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Commit-Queue: Tristan Honscheid <honscheid@google.com>
Tested-by: Tristan Honscheid <honscheid@google.com>
  • Loading branch information
Thalley authored and Chromeos LUCI committed Jan 12, 2024
1 parent 0e21ae5 commit ede2d56
Show file tree
Hide file tree
Showing 12 changed files with 558 additions and 36 deletions.
4 changes: 2 additions & 2 deletions subsys/bluetooth/audio/shell/cap_initiator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,9 +1134,9 @@ static int cmd_cap_ac_13(const struct shell *sh, size_t argc, char **argv)
static int cmd_cap_ac_14(const struct shell *sh, size_t argc, char **argv)
{
const struct bap_broadcast_ac_param param = {
.name = "AC_13",
.name = "AC_14",
.stream_cnt = 2U,
.chan_cnt = 1U,
.chan_cnt = 2U,
};

return cap_ac_broadcast(sh, argc, argv, &param);
Expand Down
6 changes: 3 additions & 3 deletions tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ static void recv_cb(struct bt_bap_stream *stream,
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);

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

if (test_stream->rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
Expand Down Expand Up @@ -313,7 +313,7 @@ static void recv_cb(struct bt_bap_stream *stream,
SET_FLAG(flag_received);
}
} else {
FAIL("Unexpected data received");
FAIL("Unexpected data received\n");
}
}

Expand Down
7 changes: 5 additions & 2 deletions tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
{
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);

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

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

Expand Down
7 changes: 5 additions & 2 deletions tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
{
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);

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

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

Expand Down
68 changes: 59 additions & 9 deletions tests/bsim/bluetooth/audio/src/cap_acceptor_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static struct bt_le_scan_recv_info broadcaster_info;
static bt_addr_le_t broadcaster_addr;
static struct bt_le_per_adv_sync *pa_sync;
static uint32_t broadcaster_broadcast_id;
static struct bt_cap_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
static struct audio_test_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];

static const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
BT_AUDIO_CODEC_LC3_FREQ_ANY, BT_AUDIO_CODEC_LC3_DURATION_ANY,
Expand Down Expand Up @@ -260,7 +260,47 @@ static void stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
static void recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info,
struct net_buf *buf)
{
SET_FLAG(flag_received);
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);

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

if (test_stream->rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
FAIL("Duplicated timestamp received: %u\n", test_stream->last_info.ts);
return;
}

if (test_stream->rx_cnt > 0U && info->seq_num == test_stream->last_info.seq_num) {
FAIL("Duplicated PSN received: %u\n", test_stream->last_info.seq_num);
return;
}

if (info->flags & BT_ISO_FLAGS_ERROR) {
/* Fail the test if we have not received what we expected */
if (!TEST_FLAG(flag_received)) {
FAIL("ISO receive error\n");
}

return;
}

if (info->flags & BT_ISO_FLAGS_LOST) {
FAIL("ISO receive lost\n");
return;
}

if (memcmp(buf->data, mock_iso_data, buf->len) == 0) {
test_stream->rx_cnt++;

if (test_stream->rx_cnt >= MIN_SEND_COUNT) {
/* We set the flag is just one stream has received the expected */
SET_FLAG(flag_received);
}
} else {
FAIL("Unexpected data received\n");
}
}

static struct bt_bap_stream_ops broadcast_stream_ops = {
Expand Down Expand Up @@ -604,8 +644,9 @@ static void init(void)
UNSET_FLAG(flag_pa_synced);

for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) {
bt_cap_stream_ops_register(&broadcast_sink_streams[i],
&broadcast_stream_ops);
bt_cap_stream_ops_register(
cap_stream_from_audio_test_stream(&broadcast_sink_streams[i]),
&broadcast_stream_ops);
}
}

Expand Down Expand Up @@ -678,6 +719,7 @@ static int pa_sync_create(void)
static void test_cap_acceptor_broadcast(void)
{
static struct bt_bap_stream *bap_streams[ARRAY_SIZE(broadcast_sink_streams)];
size_t stream_count;
int err;

init();
Expand Down Expand Up @@ -724,24 +766,32 @@ static void test_cap_acceptor_broadcast(void)
WAIT_FOR_FLAG(flag_syncable);

for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) {
bap_streams[i] = &broadcast_sink_streams[i].bap_stream;
bap_streams[i] = bap_stream_from_audio_test_stream(&broadcast_sink_streams[i]);
}

printk("Syncing the sink\n");
stream_count = 0;
for (int i = 1; i < BT_ISO_MAX_GROUP_ISO_COUNT; i++) {
if ((bis_index_bitfield & BIT(i)) != 0) {
stream_count++;
}
}

err = bt_bap_broadcast_sink_sync(g_broadcast_sink, bis_index_bitfield, bap_streams, NULL);
if (err != 0) {
FAIL("Unable to sync the sink: %d\n", err);
return;
}

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

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

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

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

Expand Down
Loading

0 comments on commit ede2d56

Please sign in to comment.