@ -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 %z u streams \n " ,
ARRAY_SIZE ( subgroup_params ) , ARRAY_SIZE ( stream_params ) ) ;
printk ( " Creating broadcast source with %lu subgroups and %l u 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 %z u 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 %l u 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 %z u 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 %l u 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 ,
} ;