Bluetooth: audio: ascs: Add cleanup function
This adds ascs_cleanup() function guarded by ZTEST_UNITTEST. The purpose of it is to clean up the ASCS between the tests. Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
parent
4bfebf0a9c
commit
b8d441842a
|
@ -2717,4 +2717,41 @@ static int control_point_notify(struct bt_conn *conn, const void *data, uint16_t
|
|||
return bt_gatt_notify_uuid(conn, BT_UUID_ASCS_ASE_CP, ascs_svc.attrs, data, len);
|
||||
}
|
||||
|
||||
#if defined(ZTEST_UNITTEST)
|
||||
static void ase_cleanup(struct bt_ascs_ase *ase)
|
||||
{
|
||||
if (ase->ep.iso != NULL) {
|
||||
bt_bap_iso_unbind_ep(ase->ep.iso, &ase->ep);
|
||||
}
|
||||
|
||||
if (ase->ep.stream != NULL) {
|
||||
bt_bap_stream_detach(ase->ep.stream);
|
||||
}
|
||||
|
||||
bt_ascs_ase_return_to_slab(ase);
|
||||
}
|
||||
|
||||
void ascs_cleanup(void)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(sessions); i++) {
|
||||
struct bt_ascs *session = &sessions[i];
|
||||
sys_snode_t *node, *tmp;
|
||||
|
||||
if (session->conn == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SYS_SLIST_FOR_EACH_NODE_SAFE(&session->ases, node, tmp) {
|
||||
struct bt_ascs_ase *ase;
|
||||
|
||||
ase = CONTAINER_OF(node, struct bt_ascs_ase, node);
|
||||
|
||||
ase_cleanup(ase);
|
||||
}
|
||||
|
||||
bt_conn_unref(session->conn);
|
||||
session->conn = NULL;
|
||||
}
|
||||
}
|
||||
#endif /* ZTEST_UNITTEST */
|
||||
#endif /* BT_BAP_UNICAST_SERVER */
|
||||
|
|
Loading…
Reference in a new issue