Skip to content

Commit b8a9f1f

Browse files
Thalleykartben
authored andcommitted
tests: Bluetooth: CAP: Refactor CAP broadcast tests to multiple tests
The cap_broadcast test has been split into 3 tests: 1) Regular test 2) Regular test with metadata update 3) Test for invalid parameters This will make it easier to use the regular cap_broadcast test for other test cases, as it does less now. It also makes each test run faster seperately and reduce their scopes. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 1148b9a commit b8a9f1f

File tree

8 files changed

+224
-33
lines changed

8 files changed

+224
-33
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,28 @@ static void test_cap_acceptor_broadcast(void)
10531053
PASS("CAP acceptor broadcast passed\n");
10541054
}
10551055

1056+
static void test_cap_acceptor_broadcast_update(void)
1057+
{
1058+
static struct bt_bap_stream *bap_streams[ARRAY_SIZE(broadcast_sink_streams)];
1059+
size_t stream_count;
1060+
1061+
init();
1062+
1063+
pa_sync_to_broadcaster();
1064+
1065+
create_and_sync_sink(bap_streams, &stream_count);
1066+
1067+
sink_wait_for_data();
1068+
1069+
printk("Waiting for metadata update");
1070+
WAIT_FOR_FLAG(flag_base_metadata_updated);
1071+
backchannel_sync_send_all(); /* let other devices know we have received metadata */
1072+
1073+
wait_for_streams_stop(stream_count);
1074+
1075+
PASS("CAP acceptor broadcast passed\n");
1076+
}
1077+
10561078
static void test_cap_acceptor_broadcast_reception(void)
10571079
{
10581080
static struct bt_bap_stream *bap_streams[ARRAY_SIZE(broadcast_sink_streams)];
@@ -1124,6 +1146,12 @@ static const struct bst_test_instance test_cap_acceptor[] = {
11241146
.test_tick_f = test_tick,
11251147
.test_main_f = test_cap_acceptor_broadcast,
11261148
},
1149+
{
1150+
.test_id = "cap_acceptor_broadcast_update",
1151+
.test_pre_init_f = test_init,
1152+
.test_tick_f = test_tick,
1153+
.test_main_f = test_cap_acceptor_broadcast_update,
1154+
},
11271155
{
11281156
.test_id = "cap_acceptor_broadcast_reception",
11291157
.test_pre_init_f = test_init,

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

Lines changed: 104 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022-2024 Nordic Semiconductor ASA
2+
* Copyright (c) 2022-2025 Nordic Semiconductor ASA
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -624,10 +624,8 @@ static void test_main_cap_initiator_broadcast(void)
624624

625625
setup_broadcast_adv(&adv);
626626

627-
test_broadcast_audio_create_inval();
628627
test_broadcast_audio_create(&broadcast_source);
629628

630-
test_broadcast_audio_start_inval(broadcast_source, adv);
631629
test_broadcast_audio_start(broadcast_source, adv);
632630

633631
setup_extended_adv_data(broadcast_source, adv);
@@ -642,17 +640,57 @@ static void test_main_cap_initiator_broadcast(void)
642640

643641
WAIT_FOR_FLAG(flag_source_started);
644642

645-
/* Wait for other devices to have received what they wanted */
643+
/* Wait for other devices to have received the data they wanted */
646644
backchannel_sync_wait_any();
647645

646+
test_broadcast_audio_tx_sync();
647+
648+
test_broadcast_audio_stop(broadcast_source);
649+
650+
test_broadcast_audio_delete(broadcast_source);
651+
broadcast_source = NULL;
652+
653+
stop_and_delete_extended_adv(adv);
654+
adv = NULL;
655+
656+
PASS("CAP initiator broadcast passed\n");
657+
}
658+
659+
static void test_main_cap_initiator_broadcast_inval(void)
660+
{
661+
struct bt_cap_broadcast_source *broadcast_source;
662+
struct bt_le_ext_adv *adv;
663+
664+
(void)memset(broadcast_source_streams, 0, sizeof(broadcast_source_streams));
665+
666+
init();
667+
668+
setup_extended_adv(&adv);
669+
670+
test_broadcast_audio_create_inval();
671+
test_broadcast_audio_create(&broadcast_source);
672+
673+
test_broadcast_audio_start_inval(broadcast_source, adv);
674+
test_broadcast_audio_start(broadcast_source, adv);
675+
676+
setup_extended_adv_data(broadcast_source, adv);
677+
678+
start_extended_adv(adv);
679+
680+
/* Wait for all to be started */
681+
printk("Waiting for broadcast_streams to be started\n");
682+
for (size_t i = 0U; i < stream_count; i++) {
683+
k_sem_take(&sem_broadcast_stream_started, K_FOREVER);
684+
}
685+
686+
WAIT_FOR_FLAG(flag_source_started);
687+
648688
test_broadcast_audio_update_inval(broadcast_source);
649689
test_broadcast_audio_update(broadcast_source);
650690

651691
/* Keeping running for a little while */
652692
k_sleep(K_SECONDS(5));
653693

654-
test_broadcast_audio_tx_sync();
655-
656694
test_broadcast_audio_stop_inval();
657695
test_broadcast_audio_stop(broadcast_source);
658696

@@ -663,6 +701,54 @@ static void test_main_cap_initiator_broadcast(void)
663701
stop_and_delete_extended_adv(adv);
664702
adv = NULL;
665703

704+
PASS("CAP initiator broadcast inval passed\n");
705+
}
706+
707+
static void test_main_cap_initiator_broadcast_update(void)
708+
{
709+
struct bt_cap_broadcast_source *broadcast_source;
710+
struct bt_le_ext_adv *adv;
711+
712+
(void)memset(broadcast_source_streams, 0, sizeof(broadcast_source_streams));
713+
714+
init();
715+
716+
setup_extended_adv(&adv);
717+
718+
test_broadcast_audio_create(&broadcast_source);
719+
720+
test_broadcast_audio_start(broadcast_source, adv);
721+
722+
setup_extended_adv_data(broadcast_source, adv);
723+
724+
start_extended_adv(adv);
725+
726+
/* Wait for all to be started */
727+
printk("Waiting for broadcast_streams to be started\n");
728+
for (size_t i = 0U; i < stream_count; i++) {
729+
k_sem_take(&sem_broadcast_stream_started, K_FOREVER);
730+
}
731+
732+
WAIT_FOR_FLAG(flag_source_started);
733+
734+
/* Wait for other devices to have received the data they wanted */
735+
backchannel_sync_wait_any();
736+
737+
test_broadcast_audio_update(broadcast_source);
738+
739+
/* Wait for other devices to have received the update */
740+
backchannel_sync_wait_any();
741+
742+
test_broadcast_audio_tx_sync();
743+
744+
test_broadcast_audio_stop(broadcast_source);
745+
746+
test_broadcast_audio_delete(broadcast_source);
747+
broadcast_source = NULL;
748+
749+
stop_and_delete_extended_adv(adv);
750+
adv = NULL;
751+
666752
PASS("CAP initiator broadcast passed\n");
667753
}
668754

@@ -829,6 +915,18 @@ static const struct bst_test_instance test_cap_initiator_broadcast[] = {
829915
.test_tick_f = test_tick,
830916
.test_main_f = test_main_cap_initiator_broadcast,
831917
},
918+
{
919+
.test_id = "cap_initiator_broadcast_inval",
920+
.test_pre_init_f = test_init,
921+
.test_tick_f = test_tick,
922+
.test_main_f = test_main_cap_initiator_broadcast_inval,
923+
},
924+
{
925+
.test_id = "cap_initiator_broadcast_update",
926+
.test_pre_init_f = test_init,
927+
.test_tick_f = test_tick,
928+
.test_main_f = test_main_cap_initiator_broadcast_update,
929+
},
832930
{
833931
.test_id = "cap_initiator_ac_12",
834932
.test_pre_init_f = test_init,
Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,12 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2022-2023 Nordic Semiconductor ASA
3+
# Copyright (c) 2022-2025 Nordic Semiconductor ASA
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

77
dir_path=$(dirname "$0")
88

99
set -e # Exit on error
1010

11-
$dir_path/cap_unicast_inval.sh
12-
13-
$dir_path/cap_unicast.sh
14-
15-
$dir_path/cap_broadcast.sh
16-
$dir_path/cap_broadcast_ac_12.sh
17-
$dir_path/cap_broadcast_ac_13.sh
18-
$dir_path/cap_broadcast_ac_14.sh
19-
20-
$dir_path/cap_unicast_ac_1.sh
21-
$dir_path/cap_unicast_ac_2.sh
22-
$dir_path/cap_unicast_ac_3.sh
23-
$dir_path/cap_unicast_ac_4.sh
24-
$dir_path/cap_unicast_ac_5.sh
25-
$dir_path/cap_unicast_ac_6_i.sh
26-
$dir_path/cap_unicast_ac_6_ii.sh
27-
$dir_path/cap_unicast_ac_7_i.sh
28-
$dir_path/cap_unicast_ac_7_ii.sh
29-
$dir_path/cap_unicast_ac_8_i.sh
30-
$dir_path/cap_unicast_ac_8_ii.sh
31-
$dir_path/cap_unicast_ac_9_i.sh
32-
$dir_path/cap_unicast_ac_9_ii.sh
33-
$dir_path/cap_unicast_ac_10.sh
34-
$dir_path/cap_unicast_ac_11_i.sh
35-
$dir_path/cap_unicast_ac_11_ii.sh
11+
$dir_path/_cap_broadcast.sh
12+
$dir_path/_cap_unicast.sh
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2025 Nordic Semiconductor ASA
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
dir_path=$(dirname "$0")
8+
9+
set -e # Exit on error
10+
11+
# Run all cap_broadcast* tests
12+
for file in "$dir_path"/cap_broadcast*.sh; do
13+
if [ -f "$file" ]; then
14+
echo "Running $file"
15+
$file
16+
fi
17+
done
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2025 Nordic Semiconductor ASA
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
dir_path=$(dirname "$0")
8+
9+
set -e # Exit on error
10+
11+
# Run all cap_unicast* tests
12+
for file in "$dir_path"/cap_unicast*.sh; do
13+
if [ -f "$file" ]; then
14+
echo "Running $file"
15+
$file
16+
fi
17+
done
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2025 Nordic Semiconductor ASA
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
SIMULATION_ID="cap_broadcast_inval"
8+
VERBOSITY_LEVEL=2
9+
EXECUTE_TIMEOUT=120
10+
11+
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
12+
13+
cd ${BSIM_OUT_PATH}/bin
14+
15+
printf "\n\n======== Running CAP broadcast inval test =========\n\n"
16+
17+
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
18+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=cap_initiator_broadcast_inval \
19+
-RealEncryption=1 -rs=46 -D=1
20+
21+
# Simulation time should be larger than the WAIT_TIME in common.h
22+
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \
23+
-D=1 -sim_length=60e6 $@
24+
25+
wait_for_background_jobs

tests/bsim/bluetooth/audio/test_scripts/cap_broadcast_reception.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
# Copyright (c) 2024-2025 Nordic Semiconductor ASA
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2025 Nordic Semiconductor ASA
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
SIMULATION_ID="cap_broadcast_update"
8+
VERBOSITY_LEVEL=2
9+
EXECUTE_TIMEOUT=120
10+
11+
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
12+
13+
cd ${BSIM_OUT_PATH}/bin
14+
15+
printf "\n\n======== Running CAP broadcast update test =========\n\n"
16+
17+
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
18+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=cap_initiator_broadcast_update \
19+
-RealEncryption=1 -rs=46 -D=2
20+
21+
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
22+
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=cap_acceptor_broadcast_update \
23+
-RealEncryption=1 -rs=23 -D=2
24+
25+
# Simulation time should be larger than the WAIT_TIME in common.h
26+
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \
27+
-D=2 -sim_length=60e6 $@
28+
29+
wait_for_background_jobs

0 commit comments

Comments
 (0)