Skip to content

Commit 2423a41

Browse files
Thalleynashif
authored andcommitted
tests: Bluetooth: Audio: Add RX check for each stream
Changed the generic global flag_audio_received flag to exist for each stream. This will help verify that each stream, if configured for RX, receives the expected data. One test started failing due to this, so that was disabled until a fix is in place in the controller. Signed-off-by: Emil Gydesen <[email protected]>
1 parent f877417 commit 2423a41

17 files changed

+194
-76
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ static void stream_started_cb(struct bt_bap_stream *stream)
570570
memset(&test_stream->last_info, 0, sizeof(test_stream->last_info));
571571
test_stream->rx_cnt = 0U;
572572
test_stream->valid_rx_cnt = 0U;
573+
UNSET_FLAG(test_stream->flag_audio_received);
573574

574575
err = bt_bap_ep_get_info(stream->ep, &info);
575576
if (err != 0) {
@@ -920,6 +921,17 @@ static void test_broadcast_delete_inval(void)
920921
}
921922
}
922923

924+
static void wait_for_data(void)
925+
{
926+
printk("Waiting for data\n");
927+
ARRAY_FOR_EACH_PTR(broadcast_sink_streams, test_stream) {
928+
if (audio_test_stream_is_streaming(test_stream)) {
929+
WAIT_FOR_FLAG(test_stream->flag_audio_received);
930+
}
931+
}
932+
printk("Data received\n");
933+
}
934+
923935
static void test_common(void)
924936
{
925937
int err;
@@ -953,8 +965,7 @@ static void test_common(void)
953965
k_sem_take(&sem_stream_started, K_FOREVER);
954966
}
955967

956-
printk("Waiting for data\n");
957-
WAIT_FOR_FLAG(flag_audio_received);
968+
wait_for_data();
958969
backchannel_sync_send_all(); /* let other devices know we have received what we wanted */
959970
}
960971

@@ -1067,8 +1078,7 @@ static void test_sink_encrypted(void)
10671078
k_sem_take(&sem_stream_started, K_FOREVER);
10681079
}
10691080

1070-
printk("Waiting for data\n");
1071-
WAIT_FOR_FLAG(flag_audio_received);
1081+
wait_for_data();
10721082

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

@@ -1122,9 +1132,7 @@ static void test_sink_encrypted_incorrect_code(void)
11221132
k_sem_take(&sem_stream_started, K_FOREVER);
11231133
}
11241134

1125-
printk("Waiting for data\n");
1126-
WAIT_FOR_FLAG(flag_audio_received);
1127-
printk("Data received\n");
1135+
wait_for_data();
11281136

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

1174-
printk("Waiting for data\n");
1175-
WAIT_FOR_FLAG(flag_audio_received);
1182+
wait_for_data();
11761183
backchannel_sync_send_all(); /* let other devices know we have received what we wanted */
11771184

11781185
printk("Waiting for BIG sync terminate request\n");

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
#include <zephyr/autoconf.h>
1313
#include <zephyr/bluetooth/audio/audio.h>
1414
#include <zephyr/bluetooth/audio/bap.h>
15+
#include <zephyr/bluetooth/audio/cap.h>
1516
#include <zephyr/bluetooth/bluetooth.h>
1617
#include <zephyr/bluetooth/hci_types.h>
1718
#include <zephyr/bluetooth/iso.h>
1819
#include <zephyr/sys/byteorder.h>
1920
#include <zephyr/sys/printk.h>
2021

2122
#include "bap_common.h"
23+
#include "common.h"
2224

2325
#define VS_CODEC_CID 0x05F1 /* Linux foundation*/
2426
#define VS_CODEC_VID 0x1234 /* any value*/
@@ -138,3 +140,39 @@ void copy_unicast_stream_preset(struct unicast_stream *stream,
138140
memcpy(&stream->qos, &named_preset->preset.qos, sizeof(stream->qos));
139141
memcpy(&stream->codec_cfg, &named_preset->preset.codec_cfg, sizeof(stream->codec_cfg));
140142
}
143+
144+
bool bap_stream_is_streaming(const struct bt_bap_stream *bap_stream)
145+
{
146+
struct bt_bap_ep_info ep_info;
147+
int err;
148+
149+
if (bap_stream == NULL) {
150+
return false;
151+
}
152+
153+
/* No-op if stream is not configured */
154+
if (bap_stream->ep == NULL) {
155+
return false;
156+
}
157+
158+
err = bt_bap_ep_get_info(bap_stream->ep, &ep_info);
159+
if (err != 0) {
160+
return false;
161+
}
162+
163+
if (ep_info.iso_chan == NULL || ep_info.iso_chan->state != BT_ISO_STATE_CONNECTED) {
164+
return false;
165+
}
166+
167+
return ep_info.state == BT_BAP_EP_STATE_STREAMING;
168+
}
169+
170+
bool cap_stream_is_streaming(const struct bt_cap_stream *cap_stream)
171+
{
172+
return bap_stream_is_streaming(&cap_stream->bap_stream);
173+
}
174+
175+
bool audio_test_stream_is_streaming(const struct audio_test_stream *test_stream)
176+
{
177+
return cap_stream_is_streaming(&test_stream->stream);
178+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,7 @@ static inline bool valid_metadata_type(uint8_t type, uint8_t len)
117117
return false;
118118
}
119119
}
120-
120+
bool bap_stream_is_streaming(const struct bt_bap_stream *bap_stream);
121+
bool cap_stream_is_streaming(const struct bt_cap_stream *cap_stream);
122+
bool audio_test_stream_is_streaming(const struct audio_test_stream *test_stream);
121123
#endif /* ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_COMMON_ */

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

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
LOG_MODULE_REGISTER(bap_stream_rx, LOG_LEVEL_INF);
1919

