tests: bsim: bluetooth: Refactor MTU Update test
To isolate Central and Peripheral in two separate builds. Signed-off-by: Luis Ubieda <luisf@croxel.com>
This commit is contained in:
parent
775cd201c3
commit
75f70c4636
8 changed files with 139 additions and 53 deletions
|
@ -5,12 +5,18 @@ cmake_minimum_required(VERSION 3.20.0)
|
||||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
project(bsim_test_mtu_update)
|
project(bsim_test_mtu_update)
|
||||||
|
|
||||||
target_sources(app PRIVATE
|
target_include_directories(app PRIVATE src)
|
||||||
src/main.c
|
|
||||||
${ZEPHYR_BASE}/samples/bluetooth/mtu_update/central/src/central_mtu_update.c
|
target_sources_ifdef(CONFIG_BT_PERIPHERAL app PRIVATE
|
||||||
|
src/main_peripheral.c
|
||||||
${ZEPHYR_BASE}/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c
|
${ZEPHYR_BASE}/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_sources_ifdef(CONFIG_BT_CENTRAL app PRIVATE
|
||||||
|
src/main_central.c
|
||||||
|
${ZEPHYR_BASE}/samples/bluetooth/mtu_update/central/src/central_mtu_update.c
|
||||||
|
)
|
||||||
|
|
||||||
zephyr_include_directories(
|
zephyr_include_directories(
|
||||||
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
|
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
|
||||||
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
|
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
|
||||||
|
|
|
@ -8,6 +8,7 @@ set -eu
|
||||||
INCR_BUILD=1
|
INCR_BUILD=1
|
||||||
source ${ZEPHYR_BASE}/tests/bsim/compile.source
|
source ${ZEPHYR_BASE}/tests/bsim/compile.source
|
||||||
|
|
||||||
app="$(guess_test_relpath)" compile
|
app="$(guess_test_relpath)" conf_file=prj_central.conf compile
|
||||||
|
app="$(guess_test_relpath)" conf_file=prj_peripheral.conf compile
|
||||||
|
|
||||||
wait_for_background_jobs
|
wait_for_background_jobs
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
CONFIG_BT=y
|
CONFIG_BT=y
|
||||||
CONFIG_BT_CENTRAL=y
|
CONFIG_BT_CENTRAL=y
|
||||||
CONFIG_BT_PERIPHERAL=y
|
|
||||||
CONFIG_BT_DEVICE_NAME="MTU Update Test"
|
CONFIG_BT_DEVICE_NAME="MTU Update Test"
|
||||||
|
|
||||||
CONFIG_BT_GATT_CLIENT=y
|
CONFIG_BT_GATT_CLIENT=y
|
13
tests/bsim/bluetooth/host/att/mtu_update/prj_peripheral.conf
Normal file
13
tests/bsim/bluetooth/host/att/mtu_update/prj_peripheral.conf
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
CONFIG_BT=y
|
||||||
|
CONFIG_BT_PERIPHERAL=y
|
||||||
|
CONFIG_BT_DEVICE_NAME="MTU Update Test"
|
||||||
|
|
||||||
|
# HCI ACL buffers size
|
||||||
|
# BT_L2CAP_RX_MTU = CONFIG_BT_BUF_ACL_RX_SIZE - BT_L2CAP_HDR_SIZE
|
||||||
|
CONFIG_BT_BUF_ACL_RX_SIZE=251
|
||||||
|
|
||||||
|
# L2CAP SDU/PDU TX MTU
|
||||||
|
CONFIG_BT_L2CAP_TX_MTU=247
|
||||||
|
|
||||||
|
CONFIG_LOG=y
|
||||||
|
CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y
|
37
tests/bsim/bluetooth/host/att/mtu_update/src/common.h
Normal file
37
tests/bsim/bluetooth/host/att/mtu_update/src/common.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Common functions and helpers for MTU Update test
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "bs_types.h"
|
||||||
|
#include "bs_tracing.h"
|
||||||
|
#include "bstests.h"
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
||||||
|
extern enum bst_result_t bst_result;
|
||||||
|
|
||||||
|
#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false
|
||||||
|
#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true)
|
||||||
|
#define WAIT_FOR_FLAG(flag) \
|
||||||
|
while (!(bool)atomic_get(&flag)) { \
|
||||||
|
(void)k_sleep(K_MSEC(1)); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define WAIT_TIME (20e6) /* 20 seconds */
|
||||||
|
#define PERIPHERAL_NOTIFY_TIME ((WAIT_TIME - 10e6) / 1e6)
|
|
@ -14,40 +14,13 @@
|
||||||
|
|
||||||
#include <zephyr/bluetooth/gatt.h>
|
#include <zephyr/bluetooth/gatt.h>
|
||||||
|
|
||||||
#include "bs_types.h"
|
#include "common.h"
|
||||||
#include "bs_tracing.h"
|
|
||||||
#include "time_machine.h"
|
#include "time_machine.h"
|
||||||
#include "bstests.h"
|
|
||||||
|
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
LOG_MODULE_REGISTER(bt_bsim_mtu_update, LOG_LEVEL_DBG);
|
LOG_MODULE_REGISTER(bt_bsim_mtu_update, LOG_LEVEL_DBG);
|
||||||
|
|
||||||
extern void run_central_sample(void *cb);
|
extern void run_central_sample(void *cb);
|
||||||
extern void run_peripheral_sample(uint8_t *notify_data, size_t notify_data_size, uint16_t seconds);
|
|
||||||
|
|
||||||
#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)
|
|
||||||
|
|
||||||
extern enum bst_result_t bst_result;
|
|
||||||
|
|
||||||
#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false
|
|
||||||
#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true)
|
|
||||||
#define WAIT_FOR_FLAG(flag) \
|
|
||||||
while (!(bool)atomic_get(&flag)) { \
|
|
||||||
(void)k_sleep(K_MSEC(1)); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define WAIT_TIME (20e6) /* 20 seconds */
|
|
||||||
#define PERIPHERAL_NOTIFY_TIME ((WAIT_TIME - 10e6) / 1e6)
|
|
||||||
|
|
||||||
CREATE_FLAG(flag_notification_received);
|
CREATE_FLAG(flag_notification_received);
|
||||||
uint8_t notify_data[100] = {};
|
uint8_t notify_data[100] = {};
|
||||||
|
@ -84,16 +57,6 @@ static void test_central_main(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_peripheral_main(void)
|
|
||||||
{
|
|
||||||
notify_data[13] = 0x7f;
|
|
||||||
notify_data[99] = 0x55;
|
|
||||||
|
|
||||||
run_peripheral_sample(notify_data, sizeof(notify_data), PERIPHERAL_NOTIFY_TIME);
|
|
||||||
|
|
||||||
PASS("MTU Update test passed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_tick(bs_time_t HW_device_time)
|
void test_tick(bs_time_t HW_device_time)
|
||||||
{
|
{
|
||||||
if (bst_result != Passed) {
|
if (bst_result != Passed) {
|
||||||
|
@ -115,13 +78,6 @@ static const struct bst_test_instance test_def[] = {
|
||||||
.test_tick_f = test_tick,
|
.test_tick_f = test_tick,
|
||||||
.test_main_f = test_central_main
|
.test_main_f = test_central_main
|
||||||
},
|
},
|
||||||
{
|
|
||||||
.test_id = "peripheral",
|
|
||||||
.test_descr = "Peripheral GATT MTU Update",
|
|
||||||
.test_pre_init_f = test_mtu_update_init,
|
|
||||||
.test_tick_f = test_tick,
|
|
||||||
.test_main_f = test_peripheral_main
|
|
||||||
},
|
|
||||||
BSTEST_END_MARKER
|
BSTEST_END_MARKER
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Nordic Semiconductor
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
|
||||||
|
#include <zephyr/sys/printk.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "time_machine.h"
|
||||||
|
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(bt_bsim_mtu_update, LOG_LEVEL_DBG);
|
||||||
|
|
||||||
|
extern void run_peripheral_sample(uint8_t *notify_data, size_t notify_data_size, uint16_t seconds);
|
||||||
|
|
||||||
|
uint8_t notify_data[100] = {};
|
||||||
|
|
||||||
|
static void test_peripheral_main(void)
|
||||||
|
{
|
||||||
|
notify_data[13] = 0x7f;
|
||||||
|
notify_data[99] = 0x55;
|
||||||
|
|
||||||
|
run_peripheral_sample(notify_data, sizeof(notify_data), PERIPHERAL_NOTIFY_TIME);
|
||||||
|
|
||||||
|
PASS("MTU Update test passed\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tick(bs_time_t HW_device_time)
|
||||||
|
{
|
||||||
|
if (bst_result != Passed) {
|
||||||
|
FAIL("Test failed (not passed after %i seconds)\n", WAIT_TIME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_mtu_update_init(void)
|
||||||
|
{
|
||||||
|
bst_ticker_set_next_tick_absolute(WAIT_TIME);
|
||||||
|
bst_result = In_progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct bst_test_instance test_def[] = {
|
||||||
|
{
|
||||||
|
.test_id = "peripheral",
|
||||||
|
.test_descr = "Peripheral GATT MTU Update",
|
||||||
|
.test_pre_init_f = test_mtu_update_init,
|
||||||
|
.test_tick_f = test_tick,
|
||||||
|
.test_main_f = test_peripheral_main
|
||||||
|
},
|
||||||
|
BSTEST_END_MARKER
|
||||||
|
};
|
||||||
|
|
||||||
|
struct bst_test_list *test_mtu_update_install(struct bst_test_list *tests)
|
||||||
|
{
|
||||||
|
return bst_add_tests(tests, test_def);
|
||||||
|
}
|
||||||
|
|
||||||
|
bst_test_install_t test_installers[] = {
|
||||||
|
test_mtu_update_install,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
bst_main();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -5,13 +5,14 @@
|
||||||
set -eu
|
set -eu
|
||||||
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
|
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
|
||||||
|
|
||||||
simulation_id="$(guess_test_long_name)"
|
simulation_id="mtu_update"
|
||||||
verbosity_level=2
|
verbosity_level=2
|
||||||
central_exe="${BSIM_OUT_PATH}/bin/bs_${BOARD_TS}_$(guess_test_long_name)_prj_conf"
|
|
||||||
peripheral_exe="${central_exe}"
|
|
||||||
|
|
||||||
cd ${BSIM_OUT_PATH}/bin
|
cd ${BSIM_OUT_PATH}/bin
|
||||||
|
|
||||||
|
central_exe="./bs_${BOARD_TS}_tests_bsim_bluetooth_host_att_mtu_update_prj_central_conf"
|
||||||
|
peripheral_exe="./bs_${BOARD_TS}_tests_bsim_bluetooth_host_att_mtu_update_prj_peripheral_conf"
|
||||||
|
|
||||||
Execute "$central_exe" \
|
Execute "$central_exe" \
|
||||||
-v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -RealEncryption=1
|
-v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -RealEncryption=1
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue