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

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

@ -3,9 +3,11 @@ @@ -3,9 +3,11 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <zephyr/autoconf.h>
@ -48,6 +50,8 @@ static uint8_t bis_codec_data[] = { @@ -48,6 +50,8 @@ static uint8_t bis_codec_data[] = {
BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_CHAN_ALLOC,
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_stopped, 0U, ARRAY_SIZE(broadcast_source_streams));
@ -251,13 +255,21 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool @@ -251,13 +255,21 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool
stream_params[ARRAY_SIZE(broadcast_source_streams)];
struct bt_bap_broadcast_source_subgroup_param
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;
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,
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 =
bap_stream_from_audio_test_stream(&broadcast_source_streams[i]);
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 @@ -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 */
}
for (size_t i = 0U; i < ARRAY_SIZE(subgroup_params); i++) {
subgroup_params[i].params_count = ARRAY_SIZE(stream_params);
subgroup_params[i].params = &stream_params[i];
for (size_t i = 0U; i < subgroup_cnt_arg; i++) {
subgroup_params[i].params_count = streams_per_subgroup_cnt_arg;
subgroup_params[i].params = &stream_params[i * streams_per_subgroup_cnt_arg];
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.qos = &preset_16_2_1.qos;
create_param.packing = BT_ISO_PACKING_SEQUENTIAL;
@ -283,15 +295,15 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source, bool @@ -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));
}
printk("Creating broadcast source with %zu subgroups and %zu streams\n",
ARRAY_SIZE(subgroup_params), ARRAY_SIZE(stream_params));
printk("Creating broadcast source with %lu subgroups and %lu streams\n", subgroup_cnt_arg,
stream_cnt);
err = bt_bap_broadcast_source_create(&create_param, source);
if (err != 0) {
printk("Unable to create broadcast source: %d\n", 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];
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 @@ -393,23 +405,24 @@ static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *sourc
stream_params[ARRAY_SIZE(broadcast_source_streams)];
struct bt_bap_broadcast_source_subgroup_param
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;
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 =
bap_stream_from_audio_test_stream(&broadcast_source_streams[i]);
stream_params[i].data_len = ARRAY_SIZE(bis_codec_data);
stream_params[i].data = bis_codec_data;
}
for (size_t i = 0U; i < ARRAY_SIZE(subgroup_params); i++) {
subgroup_params[i].params_count = 1U;
subgroup_params[i].params = &stream_params[i];
for (size_t i = 0U; i < subgroup_cnt_arg; i++) {
subgroup_params[i].params_count = streams_per_subgroup_cnt_arg;
subgroup_params[i].params = &stream_params[i * streams_per_subgroup_cnt_arg];
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.qos = &preset_16_1_1.qos;
reconfig_param.packing = BT_ISO_PACKING_SEQUENTIAL;
@ -422,7 +435,7 @@ static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *sourc @@ -422,7 +435,7 @@ static void test_broadcast_source_reconfig(struct bt_bap_broadcast_source *sourc
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];
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 @@ -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,
struct bt_le_ext_adv *adv)
{
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
int err;
printk("Starting broadcast source\n");
@ -442,8 +456,8 @@ static void test_broadcast_source_start(struct bt_bap_broadcast_source *source, @@ -442,8 +456,8 @@ static void test_broadcast_source_start(struct bt_bap_broadcast_source *source,
}
/* Wait for all to be started */
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(broadcast_source_streams));
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) {
printk("Waiting for %lu streams to be started\n", stream_cnt);
for (size_t i = 0U; i < stream_cnt; i++) {
k_sem_take(&sem_stream_started, K_FOREVER);
}
@ -482,6 +496,7 @@ static void test_broadcast_source_update_metadata(struct bt_bap_broadcast_source @@ -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)
{
const unsigned long stream_cnt = subgroup_cnt_arg * streams_per_subgroup_cnt_arg;
int err;
printk("Stopping broadcast source\n");
@ -493,8 +508,8 @@ static void test_broadcast_source_stop(struct bt_bap_broadcast_source *source) @@ -493,8 +508,8 @@ static void test_broadcast_source_stop(struct bt_bap_broadcast_source *source)
}
/* Wait for all to be stopped */
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(broadcast_source_streams));
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) {
printk("Waiting for %lu streams to be stopped\n", stream_cnt);
for (size_t i = 0U; i < stream_cnt; i++) {
k_sem_take(&sem_stream_stopped, K_FOREVER);
}
@ -669,18 +684,48 @@ static void test_main_encrypted(void) @@ -669,18 +684,48 @@ static void test_main_encrypted(void)
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[] = {
{
.test_id = "broadcast_source",
.test_pre_init_f = test_init,
.test_tick_f = test_tick,
.test_main_f = test_main,
.test_args_f = test_args,
},
{
.test_id = "broadcast_source_encrypted",
.test_pre_init_f = test_init,
.test_tick_f = test_tick,
.test_main_f = test_main_encrypted,
.test_args_f = test_args,
},
BSTEST_END_MARKER,
};

Loading…
Cancel
Save