Browse Source

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 <emil.gydesen@nordicsemi.no>
pull/83425/head
Emil Gydesen 7 months ago committed by Benjamin Cabé
parent
commit
01e8d0e3e0
  1. 31
      tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c
  2. 81
      tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c

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

@ -51,6 +51,7 @@ CREATE_FLAG(flag_big_sync_mic_failure);
CREATE_FLAG(flag_sink_started); CREATE_FLAG(flag_sink_started);
static struct bt_bap_broadcast_sink *g_sink; static struct bt_bap_broadcast_sink *g_sink;
static size_t stream_sync_cnt;
static struct bt_le_scan_recv_info broadcaster_info; static struct bt_le_scan_recv_info broadcaster_info;
static bt_addr_le_t broadcaster_addr; static bt_addr_le_t broadcaster_addr;
static struct bt_le_per_adv_sync *pa_sync; 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
FAIL("Unable to sync the sink: %d\n", err); FAIL("Unable to sync the sink: %d\n", err);
return; return;
} }
stream_sync_cnt = POPCOUNT(bis_index_bitfield);
} }
static void test_broadcast_sync_inval(void) static void test_broadcast_sync_inval(void)
@ -833,8 +836,8 @@ static void test_broadcast_stop(void)
return; return;
} }
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(streams)); printk("Waiting for %zu streams to be stopped\n", stream_sync_cnt);
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { for (size_t i = 0U; i < stream_sync_cnt; i++) {
k_sem_take(&sem_stream_stopped, K_FOREVER); k_sem_take(&sem_stream_stopped, K_FOREVER);
} }
@ -938,8 +941,8 @@ static void test_common(void)
WAIT_FOR_FLAG(flag_sink_started); WAIT_FOR_FLAG(flag_sink_started);
/* Wait for all to be started */ /* Wait for all to be started */
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams)); printk("Waiting for %zu streams to be started\n", stream_sync_cnt);
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { for (size_t i = 0U; i < stream_sync_cnt; i++) {
k_sem_take(&sem_stream_started, K_FOREVER); k_sem_take(&sem_stream_started, K_FOREVER);
} }
@ -967,8 +970,8 @@ static void test_main(void)
printk("Waiting for PA disconnected\n"); printk("Waiting for PA disconnected\n");
WAIT_FOR_FLAG(flag_pa_sync_lost); WAIT_FOR_FLAG(flag_pa_sync_lost);
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(streams)); printk("Waiting for %zu streams to be stopped\n", stream_sync_cnt);
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { for (size_t i = 0U; i < stream_sync_cnt; i++) {
k_sem_take(&sem_stream_stopped, K_FOREVER); k_sem_take(&sem_stream_stopped, K_FOREVER);
} }
WAIT_FOR_UNSET_FLAG(flag_sink_started); WAIT_FOR_UNSET_FLAG(flag_sink_started);
@ -989,8 +992,8 @@ static void test_sink_disconnect(void)
WAIT_FOR_FLAG(flag_sink_started); WAIT_FOR_FLAG(flag_sink_started);
/* Wait for all to be started */ /* Wait for all to be started */
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams)); printk("Waiting for %zu streams to be started\n", stream_sync_cnt);
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { for (size_t i = 0U; i < stream_sync_cnt; i++) {
k_sem_take(&sem_stream_started, K_FOREVER); k_sem_take(&sem_stream_started, K_FOREVER);
} }
@ -1030,8 +1033,8 @@ static void test_sink_encrypted(void)
WAIT_FOR_FLAG(flag_sink_started); WAIT_FOR_FLAG(flag_sink_started);
/* Wait for all to be started */ /* Wait for all to be started */
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams)); printk("Waiting for %zu streams to be started\n", stream_sync_cnt);
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { for (size_t i = 0U; i < stream_sync_cnt; i++) {
k_sem_take(&sem_stream_started, K_FOREVER); k_sem_take(&sem_stream_started, K_FOREVER);
} }
@ -1049,8 +1052,8 @@ static void test_sink_encrypted(void)
printk("Waiting for PA disconnected\n"); printk("Waiting for PA disconnected\n");
WAIT_FOR_FLAG(flag_pa_sync_lost); WAIT_FOR_FLAG(flag_pa_sync_lost);
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(streams)); printk("Waiting for %zu streams to be stopped\n", stream_sync_cnt);
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { for (size_t i = 0U; i < stream_sync_cnt; i++) {
k_sem_take(&sem_stream_stopped, K_FOREVER); k_sem_take(&sem_stream_stopped, K_FOREVER);
} }
@ -1133,8 +1136,8 @@ static void broadcast_sink_with_assistant(void)
WAIT_FOR_FLAG(flag_sink_started); WAIT_FOR_FLAG(flag_sink_started);
/* Wait for all to be started */ /* Wait for all to be started */
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams)); printk("Waiting for %zu streams to be started\n", stream_sync_cnt);
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { for (size_t i = 0U; i < stream_sync_cnt; i++) {
k_sem_take(&sem_stream_started, K_FOREVER); k_sem_take(&sem_stream_started, K_FOREVER);
} }

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

