Skip to content

Commit

Permalink
bluetooth: controller: mocks as a library
Browse files Browse the repository at this point in the history
specify the mocks and the helper routines as a library
instead of adding them to the file list

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
  • Loading branch information
kruithofa committed Dec 8, 2022
1 parent 9c97471 commit 6e8c053
Show file tree
Hide file tree
Showing 22 changed files with 140 additions and 8 deletions.
23 changes: 23 additions & 0 deletions tests/bluetooth/controller/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# CMakeLists.txt file for creating of mocks library.
#

add_library(common STATIC
src/helper_pdu.c
src/helper_util.c
)

target_include_directories(common PUBLIC
${ZEPHYR_BASE}/tests/bluetooth/controller/common/include
${ZEPHYR_BASE}/subsys/bluetooth/controller/include
${ZEPHYR_BASE}/subsys/bluetooth/controller/util
${ZEPHYR_BASE}/subsys/bluetooth/controller
${ZEPHYR_BASE}/subsys/bluetooth
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic/lll
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic
${ZEPHYR_BASE}/include/zephyr/bluetooth

)

target_link_libraries(common PRIVATE test_interface)
2 changes: 1 addition & 1 deletion tests/bluetooth/controller/common/src/helper_pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "zephyr/types.h"
#include "ztest.h"
#include "zephyr/ztest.h"

#include <zephyr/bluetooth/hci.h>
#include <zephyr/sys/byteorder.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/bluetooth/controller/common/src/helper_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "zephyr/types.h"
#include "ztest.h"
#include "zephyr/ztest.h"
#include <stdlib.h>

#include <zephyr/bluetooth/hci.h>
Expand Down
37 changes: 37 additions & 0 deletions tests/bluetooth/controller/common/unit_sources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Common include directories and source files for bluetooth unit tests
#

include_directories(
src
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include
${ZEPHYR_BASE}/tests/bluetooth/controller/common/include
${ZEPHYR_BASE}/include/zephyr/bluetooth
${ZEPHYR_BASE}/subsys/bluetooth
${ZEPHYR_BASE}/subsys/bluetooth/controller
${ZEPHYR_BASE}/subsys/bluetooth/controller/util
${ZEPHYR_BASE}/subsys/bluetooth/controller/include
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic/lll
)

FILE(GLOB unit_sources
${ZEPHYR_BASE}/subsys/bluetooth/controller/util/mem.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/util/memq.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_chan.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_tx_queue.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_local.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_remote.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_pdu.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_common.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_phy.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_enc.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_conn_upd.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_chmu.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_llcp.c
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/ull_conn.c
)

add_definitions(-include ztest.h)
13 changes: 9 additions & 4 deletions tests/bluetooth/controller/ctrl_feature_exchange/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ cmake_minimum_required(VERSION 3.20.0)

project(bluetooth_ull_llcp_feature_exchange)
find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE})
include(${ZEPHYR_BASE}/tests/bluetooth/controller/common/defaults_cmake.txt)

add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/controller/common common)
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl mocks)

target_link_libraries(testbinary PRIVATE mocks common)

include(${ZEPHYR_BASE}/tests/bluetooth/controller/common/unit_sources.txt)

target_sources(testbinary
PRIVATE
src/main.c
src/main_hci.c
${ll_sw_sources}
${mock_sources}
${common_sources}
${unit_sources}
)
8 changes: 8 additions & 0 deletions tests/bluetooth/controller/ctrl_feature_exchange/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ config BT_CTLR_PHY_UPDATE_SUPPORT
bool
default y

config BT_CTLR_PHY_CODED_SUPPORT
bool
default y

config BT_CTLR_PHY_2M_SUPPORT
bool
default y

config ENTROPY_NRF_FORCE_ALT
bool
default n
Expand Down
2 changes: 2 additions & 0 deletions tests/bluetooth/controller/ctrl_feature_exchange/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ CONFIG_BT_HCI=y
CONFIG_BT_CTLR=y
CONFIG_BT_LL_SW_SPLIT=y

CONFIG_BT_LLL_VENDOR_NORDIC=y

