Skip to content

Commit 1d09a29

Browse files
committed
tests: Bluetooth: CAP: Handover sample test
Add testing of the CAP handver sample. It reuses the CAP acceptor sample test, but since handover tests both unicast and broadcast, it requires additional runtime, so the other CAP tests have their runtimes increased to 60 seconds. Signed-off-by: Emil Gydesen <[email protected]>
1 parent b8f1825 commit 1d09a29

File tree

13 files changed

+191
-7
lines changed

13 files changed

+191
-7
lines changed

tests/bsim/bluetooth/audio_samples/cap/acceptor/src/cap_acceptor_sample_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "bs_utils.h"
1515
#include "bstests.h"
1616

17-
#define WAIT_TIME 15 /* Seconds */
17+
#define WAIT_TIME 60 /* Seconds */
1818

1919
#define PASS_THRESHOLD 100 /* Audio packets */
2020

tests/bsim/bluetooth/audio_samples/cap/compile.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ if [ "${BOARD_TS}" == "nrf5340bsim_nrf5340_cpuapp" ]; then
3232
conf_file=${sample}/prj.conf \
3333
conf_overlay=${sample}/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf \
3434
exe_name=bs_${BOARD_TS}_${app}_unicast_prj_conf sysbuild=1 compile
35+
app=tests/bsim/bluetooth/audio_samples/cap/handover \
36+
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_handover \
37+
conf_file=${sample}/prj.conf \
38+
conf_overlay=${sample}/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf \
39+
exe_name=bs_${BOARD_TS}_${app}_prj_conf sysbuild=1 compile
40+
app=tests/bsim/bluetooth/audio_samples/cap/acceptor \
41+
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_acceptor \
42+
cmake_extra_args="-DCONFIG_SAMPLE_BROADCAST=y" \
43+
conf_file=${sample}/prj.conf \
44+
conf_overlay=${sample}/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf \
45+
exe_name=bs_${BOARD_TS}_${app}_handover_prj_conf sysbuild=1 compile
3546
else
3647
app=tests/bsim/bluetooth/audio_samples/cap/initiator \
3748
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_initiator \
@@ -55,6 +66,17 @@ else
5566
conf_file=${sample}/prj.conf \
5667
conf_overlay=${sample}/overlay-bt_ll_sw_split.conf \
5768
exe_name=bs_${BOARD_TS}_${app}_unicast_prj_conf sysbuild=1 compile
69+
app=tests/bsim/bluetooth/audio_samples/cap/handover \
70+
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_handover \
71+
conf_file=${sample}/prj.conf \
72+
conf_overlay=${sample}/overlay-bt_ll_sw_split.conf \
73+
exe_name=bs_${BOARD_TS}_${app}_prj_conf sysbuild=1 compile
74+
app=tests/bsim/bluetooth/audio_samples/cap/acceptor \
75+
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_acceptor \
76+
cmake_extra_args="-DCONFIG_SAMPLE_BROADCAST=y" \
77+
conf_file=${sample}/prj.conf \
78+
conf_overlay=${sample}/overlay-bt_ll_sw_split.conf \
79+
exe_name=bs_${BOARD_TS}_${app}_handover_prj_conf sysbuild=1 compile
5880
fi
5981

