Skip to content

Commit 47f991b

Browse files
Thalleyjhedberg
authored andcommitted
tests: Bluetooth: Audio: BSIM uniform use of default_conn
Update the Bluetooth Audio babblesim tests to all use default_conn, and use it correctly. Signed-off-by: Emil Gydesen <[email protected]>
1 parent b2cf78a commit 47f991b

File tree

10 files changed

+26
-32
lines changed

10 files changed

+26
-32
lines changed

tests/bluetooth/bsim_bt/bsim_test_audio/src/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
#define AD_SIZE 1
5959
extern const struct bt_data ad[AD_SIZE];
60+
extern struct bt_conn *default_conn;
6061

6162
void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
6263
struct net_buf_simple *ad);

tests/bluetooth/bsim_bt/bsim_test_audio/src/csis_client_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ static void connected(struct bt_conn *conn, uint8_t err)
9999
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
100100

101101
if (err != 0) {
102+
bt_conn_unref(default_conn);
103+
default_conn = NULL;
102104
FAIL("Failed to connect to %s (%u)\n", addr, err);
103105
return;
104106
}

tests/bluetooth/bsim_bt/bsim_test_audio/src/mcc_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
extern enum bst_result_t bst_result;
3131

32-
static struct bt_conn *default_conn;
3332
static struct bt_mcc_cb mcc_cb;
3433

3534
static uint64_t g_icon_object_id;
@@ -570,11 +569,12 @@ static void connected(struct bt_conn *conn, uint8_t err)
570569
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
571570

572571
if (err) {
572+
bt_conn_unref(default_conn);
573+
default_conn = NULL;
573574
FAIL("Failed to connect to %s (%u)\n", addr, err);
574575
return;
575576
}
576577

577-
default_conn = conn;
578578
SET_FLAG(ble_link_is_ready);
579579
}
580580

tests/bluetooth/bsim_bt/bsim_test_audio/src/mcs_test.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
extern enum bst_result_t bst_result;
2727

28-
static struct bt_conn *default_conn;
29-
3028
CREATE_FLAG(ble_link_is_ready);
3129

3230
/* Callback after Bluetoot initialization attempt */
@@ -58,7 +56,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
5856
if (err) {
5957
FAIL("Failed to connect to %s (%u)\n", addr, err);
6058
} else {
61-
default_conn = conn;
59+
default_conn = bt_conn_ref(conn);
6260
printk("Connected: %s\n", addr);
6361
SET_FLAG(ble_link_is_ready);
6462
}

tests/bluetooth/bsim_bt/bsim_test_audio/src/media_controller_test.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ static struct media_player *local_player;
7979
static struct media_player *remote_player;
8080
static struct media_player *current_player;
8181

82-
static struct bt_conn *default_conn;
83-
8482
static void local_player_instance_cb(struct media_player *player, int err)
8583
{
8684
if (err) {
@@ -588,7 +586,6 @@ static void connected(struct bt_conn *conn, uint8_t err)
588586
return;
589587
}
590588

591-
default_conn = conn;
592589
printk("Connected: %s\n", addr);
593590
SET_FLAG(ble_link_is_ready);
594591
}

tests/bluetooth/bsim_bt/bsim_test_audio/src/mics_client_test.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static volatile uint8_t g_aics_gain_min;
3737
static volatile bool g_aics_active = true;
3838
static char g_aics_desc[AICS_DESC_SIZE];
3939
static volatile bool g_cb;
40-
static struct bt_conn *g_conn;
4140

4241
static void aics_state_cb(struct bt_aics *inst, int err, int8_t gain,
4342
uint8_t mute, uint8_t mode)
@@ -202,12 +201,13 @@ static void connected(struct bt_conn *conn, uint8_t err)
202201
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
203202

204203
if (err != 0) {
204+
bt_conn_unref(default_conn);
205+
default_conn = NULL;
205206
FAIL("Failed to connect to %s (%u)\n", addr, err);
206207
return;
207208
}
208209

209210
printk("Connected to %s\n", addr);
210-
g_conn = conn;
211211
g_is_connected = true;
212212
}
213213

