36
36
#include "ztest_assert.h"
37
37
#include "ztest_test.h"
38
38
39
+ BUILD_ASSERT (CONFIG_BT_MAX_CONN * (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT +
40
+ CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT ) >=
41
+ CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT );
42
+
43
+ /* Either BT_AUDIO_DIR_SINK or BT_AUDIO_DIR_SOURCE */
44
+ #define INDEX_TO_DIR (_idx ) (((_idx) & 1U) + 1U)
45
+
46
+ DECLARE_FAKE_VOID_FUNC (mock_bap_discover_endpoint , struct bt_conn * , enum bt_audio_dir ,
47
+ struct bt_bap_ep * );
48
+ DEFINE_FAKE_VOID_FUNC (mock_bap_discover_endpoint , struct bt_conn * , enum bt_audio_dir ,
49
+ struct bt_bap_ep * );
50
+
39
51
struct cap_initiator_test_unicast_start_fixture {
40
52
struct bt_cap_stream cap_streams [CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT ];
41
- struct bt_bap_ep eps [CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT ];
53
+ struct bt_bap_ep * snk_eps [CONFIG_BT_MAX_CONN ][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT ];
54
+ struct bt_bap_ep * src_eps [CONFIG_BT_MAX_CONN ][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT ];
42
55
struct bt_cap_unicast_audio_start_stream_param
43
56
audio_start_stream_params [CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT ];
44
57
struct bt_cap_unicast_audio_start_param audio_start_param ;
@@ -51,9 +64,9 @@ static void cap_initiator_test_unicast_start_fixture_init(
51
64
struct cap_initiator_test_unicast_start_fixture * fixture )
52
65
{
53
66
struct bt_cap_unicast_group_stream_pair_param
54
- pair_params [CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT ] = {0 };
67
+ group_pair_params [CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT ] = {0 };
55
68
struct bt_cap_unicast_group_stream_param
56
- stream_params [CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT ] = {0 };
69
+ group_stream_param [CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT ] = {0 };
57
70
struct bt_cap_unicast_group_param group_param = {0 };
58
71
size_t stream_cnt = 0U ;
59
72
size_t pair_cnt = 0U ;
@@ -63,24 +76,20 @@ static void cap_initiator_test_unicast_start_fixture_init(
63
76
BT_AUDIO_LOCATION_MONO_AUDIO , BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED );
64
77
65
78
for (size_t i = 0U ; i < ARRAY_SIZE (fixture -> conns ); i ++ ) {
66
- test_conn_init (& fixture -> conns [i ]);
79
+ test_conn_init (& fixture -> conns [i ], i );
67
80
}
68
81
69
- for ( size_t i = 0U ; i < ARRAY_SIZE (fixture -> eps ); i ++ ) {
70
- const uint8_t dir = ( i & 1 ) + 1 ; /* Makes it either 1 or 2 (sink or source)*/
82
+ while ( stream_cnt < ARRAY_SIZE (group_stream_param ) ) {
83
+ const enum bt_audio_dir dir = INDEX_TO_DIR ( stream_cnt );
71
84
72
- fixture -> eps [i ].dir = dir ;
73
- }
74
-
75
- while (stream_cnt < ARRAY_SIZE (stream_params )) {
76
- stream_params [stream_cnt ].stream = & fixture -> cap_streams [stream_cnt ];
77
- stream_params [stream_cnt ].qos_cfg = & fixture -> preset .qos ;
85
+ group_stream_param [stream_cnt ].stream = & fixture -> cap_streams [stream_cnt ];
86
+ group_stream_param [stream_cnt ].qos_cfg = & fixture -> preset .qos ;
78
87
79
88
/* Switch between sink and source depending on index*/
80
- if (( stream_cnt & 1 ) == 0 ) {
81
- pair_params [pair_cnt ].tx_param = & stream_params [stream_cnt ];
89
+ if (dir == BT_AUDIO_DIR_SINK ) {
90
+ group_pair_params [pair_cnt ].tx_param = & group_stream_param [stream_cnt ];
82
91
} else {
83
- pair_params [pair_cnt ].rx_param = & stream_params [stream_cnt ];
92
+ group_pair_params [pair_cnt ].rx_param = & group_stream_param [stream_cnt ];
84
93
}
85
94
86
95
pair_cnt = DIV_ROUND_UP (stream_cnt , 2U );
@@ -89,42 +98,133 @@ static void cap_initiator_test_unicast_start_fixture_init(
89
98
90
99
group_param .packing = BT_ISO_PACKING_SEQUENTIAL ;
91
100
group_param .params_count = pair_cnt ;
92
- group_param .params = pair_params ;
101
+ group_param .params = group_pair_params ;
93
102
94
103
err = bt_cap_unicast_group_create (& group_param , & fixture -> unicast_group );
95
104
zassert_equal (err , 0 , "Unexpected return value %d" , err );
105
+ }
106
+
107
+ static void * cap_initiator_test_unicast_start_setup (void )
108
+ {
109
+ struct cap_initiator_test_unicast_start_fixture * fixture ;
110
+
111
+ fixture = malloc (sizeof (* fixture ));
112
+ zassert_not_null (fixture );
113
+
114
+ return fixture ;
115
+ }
116
+
117
+ static void mock_discover (struct cap_initiator_test_unicast_start_fixture * fixture )
118
+ {
119
+ struct bt_bap_unicast_client_cb unicast_client_cb = {
120
+ .endpoint = mock_bap_discover_endpoint ,
121
+ };
122
+ int err ;
123
+
124
+ err = bt_bap_unicast_client_register_cb (& unicast_client_cb );
125
+ zassert_equal (0 , err , "Unexpected return value %d" , err );
126
+
127
+ for (size_t i = 0U ; i < ARRAY_SIZE (fixture -> conns ); i ++ ) {
128
+ RESET_FAKE (mock_bap_discover_endpoint );
129
+ err = bt_bap_unicast_client_discover (& fixture -> conns [i ], BT_AUDIO_DIR_SINK );
130
+ zassert_equal (0 , err , "Unexpected return value %d" , err );
131
+
132
+ /* TODO: use callback to populate eps */
133
+
134
+ zexpect_call_count ("unicast_client_cb.bap_discover_endpoint" ,
135
+ CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT ,
136
+ mock_bap_discover_endpoint_fake .call_count );
137
+ for (size_t j = 0U ; j < mock_bap_discover_endpoint_fake .call_count ; j ++ ) {
138
+ /* Verify conn */
139
+ zassert_equal (mock_bap_discover_endpoint_fake .arg0_history [j ],
140
+ & fixture -> conns [i ], "%p" ,
141
+ mock_bap_discover_endpoint_fake .arg0_history [j ]);
142
+
143
+ /* Verify dir */
144
+ zassert_equal (mock_bap_discover_endpoint_fake .arg1_history [j ],
145
+ BT_AUDIO_DIR_SINK , "%d" ,
146
+ mock_bap_discover_endpoint_fake .arg1_history [j ]);
147
+
148
+ /* Verify and store ep */
149
+ zassert_not_equal (mock_bap_discover_endpoint_fake .arg2_history [j ], NULL ,
150
+ "%p" , mock_bap_discover_endpoint_fake .arg2_history [j ]);
151
+
152
+ fixture -> snk_eps [fixture -> conns [i ].index ][j ] =
153
+ mock_bap_discover_endpoint_fake .arg2_history [j ];
154
+ }
96
155
156
+ RESET_FAKE (mock_bap_discover_endpoint );
157
+ err = bt_bap_unicast_client_discover (& fixture -> conns [i ], BT_AUDIO_DIR_SOURCE );
158
+ zassert_equal (0 , err , "Unexpected return value %d" , err );
159
+
160
+ zexpect_call_count ("unicast_client_cb.bap_discover_endpoint" ,
161
+ CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT ,
162
+ mock_bap_discover_endpoint_fake .call_count );
163
+ for (size_t j = 0U ; j < mock_bap_discover_endpoint_fake .call_count ; j ++ ) {
164
+ /* Verify conn */
165
+ zassert_equal (mock_bap_discover_endpoint_fake .arg0_history [j ],
166
+ & fixture -> conns [i ], "%p" ,
167
+ mock_bap_discover_endpoint_fake .arg0_history [j ]);
168
+
169
+ /* Verify dir */
170
+ zassert_equal (mock_bap_discover_endpoint_fake .arg1_history [j ],
171
+ BT_AUDIO_DIR_SOURCE , "%d" ,
172
+ mock_bap_discover_endpoint_fake .arg1_history [j ]);
173
+
174
+ /* Verify and store ep */
175
+ zassert_not_equal (mock_bap_discover_endpoint_fake .arg2_history [j ], NULL ,
176
+ "%p" , mock_bap_discover_endpoint_fake .arg2_history [j ]);
177
+
178
+ fixture -> src_eps [fixture -> conns [i ].index ][j ] =
179
+ mock_bap_discover_endpoint_fake .arg2_history [j ];
180
+ }
181
+ }
182
+
183
+ /* We don't need the callbacks anymore */
184
+ err = bt_bap_unicast_client_unregister_cb (& unicast_client_cb );
185
+ zassert_equal (0 , err , "Unexpected return value %d" , err );
186
+ }
187
+
188
+ static void init_default_params (struct cap_initiator_test_unicast_start_fixture * fixture )
189
+ {
97
190
/* Setup default params */
98
191
ARRAY_FOR_EACH (fixture -> audio_start_stream_params , i ) {
99
192
struct bt_cap_unicast_audio_start_stream_param * stream_param =
100
193
& fixture -> audio_start_stream_params [i ];
194
+
101
195
/* We pair 2 streams, so only increase conn_index every 2nd stream and otherwise
102
196
* round robin on all conns
103
197
*/
104
- const size_t conn_index = (i / 2 ) % ARRAY_SIZE (fixture -> conns );
198
+ const size_t conn_index = (i / 2U ) % ARRAY_SIZE (fixture -> conns );
199
+ const size_t ep_index = i / (ARRAY_SIZE (fixture -> conns ) * 2U );
200
+ const enum bt_audio_dir dir = INDEX_TO_DIR (i );
105
201
106
202
stream_param -> stream = & fixture -> cap_streams [i ];
107
203
stream_param -> codec_cfg = & fixture -> preset .codec_cfg ;
108
- /* Distribute the streams equally among the connections */
204
+
205
+ /* Distribute the streams like
206
+ * [0]: conn[0] src[0]
207
+ * [1]: conn[0] snk[0]
208
+ * [2]: conn[1] src[0]
209
+ * [3]: conn[0] snk[0]
210
+ * [4]: conn[0] src[1]
211
+ * [5]: conn[0] snk[1]
212
+ * [6]: conn[1] src[1]
213
+ * [7]: conn[0] snk[1]
214
+ */
109
215
stream_param -> member .member = & fixture -> conns [conn_index ];
110
- stream_param -> ep = & fixture -> eps [i ];
216
+ if (dir == BT_AUDIO_DIR_SINK ) {
217
+ stream_param -> ep = fixture -> snk_eps [conn_index ][ep_index ];
218
+ } else {
219
+ stream_param -> ep = fixture -> src_eps [conn_index ][ep_index ];
220
+ }
111
221
}
112
222
113
223
fixture -> audio_start_param .type = BT_CAP_SET_TYPE_AD_HOC ;
114
224
fixture -> audio_start_param .count = CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT ;
115
225
fixture -> audio_start_param .stream_params = fixture -> audio_start_stream_params ;
116
226
}
117
227
118
- static void * cap_initiator_test_unicast_start_setup (void )
119
- {
120
- struct cap_initiator_test_unicast_start_fixture * fixture ;
121
-
122
- fixture = malloc (sizeof (* fixture ));
123
- zassert_not_null (fixture );
124
-
125
- return fixture ;
126
- }
127
-
128
228
static void cap_initiator_test_unicast_start_before (void * f )
129
229
{
130
230
struct cap_initiator_test_unicast_start_fixture * fixture = f ;
@@ -135,6 +235,9 @@ static void cap_initiator_test_unicast_start_before(void *f)
135
235
136
236
err = bt_cap_initiator_register_cb (& mock_cap_initiator_cb );
137
237
zassert_equal (0 , err , "Unexpected return value %d" , err );
238
+
239
+ mock_discover (fixture );
240
+ init_default_params (fixture );
138
241
}
139
242
140
243
static void cap_initiator_test_unicast_start_after (void * f )
0 commit comments