1 /* test_ase_state_transition.c - ASE state transition tests */
2
3 /*
4 * Copyright (c) 2023 Codecoup
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #include <stdlib.h>
10 #include <zephyr/types.h>
11 #include <zephyr/bluetooth/audio/audio.h>
12 #include <zephyr/bluetooth/audio/bap.h>
13 #include <zephyr/bluetooth/conn.h>
14 #include <zephyr/bluetooth/gatt.h>
15 #include <zephyr/sys/util_macro.h>
16
17 #include "bap_unicast_server.h"
18 #include "bap_unicast_server_expects.h"
19 #include "bap_stream.h"
20 #include "bap_stream_expects.h"
21 #include "conn.h"
22 #include "gatt.h"
23 #include "gatt_expects.h"
24 #include "iso.h"
25
26 #include "test_common.h"
27
28 #define test_sink_ase_state_transition_fixture test_ase_state_transition_fixture
29 #define test_source_ase_state_transition_fixture test_ase_state_transition_fixture
30
31 static const struct bt_audio_codec_qos_pref qos_pref =
32 BT_AUDIO_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0x02, 10, 40000, 40000, 40000, 40000);
33
34 struct test_ase_state_transition_fixture {
35 struct bt_conn conn;
36 struct bt_bap_stream stream;
37 struct {
38 uint8_t id;
39 const struct bt_gatt_attr *attr;
40 } ase;
41 };
42
test_sink_ase_state_transition_setup(void)43 static void *test_sink_ase_state_transition_setup(void)
44 {
45 struct test_ase_state_transition_fixture *fixture;
46
47 fixture = malloc(sizeof(*fixture));
48 zassert_not_null(fixture);
49
50 memset(fixture, 0, sizeof(*fixture));
51 test_conn_init(&fixture->conn);
52 test_ase_snk_get(1, &fixture->ase.attr);
53 if (fixture->ase.attr != NULL) {
54 fixture->ase.id = test_ase_id_get(fixture->ase.attr);
55 }
56
57 return fixture;
58 }
59
test_ase_state_transition_before(void * f)60 static void test_ase_state_transition_before(void *f)
61 {
62 bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb);
63 }
64
test_ase_state_transition_after(void * f)65 static void test_ase_state_transition_after(void *f)
66 {
67 bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);
68 }
69
test_ase_state_transition_teardown(void * f)70 static void test_ase_state_transition_teardown(void *f)
71 {
72 free(f);
73 }
74
75 ZTEST_SUITE(test_sink_ase_state_transition, NULL, test_sink_ase_state_transition_setup,
76 test_ase_state_transition_before, test_ase_state_transition_after,
77 test_ase_state_transition_teardown);
78
ZTEST_F(test_sink_ase_state_transition,test_client_idle_to_codec_configured)79 ZTEST_F(test_sink_ase_state_transition, test_client_idle_to_codec_configured)
80 {
81 struct bt_bap_stream *stream = &fixture->stream;
82 struct bt_conn *conn = &fixture->conn;
83 uint8_t ase_id = fixture->ase.id;
84
85 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
86
87 test_ase_control_client_config_codec(conn, ase_id, stream);
88
89 /* Verification */
90 expect_bt_bap_unicast_server_cb_config_called_once(conn, EMPTY, BT_AUDIO_DIR_SINK, EMPTY);
91 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
92 }
93
ZTEST_F(test_sink_ase_state_transition,test_client_codec_configured_to_qos_configured)94 ZTEST_F(test_sink_ase_state_transition, test_client_codec_configured_to_qos_configured)
95 {
96 struct bt_bap_stream *stream = &fixture->stream;
97 struct bt_conn *conn = &fixture->conn;
98 uint8_t ase_id = fixture->ase.id;
99
100 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
101
102 test_preamble_state_codec_configured(conn, ase_id, stream);
103
104 test_ase_control_client_config_qos(conn, ase_id);
105
106 /* Verification */
107 expect_bt_bap_unicast_server_cb_qos_called_once(stream, EMPTY);
108 expect_bt_bap_stream_ops_qos_set_called_once(stream);
109 }
110
ZTEST_F(test_sink_ase_state_transition,test_client_qos_configured_to_enabling)111 ZTEST_F(test_sink_ase_state_transition, test_client_qos_configured_to_enabling)
112 {
113 struct bt_bap_stream *stream = &fixture->stream;
114 struct bt_conn *conn = &fixture->conn;
115 uint8_t ase_id = fixture->ase.id;
116
117 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
118
119 test_preamble_state_qos_configured(conn, ase_id, stream);
120
121 test_ase_control_client_enable(conn, ase_id);
122
123 /* Verification */
124 expect_bt_bap_unicast_server_cb_enable_called_once(stream, EMPTY, EMPTY);
125 expect_bt_bap_stream_ops_enabled_called_once(stream);
126 }
127
ZTEST_F(test_sink_ase_state_transition,test_client_enabling_to_qos_configured)128 ZTEST_F(test_sink_ase_state_transition, test_client_enabling_to_qos_configured)
129 {
130 struct bt_bap_stream *stream = &fixture->stream;
131 struct bt_conn *conn = &fixture->conn;
132 uint8_t ase_id = fixture->ase.id;
133
134 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
135
136 test_preamble_state_enabling(conn, ase_id, stream);
137
138 test_ase_control_client_disable(conn, ase_id);
139
140 /* Verification */
141 expect_bt_bap_unicast_server_cb_disable_called_once(stream);
142 expect_bt_bap_stream_ops_qos_set_called_once(stream);
143 }
144
ZTEST_F(test_sink_ase_state_transition,test_client_qos_configured_to_releasing)145 ZTEST_F(test_sink_ase_state_transition, test_client_qos_configured_to_releasing)
146 {
147 struct bt_bap_stream *stream = &fixture->stream;
148 struct bt_conn *conn = &fixture->conn;
149 uint8_t ase_id = fixture->ase.id;
150
151 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
152
153 test_preamble_state_qos_configured(conn, ase_id, stream);
154
155 test_ase_control_client_release(conn, ase_id);
156
157 /* Verification */
158 expect_bt_bap_unicast_server_cb_release_called_once(stream);
159 expect_bt_bap_stream_ops_released_called_once(stream);
160 }
161
ZTEST_F(test_sink_ase_state_transition,test_client_codec_configured_to_codec_configured)162 ZTEST_F(test_sink_ase_state_transition, test_client_codec_configured_to_codec_configured)
163 {
164 struct bt_bap_stream *stream = &fixture->stream;
165 struct bt_conn *conn = &fixture->conn;
166 uint8_t ase_id = fixture->ase.id;
167
168 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
169
170 test_preamble_state_codec_configured(conn, ase_id, stream);
171
172 test_ase_control_client_config_codec(conn, ase_id, stream);
173
174 /* Verification */
175 expect_bt_bap_unicast_server_cb_config_not_called();
176 expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SINK, EMPTY);
177 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
178 }
179
ZTEST_F(test_sink_ase_state_transition,test_client_qos_configured_to_qos_configured)180 ZTEST_F(test_sink_ase_state_transition, test_client_qos_configured_to_qos_configured)
181 {
182 struct bt_bap_stream *stream = &fixture->stream;
183 struct bt_conn *conn = &fixture->conn;
184 uint8_t ase_id = fixture->ase.id;
185
186 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
187
188 test_preamble_state_qos_configured(conn, ase_id, stream);
189
190 test_ase_control_client_config_qos(conn, ase_id);
191
192 /* Verification */
193 expect_bt_bap_unicast_server_cb_qos_called_once(stream, EMPTY);
194 expect_bt_bap_stream_ops_qos_set_called_once(stream);
195 }
196
ZTEST_F(test_sink_ase_state_transition,test_client_qos_configured_to_codec_configured)197 ZTEST_F(test_sink_ase_state_transition, test_client_qos_configured_to_codec_configured)
198 {
199 struct bt_bap_stream *stream = &fixture->stream;
200 struct bt_conn *conn = &fixture->conn;
201 uint8_t ase_id = fixture->ase.id;
202
203 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
204
205 test_preamble_state_qos_configured(conn, ase_id, stream);
206
207 test_ase_control_client_config_codec(conn, ase_id, stream);
208
209 /* Verification */
210 expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SINK, EMPTY);
211 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
212 }
213
ZTEST_F(test_sink_ase_state_transition,test_client_codec_configured_to_releasing)214 ZTEST_F(test_sink_ase_state_transition, test_client_codec_configured_to_releasing)
215 {
216 struct bt_bap_stream *stream = &fixture->stream;
217 struct bt_conn *conn = &fixture->conn;
218 uint8_t ase_id = fixture->ase.id;
219
220 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
221
222 test_preamble_state_codec_configured(conn, ase_id, stream);
223
224 test_ase_control_client_release(conn, ase_id);
225
226 /* Verification */
227 expect_bt_bap_unicast_server_cb_release_called_once(stream);
228 expect_bt_bap_stream_ops_released_called_once(stream);
229 }
230
ZTEST_F(test_sink_ase_state_transition,test_client_enabling_to_releasing)231 ZTEST_F(test_sink_ase_state_transition, test_client_enabling_to_releasing)
232 {
233 struct bt_bap_stream *stream = &fixture->stream;
234 struct bt_conn *conn = &fixture->conn;
235 uint8_t ase_id = fixture->ase.id;
236
237 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
238
239 test_preamble_state_enabling(conn, ase_id, stream);
240
241 test_ase_control_client_release(conn, ase_id);
242
243 /* Verification */
244 expect_bt_bap_unicast_server_cb_release_called_once(stream);
245 expect_bt_bap_stream_ops_released_called_once(stream);
246 }
247
ZTEST_F(test_sink_ase_state_transition,test_client_enabling_to_enabling)248 ZTEST_F(test_sink_ase_state_transition, test_client_enabling_to_enabling)
249 {
250 struct bt_bap_stream *stream = &fixture->stream;
251 struct bt_conn *conn = &fixture->conn;
252 uint8_t ase_id = fixture->ase.id;
253
254 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
255
256 test_preamble_state_enabling(conn, ase_id, stream);
257
258 test_ase_control_client_update_metadata(conn, ase_id);
259
260 /* Verification */
261 expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY);
262 expect_bt_bap_stream_ops_metadata_updated_called_once(stream);
263 }
264
ZTEST_F(test_sink_ase_state_transition,test_client_streaming_to_releasing)265 ZTEST_F(test_sink_ase_state_transition, test_client_streaming_to_releasing)
266 {
267 struct bt_bap_stream *stream = &fixture->stream;
268 struct bt_conn *conn = &fixture->conn;
269 uint8_t ase_id = fixture->ase.id;
270 struct bt_iso_chan *chan;
271
272 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
273
274 test_preamble_state_streaming(conn, ase_id, stream, &chan, false);
275
276 test_ase_control_client_release(conn, ase_id);
277
278 /* Client disconnects the ISO */
279 mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
280
281 /* Verification */
282 expect_bt_bap_unicast_server_cb_release_called_once(stream);
283 expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
284 expect_bt_bap_stream_ops_released_called_once(stream);
285 }
286
ZTEST_F(test_sink_ase_state_transition,test_client_streaming_to_streaming)287 ZTEST_F(test_sink_ase_state_transition, test_client_streaming_to_streaming)
288 {
289 struct bt_bap_stream *stream = &fixture->stream;
290 struct bt_conn *conn = &fixture->conn;
291 uint8_t ase_id = fixture->ase.id;
292 struct bt_iso_chan *chan;
293
294 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
295
296 test_preamble_state_streaming(conn, ase_id, stream, &chan, false);
297
298 test_ase_control_client_update_metadata(conn, ase_id);
299
300 /* Verification */
301 expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY);
302 expect_bt_bap_stream_ops_metadata_updated_called_once(stream);
303 }
304
ZTEST_F(test_sink_ase_state_transition,test_client_streaming_to_qos_configured)305 ZTEST_F(test_sink_ase_state_transition, test_client_streaming_to_qos_configured)
306 {
307 struct bt_bap_stream *stream = &fixture->stream;
308 struct bt_conn *conn = &fixture->conn;
309 uint8_t ase_id = fixture->ase.id;
310 struct bt_iso_chan *chan;
311
312 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
313
314 test_preamble_state_streaming(conn, ase_id, stream, &chan, false);
315
316 test_ase_control_client_disable(conn, ase_id);
317
318 /* Verification */
319 expect_bt_bap_unicast_server_cb_disable_called_once(stream);
320 expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
321 expect_bt_bap_stream_ops_qos_set_called_once(stream);
322 }
323
ZTEST_F(test_sink_ase_state_transition,test_server_idle_to_codec_configured)324 ZTEST_F(test_sink_ase_state_transition, test_server_idle_to_codec_configured)
325 {
326 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_LC3_CONFIG_16_2(
327 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
328 struct bt_bap_stream *stream = &fixture->stream;
329 struct bt_conn *conn = &fixture->conn;
330 int err;
331
332 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
333
334 err = bt_bap_unicast_server_config_ase(conn, stream, &codec_cfg, &qos_pref);
335 zassert_false(err < 0, "bt_bap_unicast_server_config_ase returned err %d", err);
336
337 /* Verification */
338 expect_bt_bap_unicast_server_cb_config_not_called();
339 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
340 }
341
ZTEST_F(test_sink_ase_state_transition,test_server_codec_configured_to_codec_configured)342 ZTEST_F(test_sink_ase_state_transition, test_server_codec_configured_to_codec_configured)
343 {
344 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_LC3_CONFIG_16_2(
345 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
346 struct bt_bap_stream *stream = &fixture->stream;
347 struct bt_conn *conn = &fixture->conn;
348 uint8_t ase_id = fixture->ase.id;
349 int err;
350
351 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
352
353 test_preamble_state_codec_configured(conn, ase_id, stream);
354
355 err = bt_bap_stream_reconfig(stream, &codec_cfg);
356 zassert_false(err < 0, "bt_bap_stream_reconfig returned err %d", err);
357
358 /* Verification */
359 expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SINK, EMPTY);
360 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
361 }
362
ZTEST_F(test_sink_ase_state_transition,test_server_codec_configured_to_releasing)363 ZTEST_F(test_sink_ase_state_transition, test_server_codec_configured_to_releasing)
364 {
365 struct bt_bap_stream *stream = &fixture->stream;
366 struct bt_conn *conn = &fixture->conn;
367 uint8_t ase_id = fixture->ase.id;
368 int err;
369
370 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
371
372 test_preamble_state_codec_configured(conn, ase_id, stream);
373
374 err = bt_bap_stream_release(stream);
375 zassert_false(err < 0, "bt_bap_stream_release returned err %d", err);
376
377 /* Verification */
378 expect_bt_bap_unicast_server_cb_release_called_once(stream);
379 expect_bt_bap_stream_ops_released_called_once(stream);
380 }
381
ZTEST_F(test_sink_ase_state_transition,test_server_qos_configured_to_codec_configured)382 ZTEST_F(test_sink_ase_state_transition, test_server_qos_configured_to_codec_configured)
383 {
384 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_LC3_CONFIG_16_2(
385 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
386 struct bt_bap_stream *stream = &fixture->stream;
387 struct bt_conn *conn = &fixture->conn;
388 uint8_t ase_id = fixture->ase.id;
389 int err;
390
391 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
392
393 test_preamble_state_qos_configured(conn, ase_id, stream);
394
395 err = bt_bap_stream_reconfig(stream, &codec_cfg);
396 zassert_false(err < 0, "bt_bap_stream_reconfig returned err %d", err);
397
398 /* Verification */
399 expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SINK, EMPTY);
400 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
401 }
402
ZTEST_F(test_sink_ase_state_transition,test_server_qos_configured_to_releasing)403 ZTEST_F(test_sink_ase_state_transition, test_server_qos_configured_to_releasing)
404 {
405 struct bt_bap_stream *stream = &fixture->stream;
406 struct bt_conn *conn = &fixture->conn;
407 uint8_t ase_id = fixture->ase.id;
408 int err;
409
410 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
411
412 test_preamble_state_qos_configured(conn, ase_id, stream);
413
414 err = bt_bap_stream_release(stream);
415 zassert_false(err < 0, "bt_bap_stream_release returned err %d", err);
416
417 /* Verification */
418 expect_bt_bap_unicast_server_cb_release_called_once(stream);
419 expect_bt_bap_stream_ops_released_called_once(stream);
420 }
421
ZTEST_F(test_sink_ase_state_transition,test_server_enabling_to_releasing)422 ZTEST_F(test_sink_ase_state_transition, test_server_enabling_to_releasing)
423 {
424 struct bt_bap_stream *stream = &fixture->stream;
425 struct bt_conn *conn = &fixture->conn;
426 uint8_t ase_id = fixture->ase.id;
427 int err;
428
429 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
430
431 test_preamble_state_enabling(conn, ase_id, stream);
432
433 err = bt_bap_stream_release(stream);
434 zassert_false(err < 0, "bt_bap_stream_release returned err %d", err);
435
436 /* Verification */
437 expect_bt_bap_unicast_server_cb_release_called_once(stream);
438 expect_bt_bap_stream_ops_released_called_once(stream);
439 }
440
ZTEST_F(test_sink_ase_state_transition,test_server_enabling_to_enabling)441 ZTEST_F(test_sink_ase_state_transition, test_server_enabling_to_enabling)
442 {
443 const uint8_t meta[] = {
444 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
445 BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_MEDIA)),
446 };
447 struct bt_bap_stream *stream = &fixture->stream;
448 struct bt_conn *conn = &fixture->conn;
449 uint8_t ase_id = fixture->ase.id;
450 int err;
451
452 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
453
454 test_preamble_state_enabling(conn, ase_id, stream);
455
456 err = bt_bap_stream_metadata(stream, meta, ARRAY_SIZE(meta));
457 zassert_false(err < 0, "bt_bap_stream_metadata returned err %d", err);
458
459 /* Verification */
460 expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY);
461 expect_bt_bap_stream_ops_metadata_updated_called_once(stream);
462 }
463
ZTEST_F(test_sink_ase_state_transition,test_server_enabling_to_qos_configured)464 ZTEST_F(test_sink_ase_state_transition, test_server_enabling_to_qos_configured)
465 {
466 struct bt_bap_stream *stream = &fixture->stream;
467 struct bt_conn *conn = &fixture->conn;
468 uint8_t ase_id = fixture->ase.id;
469 int err;
470
471 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
472
473 test_preamble_state_enabling(conn, ase_id, stream);
474
475 err = bt_bap_stream_disable(stream);
476 zassert_false(err < 0, "bt_bap_stream_disable returned err %d", err);
477
478 /* Verification */
479 expect_bt_bap_unicast_server_cb_disable_called_once(stream);
480 expect_bt_bap_stream_ops_qos_set_called_once(stream);
481 }
482
ZTEST_F(test_sink_ase_state_transition,test_server_enabling_to_streaming)483 ZTEST_F(test_sink_ase_state_transition, test_server_enabling_to_streaming)
484 {
485 struct bt_bap_stream *stream = &fixture->stream;
486 struct bt_conn *conn = &fixture->conn;
487 uint8_t ase_id = fixture->ase.id;
488 struct bt_iso_chan *chan;
489 int err;
490
491 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
492
493 test_preamble_state_enabling(conn, ase_id, stream);
494
495 err = mock_bt_iso_accept(conn, 0x01, 0x01, &chan);
496 zassert_equal(0, err, "Failed to connect iso: err %d", err);
497
498 err = bt_bap_stream_start(stream);
499 zassert_false(err < 0, "bt_bap_stream_start returned err %d", err);
500
501 /* Verification */
502 expect_bt_bap_stream_ops_started_called_once(stream);
503 /* XXX: unicast_server_cb->start is not called for Sink ASE */
504 }
505
ZTEST_F(test_sink_ase_state_transition,test_server_streaming_to_streaming)506 ZTEST_F(test_sink_ase_state_transition, test_server_streaming_to_streaming)
507 {
508 const uint8_t meta[] = {
509 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
510 BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_MEDIA)),
511 };
512 struct bt_bap_stream *stream = &fixture->stream;
513 struct bt_conn *conn = &fixture->conn;
514 uint8_t ase_id = fixture->ase.id;
515 struct bt_iso_chan *chan;
516 int err;
517
518 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
519
520 test_preamble_state_streaming(conn, ase_id, stream, &chan, false);
521
522 err = bt_bap_stream_metadata(stream, meta, ARRAY_SIZE(meta));
523 zassert_false(err < 0, "bt_bap_stream_metadata returned err %d", err);
524
525 /* Verification */
526 expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY);
527 expect_bt_bap_stream_ops_metadata_updated_called_once(stream);
528 }
529
ZTEST_F(test_sink_ase_state_transition,test_server_streaming_to_qos_configured)530 ZTEST_F(test_sink_ase_state_transition, test_server_streaming_to_qos_configured)
531 {
532 struct bt_bap_stream *stream = &fixture->stream;
533 struct bt_conn *conn = &fixture->conn;
534 uint8_t ase_id = fixture->ase.id;
535 struct bt_iso_chan *chan;
536 int err;
537
538 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
539
540 test_preamble_state_streaming(conn, ase_id, stream, &chan, false);
541
542 err = bt_bap_stream_disable(stream);
543 zassert_false(err < 0, "bt_bap_stream_disable returned err %d", err);
544
545 /* Verification */
546 expect_bt_bap_unicast_server_cb_disable_called_once(stream);
547 expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_LOCALHOST_TERM_CONN);
548 expect_bt_bap_stream_ops_qos_set_called_once(stream);
549 }
550
ZTEST_F(test_sink_ase_state_transition,test_server_streaming_to_releasing)551 ZTEST_F(test_sink_ase_state_transition, test_server_streaming_to_releasing)
552 {
553 struct bt_bap_stream *stream = &fixture->stream;
554 struct bt_conn *conn = &fixture->conn;
555 uint8_t ase_id = fixture->ase.id;
556 struct bt_iso_chan *chan;
557 int err;
558
559 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK);
560
561 test_preamble_state_streaming(conn, ase_id, stream, &chan, false);
562
563 err = bt_bap_stream_release(stream);
564 zassert_false(err < 0, "bt_bap_stream_release returned err %d", err);
565
566 /* Client disconnects the ISO */
567 mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
568
569 /* Verification */
570 expect_bt_bap_unicast_server_cb_release_called_once(stream);
571 expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_LOCALHOST_TERM_CONN);
572 expect_bt_bap_stream_ops_released_called_once(stream);
573 }
574
test_source_ase_state_transition_setup(void)575 static void *test_source_ase_state_transition_setup(void)
576 {
577 struct test_ase_state_transition_fixture *fixture;
578
579 fixture = malloc(sizeof(*fixture));
580 zassert_not_null(fixture);
581
582 memset(fixture, 0, sizeof(*fixture));
583 test_conn_init(&fixture->conn);
584 test_ase_src_get(1, &fixture->ase.attr);
585 if (fixture->ase.attr != NULL) {
586 fixture->ase.id = test_ase_id_get(fixture->ase.attr);
587 }
588
589 return fixture;
590 }
591
592 ZTEST_SUITE(test_source_ase_state_transition, NULL, test_source_ase_state_transition_setup,
593 test_ase_state_transition_before, test_ase_state_transition_after,
594 test_ase_state_transition_teardown);
595
ZTEST_F(test_source_ase_state_transition,test_client_idle_to_codec_configured)596 ZTEST_F(test_source_ase_state_transition, test_client_idle_to_codec_configured)
597 {
598 struct bt_bap_stream *stream = &fixture->stream;
599 struct bt_conn *conn = &fixture->conn;
600 uint8_t ase_id = fixture->ase.id;
601
602 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
603
604 test_ase_control_client_config_codec(conn, ase_id, stream);
605
606 /* Verification */
607 expect_bt_bap_unicast_server_cb_config_called_once(conn, EMPTY, BT_AUDIO_DIR_SOURCE, EMPTY);
608 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
609 }
610
ZTEST_F(test_source_ase_state_transition,test_client_codec_configured_to_qos_configured)611 ZTEST_F(test_source_ase_state_transition, test_client_codec_configured_to_qos_configured)
612 {
613 struct bt_bap_stream *stream = &fixture->stream;
614 struct bt_conn *conn = &fixture->conn;
615 uint8_t ase_id = fixture->ase.id;
616
617 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
618
619 test_preamble_state_codec_configured(conn, ase_id, stream);
620
621 test_ase_control_client_config_qos(conn, ase_id);
622
623 /* Verification */
624 expect_bt_bap_unicast_server_cb_qos_called_once(stream, EMPTY);
625 expect_bt_bap_stream_ops_qos_set_called_once(stream);
626 }
627
ZTEST_F(test_source_ase_state_transition,test_client_qos_configured_to_enabling)628 ZTEST_F(test_source_ase_state_transition, test_client_qos_configured_to_enabling)
629 {
630 struct bt_bap_stream *stream = &fixture->stream;
631 struct bt_conn *conn = &fixture->conn;
632 uint8_t ase_id = fixture->ase.id;
633
634 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
635
636 test_preamble_state_qos_configured(conn, ase_id, stream);
637
638 test_ase_control_client_enable(conn, ase_id);
639
640 /* Verification */
641 expect_bt_bap_unicast_server_cb_enable_called_once(stream, EMPTY, EMPTY);
642 expect_bt_bap_stream_ops_enabled_called_once(stream);
643 }
644
ZTEST_F(test_source_ase_state_transition,test_client_enabling_to_disabling)645 ZTEST_F(test_source_ase_state_transition, test_client_enabling_to_disabling)
646 {
647 struct bt_bap_stream *stream = &fixture->stream;
648 struct bt_conn *conn = &fixture->conn;
649 uint8_t ase_id = fixture->ase.id;
650
651 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
652
653 test_preamble_state_enabling(conn, ase_id, stream);
654
655 test_ase_control_client_disable(conn, ase_id);
656
657 /* Verification */
658 expect_bt_bap_unicast_server_cb_disable_called_once(stream);
659 expect_bt_bap_stream_ops_disabled_called_once(stream);
660 }
661
ZTEST_F(test_source_ase_state_transition,test_client_qos_configured_to_releasing)662 ZTEST_F(test_source_ase_state_transition, test_client_qos_configured_to_releasing)
663 {
664 struct bt_bap_stream *stream = &fixture->stream;
665 struct bt_conn *conn = &fixture->conn;
666 uint8_t ase_id = fixture->ase.id;
667
668 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
669
670 test_preamble_state_qos_configured(conn, ase_id, stream);
671
672 test_ase_control_client_release(conn, ase_id);
673
674 /* Verification */
675 expect_bt_bap_unicast_server_cb_release_called_once(stream);
676 expect_bt_bap_stream_ops_released_called_once(stream);
677 }
678
ZTEST_F(test_source_ase_state_transition,test_client_enabling_to_streaming)679 ZTEST_F(test_source_ase_state_transition, test_client_enabling_to_streaming)
680 {
681 struct bt_bap_stream *stream = &fixture->stream;
682 struct bt_conn *conn = &fixture->conn;
683 uint8_t ase_id = fixture->ase.id;
684 struct bt_iso_chan *chan;
685 int err;
686
687 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
688
689 test_preamble_state_enabling(conn, ase_id, stream);
690
691 err = mock_bt_iso_accept(conn, 0x01, 0x01, &chan);
692 zassert_equal(0, err, "Failed to connect iso: err %d", err);
693
694 test_ase_control_client_receiver_start_ready(conn, ase_id);
695
696 /* Verification */
697 expect_bt_bap_unicast_server_cb_start_called_once(stream);
698 expect_bt_bap_stream_ops_started_called_once(stream);
699 }
700
ZTEST_F(test_source_ase_state_transition,test_client_codec_configured_to_codec_configured)701 ZTEST_F(test_source_ase_state_transition, test_client_codec_configured_to_codec_configured)
702 {
703 struct bt_bap_stream *stream = &fixture->stream;
704 struct bt_conn *conn = &fixture->conn;
705 uint8_t ase_id = fixture->ase.id;
706
707 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
708
709 test_preamble_state_codec_configured(conn, ase_id, stream);
710
711 test_ase_control_client_config_codec(conn, ase_id, stream);
712
713 /* Verification */
714 expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SOURCE, EMPTY);
715 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
716 }
717
ZTEST_F(test_source_ase_state_transition,test_client_qos_configured_to_qos_configured)718 ZTEST_F(test_source_ase_state_transition, test_client_qos_configured_to_qos_configured)
719 {
720 struct bt_bap_stream *stream = &fixture->stream;
721 struct bt_conn *conn = &fixture->conn;
722 uint8_t ase_id = fixture->ase.id;
723
724 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
725
726 test_preamble_state_qos_configured(conn, ase_id, stream);
727
728 test_ase_control_client_config_qos(conn, ase_id);
729
730 /* Verification */
731 expect_bt_bap_unicast_server_cb_qos_called_once(stream, EMPTY);
732 expect_bt_bap_stream_ops_qos_set_called_once(stream);
733 }
734
ZTEST_F(test_source_ase_state_transition,test_client_qos_configured_to_codec_configured)735 ZTEST_F(test_source_ase_state_transition, test_client_qos_configured_to_codec_configured)
736 {
737 struct bt_bap_stream *stream = &fixture->stream;
738 struct bt_conn *conn = &fixture->conn;
739 uint8_t ase_id = fixture->ase.id;
740
741 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
742
743 test_preamble_state_qos_configured(conn, ase_id, stream);
744
745 test_ase_control_client_config_codec(conn, ase_id, stream);
746
747 /* Verification */
748 expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SOURCE, EMPTY);
749 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
750 }
751
ZTEST_F(test_source_ase_state_transition,test_client_codec_configured_to_releasing)752 ZTEST_F(test_source_ase_state_transition, test_client_codec_configured_to_releasing)
753 {
754 struct bt_bap_stream *stream = &fixture->stream;
755 struct bt_conn *conn = &fixture->conn;
756 uint8_t ase_id = fixture->ase.id;
757
758 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
759
760 test_preamble_state_codec_configured(conn, ase_id, stream);
761
762 test_ase_control_client_release(conn, ase_id);
763
764 /* Verification */
765 expect_bt_bap_unicast_server_cb_release_called_once(stream);
766 expect_bt_bap_stream_ops_released_called_once(stream);
767 }
768
ZTEST_F(test_source_ase_state_transition,test_client_enabling_to_releasing)769 ZTEST_F(test_source_ase_state_transition, test_client_enabling_to_releasing)
770 {
771 struct bt_bap_stream *stream = &fixture->stream;
772 struct bt_conn *conn = &fixture->conn;
773 uint8_t ase_id = fixture->ase.id;
774
775 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
776
777 test_preamble_state_enabling(conn, ase_id, stream);
778
779 test_ase_control_client_release(conn, ase_id);
780
781 /* Verification */
782 expect_bt_bap_unicast_server_cb_release_called_once(stream);
783 expect_bt_bap_stream_ops_released_called_once(stream);
784 }
785
ZTEST_F(test_source_ase_state_transition,test_client_enabling_to_enabling)786 ZTEST_F(test_source_ase_state_transition, test_client_enabling_to_enabling)
787 {
788 struct bt_bap_stream *stream = &fixture->stream;
789 struct bt_conn *conn = &fixture->conn;
790 uint8_t ase_id = fixture->ase.id;
791
792 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
793
794 test_preamble_state_enabling(conn, ase_id, stream);
795
796 test_ase_control_client_update_metadata(conn, ase_id);
797
798 /* Verification */
799 expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY);
800 expect_bt_bap_stream_ops_metadata_updated_called_once(stream);
801 }
802
ZTEST_F(test_source_ase_state_transition,test_client_streaming_to_releasing)803 ZTEST_F(test_source_ase_state_transition, test_client_streaming_to_releasing)
804 {
805 struct bt_bap_stream *stream = &fixture->stream;
806 struct bt_conn *conn = &fixture->conn;
807 uint8_t ase_id = fixture->ase.id;
808 struct bt_iso_chan *chan;
809
810 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
811
812 test_preamble_state_streaming(conn, ase_id, stream, &chan, true);
813
814 test_ase_control_client_release(conn, ase_id);
815
816 /* Client disconnects the ISO */
817 mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
818
819 /* Verification */
820 expect_bt_bap_unicast_server_cb_release_called_once(stream);
821 expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
822 expect_bt_bap_stream_ops_released_called_once(stream);
823 }
824
ZTEST_F(test_source_ase_state_transition,test_client_streaming_to_streaming)825 ZTEST_F(test_source_ase_state_transition, test_client_streaming_to_streaming)
826 {
827 struct bt_bap_stream *stream = &fixture->stream;
828 struct bt_conn *conn = &fixture->conn;
829 uint8_t ase_id = fixture->ase.id;
830 struct bt_iso_chan *chan;
831
832 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
833
834 test_preamble_state_streaming(conn, ase_id, stream, &chan, true);
835
836 test_ase_control_client_update_metadata(conn, ase_id);
837
838 /* Verification */
839 expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY);
840 expect_bt_bap_stream_ops_metadata_updated_called_once(stream);
841 }
842
ZTEST_F(test_source_ase_state_transition,test_client_streaming_to_disabling)843 ZTEST_F(test_source_ase_state_transition, test_client_streaming_to_disabling)
844 {
845 struct bt_bap_stream *stream = &fixture->stream;
846 struct bt_conn *conn = &fixture->conn;
847 uint8_t ase_id = fixture->ase.id;
848 struct bt_iso_chan *chan;
849
850 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
851
852 test_preamble_state_streaming(conn, ase_id, stream, &chan, true);
853
854 test_ase_control_client_disable(conn, ase_id);
855
856 /* Verification */
857 expect_bt_bap_unicast_server_cb_disable_called_once(stream);
858 expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
859 expect_bt_bap_stream_ops_disabled_called_once(stream);
860 }
861
ZTEST_F(test_source_ase_state_transition,test_client_enabling_to_disabling_to_qos_configured)862 ZTEST_F(test_source_ase_state_transition, test_client_enabling_to_disabling_to_qos_configured)
863 {
864 struct bt_bap_stream *stream = &fixture->stream;
865 struct bt_conn *conn = &fixture->conn;
866 uint8_t ase_id = fixture->ase.id;
867
868 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
869
870 test_preamble_state_enabling(conn, ase_id, stream);
871 test_ase_control_client_disable(conn, ase_id);
872 test_mocks_reset();
873
874 test_ase_control_client_receiver_stop_ready(conn, ase_id);
875
876 /* Verification */
877 expect_bt_bap_unicast_server_cb_stop_called_once(stream);
878 expect_bt_bap_stream_ops_qos_set_called_once(stream);
879 }
880
ZTEST_F(test_source_ase_state_transition,test_client_streaming_to_disabling_to_qos_configured)881 ZTEST_F(test_source_ase_state_transition, test_client_streaming_to_disabling_to_qos_configured)
882 {
883 struct bt_bap_stream *stream = &fixture->stream;
884 struct bt_conn *conn = &fixture->conn;
885 uint8_t ase_id = fixture->ase.id;
886 struct bt_iso_chan *chan;
887
888 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
889
890 test_preamble_state_streaming(conn, ase_id, stream, &chan, true);
891 test_ase_control_client_disable(conn, ase_id);
892
893 /* Verify that stopped callback was called by disable */
894 expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
895
896 test_mocks_reset();
897
898 test_ase_control_client_receiver_stop_ready(conn, ase_id);
899
900 /* Verification */
901 expect_bt_bap_unicast_server_cb_stop_called_once(stream);
902 expect_bt_bap_stream_ops_qos_set_called_once(stream);
903 }
904
ZTEST_F(test_source_ase_state_transition,test_server_idle_to_codec_configured)905 ZTEST_F(test_source_ase_state_transition, test_server_idle_to_codec_configured)
906 {
907 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_LC3_CONFIG_16_2(
908 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
909 struct bt_bap_stream *stream = &fixture->stream;
910 struct bt_conn *conn = &fixture->conn;
911 int err;
912
913 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
914
915 err = bt_bap_unicast_server_config_ase(conn, stream, &codec_cfg, &qos_pref);
916 zassert_false(err < 0, "bt_bap_unicast_server_config_ase returned err %d", err);
917
918 /* Verification */
919 expect_bt_bap_unicast_server_cb_config_not_called();
920 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
921 }
922
ZTEST_F(test_source_ase_state_transition,test_server_codec_configured_to_codec_configured)923 ZTEST_F(test_source_ase_state_transition, test_server_codec_configured_to_codec_configured)
924 {
925 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_LC3_CONFIG_16_2(
926 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
927 struct bt_bap_stream *stream = &fixture->stream;
928 struct bt_conn *conn = &fixture->conn;
929 uint8_t ase_id = fixture->ase.id;
930 int err;
931
932 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
933
934 test_preamble_state_codec_configured(conn, ase_id, stream);
935
936 err = bt_bap_stream_reconfig(stream, &codec_cfg);
937 zassert_false(err < 0, "bt_bap_stream_reconfig returned err %d", err);
938
939 /* Verification */
940 expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SOURCE, EMPTY);
941 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
942 }
943
ZTEST_F(test_source_ase_state_transition,test_server_codec_configured_to_releasing)944 ZTEST_F(test_source_ase_state_transition, test_server_codec_configured_to_releasing)
945 {
946 struct bt_bap_stream *stream = &fixture->stream;
947 struct bt_conn *conn = &fixture->conn;
948 uint8_t ase_id = fixture->ase.id;
949 int err;
950
951 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
952
953 test_preamble_state_codec_configured(conn, ase_id, stream);
954
955 err = bt_bap_stream_release(stream);
956 zassert_false(err < 0, "bt_bap_stream_release returned err %d", err);
957
958 /* Verification */
959 expect_bt_bap_unicast_server_cb_release_called_once(stream);
960 expect_bt_bap_stream_ops_released_called_once(stream);
961 }
962
ZTEST_F(test_source_ase_state_transition,test_server_qos_configured_to_codec_configured)963 ZTEST_F(test_source_ase_state_transition, test_server_qos_configured_to_codec_configured)
964 {
965 struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_LC3_CONFIG_16_2(
966 BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
967 struct bt_bap_stream *stream = &fixture->stream;
968 struct bt_conn *conn = &fixture->conn;
969 uint8_t ase_id = fixture->ase.id;
970 int err;
971
972 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
973
974 test_preamble_state_qos_configured(conn, ase_id, stream);
975
976 err = bt_bap_stream_reconfig(stream, &codec_cfg);
977 zassert_false(err < 0, "bt_bap_stream_reconfig returned err %d", err);
978
979 /* Verification */
980 expect_bt_bap_unicast_server_cb_reconfig_called_once(stream, BT_AUDIO_DIR_SOURCE, EMPTY);
981 expect_bt_bap_stream_ops_configured_called_once(stream, EMPTY);
982 }
983
ZTEST_F(test_source_ase_state_transition,test_server_qos_configured_to_releasing)984 ZTEST_F(test_source_ase_state_transition, test_server_qos_configured_to_releasing)
985 {
986 struct bt_bap_stream *stream = &fixture->stream;
987 struct bt_conn *conn = &fixture->conn;
988 uint8_t ase_id = fixture->ase.id;
989 int err;
990
991 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
992
993 test_preamble_state_qos_configured(conn, ase_id, stream);
994
995 err = bt_bap_stream_release(stream);
996 zassert_false(err < 0, "bt_bap_stream_release returned err %d", err);
997
998 /* Verification */
999 expect_bt_bap_unicast_server_cb_release_called_once(stream);
1000 expect_bt_bap_stream_ops_released_called_once(stream);
1001 }
1002
ZTEST_F(test_source_ase_state_transition,test_server_enabling_to_releasing)1003 ZTEST_F(test_source_ase_state_transition, test_server_enabling_to_releasing)
1004 {
1005 struct bt_bap_stream *stream = &fixture->stream;
1006 struct bt_conn *conn = &fixture->conn;
1007 uint8_t ase_id = fixture->ase.id;
1008 int err;
1009
1010 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
1011
1012 test_preamble_state_enabling(conn, ase_id, stream);
1013
1014 err = bt_bap_stream_release(stream);
1015 zassert_false(err < 0, "bt_bap_stream_release returned err %d", err);
1016
1017 /* Verification */
1018 expect_bt_bap_unicast_server_cb_release_called_once(stream);
1019 expect_bt_bap_stream_ops_released_called_once(stream);
1020 }
1021
ZTEST_F(test_source_ase_state_transition,test_server_enabling_to_enabling)1022 ZTEST_F(test_source_ase_state_transition, test_server_enabling_to_enabling)
1023 {
1024 const uint8_t meta[] = {
1025 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1026 BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_MEDIA)),
1027 };
1028 struct bt_bap_stream *stream = &fixture->stream;
1029 struct bt_conn *conn = &fixture->conn;
1030 uint8_t ase_id = fixture->ase.id;
1031 int err;
1032
1033 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
1034
1035 test_preamble_state_enabling(conn, ase_id, stream);
1036
1037 err = bt_bap_stream_metadata(stream, meta, ARRAY_SIZE(meta));
1038 zassert_false(err < 0, "bt_bap_stream_metadata returned err %d", err);
1039
1040 /* Verification */
1041 expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY);
1042 expect_bt_bap_stream_ops_metadata_updated_called_once(stream);
1043 }
1044
ZTEST_F(test_source_ase_state_transition,test_server_enabling_to_disabling)1045 ZTEST_F(test_source_ase_state_transition, test_server_enabling_to_disabling)
1046 {
1047 struct bt_bap_stream *stream = &fixture->stream;
1048 struct bt_conn *conn = &fixture->conn;
1049 uint8_t ase_id = fixture->ase.id;
1050 int err;
1051
1052 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
1053
1054 test_preamble_state_enabling(conn, ase_id, stream);
1055
1056 err = bt_bap_stream_disable(stream);
1057 zassert_false(err < 0, "bt_bap_stream_disable returned err %d", err);
1058
1059 /* Verification */
1060 expect_bt_bap_unicast_server_cb_disable_called_once(stream);
1061 expect_bt_bap_stream_ops_disabled_called_once(stream);
1062 }
1063
ZTEST_F(test_source_ase_state_transition,test_server_streaming_to_streaming)1064 ZTEST_F(test_source_ase_state_transition, test_server_streaming_to_streaming)
1065 {
1066 const uint8_t meta[] = {
1067 BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
1068 BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_MEDIA)),
1069 };
1070 struct bt_bap_stream *stream = &fixture->stream;
1071 struct bt_conn *conn = &fixture->conn;
1072 uint8_t ase_id = fixture->ase.id;
1073 struct bt_iso_chan *chan;
1074 int err;
1075
1076 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
1077
1078 test_preamble_state_streaming(conn, ase_id, stream, &chan, true);
1079
1080 err = bt_bap_stream_metadata(stream, meta, ARRAY_SIZE(meta));
1081 zassert_false(err < 0, "bt_bap_stream_metadata returned err %d", err);
1082
1083 /* Verification */
1084 expect_bt_bap_unicast_server_cb_metadata_called_once(stream, EMPTY, EMPTY);
1085 expect_bt_bap_stream_ops_metadata_updated_called_once(stream);
1086 }
1087
ZTEST_F(test_source_ase_state_transition,test_server_streaming_to_disabling)1088 ZTEST_F(test_source_ase_state_transition, test_server_streaming_to_disabling)
1089 {
1090 struct bt_bap_stream *stream = &fixture->stream;
1091 struct bt_conn *conn = &fixture->conn;
1092 uint8_t ase_id = fixture->ase.id;
1093 struct bt_iso_chan *chan;
1094 int err;
1095
1096 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
1097
1098 test_preamble_state_streaming(conn, ase_id, stream, &chan, true);
1099
1100 err = bt_bap_stream_disable(stream);
1101 zassert_false(err < 0, "bt_bap_stream_disable returned err %d", err);
1102
1103 /* Verification */
1104 expect_bt_bap_unicast_server_cb_disable_called_once(stream);
1105 expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_LOCALHOST_TERM_CONN);
1106 expect_bt_bap_stream_ops_disabled_called_once(stream);
1107 }
1108
ZTEST_F(test_source_ase_state_transition,test_server_streaming_to_releasing)1109 ZTEST_F(test_source_ase_state_transition, test_server_streaming_to_releasing)
1110 {
1111 struct bt_bap_stream *stream = &fixture->stream;
1112 struct bt_conn *conn = &fixture->conn;
1113 uint8_t ase_id = fixture->ase.id;
1114 struct bt_iso_chan *chan;
1115 int err;
1116
1117 Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
1118
1119 test_preamble_state_streaming(conn, ase_id, stream, &chan, true);
1120
1121 err = bt_bap_stream_release(stream);
1122 zassert_false(err < 0, "bt_bap_stream_release returned err %d", err);
1123
1124 /* Client disconnects the ISO */
1125 mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
1126
1127 /* Verification */
1128 expect_bt_bap_unicast_server_cb_release_called_once(stream);
1129 expect_bt_bap_stream_ops_stopped_called_once(stream, BT_HCI_ERR_LOCALHOST_TERM_CONN);
1130 expect_bt_bap_stream_ops_released_called_once(stream);
1131 }
1132