20+
#define LOG_INTERVAL 100
21+
2022
static void log_stream_rx(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info,
2123
struct net_buf *buf)
2224
{
@@ -27,54 +29,77 @@ static void log_stream_rx(struct bt_bap_stream *stream, const struct bt_iso_recv
2729
info->seq_num, info->ts);
2830
}
2931

32+
static void log_stream_err(struct audio_test_stream *test_stream,
33+
const struct bt_iso_recv_info *info, struct net_buf *buf)
34+
{
35+
if (!test_stream->last_rx_failed || (test_stream->rx_cnt % LOG_INTERVAL) == 0U) {
36+
log_stream_rx(&test_stream->stream.bap_stream, info, buf);
37+
}
38+
39+
test_stream->last_rx_failed = true;
40+
}
41+
3042
void bap_stream_rx_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info,
3143
struct net_buf *buf)
3244
{
3345
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
46+
static bool last_failed;
3447

3548
test_stream->rx_cnt++;
3649
if ((info->flags & BT_ISO_FLAGS_VALID) != 0) {
3750
if (memcmp(buf->data, mock_iso_data, buf->len) == 0) {
3851
test_stream->valid_rx_cnt++;
52+
last_failed = false;
3953

4054
if (test_stream->valid_rx_cnt >= MIN_SEND_COUNT) {
41-
/* We set the flag is just one stream has received the expected */
42-
SET_FLAG(flag_audio_received);
55+
SET_FLAG(test_stream->flag_audio_received);
4356
}
4457
} else {
45-
log_stream_rx(stream, info, buf);
58+
log_stream_err(test_stream, info, buf);
4659
FAIL("Unexpected data received\n");
4760
}
4861
}
4962

50-
if ((test_stream->rx_cnt % 50U) == 0U) {
63+
if ((test_stream->rx_cnt % LOG_INTERVAL) == 0U) {
5164
log_stream_rx(stream, info, buf);
5265
}
5366

67+
if (test_stream->rx_cnt >= LOG_INTERVAL && test_stream->valid_rx_cnt == 0U) {
68+
log_stream_err(test_stream, info, buf);
69+
70+
FAIL("No valid RX received: %zu/%zu\n", test_stream->valid_rx_cnt,
71+
test_stream->rx_cnt);
72+
}
73+
5474
if (info->ts == test_stream->last_info.ts) {
55-
log_stream_rx(stream, info, buf);
75+
log_stream_err(test_stream, info, buf);
76+
5677
if (test_stream->valid_rx_cnt > 1U) {
5778
FAIL("Duplicated timestamp received: %u\n", test_stream->last_info.ts);
5879
}
5980
}
6081

6182
if (info->seq_num == test_stream->last_info.seq_num) {
62-
log_stream_rx(stream, info, buf);
83+
log_stream_err(test_stream, info, buf);
84+
6385
if (test_stream->valid_rx_cnt > 1U) {
6486
FAIL("Duplicated PSN received: %u\n", test_stream->last_info.seq_num);
6587
}
6688
}
6789

6890
if (info->flags & BT_ISO_FLAGS_ERROR) {
6991
/* Fail the test if we have not received what we expected */
70-
log_stream_rx(stream, info, buf);
71-
if (test_stream->valid_rx_cnt > 1U && !TEST_FLAG(flag_audio_received)) {
92+
log_stream_err(test_stream, info, buf);
93+
94+
if (test_stream->valid_rx_cnt > 1U &&
95+
!TEST_FLAG(test_stream->flag_audio_received)) {
7296
FAIL("ISO receive error\n");
7397
}
7498
}
7599

76100
if (info->flags & BT_ISO_FLAGS_LOST) {
77-
log_stream_rx(stream, info, buf);
101+
log_stream_err(test_stream, info, buf);
102+
78103
if (test_stream->valid_rx_cnt > 1U) {
79104
FAIL("ISO receive lost\n");
80105
}

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

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <zephyr/sys/util_macro.h>
2828
#include <zephyr/types.h>
2929

30+
#include "bap_common.h"
3031
#include "bap_stream_tx.h"
3132
#include "common.h"
3233

@@ -43,32 +44,6 @@ struct tx_stream {
4344

4445
static struct tx_stream tx_streams[CONFIG_BT_ISO_MAX_CHAN];
4546

46-
static bool stream_is_streaming(const struct bt_bap_stream *bap_stream)
47-
{
48-
struct bt_bap_ep_info ep_info;
49-
int err;
50-
51-
if (bap_stream == NULL) {
52-
return false;
53-
}
54-
55-
/* No-op if stream is not configured */
56-
if (bap_stream->ep == NULL) {
57-
return false;
58-
}
59-
60-
err = bt_bap_ep_get_info(bap_stream->ep, &ep_info);
61-
if (err != 0) {
62-
return false;
63-
}
64-
65-
if (ep_info.iso_chan == NULL || ep_info.iso_chan->state != BT_ISO_STATE_CONNECTED) {
66-
return false;
67-
}
68-
69-
return ep_info.state == BT_BAP_EP_STATE_STREAMING;
70-
}
71-
7247
static void tx_thread_func(void *arg1, void *arg2, void *arg3)
7348
{
7449
NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT,
@@ -88,7 +63,7 @@ static void tx_thread_func(void *arg1, void *arg2, void *arg3)
8863
for (size_t i = 0U; i < ARRAY_SIZE(tx_streams); i++) {
8964
struct bt_bap_stream *bap_stream = tx_streams[i].bap_stream;
9065

91-
if (stream_is_streaming(bap_stream) &&
66+
if (bap_stream_is_streaming(bap_stream) &&
9267
atomic_get(&tx_streams[i].enqueued) < ENQUEUE_CNT) {
9368
struct net_buf *buf;
9469

@@ -102,7 +77,7 @@ static void tx_thread_func(void *arg1, void *arg2, void *arg3)
10277
tx_streams[i].seq_num++;
10378
atomic_inc(&tx_streams[i].enqueued);
10479
} else {
105-
if (!stream_is_streaming(bap_stream)) {
80+
if (!bap_stream_is_streaming(bap_stream)) {
10681
/* Can happen if we disconnected while waiting for a
10782
* buffer - Ignore
10883
*/

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,11 @@ static void transceive_streams(void)
850850
}
851851

852852
if (source_stream != NULL) {
853+
struct audio_test_stream *test_stream =
854+
audio_test_stream_from_bap_stream(source_stream);
855+
853856
printk("Waiting for data\n");
854-
WAIT_FOR_FLAG(flag_audio_received);
857+
WAIT_FOR_FLAG(test_stream->flag_audio_received);
855858
}
856859
}
857860

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,11 @@ static void transceive_test_streams(void)
336336
}
337337

338338
if (sink_stream != NULL) {
339+
struct audio_test_stream *test_stream =
340+
audio_test_stream_from_bap_stream(sink_stream);
341+
339342
printk("Waiting for data\n");
340-
WAIT_FOR_FLAG(flag_audio_received);
343+
WAIT_FOR_FLAG(test_stream->flag_audio_received);
341344
}
342345
}
343346

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ static void started_cb(struct bt_bap_stream *stream)
282282
test_stream->valid_rx_cnt = 0U;
283283
test_stream->seq_num = 0U;
284284
test_stream->tx_cnt = 0U;
285+
UNSET_FLAG(test_stream->flag_audio_received);
285286

286287
printk("Stream %p started\n", stream);
287288
k_sem_give(&sem_broadcast_started);
@@ -333,6 +334,7 @@ static void unicast_stream_started(struct bt_bap_stream *stream)
333334
test_stream->valid_rx_cnt = 0U;
334335
test_stream->seq_num = 0U;
335336
test_stream->tx_cnt = 0U;
337+
UNSET_FLAG(test_stream->flag_audio_received);
336338

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

@@ -796,7 +798,6 @@ static void init(void)
796798
UNSET_FLAG(flag_base_received);
797799
UNSET_FLAG(flag_pa_synced);
798800
UNSET_FLAG(flag_pa_request);
799-
UNSET_FLAG(flag_audio_received);
800801
UNSET_FLAG(flag_base_metadata_updated);
801802
UNSET_FLAG(flag_bis_sync_requested);
802803

@@ -882,7 +883,11 @@ static void init(void)
882883
static void wait_for_data(void)
883884
{
884885
printk("Waiting for data\n");
885-
WAIT_FOR_FLAG(flag_audio_received);
886+
ARRAY_FOR_EACH_PTR(broadcast_sink_streams, test_stream) {
887+
if (audio_test_stream_is_streaming(test_stream)) {
888+
WAIT_FOR_FLAG(test_stream->flag_audio_received);
889+
}
890+
}
886891
printk("Data received\n");
887892
}
888893

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,15 @@ static void create_and_sync_sink(void)
769769

770770
static void wait_for_data(void)
771771
{
772-
UNSET_FLAG(flag_audio_received);
773-
774772
LOG_DBG("Waiting for data");
775-
WAIT_FOR_FLAG(flag_audio_received);
773+
774+
ARRAY_FOR_EACH_PTR(streams, test_stream) {
775+
if (audio_test_stream_is_streaming(test_stream) &&
776+
bap_stream_rx_can_recv(&test_stream->stream.bap_stream)) {
777+
WAIT_FOR_FLAG(test_stream->flag_audio_received);
778+
}
779+
}
780+
776781
LOG_DBG("Data received");
777782
}
778783

0 commit comments

Comments
 (0)