Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ static void stream_started_cb(struct bt_bap_stream *stream)

memset(&test_stream->last_info, 0, sizeof(test_stream->last_info));
test_stream->rx_cnt = 0U;
test_stream->valid_rx_cnt = 0U;

err = bt_bap_ep_get_info(stream->ep, &info);
if (err != 0) {
Expand Down
4 changes: 3 additions & 1 deletion tests/bsim/bluetooth/audio/src/bap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/bluetooth.h>

#include "common.h"

#define LONG_META 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \
Expand Down Expand Up @@ -46,7 +48,7 @@
((uint8_t[]){0xDE, 0xAD, 0xBE, 0xEF, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, \
0xdd, 0xee, 0xff})
struct unicast_stream {
struct bt_cap_stream stream;
struct audio_test_stream stream;
struct bt_audio_codec_cfg codec_cfg;
struct bt_bap_qos_cfg qos;
};
Expand Down
54 changes: 40 additions & 14 deletions tests/bsim/bluetooth/audio/src/bap_stream_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ static void log_stream_rx(struct bt_bap_stream *stream, const struct bt_iso_recv
{
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);

LOG_INF("[%zu]: Incoming audio on stream %p len %u, flags 0x%02X, seq_num %u and ts %u",
test_stream->rx_cnt, stream, buf->len, info->flags, info->seq_num, info->ts);
LOG_INF("[%zu|%zu]: Incoming audio on stream %p len %u, flags 0x%02X, seq_num %u and ts %u",
test_stream->valid_rx_cnt, test_stream->rx_cnt, stream, buf->len, info->flags,
info->seq_num, info->ts);
}

void bap_stream_rx_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info,
Expand All @@ -33,13 +34,15 @@ void bap_stream_rx_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
log_stream_rx(stream, info, buf);
}

if (test_stream->rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
test_stream->rx_cnt++;

if (test_stream->valid_rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
log_stream_rx(stream, info, buf);
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) {
if (test_stream->valid_rx_cnt > 0U && info->seq_num == test_stream->last_info.seq_num) {
log_stream_rx(stream, info, buf);
FAIL("Duplicated PSN received: %u\n", test_stream->last_info.seq_num);
return;
Expand All @@ -49,27 +52,50 @@ void bap_stream_rx_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
/* Fail the test if we have not received what we expected */
if (!TEST_FLAG(flag_audio_received)) {
log_stream_rx(stream, info, buf);
FAIL("ISO receive error\n");
if (test_stream->valid_rx_cnt > 0) {
FAIL("ISO receive error\n");
}
}

return;
}

if (info->flags & BT_ISO_FLAGS_LOST) {
log_stream_rx(stream, info, buf);
FAIL("ISO receive lost\n");
if (test_stream->valid_rx_cnt > 0) {
FAIL("ISO receive lost\n");
}
return;
}

if (memcmp(buf->data, mock_iso_data, buf->len) == 0) {
test_stream->rx_cnt++;
if (info->flags & BT_ISO_FLAGS_VALID) {
if (memcmp(buf->data, mock_iso_data, buf->len) == 0) {
test_stream->valid_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_audio_received);
if (test_stream->rx_cnt >= MIN_SEND_COUNT) {
/* We set the flag is just one stream has received the expected */
SET_FLAG(flag_audio_received);
}
} else {
log_stream_rx(stream, info, buf);
FAIL("Unexpected data received\n");
}
} else {
log_stream_rx(stream, info, buf);
FAIL("Unexpected data received\n");
}
}

bool bap_stream_rx_can_recv(const struct bt_bap_stream *stream)
{
struct bt_bap_ep_info info;
int err;

if (stream == NULL || stream->ep == NULL) {
return false;
}

err = bt_bap_ep_get_info(stream->ep, &info);
if (err != 0) {
return false;
}

return info.can_recv;
}
9 changes: 9 additions & 0 deletions tests/bsim/bluetooth/audio/src/bap_stream_rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@

void bap_stream_rx_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info,
struct net_buf *buf);

/**
* @brief Test if the provided stream has been configured for RX
*
* @param bap_stream The stream to test for RX support
*
* @returns true if it has been configured for RX, and false if not
*/
bool bap_stream_rx_can_recv(const struct bt_bap_stream *stream);
96 changes: 79 additions & 17 deletions tests/bsim/bluetooth/audio/src/cap_acceptor_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <zephyr/sys/util_macro.h>

#include "bap_stream_rx.h"
#include "bap_stream_tx.h"
#include "bstests.h"
#include "common.h"
#include "bap_common.h"
Expand All @@ -53,6 +54,8 @@

extern enum bst_result_t bst_result;

#define CAP_INITIATOR_DEV_ID 0 /* CAP initiator shall be ID 0 for these tests */

CREATE_FLAG(flag_broadcaster_found);
CREATE_FLAG(flag_broadcast_code);
CREATE_FLAG(flag_base_received);
Expand All @@ -70,6 +73,7 @@ static bt_addr_le_t broadcaster_addr;
static struct bt_le_per_adv_sync *pa_sync;
static uint32_t broadcaster_broadcast_id;
static struct audio_test_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
static bool expect_rx;

static const struct bt_bap_qos_cfg_pref unicast_qos_pref =
BT_BAP_QOS_CFG_PREF(true, BT_GAP_LE_PHY_2M, 0u, 60u, 20000u, 40000u, 20000u, 40000u);
Expand All @@ -83,8 +87,8 @@ static uint32_t bis_index_bitfield;

