Skip to content

Commit bebb98e

Browse files
Thalleystephanosio
authored andcommitted
tests: Bluetooth: Unicast client BSIM used group size as stream_cnt
Instead of setting the stream_cnt based on the number of streams configurer, we use the number of streams actually added to the group, and then configure that amount. This should ensure that we do not try to configure any streams that we have not already added to the group. Signed-off-by: Emil Gydesen <[email protected]>
1 parent b18fcdb commit bebb98e

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

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

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -289,27 +289,22 @@ static int codec_configure_stream(struct bt_audio_stream *stream,
289289
return 0;
290290
}
291291

292-
static size_t codec_configure_streams(void)
292+
static void codec_configure_streams(size_t stream_cnt)
293293
{
294-
size_t stream_cnt;
295-
296-
for (stream_cnt = 0; stream_cnt < ARRAY_SIZE(g_sinks); stream_cnt++) {
297-
struct bt_audio_stream *stream = &g_streams[stream_cnt];
294+
for (size_t i = 0U; i < stream_cnt; i++) {
295+
struct bt_audio_stream *stream = &g_streams[i];
298296
int err;
299297

300-
if (g_sinks[stream_cnt] == NULL) {
298+
if (g_sinks[i] == NULL) {
301299
break;
302300
}
303301

304-
err = codec_configure_stream(stream, g_sinks[stream_cnt]);
302+
err = codec_configure_stream(stream, g_sinks[i]);
305303
if (err != 0) {
306-
FAIL("Unable to configure stream[%zu]: %d",
307-
stream_cnt, err);
308-
return 0;
304+
FAIL("Unable to configure stream[%zu]: %d", i, err);
305+
return;
309306
}
310307
}
311-
312-
return stream_cnt;
313308
}
314309

315310
static void qos_configure_streams(struct bt_audio_unicast_group *unicast_group,
@@ -389,19 +384,31 @@ static size_t release_streams(size_t stream_cnt)
389384
}
390385

391386

392-
static void create_unicast_group(struct bt_audio_unicast_group **unicast_group)
387+
static size_t create_unicast_group(struct bt_audio_unicast_group **unicast_group)
393388
{
394-
const size_t stream_cnt = ARRAY_SIZE(g_streams);
395-
struct bt_audio_unicast_group_stream_pair_param pair_params[stream_cnt];
396-
struct bt_audio_unicast_group_stream_param stream_params[stream_cnt];
389+
struct bt_audio_unicast_group_stream_pair_param pair_params[ARRAY_SIZE(g_streams)];
390+
struct bt_audio_unicast_group_stream_param stream_params[ARRAY_SIZE(g_streams)];
397391
struct bt_audio_unicast_group_param param;
392+
size_t stream_cnt = 0;
398393
int err;
399394

400-
for (size_t i = 0U; i < stream_cnt; i++) {
401-
stream_params[i].stream = &g_streams[i];
402-
stream_params[i].qos = &preset_16_2_1.qos;
403-
pair_params[i].rx_param = NULL;
404-
pair_params[i].tx_param = &stream_params[i];
395+
for (stream_cnt = 0U;
396+
stream_cnt < MIN(ARRAY_SIZE(g_sinks), ARRAY_SIZE(g_streams));
397+
stream_cnt++) {
398+
if (g_sinks[stream_cnt] == NULL) {
399+
break;
400+
}
401+
402+
stream_params[stream_cnt].stream = &g_streams[stream_cnt];
403+
stream_params[stream_cnt].qos = &preset_16_2_1.qos;
404+
pair_params[stream_cnt].rx_param = NULL;
405+
pair_params[stream_cnt].tx_param = &stream_params[stream_cnt];
406+
}
407+
408+
if (stream_cnt == 0U) {
409+
FAIL("No streams added to group");
410+
411+
return 0;
405412
}
406413

407414
param.params = pair_params;
@@ -413,8 +420,11 @@ static void create_unicast_group(struct bt_audio_unicast_group **unicast_group)
413420
err = bt_audio_unicast_group_create(&param, unicast_group);
414421
if (err != 0) {
415422
FAIL("Unable to create unicast group: %d", err);
416-
return;
423+
424+
return 0;
417425
}
426+
427+
return stream_cnt;
418428
}
419429

420430
static void delete_unicast_group(struct bt_audio_unicast_group *unicast_group)
@@ -432,8 +442,6 @@ static void delete_unicast_group(struct bt_audio_unicast_group *unicast_group)
432442
static void test_main(void)
433443
{
434444
const unsigned int iterations = 3;
435-
struct bt_audio_unicast_group *unicast_group;
436-
size_t stream_cnt;
437445

438446
init();
439447

@@ -447,13 +455,16 @@ static void test_main(void)
447455
* set and reset
448456
*/
449457
for (unsigned int i = 0U; i < iterations; i++) {
458+
struct bt_audio_unicast_group *unicast_group;
459+
size_t stream_cnt;
460+
450461
printk("\n########### Running iteration #%u\n\n", i);
451462

452463
printk("Creating unicast group\n");
453-
create_unicast_group(&unicast_group);
464+
stream_cnt = create_unicast_group(&unicast_group);
454465

455466
printk("Codec configuring streams\n");
456-
stream_cnt = codec_configure_streams();
467+
codec_configure_streams(stream_cnt);
457468

458469
printk("QoS configuring streams\n");
459470
qos_configure_streams(unicast_group, stream_cnt);

0 commit comments

Comments
 (0)