tests: bsim: Bluetooth: central_hr peripheral_hr coverage

Add bsim test coverage for central_hr and peripheral_hr
samples.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
Vinayak Kariappa Chettimada 2024-03-15 14:05:11 +01:00 committed by Fabio Baltieri
commit 12dc399c4d
16 changed files with 268 additions and 0 deletions

View file

@ -27,6 +27,8 @@ static struct bt_uuid_16 discover_uuid = BT_UUID_INIT_16(0);
static struct bt_gatt_discover_params discover_params; static struct bt_gatt_discover_params discover_params;
static struct bt_gatt_subscribe_params subscribe_params; static struct bt_gatt_subscribe_params subscribe_params;
uint64_t total_rx_count; /* This value is exposed to test code */
static uint8_t notify_func(struct bt_conn *conn, static uint8_t notify_func(struct bt_conn *conn,
struct bt_gatt_subscribe_params *params, struct bt_gatt_subscribe_params *params,
const void *data, uint16_t length) const void *data, uint16_t length)
@ -39,6 +41,8 @@ static uint8_t notify_func(struct bt_conn *conn,
printk("[NOTIFICATION] data %p length %u\n", data, length); printk("[NOTIFICATION] data %p length %u\n", data, length);
total_rx_count++;
return BT_GATT_ITER_CONTINUE; return BT_GATT_ITER_CONTINUE;
} }
@ -224,6 +228,8 @@ static void connected(struct bt_conn *conn, uint8_t conn_err)
printk("Connected: %s\n", addr); printk("Connected: %s\n", addr);
total_rx_count = 0U;
if (conn == default_conn) { if (conn == default_conn) {
memcpy(&discover_uuid, BT_UUID_HRS, sizeof(discover_uuid)); memcpy(&discover_uuid, BT_UUID_HRS, sizeof(discover_uuid));
discover_params.uuid = &discover_uuid.uuid; discover_params.uuid = &discover_uuid.uuid;

View file

@ -16,6 +16,7 @@ app=tests/bsim/bluetooth/ll/conn conf_file=prj_split_privacy.conf sysbuild=1 co
app=tests/bsim/bluetooth/ll/bis sysbuild=1 compile app=tests/bsim/bluetooth/ll/bis sysbuild=1 compile
app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group.conf sysbuild=1 compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group.conf sysbuild=1 compile
run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/samples/compile.sh
run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/audio_samples/compile.sh run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/audio_samples/compile.sh
wait_for_background_jobs wait_for_background_jobs

View file

@ -20,6 +20,7 @@ ${ZEPHYR_BASE}/tests/bsim/bluetooth/audio_samples/compile.sh
${ZEPHYR_BASE}/tests/bsim/bluetooth/host/compile.sh ${ZEPHYR_BASE}/tests/bsim/bluetooth/host/compile.sh
${ZEPHYR_BASE}/tests/bsim/bluetooth/ll/compile.sh ${ZEPHYR_BASE}/tests/bsim/bluetooth/ll/compile.sh
${ZEPHYR_BASE}/tests/bsim/bluetooth/mesh/compile.sh ${ZEPHYR_BASE}/tests/bsim/bluetooth/mesh/compile.sh
${ZEPHYR_BASE}/tests/bsim/bluetooth/samples/compile.sh
if [ ${BOARD} == "nrf52_bsim" ]; then if [ ${BOARD} == "nrf52_bsim" ]; then
${ZEPHYR_BASE}/tests/bsim/bluetooth/hci_uart/compile.sh ${ZEPHYR_BASE}/tests/bsim/bluetooth/hci_uart/compile.sh
fi fi

View file

@ -0,0 +1,24 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(central_hr_peripheral_hr_test)
set(central_hr_path ${ZEPHYR_BASE}/samples/bluetooth/central_hr)
target_sources(app PRIVATE
${central_hr_path}/src/main.c
)
target_sources(app PRIVATE
src/sample_test.c
src/test_main.c
)
zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)
zephyr_include_directories(
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
)

View file

@ -0,0 +1,10 @@
# Copyright (c) 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
# source sample's Kconfig, if any
# source "${ZEPHYR_BASE}/samples/bluetooth/central_hr/Kconfig"
# OR
# source Zephyr Kernel's Kconfig, as below (not both)
menu "Zephyr Kernel"
source "Kconfig.zephyr"
endmenu

View file

@ -0,0 +1,11 @@
# Copyright (c) 2023-2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
# source the samples' Kconfig.sysbuild, if any
source "${ZEPHYR_BASE}/samples/bluetooth/central_hr/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"

View file

@ -0,0 +1 @@
CONFIG_BT_BUF_ACL_RX_SIZE=255

View file

@ -0,0 +1,2 @@
# Please build using the sample configuration file:
# ${ZEPHYR_BASE}/samples/bluetooth/central_hr/prj.conf

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2023-2024 Nordic Semiconductor ASA
* Copyright (c) 2017-2019 Oticon A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "bs_types.h"
#include "bs_tracing.h"
#include "bs_utils.h"
#include "time_machine.h"
#include "bstests.h"
#define WAIT_TIME 10 /* Seconds */
#define PASS_THRESHOLD 5 /* packets */
extern enum bst_result_t bst_result;
#define FAIL(...) \
do { \
bst_result = Failed; \
bs_trace_error_time_line(__VA_ARGS__); \
} while (0)
#define PASS(...) \
do { \
bst_result = Passed; \
bs_trace_info_time(1, __VA_ARGS__); \
} while (0)
static void test_sample_init(void)
{
/* We set an absolute deadline in 30 seconds */
bst_ticker_set_next_tick_absolute(WAIT_TIME*1e6);
bst_result = In_progress;
}
static void test_sample_tick(bs_time_t HW_device_time)
{
/*
* If in WAIT_TIME seconds we did not get enough packets through
* we consider the test failed
*/
extern uint64_t total_rx_count;
bs_trace_info_time(2, "%"PRIu64" packets received, expected >= %i\n",
total_rx_count, PASS_THRESHOLD);
if (total_rx_count >= PASS_THRESHOLD) {
PASS("PASSED\n");
bs_trace_exit("Done, disconnecting from simulation\n");
} else {
FAIL("FAILED (Did not pass after %i seconds)\n", WAIT_TIME);
}
}
static const struct bst_test_instance test_sample[] = {
{
.test_id = "central_hr_peripheral_hr",
.test_descr = "Test based on the peripheral and central HR samples. "
"It expects to be connected to a compatible sample, "
"waits for " STR(WAIT_TIME) " seconds, and checks how "
"many packets have been received correctly",
.test_post_init_f = test_sample_init,
.test_tick_f = test_sample_tick,
},
BSTEST_END_MARKER
};
struct bst_test_list *test_sample_install(struct bst_test_list *tests)
{
tests = bst_add_tests(tests, test_sample);
return tests;
}

View file

@ -0,0 +1,14 @@
/*
* Copyright (c) 2023-2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "bstests.h"
extern struct bst_test_list *test_sample_install(struct bst_test_list *tests);
bst_test_install_t test_installers[] = {
test_sample_install,
NULL
};

View file

@ -0,0 +1,6 @@
# Copyright (c) 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
include(${ZEPHYR_BASE}/samples/bluetooth/central_hr/sysbuild.cmake)
native_simulator_set_primary_mcu_index(${DEFAULT_IMAGE} ${NET_APP})

View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Copyright 2023-2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
simulation_id="central_hr_peripheral_hr_test"
verbosity_level=2
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
EXECUTE_TIMEOUT=10
cd ${BSIM_OUT_PATH}/bin
Execute ./bs_${BOARD_TS}_samples_bluetooth_peripheral_hr_prj_conf \
-v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_samples_central_hr_peripheral_hr_prj_conf \
-v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \
-testid=central_hr_peripheral_hr
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \
-D=2 -sim_length=10e6 $@
wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails

View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Copyright 2023-2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
simulation_id="central_hr_peripheral_hr_extended_test"
test_long_name="$(guess_test_long_name)"
verbosity_level=2
EXECUTE_TIMEOUT=10
cd ${BSIM_OUT_PATH}/bin
Execute ./bs_${BOARD_TS}_samples_bluetooth_peripheral_hr_prj_conf_overlay-extended_conf \
-v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1
Execute ./bs_${BOARD_TS}_${test_long_name}_prj_conf_overlay-extended_conf \
-v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \
-testid=central_hr_peripheral_hr
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \
-D=2 -sim_length=10e6 $@
wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails

View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Copyright 2023-2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
simulation_id="central_hr_peripheral_hr_phy_coded_test"
test_long_name="$(guess_test_long_name)"
verbosity_level=2
EXECUTE_TIMEOUT=10
cd ${BSIM_OUT_PATH}/bin
Execute ./bs_${BOARD_TS}_samples_bluetooth_peripheral_hr_prj_conf_overlay-phy_coded_conf \
-v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1
Execute ./bs_${BOARD_TS}_${test_long_name}_prj_conf_overlay-phy_coded_conf \
-v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \
-testid=central_hr_peripheral_hr
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \
-D=2 -sim_length=10e6 $@
wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails

View file

@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Copyright 2023-2024 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}"
source ${ZEPHYR_BASE}/tests/bsim/compile.source
app=samples/bluetooth/peripheral_hr \
sysbuild=1 \
compile
app=tests/bsim/bluetooth/samples/central_hr_peripheral_hr \
sysbuild=1 \
extra_conf_file=${ZEPHYR_BASE}/samples/bluetooth/central_hr/prj.conf \
compile
app=samples/bluetooth/peripheral_hr \
sysbuild=1 \
conf_overlay=overlay-extended.conf \
compile
app=tests/bsim/bluetooth/samples/central_hr_peripheral_hr \
sysbuild=1 \
extra_conf_file=${ZEPHYR_BASE}/samples/bluetooth/central_hr/prj.conf \
conf_overlay=${ZEPHYR_BASE}/samples/bluetooth/central_hr/overlay-extended.conf \
compile
app=samples/bluetooth/peripheral_hr \
sysbuild=1 \
conf_overlay=overlay-phy_coded.conf \
compile
app=tests/bsim/bluetooth/samples/central_hr_peripheral_hr \
sysbuild=1 \
extra_conf_file=${ZEPHYR_BASE}/samples/bluetooth/central_hr/prj.conf \
conf_overlay=${ZEPHYR_BASE}/samples/bluetooth/central_hr/overlay-phy_coded.conf \
compile
wait_for_background_jobs

View file

@ -2,4 +2,5 @@
# This file is used in CI to select which tests are run # This file is used in CI to select which tests are run
tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh
tests/bsim/bluetooth/ll/bis/tests_scripts/broadcast_iso.sh tests/bsim/bluetooth/ll/bis/tests_scripts/broadcast_iso.sh
tests/bsim/bluetooth/samples/
tests/bsim/bluetooth/audio_samples/ tests/bsim/bluetooth/audio_samples/