3
3
/*
4
4
* Copyright (c) 2023 Codecoup
5
5
* Copyright (c) 2024 Demant A/S
6
+ * Copyright (c) 2024 Nordic Semiconductor ASA
6
7
*
7
8
* SPDX-License-Identifier: Apache-2.0
8
9
*/
9
10
11
+ #include <errno.h>
10
12
#include <stdlib.h>
11
13
#include <string.h>
12
14
#include <zephyr/fff.h>
34
36
#include "pacs.h"
35
37
36
38
#include "test_common.h"
39
+ #include "ztest_assert.h"
37
40
38
41
DEFINE_FFF_GLOBALS ;
39
42
@@ -70,6 +73,7 @@ static void ascs_test_suite_fixture_init(struct ascs_test_suite_fixture *fixture
70
73
memset (fixture , 0 , sizeof (* fixture ));
71
74
72
75
err = bt_bap_unicast_server_register (& param );
76
+ zassert_equal (err , 0 , "Unexpected err response %d" , err );
73
77
74
78
fixture -> ase_cp = test_ase_control_point_get ();
75
79
@@ -109,11 +113,17 @@ static void ascs_test_suite_teardown(void *f)
109
113
110
114
static void ascs_test_suite_after (void * f )
111
115
{
112
- /* We skip error-checking this, as somehow this breaks the tests, due to seemingly
113
- * memory corruption, causing incorrect lookup of attributes in following 'before' calls
114
- */
115
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
116
- bt_bap_unicast_server_unregister ();
116
+ int err ;
117
+
118
+ /* If any of these fails, it's a fatal error for any tests running afterwards */
119
+ err = bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
120
+ zassert_true (err == 0 || err == - EALREADY , "Unexpected err response %d" , err );
121
+
122
+ /* Sleep to trigger any pending state changes from unregister_cb */
123
+ k_sleep (K_SECONDS (1 ));
124
+
125
+ err = bt_bap_unicast_server_unregister ();
126
+ zassert_equal (err , 0 , "Unexpected err response %d" , err );
117
127
}
118
128
119
129
ZTEST_SUITE (ascs_test_suite , NULL , ascs_test_suite_setup , ascs_test_suite_before ,
@@ -153,158 +163,6 @@ ZTEST_F(ascs_test_suite, test_sink_ase_read_state_idle)
153
163
zassert_equal (0x00 , hdr .ase_state , "unexpected ASE_State 0x%02x" , hdr .ase_state );
154
164
}
155
165
156
- ZTEST_F (ascs_test_suite , test_cb_register_without_ascs_registered )
157
- {
158
- int err ;
159
-
160
- /* Unregister ASCS, as its registered through setup */
161
- err = bt_bap_unicast_server_unregister ();
162
- zassert_equal (err , 0 , "unexpected err response %d" , err );
163
-
164
- err = bt_bap_unicast_server_register_cb (& mock_bap_unicast_server_cb );
165
- zassert_equal (err , - ENOTSUP , "unexpected err response %d" , err );
166
- }
167
-
168
- ZTEST_F (ascs_test_suite , test_ascs_register_with_null_param )
169
- {
170
- int err ;
171
-
172
- /* Unregister ASCS, as its registered through setup */
173
- err = bt_bap_unicast_server_unregister ();
174
- zassert_equal (err , 0 , "unexpected err response %d" , err );
175
-
176
- err = bt_bap_unicast_server_register (NULL );
177
- zassert_equal (err , - EINVAL , "unexpected err response %d" , err );
178
- }
179
-
180
- ZTEST_F (ascs_test_suite , test_ascs_register_twice )
181
- {
182
- int err ;
183
- struct bt_bap_unicast_server_register_param param = {
184
- CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT ,
185
- CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT
186
- };
187
-
188
- /* Setup already registered once, so calling once here should be sufficient */
189
- err = bt_bap_unicast_server_register (& param );
190
- zassert_equal (err , - EALREADY , "unexpected err response %d" , err );
191
- }
192
-
193
- ZTEST_F (ascs_test_suite , test_ascs_register_too_many_sinks )
194
- {
195
- int err ;
196
- struct bt_bap_unicast_server_register_param param = {
197
- CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT + 1 ,
198
- CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT
199
- };
200
-
201
- /* Unregister ASCS, as its registered through setup */
202
- err = bt_bap_unicast_server_unregister ();
203
- zassert_equal (err , 0 , "unexpected err response %d" , err );
204
-
205
- err = bt_bap_unicast_server_register (& param );
206
- zassert_equal (err , - EINVAL , "unexpected err response %d" , err );
207
- }
208
-
209
- ZTEST_F (ascs_test_suite , test_ascs_register_too_many_sources )
210
- {
211
- int err ;
212
- struct bt_bap_unicast_server_register_param param = {
213
- CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT ,
214
- CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT + 1
215
- };
216
-
217
- /* Unregister ASCS, as its registered through setup */
218
- err = bt_bap_unicast_server_unregister ();
219
- zassert_equal (err , 0 , "unexpected err response %d" , err );
220
-
221
- err = bt_bap_unicast_server_register (& param );
222
- zassert_equal (err , - EINVAL , "unexpected err response %d" , err );
223
- }
224
-
225
- ZTEST_F (ascs_test_suite , test_ascs_register_zero_ases )
226
- {
227
- int err ;
228
- struct bt_bap_unicast_server_register_param param = {
229
- 0 ,
230
- 0
231
- };
232
-
233
- /* Unregister ASCS, as its registered through setup */
234
- err = bt_bap_unicast_server_unregister ();
235
- zassert_equal (err , 0 , "unexpected err response %d" , err );
236
-
237
- err = bt_bap_unicast_server_register (& param );
238
- zassert_equal (err , - EINVAL , "unexpected err response %d" , err );
239
- }
240
-
241
- ZTEST_F (ascs_test_suite , test_ascs_register_fewer_than_max_ases )
242
- {
243
- int err ;
244
- struct bt_bap_unicast_server_register_param param = {
245
- CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT > 0 ? CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT - 1 : 0 ,
246
- CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT > 0 ? CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT - 1 : 0
247
- };
248
-
249
- /* Unregister ASCS, as its registered through setup */
250
- err = bt_bap_unicast_server_unregister ();
251
- zassert_equal (err , 0 , "unexpected err response %d" , err );
252
-
253
- err = bt_bap_unicast_server_register (& param );
254
- zassert_equal (err , 0 , "unexpected err response %d" , err );
255
- }
256
-
257
- ZTEST_F (ascs_test_suite , test_ascs_unregister_without_register )
258
- {
259
- int err ;
260
-
261
- /* Unregister ASCS, as its registered through setup */
262
- err = bt_bap_unicast_server_unregister ();
263
- zassert_equal (err , 0 , "unexpected err response %d" , err );
264
-
265
- err = bt_bap_unicast_server_unregister ();
266
- zassert_equal (err , - EALREADY , "unexpected err response %d" , err );
267
- }
268
-
269
- ZTEST_F (ascs_test_suite , test_ascs_unregister_with_ases_in_config_state )
270
- {
271
- const struct test_ase_chrc_value_hdr * hdr ;
272
- const struct bt_gatt_attr * ase ;
273
- struct bt_bap_stream * stream = & fixture -> stream ;
274
- struct bt_conn * conn = & fixture -> conn ;
275
- struct bt_gatt_notify_params * notify_params ;
276
- uint8_t ase_id ;
277
- int err ;
278
-
279
- if (IS_ENABLED (CONFIG_BT_ASCS_ASE_SNK )) {
280
- ase = fixture -> ase_snk .attr ;
281
- ase_id = fixture -> ase_snk .id ;
282
- } else {
283
- ase = fixture -> ase_src .attr ;
284
- ase_id = fixture -> ase_src .id ;
285
- }
286
-
287
- zexpect_not_null (ase );
288
- zexpect_true (ase_id != 0x00 );
289
-
290
- err = bt_bap_unicast_server_register_cb (& mock_bap_unicast_server_cb );
291
- zassert_equal (err , 0 , "unexpected err response %d" , err );
292
-
293
- /* Set ASE to non-idle state */
294
- test_ase_control_client_config_codec (conn , ase_id , stream );
295
-
296
- err = bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
297
- zassert_equal (err , 0 , "unexpected err response %d" , err );
298
-
299
- err = bt_bap_unicast_server_unregister ();
300
-
301
- /* Expected to notify the upper layers */
302
- expect_bt_bap_unicast_server_cb_release_called_once (stream );
303
- expect_bt_bap_stream_ops_released_called_once (stream );
304
-
305
- zassert_equal (err , 0 , "unexpected err response %d" , err );
306
- }
307
-
308
166
ZTEST_F (ascs_test_suite , test_release_ase_on_callback_unregister )
309
167
{
310
168
const struct test_ase_chrc_value_hdr * hdr ;
@@ -424,8 +282,6 @@ ZTEST_F(ascs_test_suite, test_release_ase_on_acl_disconnection)
424
282
425
283
/* Mock CIS disconnection */
426
284
mock_bt_iso_disconnected (chan , BT_HCI_ERR_CONN_TIMEOUT );
427
-
428
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
429
285
}
430
286
431
287
ZTEST_F (ascs_test_suite , test_release_ase_pair_on_acl_disconnection )
@@ -486,8 +342,6 @@ ZTEST_F(ascs_test_suite, test_release_ase_pair_on_acl_disconnection)
486
342
487
343
/* Mock CIS disconnection */
488
344
mock_bt_iso_disconnected (chan , BT_HCI_ERR_CONN_TIMEOUT );
489
-
490
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
491
345
}
492
346
493
347
ZTEST_F (ascs_test_suite , test_recv_in_streaming_state )
@@ -514,8 +368,6 @@ ZTEST_F(ascs_test_suite, test_recv_in_streaming_state)
514
368
515
369
/* Verification */
516
370
expect_bt_bap_stream_ops_recv_called_once (stream , & info , & buf );
517
-
518
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
519
371
}
520
372
521
373
ZTEST_F (ascs_test_suite , test_recv_in_enabling_state )
@@ -547,8 +399,6 @@ ZTEST_F(ascs_test_suite, test_recv_in_enabling_state)
547
399
548
400
/* Verification */
549
401
expect_bt_bap_stream_ops_recv_not_called ();
550
-
551
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
552
402
}
553
403
554
404
ZTEST_F (ascs_test_suite , test_cis_link_loss_in_streaming_state )
@@ -584,8 +434,6 @@ ZTEST_F(ascs_test_suite, test_cis_link_loss_in_streaming_state)
584
434
expect_bt_bap_stream_ops_disabled_called_once (stream );
585
435
expect_bt_bap_stream_ops_released_not_called ();
586
436
expect_bt_bap_stream_ops_disconnected_called_once (stream );
587
-
588
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
589
437
}
590
438
591
439
static void test_cis_link_loss_in_disabling_state (struct ascs_test_suite_fixture * fixture ,
@@ -630,8 +478,6 @@ static void test_cis_link_loss_in_disabling_state(struct ascs_test_suite_fixture
630
478
expect_bt_bap_stream_ops_disabled_not_called ();
631
479
expect_bt_bap_stream_ops_released_not_called ();
632
480
expect_bt_bap_stream_ops_disconnected_called_once (stream );
633
-
634
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
635
481
}
636
482
637
483
ZTEST_F (ascs_test_suite , test_cis_link_loss_in_disabling_state_v1 )
@@ -690,8 +536,6 @@ ZTEST_F(ascs_test_suite, test_cis_link_loss_in_enabling_state)
690
536
/* Server-initiated disable operation that shall not cause transition to QoS */
691
537
expect_bt_bap_stream_ops_qos_set_not_called ();
692
538
}
693
-
694
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
695
539
}
696
540
697
541
ZTEST_F (ascs_test_suite , test_cis_link_loss_in_enabling_state_client_retries )
@@ -741,8 +585,6 @@ ZTEST_F(ascs_test_suite, test_cis_link_loss_in_enabling_state_client_retries)
741
585
742
586
expect_bt_bap_stream_ops_connected_called_twice (stream );
743
587
expect_bt_bap_stream_ops_started_called_once (stream );
744
-
745
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
746
588
}
747
589
748
590
static struct bt_bap_stream * stream_allocated ;
@@ -823,6 +665,4 @@ ZTEST_F(ascs_test_suite, test_ase_state_notification_retry)
823
665
k_sleep (K_MSEC (BT_CONN_INTERVAL_TO_MS (info .le .interval )));
824
666
825
667
expect_bt_bap_stream_ops_configured_called_once (stream , EMPTY );
826
-
827
- bt_bap_unicast_server_unregister_cb (& mock_bap_unicast_server_cb );
828
668
}
0 commit comments