-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: Bluetooth: Add BT Tester GAP smoke test #86146
Open
Thalley
wants to merge
1
commit into
zephyrproject-rtos:main
Choose a base branch
from
Thalley:bttester_bsim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+645
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For reviewers: Should we place the BSIM board files in the test instead of the BT Tester directory? |
||
CONFIG_TEST=n | ||
|
||
CONFIG_ASSERT=y | ||
CONFIG_THREAD_NAME=y | ||
|
||
CONFIG_LOG=y | ||
CONFIG_LOG_BACKEND_SHOW_COLOR=y | ||
CONFIG_LOG_FUNC_NAME_PREFIX_ERR=y | ||
CONFIG_LOG_FUNC_NAME_PREFIX_WRN=y | ||
|
||
CONFIG_LOG_DEFAULT_LEVEL=3 | ||
CONFIG_BTTESTER_LOG_LEVEL_DBG=y | ||
|
||
CONFIG_UART_PIPE=n |
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
# CONFIG_TEST enforces minimal logging, which we don't want | ||
CONFIG_TEST=n | ||
|
||
CONFIG_ASSERT=y | ||
CONFIG_THREAD_NAME=y | ||
|
||
CONFIG_LOG=y | ||
CONFIG_LOG_BACKEND_SHOW_COLOR=y | ||
CONFIG_LOG_FUNC_NAME_PREFIX_ERR=y | ||
CONFIG_LOG_FUNC_NAME_PREFIX_WRN=y | ||
|
||
CONFIG_LOG_DEFAULT_LEVEL=3 | ||
CONFIG_BTTESTER_LOG_LEVEL_DBG=y | ||
|
||
CONFIG_UART_PIPE=n |
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 |
---|---|---|
|
@@ -87,6 +87,8 @@ | |
|
||
#define BTP_STATUS_VAL(err) (err) ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS | ||
|
||
#define BTP_EVENT_OPCODE 0x80 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
/* TODO indicate delay response, should be removed when all commands are | ||
* converted to cmd+status+ev pattern | ||
*/ | ||
|
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
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,31 @@ | ||
# 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/ | ||
) | ||
|
||
zephyr_include_directories(src/) | ||
|
||
target_sources(app PRIVATE | ||
src/btp.c | ||
src/test_main.c | ||
src/gap/gap_central.c | ||
src/gap/gap_peripheral.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,12 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2025 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Compile all the applications needed by the bsim tests in these subfolders | ||
|
||
#set -x #uncomment this line for debugging | ||
set -ue | ||
|
||
: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root directory}" | ||
|
||
west twister -T ${ZEPHYR_BASE}/tests/bsim/bluetooth/tester/ |
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,156 @@ | ||
/* | ||
* Copyright (c) 2025 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <zephyr/bluetooth/addr.h> | ||
#include <zephyr/net_buf.h> | ||
|
||
#include "btp/btp.h" | ||
|
||
void bsim_btp_send_to_tester(const uint8_t *data, size_t len); | ||
void bsim_btp_wait_for_evt(uint8_t service, uint8_t opcode, struct net_buf **out_buf); | ||
|
||
static inline void bsim_btp_core_register(uint8_t id) | ||
{ | ||
|
||
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU); | ||
|
||
struct btp_hdr *cmd_hdr; | ||
struct btp_core_register_service_cmd *cmd; | ||
|
||
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr)); | ||
cmd_hdr->service = BTP_SERVICE_ID_CORE; | ||
cmd_hdr->opcode = BTP_CORE_REGISTER_SERVICE; | ||
cmd_hdr->index = BTP_INDEX_NONE; | ||
cmd = net_buf_simple_add(&cmd_buffer, sizeof(*cmd)); | ||
cmd->id = id; | ||
|
||
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr); | ||
|
||
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len); | ||
} | ||
|
||
static inline void bsim_btp_gap_set_discoverable(uint8_t discoverable) | ||
{ | ||
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU); | ||
|
||
struct btp_hdr *cmd_hdr; | ||
struct btp_gap_set_discoverable_cmd *cmd; | ||
|
||
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr)); | ||
cmd_hdr->service = BTP_SERVICE_ID_GAP; | ||
cmd_hdr->opcode = BTP_GAP_SET_DISCOVERABLE; | ||
cmd_hdr->index = BTP_INDEX; | ||
cmd = net_buf_simple_add(&cmd_buffer, sizeof(*cmd)); | ||
cmd->discoverable = discoverable; | ||
|
||
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr); | ||
|
||
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len); | ||
} | ||
|
||
static inline void bsim_btp_gap_start_advertising(uint8_t adv_data_len, uint8_t scan_rsp_len, | ||
const uint8_t adv_sr_data[], uint32_t duration, | ||
uint8_t own_addr_type) | ||
{ | ||
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU); | ||
|
||
struct btp_hdr *cmd_hdr; | ||
struct btp_gap_start_advertising_cmd *cmd; | ||
|
||
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr)); | ||
cmd_hdr->service = BTP_SERVICE_ID_GAP; | ||
cmd_hdr->opcode = BTP_GAP_START_ADVERTISING; | ||
cmd_hdr->index = BTP_INDEX; | ||
cmd = net_buf_simple_add(&cmd_buffer, sizeof(*cmd)); | ||
cmd->adv_data_len = adv_data_len; | ||
cmd->scan_rsp_len = scan_rsp_len; | ||
if (adv_data_len > 0U) { | ||
net_buf_simple_add_mem(&cmd_buffer, adv_sr_data, adv_data_len); | ||
} | ||
if (scan_rsp_len > 0U) { | ||
net_buf_simple_add_mem(&cmd_buffer, adv_sr_data, scan_rsp_len); | ||
} | ||
net_buf_simple_add_le32(&cmd_buffer, duration); | ||
net_buf_simple_add_u8(&cmd_buffer, own_addr_type); | ||
|
||
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr); | ||
|
||
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len); | ||
} | ||
|
||
static inline void bsim_btp_gap_start_discovery(uint8_t flags) | ||
{ | ||
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU); | ||
|
||
struct btp_hdr *cmd_hdr; | ||
struct btp_gap_start_discovery_cmd *cmd; | ||
|
||
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr)); | ||
cmd_hdr->service = BTP_SERVICE_ID_GAP; | ||
cmd_hdr->opcode = BTP_GAP_START_DISCOVERY; | ||
cmd_hdr->index = BTP_INDEX; | ||
cmd = net_buf_simple_add(&cmd_buffer, sizeof(*cmd)); | ||
cmd->flags = flags; | ||
|
||
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr); | ||
|
||
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len); | ||
} | ||
|
||
static inline void bsim_btp_gap_stop_discovery(void) | ||
{ | ||
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU); | ||
|
||
struct btp_hdr *cmd_hdr; | ||
|
||
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr)); | ||
cmd_hdr->service = BTP_SERVICE_ID_GAP; | ||
cmd_hdr->opcode = BTP_GAP_STOP_DISCOVERY; | ||
cmd_hdr->index = BTP_INDEX; | ||
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr); | ||
|
||
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len); | ||
} | ||
|
||
static inline void bsim_btp_gap_connect(const bt_addr_le_t *address, uint8_t own_addr_type) | ||
{ | ||
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU); | ||
|
||
struct btp_hdr *cmd_hdr; | ||
struct btp_gap_connect_cmd *cmd; | ||
|
||
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr)); | ||
cmd_hdr->service = BTP_SERVICE_ID_GAP; | ||
cmd_hdr->opcode = BTP_GAP_CONNECT; | ||
cmd_hdr->index = BTP_INDEX; | ||
cmd = net_buf_simple_add(&cmd_buffer, sizeof(*cmd)); | ||
bt_addr_le_copy(&cmd->address, address); | ||
cmd->own_addr_type = own_addr_type; | ||
|
||
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr); | ||
|
||
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len); | ||
} | ||
|
||
static inline void bsim_btp_gap_disconnect(const bt_addr_le_t *address) | ||
{ | ||
NET_BUF_SIMPLE_DEFINE(cmd_buffer, BTP_MTU); | ||
|
||
struct btp_hdr *cmd_hdr; | ||
struct btp_gap_disconnect_cmd *cmd; | ||
|
||
cmd_hdr = net_buf_simple_add(&cmd_buffer, sizeof(*cmd_hdr)); | ||
cmd_hdr->service = BTP_SERVICE_ID_GAP; | ||
cmd_hdr->opcode = BTP_GAP_DISCONNECT; | ||
cmd_hdr->index = BTP_INDEX; | ||
cmd = net_buf_simple_add(&cmd_buffer, sizeof(*cmd)); | ||
bt_addr_le_copy(&cmd->address, address); | ||
|
||
cmd_hdr->len = cmd_buffer.len - sizeof(*cmd_hdr); | ||
|
||
bsim_btp_send_to_tester(cmd_buffer.data, cmd_buffer.len); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reviewers: Should we just always include this? Would allow us to use
IS_ENABLED
and include BSIM header files without the guardThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may not have understood the question, but
BSIM_COMPONENTS_PATH
won't be defined when not building for an nrf*bsim target. So this-I
would be pointing to missing directories. And even if it were, users building for other targets may not have a bsim installation so they wouldn't be able to include bsim headers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we do need the guard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so :)