Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion subsys/bluetooth/audio/bap_broadcast_assistant.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <zephyr/bluetooth/l2cap.h>
#include <zephyr/bluetooth/buf.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/device.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/net_buf.h>
Expand Down
49 changes: 49 additions & 0 deletions tests/bluetooth/audio/cap_handover/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(bluetooth_cap_handover)

target_include_directories(app PRIVATE
${ZEPHYR_BASE}/subsys/bluetooth/

${ZEPHYR_BASE}/tests/bluetooth/audio/cap_handover/include
${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/include
)

target_sources(app PRIVATE
# Test source files
src/broadcast_to_unicast.c
src/unicast_to_broadcast.c
src/test_common.c

# UUT files
uut/bap_broadcast_assistant.c
uut/bap_unicast_client.c
uut/cap_handover.c
uut/cap_initiator.c
uut/csip.c

# Stack source file
${ZEPHYR_BASE}/subsys/bluetooth/audio/audio.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/codec.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/bap_broadcast_source.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/bap_iso.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/bap_stream.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/cap_commander.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/cap_handover.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/cap_initiator.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/cap_common.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/cap_stream.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/ccid.c
${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c
${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c
${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c

# Mock files
${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/src/adv.c
${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/src/conn.c
${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/src/gatt.c
${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/src/iso.c
)
111 changes: 111 additions & 0 deletions tests/bluetooth/audio/cap_handover/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Copyright (c) 2025 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

config BT_ATT_PREPARE_COUNT
int
default 1

config BT_AUDIO
bool
default y

config BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE
int
default 20

config BT_BAP_BROADCAST_ASSISTANT
bool
default y

config BT_BAP_BROADCAST_SOURCE
bool
default y

config BT_BAP_BROADCAST_SRC_STREAM_COUNT
int
default 2

config BT_BAP_SCAN_DELEGATOR
bool
default y

config BT_BAP_STREAM
bool
default y

config BT_BAP_UNICAST_CLIENT
bool
default y

config BT_BAP_UNICAST_CLIENT_GROUP_COUNT
int
default 1

config BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT
int
default 4

config BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT
int
default 2

config BT_BONDABLE
bool
default y

config BT_BUF_ACL_RX_SIZE
int
default 69

config BT_BUF_ACL_TX_COUNT
int
default 5

config BT_BUF_EVT_RX_COUNT
int
default 10

config BT_CONN
bool
default y

config BT_CSIP_SET_COORDINATOR
bool
default y

config BT_ISO_MAX_BIG
int
default 1

config BT_ISO_MAX_CIG
int
default 1

config BT_ISO_MAX_CHAN
int
default 4

config BT_MAX_PAIRED
int
default 1

config BT_L2CAP_TX_MTU
int
default 65

config BT_LOG
bool
default y

config BT_MAX_CONN
int
default 2

config BT_SMP
bool
default y

# Include Zephyr's Kconfig.
source "Kconfig"
source "subsys/bluetooth/audio/Kconfig"
source "subsys/bluetooth/Kconfig.logging"
24 changes: 24 additions & 0 deletions tests/bluetooth/audio/cap_handover/include/cap_handover.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef MOCKS_CAP_HANDOVER_H_
#define MOCKS_CAP_HANDOVER_H_

#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/audio/csip.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/fff.h>

extern const struct bt_cap_handover_cb mock_cap_handover_cb;

void mock_cap_handover_init(void);

DECLARE_FAKE_VOID_FUNC(mock_unicast_to_broadcast_complete_cb, int, struct bt_conn *,
struct bt_cap_unicast_group *, struct bt_cap_broadcast_source *);
DECLARE_FAKE_VOID_FUNC(mock_broadcast_to_unicast_complete_cb, int, struct bt_conn *,
struct bt_cap_broadcast_source *, struct bt_cap_unicast_group *);

#endif /* MOCKS_CAP_HANDOVER_H_ */
22 changes: 22 additions & 0 deletions tests/bluetooth/audio/cap_handover/include/cap_initiator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef MOCKS_CAP_INITIATOR_H_
#define MOCKS_CAP_INITIATOR_H_

#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/audio/csip.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/fff.h>

extern const struct bt_cap_initiator_cb mock_cap_initiator_cb;

void mock_cap_initiator_init(void);

DECLARE_FAKE_VOID_FUNC(mock_unicast_start_complete_cb, int, struct bt_conn *);
DECLARE_FAKE_VOID_FUNC(mock_broadcast_start_cb, struct bt_cap_broadcast_source *);

#endif /* MOCKS_CAP_INITIATOR_H_ */
30 changes: 30 additions & 0 deletions tests/bluetooth/audio/cap_handover/include/test_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* test_common.h */

/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdint.h>

#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/audio/bap.h>
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/conn.h>

#define TEST_COMMON_ADV_TYPE BT_ADDR_LE_PUBLIC
#define TEST_COMMON_ADV_SID 0x01U
#define TEST_COMMON_BROADCAST_ID 0x123456U
#define TEST_COMMON_SRC_ID 0x00U

void test_mocks_init(void);
void test_mocks_cleanup(void);
void mock_bt_csip_cleanup(void);

void test_conn_init(struct bt_conn *conn, uint8_t index);

void test_unicast_set_state(struct bt_cap_stream *cap_stream, struct bt_conn *conn,
struct bt_bap_ep *ep, struct bt_bap_lc3_preset *preset,
enum bt_bap_ep_state state);
20 changes: 20 additions & 0 deletions tests/bluetooth/audio/cap_handover/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CONFIG_ZTEST=y

CONFIG_NET_BUF=y

CONFIG_BT_CAP_INITIATOR=y
CONFIG_BT_CAP_COMMANDER=y
CONFIG_BT_CAP_HANDOVER=y

CONFIG_ASSERT=y
CONFIG_ASSERT_LEVEL=2
CONFIG_ASSERT_VERBOSE=y

CONFIG_LOG=y
CONFIG_BT_BAP_ISO_LOG_LEVEL_DBG=y
CONFIG_BT_BAP_STREAM_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_COMMON_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_COMMANDER_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_HANDOVER_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_INITIATOR_LOG_LEVEL_DBG=y
CONFIG_BT_BAP_BROADCAST_SOURCE_LOG_LEVEL_DBG=y
Loading
Loading