Skip to content

Commit 01e8d0e

Browse files
Thalleykartben
authored andcommitted
tests: Bluetooth: BAP: Add subgroup and stream args to broadcast_source
Add subgroup count and streams per subgroup arguments to the broadcast_source test. This will allow us to run multiple test setups using the same build and test case. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 0d933f4 commit 01e8d0e

File tree

2 files changed

+80
-32
lines changed

2 files changed

+80
-32
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ CREATE_FLAG(flag_big_sync_mic_failure);
5151
CREATE_FLAG(flag_sink_started);
5252

5353
static struct bt_bap_broadcast_sink *g_sink;
54+
static size_t stream_sync_cnt;
5455
static struct bt_le_scan_recv_info broadcaster_info;
5556
static bt_addr_le_t broadcaster_addr;
5657
static struct bt_le_per_adv_sync *pa_sync;
@@ -759,6 +760,8 @@ static void test_broadcast_sync(const uint8_t broadcast_code[BT_ISO_BROADCAST_CO
759760
FAIL("Unable to sync the sink: %d\n", err);
760761
return;
761762
}
763+
764+
stream_sync_cnt = POPCOUNT(bis_index_bitfield);
762765
}
763766

764767
static void test_broadcast_sync_inval(void)
@@ -833,8 +836,8 @@ static void test_broadcast_stop(void)
833836
return;
834837
}
835838

836-
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(streams));
837-
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
839+
printk("Waiting for %zu streams to be stopped\n", stream_sync_cnt);
840+
for (size_t i = 0U; i < stream_sync_cnt; i++) {
838841
k_sem_take(&sem_stream_stopped, K_FOREVER);
839842
}
840843

@@ -938,8 +941,8 @@ static void test_common(void)
938941
WAIT_FOR_FLAG(flag_sink_started);
939942

940943
/* Wait for all to be started */
941-
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams));
942-
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
944+
printk("Waiting for %zu streams to be started\n", stream_sync_cnt);
945+
for (size_t i = 0U; i < stream_sync_cnt; i++) {
943946
k_sem_take(&sem_stream_started, K_FOREVER);
944947
}
945948

@@ -967,8 +970,8 @@ static void test_main(void)
967970
printk("Waiting for PA disconnected\n");
968971
WAIT_FOR_FLAG(flag_pa_sync_lost);
969972

970-
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(streams));
971-
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
973+
printk("Waiting for %zu streams to be stopped\n", stream_sync_cnt);
974+
for (size_t i = 0U; i < stream_sync_cnt; i++) {
972975
k_sem_take(&sem_stream_stopped, K_FOREVER);
973976
}
974977
WAIT_FOR_UNSET_FLAG(flag_sink_started);
@@ -989,8 +992,8 @@ static void test_sink_disconnect(void)
989992
WAIT_FOR_FLAG(flag_sink_started);
990993

991994
/* Wait for all to be started */
992-
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams));
993-
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
995+
printk("Waiting for %zu streams to be started\n", stream_sync_cnt);
996+
for (size_t i = 0U; i < stream_sync_cnt; i++) {
994997
k_sem_take(&sem_stream_started, K_FOREVER);
995998
}
996999

@@ -1030,8 +1033,8 @@ static void test_sink_encrypted(void)
10301033
WAIT_FOR_FLAG(flag_sink_started);
10311034

10321035
/* Wait for all to be started */
1033-
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams));
1034-
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
1036+
printk("Waiting for %zu streams to be started\n", stream_sync_cnt);
1037+
for (size_t i = 0U; i < stream_sync_cnt; i++) {
10351038
k_sem_take(&sem_stream_started, K_FOREVER);
10361039
}
10371040

@@ -1049,8 +1052,8 @@ static void test_sink_encrypted(void)
10491052
printk("Waiting for PA disconnected\n");
10501053
WAIT_FOR_FLAG(flag_pa_sync_lost);
10511054

1052-
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(streams));
1053-
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
1055+
printk("Waiting for %zu streams to be stopped\n", stream_sync_cnt);
1056+
for (size_t i = 0U; i < stream_sync_cnt; i++) {
10541057
k_sem_take(&sem_stream_stopped, K_FOREVER);
10551058
}
10561059

@@ -1133,8 +1136,8 @@ static void broadcast_sink_with_assistant(void)
11331136
WAIT_FOR_FLAG(flag_sink_started);
11341137

11351138
/* Wait for all to be started */
1136-
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams));
1137-
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
1139+
printk("Waiting for %zu streams to be started\n", stream_sync_cnt);
1140+
for (size_t i = 0U; i < stream_sync_cnt; i++) {
11381141
k_sem_take(&sem_stream_started, K_FOREVER);
11391142
}
11401143

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

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6+
#include <errno.h>
67
#include <stdbool.h>
78
#include <stddef.h>
89
#include <stdint.h>
10+
#include <stdlib.h>
911
#include <string.h>
1012