@ -3,9 +3,11 @@
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <errno.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <zephyr/autoconf.h> #include <zephyr/autoconf.h>
@ -48,6 +50,8 @@ static uint8_t bis_codec_data[] = {
BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_CHAN_ALLOC, BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_CHAN_ALLOC,
BT_BYTES_LIST_LE32(BT_AUDIO_LOCATION_FRONT_CENTER)), BT_BYTES_LIST_LE32(BT_AUDIO_LOCATION_FRONT_CENTER)),
}; };
static unsigned long subgroup_cnt_arg = 1;
static unsigned long streams_per_subgroup_cnt_arg = 1;
static K_SEM_DEFINE(sem_stream_started, 0U, ARRAY_SIZE(broadcast_source_streams)); static K_SEM_DEFINE(sem_stream_started, 0U, ARRAY_SIZE(broadcast_source_streams));
static K_SEM_DEFINE(sem_stream_stopped, 0U, ARRAY_SIZE(broadcast_source_streams)); 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
stream_params[ARRAY_SIZE(broadcast_source_streams)]; stream_params[ARRAY_SIZE(broadcast_source_streams)];
struct bt_bap_broadcast_source_subgroup_param struct bt_bap_broadcast_source_subgroup_param
subgroup_params[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT]; subgroup_params[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT];
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
struct bt_bap_broadcast_source_param create_param; struct bt_bap_broadcast_source_param create_param;
int err; int err;
if (stream_cnt > ARRAY_SIZE(stream_params)) {
printk("Unable to create broadcast source with %lu subgroups with %lu streams each "
"(%lu total)\n",
subgroup_cnt_arg, streams_per_subgroup_cnt_arg, stream_cnt);
return -ENOMEM;
}
(void)memset(broadcast_source_streams, 0, (void)memset(broadcast_source_streams, 0,
sizeof(broadcast_source_streams)); sizeof(broadcast_source_streams));
for (size_t i = 0; i < ARRAY_SIZE(stream_params); i++) { for (size_t i = 0; i < stream_cnt; i++) {
stream_params[i].stream = stream_params[i].stream =
bap_stream_from_audio_test_stream(&broadcast_source_streams[i]); bap_stream_from_audio_test_stream(&broadcast_source_streams[i]);
bt_bap_stream_cb_register(stream_params[i].stream, 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
#endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */ #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */
} }
for (size_t i = 0U; i < ARRAY_SIZE(subgroup_params); i++) { for (size_t i = 0U; i < subgroup_cnt_arg; i++) {
subgroup_params[i].params_count = ARRAY_SIZE(stream_params); subgroup_params[i].params_count = streams_per_subgroup_cnt_arg;
subgroup_params[i].params = &stream_params[i]; subgroup_params[i].params = &stream_params[i * streams_per_subgroup_cnt_arg];
subgroup_params[i].codec_cfg = &preset_16_1_1.codec_cfg; subgroup_params[i].codec_cfg = &preset_16_1_1.codec_cfg;
} }
create_param.params_count = ARRAY_SIZE(subgroup_params); create_param.params_count = subgroup_cnt_arg;
create_param.params = subgroup_params; create_param.params = subgroup_params;
create_param.qos = &preset_16_2_1.qos; create_param.qos = &preset_16_2_1.qos;
create_param.packing = BT_ISO_PACKING_SEQUENTIAL; create_param.packing = BT_ISO_PACKING_SEQUENTIAL;
@ -283,15 +295,15 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool
memcpy(create_param.broadcast_code, BROADCAST_CODE, sizeof(BROADCAST_CODE)); memcpy(create_param.broadcast_code, BROADCAST_CODE, sizeof(BROADCAST_CODE));
} }
printk("Creating broadcast source with %zu subgroups and %zu streams\n", printk("Creating broadcast source with %lu subgroups and %lu streams\n", subgroup_cnt_arg,
ARRAY_SIZE(subgroup_params), ARRAY_SIZE(stream_params)); stream_cnt);
err = bt_bap_broadcast_source_create(&create_param, source); err = bt_bap_broadcast_source_create(&create_param, source);
if (err != 0) { if (err != 0) {
printk("Unable to create broadcast source: %d\n", err); printk("Unable to create broadcast source: %d\n", err);
return err; return err;
} }
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) { for (size_t i = 0U; i < stream_cnt; i++) {
struct audio_test_stream *test_stream = &broadcast_source_streams[i]; struct audio_test_stream *test_stream = &broadcast_source_streams[i];
test_stream->tx_sdu_size = preset_16_1_1.qos.sdu; 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
stream_params[ARRAY_SIZE(broadcast_source_streams)]; stream_params[ARRAY_SIZE(broadcast_source_streams)];
struct bt_bap_broadcast_source_subgroup_param struct bt_bap_broadcast_source_subgroup_param
subgroup_params[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT]; subgroup_params[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT];
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
struct bt_bap_broadcast_source_param reconfig_param; struct bt_bap_broadcast_source_param reconfig_param;
int err; int err;
for (size_t i = 0; i < ARRAY_SIZE(stream_params); i++) { for (size_t i = 0; i < stream_cnt; i++) {
stream_params[i].stream = stream_params[i].stream =
bap_stream_from_audio_test_stream(&broadcast_source_streams[i]); bap_stream_from_audio_test_stream(&broadcast_source_streams[i]);
stream_params[i].data_len = ARRAY_SIZE(bis_codec_data); stream_params[i].data_len = ARRAY_SIZE(bis_codec_data);
stream_params[i].data = bis_codec_data; stream_params[i].data = bis_codec_data;
} }
for (size_t i = 0U; i < ARRAY_SIZE(subgroup_params); i++) { for (size_t i = 0U; i < subgroup_cnt_arg; i++) {
subgroup_params[i].params_count = 1U; subgroup_params[i].params_count = streams_per_subgroup_cnt_arg;
subgroup_params[i].params = &stream_params[i]; subgroup_params[i].params = &stream_params[i * streams_per_subgroup_cnt_arg];
subgroup_params[i].codec_cfg = &preset_16_1_1.codec_cfg; subgroup_params[i].codec_cfg = &preset_16_1_1.codec_cfg;
} }
reconfig_param.params_count = ARRAY_SIZE(subgroup_params); reconfig_param.params_count = subgroup_cnt_arg;
reconfig_param.params = subgroup_params; reconfig_param.params = subgroup_params;
reconfig_param.qos = &preset_16_1_1.qos; reconfig_param.qos = &preset_16_1_1.qos;
reconfig_param.packing = BT_ISO_PACKING_SEQUENTIAL; reconfig_param.packing = BT_ISO_PACKING_SEQUENTIAL;
@ -422,7 +435,7 @@ static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *sourc
return; return;
} }
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) { for (size_t i = 0U; i < stream_cnt; i++) {
struct audio_test_stream *test_stream = &broadcast_source_streams[i]; struct audio_test_stream *test_stream = &broadcast_source_streams[i];
test_stream->tx_sdu_size = preset_16_1_1.qos.sdu; 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
static void test_broadcast_source_start(struct bt_bap_broadcast_source *source, static void test_broadcast_source_start(struct bt_bap_broadcast_source *source,
struct bt_le_ext_adv *adv) struct bt_le_ext_adv *adv)
{ {
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
int err; int err;
printk("Starting broadcast source\n"); printk("Starting broadcast source\n");
@ -442,8 +456,8 @@ static void test_broadcast_source_start(struct bt_bap_broadcast_source *source,
} }
/* Wait for all to be started */ /* Wait for all to be started */
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(broadcast_source_streams)); printk("Waiting for %lu streams to be started\n", stream_cnt);
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) { for (size_t i = 0U; i < stream_cnt; i++) {
k_sem_take(&sem_stream_started, K_FOREVER); k_sem_take(&sem_stream_started, K_FOREVER);
} }
@ -482,6 +496,7 @@ static void test_broadcast_source_update_metadata(struct bt_bap_broadcast_source
static void test_broadcast_source_stop(struct bt_bap_broadcast_source *source) static void test_broadcast_source_stop(struct bt_bap_broadcast_source *source)
{ {
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
int err; int err;
printk("Stopping broadcast source\n"); printk("Stopping broadcast source\n");
@ -493,8 +508,8 @@ static void test_broadcast_source_stop(struct bt_bap_broadcast_source *source)
} }
/* Wait for all to be stopped */ /* Wait for all to be stopped */
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(broadcast_source_streams)); printk("Waiting for %lu streams to be stopped\n", stream_cnt);
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) { for (size_t i = 0U; i < stream_cnt; i++) {
k_sem_take(&sem_stream_stopped, K_FOREVER); k_sem_take(&sem_stream_stopped, K_FOREVER);
} }
@ -669,18 +684,48 @@ static void test_main_encrypted(void)
PASS("Broadcast source encrypted passed\n"); PASS("Broadcast source encrypted passed\n");
} }
static void test_args(int argc, char *argv[])
{
for (size_t argn = 0; argn < argc; argn++) {
const char *arg = argv[argn];
if (strcmp(arg, "subgroup_cnt") == 0) {
arg = argv[++argn];
subgroup_cnt_arg = strtoul(arg, NULL, 10);
if (!IN_RANGE(subgroup_cnt_arg, 1,
CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT)) {
FAIL("Invalid number of subgroups: %lu\n", subgroup_cnt_arg);
}
} else if (strcmp(arg, "streams_per_subgroup_cnt") == 0) {
arg = argv[++argn];
streams_per_subgroup_cnt_arg = strtoul(arg, NULL, 10);
if (!IN_RANGE(streams_per_subgroup_cnt_arg, 1,
CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT)) {
FAIL("Invalid number of streams per subgroup: %lu\n",
streams_per_subgroup_cnt_arg);
}
} else {
FAIL("Invalid arg: %s\n", arg);
}
}
}
static const struct bst_test_instance test_broadcast_source[] = { static const struct bst_test_instance test_broadcast_source[] = {
{ {
.test_id = "broadcast_source", .test_id = "broadcast_source",
.test_pre_init_f = test_init, .test_pre_init_f = test_init,
.test_tick_f = test_tick, .test_tick_f = test_tick,
.test_main_f = test_main, .test_main_f = test_main,
.test_args_f = test_args,
}, },
{ {
.test_id = "broadcast_source_encrypted", .test_id = "broadcast_source_encrypted",
.test_pre_init_f = test_init, .test_pre_init_f = test_init,
.test_tick_f = test_tick, .test_tick_f = test_tick,
.test_main_f = test_main_encrypted, .test_main_f = test_main_encrypted,
.test_args_f = test_args,
}, },
BSTEST_END_MARKER, BSTEST_END_MARKER,
}; };

Loading…
Cancel
Save