@@ -242,7 +242,7 @@ static int test_aics(void)
242242
FAIL("Could not get AICS client conn (err %d)\n", err);
243243
return err;
244244
}
245-
if (cached_conn != g_conn) {
245+
if (cached_conn != default_conn) {
246246
FAIL("Cached conn was not the conn used to discover");
247247
return -ENOTCONN;
248248
}
@@ -401,13 +401,13 @@ static void test_main(void)
401401
printk("Scanning successfully started\n");
402402
WAIT_FOR(g_is_connected);
403403

404-
err = bt_gatt_exchange_mtu(g_conn, &mtu_params);
404+
err = bt_gatt_exchange_mtu(default_conn, &mtu_params);
405405
if (err != 0) {
406406
FAIL("Failed to exchange MTU %d", err);
407407
}
408408
WAIT_FOR(g_mtu_exchanged);
409409

410-
err = bt_mics_discover(g_conn, &mics);
410+
err = bt_mics_discover(default_conn, &mics);
411411
if (err != 0) {
412412
FAIL("Failed to discover MICS %d", err);
413413
}
@@ -425,7 +425,7 @@ static void test_main(void)
425425
FAIL("Failed to get MICS client conn (err %d)\n", err);
426426
return;
427427
}
428-
if (cached_conn != g_conn) {
428+
if (cached_conn != default_conn) {
429429
FAIL("Cached conn was not the conn used to discover");
430430
return;
431431
}

tests/bluetooth/bsim_bt/bsim_test_audio/src/mics_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ static volatile uint8_t g_aics_gain_min;
3030
static volatile bool g_aics_active = true;
3131
static char g_aics_desc[AICS_DESC_SIZE];
3232
static volatile bool g_cb;
33-
static struct bt_conn *g_conn;
3433
static bool g_is_connected;
3534

3635
static void mics_mute_cb(struct bt_mics *mics, int err, uint8_t mute)
@@ -133,7 +132,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
133132
}
134133

135134
printk("Connected to %s\n", addr);
136-
g_conn = conn;
135+
default_conn = bt_conn_ref(conn);
137136
g_is_connected = true;
138137
}
139138

tests/bluetooth/bsim_bt/bsim_test_audio/src/unicast_client_test.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern enum bst_result_t bst_result;
1717
static struct bt_audio_stream g_streams[CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT];
1818
static struct bt_codec *g_remote_codecs[CONFIG_BT_AUDIO_UNICAST_CLIENT_PAC_COUNT];
1919
static struct bt_audio_ep *g_sinks[CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT];
20-
static struct bt_conn *g_conn;
2120

2221
/* Mandatory support preset by both client and server */
2322
static struct bt_audio_lc3_preset preset_16_2_1 = BT_AUDIO_LC3_UNICAST_PRESET_16_2_1;
@@ -173,15 +172,14 @@ static void connected(struct bt_conn *conn, uint8_t err)
173172
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
174173

175174
if (err != 0) {
176-
bt_conn_unref(conn);
177-
g_conn = NULL;
175+
bt_conn_unref(default_conn);
176+
default_conn = NULL;
178177

179178
FAIL("Failed to connect to %s (%u)\n", addr, err);
180179
return;
181180
}
182181

183182
printk("Connected to %s\n", addr);
184-
g_conn = conn;
185183
SET_FLAG(flag_connected);
186184
}
187185

@@ -226,7 +224,7 @@ static void exchange_mtu(void)
226224
};
227225
int err;
228226