6082
wait_for_background_jobs
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(cap_handover_self_tests)
7+
8+
set(cap_handover_path ${ZEPHYR_BASE}/samples/bluetooth/cap_handover)
9+
10+
target_sources(app PRIVATE
11+
src/cap_handover_sample_test.c
12+
src/test_main.c
13+
14+
${cap_handover_path}/src/main.c
15+
${cap_handover_path}/src/cap_stream_tx.c
16+
)
17+
18+
zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)
19+
20+
zephyr_include_directories(
21+
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
22+
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
23+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
source "$(ZEPHYR_BASE)/samples/bluetooth/cap_handover/Kconfig"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
source "$(ZEPHYR_BASE)/samples/bluetooth/cap_handover/Kconfig.sysbuild"
5+
6+
config NATIVE_SIMULATOR_PRIMARY_MCU_INDEX
7+
int
8+
# Let's pass the test arguments to the application MCU test
9+
# otherwise by default they would have gone to the net core.
10+
default 0 if $(BOARD_TARGET_STRING) = "NRF5340BSIM_NRF5340_CPUAPP"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Please build using the sample configuration file:
2+
# ${ZEPHYR_BASE}/samples/bluetooth/cap_handover/prj.conf
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <inttypes.h>
7+
#include <stdint.h>
8+
9+
#include <zephyr/sys/util_macro.h>
10+
11+
#include "bs_types.h"
12+
#include "bs_tracing.h"
13+
#include "bs_utils.h"
14+
#include "bstests.h"
15+
16+
#define WAIT_TIME 60 /* Seconds */
17+
18+
#define PASS_THRESHOLD 100 /* Audio packets */
19+
20+
extern enum bst_result_t bst_result;
21+
22+
#define FAIL(...) \
23+
do { \
24+
bst_result = Failed; \
25+
bs_trace_error_time_line(__VA_ARGS__); \
26+
} while (0)
27+
28+
#define PASS(...) \
29+
do { \
30+
bst_result = Passed; \
31+
bs_trace_info_time(1, __VA_ARGS__); \
32+
} while (0)
33+
34+
static void test_cap_handover_sample_init(void)
35+
{
36+
bst_ticker_set_next_tick_absolute(WAIT_TIME * 1e6);
37+
bst_result = In_progress;
38+
}
39+
40+
static void test_cap_handover_sample_tick(bs_time_t HW_device_time)
41+
{
42+
/*
43+
* If in WAIT_TIME seconds we did not get enough packets through
44+
* we consider the test failed
45+
*/
46+
47+
extern uint64_t total_tx_iso_packet_count;
48+
49+
bs_trace_info_time(2, "%" PRIu64 " unicast packets sent, expected >= %i\n",
50+
total_tx_iso_packet_count, PASS_THRESHOLD);
51+
52+
if (total_tx_iso_packet_count < PASS_THRESHOLD) {
53+
FAIL("cap_handover FAILED (Did not pass after %d seconds)\n", WAIT_TIME);
54+
return;
55+
}
56+
57+
PASS("cap_handover PASSED\n");
58+
}
59+
60+
static const struct bst_test_instance test_sample[] = {
61+
{
62+
.test_id = "cap_handover",
63+
.test_descr = "Test based on the unicast client sample. "
64+
"It expects to be connected to a compatible unicast server, "
65+
"waits for " STR(WAIT_TIME) " seconds, and checks how "
66+
"many audio packets have been received correctly",
67+
.test_post_init_f = test_cap_handover_sample_init,
68+
.test_tick_f = test_cap_handover_sample_tick,
69+
},
70+
BSTEST_END_MARKER};
71+
72+
struct bst_test_list *test_cap_handover_sample_install(struct bst_test_list *tests)
73+
{
74+
tests = bst_add_tests(tests, test_sample);
75+
return tests;
76+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <stddef.h>
7+
8+
#include "bstests.h"
9+
10+
extern struct bst_test_list *test_cap_handover_sample_install(struct bst_test_list *tests);
11+
12+
bst_test_install_t test_installers[] = {
13+
test_cap_handover_sample_install,
14+
NULL,
15+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
include(${ZEPHYR_BASE}/samples/bluetooth/cap_handover/sysbuild.cmake)
5+
6+
native_simulator_set_primary_mcu_index(${DEFAULT_IMAGE} ${NET_APP})

tests/bsim/bluetooth/audio_samples/cap/initiator/src/cap_initiator_sample_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024 Nordic Semiconductor ASA
2+
* Copyright (c) 2023-2025 Nordic Semiconductor ASA
33
* Copyright (c) 2017-2019 Oticon A/S
44
*
55
* SPDX-License-Identifier: Apache-2.0
@@ -14,7 +14,7 @@
1414
#include "bs_utils.h"
1515
#include "bstests.h"
1616

17-
#define WAIT_TIME 15 /* Seconds */
17+
#define WAIT_TIME 60 /* Seconds */
1818

1919
#define PASS_THRESHOLD 100 /* Audio packets */
2020

0 commit comments

Comments
 (0)