Bluetooth: host: tests: Switch to one-time adv
This patch removes all uses of the adv auto-resume feature in the host bsim tests, except for the test of that feature itself, and instead makes all adv starts explicit. The auto-resume feature is planned for deprecation. And, explicit starting of adv makes what happens in the test more explicit as well. Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
This commit is contained in:
parent
991b3623b0
commit
765b244c27
20 changed files with 70 additions and 46 deletions
|
@ -140,7 +140,7 @@ void peripheral_setup_and_connect(void)
|
|||
FAIL("Can't enable Bluetooth (err %d)\n", err);
|
||||
}
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ static void test_main(void)
|
|||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
|
|
|
@ -339,7 +339,7 @@ static void test_main(void)
|
|||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
|
|
|
@ -101,7 +101,7 @@ static void test_main_common(bool connect_eatt)
|
|||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ static void test_main(void)
|
|||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
|
|
|
@ -183,7 +183,7 @@ static void setup(void)
|
|||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
|
|
|
@ -145,7 +145,7 @@ static void test_main(void)
|
|||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
|
|
|
@ -16,3 +16,8 @@ zephyr_include_directories(
|
|||
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
|
||||
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
|
||||
)
|
||||
|
||||
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/common/testlib testlib)
|
||||
target_link_libraries(app PRIVATE
|
||||
testlib
|
||||
)
|
||||
|
|
|
@ -4,15 +4,18 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/bluetooth/iso.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
#include <testlib/conn.h>
|
||||
|
||||
extern enum bst_result_t bst_result;
|
||||
|
||||
CREATE_FLAG(flag_iso_connected);
|
||||
CREATE_FLAG(flag_data_received);
|
||||
|
||||
static const struct bt_data ad[] = {
|
||||
|
@ -70,15 +73,11 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in
|
|||
static void iso_connected(struct bt_iso_chan *chan)
|
||||
{
|
||||
printk("ISO Channel %p connected\n", chan);
|
||||
|
||||
SET_FLAG(flag_iso_connected);
|
||||
}
|
||||
|
||||
static void iso_disconnected(struct bt_iso_chan *chan, uint8_t reason)
|
||||
{
|
||||
printk("ISO Channel %p disconnected (reason 0x%02x)\n", chan, reason);
|
||||
|
||||
UNSET_FLAG(flag_iso_connected);
|
||||
}
|
||||
|
||||
static int iso_accept(const struct bt_iso_accept_info *info, struct bt_iso_chan **chan)
|
||||
|
@ -144,7 +143,7 @@ static void adv_connect(void)
|
|||
{
|
||||
int err;
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
|
||||
|
@ -159,13 +158,15 @@ static void adv_connect(void)
|
|||
static void test_main(void)
|
||||
{
|
||||
init();
|
||||
adv_connect();
|
||||
WAIT_FOR_FLAG_SET(flag_iso_connected);
|
||||
WAIT_FOR_FLAG_SET(flag_data_received);
|
||||
WAIT_FOR_FLAG_UNSET(flag_iso_connected);
|
||||
WAIT_FOR_FLAG_UNSET(flag_connected);
|
||||
|
||||
while (true) {
|
||||
adv_connect();
|
||||
bt_testlib_conn_wait_free();
|
||||
|
||||
if (TEST_FLAG(flag_data_received)) {
|
||||
PASS("Test passed\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const struct bst_test_instance test_def[] = {
|
||||
|
|
|
@ -449,7 +449,7 @@ static void test_peripheral_main(void)
|
|||
|
||||
LOG_DBG("Peripheral Bluetooth initialized.");
|
||||
LOG_DBG("Connectable advertising...");
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err) {
|
||||
FAIL("Advertising failed to start (err %d)", err);
|
||||
return;
|
||||
|
|
|
@ -187,7 +187,7 @@ static void test_peripheral_main(void)
|
|||
|
||||
register_l2cap_server();
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
|
|
|
@ -151,7 +151,7 @@ static void test_peripheral_main(void)
|
|||
return;
|
||||
}
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
|
|
|
@ -400,7 +400,7 @@ void test_peripheral_main(void)
|
|||
sprintf(name, "per-%d", get_device_nbr());
|
||||
bt_set_name(name);
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, NULL, 0, NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, NULL, 0, NULL, 0);
|
||||
if (err) {
|
||||
LOG_ERR("Advertising failed to start (err %d)", err);
|
||||
__ASSERT_NO_MSG(err);
|
||||
|
|
|
@ -12,3 +12,8 @@ zephyr_include_directories(
|
|||
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
|
||||
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
|
||||
)
|
||||
|
||||
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/common/testlib testlib)
|
||||
target_link_libraries(app PRIVATE
|
||||
testlib
|
||||
)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
CONFIG_ASSERT=y
|
||||
CONFIG_BT=y
|
||||
CONFIG_BT_DEVICE_NAME="GATT tester"
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
|
|
|
@ -60,7 +60,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
|||
UNSET_FLAG(flag_is_connected);
|
||||
}
|
||||
|
||||
BT_CONN_CB_DEFINE(conn_callbacks) = {
|
||||
static struct bt_conn_cb conn_callbacks = {
|
||||
.connected = connected,
|
||||
.disconnected = disconnected,
|
||||
};
|
||||
|
@ -263,6 +263,8 @@ static void test_main(void)
|
|||
{
|
||||
int err;
|
||||
|
||||
bt_conn_cb_register(&conn_callbacks);
|
||||
|
||||
for (int i = 0; i < NUM_ITERATIONS; i++) {
|
||||
|
||||
err = bt_enable(NULL);
|
||||
|
|
|
@ -10,8 +10,6 @@ extern enum bst_result_t bst_result;
|
|||
|
||||
CREATE_FLAG(flag_is_connected);
|
||||
|
||||
static struct bt_conn *g_conn;
|
||||
|
||||
#define NUM_ITERATIONS 10
|
||||
|
||||
static void connected(struct bt_conn *conn, uint8_t err)
|
||||
|
@ -27,7 +25,6 @@ static void connected(struct bt_conn *conn, uint8_t err)
|
|||
|
||||
printk("Connected to %s\n", addr);
|
||||
|
||||
g_conn = bt_conn_ref(conn);
|
||||
SET_FLAG(flag_is_connected);
|
||||
}
|
||||
|
||||
|
@ -35,17 +32,10 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
|||
{
|
||||
char addr[BT_ADDR_LE_STR_LEN];
|
||||
|
||||
if (conn != g_conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
||||
|
||||
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
|
||||
|
||||
bt_conn_unref(g_conn);
|
||||
|
||||
g_conn = NULL;
|
||||
UNSET_FLAG(flag_is_connected);
|
||||
}
|
||||
|
||||
|
@ -154,7 +144,7 @@ static void test_main(void)
|
|||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
|
|
|
@ -12,3 +12,6 @@ zephyr_include_directories(
|
|||
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
|
||||
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
|
||||
)
|
||||
|
||||
add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/common/testlib testlib)
|
||||
target_link_libraries(app PRIVATE testlib)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
CONFIG_ASSERT=y
|
||||
CONFIG_BT=y
|
||||
CONFIG_BT_DEVICE_NAME="conn tester"
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "bstests.h"
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
|
||||
#include <testlib/conn.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
CREATE_FLAG(flag_is_connected);
|
||||
|
@ -29,7 +31,8 @@ static void connected(struct bt_conn *conn, uint8_t err)
|
|||
|
||||
printk("conn_callback:Connected to %s\n", addr);
|
||||
|
||||
g_conn = conn;
|
||||
__ASSERT_NO_MSG(g_conn == NULL);
|
||||
g_conn = bt_conn_ref(conn);
|
||||
SET_FLAG(flag_is_connected);
|
||||
}
|
||||
|
||||
|
@ -46,8 +49,8 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
|||
printk("conn_callback:Disconnected: %s (reason 0x%02x)\n", addr, reason);
|
||||
|
||||
bt_conn_unref(g_conn);
|
||||
|
||||
g_conn = NULL;
|
||||
|
||||
UNSET_FLAG(flag_is_connected);
|
||||
}
|
||||
|
||||
|
@ -60,6 +63,7 @@ void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, struct ne
|
|||
{
|
||||
char addr_str[BT_ADDR_LE_STR_LEN];
|
||||
int err;
|
||||
struct bt_conn *conn;
|
||||
|
||||
if (g_conn != NULL) {
|
||||
printk("g_conn != NULL\n");
|
||||
|
@ -82,11 +86,13 @@ void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, struct ne
|
|||
return;
|
||||
}
|
||||
|
||||
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &g_conn);
|
||||
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &conn);
|
||||
if (err != 0) {
|
||||
FAIL("Could not connect to peer: %d", err);
|
||||
}
|
||||
printk("%s: connected to found device\n", __func__);
|
||||
|
||||
bt_conn_unref(conn);
|
||||
}
|
||||
|
||||
static void connection_info(struct bt_conn *conn, void *user_data)
|
||||
|
@ -111,12 +117,25 @@ static void connection_info(struct bt_conn *conn, void *user_data)
|
|||
}
|
||||
}
|
||||
|
||||
static void test_peripheral_main(void)
|
||||
static void start_adv(void)
|
||||
{
|
||||
int err;
|
||||
const struct bt_data ad[] = {
|
||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR))};
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Advertising successfully started\n");
|
||||
}
|
||||
|
||||
static void test_peripheral_main(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = bt_enable(NULL);
|
||||
if (err != 0) {
|
||||
FAIL("Bluetooth init failed (err %d)\n", err);
|
||||
|
@ -127,13 +146,7 @@ static void test_peripheral_main(void)
|
|||
|
||||
bt_conn_cb_register(&conn_callbacks);
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err != 0) {
|
||||
FAIL("Advertising failed to start (err %d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Advertising successfully started\n");
|
||||
start_adv();
|
||||
|
||||
WAIT_FOR_FLAG(flag_is_connected);
|
||||
|
||||
|
@ -141,6 +154,9 @@ static void test_peripheral_main(void)
|
|||
|
||||
bt_conn_cb_unregister(&conn_callbacks);
|
||||
|
||||
bt_testlib_conn_wait_free();
|
||||
start_adv();
|
||||
|
||||
k_sleep(K_SECONDS(1));
|
||||
|
||||
err = bt_disable();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue