@@ -205,7 +205,7 @@ static int init(void)
205205 return 0 ;
206206}
207207
208- static void test_main (void )
208+ static void test_common (void )
209209{
210210 int err ;
211211
@@ -253,6 +253,12 @@ static void test_main(void)
253253 printk ("Waiting for metadata update\n" );
254254 WAIT_FOR_FLAG (flag_base_metadata_updated )
255255
256+ }
257+
258+ static void test_main (void )
259+ {
260+ test_common ();
261+
256262 /* The order of PA sync lost and BIG Sync lost is irrelevant
257263 * and depend on timeout parameters. We just wait for PA first, but
258264 * either way will work.
@@ -272,48 +278,7 @@ static void test_sink_disconnect(void)
272278{
273279 int err ;
274280
275- err = init ();
276- if (err ) {
277- FAIL ("Init failed (err %d)\n" , err );
278- return ;
279- }
280-
281- printk ("Scanning for broadcast sources\n" );
282- err = bt_audio_broadcast_sink_scan_start (BT_LE_SCAN_ACTIVE );
283- if (err != 0 ) {
284- FAIL ("Unable to start scan for broadcast sources: %d" , err );
285- return ;
286- }
287- WAIT_FOR_FLAG (broadcaster_found );
288- printk ("Broadcast source found, waiting for PA sync\n" );
289- WAIT_FOR_FLAG (pa_synced );
290- printk ("Broadcast source PA synced, waiting for BASE\n" );
291- WAIT_FOR_FLAG (base_received );
292- printk ("BASE received\n" );
293-
294- printk ("Waiting for BIG syncable\n" );
295- WAIT_FOR_FLAG (flag_syncable );
296-
297- printk ("Syncing the sink\n" );
298- /* TODO: Sync to max streams instead of just BIT(1) */
299- err = bt_audio_broadcast_sink_sync (g_sink , BIT (1 ), streams , NULL );
300- if (err != 0 ) {
301- FAIL ("Unable to sync the sink: %d\n" , err );
302- return ;
303- }
304-
305- /* Wait for all to be started */
306- printk ("Waiting for streams to be started\n" );
307- for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
308- k_sem_take (& sem_started , K_FOREVER );
309- }
310-
311- printk ("Waiting for data\n" );
312- WAIT_FOR_FLAG (flag_received );
313-
314- /* Ensure that we also see the metadata update */
315- printk ("Waiting for metadata update\n" );
316- WAIT_FOR_FLAG (flag_base_metadata_updated )
281+ test_common ();
317282
318283 err = bt_audio_broadcast_sink_stop (g_sink );
319284 if (err != 0 ) {
@@ -334,7 +299,7 @@ static void test_sink_disconnect(void)
334299 /* No "sync lost" event is generated when we initialized the disconnect */
335300 g_sink = NULL ;
336301
337- PASS ("Broadcast sink passed\n" );
302+ PASS ("Broadcast sink disconnect passed\n" );
338303}
339304
340305static const struct bst_test_instance test_broadcast_sink [] = {
0 commit comments