tests: Bluetooth: Update AD Data as fast as possible

Added tests to update AD data as fast as possible. This test
shall exercise any race condition assert checks in the
Zephyr BLE controller implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
Vinayak Kariappa Chettimada 2020-08-19 07:24:46 +05:30 committed by Carles Cufí
parent 35f2db810d
commit 819a0e3ff2
4 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(bluetooth_adv)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

View File

@ -0,0 +1,5 @@
CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_DEVICE_NAME="Test Adv Data"
CONFIG_ASSERT=y
CONFIG_ZTEST=y

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <ztest.h>
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
#define TIMEOUT_MS 300000 /* 5 minutes */
static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
};
/* Set Scan Response data */
static const struct bt_data sd[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};
void test_adv_fast_ad_data_update(void)
{
int err;
printk("Starting Beacon Demo\n");
/* Initialize the Bluetooth Subsystem */
err = bt_enable(NULL);
zassert_equal(err, 0, "Bluetooth init failed (err %d)\n", err);
printk("Bluetooth initialized\n");
/* Start advertising */
err = bt_le_adv_start(BT_LE_ADV_NCONN, ad, ARRAY_SIZE(ad),
sd, ARRAY_SIZE(sd));
zassert_equal(err, 0, "Advertising failed to start (err %d)\n", err);
printk("Advertising started\n");
while (k_uptime_get() < TIMEOUT_MS) {
err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad),
sd, ARRAY_SIZE(sd));
zassert_equal(err, 0, "Update adv data failed (err %d)\n", err);
}
}
void test_main(void)
{
ztest_test_suite(test_adv,
ztest_unit_test(test_adv_fast_ad_data_update));
ztest_run_test_suite(test_adv);
}

View File

@ -0,0 +1,6 @@
tests:
bluetooth.adv:
platform_allow: nrf52_bsim nrf51dk_nrf51422 nrf52840dk_nrf52840
tags: bluetooth
slow: true
timeout: 360