From b34b93cb28edd6cae4e04b204d551932287bf351 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 29 Sep 2025 16:45:44 +0200 Subject: [PATCH] tests: Bluetooth: CCP: Modify server unittests to native_sim Modify the unit tests to use the native_sim board instead of the unit_testing board. The native_sim board allows us to use the kernel in a more regular way, while still being able to treat the tests as unittest. To support mocking we cannot rely on the default Kconfig options and values. The required Kconfig options to satisfy dependencies are overridden in the Kconfig file and the necessary Kconfig files are sourced. We cannot enable e.g. CONFIG_BT as that would attempt to pull in a lot of files we do not want in this test. This commit also removes unused includes in the CMakelists Signed-off-by: Emil Gydesen --- .../ccp_call_control_server/CMakeLists.txt | 28 ++++++--- .../audio/ccp_call_control_server/Kconfig | 63 +++++++++++++++++++ .../audio/ccp_call_control_server/prj.conf | 18 +++--- .../audio/ccp_call_control_server/src/main.c | 5 +- .../ccp_call_control_server/testcase.yaml | 5 +- .../uut/CMakeLists.txt | 22 ------- 6 files changed, 98 insertions(+), 43 deletions(-) create mode 100644 tests/bluetooth/audio/ccp_call_control_server/Kconfig delete mode 100644 tests/bluetooth/audio/ccp_call_control_server/uut/CMakeLists.txt diff --git a/tests/bluetooth/audio/ccp_call_control_server/CMakeLists.txt b/tests/bluetooth/audio/ccp_call_control_server/CMakeLists.txt index 40b476c4d66a3..d0b56d2a8a58d 100644 --- a/tests/bluetooth/audio/ccp_call_control_server/CMakeLists.txt +++ b/tests/bluetooth/audio/ccp_call_control_server/CMakeLists.txt @@ -2,16 +2,28 @@ cmake_minimum_required(VERSION 3.20.0) -project(bluetooth_ccp) -find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(bluetooth_ccp_server) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/audio/ccp_call_control_server/uut uut) +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/subsys/bluetooth/ -target_link_libraries(testbinary PRIVATE uut) + ${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/include +) + +target_sources(app PRIVATE + # Test source files + src/main.c -target_include_directories(testbinary PRIVATE include) + # Stack source file + ${ZEPHYR_BASE}/subsys/bluetooth/audio/audio.c + ${ZEPHYR_BASE}/subsys/bluetooth/audio/ccid.c + ${ZEPHYR_BASE}/subsys/bluetooth/audio/ccp_call_control_server.c + ${ZEPHYR_BASE}/subsys/bluetooth/audio/tbs.c + ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c + ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c -target_sources(testbinary - PRIVATE - src/main.c + # Mock files + ${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/src/conn.c + ${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/src/gatt.c ) diff --git a/tests/bluetooth/audio/ccp_call_control_server/Kconfig b/tests/bluetooth/audio/ccp_call_control_server/Kconfig new file mode 100644 index 0000000000000..ffa365136745d --- /dev/null +++ b/tests/bluetooth/audio/ccp_call_control_server/Kconfig @@ -0,0 +1,63 @@ +# Copyright (c) 2025 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +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_EXT_ADV + bool + default y + +config BT_L2CAP_TX_MTU + int + default 65 + +config BT_LOG + bool + default y + +config BT_MAX_CONN + int + default 1 + +config BT_MAX_PAIRED + int + default 1 + +config BT_SMP + bool + default y + +config BT_TBS + bool + default y + +config BT_TBS_BEARER_COUNT + int + default 1 + +# Include Zephyr's Kconfig. +source "Kconfig" +source "subsys/bluetooth/audio/Kconfig" +source "subsys/bluetooth/Kconfig.logging" diff --git a/tests/bluetooth/audio/ccp_call_control_server/prj.conf b/tests/bluetooth/audio/ccp_call_control_server/prj.conf index e7d7406bf5f6a..be65ce5e7eefc 100644 --- a/tests/bluetooth/audio/ccp_call_control_server/prj.conf +++ b/tests/bluetooth/audio/ccp_call_control_server/prj.conf @@ -1,15 +1,16 @@ CONFIG_ZTEST=y -CONFIG_BT=y -CONFIG_BT_SMP=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_GATT_DYNAMIC_DB=y -CONFIG_BT_AUDIO=y +CONFIG_NET_BUF=y +#CONFIG_BT=y +#CONFIG_BT_SMP=y +#CONFIG_BT_PERIPHERAL=y +#CONFIG_BT_EXT_ADV=y +#CONFIG_BT_GATT_DYNAMIC_DB=y +#CONFIG_BT_AUDIO=y CONFIG_BT_CCP_CALL_CONTROL_SERVER=y CONFIG_BT_CCP_CALL_CONTROL_SERVER_BEARER_COUNT=2 -CONFIG_BT_TBS=y -CONFIG_BT_TBS_BEARER_COUNT=1 +#CONFIG_BT_TBS=y +#CONFIG_BT_TBS_BEARER_COUNT=1 CONFIG_UTF8=y CONFIG_ASSERT=y @@ -18,4 +19,3 @@ CONFIG_ASSERT_VERBOSE=y CONFIG_LOG=y CONFIG_BT_CCP_CALL_CONTROL_SERVER_LOG_LEVEL_DBG=y -CONFIG_BT_TBS_LOG_LEVEL_DBG=y diff --git a/tests/bluetooth/audio/ccp_call_control_server/src/main.c b/tests/bluetooth/audio/ccp_call_control_server/src/main.c index af09be763bb17..212cd185fda11 100644 --- a/tests/bluetooth/audio/ccp_call_control_server/src/main.c +++ b/tests/bluetooth/audio/ccp_call_control_server/src/main.c @@ -20,9 +20,8 @@ #include #include #include - -#include -#include +#include +#include DEFINE_FFF_GLOBALS; diff --git a/tests/bluetooth/audio/ccp_call_control_server/testcase.yaml b/tests/bluetooth/audio/ccp_call_control_server/testcase.yaml index 1a75b740147f2..0073460eb8fdd 100644 --- a/tests/bluetooth/audio/ccp_call_control_server/testcase.yaml +++ b/tests/bluetooth/audio/ccp_call_control_server/testcase.yaml @@ -4,4 +4,7 @@ common: - bluetooth_audio tests: bluetooth.audio.ccp_call_control_server.test: - type: unit + platform_allow: + - native_sim + integration_platforms: + - native_sim diff --git a/tests/bluetooth/audio/ccp_call_control_server/uut/CMakeLists.txt b/tests/bluetooth/audio/ccp_call_control_server/uut/CMakeLists.txt deleted file mode 100644 index 6dd650947733b..0000000000000 --- a/tests/bluetooth/audio/ccp_call_control_server/uut/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright (c) 2024 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/audio.c - ${ZEPHYR_BASE}/subsys/bluetooth/audio/ccid.c - ${ZEPHYR_BASE}/subsys/bluetooth/audio/ccp_call_control_server.c - ${ZEPHYR_BASE}/subsys/bluetooth/audio/tbs.c - ${ZEPHYR_BASE}/lib/net_buf/buf_simple.c - ${ZEPHYR_BASE}/lib/utils/utf8.c -) - -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/audio/mocks mocks) - -target_link_libraries(uut PUBLIC test_interface mocks) - -target_compile_options(uut PRIVATE -std=c11 -include ztest.h)