1113
#include <zephyr/autoconf.h>
@@ -48,6 +50,8 @@ static uint8_t bis_codec_data[] = {
4850
BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_CHAN_ALLOC,
4951
BT_BYTES_LIST_LE32(BT_AUDIO_LOCATION_FRONT_CENTER)),
5052
};
53+
static unsigned long subgroup_cnt_arg = 1;
54+
static unsigned long streams_per_subgroup_cnt_arg = 1;
5155

5256
static K_SEM_DEFINE(sem_stream_started, 0U, ARRAY_SIZE(broadcast_source_streams));
5357
static K_SEM_DEFINE(sem_stream_stopped, 0U, ARRAY_SIZE(broadcast_source_streams));
@@ -251,13 +255,21 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool
251255
stream_params[ARRAY_SIZE(broadcast_source_streams)];
252256
struct bt_bap_broadcast_source_subgroup_param
253257
subgroup_params[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT];
258+
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
254259
struct bt_bap_broadcast_source_param create_param;
255260
int err;
256261

262+
if (stream_cnt > ARRAY_SIZE(stream_params)) {
263+
printk("Unable to create broadcast source with %lu subgroups with %lu streams each "
264+
"(%lu total)\n",
265+
subgroup_cnt_arg, streams_per_subgroup_cnt_arg, stream_cnt);
266+
return -ENOMEM;
267+
}
268+
257269
(void)memset(broadcast_source_streams, 0,
258270
sizeof(broadcast_source_streams));
259271

