Skip to content
Open
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
25 changes: 16 additions & 9 deletions tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,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;
UNSET_FLAG(test_stream->flag_audio_received);

err = bt_bap_ep_get_info(stream->ep, &info);
if (err != 0) {
Expand Down Expand Up @@ -920,6 +921,17 @@ static void test_broadcast_delete_inval(void)
}
}

static void wait_for_data(void)
{
printk("Waiting for data\n");
ARRAY_FOR_EACH_PTR(broadcast_sink_streams, test_stream) {
if (audio_test_stream_is_streaming(test_stream)) {
WAIT_FOR_FLAG(test_stream->flag_audio_received);
}
}
printk("Data received\n");
}

static void test_common(void)
{
int err;
Expand Down Expand Up @@ -953,8 +965,7 @@ static void test_common(void)
k_sem_take(&sem_stream_started, K_FOREVER);
}

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

Expand Down Expand Up @@ -1067,8 +1078,7 @@ static void test_sink_encrypted(void)
k_sem_take(&sem_stream_started, K_FOREVER);
}

printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
wait_for_data();

backchannel_sync_send_all(); /* let other devices know we have received data */

Expand Down Expand Up @@ -1122,9 +1132,7 @@ static void test_sink_encrypted_incorrect_code(void)
k_sem_take(&sem_stream_started, K_FOREVER);
}

printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
printk("Data received\n");
wait_for_data();

backchannel_sync_send_all(); /* let other devices know we have received data */
backchannel_sync_send_all(); /* let the broadcast source know it can stop */
Expand Down Expand Up @@ -1171,8 +1179,7 @@ static void broadcast_sink_with_assistant(void)
k_sem_take(&sem_stream_started, K_FOREVER);
}

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

printk("Waiting for BIG sync terminate request\n");
Expand Down
38 changes: 38 additions & 0 deletions tests/bsim/bluetooth/audio/src/bap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
#include <zephyr/autoconf.h>
#include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/audio/bap.h>
#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci_types.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/printk.h>

#include "bap_common.h"
#include "common.h"

#define VS_CODEC_CID 0x05F1 /* Linux foundation*/
#define VS_CODEC_VID 0x1234 /* any value*/
Expand Down Expand Up @@ -138,3 +140,39 @@ void copy_unicast_stream_preset(struct unicast_stream *stream,
memcpy(&stream->qos, &named_preset->preset.qos, sizeof(stream->qos));
memcpy(&stream->codec_cfg, &named_preset->preset.codec_cfg, sizeof(stream->codec_cfg));
}

bool bap_stream_is_streaming(const struct bt_bap_stream *bap_stream)
{
struct bt_bap_ep_info ep_info;
int err;

if (bap_stream == NULL) {
return false;
}

/* No-op if stream is not configured */
if (bap_stream->ep == NULL) {
return false;
}

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

if (ep_info.iso_chan == NULL || ep_info.iso_chan->state != BT_ISO_STATE_CONNECTED) {
return false;
}

return ep_info.state == BT_BAP_EP_STATE_STREAMING;
}

bool cap_stream_is_streaming(const struct bt_cap_stream *cap_stream)
{
return bap_stream_is_streaming(&cap_stream->bap_stream);
}

bool audio_test_stream_is_streaming(const struct audio_test_stream *test_stream)
{
return cap_stream_is_streaming(&test_stream->stream);
}
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 @@ -117,5 +117,7 @@ static inline bool valid_metadata_type(uint8_t type, uint8_t len)
return false;
}
}

bool bap_stream_is_streaming(const struct bt_bap_stream *bap_stream);
bool cap_stream_is_streaming(const struct bt_cap_stream *cap_stream);
bool audio_test_stream_is_streaming(const struct audio_test_stream *test_stream);
#endif /* ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_COMMON_ */
6 changes: 3 additions & 3 deletions tests/bsim/bluetooth/audio/src/bap_stream_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void bap_stream_rx_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
test_stream->valid_rx_cnt++;