CONFIG_BT_CENTRAL=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_CTLR_PERIPHERAL_ISO=y
Expand Down
39 changes: 39 additions & 0 deletions tests/bluetooth/controller/mock_ctrl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# CMakeLists.txt file for creating of mocks library.
#

add_library(mocks STATIC
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/kernel.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/ecb.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/mayfly.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/lll.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/lll_conn.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/ll_assert.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/assert.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/util.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/ticker.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/ull.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/ull_conn_iso.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/ull_peripheral.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/ull_peripheral_iso.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/ull_central.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/ull_scan.c
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/lll_clock.c
)


target_include_directories(mocks PUBLIC
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include
${ZEPHYR_BASE}/subsys/bluetooth/controller/include
${ZEPHYR_BASE}/subsys/bluetooth/controller/util
${ZEPHYR_BASE}/subsys/bluetooth/controller
${ZEPHYR_BASE}/subsys/bluetooth
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic/lll
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic
${ZEPHYR_BASE}/include/zephyr/bluetooth

)

target_link_libraries(mocks PRIVATE test_interface)

1 change: 1 addition & 0 deletions tests/bluetooth/controller/mock_ctrl/src/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/ztest.h>
#include <zephyr/kernel.h>
#include "assert.h"

Expand Down
2 changes: 2 additions & 0 deletions tests/bluetooth/controller/mock_ctrl/src/ecb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <zephyr/ztest.h>
#include "hal/ecb.h"

__attribute__((weak)) void ecb_encrypt(uint8_t const *const key_le,
Expand Down
4 changes: 2 additions & 2 deletions tests/bluetooth/controller/mock_ctrl/src/ll_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "zephyr/types.h"
#include "ztest.h"
#include <zephyr/types.h>
#include <zephyr/ztest.h>
#include <stdlib.h>

void bt_ctlr_assert_handle(char *file, uint32_t line)
Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/controller/mock_ctrl/src/lll_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <zephyr/types.h>
#include <zephyr/ztest.h>
#include <soc.h>

#include "hal/debug.h"
Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/controller/mock_ctrl/src/lll_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <zephyr/toolchain.h>
#include <zephyr/types.h>
#include <zephyr/ztest.h>
#include <zephyr/sys/util.h>

#include "hal/cpu.h"
Expand Down
2 changes: 2 additions & 0 deletions tests/bluetooth/controller/mock_ctrl/src/mayfly.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/types.h>
#include <zephyr/ztest.h>
#include "memq.h"
#include "mayfly.h"

Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/controller/mock_ctrl/src/ticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include <zephyr/types.h>
#include <zephyr/ztest.h>

#include "ticker/ticker.h"

Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/controller/mock_ctrl/src/ull.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <zephyr/types.h>
#include <zephyr/ztest.h>

#include <zephyr/bluetooth/hci.h>

Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/controller/mock_ctrl/src/ull_central.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "zephyr/types.h"
#include <zephyr/ztest.h>
#include "util/util.h"
#include "util/mem.h"
#include "util/memq.h"
Expand Down
2 changes: 2 additions & 0 deletions tests/bluetooth/controller/mock_ctrl/src/ull_conn_iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/ztest.h>

#include <zephyr/kernel.h>

#include "hal/ccm.h"
Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/controller/mock_ctrl/src/ull_peripheral.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "zephyr/types.h"
#include <zephyr/ztest.h>
#include "util/util.h"
#include "util/mem.h"
#include "util/memq.h"
Expand Down
2 changes: 2 additions & 0 deletions tests/bluetooth/controller/mock_ctrl/src/ull_peripheral_iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/ztest.h>

#include <zephyr/kernel.h>
#include <zephyr/bluetooth/buf.h>
#include <zephyr/sys/byteorder.h>
Expand Down
2 changes: 2 additions & 0 deletions tests/bluetooth/controller/mock_ctrl/src/ull_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* SPDX-License-Identifier: Apache-2.0
*/


#include <zephyr/types.h>
#include <zephyr/ztest.h>

#include "hci_err.h"
#include "util/mem.h"
Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/controller/mock_ctrl/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <zephyr/types.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/ztest.h>
#include "util.h"
#include "pdu.h"

Expand Down

0 comments on commit 6e8c053

Please sign in to comment.