260-
for (size_t i = 0; i < ARRAY_SIZE(stream_params); i++) {
272+
for (size_t i = 0; i < stream_cnt; i++) {
261273
stream_params[i].stream =
262274
bap_stream_from_audio_test_stream(&broadcast_source_streams[i]);
263275
bt_bap_stream_cb_register(stream_params[i].stream,
@@ -268,13 +280,13 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool
268280
#endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */
269281
}
270282

271-
for (size_t i = 0U; i < ARRAY_SIZE(subgroup_params); i++) {
272-
subgroup_params[i].params_count = ARRAY_SIZE(stream_params);
273-
subgroup_params[i].params = &stream_params[i];
283+
for (size_t i = 0U; i < subgroup_cnt_arg; i++) {
284+
subgroup_params[i].params_count = streams_per_subgroup_cnt_arg;
285+
subgroup_params[i].params = &stream_params[i * streams_per_subgroup_cnt_arg];
274286
subgroup_params[i].codec_cfg = &preset_16_1_1.codec_cfg;
275287
}
276288

277-
create_param.params_count = ARRAY_SIZE(subgroup_params);
289+
create_param.params_count = subgroup_cnt_arg;
278290
create_param.params = subgroup_params;
279291
create_param.qos = &preset_16_2_1.qos;
280292
create_param.packing = BT_ISO_PACKING_SEQUENTIAL;
@@ -283,15 +295,15 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool
283295
memcpy(create_param.broadcast_code, BROADCAST_CODE, sizeof(BROADCAST_CODE));
284296
}
285297

286-
printk("Creating broadcast source with %zu subgroups and %zu streams\n",
287-
ARRAY_SIZE(subgroup_params), ARRAY_SIZE(stream_params));
298+
printk("Creating broadcast source with %lu subgroups and %lu streams\n", subgroup_cnt_arg,
299+
stream_cnt);
288300
err = bt_bap_broadcast_source_create(&create_param, source);
289301
if (err != 0) {
290302
printk("Unable to create broadcast source: %d\n", err);
291303
return err;
292304
}
293305

294-
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) {
306+
for (size_t i = 0U; i < stream_cnt; i++) {
295307
struct audio_test_stream *test_stream = &broadcast_source_streams[i];
296308

297309
test_stream->tx_sdu_size = preset_16_1_1.qos.sdu;
@@ -393,23 +405,24 @@ static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *sourc
393405
stream_params[ARRAY_SIZE(broadcast_source_streams)];
394406
struct bt_bap_broadcast_source_subgroup_param
395407
subgroup_params[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT];
408+
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
396409
struct bt_bap_broadcast_source_param reconfig_param;
397410
int err;
398411

399-
for (size_t i = 0; i < ARRAY_SIZE(stream_params); i++) {
412+
for (size_t i = 0; i < stream_cnt; i++) {
400413
stream_params[i].stream =
401414
bap_stream_from_audio_test_stream(&broadcast_source_streams[i]);
402415
stream_params[i].data_len = ARRAY_SIZE(bis_codec_data);
403416
stream_params[i].data = bis_codec_data;
404417
}
405418

406-
for (size_t i = 0U; i < ARRAY_SIZE(subgroup_params); i++) {
407-
subgroup_params[i].params_count = 1U;
408-
subgroup_params[i].params = &stream_params[i];
419+
for (size_t i = 0U; i < subgroup_cnt_arg; i++) {
420+
subgroup_params[i].params_count = streams_per_subgroup_cnt_arg;
421+
subgroup_params[i].params = &stream_params[i * streams_per_subgroup_cnt_arg];
409422
subgroup_params[i].codec_cfg = &preset_16_1_1.codec_cfg;
410423
}
411424

412-
reconfig_param.params_count = ARRAY_SIZE(subgroup_params);
425+
reconfig_param.params_count = subgroup_cnt_arg;
413426
reconfig_param.params = subgroup_params;
414427
reconfig_param.qos = &preset_16_1_1.qos;
415428
reconfig_param.packing = BT_ISO_PACKING_SEQUENTIAL;
@@ -422,7 +435,7 @@ static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *sourc
422435
return;
423436
}
424437

425-
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) {
438+
for (size_t i = 0U; i < stream_cnt; i++) {
426439
struct audio_test_stream *test_stream = &broadcast_source_streams[i];
427440

428441
test_stream->tx_sdu_size = preset_16_1_1.qos.sdu;
@@ -432,6 +445,7 @@ static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *sourc
432445
static void test_broadcast_source_start(struct bt_bap_broadcast_source *source,
433446
struct bt_le_ext_adv *adv)
434447
{
448+
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
435449
int err;
436450

437451
printk("Starting broadcast source\n");
@@ -442,8 +456,8 @@ static void test_broadcast_source_start(struct bt_bap_broadcast_source *source,
442456
}
443457

444458
/* Wait for all to be started */
445-
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(broadcast_source_streams));
446-
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) {
459+
printk("Waiting for %lu streams to be started\n", stream_cnt);
460+
for (size_t i = 0U; i < stream_cnt; i++) {
447461
k_sem_take(&sem_stream_started, K_FOREVER);
448462
}
449463

@@ -482,6 +496,7 @@ static void test_broadcast_source_update_metadata(struct bt_bap_broadcast_source
482496

483497
static void test_broadcast_source_stop(struct bt_bap_broadcast_source *source)
484498
{
499+
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
485500
int err;
486501

487502
printk("Stopping broadcast source\n");
@@ -493,8 +508,8 @@ static void test_broadcast_source_stop(struct bt_bap_broadcast_source *source)
493508
}
494509

495510
/* Wait for all to be stopped */
496-
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(broadcast_source_streams));
497-
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) {
511+
printk("Waiting for %lu streams to be stopped\n", stream_cnt);
512+
for (size_t i = 0U; i < stream_cnt; i++) {
498513
k_sem_take(&sem_stream_stopped, K_FOREVER);
499514
}
500515

@@ -669,18 +684,48 @@ static void test_main_encrypted(void)
669684
PASS("Broadcast source encrypted passed\n");
670685
}
671686

687+
static void test_args(int argc, char *argv[])
688+
{
689+
for (size_t argn = 0; argn < argc; argn++) {
690+
const char *arg = argv[argn];
691+
692+
if (strcmp(arg, "subgroup_cnt") == 0) {
693+
arg = argv[++argn];
694+
subgroup_cnt_arg = strtoul(arg, NULL, 10);
695+
696+
if (!IN_RANGE(subgroup_cnt_arg, 1,
697+
CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT)) {
698+
FAIL("Invalid number of subgroups: %lu\n", subgroup_cnt_arg);
699+
}
700+
} else if (strcmp(arg, "streams_per_subgroup_cnt") == 0) {
701+
arg = argv[++argn];
702+
streams_per_subgroup_cnt_arg = strtoul(arg, NULL, 10);
703+
704+
if (!IN_RANGE(streams_per_subgroup_cnt_arg, 1,
705+
CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT)) {
706+
FAIL("Invalid number of streams per subgroup: %lu\n",
707+
streams_per_subgroup_cnt_arg);
708+
}
709+
} else {
710+
FAIL("Invalid arg: %s\n", arg);
711+
}
712+
}
713+
}
714+
672715
static const struct bst_test_instance test_broadcast_source[] = {
673716
{
674717
.test_id = "broadcast_source",
675718
.test_pre_init_f = test_init,
676719
.test_tick_f = test_tick,
677720
.test_main_f = test_main,
721+
.test_args_f = test_args,
678722
},
679723
{
680724
.test_id = "broadcast_source_encrypted",
681725
.test_pre_init_f = test_init,
682726
.test_tick_f = test_tick,
683727
.test_main_f = test_main_encrypted,
728+
.test_args_f = test_args,
684729
},
685730
BSTEST_END_MARKER,
686731
};

0 commit comments

Comments
 (0)