Skip to content

Commit 1148b9a

Browse files
Thalleykartben
authored andcommitted
tests: Bluetooth: CAP and GMAP: Add TX/RX for AC tests
Add TX and RX verification for the audio configuration tests. This requires modifying some of the underlying structures used in those tests, as well as initializating and triggering TX, and with verification of RX as well. These tests were implemented to ensure that the streams are not just established, but can send ISO data without issues. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 1f26899 commit 1148b9a

27 files changed

+475
-96
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ static void stream_started_cb(struct bt_bap_stream *stream)
569569

570570
memset(&test_stream->last_info, 0, sizeof(test_stream->last_info));
571571
test_stream->rx_cnt = 0U;
572+
test_stream->valid_rx_cnt = 0U;
572573

573574
err = bt_bap_ep_get_info(stream->ep, &info);
574575
if (err != 0) {

tests/bsim/bluetooth/audio/src/bap_common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <zephyr/bluetooth/bluetooth.h>
2121
#include <zephyr/kernel.h>
2222

23+
#include "common.h"
24+
2325
#define LONG_META 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
2426
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \
2527
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \
@@ -50,7 +52,7 @@
5052
#define BAP_RETRY_WAIT K_MSEC(100)
5153

5254
struct unicast_stream {
53-
struct bt_cap_stream stream;
55+
struct audio_test_stream stream;
5456
struct bt_audio_codec_cfg codec_cfg;
5557
struct bt_bap_qos_cfg qos;
5658
};

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

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ static void log_stream_rx(struct bt_bap_stream *stream, const struct bt_iso_recv
2020
{
2121
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
2222

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

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

36-
if (test_stream->rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
37+
test_stream->rx_cnt++;
38+
39+
if (test_stream->valid_rx_cnt > 0U && info->ts == test_stream->last_info.ts) {
3740
log_stream_rx(stream, info, buf);
3841
FAIL("Duplicated timestamp received: %u\n", test_stream->last_info.ts);
3942
return;
4043
}
4144

42-
if (test_stream->rx_cnt > 0U && info->seq_num == test_stream->last_info.seq_num) {
45+
if (test_stream->valid_rx_cnt > 0U && info->seq_num == test_stream->last_info.seq_num) {
4346
log_stream_rx(stream, info, buf);
4447
FAIL("Duplicated PSN received: %u\n", test_stream->last_info.seq_num);
4548
return;
@@ -49,27 +52,50 @@ void bap_stream_rx_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_rec
4952
/* Fail the test if we have not received what we expected */
5053
if (!TEST_FLAG(flag_audio_received)) {
5154
log_stream_rx(stream, info, buf);
52-
FAIL("ISO receive error\n");
55+
if (test_stream->valid_rx_cnt > 0) {
56+
FAIL("ISO receive error\n");
57+
}
5358
}
5459

5560
return;
5661
}
5762

5863
if (info->flags & BT_ISO_FLAGS_LOST) {
5964
log_stream_rx(stream, info, buf);
60-
FAIL("ISO receive lost\n");
65+
if (test_stream->valid_rx_cnt > 0) {
66+
FAIL("ISO receive lost\n");
67+
}
6168
return;
6269
}
6370

64-
if (memcmp(buf->data, mock_iso_data, buf->len) == 0) {
65-
test_stream->rx_cnt++;
71+
if (info->flags & BT_ISO_FLAGS_VALID) {
72+
if (memcmp(buf->data, mock_iso_data, buf->len) == 0) {
73+
test_stream->valid_rx_cnt++;
6674

67-
if (test_stream->rx_cnt >= MIN_SEND_COUNT) {
68-
/* We set the flag is just one stream has received the expected */
69-
SET_FLAG(flag_audio_received);
75+
if (test_stream->rx_cnt >= MIN_SEND_COUNT) {
76+
/* We set the flag is just one stream has received the expected */
77+
SET_FLAG(flag_audio_received);
78+
}
79+
} else {
80+
log_stream_rx(stream, info, buf);
81+
FAIL("Unexpected data received\n");
7082
}
71-
} else {
72-
log_stream_rx(stream, info, buf);
73-
FAIL("Unexpected data received\n");
7483
}
7584
}
85+
86+
bool bap_stream_rx_can_recv(const struct bt_bap_stream *stream)
87+
{
88+
struct bt_bap_ep_info info;
89+
int err;
90+
91+
if (stream == NULL || stream->ep == NULL) {
92+
return false;
93+
}
94+
95+
err = bt_bap_ep_get_info(stream->ep, &info);
96+
if (err != 0) {
97+
return false;
98+
}
99+
100+
return info.can_recv;
101+
}

tests/bsim/bluetooth/audio/src/bap_stream_rx.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@
1010

1111
void bap_stream_rx_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info,
1212
struct net_buf *buf);
13+
14+
/**
15+
* @brief Test if the provided stream has been configured for RX
16+
*
17+
* @param bap_stream The stream to test for RX support
18+
*
19+
* @returns true if it has been configured for RX, and false if not
20+
*/
21+
bool bap_stream_rx_can_recv(const struct bt_bap_stream *stream);

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

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@
3535
#include <zephyr/sys/util_macro.h>
3636

3737
#include "bap_stream_rx.h"
38+
#include "bap_stream_tx.h"
3839
#include "bstests.h"
3940
#include "common.h"
4041
#include "bap_common.h"
4142

4243
#if defined(CONFIG_BT_CAP_ACCEPTOR)
4344
extern enum bst_result_t bst_result;
4445

46+
#define CAP_INITIATOR_DEV_ID 0 /* CAP initiator shall be ID 0 for these tests */
47+
4548
CREATE_FLAG(flag_broadcaster_found);
4649
CREATE_FLAG(flag_broadcast_code);
4750
CREATE_FLAG(flag_base_received);
@@ -59,6 +62,7 @@ static bt_addr_le_t broadcaster_addr;
5962
static struct bt_le_per_adv_sync *pa_sync;
6063
static uint32_t broadcaster_broadcast_id;
6164
static struct audio_test_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
65+
static bool expect_rx;
6266

6367
static const struct bt_bap_qos_cfg_pref unicast_qos_pref =
6468
BT_BAP_QOS_CFG_PREF(true, BT_GAP_LE_PHY_2M, 0u, 60u, 20000u, 40000u, 20000u, 40000u);
@@ -72,8 +76,8 @@ static uint32_t bis_index_bitfield;
7276

7377
#define UNICAST_CHANNEL_COUNT_1 BIT(0)
7478

75-
static struct bt_cap_stream unicast_streams[CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT +
76-
CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT];
79+
static struct audio_test_stream
80+
unicast_streams[CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT + CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT];
7781

7882
static bool subgroup_data_func_cb(struct bt_data *data, void *user_data)
7983
{
@@ -275,6 +279,7 @@ static void started_cb(struct bt_bap_stream *stream)
275279

276280
memset(&test_stream->last_info, 0, sizeof(test_stream->last_info));
277281
test_stream->rx_cnt = 0U;
282+
test_stream->valid_rx_cnt = 0U;
278283
test_stream->seq_num = 0U;
279284
test_stream->tx_cnt = 0U;
280285

@@ -319,8 +324,52 @@ static void unicast_stream_enabled_cb(struct bt_bap_stream *stream)
319324
}
320325
}
321326

327+
static void unicast_stream_started(struct bt_bap_stream *stream)
328+
{
329+
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
330+
331+
memset(&test_stream->last_info, 0, sizeof(test_stream->last_info));
332+
test_stream->rx_cnt = 0U;
333+
test_stream->valid_rx_cnt = 0U;
334+
test_stream->seq_num = 0U;
335+
test_stream->tx_cnt = 0U;
336+
337+
printk("Started stream %p\n", stream);
338+
339+
if (bap_stream_tx_can_send(stream)) {
340+
int err;
341+
342+
err = bap_stream_tx_register(stream);
343+
if (err != 0) {
344+
FAIL("Failed to register stream %p for TX: %d\n", stream, err);
345+
return;
346+
}
347+
} else if (bap_stream_rx_can_recv(stream)) {
348+
expect_rx = true;
349+
}
350+
}
351+
352+
static void unicast_stream_stopped(struct bt_bap_stream *stream, uint8_t reason)
353+
{
354+
printk("Stopped stream %p with reason 0x%02X\n", stream, reason);
355+
356+
if (bap_stream_tx_can_send(stream)) {
357+
int err;
358+
359+
err = bap_stream_tx_unregister(stream);
360+
if (err != 0) {
361+
FAIL("Failed to unregister stream %p for TX: %d\n", stream, err);
362+
return;
363+
}
364+
}
365+
}
366+
322367
static struct bt_bap_stream_ops unicast_stream_ops = {
323368
.enabled = unicast_stream_enabled_cb,
369+
.started = unicast_stream_started,
370+
.stopped = unicast_stream_stopped,
371+
.sent = bap_stream_tx_sent_cb,
372+
.recv = bap_stream_rx_recv_cb,
324373
};
325374

326375
static int pa_sync_req_cb(struct bt_conn *conn,
@@ -404,7 +453,8 @@ static struct bt_csip_set_member_svc_inst *csip_set_member;
404453
static struct bt_bap_stream *unicast_stream_alloc(void)
405454
{
406455
for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) {
407-
struct bt_bap_stream *stream = &unicast_streams[i].bap_stream;
456+
struct bt_bap_stream *stream =
457+
bap_stream_from_audio_test_stream(&unicast_streams[i]);
408458

409459
if (!stream->conn) {
410460
return stream;
@@ -660,6 +710,7 @@ static void init(void)
660710
}
661711

662712
printk("Bluetooth initialized\n");
713+
bap_stream_tx_init();
663714

664715
err = bt_pacs_register(&pacs_param);
665716
if (err) {
@@ -711,7 +762,9 @@ static void init(void)
711762
}
712763

713764
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
714-
bt_cap_stream_ops_register(&unicast_streams[i], &unicast_stream_ops);
765+
bt_cap_stream_ops_register(
766+
cap_stream_from_audio_test_stream(&unicast_streams[i]),
767+
&unicast_stream_ops);
715768
}
716769
}
717770

@@ -827,6 +880,13 @@ static void init(void)
827880
}
828881
}
829882

883+
static void wait_for_data(void)
884+
{
885+
printk("Waiting for data\n");
886+
WAIT_FOR_FLAG(flag_audio_received);
887+
printk("Data received\n");
888+
}
889+
830890
static void test_cap_acceptor_unicast(void)
831891
{
832892
init();
@@ -835,10 +895,17 @@ static void test_cap_acceptor_unicast(void)
835895

836896
auto_start_sink_streams = true;
837897

838-
/* TODO: wait for audio stream to pass */
839-
840898
WAIT_FOR_FLAG(flag_connected);
841899

900+
/* Wait until initiator is done starting streams */
901+
backchannel_sync_wait(CAP_INITIATOR_DEV_ID);
902+
903+
if (expect_rx) {
904+
wait_for_data();
905+
}
906+
/* let initiator know we have received what we wanted */
907+
backchannel_sync_send(CAP_INITIATOR_DEV_ID);
908+
842909
PASS("CAP acceptor unicast passed\n");
843910
}
844911

@@ -850,8 +917,6 @@ static void test_cap_acceptor_unicast_timeout(void)
850917

851918
auto_start_sink_streams = false; /* Cause unicast_audio_start timeout */
852919

853-
/* TODO: wait for audio stream to pass */
854-
855920
WAIT_FOR_FLAG(flag_connected);
856921

857922
PASS("CAP acceptor unicast passed\n");
@@ -947,13 +1012,6 @@ static void create_and_sync_sink(struct bt_bap_stream *bap_streams[], size_t *st
9471012
}
9481013
}
9491014

950-
static void sink_wait_for_data(void)
951-
{
952-
printk("Waiting for data\n");
953-
WAIT_FOR_FLAG(flag_audio_received);
954-
backchannel_sync_send_all(); /* let other devices know we have received what we wanted */
955-
}
956-
9571015
static void wait_for_broadcast_code(void)
9581016
{
9591017
printk("Waiting for broadcast code\n");
@@ -986,7 +1044,9 @@ static void test_cap_acceptor_broadcast(void)
9861044

9871045
create_and_sync_sink(bap_streams, &stream_count);
9881046

989-
sink_wait_for_data();
1047+
wait_for_data();
1048+
/* let other devices know we have received what we wanted */
1049+
backchannel_sync_send_all();
9901050

9911051
wait_for_streams_stop(stream_count);
9921052

@@ -1011,7 +1071,9 @@ static void test_cap_acceptor_broadcast_reception(void)
10111071
create_and_sync_sink(bap_streams, &stream_count);
10121072

10131073
wait_for_broadcast_code();
1014-
sink_wait_for_data();
1074+
wait_for_data();
1075+
/* let other devices know we have received what we wanted */
1076+
backchannel_sync_send_all();
10151077

10161078
/* when flag_bis_sync_requested is unset the bis_sync for all subgroups were set to 0 */
10171079
WAIT_FOR_UNSET_FLAG(flag_bis_sync_requested);

0 commit comments

Comments
 (0)