Skip to content

Commit b18fcdb

Browse files
Thalleystephanosio
authored andcommitted
tests: Bluetooth: Expand unicast audio BSIM tests
Expands the unicast audio babblesim tests up until the start procedure (which is not yet supported by the babblesim). This increases the test coverage of the unicast implemetations. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 54d31d0 commit b18fcdb

File tree

2 files changed

+72
-13
lines changed

2 files changed

+72
-13
lines changed

tests/bluetooth/bsim_bt/bsim_test_audio/src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false
3737
#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true)
38-
#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false)
38+
#define UNSET_FLAG(flag) (void)atomic_clear(&flag)
3939
#define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t)true)
4040
#define WAIT_FOR_FLAG(flag) \
4141
while (!(bool)atomic_get(&flag)) { \

tests/bluetooth/bsim_bt/bsim_test_audio/src/unicast_client_test.c

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ static struct bt_audio_lc3_preset preset_16_2_1 =
2626
CREATE_FLAG(flag_connected);
2727
CREATE_FLAG(flag_mtu_exchanged);
2828
CREATE_FLAG(flag_sink_discovered);
29-
CREATE_FLAG(flag_stream_configured);
30-
CREATE_FLAG(flag_stream_qos);
29+
CREATE_FLAG(flag_stream_codec_configured);
30+
static atomic_t flag_stream_qos_configured;
3131
CREATE_FLAG(flag_stream_enabled);
3232
CREATE_FLAG(flag_stream_released);
3333

@@ -40,14 +40,14 @@ static void stream_configured(struct bt_audio_stream *stream,
4040
* setting the QoS
4141
*/
4242

43-
SET_FLAG(flag_stream_configured);
43+
SET_FLAG(flag_stream_codec_configured);
4444
}
4545

4646
static void stream_qos_set(struct bt_audio_stream *stream)
4747
{
4848
printk("QoS set stream %p\n", stream);
4949

50-
SET_FLAG(flag_stream_qos);
50+
atomic_inc(&flag_stream_qos_configured);
5151
}
5252

5353
static void stream_enabled(struct bt_audio_stream *stream)
@@ -270,12 +270,12 @@ static void discover_sink(void)
270270
WAIT_FOR_FLAG(flag_sink_discovered);
271271
}
272272

273-
static int configure_stream(struct bt_audio_stream *stream,
273+
static int codec_configure_stream(struct bt_audio_stream *stream,
274274
struct bt_audio_ep *ep)
275275
{
276276
int err;
277277

278-
UNSET_FLAG(flag_stream_configured);
278+
UNSET_FLAG(flag_stream_codec_configured);
279279

280280
err = bt_audio_stream_config(default_conn, stream, ep,
281281
&preset_16_2_1.codec);
@@ -284,12 +284,12 @@ static int configure_stream(struct bt_audio_stream *stream,
284284
return err;
285285
}
286286

287-
WAIT_FOR_FLAG(flag_stream_configured);
287+
WAIT_FOR_FLAG(flag_stream_codec_configured);
288288

289289
return 0;
290290
}
291291

292-
static size_t configure_streams(void)
292+
static size_t codec_configure_streams(void)
293293
{
294294
size_t stream_cnt;
295295

@@ -301,7 +301,7 @@ static size_t configure_streams(void)
301301
break;
302302
}
303303

304-
err = configure_stream(stream, g_sinks[stream_cnt]);
304+
err = codec_configure_stream(stream, g_sinks[stream_cnt]);
305305
if (err != 0) {
306306
FAIL("Unable to configure stream[%zu]: %d",
307307
stream_cnt, err);
@@ -312,6 +312,59 @@ static size_t configure_streams(void)
312312
return stream_cnt;
313313
}
314314

315+
static void qos_configure_streams(struct bt_audio_unicast_group *unicast_group,
316+
size_t stream_cnt)
317+
{
318+
int err;
319+
320+
UNSET_FLAG(flag_stream_qos_configured);
321+
322+
err = bt_audio_stream_qos(default_conn, unicast_group);
323+
if (err != 0) {
324+
FAIL("Unable to QoS configure streams: %d", err);
325+
326+
return;
327+
}
328+
329+
while (atomic_get(&flag_stream_qos_configured) != stream_cnt) {
330+
(void)k_sleep(K_MSEC(1));
331+
}
332+
}
333+
334+
static int enable_stream(struct bt_audio_stream *stream)
335+
{
336+
int err;
337+
338+
UNSET_FLAG(flag_stream_enabled);
339+
340+
err = bt_audio_stream_enable(stream, NULL, 0);
341+
if (err != 0) {
342+
FAIL("Could not enable stream: %d\n", err);
343+
344+
return err;
345+
}
346+
347+
WAIT_FOR_FLAG(flag_stream_enabled);
348+
349+
return 0;
350+
}
351+
352+
static void enable_streams(size_t stream_cnt)
353+
{
354+
for (size_t i = 0U; i < stream_cnt; i++) {
355+
struct bt_audio_stream *stream = &g_streams[i];
356+
int err;
357+
358+
err = enable_stream(stream);
359+
if (err != 0) {
360+
FAIL("Unable to enable stream[%zu]: %d",
361+
i, err);
362+
363+
return;
364+
}
365+
}
366+
}
367+
315368
static size_t release_streams(size_t stream_cnt)
316369
{
317370
for (size_t i = 0; i < stream_cnt; i++) {
@@ -399,10 +452,16 @@ static void test_main(void)
399452
printk("Creating unicast group\n");
400453
create_unicast_group(&unicast_group);
401454

402-
printk("Configuring streams\n");
403-
stream_cnt = configure_streams();
455+
printk("Codec configuring streams\n");
456+
stream_cnt = codec_configure_streams();
457+
458+
printk("QoS configuring streams\n");
459+
qos_configure_streams(unicast_group, stream_cnt);
460+
461+
printk("Enabling streams\n");
462+
enable_streams(stream_cnt);
404463

405-
/* TODO: When babblesim supports ISO setup Audio streams */
464+
/* TODO: When babblesim supports CIS connection start Audio streams */
406465

407466
release_streams(stream_cnt);
408467

0 commit comments

Comments
 (0)