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: 32 additions & 12 deletions tests/bluetooth/audio/ascs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,42 @@

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_ascs)

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

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

target_include_directories(testbinary PRIVATE include)
target_sources(app PRIVATE
# Test source files
src/main.c
src/test_ase_control_params.c
src/test_ase_register.c
src/test_ase_state_transition_invalid.c
src/test_ase_state_transition.c
src/test_common.c

target_sources(testbinary
PRIVATE
src/main.c
src/test_ase_control_params.c
src/test_ase_register.c
src/test_ase_state_transition_invalid.c
src/test_ase_state_transition.c
src/test_common.c
# UUT files
uut/bap_unicast_client.c
uut/bap_unicast_server.c

# Stack source file
${ZEPHYR_BASE}/subsys/bluetooth/audio/ascs.c
${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/bap_unicast_server.c
${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c

# Mock files
${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/src/bap_stream.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
${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/src/pacs.c
)
71 changes: 71 additions & 0 deletions tests/bluetooth/audio/ascs/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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_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_MAX_PAIRED
int
default 1

config BT_GATT_DYNAMIC_DB
bool
default y

config BT_ISO_PERIPHERAL
bool
default y

config BT_ISO_MAX_CHAN
int
default 10

config BT_L2CAP_TX_MTU
int
default 65

config BT_LOG
bool
default y

config BT_MAX_CONN
int
default 1

config BT_PERIPHERAL
bool
default y

config BT_SMP
bool
default y

# Include Zephyr's Kconfig.
source "Kconfig"
source "subsys/bluetooth/audio/Kconfig"
source "subsys/bluetooth/Kconfig.logging"
1 change: 1 addition & 0 deletions tests/bluetooth/audio/ascs/include/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct test_ase_cp_chrc_value_hdr {
void test_mocks_init(void);
void test_mocks_cleanup(void);
void test_mocks_reset(void);
void test_drain_syswq(void);

/* Initialize connection object for test */
void test_conn_init(struct bt_conn *conn);
Expand Down
13 changes: 2 additions & 11 deletions tests/bluetooth/audio/ascs/prj.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
CONFIG_ZTEST=y

CONFIG_BT=y
CONFIG_BT_SMP=y
CONFIG_BT_MAX_CONN=1
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_ISO_PERIPHERAL=y
CONFIG_BT_ISO_MAX_CHAN=1
CONFIG_BT_GATT_DYNAMIC_DB=y
CONFIG_BT_AUDIO=y
CONFIG_NET_BUF=y

CONFIG_BT_ASCS=y
CONFIG_BT_PAC_SNK=y
CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT=2
Expand All @@ -16,9 +10,6 @@ CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT=2
CONFIG_BT_ASCS_MAX_ACTIVE_ASES=1
CONFIG_BT_BAP_UNICAST_SERVER=y

# Mandatory to support at least 1 for ASCS
CONFIG_BT_ATT_PREPARE_COUNT=1

CONFIG_LOG=y
CONFIG_BT_ASCS_LOG_LEVEL_DBG=y
CONFIG_BT_BAP_ISO_LOG_LEVEL_DBG=y
Expand Down
14 changes: 14 additions & 0 deletions tests/bluetooth/audio/ascs/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ ZTEST_F(ascs_test_suite, test_release_ase_on_callback_unregister)
/* Unregister the callbacks - which will clean up the ASCS */
bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);

test_drain_syswq(); /* Ensure that state transitions are completed */

/* Expected to notify the upper layers */
expect_bt_bap_unicast_server_cb_release_called_once(stream);
expect_bt_bap_stream_ops_released_called_once(stream);
Expand Down Expand Up @@ -434,6 +436,8 @@ ZTEST_F(ascs_test_suite, test_cis_link_loss_in_streaming_state)
/* Mock CIS disconnection */
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_TIMEOUT);

test_drain_syswq(); /* Ensure that state transitions are completed */

/* Expected to notify the upper layers */
expect_bt_bap_stream_ops_qos_set_called_once(stream);
expect_bt_bap_stream_ops_disabled_called_once(stream);
Expand Down Expand Up @@ -478,6 +482,8 @@ static void test_cis_link_loss_in_disabling_state(struct ascs_test_suite_fixture
/* Mock CIS disconnection */
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_TIMEOUT);

test_drain_syswq(); /* Ensure that state transitions are completed */

/* Expected to notify the upper layers */
expect_bt_bap_stream_ops_qos_set_called_once(stream);
expect_bt_bap_stream_ops_disabled_not_called();
Expand Down Expand Up @@ -526,6 +532,8 @@ ZTEST_F(ascs_test_suite, test_cis_link_loss_in_enabling_state)
/* Mock CIS disconnection */
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_TIMEOUT);

test_drain_syswq(); /* Ensure that state transitions are completed */

/* Expected no change in ASE state */
expect_bt_bap_stream_ops_qos_set_not_called();
expect_bt_bap_stream_ops_released_not_called();
Expand All @@ -534,6 +542,8 @@ ZTEST_F(ascs_test_suite, test_cis_link_loss_in_enabling_state)
err = bt_bap_stream_disable(stream);
zassert_equal(0, err, "Failed to disable stream: err %d", err);

test_drain_syswq(); /* Ensure that state transitions are completed */

if (IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK)) {
expect_bt_bap_stream_ops_qos_set_called_once(stream);
expect_bt_bap_stream_ops_disabled_called_once(stream);
Expand Down Expand Up @@ -573,6 +583,8 @@ ZTEST_F(ascs_test_suite, test_cis_link_loss_in_enabling_state_client_retries)
/* Mock CIS disconnection */
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_FAIL_TO_ESTAB);

test_drain_syswq(); /* Ensure that state transitions are completed */

/* Expected to not notify the upper layers */
expect_bt_bap_stream_ops_qos_set_not_called();
expect_bt_bap_stream_ops_released_not_called();
Expand All @@ -588,6 +600,8 @@ ZTEST_F(ascs_test_suite, test_cis_link_loss_in_enabling_state_client_retries)
zassert_equal(0, err, "bt_bap_stream_start err %d", err);
}

test_drain_syswq(); /* Ensure that state transitions are completed */

expect_bt_bap_stream_ops_connected_called_twice(stream);
expect_bt_bap_stream_ops_started_called_once(stream);
}
Expand Down
Loading