if (test_stream->valid_rx_cnt >= MIN_SEND_COUNT) {
/* We set the flag is just one stream has received the expected */
SET_FLAG(flag_audio_received);
SET_FLAG(test_stream->flag_audio_received);
}
} else {
log_stream_rx(stream, info, buf);
Expand Down Expand Up @@ -68,7 +67,8 @@ void bap_stream_rx_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
if (info->flags & BT_ISO_FLAGS_ERROR) {
/* Fail the test if we have not received what we expected */
log_stream_rx(stream, info, buf);
if (test_stream->valid_rx_cnt > 1U && !TEST_FLAG(flag_audio_received)) {
if (test_stream->valid_rx_cnt > 1U &&
!TEST_FLAG(test_stream->flag_audio_received)) {
FAIL("ISO receive error\n");
}
}
Expand Down
31 changes: 3 additions & 28 deletions tests/bsim/bluetooth/audio/src/bap_stream_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <zephyr/sys/util_macro.h>
#include <zephyr/types.h>

#include "bap_common.h"
#include "bap_stream_tx.h"
#include "common.h"

Expand All @@ -43,32 +44,6 @@ struct tx_stream {

static struct tx_stream tx_streams[CONFIG_BT_ISO_MAX_CHAN];

static bool stream_is_streaming(const struct bt_bap_stream *bap_stream)
{
struct bt_bap_ep_info ep_info;
int err;

if (bap_stream == NULL) {
return false;
}

/* No-op if stream is not configured */
if (bap_stream->ep == NULL) {
return false;
}

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

if (ep_info.iso_chan == NULL || ep_info.iso_chan->state != BT_ISO_STATE_CONNECTED) {
return false;
}

return ep_info.state == BT_BAP_EP_STATE_STREAMING;
}

static void tx_thread_func(void *arg1, void *arg2, void *arg3)
{
NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT,
Expand All @@ -88,7 +63,7 @@ static void tx_thread_func(void *arg1, void *arg2, void *arg3)
for (size_t i = 0U; i < ARRAY_SIZE(tx_streams); i++) {
struct bt_bap_stream *bap_stream = tx_streams[i].bap_stream;

if (stream_is_streaming(bap_stream) &&
if (bap_stream_is_streaming(bap_stream) &&
atomic_get(&tx_streams[i].enqueued) < ENQUEUE_CNT) {
struct net_buf *buf;

Expand All @@ -102,7 +77,7 @@ static void tx_thread_func(void *arg1, void *arg2, void *arg3)
tx_streams[i].seq_num++;
atomic_inc(&tx_streams[i].enqueued);
} else {
if (!stream_is_streaming(bap_stream)) {
if (!bap_stream_is_streaming(bap_stream)) {
/* Can happen if we disconnected while waiting for a
* buffer - Ignore
*/
Expand Down
5 changes: 4 additions & 1 deletion tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,11 @@ static void transceive_streams(void)
}

if (source_stream != NULL) {
struct audio_test_stream *test_stream =
audio_test_stream_from_bap_stream(source_stream);

printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
WAIT_FOR_FLAG(test_stream->flag_audio_received);
}
}

Expand Down
5 changes: 4 additions & 1 deletion tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,11 @@ static void transceive_test_streams(void)
}

if (sink_stream != NULL) {
struct audio_test_stream *test_stream =
audio_test_stream_from_bap_stream(sink_stream);

printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
WAIT_FOR_FLAG(test_stream->flag_audio_received);
}
}

Expand Down
9 changes: 7 additions & 2 deletions tests/bsim/bluetooth/audio/src/cap_acceptor_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ static void started_cb(struct bt_bap_stream *stream)
test_stream->valid_rx_cnt = 0U;
test_stream->seq_num = 0U;
test_stream->tx_cnt = 0U;
UNSET_FLAG(test_stream->flag_audio_received);

printk("Stream %p started\n", stream);
k_sem_give(&sem_broadcast_started);
Expand Down Expand Up @@ -333,6 +334,7 @@ static void unicast_stream_started(struct bt_bap_stream *stream)
test_stream->valid_rx_cnt = 0U;
test_stream->seq_num = 0U;
test_stream->tx_cnt = 0U;
UNSET_FLAG(test_stream->flag_audio_received);

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

Expand Down Expand Up @@ -796,7 +798,6 @@ static void init(void)
UNSET_FLAG(flag_base_received);
UNSET_FLAG(flag_pa_synced);
UNSET_FLAG(flag_pa_request);
UNSET_FLAG(flag_audio_received);
UNSET_FLAG(flag_base_metadata_updated);
UNSET_FLAG(flag_bis_sync_requested);

Expand Down Expand Up @@ -882,7 +883,11 @@ static void init(void)
static void wait_for_data(void)
{
printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
ARRAY_FOR_EACH_PTR(broadcast_sink_streams, test_stream) {
if (audio_test_stream_is_streaming(test_stream)) {
WAIT_FOR_FLAG(test_stream->flag_audio_received);
}
}
printk("Data received\n");
}

Expand Down
11 changes: 8 additions & 3 deletions tests/bsim/bluetooth/audio/src/cap_handover_peripheral_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,15 @@ static void create_and_sync_sink(void)

static void wait_for_data(void)
{
UNSET_FLAG(flag_audio_received);

LOG_DBG("Waiting for data");
WAIT_FOR_FLAG(flag_audio_received);

ARRAY_FOR_EACH_PTR(streams, test_stream) {
if (audio_test_stream_is_streaming(test_stream) &&
bap_stream_rx_can_recv(&test_stream->stream.bap_stream)) {
WAIT_FOR_FLAG(test_stream->flag_audio_received);
}
}

LOG_DBG("Data received");
}

Expand Down
29 changes: 19 additions & 10 deletions tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ static void unicast_stream_started(struct bt_bap_stream *stream)
test_stream->valid_rx_cnt = 0U;
test_stream->seq_num = 0U;
test_stream->tx_cnt = 0U;
UNSET_FLAG(test_stream->flag_audio_received);

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

Expand Down Expand Up @@ -905,6 +906,17 @@ static void unicast_group_delete(struct bt_cap_unicast_group *unicast_group)
}
}

static void wait_for_data(void)
{
printk("Waiting for data\n");
ARRAY_FOR_EACH_PTR(unicast_client_source_streams, test_stream) {
if (audio_test_stream_is_streaming(test_stream)) {
WAIT_FOR_FLAG(test_stream->flag_audio_received);
}
}
printk("Data received\n");
}

static void test_main_cap_initiator_unicast(void)
{
struct bt_cap_unicast_group *unicast_group;
Expand All @@ -930,14 +942,15 @@ static void test_main_cap_initiator_unicast(void)
for (size_t j = 0U; j < iterations; j++) {
printk("\nRunning iteration j=%zu\n\n", i);

UNSET_FLAG(flag_audio_received);
ARRAY_FOR_EACH_PTR(unicast_client_sink_streams, test_stream) {
UNSET_FLAG(test_stream->flag_audio_received);
}

unicast_audio_start(unicast_group, true);

unicast_audio_update();

printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
wait_for_data();

/* Due to how the backchannel sync is implemented for LE Audio we cannot
* easily tell the remote (CAP acceptor) how many times to wait for data,
Expand Down Expand Up @@ -981,9 +994,7 @@ static void test_main_cap_initiator_unicast_inval(void)
unicast_audio_update_inval();
unicast_audio_update();

printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
printk("Data received\n");
wait_for_data();

/* Wait until acceptors have received expected data */
backchannel_sync_wait_all();
Expand Down Expand Up @@ -1091,9 +1102,7 @@ static void test_cap_initiator_unicast_ase_error(void)
/* Without invalid metadata type, start should pass */
unicast_audio_start(unicast_group, true);

printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
printk("Data received\n");
wait_for_data();

/* Wait until acceptors have received expected data */
backchannel_sync_wait_all();
Expand Down Expand Up @@ -1487,7 +1496,7 @@ static void test_cap_initiator_ac(const struct cap_initiator_ac_param *param)

if (expect_rx) {
printk("Waiting for data\n");
WAIT_FOR_FLAG(flag_audio_received);
wait_for_data();
}

cap_initiator_unicast_audio_stop(unicast_group);
Expand Down
1 change: 0 additions & 1 deletion tests/bsim/bluetooth/audio/src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ struct bt_conn *default_conn;
atomic_t flag_connected;
atomic_t flag_disconnected;
atomic_t flag_conn_updated;
atomic_t flag_audio_received;
volatile bt_security_t security_level;
#if defined(CONFIG_BT_CSIP_SET_MEMBER)
uint8_t csip_rsi[BT_CSIP_RSI_SIZE];
Expand Down
2 changes: 1 addition & 1 deletion tests/bsim/bluetooth/audio/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ extern struct bt_conn *default_conn;
extern atomic_t flag_connected;
extern atomic_t flag_disconnected;
extern atomic_t flag_conn_updated;
extern atomic_t flag_audio_received;
extern volatile bt_security_t security_level;
extern uint8_t csip_rsi[BT_CSIP_RSI_SIZE];

Expand Down Expand Up @@ -170,6 +169,7 @@ struct audio_test_stream {
struct bt_iso_recv_info last_info;
size_t rx_cnt;
size_t valid_rx_cnt;
atomic_t flag_audio_received;
};

static inline struct bt_cap_stream *cap_stream_from_bap_stream(struct bt_bap_stream *bap_stream)
Expand Down
Loading
Loading