diff --git a/tests/bluetooth/audio/ascs/CMakeLists.txt b/tests/bluetooth/audio/ascs/CMakeLists.txt index 6b4b0311daa79..082353a54ad71 100644 --- a/tests/bluetooth/audio/ascs/CMakeLists.txt +++ b/tests/bluetooth/audio/ascs/CMakeLists.txt @@ -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 ) diff --git a/tests/bluetooth/audio/ascs/Kconfig b/tests/bluetooth/audio/ascs/Kconfig new file mode 100644 index 0000000000000..1e9ed9b5ba994 --- /dev/null +++ b/tests/bluetooth/audio/ascs/Kconfig @@ -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" diff --git a/tests/bluetooth/audio/ascs/include/test_common.h b/tests/bluetooth/audio/ascs/include/test_common.h index 591395182d069..243f157eb6ac8 100644 --- a/tests/bluetooth/audio/ascs/include/test_common.h +++ b/tests/bluetooth/audio/ascs/include/test_common.h @@ -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); diff --git a/tests/bluetooth/audio/ascs/prj.conf b/tests/bluetooth/audio/ascs/prj.conf index 5b6276dfccaf2..0ec727830d33f 100644 --- a/tests/bluetooth/audio/ascs/prj.conf +++ b/tests/bluetooth/audio/ascs/prj.conf @@ -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 @@ -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 diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c index a326c7b1495fb..04c06e756dce4 100644 --- a/tests/bluetooth/audio/ascs/src/main.c +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -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); @@ -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); @@ -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(); @@ -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(); @@ -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); @@ -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(); @@ -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); } diff --git a/tests/bluetooth/audio/ascs/src/test_ase_state_transition.c b/tests/bluetooth/audio/ascs/src/test_ase_state_transition.c index c51e174754ed5..a9b47288938a1 100644 --- a/tests/bluetooth/audio/ascs/src/test_ase_state_transition.c +++ b/tests/bluetooth/audio/ascs/src/test_ase_state_transition.c @@ -343,6 +343,8 @@ ZTEST_F(test_sink_ase_state_transition, test_client_streaming_to_releasing) /* Client disconnects the ISO */ mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_REMOTE_USER_TERM_CONN); @@ -404,6 +406,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_idle_to_codec_configured) err = bt_bap_unicast_server_config_ase(conn, stream, &codec_cfg, &qos_pref); zassert_false(err < 0, "bt_bap_unicast_server_config_ase returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_config_not_called(); expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY); @@ -426,6 +430,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_codec_configured_to_codec_co err = bt_bap_stream_reconfig(stream, &codec_cfg); zassert_false(err < 0, "bt_bap_stream_reconfig returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SINK, EMPTY); expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY); @@ -445,6 +451,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_codec_configured_to_releasin err = bt_bap_stream_release(stream); zassert_false(err < 0, "bt_bap_stream_release returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); @@ -467,6 +475,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_qos_configured_to_codec_conf err = bt_bap_stream_reconfig(stream, &codec_cfg); zassert_false(err < 0, "bt_bap_stream_reconfig returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SINK, EMPTY); expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY); @@ -486,6 +496,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_qos_configured_to_releasing) err = bt_bap_stream_release(stream); zassert_false(err < 0, "bt_bap_stream_release returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); @@ -505,6 +517,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_enabling_to_releasing) err = bt_bap_stream_release(stream); zassert_false(err < 0, "bt_bap_stream_release returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); @@ -529,6 +543,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_enabling_to_enabling) err = bt_bap_stream_metadata(stream, meta, ARRAY_SIZE(meta)); zassert_false(err < 0, "bt_bap_stream_metadata returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY); expect_bt_bap_stream_ops_metadata_updated_called_once(stream); @@ -549,6 +565,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_enabling_to_qos_configured) err = bt_bap_stream_disable(stream); zassert_false(err < 0, "bt_bap_stream_disable returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_disable_called_once(stream); expect_bt_bap_stream_ops_qos_set_called_once(stream); @@ -573,6 +591,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_enabling_to_streaming) err = bt_bap_stream_start(stream); zassert_false(err < 0, "bt_bap_stream_start returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_stream_ops_connected_called_once(stream); expect_bt_bap_stream_ops_started_called_once(stream); @@ -599,6 +619,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_streaming_to_streaming) err = bt_bap_stream_metadata(stream, meta, ARRAY_SIZE(meta)); zassert_false(err < 0, "bt_bap_stream_metadata returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY); expect_bt_bap_stream_ops_metadata_updated_called_once(stream); @@ -620,6 +642,8 @@ ZTEST_F(test_sink_ase_state_transition, test_server_streaming_to_qos_configured) err = bt_bap_stream_disable(stream); zassert_false(err < 0, "bt_bap_stream_disable returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_disable_called_once(stream); expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_LOCALHOST_TERM_CONN); @@ -642,9 +666,13 @@ ZTEST_F(test_sink_ase_state_transition, test_server_streaming_to_releasing) err = bt_bap_stream_release(stream); zassert_false(err < 0, "bt_bap_stream_release returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Client disconnects the ISO */ mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_LOCALHOST_TERM_CONN); @@ -903,6 +931,8 @@ ZTEST_F(test_source_ase_state_transition, test_client_streaming_to_releasing) /* Client disconnects the ISO */ mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_REMOTE_USER_TERM_CONN); @@ -1012,6 +1042,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_idle_to_codec_configured) err = bt_bap_unicast_server_config_ase(conn, stream, &codec_cfg, &qos_pref); zassert_false(err < 0, "bt_bap_unicast_server_config_ase returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_config_not_called(); expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY); @@ -1034,6 +1066,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_codec_configured_to_codec_ err = bt_bap_stream_reconfig(stream, &codec_cfg); zassert_false(err < 0, "bt_bap_stream_reconfig returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SOURCE, EMPTY); expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY); @@ -1053,6 +1087,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_codec_configured_to_releas err = bt_bap_stream_release(stream); zassert_false(err < 0, "bt_bap_stream_release returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); @@ -1075,6 +1111,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_qos_configured_to_codec_co err = bt_bap_stream_reconfig(stream, &codec_cfg); zassert_false(err < 0, "bt_bap_stream_reconfig returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SOURCE, EMPTY); expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY); @@ -1094,6 +1132,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_qos_configured_to_releasin err = bt_bap_stream_release(stream); zassert_false(err < 0, "bt_bap_stream_release returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); @@ -1113,6 +1153,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_enabling_to_releasing) err = bt_bap_stream_release(stream); zassert_false(err < 0, "bt_bap_stream_release returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); @@ -1137,6 +1179,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_enabling_to_enabling) err = bt_bap_stream_metadata(stream, meta, ARRAY_SIZE(meta)); zassert_false(err < 0, "bt_bap_stream_metadata returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY); expect_bt_bap_stream_ops_metadata_updated_called_once(stream); @@ -1157,6 +1201,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_enabling_to_disabling) err = bt_bap_stream_disable(stream); zassert_false(err < 0, "bt_bap_stream_disable returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_disable_called_once(stream); expect_bt_bap_stream_ops_disabled_called_once(stream); @@ -1181,6 +1227,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_streaming_to_streaming) err = bt_bap_stream_metadata(stream, meta, ARRAY_SIZE(meta)); zassert_false(err < 0, "bt_bap_stream_metadata returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY); expect_bt_bap_stream_ops_metadata_updated_called_once(stream); @@ -1202,6 +1250,8 @@ ZTEST_F(test_source_ase_state_transition, test_server_streaming_to_disabling) err = bt_bap_stream_disable(stream); zassert_false(err < 0, "bt_bap_stream_disable returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_disable_called_once(stream); expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_LOCALHOST_TERM_CONN); @@ -1223,9 +1273,13 @@ ZTEST_F(test_source_ase_state_transition, test_server_streaming_to_releasing) err = bt_bap_stream_release(stream); zassert_false(err < 0, "bt_bap_stream_release returned err %d", err); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Client disconnects the ISO */ mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + test_drain_syswq(); /* Ensure that state transitions are completed */ + /* Verification */ expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_LOCALHOST_TERM_CONN); diff --git a/tests/bluetooth/audio/ascs/src/test_common.c b/tests/bluetooth/audio/ascs/src/test_common.c index b09677592f46f..791e076a305ab 100644 --- a/tests/bluetooth/audio/ascs/src/test_common.c +++ b/tests/bluetooth/audio/ascs/src/test_common.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include @@ -37,7 +39,6 @@ void test_mocks_init(void) { mock_bap_unicast_server_init(); mock_bt_iso_init(); - mock_kernel_init(); mock_bt_pacs_init(); mock_bap_stream_init(); mock_bt_gatt_init(); @@ -47,7 +48,6 @@ void test_mocks_cleanup(void) { mock_bap_unicast_server_cleanup(); mock_bt_iso_cleanup(); - mock_kernel_cleanup(); mock_bt_pacs_cleanup(); mock_bap_stream_cleanup(); mock_bt_gatt_cleanup(); @@ -180,6 +180,8 @@ void test_ase_control_client_config_codec(struct bt_conn *conn, uint8_t ase_id, zassert_false(ret < 0, "cp_attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); stream_allocated = NULL; + + test_drain_syswq(); /* Ensure that state transitions are completed */ } void test_ase_control_client_config_qos(struct bt_conn *conn, uint8_t ase_id) @@ -203,6 +205,8 @@ void test_ase_control_client_config_qos(struct bt_conn *conn, uint8_t ase_id) ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); + + test_drain_syswq(); /* Ensure that state transitions are completed */ } void test_ase_control_client_enable(struct bt_conn *conn, uint8_t ase_id) @@ -218,6 +222,8 @@ void test_ase_control_client_enable(struct bt_conn *conn, uint8_t ase_id) ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); + + test_drain_syswq(); /* Ensure that state transitions are completed */ } void test_ase_control_client_disable(struct bt_conn *conn, uint8_t ase_id) @@ -232,6 +238,8 @@ void test_ase_control_client_disable(struct bt_conn *conn, uint8_t ase_id) ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); + + test_drain_syswq(); /* Ensure that state transitions are completed */ } void test_ase_control_client_release(struct bt_conn *conn, uint8_t ase_id) @@ -246,6 +254,8 @@ void test_ase_control_client_release(struct bt_conn *conn, uint8_t ase_id) ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); + + test_drain_syswq(); /* Ensure that state transitions are completed */ } void test_ase_control_client_update_metadata(struct bt_conn *conn, uint8_t ase_id) @@ -262,6 +272,8 @@ void test_ase_control_client_update_metadata(struct bt_conn *conn, uint8_t ase_i ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); + + test_drain_syswq(); /* Ensure that state transitions are completed */ } void test_ase_control_client_receiver_start_ready(struct bt_conn *conn, uint8_t ase_id) @@ -276,6 +288,8 @@ void test_ase_control_client_receiver_start_ready(struct bt_conn *conn, uint8_t ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); + + test_drain_syswq(); /* Ensure that state transitions are completed */ } void test_ase_control_client_receiver_stop_ready(struct bt_conn *conn, uint8_t ase_id) @@ -290,6 +304,8 @@ void test_ase_control_client_receiver_stop_ready(struct bt_conn *conn, uint8_t a ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); + + test_drain_syswq(); /* Ensure that state transitions are completed */ } void test_preamble_state_codec_configured(struct bt_conn *conn, uint8_t ase_id, @@ -336,6 +352,8 @@ void test_preamble_state_streaming(struct bt_conn *conn, uint8_t ase_id, zassert_equal(0, err, "bt_bap_stream_start err %d", err); } + test_drain_syswq(); /* Ensure that state transitions are completed */ + test_mocks_reset(); } @@ -376,3 +394,10 @@ void test_preamble_state_releasing(struct bt_conn *conn, uint8_t ase_id, /* At this point, ISO is still connected, thus ASE is in releasing state */ } + +void test_drain_syswq(void) +{ + const int err = k_work_queue_drain(&k_sys_work_q, false); + + zassert_true(err >= 0, "Failed to drain system workqueue: %d", err); +} diff --git a/tests/bluetooth/audio/ascs/testcase.yaml b/tests/bluetooth/audio/ascs/testcase.yaml index f0501d65cc825..25482be388f4a 100644 --- a/tests/bluetooth/audio/ascs/testcase.yaml +++ b/tests/bluetooth/audio/ascs/testcase.yaml @@ -2,19 +2,20 @@ common: tags: - bluetooth - bluetooth_audio + tests: bluetooth.audio.ascs.test_default: - type: unit + platform_allow: + - native_sim + integration_platforms: + - native_sim bluetooth.audio.ascs.test_snk_only: - type: unit extra_configs: - CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT=0 bluetooth.audio.ascs.test_src_only: - type: unit extra_configs: - CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT=0 bluetooth.audio.ascs.test_unicast_client_enabled: - type: unit extra_configs: - CONFIG_BT_CENTRAL=y - CONFIG_BT_ISO_CENTRAL=y @@ -23,6 +24,5 @@ tests: - CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y - CONFIG_BT_GATT_AUTO_UPDATE_MTU=y bluetooth.audio.ascs.test_stream_pair: - type: unit extra_configs: - CONFIG_BT_ASCS_MAX_ACTIVE_ASES=2 diff --git a/tests/bluetooth/audio/ascs/uut/CMakeLists.txt b/tests/bluetooth/audio/ascs/uut/CMakeLists.txt deleted file mode 100644 index 3c1a04c271fd2..0000000000000 --- a/tests/bluetooth/audio/ascs/uut/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# -# Copyright (c) 2022 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 -# -# CMakeLists.txt file for creating of uut library. -# - -add_library(uut STATIC - ${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/common/bt_str.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/data.c - ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c - ${ZEPHYR_BASE}/subsys/logging/log_minimal.c - ${ZEPHYR_BASE}/lib/net_buf/buf_simple.c - bap_unicast_client.c - bap_unicast_server.c -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/audio/mocks mocks) - -target_link_libraries(uut PUBLIC test_interface mocks) -target_include_directories(uut PRIVATE ${ZEPHYR_BASE}/tests/bluetooth/audio/ascs/include) - -target_compile_options(uut PRIVATE -std=c11 -include ztest.h) diff --git a/tests/bluetooth/audio/mocks/src/gatt.c b/tests/bluetooth/audio/mocks/src/gatt.c index 79d084f5aa8fa..0d777dc3c2228 100644 --- a/tests/bluetooth/audio/mocks/src/gatt.c +++ b/tests/bluetooth/audio/mocks/src/gatt.c @@ -150,6 +150,7 @@ static struct bt_uuid *uuid_deep_copy(const struct bt_uuid *uuid) memcpy(copy, uuid, sizeof(struct bt_uuid_128)); break; default: + copy = NULL; zassert_unreachable("Unexpected uuid->type 0x%02x", uuid->type); } diff --git a/tests/bluetooth/audio/mocks/src/pacs.c b/tests/bluetooth/audio/mocks/src/pacs.c index 9e31e5259336e..51fe7e79a348c 100644 --- a/tests/bluetooth/audio/mocks/src/pacs.c +++ b/tests/bluetooth/audio/mocks/src/pacs.c @@ -14,8 +14,9 @@ #include #include +#include "audio/pacs_internal.h" + #include "pacs.h" -#include "pacs_internal.h" /* List of fakes used by this unit tester */ #define PACS_FFF_FAKES_LIST(FAKE) \