Skip to content
Open
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
44 changes: 33 additions & 11 deletions tests/bluetooth/audio/cap_initiator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,43 @@

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE})
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(bluetooth_cap_initiator)

add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/audio/cap_initiator/uut uut)
target_include_directories(app PRIVATE
${ZEPHYR_BASE}/subsys/bluetooth/

target_link_libraries(testbinary PRIVATE uut)
${ZEPHYR_BASE}/tests/bluetooth/audio/cap_initiator/include
${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/include
)

target_sources(app PRIVATE
# Test source files
src/main.c
src/test_common.c
src/test_unicast_group.c
src/test_unicast_start.c
src/test_unicast_stop.c

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

target_include_directories(testbinary PRIVATE include)
# Stack source file
${ZEPHYR_BASE}/subsys/bluetooth/audio/audio.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/bap_iso.c
${ZEPHYR_BASE}/subsys/bluetooth/audio/bap_stream.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/bt_str.c
${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c

target_sources(testbinary
PRIVATE
src/main.c
src/test_common.c
src/test_unicast_group.c
src/test_unicast_start.c
src/test_unicast_stop.c
# Mock files
${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
)
79 changes: 79 additions & 0 deletions tests/bluetooth/audio/cap_initiator/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 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_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_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_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"
22 changes: 1 addition & 21 deletions tests/bluetooth/audio/cap_initiator/prj.conf
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
CONFIG_ZTEST=y
CONFIG_LOG=y

CONFIG_BT=y
CONFIG_BT_SMP=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_ISO_CENTRAL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y
CONFIG_BT_GATT_AUTO_UPDATE_MTU=y
CONFIG_BT_AUDIO=y

# Dependencies for CAP initiator unicast
CONFIG_BT_BAP_UNICAST_CLIENT=y
CONFIG_BT_CSIP_SET_COORDINATOR=y

CONFIG_BT_CAP_INITIATOR=y

# Support setting up a sink and source stream on 2 acceptors
CONFIG_BT_MAX_CONN=2
CONFIG_BT_ISO_MAX_CHAN=4
CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT=4
CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT=2
CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT=2

CONFIG_ASSERT=y
CONFIG_ASSERT_LEVEL=2
CONFIG_ASSERT_VERBOSE=y

CONFIG_LOG=y
CONFIG_BT_BAP_STREAM_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_COMMON_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_INITIATOR_LOG_LEVEL_DBG=y
4 changes: 2 additions & 2 deletions tests/bluetooth/audio/cap_initiator/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#include <zephyr/bluetooth/hci_types.h>
#include <zephyr/fff.h>
#include <zephyr/sys/util.h>
#include <zephyr/ztest_assert.h>
#include <zephyr/ztest_test.h>

#include "cap_initiator.h"
#include "conn.h"
#include "expects_util.h"
#include "test_common.h"
#include "ztest_assert.h"
#include "ztest_test.h"

static void mock_init_rule_before(const struct ztest_unit_test *test, void *fixture)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/bluetooth/audio/cap_initiator/src/test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#include <zephyr/bluetooth/hci_types.h>
#include <zephyr/fff.h>
#include <zephyr/sys/printk.h>
#include <zephyr/ztest_assert.h>

#include "bap_endpoint.h"
#include "audio/bap_endpoint.h"
#include "cap_initiator.h"
#include "conn.h"
#include "test_common.h"
#include "ztest_assert.h"

DEFINE_FFF_GLOBALS;

Expand Down
21 changes: 15 additions & 6 deletions tests/bluetooth/audio/cap_initiator/src/test_unicast_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#include <zephyr/fff.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/util.h>
#include <zephyr/ztest_assert.h>
#include <zephyr/ztest_test.h>
#include <sys/errno.h>

#include "bap_endpoint.h"
#include "audio/bap_endpoint.h"
#include "test_common.h"
#include "ztest_assert.h"
#include "ztest_test.h"

struct cap_initiator_test_unicast_group_fixture {
struct bt_cap_unicast_group_param *group_param;
Expand Down Expand Up @@ -126,6 +126,9 @@ static ZTEST_F(cap_initiator_test_unicast_group, test_initiator_unicast_group_cr

err = bt_cap_unicast_group_create(fixture->group_param, &fixture->unicast_group);
zassert_equal(err, 0, "Unexpected return value %d", err);

err = bt_cap_unicast_group_delete(fixture->unicast_group);
zassert_equal(err, 0, "Unexpected return value %d", err);
}

static ZTEST_F(cap_initiator_test_unicast_group,
Expand Down Expand Up @@ -185,6 +188,9 @@ static ZTEST_F(cap_initiator_test_unicast_group, test_initiator_unicast_group_re

err = bt_cap_unicast_group_reconfig(fixture->unicast_group, fixture->group_param);
zassert_equal(err, 0, "Unexpected return value %d", err);

err = bt_cap_unicast_group_delete(fixture->unicast_group);
zassert_equal(err, 0, "Unexpected return value %d", err);
}

static ZTEST_F(cap_initiator_test_unicast_group,
Expand Down Expand Up @@ -213,7 +219,7 @@ static ZTEST_F(cap_initiator_test_unicast_group,

static ZTEST_F(cap_initiator_test_unicast_group, test_initiator_unicast_group_add_streams)
{
struct bt_cap_stream stream = {};
struct bt_cap_stream stream = {0};
struct bt_cap_unicast_group_stream_param stream_param = {
.stream = &stream,
.qos_cfg = fixture->qos_cfg,
Expand All @@ -228,12 +234,15 @@ static ZTEST_F(cap_initiator_test_unicast_group, test_initiator_unicast_group_ad

err = bt_cap_unicast_group_add_streams(fixture->unicast_group, &pair_param, 1);
zassert_equal(err, 0, "Unexpected return value %d", err);

err = bt_cap_unicast_group_delete(fixture->unicast_group);
zassert_equal(err, 0, "Unexpected return value %d", err);
}

static ZTEST_F(cap_initiator_test_unicast_group,
test_initiator_unicast_group_add_streams_inval_null_group)
{
struct bt_cap_stream stream = {};
struct bt_cap_stream stream = {0};
struct bt_cap_unicast_group_stream_param stream_param = {
.stream = &stream,
.qos_cfg = fixture->qos_cfg,
Expand Down Expand Up @@ -265,7 +274,7 @@ static ZTEST_F(cap_initiator_test_unicast_group,
static ZTEST_F(cap_initiator_test_unicast_group,
test_initiator_unicast_group_add_streams_inval_0_param)
{
struct bt_cap_stream stream = {};
struct bt_cap_stream stream = {0};
struct bt_cap_unicast_group_stream_param stream_param = {
.stream = &stream,
.qos_cfg = fixture->qos_cfg,
Expand Down
9 changes: 5 additions & 4 deletions tests/bluetooth/audio/cap_initiator/src/test_unicast_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/util.h>
#include <zephyr/ztest_assert.h>
#include <zephyr/ztest_test.h>

#include <sys/errno.h>

#include "bap_endpoint.h"
#include "bap_iso.h"
#include "audio/bap_endpoint.h"
#include "audio/bap_iso.h"
#include "cap_initiator.h"
#include "conn.h"
#include "expects_util.h"
#include "test_common.h"
#include "ztest_assert.h"
#include "ztest_test.h"

struct cap_initiator_test_unicast_start_fixture {
struct bt_cap_stream cap_streams[CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT];
Expand Down
6 changes: 3 additions & 3 deletions tests/bluetooth/audio/cap_initiator/src/test_unicast_stop.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
#include <zephyr/sys/slist.h>
#include <zephyr/sys/util.h>
#include <zephyr/ztest_assert.h>
#include <zephyr/ztest_test.h>

#include <sys/errno.h>

#include "bap_endpoint.h"
#include "audio/bap_endpoint.h"
#include "cap_initiator.h"
#include "conn.h"
#include "expects_util.h"
#include "test_common.h"
#include "ztest_assert.h"
#include "ztest_test.h"

struct cap_initiator_test_unicast_stop_fixture {
struct bt_cap_stream cap_streams[CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT];
Expand Down
5 changes: 4 additions & 1 deletion tests/bluetooth/audio/cap_initiator/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ common:
- bluetooth_audio
tests:
bluetooth.audio.cap_initiator.test_default:
type: unit
platform_allow:
- native_sim
integration_platforms:
- native_sim
31 changes: 0 additions & 31 deletions tests/bluetooth/audio/cap_initiator/uut/CMakeLists.txt

This file was deleted.

4 changes: 2 additions & 2 deletions tests/bluetooth/audio/cap_initiator/uut/bap_unicast_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <zephyr/ztest_assert.h>
#include <sys/errno.h>

#include "bap_endpoint.h"
#include "bap_iso.h"
#include "audio/bap_endpoint.h"
#include "audio/bap_iso.h"

static struct bt_bap_unicast_client_cb *unicast_client_cb;
static struct bt_bap_unicast_group bap_unicast_group;
Expand Down