229-
err = bt_gatt_exchange_mtu(g_conn, &mtu_params);
227+
err = bt_gatt_exchange_mtu(default_conn, &mtu_params);
230228
if (err != 0) {
231229
FAIL("Failed to exchange MTU %d\n", err);
232230
return;
@@ -243,7 +241,7 @@ static void discover_sink(void)
243241
params.func = discover_sink_cb;
244242
params.type = BT_AUDIO_SINK;
245243

246-
err = bt_audio_discover(g_conn, &params);
244+
err = bt_audio_discover(default_conn, &params);
247245
if (err != 0) {
248246
printk("Failed to discover sink: %d\n", err);
249247
return;
@@ -259,7 +257,7 @@ static int configure_stream(struct bt_audio_stream *stream,
259257

260258
UNSET_FLAG(flag_stream_configured);
261259

262-
err = bt_audio_stream_config(g_conn, stream, ep,
260+
err = bt_audio_stream_config(default_conn, stream, ep,
263261
&preset_16_2_1.codec);
264262
if (err != 0) {
265263
FAIL("Could not configure stream: %d\n", err);

tests/bluetooth/bsim_bt/bsim_test_audio/src/vcs_client_test.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ static volatile uint8_t g_aics_gain_min;
4141
static volatile bool g_aics_active = 1;
4242
static char g_aics_desc[AICS_DESC_SIZE];
4343
static volatile bool g_cb;
44-
static struct bt_conn *g_conn;
4544

4645
static void vcs_state_cb(struct bt_vcs *vcs, int err, uint8_t volume,
4746
uint8_t mute)
@@ -276,11 +275,12 @@ static void connected(struct bt_conn *conn, uint8_t err)
276275
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
277276

278277
if (err) {
278+
bt_conn_unref(default_conn);
279+
default_conn = NULL;
279280
FAIL("Failed to connect to %s (%u)\n", addr, err);
280281
return;
281282
}
282283
printk("Connected to %s\n", addr);
283-
g_conn = conn;
284284
g_is_connected = true;
285285
}
286286

@@ -315,7 +315,7 @@ static int test_aics(void)
315315
FAIL("Could not get AICS client conn (err %d)\n", err);
316316
return err;
317317
}
318-
if (cached_conn != g_conn) {
318+
if (cached_conn != default_conn) {
319319
FAIL("Cached conn was not the conn used to discover");
320320
return -ENOTCONN;
321321
}
@@ -463,7 +463,7 @@ static int test_vocs(void)
463463
FAIL("Could not get VOCS client conn (err %d)\n", err);
464464
return err;
465465
}
466-
if (cached_conn != g_conn) {
466+
if (cached_conn != default_conn) {
467467
FAIL("Cached conn was not the conn used to discover");
468468
return -ENOTCONN;
469469
}
@@ -577,14 +577,14 @@ static void test_main(void)
577577

578578
WAIT_FOR(g_is_connected);
579579

580-
err = bt_gatt_exchange_mtu(g_conn, &mtu_params);
580+
err = bt_gatt_exchange_mtu(default_conn, &mtu_params);
581581
if (err) {
582582
FAIL("Failed to exchange MTU %d", err);
583583
}
584584

585585
WAIT_FOR(g_mtu_exchanged);
586586

587-
err = bt_vcs_discover(g_conn, &vcs);
587+
err = bt_vcs_discover(default_conn, &vcs);
588588
if (err) {
589589
FAIL("Failed to discover VCS %d", err);
590590
}
@@ -603,7 +603,7 @@ static void test_main(void)
603603
FAIL("Could not get VCS client conn (err %d)\n", err);
604604
return;
605605
}
606-
if (cached_conn != g_conn) {
606+
if (cached_conn != default_conn) {
607607
FAIL("Cached conn was not the conn used to discover");
608608
return;
609609
}

tests/bluetooth/bsim_bt/bsim_test_audio/src/vcs_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ static volatile uint8_t g_aics_gain_min;
4141
static volatile bool g_aics_active = 1;
4242
static char g_aics_desc[AICS_DESC_SIZE];
4343
static volatile bool g_cb;
44-
static struct bt_conn *g_conn;
4544
static bool g_is_connected;
4645

4746
static void vcs_state_cb(struct bt_vcs *vcs, int err, uint8_t volume,
@@ -197,7 +196,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
197196
return;
198197
}
199198
printk("Connected to %s\n", addr);
200-
g_conn = conn;
199+
default_conn = bt_conn_ref(conn);
201200
g_is_connected = true;
202201
}
203202

0 commit comments

Comments
 (0)