tests: bluetooth: added bsim test for longer per adv data

Added a bsim_bt host test to test the handling of periodic adv
report data received across multiple packets

Signed-off-by: Pierce Lowe <pierce.lowe@nordicsemi.no>
This commit is contained in:
Pierce Lowe 2023-01-30 09:46:04 +01:00 committed by Carles Cufí
commit 205a077118
7 changed files with 197 additions and 0 deletions

View file

@ -0,0 +1,21 @@
CONFIG_BT=y
CONFIG_BT_DEVICE_NAME="test_per_adv"
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_SMP=y
CONFIG_BT_PRIVACY=y
CONFIG_BT_EXT_ADV=y
CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
CONFIG_BT_CTLR_ADV_AUX_SET=2
CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2
CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK=y
CONFIG_BT_CTLR_ADV_SYNC_PDU_BACK2BACK=y
CONFIG_BT_PER_ADV=y
CONFIG_BT_PER_ADV_SYNC=y
CONFIG_BT_PER_ADV_SYNC_BUF_SIZE=1650
CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650
CONFIG_BT_CTLR_ADV_DATA_CHAIN=y
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650

View file

@ -20,3 +20,22 @@ void test_init(void)
bst_ticker_set_next_tick_absolute(WAIT_TIME);
bst_result = In_progress;
}
uint8_t mfg_data[254] = {
0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B,
0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
0x2B, 0x2C, 0x2D, 0x2E, 0x2F,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xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED,
0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB};

View file

@ -54,4 +54,6 @@
void test_tick(bs_time_t HW_device_time);
void test_init(void);
extern uint8_t mfg_data[254];
#endif /* ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_ */

View file

@ -145,6 +145,25 @@ static void start_per_adv_set(struct bt_le_ext_adv *adv)
printk("done.\n");
}
#if (CONFIG_BT_CTLR_ADV_DATA_CHAIN)
static void set_per_adv_data(struct bt_le_ext_adv *adv)
{
int err;
const struct bt_data ad[] = {
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ARRAY_SIZE(mfg_data)),
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ARRAY_SIZE(mfg_data))};
printk("Setting Periodic Advertising Data...");
err = bt_le_per_adv_set_data(adv, ad, ARRAY_SIZE(ad));
if (err) {
printk("Failed to set periodic advertising data: %d\n",
err);
return;
}
printk("done.\n");
}
#endif
static void stop_ext_adv_set(struct bt_le_ext_adv *adv)
{
int err;
@ -276,6 +295,31 @@ static void main_per_adv_conn_privacy_advertiser(void)
PASS("Periodic advertiser passed\n");
}
static void main_per_adv_long_data_advertiser(void)
{
#if (CONFIG_BT_CTLR_ADV_DATA_CHAIN)
struct bt_le_ext_adv *per_adv;
common_init();
create_per_adv_set(&per_adv);
set_per_adv_data(per_adv);
start_per_adv_set(per_adv);
start_ext_adv_set(per_adv);
/* Advertise for a bit */
k_sleep(K_SECONDS(10));
stop_per_adv_set(per_adv);
stop_ext_adv_set(per_adv);
delete_adv_set(per_adv);
per_adv = NULL;
#endif
PASS("Periodic long data advertiser passed\n");
}
static const struct bst_test_instance per_adv_advertiser[] = {
{
.test_id = "per_adv_advertiser",
@ -301,6 +345,14 @@ static const struct bst_test_instance per_adv_advertiser[] = {
.test_tick_f = test_tick,
.test_main_f = main_per_adv_conn_privacy_advertiser
},
{
.test_id = "per_adv_long_data_advertiser",
.test_descr = "Periodic advertising test with a longer data length. "
"To test the syncers reassembly of large data packets",
.test_post_init_f = test_init,
.test_tick_f = test_tick,
.test_main_f = main_per_adv_long_data_advertiser
},
BSTEST_END_MARKER
};

View file

@ -28,6 +28,7 @@ CREATE_FLAG(flag_bonded);
CREATE_FLAG(flag_per_adv);
CREATE_FLAG(flag_per_adv_sync);
CREATE_FLAG(flag_per_adv_sync_lost);
CREATE_FLAG(flag_per_adv_recv);
static void connected(struct bt_conn *conn, uint8_t err)
{
@ -134,9 +135,37 @@ static void term_cb(struct bt_le_per_adv_sync *sync,
SET_FLAG(flag_per_adv_sync_lost);
}
static void recv_cb(struct bt_le_per_adv_sync *recv_sync,
const struct bt_le_per_adv_sync_recv_info *info,
struct net_buf_simple *buf)
{
char le_addr[BT_ADDR_LE_STR_LEN];
uint8_t buf_data_len;
if (TEST_FLAG(flag_per_adv_recv)) {
return;
}
bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr));
printk("PER_ADV_SYNC[%u]: [DEVICE]: %s advertisment received\n",
bt_le_per_adv_sync_get_index(recv_sync), le_addr);
while (buf->len > 0) {
buf_data_len = (uint8_t)net_buf_simple_pull_le16(buf);
if (buf->data[0] - 1 != sizeof(mfg_data) ||
memcmp(buf->data, mfg_data, sizeof(mfg_data))) {
FAIL("Unexpected adv data received\n");
}
net_buf_simple_pull(buf, ARRAY_SIZE(mfg_data));
}
SET_FLAG(flag_per_adv_recv);
}
static struct bt_le_per_adv_sync_cb sync_callbacks = {
.synced = sync_cb,
.term = term_cb,
.recv = recv_cb,
};
static void common_init(void)
@ -280,6 +309,29 @@ static void main_per_adv_conn_privacy_syncer(void)
PASS("Periodic advertising syncer passed\n");
}
static void main_per_adv_long_data_syncer(void)
{
#if (CONFIG_BT_PER_ADV_SYNC_BUF_SIZE > 0)
struct bt_le_per_adv_sync *sync = NULL;
common_init();
start_scan();
printk("Waiting for periodic advertising...\n");
WAIT_FOR_FLAG(flag_per_adv);
printk("Found periodic advertising.\n");
create_pa_sync(&sync);
printk("Waiting to receive periodic advertisment...\n");
WAIT_FOR_FLAG(flag_per_adv_recv);
printk("Waiting for periodic sync lost...\n");
WAIT_FOR_FLAG(flag_per_adv_sync_lost);
#endif
PASS("Periodic advertising long data syncer passed\n");
}
static const struct bst_test_instance per_adv_syncer[] = {
{
.test_id = "per_adv_syncer",
@ -307,6 +359,15 @@ static const struct bst_test_instance per_adv_syncer[] = {
.test_tick_f = test_tick,
.test_main_f = main_per_adv_conn_privacy_syncer
},
{
.test_id = "per_adv_long_data_syncer",
.test_descr = "Periodic advertising sync test with larger "
"data length. Test is used to verify that "
"reassembly of long data is handeled correctly.",
.test_post_init_f = test_init,
.test_tick_f = test_tick,
.test_main_f = main_per_adv_long_data_syncer
},
BSTEST_END_MARKER
};

View file

@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Copyright (c) 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
# Basic periodic advertising sync test: an advertiser advertises with periodic
# advertising, and a scanner scans for and syncs to the periodic advertising.
simulation_id="per_adv_long_data"
verbosity_level=2
process_ids=""; exit_code=0
function Execute(){
if [ ! -f $1 ]; then
echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\
compile it?)\e[39m"
exit 1
fi
timeout 10 $@ & process_ids="$process_ids $!"
}
: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}"
#Give a default value to BOARD if it does not have one yet:
BOARD="${BOARD:-nrf52_bsim}"
cd ${BSIM_OUT_PATH}/bin
Execute ./bs_${BOARD}_tests_bluetooth_bsim_bt_bsim_test_per_adv_prj_long_data_conf \
-v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \
-testid=per_adv_long_data_advertiser -rs=23
Execute ./bs_${BOARD}_tests_bluetooth_bsim_bt_bsim_test_per_adv_prj_long_data_conf \
-v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \
-testid=per_adv_long_data_syncer -rs=6
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \
-D=2 -sim_length=20e6 $@
for process_id in $process_ids; do
wait $process_id || let "exit_code=$?"
done
exit $exit_code #the last exit code != 0

View file

@ -68,5 +68,6 @@ app=tests/bluetooth/bsim_bt/bsim_test_mesh conf_overlay=overlay_pst.conf compile
app=tests/bluetooth/bsim_bt/bsim_test_mesh conf_overlay=overlay_gatt.conf compile &
app=tests/bluetooth/bsim_bt/bsim_test_disable compile &
app=tests/bluetooth/bsim_bt/bsim_test_per_adv compile &
app=tests/bluetooth/bsim_bt/bsim_test_per_adv conf_file=prj_long_data.conf compile &
wait