#define UNICAST_CHANNEL_COUNT_1 BIT(0)

static struct bt_cap_stream unicast_streams[CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT +
CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT];
static struct audio_test_stream
unicast_streams[CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT + CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT];

static bool subgroup_data_func_cb(struct bt_data *data, void *user_data)
{
Expand Down Expand Up @@ -286,6 +290,7 @@ static void started_cb(struct bt_bap_stream *stream)

memset(&test_stream->last_info, 0, sizeof(test_stream->last_info));
test_stream->rx_cnt = 0U;
test_stream->valid_rx_cnt = 0U;
test_stream->seq_num = 0U;
test_stream->tx_cnt = 0U;

Expand Down Expand Up @@ -330,8 +335,52 @@ static void unicast_stream_enabled_cb(struct bt_bap_stream *stream)
}
}

static void unicast_stream_started(struct bt_bap_stream *stream)
{
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);

memset(&test_stream->last_info, 0, sizeof(test_stream->last_info));
test_stream->rx_cnt = 0U;
test_stream->valid_rx_cnt = 0U;
test_stream->seq_num = 0U;
test_stream->tx_cnt = 0U;

printk("Started stream %p\n", stream);

if (bap_stream_tx_can_send(stream)) {
int err;

err = bap_stream_tx_register(stream);
if (err != 0) {
FAIL("Failed to register stream %p for TX: %d\n", stream, err);
return;
}
} else if (bap_stream_rx_can_recv(stream)) {
expect_rx = true;
}
}

static void unicast_stream_stopped(struct bt_bap_stream *stream, uint8_t reason)
{
printk("Stopped stream %p with reason 0x%02X\n", stream, reason);

if (bap_stream_tx_can_send(stream)) {
int err;

err = bap_stream_tx_unregister(stream);
if (err != 0) {
FAIL("Failed to unregister stream %p for TX: %d\n", stream, err);
return;
}
}
}

static struct bt_bap_stream_ops unicast_stream_ops = {
.enabled = unicast_stream_enabled_cb,
.started = unicast_stream_started,
.stopped = unicast_stream_stopped,
.sent = bap_stream_tx_sent_cb,
.recv = bap_stream_rx_recv_cb,
};

static int pa_sync_req_cb(struct bt_conn *conn,
Expand Down Expand Up @@ -415,7 +464,8 @@ static struct bt_csip_set_member_svc_inst *csip_set_member;
static struct bt_bap_stream *unicast_stream_alloc(void)
{
for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) {
struct bt_bap_stream *stream = &unicast_streams[i].bap_stream;
struct bt_bap_stream *stream =
bap_stream_from_audio_test_stream(&unicast_streams[i]);

if (!stream->conn) {
return stream;
Expand Down Expand Up @@ -671,6 +721,7 @@ static void init(void)
}

printk("Bluetooth initialized\n");
bap_stream_tx_init();

err = bt_pacs_register(&pacs_param);
if (err) {
Expand Down Expand Up @@ -722,7 +773,9 @@ static void init(void)
}

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

Expand Down Expand Up @@ -838,6 +891,13 @@ static void init(void)
}
}

static void wait_for_data(void)
{
printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
printk("Data received\n");
}

static void test_cap_acceptor_unicast(void)
{
init();
Expand All @@ -846,10 +906,17 @@ static void test_cap_acceptor_unicast(void)

auto_start_sink_streams = true;

/* TODO: wait for audio stream to pass */

WAIT_FOR_FLAG(flag_connected);

/* Wait until initiator is done starting streams */
backchannel_sync_wait(CAP_INITIATOR_DEV_ID);

if (expect_rx) {
wait_for_data();
}
/* let initiator know we have received what we wanted */
backchannel_sync_send(CAP_INITIATOR_DEV_ID);

PASS("CAP acceptor unicast passed\n");
}

Expand All @@ -861,8 +928,6 @@ static void test_cap_acceptor_unicast_timeout(void)

auto_start_sink_streams = false; /* Cause unicast_audio_start timeout */

/* TODO: wait for audio stream to pass */

WAIT_FOR_FLAG(flag_connected);

PASS("CAP acceptor unicast passed\n");
Expand Down Expand Up @@ -958,13 +1023,6 @@ static void create_and_sync_sink(struct bt_bap_stream *bap_streams[], size_t *st
}
}

static void sink_wait_for_data(void)
{
printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
backchannel_sync_send_all(); /* let other devices know we have received what we wanted */
}

static void wait_for_broadcast_code(void)
{
printk("Waiting for broadcast code\n");
Expand Down Expand Up @@ -997,7 +1055,9 @@ static void test_cap_acceptor_broadcast(void)

create_and_sync_sink(bap_streams, &stream_count);

sink_wait_for_data();
wait_for_data();
/* let other devices know we have received what we wanted */
backchannel_sync_send_all();

wait_for_streams_stop(stream_count);

Expand All @@ -1022,7 +1082,9 @@ static void test_cap_acceptor_broadcast_reception(void)
create_and_sync_sink(bap_streams, &stream_count);

wait_for_broadcast_code();
sink_wait_for_data();
wait_for_data();
/* let other devices know we have received what we wanted */
backchannel_sync_send_all();

/* when flag_bis_sync_requested is unset the bis_sync for all subgroups were set to 0 */
WAIT_FOR_UNSET_FLAG(flag_bis_sync_requested);
Expand Down
Loading
Loading