Skip to content

Commit ade1a44

Browse files
MariuszSkamracarlescufi
authored andcommitted
tests: Bluetooth: ascs: Add CIS link loss test cases
This adds test cases testing correctness of autonomous ASE state transitions triggered by CIS link loss. Signed-off-by: Mariusz Skamra <[email protected]>
1 parent 8dcec59 commit ade1a44

File tree

1 file changed

+130
-0
lines changed
  • tests/bluetooth/audio/ascs/src

1 file changed

+130
-0
lines changed

tests/bluetooth/audio/ascs/src/main.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,133 @@ ZTEST_F(ascs_test_suite, test_recv_in_enabling_state)
475475

476476
bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);
477477
}
478+
479+
ZTEST_F(ascs_test_suite, test_cis_link_loss_in_streaming_state)
480+
{
481+
struct bt_bap_stream *stream = &fixture->stream;
482+
struct bt_conn *conn = &fixture->conn;
483+
const struct bt_gatt_attr *ase;
484+
struct bt_iso_chan *chan;
485+
uint8_t ase_id;
486+
487+
if (IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK)) {
488+
ase = fixture->ase_snk.attr;
489+
ase_id = fixture->ase_snk.id;
490+
} else {
491+
ase = fixture->ase_src.attr;
492+
ase_id = fixture->ase_src.id;
493+
}
494+
zexpect_not_null(ase);
495+
zexpect_true(ase_id != 0x00);
496+
497+
bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb);
498+
499+
test_preamble_state_streaming(conn, ase_id, stream, &chan,
500+
!IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK));
501+
502+
/* Mock CIS disconnection */
503+
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_TIMEOUT);
504+
505+
/* Expected to notify the upper layers */
506+
expect_bt_bap_stream_ops_qos_set_called_once(stream);
507+
expect_bt_bap_stream_ops_released_not_called();
508+
509+
bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);
510+
}
511+
512+
static void test_cis_link_loss_in_disabling_state(struct ascs_test_suite_fixture *fixture,
513+
bool streaming)
514+
{
515+
struct bt_bap_stream *stream = &fixture->stream;
516+
struct bt_conn *conn = &fixture->conn;
517+
const struct bt_gatt_attr *ase;
518+
struct bt_iso_chan *chan;
519+
uint8_t ase_id;
520+
int err;
521+
522+
Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
523+
524+
ase = fixture->ase_src.attr;
525+
ase_id = fixture->ase_src.id;
526+
zexpect_not_null(ase);
527+
zexpect_true(ase_id != 0x00);
528+
529+
bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb);
530+
531+
test_preamble_state_enabling(conn, ase_id, stream);
532+
err = mock_bt_iso_accept(conn, 0x01, 0x01, &chan);
533+
zassert_equal(0, err, "Failed to connect iso: err %d", err);
534+
535+
if (streaming) {
536+
test_ase_control_client_receiver_start_ready(conn, ase_id);
537+
}
538+
539+
test_ase_control_client_disable(conn, ase_id);
540+
test_mocks_reset();
541+
542+
/* Mock CIS disconnection */
543+
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_TIMEOUT);
544+
545+
/* Expected to notify the upper layers */
546+
expect_bt_bap_stream_ops_qos_set_called_once(stream);
547+
expect_bt_bap_stream_ops_released_not_called();
548+
549+
bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);
550+
}
551+
552+
ZTEST_F(ascs_test_suite, test_cis_link_loss_in_disabling_state_v1)
553+
{
554+
/* Enabling -> Streaming -> Disabling */
555+
test_cis_link_loss_in_disabling_state(fixture, true);
556+
}
557+
558+
ZTEST_F(ascs_test_suite, test_cis_link_loss_in_disabling_state_v2)
559+
{
560+
/* Enabling -> Disabling */
561+
test_cis_link_loss_in_disabling_state(fixture, false);
562+
}
563+
564+
ZTEST_F(ascs_test_suite, test_cis_link_loss_in_enabling_state)
565+
{
566+
struct bt_bap_stream *stream = &fixture->stream;
567+
struct bt_conn *conn = &fixture->conn;
568+
const struct bt_gatt_attr *ase;
569+
struct bt_iso_chan *chan;
570+
uint8_t ase_id;
571+
int err;
572+
573+
if (IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK)) {
574+
ase = fixture->ase_snk.attr;
575+
ase_id = fixture->ase_snk.id;
576+
} else {
577+
ase = fixture->ase_src.attr;
578+
ase_id = fixture->ase_src.id;
579+
}
580+
zexpect_not_null(ase);
581+
zexpect_true(ase_id != 0x00);
582+
583+
bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb);
584+
585+
test_preamble_state_enabling(conn, ase_id, stream);
586+
err = mock_bt_iso_accept(conn, 0x01, 0x01, &chan);
587+
zassert_equal(0, err, "Failed to connect iso: err %d", err);
588+
589+
/* Mock CIS disconnection */
590+
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_TIMEOUT);
591+
592+
/* Expected no change in ASE state */
593+
expect_bt_bap_stream_ops_qos_set_not_called();
594+
expect_bt_bap_stream_ops_released_not_called();
595+
596+
err = bt_bap_unicast_server_disable(stream);
597+
zassert_equal(0, err, "Failed to disable stream: err %d", err);
598+
599+
if (IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK)) {
600+
expect_bt_bap_stream_ops_qos_set_called_once(stream);
601+
} else {
602+
/* Server-initiated disable operation that shall not cause transition to QoS */
603+
expect_bt_bap_stream_ops_qos_set_not_called();
604+
}
605+
606+
bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);
607+
}

0 commit comments

Comments
 (0)