Skip to content

Commit 1fbcc0e

Browse files
PavelVPVdleach02
authored andcommitted
tests: bluetooth: host: conn: Add bt_conn_le_create unit test
Add a test that checks behavior of CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE Kconfig option. Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
1 parent 8acb1cc commit 1fbcc0e

32 files changed

+734
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
7+
project(conn)
8+
9+
include_directories(BEFORE
10+
${ZEPHYR_BASE}/tests/bluetooth/host/conn
11+
${ZEPHYR_BASE}/tests/bluetooth/host/conn/mocks/zephyr/include
12+
)
13+
14+
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks)
15+
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/conn/mocks mocks)
16+
17+
target_link_libraries(testbinary PRIVATE mocks host_mocks)
18+
19+
target_sources(testbinary
20+
PRIVATE
21+
src/main.c
22+
23+
${ZEPHYR_BASE}/subsys/bluetooth/host/conn.c
24+
${ZEPHYR_BASE}/subsys/logging/log_minimal.c
25+
${ZEPHYR_BASE}/lib/net_buf/buf.c
26+
${ZEPHYR_BASE}/lib/net_buf/buf_simple.c
27+
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# CMakeLists.txt file for creating of mocks library.
3+
#
4+
5+
add_library(mocks STATIC
6+
addr_internal.c
7+
att_internal.c
8+
bt_str.c
9+
buf_view.c
10+
hci_core.c
11+
id.c
12+
kernel.c
13+
l2cap_internal.c
14+
scan.c
15+
smp.c
16+
spinlock.c
17+
sys_clock.c
18+
)
19+
20+
target_include_directories(mocks PUBLIC
21+
${ZEPHYR_BASE}/tests/bluetooth/host/conn/mocks
22+
${ZEPHYR_BASE}/subsys/bluetooth
23+
)
24+
25+
target_compile_options(test_interface INTERFACE -include ztest.h)
26+
target_link_libraries(mocks PRIVATE test_interface)
27+
target_link_options(mocks PUBLIC
28+
"SHELL:-T ${ZEPHYR_BASE}/tests/bluetooth/host/conn/mocks/mock-sections.ld"
29+
)
30+
31+
target_compile_options(mocks
32+
PRIVATE
33+
-DCONFIG_BT_ID_MAX=1
34+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
9+
#include "addr_internal.h"
10+
11+
DEFINE_FAKE_VOID_FUNC(bt_addr_le_copy_resolved, bt_addr_le_t *, const bt_addr_le_t *);
12+
DEFINE_FAKE_VALUE_FUNC(bool, bt_addr_le_is_resolved, const bt_addr_le_t *);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/fff.h>
9+
#include <zephyr/bluetooth/addr.h>
10+
11+
/* List of fakes used by this unit tester */
12+
#define ADDR_INTERNAL_MOCKS_FFF_FAKES_LIST(FAKE) \
13+
FAKE(bt_addr_le_copy_resolved) \
14+
FAKE(bt_addr_le_is_resolved)
15+
16+
DECLARE_FAKE_VOID_FUNC(bt_addr_le_copy_resolved, bt_addr_le_t *, const bt_addr_le_t *);
17+
DECLARE_FAKE_VALUE_FUNC(bool, bt_addr_le_is_resolved, const bt_addr_le_t *);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
9+
#include "att_internal.h"
10+
11+
DEFINE_FAKE_VOID_FUNC(bt_att_init);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/fff.h>
9+
10+
/* List of fakes used by this unit tester */
11+
#define ATT_INTERNAL_MOCKS_FFF_FAKES_LIST(FAKE) FAKE(bt_att_init)
12+
13+
DECLARE_FAKE_VOID_FUNC(bt_att_init);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/bluetooth/addr.h>
9+
10+
#include "bt_str.h"
11+
12+
const char *bt_addr_le_str(const bt_addr_le_t *addr)
13+
{
14+
static char str[BT_ADDR_LE_STR_LEN];
15+
16+
bt_addr_le_to_str(addr, str, sizeof(str));
17+
18+
return str;
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/bluetooth/addr.h>
9+
10+
const char *bt_addr_le_str(const bt_addr_le_t *addr);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
9+
#include "buf_view.h"
10+
11+
DEFINE_FAKE_VALUE_FUNC(bool, bt_buf_has_view, const struct net_buf *);
12+
DEFINE_FAKE_VALUE_FUNC(struct net_buf *, bt_buf_make_view, struct net_buf *, struct net_buf *,
13+
size_t, struct bt_buf_view_meta *);
14+
DEFINE_FAKE_VOID_FUNC(bt_buf_destroy_view, struct net_buf *, struct bt_buf_view_meta *);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/fff.h>
9+
10+
/* List of fakes used by this unit tester */
11+
#define BUF_VIEW_MOCKS_FFF_FAKES_LIST(FAKE) FAKE(bt_buf_has_view) \
12+
FAKE(bt_buf_make_view) \
13+
FAKE(bt_buf_destroy_view)
14+
15+
DECLARE_FAKE_VALUE_FUNC(bool, bt_buf_has_view, const struct net_buf *);
16+
DECLARE_FAKE_VALUE_FUNC(struct net_buf *, bt_buf_make_view, struct net_buf *, struct net_buf *,
17+
size_t, struct bt_buf_view_meta *);
18+
DECLARE_FAKE_VOID_FUNC(bt_buf_destroy_view, struct net_buf *, struct bt_buf_view_meta *);

0 commit comments

Comments
 (0)