diff --git a/tests/bluetooth/host/CMakeLists.txt b/tests/bluetooth/host/CMakeLists.txt index af4cfb76237..173c6d90566 100644 --- a/tests/bluetooth/host/CMakeLists.txt +++ b/tests/bluetooth/host/CMakeLists.txt @@ -4,7 +4,6 @@ add_library(host_mocks STATIC host_mocks/assert.c - host_mocks/print_utils.c ) target_include_directories(host_mocks PUBLIC diff --git a/tests/bluetooth/host/host_mocks/print_utils.c b/tests/bluetooth/host/host_mocks/print_utils.c deleted file mode 100644 index 0d601c12e0e..00000000000 --- a/tests/bluetooth/host/host_mocks/print_utils.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "host_mocks/print_utils.h" - -static int bt_addr_le_to_str_mod(const bt_addr_le_t *addr, char *str, - size_t len) -{ - char type[10]; - - switch (addr->type) { - case BT_ADDR_LE_PUBLIC: - strcpy(type, "public"); - break; - case BT_ADDR_LE_RANDOM: - strcpy(type, "random"); - break; - case BT_ADDR_LE_PUBLIC_ID: - strcpy(type, "public-id"); - break; - case BT_ADDR_LE_RANDOM_ID: - strcpy(type, "random-id"); - break; - default: - snprintf(type, sizeof(type), "0x%02x", addr->type); - break; - } - - return snprintf(str, len, "%02X:%02X:%02X:%02X:%02X:%02X (%s)", - addr->a.val[5], addr->a.val[4], addr->a.val[3], - addr->a.val[2], addr->a.val[1], addr->a.val[0], type); -} - -static int bt_addr_to_str_mod(const bt_addr_t *addr, char *str, size_t len) -{ - return snprintf(str, len, "%02X:%02X:%02X:%02X:%02X:%02X", - addr->val[5], addr->val[4], addr->val[3], - addr->val[2], addr->val[1], addr->val[0]); -} - -const char *bt_addr_str_real(const bt_addr_t *addr) -{ - static char str[BT_ADDR_STR_LEN]; - - bt_addr_to_str_mod(addr, str, sizeof(str)); - - return str; -} - -const char *bt_addr_le_str_real(const bt_addr_le_t *addr) -{ - static char str[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str_mod(addr, str, sizeof(str)); - - return str; -} - -const char *bt_hex_real(const void *buf, size_t len) -{ - static const char hex[] = "0123456789abcdef"; - static char str[129]; - const uint8_t *b = buf; - size_t i; - - len = MIN(len, (sizeof(str) - 1) / 2); - - for (i = 0; i < len; i++) { - str[i * 2] = hex[b[i] >> 4]; - str[i * 2 + 1] = hex[b[i] & 0xf]; - } - - str[i * 2] = '\0'; - - return str; -} - -void z_log_minimal_printk(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vprintk(fmt, ap); - va_end(ap); -} diff --git a/tests/bluetooth/host/host_mocks/print_utils.h b/tests/bluetooth/host/host_mocks/print_utils.h deleted file mode 100644 index 9d94cb0e400..00000000000 --- a/tests/bluetooth/host/host_mocks/print_utils.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -const char *bt_addr_str_real(const bt_addr_t *addr); -const char *bt_addr_le_str_real(const bt_addr_le_t *addr); -const char *bt_hex_real(const void *buf, size_t len); -void z_log_minimal_printk(const char *fmt, ...); - -#ifndef bt_addr_le_str -#define bt_addr_le_str(addr) bt_addr_le_str_real(addr) -#endif diff --git a/tests/bluetooth/host/keys/CMakeLists.txt b/tests/bluetooth/host/keys/CMakeLists.txt deleted file mode 100644 index b02d36f2f64..00000000000 --- a/tests/bluetooth/host/keys/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# -# CMakeLists.txt file for creating of mocks library. -# - -add_library(mocks STATIC - mocks/id.c - mocks/rpa.c - mocks/conn.c - mocks/hci_core.c - mocks/hci_core_expects.c - mocks/keys_help_utils.c - - ${ZEPHYR_BASE}/subsys/bluetooth/host/keys.c - ${ZEPHYR_BASE}/subsys/bluetooth/common/addr.c -) - -target_include_directories(mocks PUBLIC - . - ${ZEPHYR_BASE}/tests/bluetooth/host - ${ZEPHYR_BASE}/subsys/bluetooth - ${ZEPHYR_BASE}/subsys/bluetooth/host -) - -target_link_libraries(mocks PRIVATE test_interface) diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_bond/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_foreach_bond/CMakeLists.txt index f9f6431bd0c..c49d2129c98 100644 --- a/tests/bluetooth/host/keys/bt_keys_foreach_bond/CMakeLists.txt +++ b/tests/bluetooth/host/keys/bt_keys_foreach_bond/CMakeLists.txt @@ -6,11 +6,16 @@ project(bt_keys_foreach_bond) find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) + +target_link_libraries(testbinary PRIVATE mocks host_mocks) target_sources(testbinary - PRIVATE + PRIVATE src/main.c src/test_suite_foreach_bond_invalid_inputs.c + + # Unit under test + $ENV{ZEPHYR_BASE}/subsys/bluetooth/host/keys.c + $ENV{ZEPHYR_BASE}/subsys/bluetooth/common/addr.c ) -target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_bond/prj.conf b/tests/bluetooth/host/keys/bt_keys_foreach_bond/prj.conf index 89d6267d5b3..5a575943b32 100644 --- a/tests/bluetooth/host/keys/bt_keys_foreach_bond/prj.conf +++ b/tests/bluetooth/host/keys/bt_keys_foreach_bond/prj.conf @@ -6,3 +6,6 @@ CONFIG_BT_MAX_PAIRED=4 CONFIG_ASSERT=y CONFIG_ASSERT_LEVEL=2 CONFIG_ASSERT_VERBOSE=y +CONFIG_LOG=n +CONFIG_BT_DEBUG_LOG=n +CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_type/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_foreach_type/CMakeLists.txt index 5d1c71d5eec..f43808e771d 100644 --- a/tests/bluetooth/host/keys/bt_keys_foreach_type/CMakeLists.txt +++ b/tests/bluetooth/host/keys/bt_keys_foreach_type/CMakeLists.txt @@ -6,11 +6,16 @@ project(bt_keys_foreach_type) find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) target_link_libraries(testbinary PRIVATE mocks host_mocks) + target_sources(testbinary - PRIVATE + PRIVATE src/main.c src/test_suite_foreach_type_invalid_inputs.c + + # Unit under test + $ENV{ZEPHYR_BASE}/subsys/bluetooth/host/keys.c + $ENV{ZEPHYR_BASE}/subsys/bluetooth/common/addr.c ) diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_type/prj.conf b/tests/bluetooth/host/keys/bt_keys_foreach_type/prj.conf index 1fbdabaf1fa..c41ea9eec9d 100644 --- a/tests/bluetooth/host/keys/bt_keys_foreach_type/prj.conf +++ b/tests/bluetooth/host/keys/bt_keys_foreach_type/prj.conf @@ -6,3 +6,6 @@ CONFIG_BT_MAX_PAIRED=7 CONFIG_ASSERT=y CONFIG_ASSERT_LEVEL=2 CONFIG_ASSERT_VERBOSE=y +CONFIG_LOG=n +CONFIG_BT_DEBUG_LOG=n +CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/CMakeLists.txt b/tests/bluetooth/host/keys/bt_keys_get_addr/CMakeLists.txt index 85bf81081c1..c24f89b8859 100644 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/CMakeLists.txt +++ b/tests/bluetooth/host/keys/bt_keys_get_addr/CMakeLists.txt @@ -6,13 +6,20 @@ find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) project(bt_keys_get_addr) add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) -add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/keys/mocks mocks) target_link_libraries(testbinary PRIVATE mocks host_mocks) + target_sources(testbinary - PRIVATE + PRIVATE src/main.c src/test_suite_full_list_invalid_values.c src/test_suite_full_list_no_overwrite.c src/test_suite_full_list_overwrite_oldest.c + $ENV{ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c + $ENV{ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c + + # Unit under test + $ENV{ZEPHYR_BASE}/subsys/bluetooth/host/keys.c + $ENV{ZEPHYR_BASE}/subsys/bluetooth/common/addr.c ) diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/prj.conf b/tests/bluetooth/host/keys/bt_keys_get_addr/prj.conf index 89d6267d5b3..5a575943b32 100644 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/prj.conf +++ b/tests/bluetooth/host/keys/bt_keys_get_addr/prj.conf @@ -6,3 +6,6 @@ CONFIG_BT_MAX_PAIRED=4 CONFIG_ASSERT=y CONFIG_ASSERT_LEVEL=2 CONFIG_ASSERT_VERBOSE=y +CONFIG_LOG=n +CONFIG_BT_DEBUG_LOG=n +CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/src/main.c b/tests/bluetooth/host/keys/bt_keys_get_addr/src/main.c index 093ce967de2..8515f55b5b1 100644 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/src/main.c +++ b/tests/bluetooth/host/keys/bt_keys_get_addr/src/main.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include #include @@ -11,11 +12,24 @@ #include "mocks/conn.h" #include "mocks/hci_core.h" #include "mocks/keys_help_utils.h" -#include "host_mocks/print_utils.h" #include "testing_common_defs.h" +#include "common/bt_str.h" DEFINE_FFF_GLOBALS; +/* Define snprintk to use libc since we are not compiling the whole kernel. */ +int snprintk(char *str, size_t size, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = snprintf(str, size, fmt, ap); + va_end(ap); + + return ret; +} + /* This LUT contains different combinations of ID and Address pairs */ const struct id_addr_pair testing_id_addr_pair_lut[] = { { BT_ADDR_ID_1, BT_ADDR_LE_1 }, diff --git a/tests/bluetooth/host/keys/mocks/CMakeLists.txt b/tests/bluetooth/host/keys/mocks/CMakeLists.txt new file mode 100644 index 00000000000..761c87e9a48 --- /dev/null +++ b/tests/bluetooth/host/keys/mocks/CMakeLists.txt @@ -0,0 +1,21 @@ +# +# CMakeLists.txt file for creating of mocks library. +# + +add_library(mocks STATIC + id.c + rpa.c + conn.c + hci_core.c + hci_core_expects.c + keys_help_utils.c +) + +target_include_directories(mocks PUBLIC + .. + ${ZEPHYR_BASE}/tests/bluetooth/host + ${ZEPHYR_BASE}/subsys/bluetooth + ${ZEPHYR_BASE}/subsys/bluetooth/host +) + +target_link_libraries(mocks PRIVATE test_interface)