Skip to content

Commit 931102c

Browse files
committed
Add channel sounding extended unit tests
1 parent f2a00a7 commit 931102c

File tree

13 files changed

+433
-1
lines changed

13 files changed

+433
-1
lines changed

ProjectAnalysisReport.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ Isto ponasanje je primeceno i kod heartrate aplikacije:
679679
680680
Nisu pronadjene greske u okviru samog primera nad kojim smo vrsili testiranje, vec samo ocekivane greske koje su suppressed. U heartrate aplikaciji, rucnom analizom vidimo da nema puno mesta na kojima se koristi dinamicka alokacija memorije. Jedan pokazivac koji se koristi jeste pokazivac na strukturu `bt_le_ext_adv` koja se pri podrazumevanoj konfiguraciji ni ne koristi. Da bismo pokrili i slucaj prosirenog oglasavanja (`BT_EXT_ADV`), ukljucicemo `CONFIG_BT_EXT_ADV` flag tako sto cemo `west build` komandi proslediti overlay fajl koji prosiruje konfiguraciju pomenutim flag-om (`-- -DOVERLAY_CONFIG=$ZEPHYR_BASE/samples/bluetooth/peripheral_hr/overlay-extended.conf`). Krajnji izvestaj je identican prethodnom, tako da zakljucujemo da je primer bezbedno implementiran.
681681
682-
##### valgrind helgrind
682+
##### valgrind callgrind
683683
684684
--- ;
685685
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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(bt_channel_sounding)
8+
9+
include_directories(BEFORE
10+
${ZEPHYR_BASE}/tests/bluetooth/host/cs/channel_sounding/mocks_unit_tests
11+
)
12+
13+
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks)
14+
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/cs/channel_sounding/mocks_unit_tests mocks)
15+
16+
target_link_libraries(testbinary PRIVATE mocks host_mocks)
17+
18+
target_sources(testbinary
19+
PRIVATE
20+
src/main.c
21+
22+
${ZEPHYR_BASE}/subsys/bluetooth/host/cs.c
23+
${ZEPHYR_BASE}/subsys/logging/log_minimal.c
24+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
add_library(mocks STATIC
4+
conn.c
5+
hci_core.c
6+
net_buf.c
7+
)
8+
9+
target_include_directories(mocks PUBLIC
10+
..
11+
${ZEPHYR_BASE}/subsys/bluetooth
12+
${ZEPHYR_BASE}/subsys/bluetooth/host
13+
${ZEPHYR_BASE}/tests/bluetooth/host
14+
${ZEPHYR_BASE}/tests/bluetooth/host/cs/mocks
15+
)
16+
17+
target_link_libraries(mocks PRIVATE test_interface)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "mocks_unit_tests/conn.h"
8+
9+
#include <zephyr/kernel.h>
10+
11+
DEFINE_FAKE_VOID_FUNC(bt_conn_unref, struct bt_conn *);
12+
DEFINE_FAKE_VALUE_FUNC(struct bt_conn *, bt_conn_lookup_handle, uint16_t, enum bt_conn_type);
13+
DEFINE_FAKE_VOID_FUNC(notify_remote_cs_capabilities, struct bt_conn *,
14+
struct bt_conn_le_cs_capabilities);
15+
DEFINE_FAKE_VOID_FUNC(notify_remote_cs_fae_table, struct bt_conn *, struct bt_conn_le_cs_fae_table);
16+
DEFINE_FAKE_VOID_FUNC(notify_cs_config_created, struct bt_conn *, struct bt_conn_le_cs_config *);
17+
DEFINE_FAKE_VOID_FUNC(notify_cs_config_removed, struct bt_conn *, uint8_t);
18+
DEFINE_FAKE_VOID_FUNC(notify_cs_subevent_result, struct bt_conn *,
19+
struct bt_conn_le_cs_subevent_result *);
20+
DEFINE_FAKE_VOID_FUNC(notify_cs_security_enable_available, struct bt_conn *);
21+
DEFINE_FAKE_VOID_FUNC(notify_cs_procedure_enable_available, struct bt_conn *,
22+
struct bt_conn_le_cs_procedure_enable_complete *);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/bluetooth/conn.h>
8+
#include <zephyr/fff.h>
9+
#include <zephyr/kernel.h>
10+
11+
#include <host/conn_internal.h>
12+
13+
/* List of fakes used by this unit tester */
14+
#define CONN_FFF_FAKES_LIST(FAKE) \
15+
FAKE(bt_conn_unref) \
16+
FAKE(bt_conn_lookup_handle) \
17+
FAKE(notify_remote_cs_capabilities) \
18+
FAKE(notify_cs_config_created) \
19+
FAKE(notify_cs_config_removed) \
20+
FAKE(notify_cs_subevent_result) \
21+
FAKE(notify_cs_security_enable_available) \
22+
FAKE(notify_cs_procedure_enable_available) \
23+
FAKE(notify_remote_cs_fae_table)
24+
25+
DECLARE_FAKE_VOID_FUNC(bt_conn_unref, struct bt_conn *);
26+
DECLARE_FAKE_VALUE_FUNC(struct bt_conn *, bt_conn_lookup_handle, uint16_t, enum bt_conn_type);
27+
DECLARE_FAKE_VOID_FUNC(notify_remote_cs_capabilities, struct bt_conn *,
28+
struct bt_conn_le_cs_capabilities);
29+
DECLARE_FAKE_VOID_FUNC(notify_remote_cs_fae_table, struct bt_conn *,
30+
struct bt_conn_le_cs_fae_table);
31+
DECLARE_FAKE_VOID_FUNC(notify_cs_config_created, struct bt_conn *, struct bt_conn_le_cs_config *);
32+
DECLARE_FAKE_VOID_FUNC(notify_cs_config_removed, struct bt_conn *, uint8_t);
33+
DECLARE_FAKE_VOID_FUNC(notify_cs_subevent_result, struct bt_conn *,
34+
struct bt_conn_le_cs_subevent_result *);
35+
DECLARE_FAKE_VOID_FUNC(notify_cs_security_enable_available, struct bt_conn *);
36+
DECLARE_FAKE_VOID_FUNC(notify_cs_procedure_enable_available, struct bt_conn *,
37+
struct bt_conn_le_cs_procedure_enable_complete *);
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 "mocks_unit_tests/hci_core.h"
8+
9+
#include <zephyr/bluetooth/hci.h>
10+
#include <zephyr/kernel.h>
11+
12+
DEFINE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_create, uint16_t, uint8_t);
13+
DEFINE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/fff.h>
8+
#include <zephyr/kernel.h>
9+
10+
/* List of fakes used by this unit tester */
11+
#define HCI_CORE_FFF_FAKES_LIST(FAKE) \
12+
FAKE(bt_hci_cmd_create) \
13+
FAKE(bt_hci_cmd_send_sync)
14+
15+
DECLARE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_create, uint16_t, uint8_t);
16+
DECLARE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **);
17+
18+
// Insert real function declarations - these functions are defined in hci_core.h, but implemented in cs.c that is our module-under-test
19+
void bt_hci_le_cs_read_remote_supported_capabilities_complete(struct net_buf *buf);
20+
// void bt_hci_le_cs_read_remote_fae_table_complete(struct net_buf *buf);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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/net_buf.h>
9+
10+
#include "mocks_unit_tests/net_buf.h"
11+
12+
const struct net_buf_data_cb net_buf_fixed_cb;
13+
14+
DEFINE_FAKE_VOID_FUNC(net_buf_unref, struct net_buf *);
15+
DEFINE_FAKE_VOID_FUNC(net_buf_reset, struct net_buf *);
16+
DEFINE_FAKE_VOID_FUNC(net_buf_slist_put, sys_slist_t *, struct net_buf *);
17+
DEFINE_FAKE_VALUE_FUNC(struct net_buf *, net_buf_alloc_fixed, struct net_buf_pool *, k_timeout_t);
18+
DEFINE_FAKE_VALUE_FUNC(void *, net_buf_simple_add, struct net_buf_simple *, size_t);
19+
DEFINE_FAKE_VALUE_FUNC(uint8_t *, net_buf_simple_add_u8, struct net_buf_simple *, uint8_t);
20+
DEFINE_FAKE_VOID_FUNC(net_buf_simple_add_le32, struct net_buf_simple *, uint32_t);
21+
DEFINE_FAKE_VALUE_FUNC(void *, net_buf_simple_add_mem, struct net_buf_simple *, const void *, size_t);
22+
DEFINE_FAKE_VALUE_FUNC(void *, net_buf_simple_pull_mem, struct net_buf_simple *, size_t);
23+
DEFINE_FAKE_VALUE_FUNC(size_t, net_buf_simple_tailroom, const struct net_buf_simple *);
24+
DEFINE_FAKE_VOID_FUNC(net_buf_simple_init_with_data, struct net_buf_simple *, void *, size_t);
25+
DEFINE_FAKE_VALUE_FUNC(uint8_t, net_buf_simple_pull_u8, struct net_buf_simple *);
26+
DEFINE_FAKE_VALUE_FUNC(void *, net_buf_simple_pull, struct net_buf_simple *, size_t);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/fff.h>
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/net_buf.h>
10+
11+
/* List of fakes used by this unit tester */
12+
#define NET_BUF_FFF_FAKES_LIST(FAKE) \
13+
FAKE(net_buf_unref) \
14+
FAKE(net_buf_reset) \
15+
FAKE(net_buf_slist_put) \
16+
FAKE(net_buf_alloc_fixed) \
17+
FAKE(net_buf_simple_add_mem) \
18+
FAKE(net_buf_simple_pull_mem) \
19+
FAKE(net_buf_simple_tailroom) \
20+
FAKE(net_buf_simple_init_with_data) \
21+
FAKE(net_buf_simple_pull_u8) \
22+
FAKE(net_buf_simple_pull) \
23+
FAKE(net_buf_simple_add) \
24+
FAKE(net_buf_simple_add_u8) \
25+
FAKE(net_buf_simple_add_le32)
26+
27+
28+
DECLARE_FAKE_VOID_FUNC(net_buf_unref, struct net_buf *);
29+
DECLARE_FAKE_VOID_FUNC(net_buf_reset, struct net_buf *);
30+
DECLARE_FAKE_VOID_FUNC(net_buf_slist_put, sys_slist_t *, struct net_buf *);
31+
DECLARE_FAKE_VALUE_FUNC(struct net_buf *, net_buf_alloc_fixed, struct net_buf_pool *, k_timeout_t);
32+
DECLARE_FAKE_VALUE_FUNC(void *, net_buf_simple_add, struct net_buf_simple *, size_t);
33+
DECLARE_FAKE_VALUE_FUNC(uint8_t *, net_buf_simple_add_u8, struct net_buf_simple *, uint8_t);
34+
DECLARE_FAKE_VOID_FUNC(net_buf_simple_add_le32, struct net_buf_simple *, uint32_t);
35+
DECLARE_FAKE_VALUE_FUNC(void *, net_buf_simple_add_mem, struct net_buf_simple *, const void *, size_t);
36+
DECLARE_FAKE_VALUE_FUNC(void *, net_buf_simple_pull_mem, struct net_buf_simple *, size_t);
37+
DECLARE_FAKE_VALUE_FUNC(size_t, net_buf_simple_tailroom, const struct net_buf_simple *);
38+
DECLARE_FAKE_VOID_FUNC(net_buf_simple_init_with_data, struct net_buf_simple *, void *, size_t);
39+
DECLARE_FAKE_VALUE_FUNC(uint8_t, net_buf_simple_pull_u8, struct net_buf_simple *);
40+
DECLARE_FAKE_VALUE_FUNC(void *, net_buf_simple_pull, struct net_buf_simple *, size_t);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_BT=y
3+
CONFIG_BT_HCI=y
4+
CONFIG_BT_CENTRAL=y
5+
CONFIG_BT_CHANNEL_SOUNDING=y
6+
CONFIG_ASSERT=y
7+
CONFIG_ASSERT_LEVEL=2
8+
CONFIG_ASSERT_VERBOSE=y
9+
CONFIG_ASSERT_ON_ERRORS=y
10+
CONFIG_NET_BUF=y

0 commit comments

Comments
 (0)