From 819a0e3ff2a7b64945a9f841a2d5f941ef38463d Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 19 Aug 2020 07:24:46 +0530 Subject: [PATCH] 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 --- tests/bluetooth/adv/CMakeLists.txt | 8 +++++ tests/bluetooth/adv/prj.conf | 5 +++ tests/bluetooth/adv/src/main.c | 58 ++++++++++++++++++++++++++++++ tests/bluetooth/adv/testcase.yaml | 6 ++++ 4 files changed, 77 insertions(+) create mode 100644 tests/bluetooth/adv/CMakeLists.txt create mode 100644 tests/bluetooth/adv/prj.conf create mode 100644 tests/bluetooth/adv/src/main.c create mode 100644 tests/bluetooth/adv/testcase.yaml diff --git a/tests/bluetooth/adv/CMakeLists.txt b/tests/bluetooth/adv/CMakeLists.txt new file mode 100644 index 00000000000..cc3ec044a3e --- /dev/null +++ b/tests/bluetooth/adv/CMakeLists.txt @@ -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}) diff --git a/tests/bluetooth/adv/prj.conf b/tests/bluetooth/adv/prj.conf new file mode 100644 index 00000000000..ef3f2fa1643 --- /dev/null +++ b/tests/bluetooth/adv/prj.conf @@ -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 diff --git a/tests/bluetooth/adv/src/main.c b/tests/bluetooth/adv/src/main.c new file mode 100644 index 00000000000..a2aaf29e8d9 --- /dev/null +++ b/tests/bluetooth/adv/src/main.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include + +#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); +} diff --git a/tests/bluetooth/adv/testcase.yaml b/tests/bluetooth/adv/testcase.yaml new file mode 100644 index 00000000000..b06710d62fe --- /dev/null +++ b/tests/bluetooth/adv/testcase.yaml @@ -0,0 +1,6 @@ +tests: + bluetooth.adv: + platform_allow: nrf52_bsim nrf51dk_nrf51422 nrf52840dk_nrf52840 + tags: bluetooth + slow: true + timeout: 360