Bluetooth: tests: fix double-registering of callbacks
This was the source of assert failures. If only they were enabled in the first place... The issue is that in order to save on build time, these two tests build only one image, from which two devices are instantiated (`gatt_client_test.c` and `gatt_server_test.c`). The double-registration happens as `BT_CONN_CB_DEFINE()` is build-time, and is included in two files of the same image. Then _both_ images will end up with both `connected()` `disconnected()` etc callbacks, which have logic specific to their respective images/devices. The patch uses runtime registration instead so each device only ever registers its own callbacks and not the other device's too. Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
This commit is contained in:
parent
1b4844aad0
commit
ea41a24d3a
4 changed files with 12 additions and 4 deletions
|
@ -60,7 +60,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
||||||
UNSET_FLAG(flag_is_connected);
|
UNSET_FLAG(flag_is_connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_CONN_CB_DEFINE(conn_callbacks) = {
|
static struct bt_conn_cb conn_callbacks = {
|
||||||
.connected = connected,
|
.connected = connected,
|
||||||
.disconnected = disconnected,
|
.disconnected = disconnected,
|
||||||
};
|
};
|
||||||
|
@ -297,6 +297,8 @@ static void test_main(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
bt_conn_cb_register(&conn_callbacks);
|
||||||
|
|
||||||
err = bt_enable(NULL);
|
err = bt_enable(NULL);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
FAIL("Bluetooth discover failed (err %d)\n", err);
|
FAIL("Bluetooth discover failed (err %d)\n", err);
|
||||||
|
|
|
@ -45,7 +45,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
||||||
g_conn = NULL;
|
g_conn = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_CONN_CB_DEFINE(conn_callbacks) = {
|
static struct bt_conn_cb conn_callbacks = {
|
||||||
.connected = connected,
|
.connected = connected,
|
||||||
.disconnected = disconnected,
|
.disconnected = disconnected,
|
||||||
};
|
};
|
||||||
|
@ -331,6 +331,8 @@ static void test_main(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bt_conn_cb_register(&conn_callbacks);
|
||||||
|
|
||||||
err = bt_enable(NULL);
|
err = bt_enable(NULL);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
FAIL("Bluetooth init failed (err %d)\n", err);
|
FAIL("Bluetooth init failed (err %d)\n", err);
|
||||||
|
|
|
@ -74,7 +74,7 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_CONN_CB_DEFINE(conn_callbacks) = {
|
static struct bt_conn_cb conn_callbacks = {
|
||||||
.connected = connected,
|
.connected = connected,
|
||||||
.disconnected = disconnected,
|
.disconnected = disconnected,
|
||||||
.security_changed = security_changed,
|
.security_changed = security_changed,
|
||||||
|
@ -351,6 +351,8 @@ static void test_main(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
bt_conn_cb_register(&conn_callbacks);
|
||||||
|
|
||||||
err = bt_enable(NULL);
|
err = bt_enable(NULL);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
FAIL("Bluetooth discover failed (err %d)\n", err);
|
FAIL("Bluetooth discover failed (err %d)\n", err);
|
||||||
|
|
|
@ -47,7 +47,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
||||||
UNSET_FLAG(flag_is_connected);
|
UNSET_FLAG(flag_is_connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_CONN_CB_DEFINE(conn_callbacks) = {
|
static struct bt_conn_cb conn_callbacks = {
|
||||||
.connected = connected,
|
.connected = connected,
|
||||||
.disconnected = disconnected,
|
.disconnected = disconnected,
|
||||||
};
|
};
|
||||||
|
@ -151,6 +151,8 @@ static void test_main(void)
|
||||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR))
|
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bt_conn_cb_register(&conn_callbacks);
|
||||||
|
|
||||||
err = bt_enable(NULL);
|
err = bt_enable(NULL);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
FAIL("Bluetooth init failed (err %d)\n", err);
|
FAIL("Bluetooth init failed (err %d)\n", err);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue