-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Bluetooth: Add BT Tester GAP smoke test
Add a babblesim test of the BT Tester doing a GAP smoke test connecting 2 BT testers using BTP. The purpose of this is to further increase the test coverage of the BT Tester in CI, as it is only being built, and runtime errors are typically not caught. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
- Loading branch information
Showing
16 changed files
with
345 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# CONFIG_TEST enforces minimal logging, which we don't want | ||
CONFIG_TEST=n | ||
|
||
CONFIG_ASSERT=y | ||
# Enable the option below to measure stack usage | ||
#CONFIG_INIT_STACKS=y | ||
CONFIG_THREAD_NAME=y | ||
|
||
CONFIG_LOG=y | ||
CONFIG_LOG_BACKEND_SHOW_COLOR=y | ||
|
||
CONFIG_LOG_DEFAULT_LEVEL=3 | ||
CONFIG_BTTESTER_LOG_LEVEL_DBG=y | ||
|
||
CONFIG_UART_PIPE=n |
24 changes: 24 additions & 0 deletions
24
tests/bluetooth/tester/boards/nrf5340bsim_nrf5340_cpuapp.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# CONFIG_TEST enforces minimal logging, which we don't want | ||
CONFIG_TEST=n | ||
|
||
CONFIG_ASSERT=y | ||
# Enable the option below to measure stack usage | ||
#CONFIG_INIT_STACKS=y | ||
CONFIG_THREAD_NAME=y | ||
CONFIG_HW_STACK_PROTECTION=y | ||
|
||
CONFIG_LOG=y | ||
CONFIG_LOG_BUFFER_SIZE=4096 | ||
CONFIG_RTT_CONSOLE=y | ||
CONFIG_LOG_BACKEND_RTT=y | ||
CONFIG_LOG_BACKEND_RTT_MODE_DROP=y | ||
CONFIG_LOG_BACKEND_RTT_MESSAGE_SIZE=256 | ||
CONFIG_USE_SEGGER_RTT=y | ||
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=4096 | ||
CONFIG_LOG_BACKEND_SHOW_COLOR=n | ||
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=1024 | ||
|
||
CONFIG_LOG_DEFAULT_LEVEL=3 | ||
CONFIG_BTTESTER_LOG_LEVEL_DBG=y | ||
|
||
CONFIG_UART_INTERRUPT_DRIVEN=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(tester_bsim) | ||
|
||
# Add the BSIM tester | ||
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/tester ${CMAKE_BINARY_DIR}/tester_build) | ||
|
||
# This contains babblesim-specific helpers, e.g. device synchronization. | ||
add_subdirectory(${ZEPHYR_BASE}/tests/bsim/babblekit babblekit) | ||
target_link_libraries(app PRIVATE babblekit) | ||
|
||
# Add the testlib | ||
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/common/testlib testlib) | ||
target_link_libraries(app PRIVATE testlib) | ||
|
||
zephyr_include_directories( | ||
${BSIM_COMPONENTS_PATH}/libUtilv1/src/ | ||
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/ | ||
) | ||
|
||
target_sources(app PRIVATE | ||
src/btp.c | ||
src/gap_central.c | ||
src/gap_peripheral.c | ||
src/test_main.c | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) 2024-2025 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
source "${ZEPHYR_BASE}/tests/bluetooth/tester/Kconfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) 2023-2025 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
source "${ZEPHYR_BASE}/tests/bluetooth/tester/Kconfig.sysbuild" | ||
|
||
config NATIVE_SIMULATOR_PRIMARY_MCU_INDEX | ||
int | ||
# Let's pass the test arguments to the application MCU test | ||
# otherwise by default they would have gone to the net core. | ||
default 0 if $(BOARD_TARGET_STRING) = "NRF5340BSIM_NRF5340_CPUAPP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2023-2025 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
#set -x #uncomment this line for debugging | ||
set -ue | ||
|
||
: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root directory}" | ||
|
||
source ${ZEPHYR_BASE}/tests/bsim/compile.source | ||
|
||
if [ "${BOARD_TS}" == "nrf5340bsim_nrf5340_cpuapp" ]; then | ||
app=tests/bsim/bluetooth/tester \ | ||
tester=${ZEPHYR_BASE}/tests/bluetooth/tester \ | ||
conf_file=${tester}/prj.conf \ | ||
extra_conf_file="${tester}/boards/nrf5340bsim_nrf5340_cpuapp.conf" \ | ||
exe_name=bs_${BOARD_TS}_${app}_prj_conf sysbuild=1 compile | ||
else | ||
app=tests/bsim/bluetooth/tester \ | ||
tester=${ZEPHYR_BASE}/tests/bluetooth/tester \ | ||
conf_file=${tester}/prj.conf \ | ||
extra_conf_file="${tester}/boards/nrf52_bsim.conf" \ | ||
exe_name=bs_${BOARD_TS}_${app}_prj_conf sysbuild=1 compile | ||
fi | ||
|
||
wait_for_background_jobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Please build using the sample configuration file: | ||
# ${ZEPHYR_BASE}/tests/bluetooth/tester/prj.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2025 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <string.h> | ||
|
||
#include <zephyr/drivers/uart_pipe.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/logging/log.h> | ||
#include <zephyr/sys/util.h> | ||
#include <zephyr/sys_clock.h> | ||
|
||
#include "babblekit/testcase.h" | ||
|
||
#include "btp.h" | ||
|
||
LOG_MODULE_REGISTER(bsim_btp, CONFIG_BTTESTER_LOG_LEVEL); | ||
|
||
static uint8_t *btp_buffer; | ||
static size_t btp_buffer_len; | ||
static uart_pipe_recv_cb btp_cb; | ||
|
||
static uint8_t rsp_buffer[1024]; | ||
static size_t rsp_buffer_len; | ||
static void wait_for_response(void) | ||
{ | ||
const uint64_t timeout_us = 10 * USEC_PER_SEC; | ||
struct btp_hdr *rsp_hdr; | ||
|
||
memset(rsp_buffer, 0, sizeof(rsp_buffer)); /* reset response buffer */ | ||
rsp_buffer_len = 0U; | ||
|
||
WAIT_FOR(rsp_buffer_len > sizeof(*rsp_hdr), timeout_us, k_msleep(1)); | ||
rsp_hdr = (struct btp_hdr *)rsp_buffer; | ||
if (rsp_hdr->len > 0) { | ||
WAIT_FOR(rsp_buffer_len > sizeof(*rsp_hdr) + rsp_hdr->len, timeout_us, k_msleep(1)); | ||
} | ||
rsp_buffer_len = 0U; | ||
} | ||
|
||
/* BTP communication is inspired from `uart_pipe_rx` to achieve a similar API */ | ||
void btp_send_to_tester(const uint8_t *data, size_t len) | ||
{ | ||
size_t offset = 0U; | ||
|
||
TEST_ASSERT(len > 0U); | ||
TEST_ASSERT(data != NULL); | ||
TEST_ASSERT(btp_buffer != NULL); | ||
TEST_ASSERT(len <= btp_buffer_len); | ||
|
||
memcpy(btp_buffer, data, len); | ||
|
||
btp_buffer = btp_cb(btp_buffer, &offset); | ||
TEST_ASSERT(offset == 0U); | ||
|
||
wait_for_response(); | ||
} | ||
|
||
void btp_register_tester(uint8_t *buffer, size_t len, uart_pipe_recv_cb cb) | ||
{ | ||
TEST_ASSERT(cb > 0U); | ||
TEST_ASSERT(len > 0U); | ||
TEST_ASSERT(buffer != NULL); | ||
|
||
btp_buffer = buffer; | ||
btp_buffer_len = len; | ||
btp_cb = cb; | ||
|
||
LOG_INF("%p %zu", buffer, len); | ||
} | ||
|
||
void btp_send_to_bsim(const uint8_t *data, size_t len) | ||
{ | ||
|
||
TEST_ASSERT(len > 0U); | ||
TEST_ASSERT(data != NULL); | ||
TEST_ASSERT(len <= ARRAY_SIZE(rsp_buffer)); | ||
|
||
/* TODO: Parse incoming data and call relevant handlers */ | ||
/* We will always get a `struct btp_hdr msg` first and then if len > 0 then some additional | ||
* data | ||
*/ | ||
LOG_ERR("%zu", len); | ||
memcpy(rsp_buffer + rsp_buffer_len, data, len); | ||
rsp_buffer_len += len; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2025 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <inttypes.h> | ||
#include <stdint.h> | ||
|
||
#include <zephyr/sys/util_macro.h> | ||
|
||
#include "babblekit/testcase.h" | ||
#include "bstests.h" | ||
|
||
#include "bttester.h" | ||
|
||
static void test_gap_central(void) | ||
{ | ||
TEST_PASS("PASSED\n"); | ||
} | ||
|
||
static const struct bst_test_instance test_sample[] = { | ||
{ | ||
.test_id = "gap_central", | ||
.test_descr = "Smoketest for the GAP central BT Tester behavior", | ||
.test_main_f = test_gap_central, | ||
}, | ||
BSTEST_END_MARKER, | ||
}; | ||
|
||
struct bst_test_list *test_gap_central_install(struct bst_test_list *tests) | ||
{ | ||
return bst_add_tests(tests, test_sample); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2025 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <inttypes.h> | ||
#include <stdint.h> | ||
|
||
#include <zephyr/sys/util_macro.h> | ||
|
||
#include "babblekit/testcase.h" | ||
#include "bstests.h" | ||
|
||
static void test_gap_peripheral(void) | ||
{ | ||
TEST_PASS("PASSED\n"); | ||
} | ||
|
||
static const struct bst_test_instance test_sample[] = { | ||
{ | ||
.test_id = "gap_peripheral", | ||
.test_descr = "Smoketest for the GAP central BT Tester behavior", | ||
.test_main_f = test_gap_peripheral, | ||
}, | ||
BSTEST_END_MARKER, | ||
}; | ||
|
||
struct bst_test_list *test_gap_peripheral_install(struct bst_test_list *tests) | ||
{ | ||
return bst_add_tests(tests, test_sample); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2025 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stddef.h> | ||
|
||
#include "bstests.h" | ||
|
||
extern struct bst_test_list *test_gap_central_install(struct bst_test_list *tests); | ||
extern struct bst_test_list *test_gap_peripheral_install(struct bst_test_list *tests); | ||
|
||
bst_test_install_t test_installers[] = { | ||
test_gap_central_install, | ||
test_gap_peripheral_install, | ||
NULL, | ||
}; | ||
|
||
/* bst_main will be called by the BT tester's `main` function */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright (c) 2023-2025 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
include(${ZEPHYR_BASE}/tests/bluetooth/tester/sysbuild.cmake) | ||
|
||
native_simulator_set_primary_mcu_index(${DEFAULT_IMAGE} ${NET_APP}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2023-2025 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Smoketest for GAP BTP commands with the BT tester | ||
|
||
simulation_id="tester_gap" | ||
verbosity_level=2 | ||
EXECUTE_TIMEOUT=20 | ||
|
||
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source | ||
|
||
cd ${BSIM_OUT_PATH}/bin | ||
|
||
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_tester_prj_conf \ | ||
-v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 -testid=gap_central | ||
|
||
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_tester_prj_conf \ | ||
-v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 -testid=gap_peripheral | ||
|
||
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ | ||
-D=2 -sim_length=20e6 $@ -argschannel -at=40 | ||
|
||
wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails |