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 <mariusz.skamra@codecoup.pl>
This commit is contained in:
Mariusz Skamra 2023-08-02 10:31:48 +02:00 committed by Carles Cufí
parent 8dcec59115
commit ade1a4495e

View file

@ -475,3 +475,133 @@ ZTEST_F(ascs_test_suite, test_recv_in_enabling_state)
bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);
}
ZTEST_F(ascs_test_suite, test_cis_link_loss_in_streaming_state)
{
struct bt_bap_stream *stream = &fixture->stream;
struct bt_conn *conn = &fixture->conn;
const struct bt_gatt_attr *ase;
struct bt_iso_chan *chan;
uint8_t ase_id;
if (IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK)) {
ase = fixture->ase_snk.attr;
ase_id = fixture->ase_snk.id;
} else {
ase = fixture->ase_src.attr;
ase_id = fixture->ase_src.id;
}
zexpect_not_null(ase);
zexpect_true(ase_id != 0x00);
bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb);
test_preamble_state_streaming(conn, ase_id, stream, &chan,
!IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK));
/* Mock CIS disconnection */
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_TIMEOUT);
/* Expected to notify the upper layers */
expect_bt_bap_stream_ops_qos_set_called_once(stream);
expect_bt_bap_stream_ops_released_not_called();
bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);
}
static void test_cis_link_loss_in_disabling_state(struct ascs_test_suite_fixture *fixture,
bool streaming)
{
struct bt_bap_stream *stream = &fixture->stream;
struct bt_conn *conn = &fixture->conn;
const struct bt_gatt_attr *ase;
struct bt_iso_chan *chan;
uint8_t ase_id;
int err;
Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC);
ase = fixture->ase_src.attr;
ase_id = fixture->ase_src.id;
zexpect_not_null(ase);
zexpect_true(ase_id != 0x00);
bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb);
test_preamble_state_enabling(conn, ase_id, stream);
err = mock_bt_iso_accept(conn, 0x01, 0x01, &chan);
zassert_equal(0, err, "Failed to connect iso: err %d", err);
if (streaming) {
test_ase_control_client_receiver_start_ready(conn, ase_id);
}
test_ase_control_client_disable(conn, ase_id);
test_mocks_reset();
/* Mock CIS disconnection */
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_TIMEOUT);
/* Expected to notify the upper layers */
expect_bt_bap_stream_ops_qos_set_called_once(stream);
expect_bt_bap_stream_ops_released_not_called();
bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);
}
ZTEST_F(ascs_test_suite, test_cis_link_loss_in_disabling_state_v1)
{
/* Enabling -> Streaming -> Disabling */
test_cis_link_loss_in_disabling_state(fixture, true);
}
ZTEST_F(ascs_test_suite, test_cis_link_loss_in_disabling_state_v2)
{
/* Enabling -> Disabling */
test_cis_link_loss_in_disabling_state(fixture, false);
}
ZTEST_F(ascs_test_suite, test_cis_link_loss_in_enabling_state)
{
struct bt_bap_stream *stream = &fixture->stream;
struct bt_conn *conn = &fixture->conn;
const struct bt_gatt_attr *ase;
struct bt_iso_chan *chan;
uint8_t ase_id;
int err;
if (IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK)) {
ase = fixture->ase_snk.attr;
ase_id = fixture->ase_snk.id;
} else {
ase = fixture->ase_src.attr;
ase_id = fixture->ase_src.id;
}
zexpect_not_null(ase);
zexpect_true(ase_id != 0x00);
bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb);
test_preamble_state_enabling(conn, ase_id, stream);
err = mock_bt_iso_accept(conn, 0x01, 0x01, &chan);
zassert_equal(0, err, "Failed to connect iso: err %d", err);
/* Mock CIS disconnection */
mock_bt_iso_disconnected(chan, BT_HCI_ERR_CONN_TIMEOUT);
/* Expected no change in ASE state */
expect_bt_bap_stream_ops_qos_set_not_called();
expect_bt_bap_stream_ops_released_not_called();
err = bt_bap_unicast_server_disable(stream);
zassert_equal(0, err, "Failed to disable stream: err %d", err);
if (IS_ENABLED(CONFIG_BT_ASCS_ASE_SNK)) {
expect_bt_bap_stream_ops_qos_set_called_once(stream);
} else {
/* Server-initiated disable operation that shall not cause transition to QoS */
expect_bt_bap_stream_ops_qos_set_not_called();
}
bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb);
}