From 90eeeeb6b616d628ba84f3df65c2072bff6b7506 Mon Sep 17 00:00:00 2001 From: Timothy Keys Date: Thu, 31 Oct 2024 15:08:18 +0000 Subject: [PATCH] [nrf fromtree] Bluetooth: Host: Unit test for bt_le_cs_set_valid_chmap_bits Add coverage of the bt_le_cs_set_valid_chmap_bits function to unit tests Signed-off-by: Timothy Keys (cherry picked from commit e976a01bedff4ef4c122c2d7e63cb480784a5dde) Signed-off-by: Sean Madigan --- .../CMakeLists.txt | 26 ++++++++++++++++ .../cs/bt_le_cs_set_valid_chmap_bits/prj.conf | 10 +++++++ .../bt_le_cs_set_valid_chmap_bits/src/main.c | 30 +++++++++++++++++++ .../testcase.yaml | 7 +++++ 4 files changed, 73 insertions(+) create mode 100644 tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/CMakeLists.txt create mode 100644 tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/prj.conf create mode 100644 tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/src/main.c create mode 100644 tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/testcase.yaml diff --git a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/CMakeLists.txt b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/CMakeLists.txt new file mode 100644 index 00000000000..aee0c445f6b --- /dev/null +++ b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/CMakeLists.txt @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +get_filename_component(project_name ${CMAKE_CURRENT_SOURCE_DIR} NAME) +project(${project_name}) + +include_directories(BEFORE + ${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks +) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks mocks) + +target_link_libraries(testbinary PRIVATE mocks host_mocks) + +target_sources(testbinary + PRIVATE + src/main.c + + ${ZEPHYR_BASE}/subsys/bluetooth/host/cs.c + ${ZEPHYR_BASE}/lib/net_buf/buf_simple.c + ${ZEPHYR_BASE}/subsys/logging/log_minimal.c +) diff --git a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/prj.conf b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/prj.conf new file mode 100644 index 00000000000..8ff995b6f04 --- /dev/null +++ b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/prj.conf @@ -0,0 +1,10 @@ +CONFIG_ZTEST=y +CONFIG_BT=y +CONFIG_BT_HCI=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_CHANNEL_SOUNDING=y +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y +CONFIG_NET_BUF=y diff --git a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/src/main.c b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/src/main.c new file mode 100644 index 00000000000..72784fba71d --- /dev/null +++ b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/src/main.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +DEFINE_FFF_GLOBALS; + +ZTEST_SUITE(bt_le_cs_set_valid_chmap_bits, NULL, NULL, NULL, NULL, NULL); + +/* + * Test uninitialized chmap buffer is populated correctly + * + * Expected behaviour: + * - test_chmap matches correct_chmap + */ +ZTEST(bt_le_cs_set_valid_chmap_bits, test_uninitialized_chmap) +{ + uint8_t test_chmap[10]; + + bt_le_cs_set_valid_chmap_bits(test_chmap); + + uint8_t correct_chmap[10] = {0xFC, 0xFF, 0x7F, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F}; + + zassert_mem_equal(test_chmap, correct_chmap, 10); +} diff --git a/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/testcase.yaml b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/testcase.yaml new file mode 100644 index 00000000000..b040e501559 --- /dev/null +++ b/tests/bluetooth/host/cs/bt_le_cs_set_valid_chmap_bits/testcase.yaml @@ -0,0 +1,7 @@ +common: + tags: + - bluetooth + - host +tests: + bluetooth.host.cs.bt_le_cs_set_valid_chmap_bits: + type: unit