Skip to content

Commit ad34ce1

Browse files
committed
tests: Bluetooth: BAP: Test bt_bap_ep_get_conn in BSIM
Add steps in the BAP tests to verify the correctness of bt_bap_ep_get_conn. Signed-off-by: Emil Gydesen <[email protected]>
1 parent fbfa3d3 commit ad34ce1

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ static void stream_started_cb(struct bt_bap_stream *stream)
565565
{
566566
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
567567
struct bt_bap_ep_info info;
568+
struct bt_conn *ep_conn;
568569
int err;
569570

570571
memset(&test_stream->last_info, 0, sizeof(test_stream->last_info));
@@ -602,6 +603,12 @@ static void stream_started_cb(struct bt_bap_stream *stream)
602603
return;
603604
}
604605

606+
ep_conn = bt_bap_ep_get_conn(stream->ep);
607+
if (ep_conn != NULL) {
608+
FAIL("Invalid conn from endpoint: %p", ep_conn);
609+
return;
610+
}
611+
605612
printk("Stream %p started\n", stream);
606613
k_sem_give(&sem_stream_started);
607614

tests/bsim/bluetooth/audio/src/bap_broadcast_source_test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ static void stream_started_cb(struct bt_bap_stream *stream)
178178
{
179179
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
180180
struct bt_bap_ep_info info;
181+
struct bt_conn *ep_conn;
181182
int err;
182183

183184
test_stream->seq_num = 0U;
@@ -214,6 +215,12 @@ static void stream_started_cb(struct bt_bap_stream *stream)
214215
return;
215216
}
216217

218+
ep_conn = bt_bap_ep_get_conn(stream->ep);
219+
if (ep_conn != NULL) {
220+
FAIL("Invalid conn from endpoint: %p", ep_conn);
221+
return;
222+
}
223+
217224
err = bap_stream_tx_register(stream);
218225
if (err != 0) {
219226
FAIL("Failed to register stream %p for TX: %d\n", stream, err);

tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,21 @@ CREATE_FLAG(flag_operation_success);
6969

7070
static void stream_configured(struct bt_bap_stream *stream, const struct bt_bap_qos_cfg_pref *pref)
7171
{
72+
struct bt_conn *ep_conn;
73+
7274
printk("Configured stream %p\n", stream);
7375

7476
/* TODO: The preference should be used/taken into account when
7577
* setting the QoS
7678
*/
7779

80+
ep_conn = bt_bap_ep_get_conn(stream->ep);
81+
if (ep_conn == NULL || stream->conn != ep_conn) {
82+
FAIL("Invalid conn from endpoint: %p", ep_conn);
83+
return;
84+
}
85+
bt_conn_unref(ep_conn);
86+
7887
SET_FLAG(flag_stream_codec_configured);
7988
}
8089

tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_
114114

115115
bt_bap_unicast_server_foreach_ep(conn, print_ase_info, NULL);
116116

117-
SET_FLAG(flag_stream_configured);
118-
119117
*pref = qos_pref;
120118

121119
return 0;
@@ -222,6 +220,23 @@ static const struct bt_bap_unicast_server_cb unicast_server_cb = {
222220
.release = lc3_release,
223221
};
224222

223+
static void stream_configured_cb(struct bt_bap_stream *stream,
224+
const struct bt_bap_qos_cfg_pref *pref)
225+
{
226+
struct bt_conn *ep_conn;
227+
228+
printk("Configured stream %p\n", stream);
229+
230+
ep_conn = bt_bap_ep_get_conn(stream->ep);
231+
if (ep_conn == NULL || stream->conn != ep_conn) {
232+
FAIL("Invalid conn from endpoint: %p", ep_conn);
233+
return;
234+
}
235+
bt_conn_unref(ep_conn);
236+
237+
SET_FLAG(flag_stream_configured);
238+
}
239+
225240
static void stream_enabled_cb(struct bt_bap_stream *stream)
226241
{
227242
struct bt_bap_ep_info ep_info;
@@ -279,6 +294,7 @@ static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
279294
}
280295

281296
static struct bt_bap_stream_ops stream_ops = {
297+
.configured = stream_configured_cb,
282298
.enabled = stream_enabled_cb,
283299
.started = stream_started_cb,
284300
.stopped = stream_stopped_cb,

0 commit comments

Comments
 (0)