1 /*
2 * Copyright (c) 2020 Demant
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /* Each segment header in a test would usually be written to when it is first
8 * inserted and again when the segment is finalized.
9 */
10 #define EXPECTED_SEG_HDR_WRITES (2)
11
12 /*------------------ PDU Allocation Callback ---------------------------------*/
13 /* Fake function */
14 FAKE_VALUE_FUNC(isoal_status_t, source_pdu_alloc_test, struct isoal_pdu_buffer *);
15
16 /* Customized buffering for data returned in pdu_buffer */
17 /* Queue for pdu_buffer return data */
18 static struct {
19 struct isoal_pdu_buffer out[10];
20 size_t buffer_size;
21 size_t pos;
22
23 } custom_source_pdu_alloc_test_pdu_buffers;
24
25 /* Push to pdu_buffer queue */
push_custom_source_pdu_alloc_test_pdu_buffer(struct isoal_pdu_buffer * data)26 static void push_custom_source_pdu_alloc_test_pdu_buffer(struct isoal_pdu_buffer *data)
27 {
28 size_t buffer_size = custom_source_pdu_alloc_test_pdu_buffers.buffer_size;
29
30 custom_source_pdu_alloc_test_pdu_buffers.out[buffer_size] = *data;
31 zassert_true(custom_source_pdu_alloc_test_pdu_buffers.buffer_size <=
32 ARRAY_SIZE(custom_source_pdu_alloc_test_pdu_buffers.out),
33 "Maximum PDU buffers reached!!");
34
35 custom_source_pdu_alloc_test_pdu_buffers.buffer_size++;
36 }
37
38 /* Customized routine for fake function */
custom_source_pdu_alloc_test(struct isoal_pdu_buffer * pdu_buffer)39 static isoal_status_t custom_source_pdu_alloc_test(struct isoal_pdu_buffer *pdu_buffer)
40 {
41 isoal_test_debug_trace_func_call(__func__, "IN");
42
43 /* Return PDU buffer details as provided by the test */
44 size_t pos = custom_source_pdu_alloc_test_pdu_buffers.pos;
45 size_t buffer_size = custom_source_pdu_alloc_test_pdu_buffers.buffer_size;
46
47 zassert_not_null(pdu_buffer);
48 zassert_true(pos < buffer_size,
49 "No PDU buffers (Allocated %u, required %u)",
50 buffer_size,
51 pos);
52 (void)memcpy(pdu_buffer,
53 &custom_source_pdu_alloc_test_pdu_buffers.out[pos],
54 sizeof(*pdu_buffer));
55
56 custom_source_pdu_alloc_test_pdu_buffers.pos++;
57
58 return source_pdu_alloc_test_fake.return_val;
59 }
60
61 #define SET_NEXT_PDU_ALLOC_BUFFER(_buf) push_custom_source_pdu_alloc_test_pdu_buffer(_buf)
62
63 #define PDU_ALLOC_TEST_RETURNS(_status) source_pdu_alloc_test_fake.return_val = _status
64
65 #define ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(_expected) \
66 zassert_equal(_expected, \
67 source_pdu_alloc_test_fake.call_count, \
68 "Expected %u got %u", \
69 _expected, \
70 source_pdu_alloc_test_fake.call_count)
71
72 /*------------------ PDU Write Callback --------------------------------------*/
73 /* Fake function */
74 FAKE_VALUE_FUNC(isoal_status_t,
75 source_pdu_write_test,
76 struct isoal_pdu_buffer *,
77 const size_t,
78 const uint8_t *,
79 const size_t);
80
81 FAKE_VOID_FUNC(source_pdu_write_test_handler, struct isoal_pdu_buffer);
82
83 /* Customized buffering for data returned in sdu_payload */
84 /* Queue for sdu_payload return data */
85 static struct {
86 uint8_t out[20][TEST_TX_SDU_FRAG_PAYLOAD_MAX];
87 size_t out_size[20];
88 size_t buffer_size;
89 size_t pos;
90
91 } custom_source_pdu_write_test_sdu_payloads;
92
93 /* Push to sdu_payload queue */
push_custom_source_pdu_write_test_sdu_payload(const uint8_t * data,const size_t length)94 static void push_custom_source_pdu_write_test_sdu_payload(const uint8_t *data, const size_t length)
95 {
96 size_t buffer_size = custom_source_pdu_write_test_sdu_payloads.buffer_size;
97
98 zassert_true(length <= TEST_TX_SDU_FRAG_PAYLOAD_MAX,
99 "Length exceeds TEST_TX_SDU_FRAG_PAYLOAD_MAX");
100 memcpy(&custom_source_pdu_write_test_sdu_payloads.out[buffer_size][0], data, length);
101 custom_source_pdu_write_test_sdu_payloads.out_size[buffer_size] = length;
102 zassert_true(buffer_size <= ARRAY_SIZE(custom_source_pdu_write_test_sdu_payloads.out),
103 "Maximum SDU payloads reached!!");
104
105 custom_source_pdu_write_test_sdu_payloads.buffer_size++;
106 }
107
check_next_custom_source_pdu_write_test_sdu_payload(const uint8_t * data,const size_t length,const uint32_t line)108 static void check_next_custom_source_pdu_write_test_sdu_payload(const uint8_t *data,
109 const size_t length,
110 const uint32_t line)
111 {
112 size_t pos = custom_source_pdu_write_test_sdu_payloads.pos;
113 size_t buffer_size = custom_source_pdu_write_test_sdu_payloads.buffer_size;
114
115 zassert_true(pos < buffer_size, "%u exceeds received SDU payloads %u", pos, buffer_size);
116 zassert_equal(length,
117 custom_source_pdu_write_test_sdu_payloads.out_size[pos],
118 "Expected %u != received %u",
119 length,
120 custom_source_pdu_write_test_sdu_payloads.out_size[pos]);
121 for (size_t i = 0; i < custom_source_pdu_write_test_sdu_payloads.out_size[pos]; i++) {
122 zassert_equal(custom_source_pdu_write_test_sdu_payloads.out[pos][i],
123 data[i],
124 "[Line %lu] deviation at index %u, expected %u, got %u",
125 line,
126 i,
127 data[i],
128 custom_source_pdu_write_test_sdu_payloads.out[pos][i]);
129 }
130 custom_source_pdu_write_test_sdu_payloads.pos++;
131 }
132
133 /* Customized routine for fake function */
custom_source_pdu_write_test(struct isoal_pdu_buffer * pdu_buffer,const size_t pdu_offset,const uint8_t * sdu_payload,const size_t consume_len)134 static isoal_status_t custom_source_pdu_write_test(struct isoal_pdu_buffer *pdu_buffer,
135 const size_t pdu_offset,
136 const uint8_t *sdu_payload,
137 const size_t consume_len)
138 {
139 isoal_test_debug_trace_func_call(__func__, "IN");
140
141 #if defined(DEBUG_TEST)
142 zassert_not_null(pdu_buffer, "");
143 zassert_not_null(sdu_payload, "");
144
145 zassert_false((pdu_offset + consume_len) > pdu_buffer->size,
146 "Write size of %u at offset %u exceeds buffer!",
147 consume_len,
148 pdu_offset);
149
150 /* Copy source to destination at given offset */
151 memcpy(&pdu_buffer->pdu->payload[pdu_offset], sdu_payload, consume_len);
152 #endif
153
154 /* Return SDU payload details as provided by the test */
155 zassert_not_null(sdu_payload, NULL);
156
157 source_pdu_write_test_handler(*pdu_buffer);
158
159 push_custom_source_pdu_write_test_sdu_payload(sdu_payload, consume_len);
160
161 return source_pdu_write_test_fake.return_val;
162 }
163
164 #define PDU_WRITE_TEST_RETURNS(_status) source_pdu_write_test_fake.return_val = _status;
165
166 #define ZASSERT_PDU_WRITE_TEST(_typ, _pdu_buffer, _pdu_offset, _sdu_payload, _consume_len) \
167 zassert_equal_ptr(_pdu_buffer.handle, \
168 source_pdu_write_test_handler_fake.arg0_##_typ.handle, \
169 "\t\t%p != %p", \
170 _pdu_buffer.handle, \
171 source_pdu_write_test_handler_fake.arg0_##_typ.handle); \
172 zassert_equal_ptr(_pdu_buffer.pdu, \
173 source_pdu_write_test_handler_fake.arg0_##_typ.pdu, \
174 "\t\t%p != %p", \
175 _pdu_buffer.pdu, \
176 source_pdu_write_test_handler_fake.arg0_##_typ.pdu); \
177 zassert_equal(_pdu_buffer.size, \
178 source_pdu_write_test_handler_fake.arg0_##_typ.size, \
179 "\t\t%u != %u", \
180 _pdu_buffer.size, \
181 source_pdu_write_test_handler_fake.arg0_##_typ.size); \
182 zassert_equal(_pdu_offset, \
183 source_pdu_write_test_fake.arg1_##_typ, \
184 "\t\t%u != %u", \
185 _pdu_offset, \
186 source_pdu_write_test_fake.arg1_##_typ); \
187 zassert_equal(_consume_len, \
188 source_pdu_write_test_fake.arg3_##_typ, \
189 "\t\t%u != %u", \
190 _consume_len, \
191 source_pdu_write_test_fake.arg3_##_typ); \
192 check_next_custom_source_pdu_write_test_sdu_payload((const uint8_t *)_sdu_payload, \
193 _consume_len, __LINE__)
194
195 #define ZASSERT_PDU_WRITE_TEST_CALL_COUNT(_expected) \
196 zassert_equal(_expected, \
197 source_pdu_write_test_fake.call_count, \
198 "Expected %u, got %u", \
199 _expected, \
200 source_pdu_write_test_fake.call_count)
201
202 /*------------------ PDU Emit Callback --------------------------------------*/
203 /**
204 * Emit the encoded node to the transmission queue
205 * @param node_tx TX node to enqueue
206 * @param handle CIS/BIS handle
207 * @return Error status of enqueue operation
208 */
209
210 /* Fake function */
211 FAKE_VALUE_FUNC(isoal_status_t, source_pdu_emit_test, struct node_tx_iso *, const uint16_t);
212
213 FAKE_VOID_FUNC(source_pdu_emit_test_handler, struct node_tx_iso, struct pdu_iso);
214
215 /* Customized routine for fake function */
custom_source_pdu_emit_test(struct node_tx_iso * node_tx,const uint16_t handle)216 static isoal_status_t custom_source_pdu_emit_test(struct node_tx_iso *node_tx,
217 const uint16_t handle)
218 {
219 isoal_test_debug_trace_func_call(__func__, "IN");
220
221 zassert_not_null(node_tx);
222 zassert_not_null(node_tx->pdu);
223 source_pdu_emit_test_handler(*node_tx, *((struct pdu_iso *)node_tx->pdu));
224
225 isoal_test_debug_print_tx_pdu(node_tx);
226
227 return source_pdu_emit_test_fake.return_val;
228 }
229
230 #define PDU_EMIT_TEST_RETURNS(_status) source_pdu_emit_test_fake.return_val = _status
231
232 #define ZASSERT_PDU_EMIT_TEST(_typ, \
233 _node_tx, \
234 _payload_count, \
235 _sdu_fragments, \
236 _ll_id, \
237 _length, \
238 _handle) \
239 zassert_equal_ptr(_node_tx, \
240 source_pdu_emit_test_fake.arg0_##_typ, \
241 "\t\t%p != %p", \
242 _node_tx, \
243 source_pdu_emit_test_fake.arg0_##_typ); \
244 zassert_equal(_payload_count, \
245 source_pdu_emit_test_handler_fake.arg0_##_typ.payload_count, \
246 "\t\t%u != %u", \
247 _payload_count, \
248 source_pdu_emit_test_handler_fake.arg0_##_typ.payload_count); \
249 zassert_equal(_sdu_fragments, \
250 source_pdu_emit_test_handler_fake.arg0_##_typ.sdu_fragments, \
251 "\t\t%u != %u", \
252 _sdu_fragments, \
253 source_pdu_emit_test_handler_fake.arg0_##_typ.sdu_fragments); \
254 zassert_equal(_ll_id, \
255 source_pdu_emit_test_handler_fake.arg1_##_typ.ll_id, \
256 "\t\t%u != %u", \
257 _ll_id, \
258 source_pdu_emit_test_handler_fake.arg1_##_typ.ll_id); \
259 zassert_equal(_length, \
260 source_pdu_emit_test_handler_fake.arg1_##_typ.len, \
261 "\t\t%u != %u", \
262 _length, \
263 source_pdu_emit_test_handler_fake.arg1_##_typ.len); \
264 zassert_equal(bt_iso_handle(_handle), \
265 source_pdu_emit_test_fake.arg1_##_typ, \
266 "\t\t%08x != %08x", \
267 bt_iso_handle(_handle), \
268 source_pdu_emit_test_fake.arg1_##_typ)
269
270 #define ZASSERT_PDU_EMIT_TEST_CALL_COUNT(_expected) \
271 zassert_equal(_expected, \
272 source_pdu_emit_test_fake.call_count, \
273 "Expected %u, got %u", \
274 _expected, \
275 source_pdu_emit_test_fake.call_count)
276
277 /*------------------ PDU Release Callback --------------------------------------*/
278 /**
279 * Test releasing the given payload back to the memory pool.
280 * @param node_tx TX node to release or forward
281 * @param handle CIS/BIS handle
282 * @param status Reason for release
283 * @return Error status of release operation
284 */
285
286 /* Fake function */
287 FAKE_VALUE_FUNC(isoal_status_t,
288 source_pdu_release_test,
289 struct node_tx_iso *,
290 const uint16_t,
291 const isoal_status_t);
292
293 /* Customized routine for fake function */
custom_source_pdu_release_test(struct node_tx_iso * node_tx,const uint16_t handle,const isoal_status_t status)294 static isoal_status_t custom_source_pdu_release_test(struct node_tx_iso *node_tx,
295 const uint16_t handle,
296 const isoal_status_t status)
297 {
298 isoal_test_debug_trace_func_call(__func__, "IN");
299
300 return source_pdu_release_test_fake.return_val;
301 }
302
303 #define PDU_RELEASE_TEST_RETURNS(_status) source_pdu_release_test_fake.return_val = _status
304
305 #define ZASSERT_PDU_RELEASE_TEST(_typ, _node_tx, _handle, _status) \
306 zassert_equal_ptr(_node_tx, \
307 source_pdu_release_test_fake.arg0_##_typ, \
308 "\t\t%p != %p", \
309 _node_tx, \
310 source_pdu_release_test_fake.arg0_##_typ); \
311 zassert_equal(_handle, \
312 source_pdu_release_test_fake.arg1_##_typ, \
313 "\t\t%u != %u", \
314 _handle, \
315 source_pdu_release_test_fake.arg1_##_typ); \
316 zassert_equal(_status, \
317 source_pdu_release_test_fake.arg2_##_typ, \
318 "\t\t%u != %u", \
319 _status, \
320 source_pdu_release_test_fake.arg2_##_typ)
321
322 #define ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(_expected) \
323 zassert_equal(_expected, \
324 source_pdu_release_test_fake.call_count, \
325 "Expected %u, got %u", \
326 _expected, \
327 source_pdu_release_test_fake.call_count)
328
329 /**
330 * TX common setup before running tests
331 * @param f Input configuration parameters
332 */
isoal_test_tx_common_before(void * f)333 static void isoal_test_tx_common_before(void *f)
334 {
335 ARG_UNUSED(f);
336
337 custom_source_pdu_alloc_test_pdu_buffers.buffer_size = 0;
338 custom_source_pdu_alloc_test_pdu_buffers.pos = 0;
339 custom_source_pdu_write_test_sdu_payloads.buffer_size = 0;
340 custom_source_pdu_write_test_sdu_payloads.pos = 0;
341 RESET_FAKE(source_pdu_alloc_test);
342 RESET_FAKE(source_pdu_write_test);
343 RESET_FAKE(source_pdu_write_test_handler);
344 RESET_FAKE(source_pdu_emit_test);
345 RESET_FAKE(source_pdu_emit_test_handler);
346 RESET_FAKE(source_pdu_release_test);
347
348 FFF_RESET_HISTORY();
349
350 source_pdu_alloc_test_fake.custom_fake = custom_source_pdu_alloc_test;
351 source_pdu_write_test_fake.custom_fake = custom_source_pdu_write_test;
352 source_pdu_emit_test_fake.custom_fake = custom_source_pdu_emit_test;
353 source_pdu_release_test_fake.custom_fake = custom_source_pdu_release_test;
354 }
355
356 /**
357 * Wrapper totest time difference
358 * @param time_before Subtrahend
359 * @param time_after Minuend
360 * @param result Difference if valid
361 * @return Validity
362 */
isoal_get_time_diff_test(uint32_t time_before,uint32_t time_after,uint32_t * result)363 static bool isoal_get_time_diff_test(uint32_t time_before, uint32_t time_after, uint32_t *result)
364 {
365 bool valid = isoal_get_time_diff(time_before, time_after, result);
366
367 #if defined(DEBUG_TEST)
368 if (valid) {
369 PRINT("[isoal_get_time_diff] time_before %12lu time_after %12lu result %lu\n",
370 time_before,
371 time_after,
372 *result);
373 } else {
374 PRINT("[isoal_get_time_diff] time_before %12lu time_after %12lu result INVALID\n",
375 time_before,
376 time_after);
377 }
378 #endif
379
380 return valid;
381 }
382
383 /**
384 * Basic setup of a single source for any TX test
385 * @param handle Stream handle
386 * @param role Peripheral / Central / Broadcast
387 * @param framed PDU framing
388 * @param burst_number BN
389 * @param flush_timeout FT
390 * @param max_octets Max PDU Size
391 * @param sdu_interval SDU Interval (us)
392 * @param iso_interval_int ISO Interval (integer multiple of 1250us)
393 * @param stream_sync_delay CIS / BIS sync delay
394 * @param group_sync_delay CIG / BIG sync delay
395 * @return Newly created source handle
396 */
basic_tx_test_setup(uint16_t handle,uint8_t role,uint8_t framed,uint8_t burst_number,uint8_t flush_timeout,uint8_t max_octets,uint32_t sdu_interval,uint16_t iso_interval_int,uint32_t stream_sync_delay,uint32_t group_sync_delay)397 static isoal_source_handle_t basic_tx_test_setup(uint16_t handle,
398 uint8_t role,
399 uint8_t framed,
400 uint8_t burst_number,
401 uint8_t flush_timeout,
402 uint8_t max_octets,
403 uint32_t sdu_interval,
404 uint16_t iso_interval_int,
405 uint32_t stream_sync_delay,
406 uint32_t group_sync_delay)
407 {
408 isoal_source_handle_t source_hdl;
409 isoal_status_t err;
410
411 #if defined(DEBUG_TEST)
412 PRINT("TX Test Setup:\n\tHandle 0x%04x\n\tRole %s\n\tFraming %s"
413 "\n\tBN %u\n\tFT %d\n\tMax PDU %u\n\tISO Interval %dus"
414 "\n\tSDU Interval %dus\n\tStream Sync Delay %dus"
415 "\n\tGroup Sync Delay %dus\n\n",
416 handle,
417 ROLE_TO_STR(role),
418 framed ? "Framed" : "Unframed",
419 burst_number,
420 flush_timeout,
421 max_octets,
422 (iso_interval_int * ISO_INT_UNIT_US),
423 sdu_interval,
424 stream_sync_delay,
425 group_sync_delay);
426 #endif
427
428 ztest_set_assert_valid(false);
429
430 err = isoal_init();
431 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
432
433 err = isoal_reset();
434 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
435
436 /* Create a source based on global parameters */
437 err = isoal_source_create(handle,
438 role,
439 framed,
440 burst_number,
441 flush_timeout,
442 max_octets,
443 sdu_interval,
444 iso_interval_int,
445 stream_sync_delay,
446 group_sync_delay,
447 source_pdu_alloc_test,
448 source_pdu_write_test,
449 source_pdu_emit_test,
450 source_pdu_release_test,
451 &source_hdl);
452 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
453
454 /* Enable newly created source */
455 isoal_source_enable(source_hdl);
456
457 return source_hdl;
458 }
459
460 /**
461 * Creates a SDU fragment according to the provided configuration.
462 * @param[In] sdu_state Fragment type (Single / Start / Cont. / End)
463 * @param[In] dataptr Test data to fill SDU payload
464 * @param[In] length Length of SDU fragment
465 * @param[In] sdu_total_length Total size of the SDU
466 * @param[In] packet_number SDU packet sequence number
467 * @param[In] timestamp SDU timestamp at source
468 * @param[In] ref_point CIG / BIG reference point
469 * @param[In] target_event Event number requested
470 * @param[Out] sdu_tx SDU buffer
471 */
isoal_test_create_sdu_fagment(uint8_t sdu_state,uint8_t * dataptr,uint16_t length,uint16_t sdu_total_length,uint16_t packet_number,uint32_t timestamp,uint32_t cntr_timestamp,uint32_t ref_point,uint64_t target_event,struct isoal_sdu_tx * sdu_tx)472 static void isoal_test_create_sdu_fagment(uint8_t sdu_state,
473 uint8_t *dataptr,
474 uint16_t length,
475 uint16_t sdu_total_length,
476 uint16_t packet_number,
477 uint32_t timestamp,
478 uint32_t cntr_timestamp,
479 uint32_t ref_point,
480 uint64_t target_event,
481 struct isoal_sdu_tx *sdu_tx)
482 {
483 sdu_tx->sdu_state = sdu_state;
484 sdu_tx->packet_sn = packet_number;
485 sdu_tx->iso_sdu_length = sdu_total_length;
486 sdu_tx->time_stamp = timestamp;
487 sdu_tx->cntr_time_stamp = cntr_timestamp;
488 sdu_tx->grp_ref_point = ref_point;
489 sdu_tx->target_event = target_event;
490 memcpy(sdu_tx->dbuf, dataptr, length);
491 sdu_tx->size = length;
492
493 isoal_test_debug_print_tx_sdu(sdu_tx);
494 }
495
496 /**
497 * Test Suite : TX basic test
498 *
499 * Test creating and destroying sources upto the maximum, with randomized
500 * configuration parameters.
501 */
ZTEST(test_tx_basics,test_source_isoal_test_create_destroy)502 ZTEST(test_tx_basics, test_source_isoal_test_create_destroy)
503 {
504 isoal_sink_handle_t source_hdl[CONFIG_BT_CTLR_ISOAL_SOURCES];
505 uint32_t stream_sync_delay;
506 uint32_t group_sync_delay;
507 uint8_t sdu_interval_int;
508 uint8_t iso_interval_int;
509 uint8_t flush_timeout;
510 uint32_t iso_interval;
511 uint32_t sdu_interval;
512 uint8_t burst_number;
513 uint8_t pdus_per_sdu;
514 uint8_t max_octets;
515 isoal_status_t res;
516 uint16_t handle;
517 bool framed;
518
519 res = isoal_init();
520 zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res);
521
522 res = isoal_reset();
523 zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res);
524
525 for (int role = 0; role <= 3; role++) {
526 /* 0 Central
527 * 1 Peripheral
528 * 2 Broadcast
529 * 3 Undefined
530 */
531 handle = 0x8000;
532 burst_number = 0;
533 flush_timeout = 1;
534 framed = false;
535 max_octets = 40;
536 sdu_interval_int = 1;
537 iso_interval_int = 1;
538 iso_interval = iso_interval_int * ISO_INT_UNIT_US;
539 sdu_interval = sdu_interval_int * ISO_INT_UNIT_US;
540 stream_sync_delay = iso_interval - 200;
541 group_sync_delay = iso_interval - 50;
542
543 ztest_set_assert_valid(false);
544
545 for (int i = 0; i < CONFIG_BT_CTLR_ISOAL_SOURCES; i++) {
546 res = ISOAL_STATUS_ERR_UNSPECIFIED;
547 source_hdl[i] = 0xFF;
548
549 pdus_per_sdu = (burst_number * sdu_interval) / iso_interval;
550
551 res = isoal_source_create(handle,
552 role,
553 framed,
554 burst_number,
555 flush_timeout,
556 max_octets,
557 sdu_interval,
558 iso_interval_int,
559 stream_sync_delay,
560 group_sync_delay,
561 source_pdu_alloc_test,
562 source_pdu_write_test,
563 source_pdu_emit_test,
564 source_pdu_release_test,
565 &source_hdl[i]);
566
567 zassert_equal(isoal_global.source_allocated[source_hdl[i]],
568 ISOAL_ALLOC_STATE_TAKEN,
569 "");
570
571 zassert_equal(isoal_global.source_state[source_hdl[i]].session.pdus_per_sdu,
572 pdus_per_sdu,
573 "%s pdus_per_sdu %d should be %d for:\n\tBN %d"
574 "\n\tFT %d\n\tISO Interval %dus"
575 "\n\tSDU Interval %dus"
576 "\n\tStream Sync Delay %dus"
577 "\n\tGroup Sync Delay %dus",
578 (framed ? "Framed" : "Unframed"),
579 isoal_global.source_state[source_hdl[i]].session.pdus_per_sdu,
580 pdus_per_sdu,
581 burst_number,
582 flush_timeout,
583 iso_interval,
584 sdu_interval,
585 stream_sync_delay,
586 group_sync_delay);
587
588 zassert_equal(res,
589 ISOAL_STATUS_OK,
590 "Source %d in role %s creation failed!",
591 i,
592 ROLE_TO_STR(role));
593
594 isoal_source_enable(source_hdl[i]);
595
596 zassert_equal(isoal_global.source_state[source_hdl[i]].pdu_production.mode,
597 ISOAL_PRODUCTION_MODE_ENABLED,
598 "Source %d in role %s enable failed!",
599 i,
600 ROLE_TO_STR(role));
601
602 framed = !framed;
603 burst_number++;
604 flush_timeout = (flush_timeout % 3) + 1;
605 max_octets += max_octets / 2;
606 sdu_interval_int++;
607 iso_interval_int = iso_interval_int * sdu_interval_int;
608 sdu_interval = (sdu_interval_int * ISO_INT_UNIT_US) - (framed ? 100 : 0);
609 iso_interval = iso_interval_int * ISO_INT_UNIT_US;
610 stream_sync_delay = iso_interval - (200 * i);
611 group_sync_delay = iso_interval - 50;
612 }
613
614 /* Destroy in order */
615 for (int i = 0; i < CONFIG_BT_CTLR_ISOAL_SOURCES; i++) {
616 isoal_source_destroy(source_hdl[i]);
617
618 zassert_equal(isoal_global.source_allocated[source_hdl[i]],
619 ISOAL_ALLOC_STATE_FREE,
620 "Source destruction failed!");
621
622 zassert_equal(isoal_global.source_state[source_hdl[i]].pdu_production.mode,
623 ISOAL_PRODUCTION_MODE_DISABLED,
624 "Source disable failed!");
625 }
626 }
627 }
628
629 /**
630 * Test Suite : TX basic test
631 *
632 * Test error return on exceeding the maximum number of sources available.
633 */
ZTEST(test_tx_basics,test_source_isoal_test_create_err)634 ZTEST(test_tx_basics, test_source_isoal_test_create_err)
635 {
636 isoal_source_handle_t source_hdl[CONFIG_BT_CTLR_ISOAL_SOURCES + 1];
637 uint32_t stream_sync_delay;
638 uint32_t group_sync_delay;
639 uint8_t iso_interval_int;
640 uint8_t flush_timeout;
641 uint32_t sdu_interval;
642 uint8_t burst_number;
643 uint8_t max_octets;
644 isoal_status_t res;
645 uint16_t handle;
646 uint8_t role;
647 bool framed;
648
649 handle = 0x8000;
650 role = ISOAL_ROLE_PERIPHERAL;
651 burst_number = 1;
652 max_octets = 40;
653 flush_timeout = 1;
654 framed = false;
655 iso_interval_int = 1;
656 sdu_interval = ISO_INT_UNIT_US;
657 stream_sync_delay = ISO_INT_UNIT_US - 200;
658 group_sync_delay = ISO_INT_UNIT_US - 50;
659
660 res = isoal_init();
661 zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res);
662
663 res = isoal_reset();
664 zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res);
665
666 for (int i = 0; i < CONFIG_BT_CTLR_ISOAL_SOURCES; i++) {
667 res = isoal_source_create(handle,
668 role,
669 framed,
670 burst_number,
671 flush_timeout,
672 max_octets,
673 sdu_interval,
674 iso_interval_int,
675 stream_sync_delay,
676 group_sync_delay,
677 source_pdu_alloc_test,
678 source_pdu_write_test,
679 source_pdu_emit_test,
680 source_pdu_release_test,
681 &source_hdl[i]);
682
683 zassert_equal(res,
684 ISOAL_STATUS_OK,
685 "Source %d in role %s creation failed!",
686 i,
687 ROLE_TO_STR(role));
688 }
689
690 res = isoal_source_create(handle,
691 role,
692 framed,
693 burst_number,
694 flush_timeout,
695 max_octets,
696 sdu_interval,
697 iso_interval_int,
698 stream_sync_delay,
699 group_sync_delay,
700 source_pdu_alloc_test,
701 source_pdu_write_test,
702 source_pdu_emit_test,
703 source_pdu_release_test,
704 &source_hdl[CONFIG_BT_CTLR_ISOAL_SOURCES]);
705
706 zassert_equal(res,
707 ISOAL_STATUS_ERR_SOURCE_ALLOC,
708 "Source creation did not return error as expected!");
709 }
710
711 /**
712 * Test Suite : TX unframed SDU fragmentation
713 *
714 * Tests fragmentation of a single SDU contained in a single fragment
715 * into a single PDU where Max PDU is less than the PDU buffer size
716 */
ZTEST(test_tx_unframed,test_tx_unframed_1_sdu_1_frag_1_pdu_maxPDU)717 ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_maxPDU)
718 {
719 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX - 5];
720 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
721 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
722 struct isoal_pdu_buffer pdu_buffer;
723 isoal_source_handle_t source_hdl;
724 isoal_sdu_len_t sdu_total_size;
725 isoal_pdu_len_t pdu_write_size;
726 uint32_t stream_sync_delay;
727 uint64_t sdu_packet_number;
728 uint32_t group_sync_delay;
729 uint8_t iso_interval_int;
730 uint64_t payload_number;
731 uint32_t sdu_timestamp;
732 uint16_t testdata_indx;
733 uint16_t testdata_size;
734 uint16_t pdu_write_loc;
735 uint16_t sdu_read_loc;
736 uint64_t event_number;
737 uint32_t sdu_interval;
738 uint8_t sdu_fragments;
739 uint32_t ref_point;
740 isoal_status_t err;
741 uint8_t max_octets;
742 uint8_t role;
743 uint8_t BN;
744 uint8_t FT;
745
746 /* Settings */
747 role = ISOAL_ROLE_PERIPHERAL;
748 iso_interval_int = 1;
749 sdu_interval = ISO_INT_UNIT_US;
750 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
751 BN = 1;
752 FT = 1;
753 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
754 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
755
756 /* SDU Frag 1 --------------------------------------------------------*/
757 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
758 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
759 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX - 5);
760 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
761 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
762 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
763 sdu_packet_number = 2000;
764 event_number = 2000;
765 sdu_timestamp = 9249;
766 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
767 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
768 testdata_indx = 0;
769 testdata_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
770 payload_number = event_number * BN;
771 pdu_write_loc = 0;
772 sdu_read_loc = 0;
773 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
774
775 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
776 role, /* Role */
777 false, /* Framed */
778 BN, /* BN */
779 FT, /* FT */
780 max_octets, /* max_octets */
781 sdu_interval, /* SDU Interval */
782 iso_interval_int, /* ISO Interval */
783 stream_sync_delay, /* Stream Sync Delay */
784 group_sync_delay); /* Group Sync Delay */
785
786 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
787 &testdata[testdata_indx],
788 (testdata_size - testdata_indx),
789 sdu_total_size,
790 sdu_packet_number,
791 sdu_timestamp,
792 sdu_timestamp,
793 ref_point,
794 event_number,
795 &tx_sdu_frag_buf.sdu_tx);
796
797 /* Test fragmentation (Black Box) */
798 /* Valid PDUs */
799 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
800 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
801 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
802 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
803 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
804
805 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
806
807 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
808
809 /* PDU 1 */
810 sdu_fragments = 1;
811
812 ZASSERT_PDU_WRITE_TEST(val,
813 pdu_buffer,
814 pdu_write_loc,
815 &testdata[sdu_read_loc],
816 (pdu_write_size - pdu_write_loc));
817
818 ZASSERT_PDU_EMIT_TEST(val,
819 &tx_pdu_meta_buf.node_tx,
820 payload_number,
821 sdu_fragments,
822 PDU_BIS_LLID_COMPLETE_END,
823 pdu_write_size,
824 isoal_global.source_state[source_hdl].session.handle);
825
826 /* PDU release not expected (No Error) */
827 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
828
829 /* Test PDU release */
830 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
831
832 isoal_tx_pdu_release(source_hdl, &tx_pdu_meta_buf.node_tx);
833
834 ZASSERT_PDU_RELEASE_TEST(val,
835 &tx_pdu_meta_buf.node_tx,
836 isoal_global.source_state[source_hdl].session.handle,
837 ISOAL_STATUS_OK);
838 }
839
840 /**
841 * Test Suite : TX unframed SDU fragmentation
842 *
843 * Tests fragmentation of a single SDU contained in a single fragment
844 * into a single PDU where Max PDU is greater than the PDU buffer size
845 */
ZTEST(test_tx_unframed,test_tx_unframed_1_sdu_1_frag_1_pdu_bufSize)846 ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_bufSize)
847 {
848 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX];
849 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
850 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
851 struct isoal_pdu_buffer pdu_buffer;
852 isoal_source_handle_t source_hdl;
853 isoal_sdu_len_t sdu_total_size;
854 isoal_pdu_len_t pdu_write_size;
855 uint32_t stream_sync_delay;
856 uint64_t sdu_packet_number;
857 uint32_t group_sync_delay;
858 uint8_t iso_interval_int;
859 uint64_t payload_number;
860 uint32_t sdu_timestamp;
861 uint16_t testdata_indx;
862 uint16_t testdata_size;
863 uint16_t pdu_write_loc;
864 uint16_t sdu_read_loc;
865 uint64_t event_number;
866 uint32_t sdu_interval;
867 uint8_t sdu_fragments;
868 uint32_t ref_point;
869 isoal_status_t err;
870 uint8_t max_octets;
871 uint8_t role;
872 uint8_t BN;
873 uint8_t FT;
874
875 /* Settings */
876 role = ISOAL_ROLE_PERIPHERAL;
877 iso_interval_int = 1;
878 sdu_interval = ISO_INT_UNIT_US;
879 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
880 BN = 1;
881 FT = 1;
882 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
883 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
884
885 /* SDU Frag 1 --------------------------------------------------------*/
886 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
887 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
888 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX);
889 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
890 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
891 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
892 sdu_packet_number = 2000;
893 event_number = 2000;
894 sdu_timestamp = 9249;
895 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
896 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX;
897 testdata_indx = 0;
898 testdata_size = TEST_TX_PDU_PAYLOAD_MAX;
899 payload_number = event_number * BN;
900 pdu_write_loc = 0;
901 sdu_read_loc = 0;
902 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
903
904 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
905 role, /* Role */
906 false, /* Framed */
907 BN, /* BN */
908 FT, /* FT */
909 max_octets, /* max_octets */
910 sdu_interval, /* SDU Interval */
911 iso_interval_int, /* ISO Interval */
912 stream_sync_delay, /* Stream Sync Delay */
913 group_sync_delay); /* Group Sync Delay */
914
915 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
916 &testdata[testdata_indx],
917 (testdata_size - testdata_indx),
918 sdu_total_size,
919 sdu_packet_number,
920 sdu_timestamp,
921 sdu_timestamp,
922 ref_point,
923 event_number,
924 &tx_sdu_frag_buf.sdu_tx);
925
926 /* Test fragmentation (Black Box) */
927 /* Valid PDUs */
928 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
929 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
930 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
931 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
932 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
933
934 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
935
936 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
937
938 /* PDU 1 */
939 sdu_fragments = 1;
940
941 ZASSERT_PDU_WRITE_TEST(val,
942 pdu_buffer,
943 pdu_write_loc,
944 &testdata[sdu_read_loc],
945 (pdu_write_size - pdu_write_loc));
946
947 ZASSERT_PDU_EMIT_TEST(val,
948 &tx_pdu_meta_buf.node_tx,
949 payload_number,
950 sdu_fragments,
951 PDU_BIS_LLID_COMPLETE_END,
952 pdu_write_size,
953 isoal_global.source_state[source_hdl].session.handle);
954
955 /* PDU release not expected (No Error) */
956 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
957 }
958
959 /**
960 * Test Suite : TX unframed SDU fragmentation
961 *
962 * Tests fragmentation of a single SDU contained in a single fragment
963 * into three PDUs where Max PDU is less than the PDU buffer size
964 */
ZTEST(test_tx_unframed,test_tx_unframed_1_sdu_1_frag_3_pdu)965 ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_3_pdu)
966 {
967 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
968 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
969 struct isoal_pdu_buffer pdu_buffer;
970 isoal_source_handle_t source_hdl;
971 isoal_sdu_len_t sdu_total_size;
972 isoal_pdu_len_t pdu_write_size;
973 uint32_t stream_sync_delay;
974 uint64_t sdu_packet_number;
975 uint32_t group_sync_delay;
976 uint8_t iso_interval_int;
977 uint64_t payload_number;
978 uint32_t sdu_timestamp;
979 uint16_t testdata_indx;
980 uint16_t testdata_size;
981 uint16_t pdu_write_loc;
982 uint16_t sdu_read_loc;
983 uint64_t event_number;
984 uint32_t sdu_interval;
985 uint8_t sdu_fragments;
986 uint8_t testdata[100];
987 uint32_t ref_point;
988 isoal_status_t err;
989 uint8_t max_octets;
990 uint8_t role;
991 uint8_t BN;
992 uint8_t FT;
993
994 /* Settings */
995 role = ISOAL_ROLE_PERIPHERAL;
996 iso_interval_int = 1;
997 sdu_interval = ISO_INT_UNIT_US;
998 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
999 BN = 3;
1000 FT = 1;
1001 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
1002 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
1003
1004 /* SDU Frag 1 --------------------------------------------------------*/
1005 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
1006 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1007 init_test_data_buffer(testdata, 100);
1008 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
1009 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
1010 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
1011 sdu_packet_number = 2000;
1012 event_number = 2000;
1013 sdu_timestamp = 9249;
1014 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
1015 sdu_total_size = 100;
1016 testdata_indx = 0;
1017 testdata_size = 100;
1018 payload_number = event_number * BN;
1019
1020 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
1021 role, /* Role */
1022 false, /* Framed */
1023 BN, /* BN */
1024 FT, /* FT */
1025 max_octets, /* max_octets */
1026 sdu_interval, /* SDU Interval */
1027 iso_interval_int, /* ISO Interval */
1028 stream_sync_delay, /* Stream Sync Delay */
1029 group_sync_delay); /* Group Sync Delay */
1030
1031 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
1032 &testdata[testdata_indx],
1033 (testdata_size - testdata_indx),
1034 sdu_total_size,
1035 sdu_packet_number,
1036 sdu_timestamp,
1037 sdu_timestamp,
1038 ref_point,
1039 event_number,
1040 &tx_sdu_frag_buf.sdu_tx);
1041
1042 /* Test fragmentation (Black Box) */
1043 /* Valid PDUs */
1044 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
1045 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
1046 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
1047 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
1048 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
1049 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
1050 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
1051
1052 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1053
1054 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1055
1056 /* PDU 1 */
1057 pdu_write_loc = 0;
1058 sdu_read_loc = 0;
1059 pdu_write_size = max_octets;
1060 sdu_fragments = 0;
1061
1062 ZASSERT_PDU_WRITE_TEST(history[0],
1063 pdu_buffer,
1064 pdu_write_loc,
1065 &testdata[sdu_read_loc],
1066 (pdu_write_size - pdu_write_loc));
1067
1068 ZASSERT_PDU_EMIT_TEST(history[0],
1069 &tx_pdu_meta_buf.node_tx,
1070 payload_number,
1071 sdu_fragments,
1072 PDU_BIS_LLID_START_CONTINUE,
1073 pdu_write_size,
1074 isoal_global.source_state[source_hdl].session.handle);
1075
1076 /* PDU 2 */
1077 payload_number++;
1078 sdu_read_loc += pdu_write_size;
1079 sdu_fragments = 0;
1080
1081 ZASSERT_PDU_WRITE_TEST(history[1],
1082 pdu_buffer,
1083 pdu_write_loc,
1084 &testdata[sdu_read_loc],
1085 (pdu_write_size - pdu_write_loc));
1086
1087 ZASSERT_PDU_EMIT_TEST(history[1],
1088 &tx_pdu_meta_buf.node_tx,
1089 payload_number,
1090 sdu_fragments,
1091 PDU_BIS_LLID_START_CONTINUE,
1092 pdu_write_size,
1093 isoal_global.source_state[source_hdl].session.handle);
1094
1095 /* PDU 3 */
1096 payload_number++;
1097 sdu_read_loc += pdu_write_size;
1098 pdu_write_size = 30;
1099 sdu_fragments++;
1100
1101 ZASSERT_PDU_WRITE_TEST(history[2],
1102 pdu_buffer,
1103 pdu_write_loc,
1104 &testdata[sdu_read_loc],
1105 (pdu_write_size - pdu_write_loc));
1106
1107 ZASSERT_PDU_EMIT_TEST(history[2],
1108 &tx_pdu_meta_buf.node_tx,
1109 payload_number,
1110 sdu_fragments,
1111 PDU_BIS_LLID_COMPLETE_END,
1112 pdu_write_size,
1113 isoal_global.source_state[source_hdl].session.handle);
1114
1115 /* PDU release not expected (No Error) */
1116 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1117 }
1118
1119 /**
1120 * Test Suite : TX unframed SDU fragmentation
1121 *
1122 * Tests fragmentation of a single SDU contained in three fragments
1123 * into a single PDU where Max PDU is greater than the PDU buffer size
1124 */
ZTEST(test_tx_unframed,test_tx_unframed_1_sdu_3_frag_1_pdu)1125 ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu)
1126 {
1127 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
1128 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
1129 struct isoal_pdu_buffer pdu_buffer;
1130 isoal_source_handle_t source_hdl;
1131 isoal_sdu_len_t sdu_total_size;
1132 isoal_pdu_len_t pdu_write_size;
1133 uint32_t stream_sync_delay;
1134 uint64_t sdu_packet_number;
1135 uint32_t group_sync_delay;
1136 uint8_t iso_interval_int;
1137 uint64_t payload_number;
1138 uint32_t sdu_timestamp;
1139 uint16_t testdata_indx;
1140 uint16_t testdata_size;
1141 uint16_t pdu_write_loc;
1142 uint16_t sdu_read_loc;
1143 uint64_t event_number;
1144 uint32_t sdu_interval;
1145 uint8_t sdu_fragments;
1146 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX];
1147 uint32_t ref_point;
1148 isoal_status_t err;
1149 uint8_t max_octets;
1150 uint8_t role;
1151 uint8_t BN;
1152 uint8_t FT;
1153
1154 /* Settings */
1155 role = ISOAL_ROLE_PERIPHERAL;
1156 iso_interval_int = 1;
1157 sdu_interval = ISO_INT_UNIT_US;
1158 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
1159 BN = 1;
1160 FT = 1;
1161 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
1162 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
1163
1164 /* SDU Frag 1 --------------------------------------------------------*/
1165 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
1166 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1167 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX);
1168 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
1169 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
1170 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
1171 sdu_packet_number = 2000;
1172 event_number = 2000;
1173 sdu_timestamp = 9249;
1174 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
1175 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX;
1176 testdata_indx = 0;
1177 testdata_size = TEST_TX_PDU_PAYLOAD_MAX / 3;
1178 payload_number = event_number * BN;
1179 sdu_fragments = 0;
1180
1181 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
1182 role, /* Role */
1183 false, /* Framed */
1184 BN, /* BN */
1185 FT, /* FT */
1186 max_octets, /* max_octets */
1187 sdu_interval, /* SDU Interval */
1188 iso_interval_int, /* ISO Interval */
1189 stream_sync_delay, /* Stream Sync Delay */
1190 group_sync_delay); /* Group Sync Delay */
1191
1192 isoal_test_create_sdu_fagment(BT_ISO_START,
1193 &testdata[testdata_indx],
1194 (testdata_size - testdata_indx),
1195 sdu_total_size,
1196 sdu_packet_number,
1197 sdu_timestamp,
1198 sdu_timestamp,
1199 ref_point,
1200 event_number,
1201 &tx_sdu_frag_buf.sdu_tx);
1202
1203 /* Test fragmentation (Black Box) */
1204 /* Valid PDUs */
1205 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
1206 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
1207 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
1208 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
1209 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
1210
1211 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1212
1213 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1214
1215 /* PDU 1 */
1216 pdu_write_loc = 0;
1217 sdu_read_loc = 0;
1218 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX / 3;
1219 sdu_fragments++;
1220
1221 ZASSERT_PDU_WRITE_TEST(history[0],
1222 pdu_buffer,
1223 pdu_write_loc,
1224 &testdata[sdu_read_loc],
1225 (pdu_write_size - pdu_write_loc));
1226
1227 /* PDU should not be emitted */
1228 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
1229
1230 /* PDU release not expected (No Error) */
1231 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1232
1233 /* SDU Frag 2 --------------------------------------------------------*/
1234 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1235 sdu_timestamp += 10;
1236 testdata_indx += testdata_size;
1237 testdata_size += TEST_TX_PDU_PAYLOAD_MAX / 3;
1238
1239 isoal_test_create_sdu_fagment(BT_ISO_CONT,
1240 &testdata[testdata_indx],
1241 (testdata_size - testdata_indx),
1242 sdu_total_size,
1243 sdu_packet_number,
1244 sdu_timestamp,
1245 sdu_timestamp,
1246 ref_point,
1247 event_number,
1248 &tx_sdu_frag_buf.sdu_tx);
1249
1250 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1251
1252 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1253
1254 /* Test fragmentation (Black Box) */
1255 /* Valid PDUs */
1256 /* PDU 1 */
1257 pdu_write_loc = pdu_write_size;
1258 pdu_write_size += TEST_TX_PDU_PAYLOAD_MAX / 3;
1259 sdu_read_loc = testdata_indx;
1260 sdu_fragments++;
1261
1262 /* PDU should not be allocated */
1263 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(1);
1264
1265 ZASSERT_PDU_WRITE_TEST(history[1],
1266 pdu_buffer,
1267 pdu_write_loc,
1268 &testdata[sdu_read_loc],
1269 (pdu_write_size - pdu_write_loc));
1270
1271 /* PDU should not be emitted */
1272 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
1273
1274 /* PDU release not expected (No Error) */
1275 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1276
1277 /* SDU Frag 3 --------------------------------------------------------*/
1278 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1279 sdu_timestamp += 10;
1280 testdata_indx = testdata_size;
1281 testdata_size = TEST_TX_PDU_PAYLOAD_MAX;
1282
1283 isoal_test_create_sdu_fagment(BT_ISO_END,
1284 &testdata[testdata_indx],
1285 (testdata_size - testdata_indx),
1286 sdu_total_size,
1287 sdu_packet_number,
1288 sdu_timestamp,
1289 sdu_timestamp,
1290 ref_point,
1291 event_number,
1292 &tx_sdu_frag_buf.sdu_tx);
1293
1294 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1295
1296 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1297
1298 /* Test fragmentation (Black Box) */
1299 /* Valid PDUs */
1300 /* PDU 1 */
1301 pdu_write_loc = pdu_write_size;
1302 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
1303 sdu_read_loc = testdata_indx;
1304 sdu_fragments++;
1305
1306 /* PDU should not be allocated */
1307 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(1);
1308
1309 ZASSERT_PDU_WRITE_TEST(history[2],
1310 pdu_buffer,
1311 pdu_write_loc,
1312 &testdata[sdu_read_loc],
1313 (pdu_write_size - pdu_write_loc));
1314
1315 ZASSERT_PDU_EMIT_TEST(history[0],
1316 &tx_pdu_meta_buf.node_tx,
1317 payload_number,
1318 sdu_fragments,
1319 PDU_BIS_LLID_COMPLETE_END,
1320 pdu_write_size,
1321 isoal_global.source_state[source_hdl].session.handle);
1322
1323 /* PDU release not expected (No Error) */
1324 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1325 }
1326
1327 /**
1328 * Test Suite : TX unframed SDU fragmentation
1329 *
1330 * Tests fragmentation of a single SDU contained in three fragments
1331 * into two PDUs where Max PDU is greater than the PDU buffer size
1332 */
ZTEST(test_tx_unframed,test_tx_unframed_1_sdu_3_frag_2_pdu)1333 ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu)
1334 {
1335 struct tx_pdu_meta_buffer tx_pdu_meta_buf[2];
1336 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
1337 struct isoal_pdu_buffer pdu_buffer[2];
1338 isoal_source_handle_t source_hdl;
1339 isoal_sdu_len_t sdu_total_size;
1340 isoal_pdu_len_t pdu_write_size;
1341 uint32_t stream_sync_delay;
1342 uint64_t sdu_packet_number;
1343 uint32_t group_sync_delay;
1344 uint8_t iso_interval_int;
1345 uint64_t payload_number;
1346 uint32_t sdu_timestamp;
1347 uint16_t testdata_indx;
1348 uint16_t testdata_size;
1349 uint16_t pdu_write_loc;
1350 uint16_t sdu_read_loc;
1351 uint64_t event_number;
1352 uint32_t sdu_interval;
1353 uint8_t sdu_fragments;
1354 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX * 2];
1355 uint32_t ref_point;
1356 isoal_status_t err;
1357 uint8_t max_octets;
1358 uint8_t role;
1359 uint8_t BN;
1360 uint8_t FT;
1361
1362 /* Settings */
1363 role = ISOAL_ROLE_PERIPHERAL;
1364 iso_interval_int = 1;
1365 sdu_interval = ISO_INT_UNIT_US;
1366 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
1367 BN = 2;
1368 FT = 1;
1369 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
1370 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
1371
1372 /* SDU Frag 1 --------------------------------------------------------*/
1373 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
1374 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
1375 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1376 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX * 2);
1377 pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx;
1378 pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu;
1379 pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX;
1380 pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx;
1381 pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu;
1382 pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX;
1383 sdu_packet_number = 2000;
1384 event_number = 2000;
1385 sdu_timestamp = 9249;
1386 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
1387 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
1388 testdata_indx = 0;
1389 testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
1390 sdu_fragments = 0;
1391
1392 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
1393 role, /* Role */
1394 false, /* Framed */
1395 BN, /* BN */
1396 FT, /* FT */
1397 max_octets, /* max_octets */
1398 sdu_interval, /* SDU Interval */
1399 iso_interval_int, /* ISO Interval */
1400 stream_sync_delay, /* Stream Sync Delay */
1401 group_sync_delay); /* Group Sync Delay */
1402
1403 isoal_test_create_sdu_fagment(BT_ISO_START,
1404 &testdata[testdata_indx],
1405 (testdata_size - testdata_indx),
1406 sdu_total_size,
1407 sdu_packet_number,
1408 sdu_timestamp,
1409 sdu_timestamp,
1410 ref_point,
1411 event_number,
1412 &tx_sdu_frag_buf.sdu_tx);
1413
1414 /* Test fragmentation (Black Box) */
1415 /* Valid PDUs */
1416 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
1417 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
1418 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
1419 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
1420 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
1421 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
1422
1423 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1424
1425 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1426
1427 /* PDU 1 */
1428 payload_number = event_number * BN;
1429 pdu_write_loc = 0;
1430 sdu_read_loc = 0;
1431 pdu_write_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
1432 sdu_fragments++;
1433
1434 ZASSERT_PDU_WRITE_TEST(history[0],
1435 pdu_buffer[0],
1436 pdu_write_loc,
1437 &testdata[sdu_read_loc],
1438 (pdu_write_size - pdu_write_loc));
1439
1440 /* PDU should not be emitted */
1441 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
1442
1443 /* PDU release not expected (No Error) */
1444 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1445
1446 /* SDU Frag 2 --------------------------------------------------------*/
1447 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1448 sdu_timestamp += 10;
1449 testdata_indx += testdata_size;
1450 testdata_size += (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
1451
1452 isoal_test_create_sdu_fagment(BT_ISO_CONT,
1453 &testdata[testdata_indx],
1454 (testdata_size - testdata_indx),
1455 sdu_total_size,
1456 sdu_packet_number,
1457 sdu_timestamp,
1458 sdu_timestamp,
1459 ref_point,
1460 event_number,
1461 &tx_sdu_frag_buf.sdu_tx);
1462
1463 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1464
1465 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1466
1467 /* Test fragmentation (Black Box) */
1468 /* Valid PDUs */
1469 /* PDU 1 */
1470 pdu_write_loc = pdu_write_size;
1471 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
1472 sdu_read_loc = testdata_indx;
1473
1474 /* PDU should not be allocated (Allocated for PDU 2) */
1475 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(2);
1476
1477 ZASSERT_PDU_WRITE_TEST(history[1],
1478 pdu_buffer[0],
1479 pdu_write_loc,
1480 &testdata[sdu_read_loc],
1481 (pdu_write_size - pdu_write_loc));
1482
1483 ZASSERT_PDU_EMIT_TEST(history[0],
1484 &tx_pdu_meta_buf[0].node_tx,
1485 payload_number,
1486 sdu_fragments,
1487 PDU_BIS_LLID_START_CONTINUE,
1488 pdu_write_size,
1489 isoal_global.source_state[source_hdl].session.handle);
1490
1491 /* PDU release not expected (No Error) */
1492 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1493
1494 /* PDU 2 */
1495 payload_number++;
1496 sdu_read_loc = pdu_write_size;
1497 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc);
1498 pdu_write_loc = 0;
1499 sdu_fragments = 1;
1500
1501 ZASSERT_PDU_WRITE_TEST(history[2],
1502 pdu_buffer[1],
1503 pdu_write_loc,
1504 &testdata[sdu_read_loc],
1505 (pdu_write_size - pdu_write_loc));
1506
1507 /* PDU should not be emitted */
1508 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1);
1509
1510 /* PDU release not expected (No Error) */
1511 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1512
1513 /* SDU Frag 3 --------------------------------------------------------*/
1514 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1515 sdu_timestamp += 10;
1516 testdata_indx = testdata_size;
1517 testdata_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
1518
1519 isoal_test_create_sdu_fagment(BT_ISO_END,
1520 &testdata[testdata_indx],
1521 (testdata_size - testdata_indx),
1522 sdu_total_size,
1523 sdu_packet_number,
1524 sdu_timestamp,
1525 sdu_timestamp,
1526 ref_point,
1527 event_number,
1528 &tx_sdu_frag_buf.sdu_tx);
1529
1530 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1531
1532 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1533
1534 /* Test fragmentation (Black Box) */
1535 /* Valid PDUs */
1536 /* PDU 2 */
1537 pdu_write_loc = pdu_write_size;
1538 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
1539 sdu_read_loc = testdata_indx;
1540 sdu_fragments++;
1541
1542 /* PDU should not be allocated */
1543 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(2);
1544
1545 ZASSERT_PDU_WRITE_TEST(history[3],
1546 pdu_buffer[1],
1547 pdu_write_loc,
1548 &testdata[sdu_read_loc],
1549 (pdu_write_size - pdu_write_loc));
1550
1551 ZASSERT_PDU_EMIT_TEST(history[1],
1552 &tx_pdu_meta_buf[1].node_tx,
1553 payload_number,
1554 sdu_fragments,
1555 PDU_BIS_LLID_COMPLETE_END,
1556 pdu_write_size,
1557 isoal_global.source_state[source_hdl].session.handle);
1558
1559 /* PDU release not expected (No Error) */
1560 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1561 }
1562
1563 /**
1564 * Test Suite : TX unframed SDU fragmentation
1565 *
1566 * Tests boundary conditions for the time difference function
1567 */
ZTEST(test_tx_unframed,test_tx_time_diff)1568 ZTEST(test_tx_unframed, test_tx_time_diff)
1569 {
1570 uint32_t time_before;
1571 uint32_t time_after;
1572 uint32_t result;
1573 bool valid;
1574
1575 result = 0;
1576
1577 /* Check that the difference from maximum to 0 is 1 */
1578 time_before = ISOAL_TIME_WRAPPING_POINT_US;
1579 time_after = 0;
1580 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1581 zassert_true(valid, NULL);
1582 zassert_equal(result, 1, "%lu != %lu", result, 1);
1583
1584 /* Check that if time_before is ahead of time_after the result is
1585 * invalid
1586 */
1587 time_before = 0;
1588 time_after = ISOAL_TIME_WRAPPING_POINT_US;
1589 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1590 zassert_false(valid, NULL);
1591
1592 time_before = ISOAL_TIME_WRAPPING_POINT_US;
1593 time_after = ISOAL_TIME_WRAPPING_POINT_US - 1;
1594 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1595 zassert_false(valid, NULL);
1596
1597 time_before = 1;
1598 time_after = 0;
1599 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1600 zassert_false(valid, NULL);
1601
1602 time_before = ISOAL_TIME_MID_POINT_US;
1603 time_after = ISOAL_TIME_MID_POINT_US - 1;
1604 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1605 zassert_false(valid, NULL);
1606
1607 time_before = ISOAL_TIME_MID_POINT_US + 1;
1608 time_after = ISOAL_TIME_MID_POINT_US;
1609 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1610 zassert_false(valid, NULL);
1611
1612 time_before = ISOAL_TIME_MID_POINT_US + 1;
1613 time_after = ISOAL_TIME_MID_POINT_US - 1;
1614 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1615 zassert_false(valid, NULL);
1616
1617 /* Check valid results that are 0 */
1618 time_before = 0;
1619 time_after = 0;
1620 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1621 zassert_true(valid, NULL);
1622 zassert_equal(result, 0, "%lu != %lu", result, 0);
1623
1624 time_before = ISOAL_TIME_WRAPPING_POINT_US;
1625 time_after = ISOAL_TIME_WRAPPING_POINT_US;
1626 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1627 zassert_true(valid, NULL);
1628 zassert_equal(result, 0, "%lu != %lu", result, 0);
1629
1630 time_before = ISOAL_TIME_MID_POINT_US;
1631 time_after = ISOAL_TIME_MID_POINT_US;
1632 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1633 zassert_true(valid, NULL);
1634 zassert_equal(result, 0, "%lu != %lu", result, 0);
1635
1636 /* Check valid results across the mid-point */
1637 time_before = ISOAL_TIME_MID_POINT_US;
1638 time_after = ISOAL_TIME_MID_POINT_US + 1;
1639 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1640 zassert_true(valid, NULL);
1641 zassert_equal(result, 1, "%lu != %lu", result, 1);
1642
1643 time_before = ISOAL_TIME_MID_POINT_US - 1;
1644 time_after = ISOAL_TIME_MID_POINT_US;
1645 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1646 zassert_true(valid, NULL);
1647 zassert_equal(result, 1, "%lu != %lu", result, 1);
1648
1649 time_before = ISOAL_TIME_MID_POINT_US - 1;
1650 time_after = ISOAL_TIME_MID_POINT_US + 1;
1651 valid = isoal_get_time_diff_test(time_before, time_after, &result);
1652 zassert_true(valid, NULL);
1653 zassert_equal(result, 2, "%lu != %lu", result, 2);
1654 }
1655
1656 /**
1657 * Test Suite : TX unframed SDU fragmentation
1658 *
1659 * Tests fragmentation of a single SDU contained in a single fragment
1660 * into a single PDU where Max PDU is less than the PDU buffer size
1661 */
ZTEST(test_tx_unframed,test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1)1662 ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1)
1663 {
1664 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
1665 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
1666 uint32_t tx_sync_timestamp_expected;
1667 struct isoal_pdu_buffer pdu_buffer;
1668 isoal_source_handle_t source_hdl;
1669 uint32_t tx_sync_offset_expected;
1670 isoal_sdu_len_t sdu_total_size;
1671 isoal_pdu_len_t pdu_write_size;
1672 uint16_t tx_sync_seq_expected;
1673 uint32_t stream_sync_delay;
1674 uint64_t sdu_packet_number;
1675 uint32_t tx_sync_timestamp;
1676 uint32_t group_sync_delay;
1677 uint8_t iso_interval_int;
1678 uint64_t payload_number;
1679 uint32_t tx_sync_offset;
1680 uint32_t sdu_timestamp;
1681 uint16_t testdata_indx;
1682 uint16_t testdata_size;
1683 uint16_t pdu_write_loc;
1684 uint16_t sdu_read_loc;
1685 uint64_t event_number;
1686 uint32_t sdu_interval;
1687 uint8_t sdu_fragments;
1688 uint8_t testdata[33];
1689 uint16_t tx_sync_seq;
1690 uint32_t ref_point;
1691 isoal_status_t err;
1692 uint8_t max_octets;
1693 uint8_t role;
1694 uint8_t BN;
1695 uint8_t FT;
1696
1697 /* Settings */
1698 role = ISOAL_ROLE_PERIPHERAL;
1699 iso_interval_int = 1;
1700 sdu_interval = ISO_INT_UNIT_US;
1701 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
1702 BN = 1;
1703 FT = 1;
1704 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
1705 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
1706
1707 /* SDU Frag 1 --------------------------------------------------------*/
1708 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
1709 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1710 init_test_data_buffer(testdata, 33);
1711 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
1712 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
1713 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
1714 sdu_packet_number = 2000;
1715 event_number = 2000;
1716 sdu_timestamp = ISOAL_TIME_WRAPPING_POINT_US;
1717 ref_point = ISOAL_TIME_WRAPPING_POINT_US;
1718 sdu_total_size = 23;
1719 testdata_indx = 0;
1720 testdata_size = 23;
1721 payload_number = event_number * BN;
1722 pdu_write_loc = 0;
1723 sdu_read_loc = 0;
1724 pdu_write_size = 23;
1725
1726 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
1727 role, /* Role */
1728 false, /* Framed */
1729 BN, /* BN */
1730 FT, /* FT */
1731 max_octets, /* max_octets */
1732 sdu_interval, /* SDU Interval */
1733 iso_interval_int, /* ISO Interval */
1734 stream_sync_delay, /* Stream Sync Delay */
1735 group_sync_delay); /* Group Sync Delay */
1736
1737 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
1738 &testdata[testdata_indx],
1739 (testdata_size - testdata_indx),
1740 sdu_total_size,
1741 sdu_packet_number,
1742 sdu_timestamp,
1743 sdu_timestamp,
1744 ref_point,
1745 event_number,
1746 &tx_sdu_frag_buf.sdu_tx);
1747
1748 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
1749 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
1750 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
1751 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
1752 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
1753 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
1754
1755 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1756
1757 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1758
1759 /* Test fragmentation (Black Box) */
1760 /* Valid PDUs */
1761 /* PDU 1 */
1762 sdu_fragments = 1;
1763
1764 ZASSERT_PDU_WRITE_TEST(history[0],
1765 pdu_buffer,
1766 pdu_write_loc,
1767 &testdata[sdu_read_loc],
1768 (pdu_write_size - pdu_write_loc));
1769
1770 ZASSERT_PDU_EMIT_TEST(history[0],
1771 &tx_pdu_meta_buf.node_tx,
1772 payload_number,
1773 sdu_fragments,
1774 PDU_BIS_LLID_COMPLETE_END,
1775 pdu_write_size,
1776 isoal_global.source_state[source_hdl].session.handle);
1777
1778 /* PDU release not expected (No Error) */
1779 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1780
1781 /* SDU 2 Frag 1 ------------------------------------------------------*/
1782 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
1783 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1784 sdu_packet_number++;
1785 sdu_timestamp = sdu_interval - 1;
1786 sdu_total_size = 10;
1787 testdata_indx = 0;
1788 testdata_size = 10;
1789 sdu_fragments = 0;
1790
1791 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
1792 &testdata[testdata_indx],
1793 (testdata_size - testdata_indx),
1794 sdu_total_size,
1795 sdu_packet_number,
1796 sdu_timestamp,
1797 sdu_timestamp,
1798 ref_point,
1799 event_number,
1800 &tx_sdu_frag_buf.sdu_tx);
1801
1802 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1803
1804 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1805
1806 /* Test fragmentation (Black Box) */
1807 /* Valid PDUs */
1808 /* PDU 3 */
1809 payload_number++;
1810 pdu_write_loc = 0;
1811 sdu_read_loc = 0;
1812 pdu_write_size = testdata_size;
1813 sdu_fragments++;
1814
1815 ZASSERT_PDU_WRITE_TEST(history[1],
1816 pdu_buffer,
1817 pdu_write_loc,
1818 &testdata[sdu_read_loc],
1819 (pdu_write_size - pdu_write_loc));
1820
1821 ZASSERT_PDU_EMIT_TEST(history[1],
1822 &tx_pdu_meta_buf.node_tx,
1823 payload_number,
1824 sdu_fragments,
1825 PDU_BIS_LLID_COMPLETE_END,
1826 pdu_write_size,
1827 isoal_global.source_state[source_hdl].session.handle);
1828
1829 /* PDU release not expected (No Error) */
1830 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1831
1832 /* Check TX Sync info */
1833 tx_sync_seq_expected = 2;
1834 tx_sync_timestamp_expected = (iso_interval_int * ISO_INT_UNIT_US) - 1;
1835 tx_sync_offset_expected = 0;
1836
1837 err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset);
1838
1839 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1840 zassert_equal(tx_sync_seq, tx_sync_seq_expected, "%u != %u", tx_sync_seq, 2);
1841 zassert_equal(tx_sync_timestamp, tx_sync_timestamp_expected, "%u != %u", tx_sync_seq, 2);
1842 zassert_equal(tx_sync_offset, tx_sync_offset_expected, "%u != %u", tx_sync_seq, 0);
1843 }
1844
1845 /**
1846 * Test Suite : TX unframed SDU fragmentation
1847 *
1848 * Tests fragmentation of two SDUs containing three fragments each
1849 * into two PDUs each where Max PDU is greater than the PDU buffer size
1850 */
ZTEST(test_tx_unframed,test_tx_unframed_2_sdu_3_frag_4_pdu)1851 ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu)
1852 {
1853 struct tx_pdu_meta_buffer tx_pdu_meta_buf[2];
1854 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
1855 struct isoal_pdu_buffer pdu_buffer[2];
1856 isoal_source_handle_t source_hdl;
1857 isoal_sdu_len_t sdu_total_size;
1858 isoal_pdu_len_t pdu_write_size;
1859 uint32_t stream_sync_delay;
1860 uint64_t sdu_packet_number;
1861 uint32_t group_sync_delay;
1862 uint8_t iso_interval_int;
1863 uint64_t payload_number;
1864 uint32_t sdu_timestamp;
1865 uint16_t testdata_indx;
1866 uint16_t testdata_size;
1867 uint16_t pdu_write_loc;
1868 uint16_t sdu_read_loc;
1869 uint64_t event_number;
1870 uint32_t sdu_interval;
1871 uint8_t sdu_fragments;
1872 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX * 2];
1873 uint32_t ref_point;
1874 isoal_status_t err;
1875 uint8_t max_octets;
1876 uint8_t role;
1877 uint8_t BN;
1878 uint8_t FT;
1879
1880 /* Settings */
1881 role = ISOAL_ROLE_PERIPHERAL;
1882 iso_interval_int = 2;
1883 sdu_interval = ISO_INT_UNIT_US;
1884 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
1885 BN = 4;
1886 FT = 1;
1887 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
1888 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
1889
1890 /* SDU 1 Frag 1 ------------------------------------------------------*/
1891 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
1892 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
1893 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1894 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX * 2);
1895 pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx;
1896 pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu;
1897 pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX;
1898 pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx;
1899 pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu;
1900 pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX;
1901 sdu_packet_number = 2000;
1902 event_number = 2000;
1903 sdu_timestamp = 9249;
1904 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
1905 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
1906 testdata_indx = 0;
1907 testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
1908 sdu_fragments = 0;
1909
1910 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
1911 role, /* Role */
1912 false, /* Framed */
1913 BN, /* BN */
1914 FT, /* FT */
1915 max_octets, /* max_octets */
1916 sdu_interval, /* SDU Interval */
1917 iso_interval_int, /* ISO Interval */
1918 stream_sync_delay, /* Stream Sync Delay */
1919 group_sync_delay); /* Group Sync Delay */
1920
1921 isoal_test_create_sdu_fagment(BT_ISO_START,
1922 &testdata[testdata_indx],
1923 (testdata_size - testdata_indx),
1924 sdu_total_size,
1925 sdu_packet_number,
1926 sdu_timestamp,
1927 sdu_timestamp,
1928 ref_point,
1929 event_number,
1930 &tx_sdu_frag_buf.sdu_tx);
1931
1932 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
1933 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
1934 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
1935 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
1936 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
1937 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
1938 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
1939 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
1940
1941 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1942
1943 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1944
1945 /* Test fragmentation (Black Box) */
1946 /* Valid PDUs */
1947 /* PDU 1 */
1948 payload_number = event_number * BN;
1949 pdu_write_loc = 0;
1950 sdu_read_loc = 0;
1951 pdu_write_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
1952 sdu_fragments++;
1953
1954 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(1);
1955
1956 ZASSERT_PDU_WRITE_TEST(history[0],
1957 pdu_buffer[0],
1958 pdu_write_loc,
1959 &testdata[sdu_read_loc],
1960 (pdu_write_size - pdu_write_loc));
1961
1962 /* PDU should not be emitted */
1963 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
1964
1965 /* PDU release not expected (No Error) */
1966 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
1967
1968 /* SDU 1 Frag 2 ------------------------------------------------------*/
1969 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
1970 sdu_timestamp += 10;
1971 testdata_indx += testdata_size;
1972 testdata_size += (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
1973
1974 isoal_test_create_sdu_fagment(BT_ISO_CONT,
1975 &testdata[testdata_indx],
1976 (testdata_size - testdata_indx),
1977 sdu_total_size,
1978 sdu_packet_number,
1979 sdu_timestamp,
1980 sdu_timestamp,
1981 ref_point,
1982 event_number,
1983 &tx_sdu_frag_buf.sdu_tx);
1984
1985 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
1986
1987 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1988
1989 /* Test fragmentation (Black Box) */
1990 /* Valid PDUs */
1991 /* PDU 1 */
1992 pdu_write_loc = pdu_write_size;
1993 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
1994 sdu_read_loc = testdata_indx;
1995
1996 ZASSERT_PDU_WRITE_TEST(history[1],
1997 pdu_buffer[0],
1998 pdu_write_loc,
1999 &testdata[sdu_read_loc],
2000 (pdu_write_size - pdu_write_loc));
2001
2002 ZASSERT_PDU_EMIT_TEST(history[0],
2003 &tx_pdu_meta_buf[0].node_tx,
2004 payload_number,
2005 sdu_fragments,
2006 PDU_BIS_LLID_START_CONTINUE,
2007 pdu_write_size,
2008 isoal_global.source_state[source_hdl].session.handle);
2009
2010 /* PDU release not expected (No Error) */
2011 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2012
2013 /* PDU 2 */
2014 payload_number++;
2015 sdu_read_loc = pdu_write_size;
2016 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc);
2017 pdu_write_loc = 0;
2018 sdu_fragments = 1;
2019
2020 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(2);
2021
2022 ZASSERT_PDU_WRITE_TEST(history[2],
2023 pdu_buffer[1],
2024 pdu_write_loc,
2025 &testdata[sdu_read_loc],
2026 (pdu_write_size - pdu_write_loc));
2027
2028 /* PDU should not be emitted */
2029 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1);
2030
2031 /* SDU 1 Frag 3 ------------------------------------------------------*/
2032 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2033 sdu_timestamp += 10;
2034 testdata_indx = testdata_size;
2035 testdata_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
2036
2037 isoal_test_create_sdu_fagment(BT_ISO_END,
2038 &testdata[testdata_indx],
2039 (testdata_size - testdata_indx),
2040 sdu_total_size,
2041 sdu_packet_number,
2042 sdu_timestamp,
2043 sdu_timestamp,
2044 ref_point,
2045 event_number,
2046 &tx_sdu_frag_buf.sdu_tx);
2047
2048 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2049
2050 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2051
2052 /* Test fragmentation (Black Box) */
2053 /* Valid PDUs */
2054 /* PDU 2 */
2055 pdu_write_loc = pdu_write_size;
2056 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
2057 sdu_read_loc = testdata_indx;
2058 sdu_fragments++;
2059
2060 /* PDU should not be allocated */
2061 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(2);
2062
2063 ZASSERT_PDU_WRITE_TEST(history[3],
2064 pdu_buffer[1],
2065 pdu_write_loc,
2066 &testdata[sdu_read_loc],
2067 (pdu_write_size - pdu_write_loc));
2068
2069 ZASSERT_PDU_EMIT_TEST(history[1],
2070 &tx_pdu_meta_buf[1].node_tx,
2071 payload_number,
2072 sdu_fragments,
2073 PDU_BIS_LLID_COMPLETE_END,
2074 pdu_write_size,
2075 isoal_global.source_state[source_hdl].session.handle);
2076
2077 /* PDU release not expected (No Error) */
2078 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2079
2080 /* SDU 2 Frag 1 ------------------------------------------------------*/
2081 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
2082 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
2083 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2084 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX * 2);
2085 sdu_packet_number++;
2086 event_number = 2000;
2087 sdu_timestamp = 9249 + sdu_interval;
2088 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
2089 testdata_indx = 0;
2090 testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
2091 sdu_fragments = 0;
2092
2093 isoal_test_create_sdu_fagment(BT_ISO_START,
2094 &testdata[testdata_indx],
2095 (testdata_size - testdata_indx),
2096 sdu_total_size,
2097 sdu_packet_number,
2098 sdu_timestamp,
2099 sdu_timestamp,
2100 ref_point,
2101 event_number,
2102 &tx_sdu_frag_buf.sdu_tx);
2103
2104 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2105
2106 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2107
2108 /* Test fragmentation (Black Box) */
2109 /* Valid PDUs */
2110 /* PDU 3 */
2111 payload_number++;
2112 pdu_write_loc = 0;
2113 sdu_read_loc = 0;
2114 pdu_write_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
2115 sdu_fragments++;
2116
2117 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(3);
2118
2119 ZASSERT_PDU_WRITE_TEST(history[4],
2120 pdu_buffer[0],
2121 pdu_write_loc,
2122 &testdata[sdu_read_loc],
2123 (pdu_write_size - pdu_write_loc));
2124
2125 /* PDU should not be emitted */
2126 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2);
2127
2128 /* PDU release not expected (No Error) */
2129 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2130
2131 /* SDU 2 Frag 2 ------------------------------------------------------*/
2132 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2133 sdu_timestamp += 10;
2134 testdata_indx += testdata_size;
2135 testdata_size += (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
2136
2137 isoal_test_create_sdu_fagment(BT_ISO_CONT,
2138 &testdata[testdata_indx],
2139 (testdata_size - testdata_indx),
2140 sdu_total_size,
2141 sdu_packet_number,
2142 sdu_timestamp,
2143 sdu_timestamp,
2144 ref_point,
2145 event_number,
2146 &tx_sdu_frag_buf.sdu_tx);
2147
2148 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2149
2150 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2151
2152 /* Test fragmentation (Black Box) */
2153 /* Valid PDUs */
2154 /* PDU 3 */
2155 pdu_write_loc = pdu_write_size;
2156 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
2157 sdu_read_loc = testdata_indx;
2158
2159 ZASSERT_PDU_WRITE_TEST(history[5],
2160 pdu_buffer[0],
2161 pdu_write_loc,
2162 &testdata[sdu_read_loc],
2163 (pdu_write_size - pdu_write_loc));
2164
2165 ZASSERT_PDU_EMIT_TEST(history[2],
2166 &tx_pdu_meta_buf[0].node_tx,
2167 payload_number,
2168 sdu_fragments,
2169 PDU_BIS_LLID_START_CONTINUE,
2170 pdu_write_size,
2171 isoal_global.source_state[source_hdl].session.handle);
2172
2173 /* PDU release not expected (No Error) */
2174 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2175
2176 /* PDU 4 */
2177 payload_number++;
2178 sdu_read_loc = pdu_write_size;
2179 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc);
2180 pdu_write_loc = 0;
2181 sdu_fragments = 1;
2182
2183 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(4);
2184
2185 ZASSERT_PDU_WRITE_TEST(history[6],
2186 pdu_buffer[1],
2187 pdu_write_loc,
2188 &testdata[sdu_read_loc],
2189 (pdu_write_size - pdu_write_loc));
2190
2191 /* PDU should not be emitted */
2192 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(3);
2193
2194 /* SDU 2 Frag 3 ------------------------------------------------------*/
2195 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2196 sdu_timestamp += 10;
2197 testdata_indx = testdata_size;
2198 testdata_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
2199
2200 isoal_test_create_sdu_fagment(BT_ISO_END,
2201 &testdata[testdata_indx],
2202 (testdata_size - testdata_indx),
2203 sdu_total_size,
2204 sdu_packet_number,
2205 sdu_timestamp,
2206 sdu_timestamp,
2207 ref_point,
2208 event_number,
2209 &tx_sdu_frag_buf.sdu_tx);
2210
2211 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2212
2213 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2214
2215 /* Test fragmentation (Black Box) */
2216 /* Valid PDUs */
2217 /* PDU 4 */
2218 pdu_write_loc = pdu_write_size;
2219 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
2220 sdu_read_loc = testdata_indx;
2221 sdu_fragments++;
2222
2223 /* PDU should not be allocated */
2224 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(4);
2225
2226 ZASSERT_PDU_WRITE_TEST(history[7],
2227 pdu_buffer[1],
2228 pdu_write_loc,
2229 &testdata[sdu_read_loc],
2230 (pdu_write_size - pdu_write_loc));
2231
2232 ZASSERT_PDU_EMIT_TEST(history[3],
2233 &tx_pdu_meta_buf[1].node_tx,
2234 payload_number,
2235 sdu_fragments,
2236 PDU_BIS_LLID_COMPLETE_END,
2237 pdu_write_size,
2238 isoal_global.source_state[source_hdl].session.handle);
2239
2240 /* PDU release not expected (No Error) */
2241 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2242 }
2243
2244 /**
2245 * Test Suite : TX unframed SDU fragmentation
2246 *
2247 * Tests fragmentation of two SDUs containing three fragments each
2248 * into two PDUs each where Max PDU is greater than the PDU buffer size
2249 * with padding
2250 */
ZTEST(test_tx_unframed,test_tx_unframed_2_sdu_3_frag_4_pdu_padding)2251 ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding)
2252 {
2253 struct tx_pdu_meta_buffer tx_pdu_meta_buf[3];
2254 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
2255 struct isoal_pdu_buffer pdu_buffer[3];
2256 isoal_source_handle_t source_hdl;
2257 isoal_sdu_len_t sdu_total_size;
2258 isoal_pdu_len_t pdu_write_size;
2259 uint32_t stream_sync_delay;
2260 uint64_t sdu_packet_number;
2261 uint32_t group_sync_delay;
2262 uint8_t iso_interval_int;
2263 uint64_t payload_number;
2264 uint32_t sdu_timestamp;
2265 uint16_t testdata_indx;
2266 uint16_t testdata_size;
2267 uint16_t pdu_write_loc;
2268 uint16_t sdu_read_loc;
2269 uint64_t event_number;
2270 uint32_t sdu_interval;
2271 uint8_t sdu_fragments;
2272 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX * 2];
2273 uint32_t ref_point;
2274 isoal_status_t err;
2275 uint8_t max_octets;
2276 uint8_t role;
2277 uint8_t BN;
2278 uint8_t FT;
2279
2280 /* Settings */
2281 role = ISOAL_ROLE_PERIPHERAL;
2282 iso_interval_int = 2;
2283 sdu_interval = ISO_INT_UNIT_US;
2284 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
2285 BN = 8;
2286 FT = 1;
2287 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
2288 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
2289
2290 /* SDU 1 Frag 1 ------------------------------------------------------*/
2291 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
2292 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
2293 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]);
2294 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2295 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX * 2);
2296 pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx;
2297 pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu;
2298 pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX;
2299 pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx;
2300 pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu;
2301 pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX;
2302 pdu_buffer[2].handle = (void *)&tx_pdu_meta_buf[2].node_tx;
2303 pdu_buffer[2].pdu = (struct pdu_iso *)tx_pdu_meta_buf[2].node_tx.pdu;
2304 pdu_buffer[2].size = TEST_TX_PDU_PAYLOAD_MAX;
2305 sdu_packet_number = 2000;
2306 event_number = 2000;
2307 sdu_timestamp = 9249;
2308 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
2309 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
2310 testdata_indx = 0;
2311 testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
2312 sdu_fragments = 0;
2313
2314 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
2315 role, /* Role */
2316 false, /* Framed */
2317 BN, /* BN */
2318 FT, /* FT */
2319 max_octets, /* max_octets */
2320 sdu_interval, /* SDU Interval */
2321 iso_interval_int, /* ISO Interval */
2322 stream_sync_delay, /* Stream Sync Delay */
2323 group_sync_delay); /* Group Sync Delay */
2324
2325 isoal_test_create_sdu_fagment(BT_ISO_START,
2326 &testdata[testdata_indx],
2327 (testdata_size - testdata_indx),
2328 sdu_total_size,
2329 sdu_packet_number,
2330 sdu_timestamp,
2331 sdu_timestamp,
2332 ref_point,
2333 event_number,
2334 &tx_sdu_frag_buf.sdu_tx);
2335
2336 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
2337 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
2338 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
2339 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[2]);
2340 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
2341 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
2342 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
2343 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[2]);
2344 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
2345 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
2346 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
2347 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
2348
2349 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2350
2351 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2352
2353 /* Test fragmentation (Black Box) */
2354 /* Valid PDUs */
2355 /* PDU 2 */
2356 payload_number = event_number * BN;
2357 pdu_write_loc = 0;
2358 sdu_read_loc = 0;
2359 pdu_write_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
2360 sdu_fragments++;
2361
2362 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(1);
2363
2364 ZASSERT_PDU_WRITE_TEST(history[0],
2365 pdu_buffer[0],
2366 pdu_write_loc,
2367 &testdata[sdu_read_loc],
2368 (pdu_write_size - pdu_write_loc));
2369
2370 /* PDU should not be emitted */
2371 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
2372
2373 /* PDU release not expected (No Error) */
2374 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2375
2376 /* SDU 1 Frag 2 ------------------------------------------------------*/
2377 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2378 sdu_timestamp += 10;
2379 testdata_indx += testdata_size;
2380 testdata_size += (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
2381
2382 isoal_test_create_sdu_fagment(BT_ISO_CONT,
2383 &testdata[testdata_indx],
2384 (testdata_size - testdata_indx),
2385 sdu_total_size,
2386 sdu_packet_number,
2387 sdu_timestamp,
2388 sdu_timestamp,
2389 ref_point,
2390 event_number,
2391 &tx_sdu_frag_buf.sdu_tx);
2392
2393 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2394
2395 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2396
2397 /* Test fragmentation (Black Box) */
2398 /* Valid PDUs */
2399 /* PDU 1 */
2400 pdu_write_loc = pdu_write_size;
2401 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
2402 sdu_read_loc = testdata_indx;
2403
2404 ZASSERT_PDU_WRITE_TEST(history[1],
2405 pdu_buffer[0],
2406 pdu_write_loc,
2407 &testdata[sdu_read_loc],
2408 (pdu_write_size - pdu_write_loc));
2409
2410 ZASSERT_PDU_EMIT_TEST(history[0],
2411 &tx_pdu_meta_buf[0].node_tx,
2412 payload_number,
2413 sdu_fragments,
2414 PDU_BIS_LLID_START_CONTINUE,
2415 pdu_write_size,
2416 isoal_global.source_state[source_hdl].session.handle);
2417
2418 /* PDU 2 */
2419 payload_number++;
2420 sdu_read_loc = pdu_write_size;
2421 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc);
2422 pdu_write_loc = 0;
2423 sdu_fragments = 1;
2424
2425 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(2);
2426
2427 ZASSERT_PDU_WRITE_TEST(history[2],
2428 pdu_buffer[1],
2429 pdu_write_loc,
2430 &testdata[sdu_read_loc],
2431 (pdu_write_size - pdu_write_loc));
2432
2433 /* PDU should not be emitted */
2434 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1);
2435
2436 /* PDU release not expected (No Error) */
2437 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2438
2439 /* SDU 1 Frag 3 ------------------------------------------------------*/
2440 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2441 sdu_timestamp += 10;
2442 testdata_indx = testdata_size;
2443 testdata_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
2444
2445 isoal_test_create_sdu_fagment(BT_ISO_END,
2446 &testdata[testdata_indx],
2447 (testdata_size - testdata_indx),
2448 sdu_total_size,
2449 sdu_packet_number,
2450 sdu_timestamp,
2451 sdu_timestamp,
2452 ref_point,
2453 event_number,
2454 &tx_sdu_frag_buf.sdu_tx);
2455
2456 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2457
2458 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2459
2460 /* Test fragmentation (Black Box) */
2461 /* Valid PDUs */
2462 /* PDU 2 */
2463 pdu_write_loc = pdu_write_size;
2464 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
2465 sdu_read_loc = testdata_indx;
2466 sdu_fragments++;
2467
2468 ZASSERT_PDU_WRITE_TEST(history[3],
2469 pdu_buffer[1],
2470 pdu_write_loc,
2471 &testdata[sdu_read_loc],
2472 (pdu_write_size - pdu_write_loc));
2473
2474 ZASSERT_PDU_EMIT_TEST(history[1],
2475 &tx_pdu_meta_buf[1].node_tx,
2476 payload_number,
2477 sdu_fragments,
2478 PDU_BIS_LLID_COMPLETE_END,
2479 pdu_write_size,
2480 isoal_global.source_state[source_hdl].session.handle);
2481
2482 /* PDU release not expected (No Error) */
2483 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2484
2485 /* Padding PDUs */
2486 /* Padding 1 */
2487 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
2488 payload_number++;
2489 pdu_write_size = 0;
2490 sdu_fragments = 0;
2491
2492 /* PDU should not be written to */
2493 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(4);
2494
2495 ZASSERT_PDU_EMIT_TEST(history[2],
2496 &tx_pdu_meta_buf[0].node_tx,
2497 payload_number,
2498 sdu_fragments,
2499 PDU_BIS_LLID_START_CONTINUE,
2500 pdu_write_size,
2501 isoal_global.source_state[source_hdl].session.handle);
2502
2503 /* PDU release not expected (No Error) */
2504 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2505
2506 /* Padding 2 */
2507 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]);
2508 payload_number++;
2509 pdu_write_size = 0;
2510 sdu_fragments = 0;
2511
2512 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(4);
2513
2514 /* PDU should not be written to */
2515 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(4);
2516
2517 ZASSERT_PDU_EMIT_TEST(history[3],
2518 &tx_pdu_meta_buf[2].node_tx,
2519 payload_number,
2520 sdu_fragments,
2521 PDU_BIS_LLID_START_CONTINUE,
2522 pdu_write_size,
2523 isoal_global.source_state[source_hdl].session.handle);
2524
2525 /* PDU release not expected (No Error) */
2526 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2527
2528 /* SDU 2 Frag 1 ------------------------------------------------------*/
2529 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
2530 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
2531 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2532 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX * 2);
2533 sdu_packet_number++;
2534 event_number = 2000;
2535 sdu_timestamp = 9249 + sdu_interval;
2536 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
2537 testdata_indx = 0;
2538 testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
2539 sdu_fragments = 0;
2540
2541 isoal_test_create_sdu_fagment(BT_ISO_START,
2542 &testdata[testdata_indx],
2543 (testdata_size - testdata_indx),
2544 sdu_total_size,
2545 sdu_packet_number,
2546 sdu_timestamp,
2547 sdu_timestamp,
2548 ref_point,
2549 event_number,
2550 &tx_sdu_frag_buf.sdu_tx);
2551
2552 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2553
2554 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2555
2556 /* Test fragmentation (Black Box) */
2557 /* Valid PDUs */
2558 /* PDU 3 */
2559 payload_number++;
2560 pdu_write_loc = 0;
2561 sdu_read_loc = 0;
2562 pdu_write_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
2563 sdu_fragments++;
2564
2565 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(5);
2566
2567 ZASSERT_PDU_WRITE_TEST(history[4],
2568 pdu_buffer[0],
2569 pdu_write_loc,
2570 &testdata[sdu_read_loc],
2571 (pdu_write_size - pdu_write_loc));
2572
2573 /* PDU should not be emitted */
2574 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(4);
2575
2576 /* PDU release not expected (No Error) */
2577
2578 /* SDU 2 Frag 2 ------------------------------------------------------*/
2579 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2580 sdu_timestamp += 10;
2581 testdata_indx += testdata_size;
2582 testdata_size += (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3;
2583
2584 isoal_test_create_sdu_fagment(BT_ISO_CONT,
2585 &testdata[testdata_indx],
2586 (testdata_size - testdata_indx),
2587 sdu_total_size,
2588 sdu_packet_number,
2589 sdu_timestamp,
2590 sdu_timestamp,
2591 ref_point,
2592 event_number,
2593 &tx_sdu_frag_buf.sdu_tx);
2594
2595 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2596
2597 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2598
2599 /* Test fragmentation (Black Box) */
2600 /* Valid PDUs */
2601 /* PDU 3 */
2602 pdu_write_loc = pdu_write_size;
2603 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
2604 sdu_read_loc = testdata_indx;
2605
2606 ZASSERT_PDU_WRITE_TEST(history[5],
2607 pdu_buffer[0],
2608 pdu_write_loc,
2609 &testdata[sdu_read_loc],
2610 (pdu_write_size - pdu_write_loc));
2611
2612 ZASSERT_PDU_EMIT_TEST(history[4],
2613 &tx_pdu_meta_buf[0].node_tx,
2614 payload_number,
2615 sdu_fragments,
2616 PDU_BIS_LLID_START_CONTINUE,
2617 pdu_write_size,
2618 isoal_global.source_state[source_hdl].session.handle);
2619
2620 /* PDU 4 */
2621 payload_number++;
2622 sdu_read_loc = pdu_write_size;
2623 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc);
2624 pdu_write_loc = 0;
2625 sdu_fragments = 1;
2626
2627 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(6);
2628
2629 ZASSERT_PDU_WRITE_TEST(history[6],
2630 pdu_buffer[1],
2631 pdu_write_loc,
2632 &testdata[sdu_read_loc],
2633 (pdu_write_size - pdu_write_loc));
2634
2635 /* PDU should not be emitted */
2636 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(5);
2637
2638 /* PDU release not expected (No Error) */
2639 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2640
2641 /* SDU 2 Frag 3 ------------------------------------------------------*/
2642 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2643 sdu_timestamp += 10;
2644 testdata_indx = testdata_size;
2645 testdata_size = TEST_TX_PDU_PAYLOAD_MAX * 2;
2646
2647 isoal_test_create_sdu_fagment(BT_ISO_END,
2648 &testdata[testdata_indx],
2649 (testdata_size - testdata_indx),
2650 sdu_total_size,
2651 sdu_packet_number,
2652 sdu_timestamp,
2653 sdu_timestamp,
2654 ref_point,
2655 event_number,
2656 &tx_sdu_frag_buf.sdu_tx);
2657
2658 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2659
2660 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2661
2662 /* Test fragmentation (Black Box) */
2663 /* Valid PDUs */
2664 /* PDU 4 */
2665 pdu_write_loc = pdu_write_size;
2666 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
2667 sdu_read_loc = testdata_indx;
2668 sdu_fragments++;
2669
2670 ZASSERT_PDU_WRITE_TEST(history[7],
2671 pdu_buffer[1],
2672 pdu_write_loc,
2673 &testdata[sdu_read_loc],
2674 (pdu_write_size - pdu_write_loc));
2675
2676 ZASSERT_PDU_EMIT_TEST(history[5],
2677 &tx_pdu_meta_buf[1].node_tx,
2678 payload_number,
2679 sdu_fragments,
2680 PDU_BIS_LLID_COMPLETE_END,
2681 pdu_write_size,
2682 isoal_global.source_state[source_hdl].session.handle);
2683
2684 /* Padding PDUs */
2685 /* Padding 3 */
2686 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
2687 payload_number++;
2688 pdu_write_size = 0;
2689 sdu_fragments = 0;
2690
2691 /* PDU should not be written to */
2692 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(8);
2693
2694 ZASSERT_PDU_EMIT_TEST(history[6],
2695 &tx_pdu_meta_buf[0].node_tx,
2696 payload_number,
2697 sdu_fragments,
2698 PDU_BIS_LLID_START_CONTINUE,
2699 pdu_write_size,
2700 isoal_global.source_state[source_hdl].session.handle);
2701
2702 /* Padding 4 */
2703 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]);
2704 payload_number++;
2705 pdu_write_size = 0;
2706 sdu_fragments = 0;
2707
2708 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(8);
2709
2710 /* PDU should not be written to */
2711 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(8);
2712
2713 ZASSERT_PDU_EMIT_TEST(history[7],
2714 &tx_pdu_meta_buf[2].node_tx,
2715 payload_number,
2716 sdu_fragments,
2717 PDU_BIS_LLID_START_CONTINUE,
2718 pdu_write_size,
2719 isoal_global.source_state[source_hdl].session.handle);
2720
2721 /* PDU release not expected (No Error) */
2722 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2723 }
2724
2725 /**
2726 * Test Suite : TX unframed SDU fragmentation
2727 *
2728 * Tests fragmentation of a single SDU contained in a single fragment
2729 * into a single PDU where Max PDU is less than the PDU buffer size,
2730 * followed by padding
2731 */
ZTEST(test_tx_unframed,test_tx_unframed_1_zero_sdu_1_frag_1_pdu_maxPDU_padding)2732 ZTEST(test_tx_unframed, test_tx_unframed_1_zero_sdu_1_frag_1_pdu_maxPDU_padding)
2733 {
2734 struct tx_pdu_meta_buffer tx_pdu_meta_buf[3];
2735 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
2736 struct isoal_pdu_buffer pdu_buffer[3];
2737 isoal_source_handle_t source_hdl;
2738 isoal_sdu_len_t sdu_total_size;
2739 isoal_pdu_len_t pdu_write_size;
2740 uint32_t stream_sync_delay;
2741 uint64_t sdu_packet_number;
2742 uint32_t group_sync_delay;
2743 uint8_t iso_interval_int;
2744 uint64_t payload_number;
2745 uint32_t sdu_timestamp;
2746 uint16_t testdata_indx;
2747 uint16_t testdata_size;
2748 uint16_t pdu_write_loc;
2749 uint16_t sdu_read_loc;
2750 uint64_t event_number;
2751 uint32_t sdu_interval;
2752 uint8_t sdu_fragments;
2753 uint8_t testdata[1];
2754 uint32_t ref_point;
2755 isoal_status_t err;
2756 uint8_t max_octets;
2757 uint8_t role;
2758 uint8_t BN;
2759 uint8_t FT;
2760
2761 /* Settings */
2762 role = ISOAL_ROLE_PERIPHERAL;
2763 iso_interval_int = 1;
2764 sdu_interval = ISO_INT_UNIT_US;
2765 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
2766 BN = 3;
2767 FT = 1;
2768 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
2769 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
2770
2771 /* SDU 1 Frag 1 ------------------------------------------------------*/
2772 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
2773 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
2774 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]);
2775 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2776 init_test_data_buffer(testdata, 1);
2777 pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx;
2778 pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu;
2779 pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX;
2780 pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx;
2781 pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu;
2782 pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX;
2783 pdu_buffer[2].handle = (void *)&tx_pdu_meta_buf[2].node_tx;
2784 pdu_buffer[2].pdu = (struct pdu_iso *)tx_pdu_meta_buf[2].node_tx.pdu;
2785 pdu_buffer[2].size = TEST_TX_PDU_PAYLOAD_MAX;
2786 sdu_packet_number = 2000;
2787 event_number = 2000;
2788 sdu_timestamp = 9249;
2789 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
2790 sdu_total_size = 0;
2791 testdata_indx = 0;
2792 testdata_size = 0;
2793 payload_number = event_number * BN;
2794 pdu_write_loc = 0;
2795 sdu_read_loc = 0;
2796 pdu_write_size = 0;
2797
2798 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
2799 role, /* Role */
2800 false, /* Framed */
2801 BN, /* BN */
2802 FT, /* FT */
2803 max_octets, /* max_octets */
2804 sdu_interval, /* SDU Interval */
2805 iso_interval_int, /* ISO Interval */
2806 stream_sync_delay, /* Stream Sync Delay */
2807 group_sync_delay); /* Group Sync Delay */
2808
2809 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
2810 &testdata[testdata_indx],
2811 (testdata_size - testdata_indx),
2812 sdu_total_size,
2813 sdu_packet_number,
2814 sdu_timestamp,
2815 sdu_timestamp,
2816 ref_point,
2817 event_number,
2818 &tx_sdu_frag_buf.sdu_tx);
2819
2820 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
2821 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
2822 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[2]);
2823 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
2824 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
2825 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
2826 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
2827
2828 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2829
2830 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2831
2832 /* Test fragmentation (Black Box) */
2833 /* Valid PDUs */
2834 /* PDU 1 */
2835 sdu_fragments = 1;
2836
2837 /* PDU should not be written to */
2838 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(0);
2839
2840 ZASSERT_PDU_EMIT_TEST(history[0],
2841 &tx_pdu_meta_buf[0].node_tx,
2842 payload_number,
2843 sdu_fragments,
2844 PDU_BIS_LLID_COMPLETE_END,
2845 pdu_write_size,
2846 isoal_global.source_state[source_hdl].session.handle);
2847
2848 /* PDU release not expected (No Error) */
2849 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2850
2851 /* Padding PDUs */
2852 /* Padding 1 */
2853 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
2854 payload_number++;
2855 pdu_write_size = 0;
2856 sdu_fragments = 0;
2857
2858 /* PDU should not be written to */
2859 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(0);
2860
2861 ZASSERT_PDU_EMIT_TEST(history[1],
2862 &tx_pdu_meta_buf[1].node_tx,
2863 payload_number,
2864 sdu_fragments,
2865 PDU_BIS_LLID_START_CONTINUE,
2866 pdu_write_size,
2867 isoal_global.source_state[source_hdl].session.handle);
2868
2869 /* PDU release not expected (No Error) */
2870 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2871
2872 /* Padding 2 */
2873 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]);
2874 payload_number++;
2875 pdu_write_size = 0;
2876 sdu_fragments = 0;
2877
2878 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(3);
2879
2880 /* PDU should not be written to */
2881 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(0);
2882
2883 ZASSERT_PDU_EMIT_TEST(history[2],
2884 &tx_pdu_meta_buf[2].node_tx,
2885 payload_number,
2886 sdu_fragments,
2887 PDU_BIS_LLID_START_CONTINUE,
2888 pdu_write_size,
2889 isoal_global.source_state[source_hdl].session.handle);
2890
2891 /* PDU release not expected (No Error) */
2892 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
2893 }
2894
2895 /**
2896 * Test Suite : TX unframed SDU fragmentation
2897 *
2898 * Tests fragmentation of a single SDU contained in a single fragment,
2899 * where PDU allocation fails
2900 */
ZTEST(test_tx_unframed,test_tx_unframed_1_sdu_1_frag_pdu_alloc_err)2901 ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_alloc_err)
2902 {
2903 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
2904 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
2905 struct isoal_pdu_buffer pdu_buffer;
2906 isoal_source_handle_t source_hdl;
2907 isoal_sdu_len_t sdu_total_size;
2908 isoal_pdu_len_t pdu_write_size;
2909 uint32_t stream_sync_delay;
2910 uint64_t sdu_packet_number;
2911 uint32_t group_sync_delay;
2912 uint8_t iso_interval_int;
2913 uint64_t payload_number;
2914 uint32_t sdu_timestamp;
2915 uint16_t testdata_indx;
2916 uint16_t testdata_size;
2917 uint16_t pdu_write_loc;
2918 uint16_t sdu_read_loc;
2919 uint64_t event_number;
2920 uint32_t sdu_interval;
2921 uint8_t sdu_fragments;
2922 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX - 5];
2923 uint32_t ref_point;
2924 isoal_status_t err;
2925 uint8_t max_octets;
2926 uint8_t role;
2927 uint8_t BN;
2928 uint8_t FT;
2929
2930 /* Settings */
2931 role = ISOAL_ROLE_PERIPHERAL;
2932 iso_interval_int = 1;
2933 sdu_interval = ISO_INT_UNIT_US;
2934 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
2935 BN = 1;
2936 FT = 1;
2937 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
2938 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
2939
2940 /* SDU Frag 1 --------------------------------------------------------*/
2941 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
2942 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
2943 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX - 5);
2944 pdu_buffer.handle = NULL;
2945 pdu_buffer.pdu = NULL;
2946 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
2947 sdu_packet_number = 2000;
2948 event_number = 2000;
2949 sdu_timestamp = 9249;
2950 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
2951 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
2952 testdata_indx = 0;
2953 testdata_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
2954 payload_number = event_number * BN;
2955 pdu_write_loc = 0;
2956 sdu_read_loc = 0;
2957 pdu_write_size = 0;
2958
2959 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
2960 role, /* Role */
2961 false, /* Framed */
2962 BN, /* BN */
2963 FT, /* FT */
2964 max_octets, /* max_octets */
2965 sdu_interval, /* SDU Interval */
2966 iso_interval_int, /* ISO Interval */
2967 stream_sync_delay, /* Stream Sync Delay */
2968 group_sync_delay); /* Group Sync Delay */
2969
2970 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
2971 &testdata[testdata_indx],
2972 (testdata_size - testdata_indx),
2973 sdu_total_size,
2974 sdu_packet_number,
2975 sdu_timestamp,
2976 sdu_timestamp,
2977 ref_point,
2978 event_number,
2979 &tx_sdu_frag_buf.sdu_tx);
2980
2981 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
2982 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_ERR_PDU_ALLOC);
2983 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
2984 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
2985 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
2986
2987 ztest_set_assert_valid(true);
2988
2989 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
2990
2991 ztest_set_assert_valid(false);
2992
2993 zassert_equal(err, ISOAL_STATUS_ERR_PDU_ALLOC, "err = 0x%02x", err);
2994
2995 /* Test fragmentation (Black Box) */
2996 /* Valid PDUs */
2997 /* PDU 1 */
2998 sdu_fragments = 1;
2999
3000 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(1);
3001
3002 /* PDU should not be written to */
3003 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(0);
3004
3005 /* PDU should not be emitted */
3006 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
3007
3008 /* PDU release not expected (No Error) */
3009 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
3010 }
3011
3012 /**
3013 * Test Suite : TX unframed SDU fragmentation
3014 *
3015 * Tests fragmentation of a single SDU contained in a single fragment
3016 * into a single PDU where Max PDU is less than the PDU buffer size,
3017 * where PDU emit fails
3018 */
ZTEST(test_tx_unframed,test_tx_unframed_1_sdu_1_frag_pdu_emit_err)3019 ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_emit_err)
3020 {
3021 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
3022 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
3023 struct isoal_pdu_buffer pdu_buffer;
3024 isoal_source_handle_t source_hdl;
3025 isoal_sdu_len_t sdu_total_size;
3026 isoal_pdu_len_t pdu_write_size;
3027 uint32_t stream_sync_delay;
3028 uint64_t sdu_packet_number;
3029 uint32_t group_sync_delay;
3030 uint8_t iso_interval_int;
3031 uint64_t payload_number;
3032 uint32_t sdu_timestamp;
3033 uint16_t testdata_indx;
3034 uint16_t testdata_size;
3035 uint16_t pdu_write_loc;
3036 uint16_t sdu_read_loc;
3037 uint64_t event_number;
3038 uint32_t sdu_interval;
3039 uint8_t sdu_fragments;
3040 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX - 5];
3041 uint32_t ref_point;
3042 isoal_status_t err;
3043 uint8_t max_octets;
3044 uint8_t role;
3045 uint8_t BN;
3046 uint8_t FT;
3047
3048 /* Settings */
3049 role = ISOAL_ROLE_PERIPHERAL;
3050 iso_interval_int = 1;
3051 sdu_interval = ISO_INT_UNIT_US;
3052 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
3053 BN = 1;
3054 FT = 1;
3055 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
3056 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
3057
3058 /* SDU Frag 1 --------------------------------------------------------*/
3059 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
3060 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3061 init_test_data_buffer(testdata, TEST_TX_PDU_PAYLOAD_MAX - 5);
3062 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
3063 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
3064 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
3065 sdu_packet_number = 2000;
3066 event_number = 2000;
3067 sdu_timestamp = 9249;
3068 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
3069 sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
3070 testdata_indx = 0;
3071 testdata_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
3072 payload_number = event_number * BN;
3073 pdu_write_loc = 0;
3074 sdu_read_loc = 0;
3075 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
3076
3077 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
3078 role, /* Role */
3079 false, /* Framed */
3080 BN, /* BN */
3081 FT, /* FT */
3082 max_octets, /* max_octets */
3083 sdu_interval, /* SDU Interval */
3084 iso_interval_int, /* ISO Interval */
3085 stream_sync_delay, /* Stream Sync Delay */
3086 group_sync_delay); /* Group Sync Delay */
3087
3088 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3089 &testdata[testdata_indx],
3090 (testdata_size - testdata_indx),
3091 sdu_total_size,
3092 sdu_packet_number,
3093 sdu_timestamp,
3094 sdu_timestamp,
3095 ref_point,
3096 event_number,
3097 &tx_sdu_frag_buf.sdu_tx);
3098
3099 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
3100 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
3101 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
3102 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_ERR_PDU_EMIT);
3103 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
3104
3105 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
3106
3107 zassert_equal(err, ISOAL_STATUS_ERR_PDU_EMIT, "err = 0x%02x", err);
3108
3109 /* Test fragmentation (Black Box) */
3110 /* Valid PDUs */
3111 /* PDU 1 */
3112 sdu_fragments = 1;
3113
3114 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(1);
3115
3116 ZASSERT_PDU_WRITE_TEST(history[0],
3117 pdu_buffer,
3118 pdu_write_loc,
3119 &testdata[sdu_read_loc],
3120 (pdu_write_size - pdu_write_loc));
3121
3122 ZASSERT_PDU_EMIT_TEST(history[0],
3123 &tx_pdu_meta_buf.node_tx,
3124 payload_number,
3125 sdu_fragments,
3126 PDU_BIS_LLID_COMPLETE_END,
3127 pdu_write_size,
3128 isoal_global.source_state[source_hdl].session.handle);
3129
3130 ZASSERT_PDU_RELEASE_TEST(
3131 history[0],
3132 &tx_pdu_meta_buf.node_tx,
3133 bt_iso_handle(isoal_global.source_state[source_hdl].session.handle),
3134 ISOAL_STATUS_ERR_PDU_EMIT);
3135 }
3136
3137 /**
3138 * Test Suite : TX unframed SDU fragmentation
3139 *
3140 * Tests fragmentation of a single SDU contained in a single fragment
3141 * into a single PDU such that it does not insert a skew into the stream.
3142 */
ZTEST(test_tx_unframed,test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc)3143 ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc)
3144 {
3145 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
3146 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
3147 uint32_t tx_sync_timestamp_expected;
3148 struct isoal_pdu_buffer pdu_buffer;
3149 isoal_source_handle_t source_hdl;
3150 uint32_t tx_sync_offset_expected;
3151 isoal_sdu_len_t sdu_total_size;
3152 isoal_pdu_len_t pdu_write_size;
3153 uint16_t tx_sync_seq_expected;
3154 uint32_t stream_sync_delay;
3155 uint64_t sdu_packet_number;
3156 uint32_t tx_sync_timestamp;
3157 uint32_t group_sync_delay;
3158 uint8_t iso_interval_int;
3159 uint64_t payload_number;
3160 uint32_t tx_sync_offset;
3161 uint32_t sdu_timestamp;
3162 uint16_t testdata_indx;
3163 uint16_t testdata_size;
3164 uint16_t pdu_write_loc;
3165 uint16_t sdu_read_loc;
3166 uint64_t event_number;
3167 uint32_t sdu_interval;
3168 uint8_t sdu_fragments;
3169 uint8_t testdata[53];
3170 uint16_t tx_sync_seq;
3171 uint32_t ref_point;
3172 isoal_status_t err;
3173 uint8_t max_octets;
3174 uint8_t role;
3175 uint8_t BN;
3176 uint8_t FT;
3177
3178 /* Settings */
3179 role = ISOAL_ROLE_PERIPHERAL;
3180 iso_interval_int = 1;
3181 sdu_interval = ISO_INT_UNIT_US / 2;
3182 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
3183 BN = 2;
3184 FT = 1;
3185 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
3186 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
3187
3188 /* SDU Frag 1 --------------------------------------------------------*/
3189 /* Sets initial fragmentation status */
3190 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
3191 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3192 init_test_data_buffer(testdata, sizeof(testdata));
3193 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
3194 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
3195 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
3196 event_number = 2000;
3197 sdu_packet_number = (event_number * BN);
3198 sdu_timestamp = 9249;
3199 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
3200 sdu_total_size = 23;
3201 testdata_indx = 0;
3202 testdata_size = 23;
3203 payload_number = event_number * BN;
3204 pdu_write_loc = 0;
3205 sdu_read_loc = 0;
3206 pdu_write_size = 23;
3207
3208 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
3209 role, /* Role */
3210 false, /* Framed */
3211 BN, /* BN */
3212 FT, /* FT */
3213 max_octets, /* max_octets */
3214 sdu_interval, /* SDU Interval */
3215 iso_interval_int, /* ISO Interval */
3216 stream_sync_delay, /* Stream Sync Delay */
3217 group_sync_delay); /* Group Sync Delay */
3218
3219 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3220 &testdata[testdata_indx],
3221 (testdata_size - testdata_indx),
3222 sdu_total_size,
3223 sdu_packet_number,
3224 sdu_timestamp,
3225 sdu_timestamp,
3226 ref_point,
3227 event_number,
3228 &tx_sdu_frag_buf.sdu_tx);
3229
3230 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
3231 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
3232 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
3233 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
3234 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
3235 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
3236 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
3237 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
3238
3239 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
3240
3241 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3242
3243 /* Test fragmentation (Black Box) */
3244 /* Valid PDUs */
3245 /* PDU 1 */
3246 sdu_fragments = 1;
3247
3248 ZASSERT_PDU_WRITE_TEST(history[0],
3249 pdu_buffer,
3250 pdu_write_loc,
3251 &testdata[sdu_read_loc],
3252 (pdu_write_size - pdu_write_loc));
3253
3254 ZASSERT_PDU_EMIT_TEST(history[0],
3255 &tx_pdu_meta_buf.node_tx,
3256 payload_number,
3257 sdu_fragments,
3258 PDU_BIS_LLID_COMPLETE_END,
3259 pdu_write_size,
3260 isoal_global.source_state[source_hdl].session.handle);
3261
3262 /* PDU release not expected (No Error) */
3263 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
3264
3265 /* Check TX Sync info */
3266 tx_sync_seq_expected = 1;
3267 tx_sync_timestamp_expected = ref_point;
3268 tx_sync_offset_expected = 0;
3269
3270 err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset);
3271
3272 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3273 zassert_equal(tx_sync_seq, tx_sync_seq_expected, "%u != %u", tx_sync_seq, 2);
3274 zassert_equal(tx_sync_timestamp, tx_sync_timestamp_expected, "%u != %u", tx_sync_seq, 2);
3275 zassert_equal(tx_sync_offset, tx_sync_offset_expected, "%u != %u", tx_sync_seq, 0);
3276
3277 /* SDU 2 Frag 1 ------------------------------------------------------*/
3278 /* Check correct position in stream based on the SDU packet number */
3279 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
3280 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3281 sdu_packet_number += 29;
3282 sdu_timestamp += ((iso_interval_int * ISO_INT_UNIT_US) * 15) - sdu_interval;
3283 event_number += 15;
3284 ref_point += (iso_interval_int * ISO_INT_UNIT_US) * 15;
3285 sdu_total_size = 10;
3286 testdata_indx = testdata_size;
3287 testdata_size += 10;
3288 sdu_fragments = 0;
3289
3290 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3291 &testdata[testdata_indx],
3292 (testdata_size - testdata_indx),
3293 sdu_total_size,
3294 sdu_packet_number,
3295 sdu_timestamp,
3296 sdu_timestamp,
3297 ref_point,
3298 event_number,
3299 &tx_sdu_frag_buf.sdu_tx);
3300
3301 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
3302
3303 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3304
3305 /* Test fragmentation (Black Box) */
3306 /* Valid PDUs */
3307 /* PDU 2 */
3308 payload_number += 29;
3309 pdu_write_loc = 0;
3310 sdu_read_loc = testdata_indx;
3311 pdu_write_size = (testdata_size - testdata_indx);
3312 sdu_fragments++;
3313
3314 ZASSERT_PDU_WRITE_TEST(history[1],
3315 pdu_buffer,
3316 pdu_write_loc,
3317 &testdata[sdu_read_loc],
3318 (pdu_write_size - pdu_write_loc));
3319
3320 ZASSERT_PDU_EMIT_TEST(history[1],
3321 &tx_pdu_meta_buf.node_tx,
3322 payload_number,
3323 sdu_fragments,
3324 PDU_BIS_LLID_COMPLETE_END,
3325 pdu_write_size,
3326 isoal_global.source_state[source_hdl].session.handle);
3327
3328 /* PDU release not expected (No Error) */
3329 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
3330
3331 /* Check TX Sync info */
3332 tx_sync_seq_expected += 29;
3333 tx_sync_timestamp_expected = ref_point - (iso_interval_int * ISO_INT_UNIT_US);
3334 tx_sync_offset_expected = 0;
3335
3336 err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset);
3337
3338 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3339 zassert_equal(tx_sync_seq, tx_sync_seq_expected, "%u != %u", tx_sync_seq, 2);
3340 zassert_equal(tx_sync_timestamp, tx_sync_timestamp_expected, "%u != %u", tx_sync_seq, 2);
3341 zassert_equal(tx_sync_offset, tx_sync_offset_expected, "%u != %u", tx_sync_seq, 0);
3342
3343 /* SDU 3 Frag 1 ------------------------------------------------------*/
3344 /* Check correct position in stream based on the SDU time stamp */
3345 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
3346 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3347 /* Same SDU packet sequence number for testing */
3348 /* Time stamp just before the exact multiple of the SDU interval */
3349 sdu_timestamp += ((iso_interval_int * ISO_INT_UNIT_US) * 15) - 1;
3350 event_number += 15;
3351 ref_point += (iso_interval_int * ISO_INT_UNIT_US) * 15;
3352 sdu_total_size = 10;
3353 testdata_indx = testdata_size;
3354 testdata_size += 10;
3355 sdu_fragments = 0;
3356
3357 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3358 &testdata[testdata_indx],
3359 (testdata_size - testdata_indx),
3360 sdu_total_size,
3361 sdu_packet_number,
3362 sdu_timestamp,
3363 sdu_timestamp,
3364 ref_point,
3365 event_number,
3366 &tx_sdu_frag_buf.sdu_tx);
3367
3368 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
3369
3370 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3371
3372 /* Test fragmentation (Black Box) */
3373 /* Valid PDUs */
3374 /* PDU 3 */
3375 payload_number += 30;
3376 pdu_write_loc = 0;
3377 sdu_read_loc = testdata_indx;
3378 pdu_write_size = (testdata_size - testdata_indx);
3379 sdu_fragments++;
3380
3381 ZASSERT_PDU_WRITE_TEST(history[2],
3382 pdu_buffer,
3383 pdu_write_loc,
3384 &testdata[sdu_read_loc],
3385 (pdu_write_size - pdu_write_loc));
3386
3387 ZASSERT_PDU_EMIT_TEST(history[2],
3388 &tx_pdu_meta_buf.node_tx,
3389 payload_number,
3390 sdu_fragments,
3391 PDU_BIS_LLID_COMPLETE_END,
3392 pdu_write_size,
3393 isoal_global.source_state[source_hdl].session.handle);
3394
3395 /* PDU release not expected (No Error) */
3396 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
3397
3398 /* Check TX Sync info */
3399 tx_sync_seq_expected += 30;
3400 tx_sync_timestamp_expected = ref_point - (iso_interval_int * ISO_INT_UNIT_US);
3401 tx_sync_offset_expected = 0;
3402
3403 err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset);
3404
3405 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3406 zassert_equal(tx_sync_seq, tx_sync_seq_expected, "%u != %u", tx_sync_seq, 2);
3407 zassert_equal(tx_sync_timestamp, tx_sync_timestamp_expected, "%u != %u", tx_sync_seq, 2);
3408 zassert_equal(tx_sync_offset, tx_sync_offset_expected, "%u != %u", tx_sync_seq, 0);
3409
3410 /* SDU 4 Frag 1 ------------------------------------------------------*/
3411 /* Check correct position in stream based on the SDU time stamp */
3412 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
3413 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3414 /* Same SDU packet sequence number for testing */
3415 /* Time stamp just after the exact multiple of the SDU interval.
3416 * +1 (reset to exact multiple of SDU interval from the last SDU)
3417 * +1 (push the time stamp 1us beyond the multiple mark)
3418 */
3419 sdu_timestamp += ((iso_interval_int * ISO_INT_UNIT_US) * 15) + 1 + 1;
3420 event_number += 15;
3421 ref_point += (iso_interval_int * ISO_INT_UNIT_US) * 15;
3422 sdu_total_size = 10;
3423 testdata_indx = testdata_size;
3424 testdata_size += 10;
3425 sdu_fragments = 0;
3426
3427 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3428 &testdata[testdata_indx],
3429 (testdata_size - testdata_indx),
3430 sdu_total_size,
3431 sdu_packet_number,
3432 sdu_timestamp,
3433 sdu_timestamp,
3434 ref_point,
3435 event_number,
3436 &tx_sdu_frag_buf.sdu_tx);
3437
3438 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
3439
3440 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3441
3442 /* Test fragmentation (Black Box) */
3443 /* Valid PDUs */
3444 /* PDU 3 */
3445 payload_number += 30;
3446 pdu_write_loc = 0;
3447 sdu_read_loc = testdata_indx;
3448 pdu_write_size = (testdata_size - testdata_indx);
3449 sdu_fragments++;
3450
3451 ZASSERT_PDU_WRITE_TEST(history[3],
3452 pdu_buffer,
3453 pdu_write_loc,
3454 &testdata[sdu_read_loc],
3455 (pdu_write_size - pdu_write_loc));
3456
3457 ZASSERT_PDU_EMIT_TEST(history[3],
3458 &tx_pdu_meta_buf.node_tx,
3459 payload_number,
3460 sdu_fragments,
3461 PDU_BIS_LLID_COMPLETE_END,
3462 pdu_write_size,
3463 isoal_global.source_state[source_hdl].session.handle);
3464
3465 /* PDU release not expected (No Error) */
3466 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
3467
3468 /* Check TX Sync info */
3469 tx_sync_seq_expected += 30;
3470 tx_sync_timestamp_expected = ref_point - (iso_interval_int * ISO_INT_UNIT_US);
3471 tx_sync_offset_expected = 0;
3472
3473 err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset);
3474
3475 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3476 zassert_equal(tx_sync_seq, tx_sync_seq_expected, "%u != %u", tx_sync_seq, 2);
3477 zassert_equal(tx_sync_timestamp, tx_sync_timestamp_expected, "%u != %u", tx_sync_seq, 2);
3478 zassert_equal(tx_sync_offset, tx_sync_offset_expected, "%u != %u", tx_sync_seq, 0);
3479 }
3480
3481 /**
3482 * Test Suite : TX framed SDU segmentation
3483 *
3484 * Tests framed event selection
3485 */
3486 #define RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT() \
3487 out_sdus_skipped = isoal_tx_framed_find_correct_tx_event(source, \
3488 &tx_sdu_frag_buf.sdu_tx, \
3489 &out_payload_number, \
3490 &out_ref_point, \
3491 &out_time_offset); \
3492 \
3493 zassert_equal(out_payload_number, expect_payload_number, "%llu != %llu", \
3494 out_payload_number, expect_payload_number); \
3495 zassert_equal(out_ref_point, expect_ref_point, "%u != %u", \
3496 out_ref_point, expect_ref_point); \
3497 zassert_equal(out_time_offset, expect_time_offset, "%u != %u", \
3498 out_time_offset, expect_time_offset); \
3499 zassert_equal(out_sdus_skipped, expect_sdus_skipped, "%u .!= %u", \
3500 out_sdus_skipped, expect_sdus_skipped)
3501
ZTEST(test_tx_framed,test_tx_framed_find_correct_tx_event)3502 ZTEST(test_tx_framed, test_tx_framed_find_correct_tx_event)
3503 {
3504 const uint8_t number_of_pdus = 1;
3505 const uint8_t testdata_size_max = MAX_FRAMED_PDU_PAYLOAD(number_of_pdus);
3506
3507 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
3508 struct isoal_source_session *session;
3509 uint8_t testdata[testdata_size_max];
3510 isoal_sdu_len_t in_sdu_total_size;
3511 isoal_source_handle_t source_hdl;
3512 struct isoal_pdu_production *pp;
3513 uint64_t expect_payload_number;
3514 struct isoal_source *source;
3515 uint64_t out_payload_number;
3516 uint32_t expect_time_offset;
3517 uint8_t expect_sdus_skipped;
3518 uint32_t expected_timestamp;
3519 uint32_t stream_sync_delay;
3520 uint32_t in_cntr_timestamp;
3521 uint32_t group_sync_delay;
3522 uint64_t in_sdu_packet_sn;
3523 uint32_t in_sdu_timestamp;
3524 uint32_t expect_ref_point;
3525 uint64_t in_target_event;
3526 uint32_t iso_interval_us;
3527 uint8_t iso_interval_int;
3528 uint32_t out_time_offset;
3529 uint8_t out_sdus_skipped;
3530 uint16_t testdata_indx;
3531 uint16_t testdata_size;
3532 uint32_t out_ref_point;
3533 uint32_t sdu_interval;
3534 uint32_t in_ref_point;
3535 uint8_t max_octets;
3536 uint8_t role;
3537 uint8_t BN;
3538 uint8_t FT;
3539
3540 /* Settings */
3541 role = BT_CONN_ROLE_PERIPHERAL;
3542 iso_interval_int = 1;
3543 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
3544 sdu_interval = iso_interval_us + 50;
3545 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
3546 BN = 2;
3547 FT = 1;
3548 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
3549 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
3550
3551 init_test_data_buffer(testdata, testdata_size_max);
3552
3553 /* Create source */
3554 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
3555 role, /* Role */
3556 true, /* Framed */
3557 BN, /* BN */
3558 FT, /* FT */
3559 max_octets, /* max_octets */
3560 sdu_interval, /* SDU Interval */
3561 iso_interval_int, /* ISO Interval */
3562 stream_sync_delay, /* Stream Sync Delay */
3563 group_sync_delay); /* Group Sync Delay */
3564
3565 source = &isoal_global.source_state[source_hdl];
3566 session = &source->session;
3567 pp = &source->pdu_production;
3568
3569 in_sdu_total_size = testdata_size_max;
3570 testdata_indx = 0;
3571 testdata_size = testdata_size_max;
3572
3573 /* Test : Selection of event for first SDU where
3574 * -- Last SDU packet number is uninitialized
3575 * -- Last SDU time stamp is uninitialized
3576 * -- Payload number is uninitialized
3577 * -- Target event and reference point are one event ahead
3578 * -- Time stamp is valid
3579 * -- Time stamp indicates that target event is feasible
3580 * Expected:
3581 * -- Target event is used for transmission and calculations are based
3582 * on that
3583 * -- Time offset is based on the SDUs time stamp
3584 */
3585 in_sdu_packet_sn = 2000;
3586 in_target_event = 2000;
3587 in_sdu_timestamp = 9249;
3588 in_cntr_timestamp = in_sdu_timestamp + 200;
3589 in_ref_point = in_sdu_timestamp + iso_interval_us - 50;
3590
3591 pp->initialized = 0U;
3592 session->tx_time_stamp = 0;
3593 session->tx_time_offset = 0;
3594 session->last_input_sn = 0;
3595 session->last_input_time_stamp = 0;
3596 pp->payload_number = 0;
3597
3598 expect_sdus_skipped = 0;
3599 expect_payload_number = in_target_event * BN;
3600 expect_ref_point = in_ref_point;
3601 expected_timestamp = in_sdu_timestamp;
3602 expect_time_offset = expect_ref_point - expected_timestamp;
3603
3604 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3605 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3606 &testdata[testdata_indx],
3607 (testdata_size - testdata_indx),
3608 in_sdu_total_size,
3609 in_sdu_packet_sn,
3610 in_sdu_timestamp,
3611 in_cntr_timestamp,
3612 in_ref_point,
3613 in_target_event,
3614 &tx_sdu_frag_buf.sdu_tx);
3615
3616 RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT();
3617
3618 /* Test : Selection of event for first SDU where
3619 * -- Last SDU packet number is uninitialized
3620 * -- Last SDU time stamp is uninitialized
3621 * -- Payload number ahead of target event
3622 * -- Target event and reference point are one event behind
3623 * current payload
3624 * -- Time stamp is valid
3625 * -- Time stamp indicates that target event is feasible
3626 * Expected:
3627 * -- Target event + 1 is selected based on the payload being ahead and
3628 * calculations are based on that reference
3629 * -- Time offset is based on the SDUs time stamp
3630 */
3631 in_sdu_packet_sn = 2000;
3632 in_target_event = 2000;
3633 in_sdu_timestamp = 9249;
3634 in_cntr_timestamp = in_sdu_timestamp + 200;
3635 in_ref_point = in_sdu_timestamp + iso_interval_us - 50;
3636
3637 pp->initialized = 0U;
3638 session->tx_time_stamp = 0;
3639 session->tx_time_offset = 0;
3640 session->last_input_sn = 0;
3641 session->last_input_time_stamp = 0;
3642 pp->payload_number = (in_target_event + 1) * BN;
3643
3644 expect_sdus_skipped = 0;
3645 expect_payload_number = (in_target_event + 1) * BN;
3646 expect_ref_point = in_ref_point + iso_interval_us;
3647 expected_timestamp = in_sdu_timestamp;
3648 expect_time_offset = expect_ref_point - expected_timestamp;
3649
3650 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3651 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3652 &testdata[testdata_indx],
3653 (testdata_size - testdata_indx),
3654 in_sdu_total_size,
3655 in_sdu_packet_sn,
3656 in_sdu_timestamp,
3657 in_cntr_timestamp,
3658 in_ref_point,
3659 in_target_event,
3660 &tx_sdu_frag_buf.sdu_tx);
3661
3662 RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT();
3663
3664 /* Test : Selection of event for first SDU where
3665 * -- Last SDU packet number is uninitialized
3666 * -- Last SDU time stamp is uninitialized
3667 * -- Payload number ahead of target event
3668 * -- Target event and reference point are one event behind
3669 * current payload
3670 * -- Time stamp is invalid
3671 * -- Controller time stamp indicates that target event is
3672 * feasible
3673 * Expected:
3674 * -- Target event + 1 is selected based on the payload being ahead and
3675 * calculations are based on that reference
3676 * -- Time offset is based on the controller's capture time
3677 */
3678 in_sdu_packet_sn = 2000;
3679 in_target_event = 2000;
3680 in_sdu_timestamp = 0;
3681 in_cntr_timestamp = 9249 + 200;
3682 in_ref_point = in_cntr_timestamp + iso_interval_us - 50;
3683
3684 pp->initialized = 0U;
3685 session->tx_time_stamp = 0;
3686 session->tx_time_offset = 0;
3687 session->last_input_sn = 0;
3688 session->last_input_time_stamp = 0;
3689 pp->payload_number = (in_target_event + 1) * BN;
3690
3691 expect_sdus_skipped = 0;
3692 expect_payload_number = (in_target_event + 1) * BN;
3693 expect_ref_point = in_ref_point + iso_interval_us;
3694 expected_timestamp = in_cntr_timestamp;
3695 expect_time_offset = expect_ref_point - expected_timestamp;
3696
3697 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3698 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3699 &testdata[testdata_indx],
3700 (testdata_size - testdata_indx),
3701 in_sdu_total_size,
3702 in_sdu_packet_sn,
3703 in_sdu_timestamp,
3704 in_cntr_timestamp,
3705 in_ref_point,
3706 in_target_event,
3707 &tx_sdu_frag_buf.sdu_tx);
3708
3709 RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT();
3710
3711 /* Test : Selection of event for a subsequent SDU where
3712 * -- Last SDU packet number is in sequence
3713 * -- Last SDU time stamp is in sequence
3714 * -- Payload number is in sequence
3715 * -- Target event and reference point are one event ahead of
3716 * current payload
3717 * -- Time stamp is valid
3718 * -- Time stamp indicates that target event is feasible
3719 * Expected:
3720 * -- Target event is selected based on the time stamp and calculations
3721 * are based on that reference
3722 * -- Time offset is based on the SDUs time stamp
3723 */
3724 in_sdu_packet_sn = 2000;
3725 in_target_event = 2000;
3726 in_sdu_timestamp = 9249;
3727 in_cntr_timestamp = 9249 + 200;
3728 in_ref_point = in_sdu_timestamp + iso_interval_us - 50;
3729
3730 pp->initialized = 1U;
3731 session->tx_time_stamp = 0;
3732 session->tx_time_offset = 0;
3733 session->last_input_sn = in_sdu_packet_sn - 1;
3734 session->last_input_time_stamp = in_sdu_timestamp - sdu_interval;
3735 pp->payload_number = (in_target_event - 1) * BN;
3736
3737 expect_sdus_skipped = 0;
3738 expect_payload_number = in_target_event * BN;
3739 expect_ref_point = in_ref_point;
3740 expected_timestamp = in_sdu_timestamp;
3741 expect_time_offset = expect_ref_point - expected_timestamp;
3742
3743 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3744 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3745 &testdata[testdata_indx],
3746 (testdata_size - testdata_indx),
3747 in_sdu_total_size,
3748 in_sdu_packet_sn,
3749 in_sdu_timestamp,
3750 in_cntr_timestamp,
3751 in_ref_point,
3752 in_target_event,
3753 &tx_sdu_frag_buf.sdu_tx);
3754
3755 RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT();
3756
3757 /* Test : Selection of event for a subsequent SDU where
3758 * -- Last SDU packet number is not in sequence
3759 * -- Last SDU time stamp is not in sequence
3760 * -- Payload number is not in sequence
3761 * -- Target event and reference point are two events ahead
3762 * -- Time stamp is valid but at the border of the range
3763 * -- Time stamp indicates that target event - 1 is feasible
3764 * Expected:
3765 * -- Target event - 1 is selected based on the time stamp and
3766 * calculations are based on that reference
3767 * -- Time offset is based on the SDUs time stamp
3768 */
3769 in_sdu_packet_sn = 2000;
3770 in_target_event = 2001;
3771 in_sdu_timestamp = 9249;
3772 in_cntr_timestamp = 9249 + sdu_interval + iso_interval_us;
3773 in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50;
3774
3775 pp->initialized = 1U;
3776 session->tx_time_stamp = 0;
3777 session->tx_time_offset = 0;
3778 session->last_input_sn = in_sdu_packet_sn - 3;
3779 session->last_input_time_stamp = in_sdu_timestamp - (sdu_interval * 2);
3780 pp->payload_number = (in_target_event - 2) * BN;
3781
3782 expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1;
3783 expect_payload_number = (in_target_event - 1) * BN;
3784 expect_ref_point = in_ref_point - iso_interval_us;
3785 expected_timestamp = in_sdu_timestamp;
3786 expect_time_offset = expect_ref_point - expected_timestamp;
3787
3788 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3789 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3790 &testdata[testdata_indx],
3791 (testdata_size - testdata_indx),
3792 in_sdu_total_size,
3793 in_sdu_packet_sn,
3794 in_sdu_timestamp,
3795 in_cntr_timestamp,
3796 in_ref_point,
3797 in_target_event,
3798 &tx_sdu_frag_buf.sdu_tx);
3799
3800 RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT();
3801
3802 /* Test : Selection of event for a subsequent SDU where
3803 * -- Last SDU packet number is not in sequence
3804 * -- Last SDU time stamp is not in sequence
3805 * -- Payload number is not in sequence
3806 * -- Target event and reference point are two events ahead
3807 * -- Time stamp is invalid
3808 * Expected:
3809 * -- Target event is selected based on the time stamp calculated
3810 * from the difference between time stamps and calculations are based
3811 * on that reference
3812 * -- Time offset is based on the SDUs time stamp
3813 */
3814 in_sdu_packet_sn = 2000;
3815 in_target_event = 2001;
3816 in_sdu_timestamp = 9249;
3817 in_cntr_timestamp = 9249 + sdu_interval + iso_interval_us + 1;
3818 in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50;
3819
3820 pp->initialized = 1U;
3821 session->tx_time_stamp = in_ref_point - iso_interval_us;
3822 session->tx_time_offset = session->tx_time_stamp -
3823 (in_sdu_timestamp - sdu_interval);
3824 session->last_input_sn = in_sdu_packet_sn - 3;
3825 session->last_input_time_stamp = in_sdu_timestamp - (sdu_interval * 2);
3826 pp->payload_number = (in_target_event - 2) * BN;
3827
3828 expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1;
3829 expect_payload_number = in_target_event * BN;
3830 expect_ref_point = in_ref_point;
3831 expected_timestamp = session->tx_time_stamp - session->tx_time_offset +
3832 (in_sdu_timestamp - session->last_input_time_stamp);
3833 expect_time_offset = expect_ref_point - expected_timestamp;
3834
3835 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3836 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3837 &testdata[testdata_indx],
3838 (testdata_size - testdata_indx),
3839 in_sdu_total_size,
3840 in_sdu_packet_sn,
3841 in_sdu_timestamp,
3842 in_cntr_timestamp,
3843 in_ref_point,
3844 in_target_event,
3845 &tx_sdu_frag_buf.sdu_tx);
3846
3847 RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT();
3848
3849 /* Test : Selection of event for a subsequent SDU where
3850 * -- Last SDU packet number is not in sequence
3851 * -- Last SDU time stamp has been projected as part of a
3852 * burst
3853 * -- Payload number is not in sequence
3854 * -- Target event and reference point are two events ahead
3855 * -- Time stamp is invalid
3856 * -- Time stamp delta is invalid
3857 * Expected:
3858 * -- Target event + 1 is selected based on the time stamp calculated
3859 * from the difference in packet sn and calculations are based
3860 * on that reference
3861 * -- Time offset is based on the SDUs time stamp
3862 */
3863 in_sdu_packet_sn = 2000;
3864 in_target_event = 2001;
3865 in_sdu_timestamp = 9249;
3866 in_cntr_timestamp = 9249 + sdu_interval + iso_interval_us + 1;
3867 in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50;
3868
3869 pp->initialized = 1U;
3870 session->tx_time_stamp = in_ref_point - iso_interval_us;
3871 session->tx_time_offset = session->tx_time_stamp -
3872 (in_sdu_timestamp + sdu_interval);
3873 session->last_input_sn = in_sdu_packet_sn - 1;
3874 session->last_input_time_stamp = in_sdu_timestamp + (sdu_interval * 2);
3875 pp->payload_number = (in_target_event - 2) * BN;
3876
3877 expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1;
3878 expect_payload_number = (in_target_event + 1) * BN;
3879 expect_ref_point = in_ref_point + iso_interval_us;
3880 expected_timestamp = session->tx_time_stamp - session->tx_time_offset + sdu_interval;
3881 expect_time_offset = expect_ref_point - expected_timestamp;
3882
3883 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3884 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3885 &testdata[testdata_indx],
3886 (testdata_size - testdata_indx),
3887 in_sdu_total_size,
3888 in_sdu_packet_sn,
3889 in_sdu_timestamp,
3890 in_cntr_timestamp,
3891 in_ref_point,
3892 in_target_event,
3893 &tx_sdu_frag_buf.sdu_tx);
3894
3895 RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT();
3896
3897 /* Test : Selection of event for a subsequent SDU where
3898 * -- Last SDU packet number is in sequence
3899 * -- Last SDU time stamp has been projected as part of a
3900 * burst
3901 * -- Payload number is ahead of selected event
3902 * -- Target event and reference point are two events ahead
3903 * -- Time stamp is valid
3904 * -- Time stamp indicates that target event - 1 is feasible
3905 * Expected:
3906 * -- Target event -1 is selected based on the time stamp and
3907 * calculations are based on that reference
3908 * -- Payload number continues from last
3909 * -- Time offset is based on the SDUs time stamp
3910 */
3911 in_sdu_packet_sn = 2000;
3912 in_target_event = 2001;
3913 in_sdu_timestamp = 9249;
3914 in_cntr_timestamp = 9249;
3915 in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50;
3916
3917 pp->initialized = 1U;
3918 session->tx_time_stamp = 0;
3919 session->tx_time_offset = 0;
3920 session->last_input_sn = in_sdu_packet_sn - 1;
3921 session->last_input_time_stamp = in_sdu_timestamp - sdu_interval;
3922 pp->payload_number = ((in_target_event - 1) * BN) + 1;
3923
3924 expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1;
3925 expect_payload_number = pp->payload_number;
3926 expect_ref_point = in_ref_point - iso_interval_us;
3927 expected_timestamp = in_sdu_timestamp;
3928 expect_time_offset = expect_ref_point - expected_timestamp;
3929
3930 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3931 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
3932 &testdata[testdata_indx],
3933 (testdata_size - testdata_indx),
3934 in_sdu_total_size,
3935 in_sdu_packet_sn,
3936 in_sdu_timestamp,
3937 in_cntr_timestamp,
3938 in_ref_point,
3939 in_target_event,
3940 &tx_sdu_frag_buf.sdu_tx);
3941
3942 RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT();
3943 }
3944
3945 /**
3946 * Test Suite : TX framed SDU segmentation
3947 *
3948 * Tests segmentation of a single SDU contained in a single fragment
3949 * into a single PDU where Max PDU is less than the PDU buffer size
3950 */
ZTEST(test_tx_framed,test_tx_framed_1_sdu_1_frag_1_pdu_maxPDU)3951 ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_maxPDU)
3952 {
3953 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX - 5 -
3954 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)];
3955 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
3956 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
3957 struct isoal_pdu_buffer pdu_buffer;
3958 isoal_source_handle_t source_hdl;
3959 struct pdu_iso_sdu_sh seg_hdr[2];
3960 isoal_sdu_len_t sdu_total_size;
3961 isoal_pdu_len_t pdu_write_size;
3962 uint32_t stream_sync_delay;
3963 uint64_t sdu_packet_number;
3964 uint32_t group_sync_delay;
3965 uint8_t iso_interval_int;
3966 uint64_t payload_number;
3967 uint32_t sdu_timestamp;
3968 uint16_t testdata_indx;
3969 uint16_t testdata_size;
3970 uint16_t pdu_write_loc;
3971 uint16_t sdu_read_loc;
3972 uint64_t event_number;
3973 uint32_t sdu_interval;
3974 uint8_t sdu_fragments;
3975 uint16_t pdu_hdr_loc;
3976 uint32_t ref_point;
3977 isoal_status_t err;
3978 uint8_t max_octets;
3979 uint8_t role;
3980 uint8_t BN;
3981 uint8_t FT;
3982
3983 /* Settings */
3984 role = ISOAL_ROLE_PERIPHERAL;
3985 iso_interval_int = 1;
3986 sdu_interval = ISO_INT_UNIT_US + 50;
3987 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
3988 BN = 1;
3989 FT = 1;
3990 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
3991 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
3992
3993 /* SDU Frag 1 --------------------------------------------------------*/
3994 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
3995 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
3996 init_test_data_buffer(testdata,
3997 TEST_TX_PDU_PAYLOAD_MAX - 5 -
3998 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
3999 (void)memset(&seg_hdr, 0, sizeof(seg_hdr));
4000 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
4001 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
4002 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
4003 sdu_packet_number = 2000;
4004 event_number = 2000;
4005 sdu_timestamp = 9249;
4006 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
4007 sdu_total_size =
4008 TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4009 testdata_indx = 0;
4010 testdata_size =
4011 TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4012 payload_number = event_number * BN;
4013
4014 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
4015 role, /* Role */
4016 true, /* Framed */
4017 BN, /* BN */
4018 FT, /* FT */
4019 max_octets, /* max_octets */
4020 sdu_interval, /* SDU Interval */
4021 iso_interval_int, /* ISO Interval */
4022 stream_sync_delay, /* Stream Sync Delay */
4023 group_sync_delay); /* Group Sync Delay */
4024
4025 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
4026 &testdata[testdata_indx],
4027 (testdata_size - testdata_indx),
4028 sdu_total_size,
4029 sdu_packet_number,
4030 sdu_timestamp,
4031 sdu_timestamp,
4032 ref_point,
4033 event_number,
4034 &tx_sdu_frag_buf.sdu_tx);
4035
4036 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
4037 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
4038 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
4039 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
4040 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
4041
4042 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
4043
4044 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4045
4046 /* Test segmentation (Black Box) */
4047 /* Valid PDUs */
4048 /* PDU 1 */
4049 seg_hdr[0].sc = 0;
4050 seg_hdr[0].cmplt = 0;
4051 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
4052 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
4053 pdu_hdr_loc = 0;
4054 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
4055 sdu_read_loc = 0;
4056 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
4057 sdu_fragments = 1;
4058
4059 ZASSERT_PDU_WRITE_TEST(history[0],
4060 pdu_buffer,
4061 pdu_hdr_loc,
4062 &seg_hdr[0],
4063 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
4064
4065 ZASSERT_PDU_WRITE_TEST(history[1],
4066 pdu_buffer,
4067 pdu_write_loc,
4068 &testdata[sdu_read_loc],
4069 (pdu_write_size - pdu_write_loc));
4070
4071 seg_hdr[1] = seg_hdr[0];
4072 seg_hdr[1].cmplt = 1;
4073 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
4074
4075 ZASSERT_PDU_WRITE_TEST(history[2],
4076 pdu_buffer,
4077 pdu_hdr_loc,
4078 &seg_hdr[1],
4079 PDU_ISO_SEG_HDR_SIZE);
4080
4081 ZASSERT_PDU_EMIT_TEST(history[0],
4082 &tx_pdu_meta_buf.node_tx,
4083 payload_number,
4084 sdu_fragments,
4085 PDU_BIS_LLID_FRAMED,
4086 pdu_write_size,
4087 isoal_global.source_state[source_hdl].session.handle);
4088
4089 /* PDU release not expected (No Error) */
4090 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
4091
4092 /* Test PDU release */
4093 isoal_tx_pdu_release(source_hdl, &tx_pdu_meta_buf.node_tx);
4094
4095 ZASSERT_PDU_RELEASE_TEST(history[0],
4096 &tx_pdu_meta_buf.node_tx,
4097 isoal_global.source_state[source_hdl].session.handle,
4098 ISOAL_STATUS_OK);
4099 }
4100
4101 /**
4102 * Test Suite : TX framed SDU segmentation
4103 *
4104 * Tests segmentation of a single SDU contained in a single fragment
4105 * into a single PDU where Max PDU is greater than the PDU buffer size
4106 */
ZTEST(test_tx_framed,test_tx_framed_1_sdu_1_frag_1_pdu_bufSize)4107 ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_bufSize)
4108 {
4109 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX -
4110 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)];
4111 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
4112 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
4113 struct isoal_pdu_buffer pdu_buffer;
4114 isoal_source_handle_t source_hdl;
4115 struct pdu_iso_sdu_sh seg_hdr[2];
4116 isoal_sdu_len_t sdu_total_size;
4117 isoal_pdu_len_t pdu_write_size;
4118 uint32_t stream_sync_delay;
4119 uint64_t sdu_packet_number;
4120 uint32_t group_sync_delay;
4121 uint8_t iso_interval_int;
4122 uint64_t payload_number;
4123 uint32_t sdu_timestamp;
4124 uint16_t testdata_indx;
4125 uint16_t testdata_size;
4126 uint16_t pdu_write_loc;
4127 uint16_t sdu_read_loc;
4128 uint64_t event_number;
4129 uint32_t sdu_interval;
4130 uint8_t sdu_fragments;
4131 uint16_t pdu_hdr_loc;
4132 uint32_t ref_point;
4133 isoal_status_t err;
4134 uint8_t max_octets;
4135 uint8_t role;
4136 uint8_t BN;
4137 uint8_t FT;
4138
4139 /* Settings */
4140 role = ISOAL_ROLE_PERIPHERAL;
4141 iso_interval_int = 1;
4142 sdu_interval = ISO_INT_UNIT_US + 50;
4143 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
4144 BN = 1;
4145 FT = 1;
4146 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4147 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4148
4149 /* SDU Frag 1 --------------------------------------------------------*/
4150 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
4151 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
4152 init_test_data_buffer(testdata,
4153 TEST_TX_PDU_PAYLOAD_MAX -
4154 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
4155 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
4156 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
4157 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
4158 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
4159 sdu_packet_number = 2000;
4160 event_number = 2000;
4161 sdu_timestamp = 9249;
4162 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
4163 sdu_total_size =
4164 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4165 testdata_indx = 0;
4166 testdata_size =
4167 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4168 payload_number = event_number * BN;
4169
4170 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
4171 role, /* Role */
4172 true, /* Framed */
4173 BN, /* BN */
4174 FT, /* FT */
4175 max_octets, /* max_octets */
4176 sdu_interval, /* SDU Interval */
4177 iso_interval_int, /* ISO Interval */
4178 stream_sync_delay, /* Stream Sync Delay */
4179 group_sync_delay); /* Group Sync Delay */
4180
4181 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
4182 &testdata[testdata_indx],
4183 (testdata_size - testdata_indx),
4184 sdu_total_size,
4185 sdu_packet_number,
4186 sdu_timestamp,
4187 sdu_timestamp,
4188 ref_point,
4189 event_number,
4190 &tx_sdu_frag_buf.sdu_tx);
4191
4192 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
4193 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
4194 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
4195 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
4196 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
4197
4198 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
4199
4200 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4201
4202 /* Test segmentation (Black Box) */
4203 /* Valid PDUs */
4204 /* PDU 1 */
4205 seg_hdr[0].sc = 0;
4206 seg_hdr[0].cmplt = 0;
4207 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
4208 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
4209 pdu_hdr_loc = 0;
4210 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
4211 sdu_read_loc = 0;
4212 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
4213 sdu_fragments = 1;
4214
4215 ZASSERT_PDU_WRITE_TEST(history[0],
4216 pdu_buffer,
4217 pdu_hdr_loc,
4218 &seg_hdr[0],
4219 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
4220
4221 ZASSERT_PDU_WRITE_TEST(history[1],
4222 pdu_buffer,
4223 pdu_write_loc,
4224 &testdata[sdu_read_loc],
4225 (pdu_write_size - pdu_write_loc));
4226
4227 seg_hdr[1] = seg_hdr[0];
4228 seg_hdr[1].cmplt = 1;
4229 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
4230
4231 ZASSERT_PDU_WRITE_TEST(history[2],
4232 pdu_buffer,
4233 pdu_hdr_loc,
4234 &seg_hdr[1],
4235 PDU_ISO_SEG_HDR_SIZE);
4236
4237 ZASSERT_PDU_EMIT_TEST(history[0],
4238 &tx_pdu_meta_buf.node_tx,
4239 payload_number,
4240 sdu_fragments,
4241 PDU_BIS_LLID_FRAMED,
4242 pdu_write_size,
4243 isoal_global.source_state[source_hdl].session.handle);
4244
4245 /* PDU release not expected (No Error) */
4246 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
4247 }
4248
4249 /**
4250 * Test Suite : TX framed SDU segmentation
4251 *
4252 * Tests segmentation of a single SDU contained in a single fragment
4253 * into three PDUs where Max PDU is less than the PDU buffer size. Also tests
4254 * endianness of the segment header.
4255 */
ZTEST(test_tx_framed,test_tx_framed_1_sdu_1_frag_3_pdu)4256 ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu)
4257 {
4258 uint8_t testdata[100 - ((3 * PDU_ISO_SEG_HDR_SIZE) + PDU_ISO_SEG_TIMEOFFSET_SIZE)];
4259 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
4260 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
4261 struct isoal_pdu_buffer pdu_buffer;
4262 isoal_source_handle_t source_hdl;
4263 struct pdu_iso_sdu_sh seg_hdr[2 * 3];
4264 isoal_sdu_len_t sdu_total_size;
4265 isoal_pdu_len_t pdu_write_size;
4266 uint32_t stream_sync_delay;
4267 uint64_t sdu_packet_number;
4268 uint32_t group_sync_delay;
4269 uint8_t iso_interval_int;
4270 uint64_t payload_number;
4271 uint32_t sdu_timestamp;
4272 uint16_t testdata_indx;
4273 uint16_t testdata_size;
4274 uint16_t pdu_write_loc;
4275 uint16_t sdu_read_loc;
4276 uint64_t event_number;
4277 uint32_t sdu_interval;
4278 uint8_t sdu_fragments;
4279 uint16_t pdu_hdr_loc;
4280 uint32_t ref_point;
4281 isoal_status_t err;
4282 uint8_t max_octets;
4283 uint8_t role;
4284 uint8_t BN;
4285 uint8_t FT;
4286
4287 /* Settings */
4288 role = ISOAL_ROLE_PERIPHERAL;
4289 iso_interval_int = 1;
4290 sdu_interval = ISO_INT_UNIT_US + 50;
4291 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
4292 BN = 3;
4293 FT = 1;
4294 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4295 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4296
4297 /* SDU Frag 1 --------------------------------------------------------*/
4298 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
4299 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
4300 init_test_data_buffer(testdata,
4301 100 - ((3 * PDU_ISO_SEG_HDR_SIZE) + PDU_ISO_SEG_TIMEOFFSET_SIZE));
4302 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
4303 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
4304 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
4305 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
4306 sdu_packet_number = 2000;
4307 event_number = 2000;
4308 sdu_timestamp = 9249;
4309 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
4310 sdu_total_size = 100 - ((3 * PDU_ISO_SEG_HDR_SIZE) + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4311 testdata_indx = 0;
4312 testdata_size = 100 - ((3 * PDU_ISO_SEG_HDR_SIZE) + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4313 payload_number = event_number * BN;
4314
4315 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
4316 role, /* Role */
4317 true, /* Framed */
4318 BN, /* BN */
4319 FT, /* FT */
4320 max_octets, /* max_octets */
4321 sdu_interval, /* SDU Interval */
4322 iso_interval_int, /* ISO Interval */
4323 stream_sync_delay, /* Stream Sync Delay */
4324 group_sync_delay); /* Group Sync Delay */
4325
4326 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
4327 &testdata[testdata_indx],
4328 (testdata_size - testdata_indx),
4329 sdu_total_size,
4330 sdu_packet_number,
4331 sdu_timestamp,
4332 sdu_timestamp,
4333 ref_point,
4334 event_number,
4335 &tx_sdu_frag_buf.sdu_tx);
4336
4337 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
4338 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
4339 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
4340 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
4341 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
4342 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
4343 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
4344
4345 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
4346
4347 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4348
4349 /* Test segmentation (Black Box) */
4350 /* Valid PDUs */
4351 /* PDU 1 */
4352 /* Test endianness */
4353 WRITE_BIT(((uint8_t *)&seg_hdr[0])[0], 0, 0); /* sc */
4354 WRITE_BIT(((uint8_t *)&seg_hdr[0])[0], 1, 0); /* cmplt */
4355 sys_put_le24(ref_point - sdu_timestamp, (uint8_t *)(&seg_hdr[0]) + PDU_ISO_SEG_HDR_SIZE);
4356 ((uint8_t *)(&seg_hdr[0]))[1] = PDU_ISO_SEG_TIMEOFFSET_SIZE; /* len */
4357 pdu_hdr_loc = 0;
4358 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
4359 sdu_read_loc = 0;
4360 pdu_write_size = max_octets;
4361 sdu_fragments = 0;
4362
4363 ZASSERT_PDU_WRITE_TEST(history[0],
4364 pdu_buffer,
4365 pdu_hdr_loc,
4366 &seg_hdr[0],
4367 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
4368
4369 ZASSERT_PDU_WRITE_TEST(history[1],
4370 pdu_buffer,
4371 pdu_write_loc,
4372 &testdata[sdu_read_loc],
4373 (pdu_write_size - pdu_write_loc));
4374
4375 seg_hdr[1] = seg_hdr[0];
4376 ((uint8_t *)(&seg_hdr[1]))[1] += (pdu_write_size - pdu_write_loc);
4377
4378 ZASSERT_PDU_WRITE_TEST(history[2],
4379 pdu_buffer,
4380 pdu_hdr_loc,
4381 &seg_hdr[1],
4382 PDU_ISO_SEG_HDR_SIZE);
4383
4384 ZASSERT_PDU_EMIT_TEST(history[0],
4385 &tx_pdu_meta_buf.node_tx,
4386 payload_number,
4387 sdu_fragments,
4388 PDU_BIS_LLID_FRAMED,
4389 pdu_write_size,
4390 isoal_global.source_state[source_hdl].session.handle);
4391
4392 /* PDU 2 */
4393 payload_number++;
4394 WRITE_BIT(((uint8_t *)&seg_hdr[2])[0], 0, 1); /* sc */
4395 WRITE_BIT(((uint8_t *)&seg_hdr[2])[0], 1, 0); /* cmplt */
4396 sys_put_le24(0, (uint8_t *)(&seg_hdr[2]) + PDU_ISO_SEG_HDR_SIZE);
4397 ((uint8_t *)(&seg_hdr[2]))[1] = 0; /* len */
4398 pdu_hdr_loc = 0;
4399 sdu_read_loc += (pdu_write_size - pdu_write_loc);
4400 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE;
4401 pdu_write_size = max_octets;
4402 sdu_fragments = 0;
4403
4404 ZASSERT_PDU_WRITE_TEST(history[3],
4405 pdu_buffer,
4406 pdu_hdr_loc,
4407 &seg_hdr[2],
4408 PDU_ISO_SEG_HDR_SIZE);
4409
4410 ZASSERT_PDU_WRITE_TEST(history[4],
4411 pdu_buffer,
4412 pdu_write_loc,
4413 &testdata[sdu_read_loc],
4414 (pdu_write_size - pdu_write_loc));
4415
4416 seg_hdr[3] = seg_hdr[2];
4417 ((uint8_t *)(&seg_hdr[3]))[1] += (pdu_write_size - pdu_write_loc); /* len */
4418
4419 ZASSERT_PDU_WRITE_TEST(history[5],
4420 pdu_buffer,
4421 pdu_hdr_loc,
4422 &seg_hdr[3],
4423 PDU_ISO_SEG_HDR_SIZE);
4424
4425 ZASSERT_PDU_EMIT_TEST(history[1],
4426 &tx_pdu_meta_buf.node_tx,
4427 payload_number,
4428 sdu_fragments,
4429 PDU_BIS_LLID_FRAMED,
4430 pdu_write_size,
4431 isoal_global.source_state[source_hdl].session.handle);
4432
4433 /* PDU 3 */
4434 payload_number++;
4435 WRITE_BIT(((uint8_t *)&seg_hdr[4])[0], 0, 1); /* sc */
4436 WRITE_BIT(((uint8_t *)&seg_hdr[4])[0], 1, 0); /* cmplt */
4437 sys_put_le24(0, (uint8_t *)(&seg_hdr[4]) + PDU_ISO_SEG_HDR_SIZE);
4438 ((uint8_t *)(&seg_hdr[4]))[1] = 0; /* len */
4439 pdu_hdr_loc = 0;
4440 sdu_read_loc += (pdu_write_size - pdu_write_loc);
4441 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE;
4442 pdu_write_size =
4443 sdu_total_size -
4444 ((2 * max_octets) - (2 * PDU_ISO_SEG_HDR_SIZE) - PDU_ISO_SEG_TIMEOFFSET_SIZE) +
4445 pdu_write_loc;
4446 sdu_fragments++;
4447
4448 ZASSERT_PDU_WRITE_TEST(history[6],
4449 pdu_buffer,
4450 pdu_hdr_loc,
4451 &seg_hdr[4],
4452 PDU_ISO_SEG_HDR_SIZE);
4453
4454 ZASSERT_PDU_WRITE_TEST(history[7],
4455 pdu_buffer,
4456 pdu_write_loc,
4457 &testdata[sdu_read_loc],
4458 (pdu_write_size - pdu_write_loc));
4459
4460 seg_hdr[5] = seg_hdr[4];
4461 WRITE_BIT(((uint8_t *)&seg_hdr[5])[0], 1, 1); /* cmplt */
4462 ((uint8_t *)(&seg_hdr[5]))[1] += (pdu_write_size - pdu_write_loc); /* len */
4463
4464 ZASSERT_PDU_WRITE_TEST(history[8],
4465 pdu_buffer,
4466 pdu_hdr_loc,
4467 &seg_hdr[5],
4468 PDU_ISO_SEG_HDR_SIZE);
4469
4470 ZASSERT_PDU_EMIT_TEST(history[2],
4471 &tx_pdu_meta_buf.node_tx,
4472 payload_number,
4473 sdu_fragments,
4474 PDU_BIS_LLID_FRAMED,
4475 pdu_write_size,
4476 isoal_global.source_state[source_hdl].session.handle);
4477
4478 /* PDU release not expected (No Error) */
4479 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
4480 }
4481
4482 /**
4483 * Test Suite : TX framed SDU segmentation
4484 *
4485 * Tests segmentation of a single SDU contained in three fragments
4486 * into a single PDU where Max PDU is greater than the PDU buffer size
4487 */
ZTEST(test_tx_framed,test_tx_framed_1_sdu_3_frag_1_pdu)4488 ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu)
4489 {
4490 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX -
4491 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)];
4492 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
4493 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
4494 struct isoal_pdu_buffer pdu_buffer;
4495 isoal_source_handle_t source_hdl;
4496 struct pdu_iso_sdu_sh seg_hdr[2];
4497 isoal_sdu_len_t sdu_total_size;
4498 isoal_pdu_len_t pdu_write_size;
4499 uint32_t stream_sync_delay;
4500 uint64_t sdu_packet_number;
4501 uint32_t group_sync_delay;
4502 uint8_t iso_interval_int;
4503 uint64_t payload_number;
4504 uint32_t sdu_timestamp;
4505 uint16_t testdata_indx;
4506 uint16_t testdata_size;
4507 uint16_t pdu_write_loc;
4508 uint16_t sdu_read_loc;
4509 uint64_t event_number;
4510 uint32_t sdu_interval;
4511 uint8_t sdu_fragments;
4512 uint16_t pdu_hdr_loc;
4513 uint32_t ref_point;
4514 isoal_status_t err;
4515 uint8_t max_octets;
4516 uint8_t role;
4517 uint8_t BN;
4518 uint8_t FT;
4519
4520 /* Settings */
4521 role = ISOAL_ROLE_PERIPHERAL;
4522 iso_interval_int = 1;
4523 sdu_interval = ISO_INT_UNIT_US + 50;
4524 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
4525 BN = 1;
4526 FT = 1;
4527 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4528 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4529
4530 /* SDU Frag 1 --------------------------------------------------------*/
4531 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
4532 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
4533 init_test_data_buffer(testdata,
4534 TEST_TX_PDU_PAYLOAD_MAX -
4535 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
4536 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
4537 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
4538 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
4539 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
4540 sdu_packet_number = 2000;
4541 event_number = 2000;
4542 sdu_timestamp = 9249;
4543 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
4544 sdu_total_size =
4545 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4546 testdata_indx = 0;
4547 testdata_size =
4548 (TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
4549 3;
4550 payload_number = event_number * BN;
4551 sdu_fragments = 0;
4552
4553 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
4554 role, /* Role */
4555 true, /* Framed */
4556 BN, /* BN */
4557 FT, /* FT */
4558 max_octets, /* max_octets */
4559 sdu_interval, /* SDU Interval */
4560 iso_interval_int, /* ISO Interval */
4561 stream_sync_delay, /* Stream Sync Delay */
4562 group_sync_delay); /* Group Sync Delay */
4563
4564 isoal_test_create_sdu_fagment(BT_ISO_START,
4565 &testdata[testdata_indx],
4566 (testdata_size - testdata_indx),
4567 sdu_total_size,
4568 sdu_packet_number,
4569 sdu_timestamp,
4570 sdu_timestamp,
4571 ref_point,
4572 event_number,
4573 &tx_sdu_frag_buf.sdu_tx);
4574
4575 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
4576 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
4577 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
4578 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
4579 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
4580
4581 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
4582
4583 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4584
4585 /* Test segmentation (Black Box) */
4586 /* Valid PDUs */
4587 /* PDU 1 */
4588 seg_hdr[0].sc = 0;
4589 seg_hdr[0].cmplt = 0;
4590 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
4591 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
4592 pdu_hdr_loc = 0;
4593 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
4594 sdu_read_loc = 0;
4595 pdu_write_size =
4596 ((TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
4597 3) +
4598 pdu_write_loc;
4599 sdu_fragments++;
4600
4601 ZASSERT_PDU_WRITE_TEST(history[0],
4602 pdu_buffer,
4603 pdu_hdr_loc,
4604 &seg_hdr[0],
4605 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
4606
4607 ZASSERT_PDU_WRITE_TEST(history[1],
4608 pdu_buffer,
4609 pdu_write_loc,
4610 &testdata[sdu_read_loc],
4611 (pdu_write_size - pdu_write_loc));
4612
4613 seg_hdr[1] = seg_hdr[0];
4614 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
4615
4616 ZASSERT_PDU_WRITE_TEST(history[2],
4617 pdu_buffer,
4618 pdu_hdr_loc,
4619 &seg_hdr[1],
4620 PDU_ISO_SEG_HDR_SIZE);
4621
4622 /* PDU should not be emitted */
4623 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
4624
4625 /* PDU release not expected (No Error) */
4626 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
4627
4628 /* SDU Frag 2 --------------------------------------------------------*/
4629 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
4630 sdu_timestamp += 10;
4631 testdata_indx += testdata_size;
4632 testdata_size +=
4633 (TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
4634 3;
4635
4636 isoal_test_create_sdu_fagment(BT_ISO_CONT,
4637 &testdata[testdata_indx],
4638 (testdata_size - testdata_indx),
4639 sdu_total_size,
4640 sdu_packet_number,
4641 sdu_timestamp,
4642 sdu_timestamp,
4643 ref_point,
4644 event_number,
4645 &tx_sdu_frag_buf.sdu_tx);
4646
4647 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
4648
4649 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4650
4651 /* Test segmentation (Black Box) */
4652 /* Valid PDUs */
4653 /* PDU 1 */
4654 pdu_write_loc = pdu_write_size;
4655 pdu_write_size +=
4656 ((TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
4657 3);
4658 sdu_read_loc = testdata_indx;
4659 sdu_fragments++;
4660
4661 /* PDU should not be allocated */
4662 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(1);
4663
4664 ZASSERT_PDU_WRITE_TEST(history[3],
4665 pdu_buffer,
4666 pdu_write_loc,
4667 &testdata[sdu_read_loc],
4668 (pdu_write_size - pdu_write_loc));
4669
4670 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
4671
4672 ZASSERT_PDU_WRITE_TEST(history[4],
4673 pdu_buffer,
4674 pdu_hdr_loc,
4675 &seg_hdr[1],
4676 PDU_ISO_SEG_HDR_SIZE);
4677
4678 /* PDU should not be emitted */
4679 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
4680
4681 /* PDU release not expected (No Error) */
4682 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
4683
4684 /* SDU Frag 3 --------------------------------------------------------*/
4685 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
4686 sdu_timestamp += 10;
4687 testdata_indx = testdata_size;
4688 testdata_size =
4689 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4690
4691 isoal_test_create_sdu_fagment(BT_ISO_END,
4692 &testdata[testdata_indx],
4693 (testdata_size - testdata_indx),
4694 sdu_total_size,
4695 sdu_packet_number,
4696 sdu_timestamp,
4697 sdu_timestamp,
4698 ref_point,
4699 event_number,
4700 &tx_sdu_frag_buf.sdu_tx);
4701
4702 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
4703
4704 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4705
4706 /* Test segmentation (Black Box) */
4707 /* Valid PDUs */
4708 /* PDU 1 */
4709 pdu_write_loc = pdu_write_size;
4710 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
4711 sdu_read_loc = testdata_indx;
4712 sdu_fragments++;
4713
4714 /* PDU should not be allocated */
4715 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(1);
4716
4717 ZASSERT_PDU_WRITE_TEST(history[5],
4718 pdu_buffer,
4719 pdu_write_loc,
4720 &testdata[sdu_read_loc],
4721 (pdu_write_size - pdu_write_loc));
4722
4723 seg_hdr[1].cmplt = 1;
4724 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
4725
4726 ZASSERT_PDU_WRITE_TEST(history[6],
4727 pdu_buffer,
4728 pdu_hdr_loc,
4729 &seg_hdr[1],
4730 PDU_ISO_SEG_HDR_SIZE);
4731
4732 ZASSERT_PDU_EMIT_TEST(history[0],
4733 &tx_pdu_meta_buf.node_tx,
4734 payload_number,
4735 sdu_fragments,
4736 PDU_BIS_LLID_FRAMED,
4737 pdu_write_size,
4738 isoal_global.source_state[source_hdl].session.handle);
4739
4740 /* PDU release not expected (No Error) */
4741 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
4742 }
4743
4744 /**
4745 * Test Suite : TX framed SDU segmentation
4746 *
4747 * Tests segmentation of a single SDU contained in three fragments
4748 * into two PDUs where Max PDU is greater than the PDU buffer size
4749 */
ZTEST(test_tx_framed,test_tx_framed_1_sdu_3_frag_2_pdu)4750 ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu)
4751 {
4752 uint8_t testdata[(TEST_TX_PDU_PAYLOAD_MAX * 2) -
4753 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)];
4754 struct tx_pdu_meta_buffer tx_pdu_meta_buf[2];
4755 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
4756 struct isoal_pdu_buffer pdu_buffer[2];
4757 struct pdu_iso_sdu_sh seg_hdr[2 * 2];
4758 isoal_source_handle_t source_hdl;
4759 isoal_sdu_len_t sdu_total_size;
4760 isoal_pdu_len_t pdu_write_size;
4761 uint32_t stream_sync_delay;
4762 uint64_t sdu_packet_number;
4763 uint32_t group_sync_delay;
4764 uint8_t iso_interval_int;
4765 uint64_t payload_number;
4766 uint32_t sdu_timestamp;
4767 uint16_t testdata_indx;
4768 uint16_t testdata_size;
4769 uint16_t pdu_write_loc;
4770 uint16_t sdu_read_loc;
4771 uint64_t event_number;
4772 uint32_t sdu_interval;
4773 uint8_t sdu_fragments;
4774 uint16_t pdu_hdr_loc;
4775 uint32_t ref_point;
4776 isoal_status_t err;
4777 uint8_t max_octets;
4778 uint8_t role;
4779 uint8_t BN;
4780 uint8_t FT;
4781
4782 /* Settings */
4783 role = ISOAL_ROLE_PERIPHERAL;
4784 iso_interval_int = 1;
4785 sdu_interval = ISO_INT_UNIT_US + 50;
4786 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
4787 BN = 2;
4788 FT = 1;
4789 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4790 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4791
4792 /* SDU Frag 1 --------------------------------------------------------*/
4793 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
4794 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
4795 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
4796 init_test_data_buffer(testdata,
4797 (TEST_TX_PDU_PAYLOAD_MAX * 2) -
4798 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE));
4799 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
4800 pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx;
4801 pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu;
4802 pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX;
4803 pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx;
4804 pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu;
4805 pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX;
4806 sdu_packet_number = 2000;
4807 event_number = 2000;
4808 sdu_timestamp = 9249;
4809 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
4810 sdu_total_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) -
4811 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4812 testdata_indx = 0;
4813 testdata_size = ((TEST_TX_PDU_PAYLOAD_MAX * 2) -
4814 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
4815 3;
4816 sdu_fragments = 0;
4817
4818 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
4819 role, /* Role */
4820 true, /* Framed */
4821 BN, /* BN */
4822 FT, /* FT */
4823 max_octets, /* max_octets */
4824 sdu_interval, /* SDU Interval */
4825 iso_interval_int, /* ISO Interval */
4826 stream_sync_delay, /* Stream Sync Delay */
4827 group_sync_delay); /* Group Sync Delay */
4828
4829 isoal_test_create_sdu_fagment(BT_ISO_START,
4830 &testdata[testdata_indx],
4831 (testdata_size - testdata_indx),
4832 sdu_total_size,
4833 sdu_packet_number,
4834 sdu_timestamp,
4835 sdu_timestamp,
4836 ref_point,
4837 event_number,
4838 &tx_sdu_frag_buf.sdu_tx);
4839
4840 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
4841 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
4842 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
4843 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
4844 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
4845 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
4846
4847 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
4848
4849 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4850
4851 /* Test segmentation (Black Box) */
4852 /* Valid PDUs */
4853 /* PDU 1 */
4854 payload_number = event_number * BN;
4855 seg_hdr[0].sc = 0;
4856 seg_hdr[0].cmplt = 0;
4857 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
4858 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
4859 pdu_hdr_loc = 0;
4860 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
4861 sdu_read_loc = 0;
4862 pdu_write_size = (((TEST_TX_PDU_PAYLOAD_MAX * 2) -
4863 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
4864 3) +
4865 pdu_write_loc;
4866 sdu_fragments++;
4867
4868 ZASSERT_PDU_WRITE_TEST(history[0],
4869 pdu_buffer[0],
4870 pdu_hdr_loc,
4871 &seg_hdr[0],
4872 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
4873
4874 ZASSERT_PDU_WRITE_TEST(history[1],
4875 pdu_buffer[0],
4876 pdu_write_loc,
4877 &testdata[sdu_read_loc],
4878 (pdu_write_size - pdu_write_loc));
4879
4880 seg_hdr[1] = seg_hdr[0];
4881 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
4882
4883 ZASSERT_PDU_WRITE_TEST(history[2],
4884 pdu_buffer[0],
4885 pdu_hdr_loc,
4886 &seg_hdr[1],
4887 PDU_ISO_SEG_HDR_SIZE);
4888
4889 /* PDU should not be emitted */
4890 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
4891
4892 /* PDU release not expected (No Error) */
4893 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
4894
4895 /* SDU Frag 2 --------------------------------------------------------*/
4896 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
4897 sdu_timestamp += 10;
4898 testdata_indx += testdata_size;
4899 testdata_size += ((TEST_TX_PDU_PAYLOAD_MAX * 2) -
4900 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
4901 3;
4902
4903 isoal_test_create_sdu_fagment(BT_ISO_CONT,
4904 &testdata[testdata_indx],
4905 (testdata_size - testdata_indx),
4906 sdu_total_size,
4907 sdu_packet_number,
4908 sdu_timestamp,
4909 sdu_timestamp,
4910 ref_point,
4911 event_number,
4912 &tx_sdu_frag_buf.sdu_tx);
4913
4914 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
4915
4916 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4917
4918 /* Test segmentation (Black Box) */
4919 /* Valid PDUs */
4920 /* PDU 1 */
4921 pdu_write_loc = pdu_write_size;
4922 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
4923 sdu_read_loc = testdata_indx;
4924
4925 /* PDU should not be allocated */
4926
4927 ZASSERT_PDU_WRITE_TEST(history[3],
4928 pdu_buffer[0],
4929 pdu_write_loc,
4930 &testdata[sdu_read_loc],
4931 (pdu_write_size - pdu_write_loc));
4932
4933 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
4934
4935 ZASSERT_PDU_WRITE_TEST(history[4],
4936 pdu_buffer[0],
4937 pdu_hdr_loc,
4938 &seg_hdr[1],
4939 PDU_ISO_SEG_HDR_SIZE);
4940
4941 ZASSERT_PDU_EMIT_TEST(history[0],
4942 &tx_pdu_meta_buf[0].node_tx,
4943 payload_number,
4944 sdu_fragments,
4945 PDU_BIS_LLID_FRAMED,
4946 pdu_write_size,
4947 isoal_global.source_state[source_hdl].session.handle);
4948
4949 /* PDU 2 */
4950 payload_number++;
4951 seg_hdr[2].sc = 1;
4952 seg_hdr[2].cmplt = 0;
4953 seg_hdr[2].timeoffset = 0;
4954 seg_hdr[2].len = 0;
4955 sdu_read_loc = (pdu_write_size - pdu_write_loc) + testdata_indx;
4956 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc) +
4957 PDU_ISO_SEG_HDR_SIZE;
4958 pdu_hdr_loc = 0;
4959 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE;
4960 sdu_fragments = 1;
4961
4962 ZASSERT_PDU_WRITE_TEST(history[5],
4963 pdu_buffer[1],
4964 pdu_hdr_loc,
4965 &seg_hdr[2],
4966 PDU_ISO_SEG_HDR_SIZE);
4967
4968 ZASSERT_PDU_WRITE_TEST(history[6],
4969 pdu_buffer[1],
4970 pdu_write_loc,
4971 &testdata[sdu_read_loc],
4972 (pdu_write_size - pdu_write_loc));
4973
4974 seg_hdr[3] = seg_hdr[2];
4975 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
4976
4977 ZASSERT_PDU_WRITE_TEST(history[7],
4978 pdu_buffer[1],
4979 pdu_hdr_loc,
4980 &seg_hdr[3],
4981 PDU_ISO_SEG_HDR_SIZE);
4982
4983 /* PDU should not be emitted */
4984 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1);
4985
4986 /* PDU release not expected (No Error) */
4987 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
4988
4989 /* SDU Frag 3 --------------------------------------------------------*/
4990 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
4991 sdu_timestamp += 10;
4992 testdata_indx = testdata_size;
4993 testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) -
4994 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE);
4995
4996 isoal_test_create_sdu_fagment(BT_ISO_END,
4997 &testdata[testdata_indx],
4998 (testdata_size - testdata_indx),
4999 sdu_total_size,
5000 sdu_packet_number,
5001 sdu_timestamp,
5002 sdu_timestamp,
5003 ref_point,
5004 event_number,
5005 &tx_sdu_frag_buf.sdu_tx);
5006
5007 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5008
5009 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5010
5011 /* Test segmentation (Black Box) */
5012 /* Valid PDUs */
5013 /* PDU 2 */
5014 pdu_write_loc = pdu_write_size;
5015 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
5016 sdu_read_loc = testdata_indx;
5017 sdu_fragments++;
5018
5019 /* PDU should not be allocated */
5020 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(2);
5021
5022 ZASSERT_PDU_WRITE_TEST(history[8],
5023 pdu_buffer[1],
5024 pdu_write_loc,
5025 &testdata[sdu_read_loc],
5026 (pdu_write_size - pdu_write_loc));
5027
5028 seg_hdr[3].cmplt = 1;
5029 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
5030
5031 ZASSERT_PDU_WRITE_TEST(history[9],
5032 pdu_buffer[1],
5033 pdu_hdr_loc,
5034 &seg_hdr[3],
5035 PDU_ISO_SEG_HDR_SIZE);
5036
5037 ZASSERT_PDU_EMIT_TEST(history[1],
5038 &tx_pdu_meta_buf[1].node_tx,
5039 payload_number,
5040 sdu_fragments,
5041 PDU_BIS_LLID_FRAMED,
5042 pdu_write_size,
5043 isoal_global.source_state[source_hdl].session.handle);
5044
5045 /* PDU release not expected (No Error) */
5046 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5047 }
5048
5049 /**
5050 * Test Suite : TX framed SDU segmentation
5051 *
5052 * Tests segmentation of two SDUs containing three fragments each
5053 * into two PDUs each where Max PDU is greater than the PDU buffer size
5054 */
ZTEST(test_tx_framed,test_tx_framed_2_sdu_3_frag_4_pdu)5055 ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu)
5056 {
5057 uint8_t testdata[(TEST_TX_PDU_PAYLOAD_MAX * 2) -
5058 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)];
5059 struct tx_pdu_meta_buffer tx_pdu_meta_buf[2];
5060 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
5061 struct isoal_pdu_buffer pdu_buffer[2];
5062 struct pdu_iso_sdu_sh seg_hdr[2 * 2];
5063 isoal_source_handle_t source_hdl;
5064 isoal_sdu_len_t sdu_total_size;
5065 isoal_pdu_len_t pdu_write_size;
5066 uint32_t stream_sync_delay;
5067 uint64_t sdu_packet_number;
5068 uint32_t group_sync_delay;
5069 uint8_t iso_interval_int;
5070 uint64_t payload_number;
5071 uint32_t sdu_timestamp;
5072 uint16_t testdata_indx;
5073 uint16_t testdata_size;
5074 uint16_t pdu_write_loc;
5075 uint16_t sdu_read_loc;
5076 uint64_t event_number;
5077 uint32_t sdu_interval;
5078 uint8_t sdu_fragments;
5079 uint16_t pdu_hdr_loc;
5080 uint32_t ref_point;
5081 isoal_status_t err;
5082 uint8_t max_octets;
5083 uint8_t role;
5084 uint8_t BN;
5085 uint8_t FT;
5086
5087 /* Settings */
5088 role = ISOAL_ROLE_PERIPHERAL;
5089 iso_interval_int = 2;
5090 sdu_interval = ISO_INT_UNIT_US + 50;
5091 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
5092 BN = 4;
5093 FT = 1;
5094 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
5095 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
5096
5097 /* SDU 1 Frag 1 ------------------------------------------------------*/
5098 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
5099 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
5100 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5101 init_test_data_buffer(testdata,
5102 (TEST_TX_PDU_PAYLOAD_MAX * 2) -
5103 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE));
5104 (void)memset(&seg_hdr, 0, sizeof(seg_hdr));
5105 pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx;
5106 pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu;
5107 pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX;
5108 pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx;
5109 pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu;
5110 pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX;
5111 sdu_packet_number = 2000;
5112 event_number = 2000;
5113 sdu_timestamp = 9249;
5114 ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50;
5115 sdu_total_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) -
5116 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE);
5117 testdata_indx = 0;
5118 testdata_size = ((TEST_TX_PDU_PAYLOAD_MAX * 2) -
5119 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
5120 3;
5121 sdu_fragments = 0;
5122
5123 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
5124 role, /* Role */
5125 true, /* Framed */
5126 BN, /* BN */
5127 FT, /* FT */
5128 max_octets, /* max_octets */
5129 sdu_interval, /* SDU Interval */
5130 iso_interval_int, /* ISO Interval */
5131 stream_sync_delay, /* Stream Sync Delay */
5132 group_sync_delay); /* Group Sync Delay */
5133
5134 isoal_test_create_sdu_fagment(BT_ISO_START,
5135 &testdata[testdata_indx],
5136 (testdata_size - testdata_indx),
5137 sdu_total_size,
5138 sdu_packet_number,
5139 sdu_timestamp,
5140 sdu_timestamp,
5141 ref_point,
5142 event_number,
5143 &tx_sdu_frag_buf.sdu_tx);
5144
5145 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
5146 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
5147 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
5148 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
5149 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
5150 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
5151 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
5152 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
5153
5154 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5155
5156 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5157
5158 /* Test segmentation (Black Box) */
5159 /* Valid PDUs */
5160 /* PDU 1 */
5161 payload_number = event_number * BN;
5162 seg_hdr[0].sc = 0;
5163 seg_hdr[0].cmplt = 0;
5164 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
5165 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
5166 pdu_hdr_loc = 0;
5167 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
5168 sdu_read_loc = 0;
5169 pdu_write_size = (((TEST_TX_PDU_PAYLOAD_MAX * 2) -
5170 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
5171 3) +
5172 pdu_write_loc;
5173 sdu_fragments++;
5174
5175 ZASSERT_PDU_WRITE_TEST(history[0],
5176 pdu_buffer[0],
5177 pdu_hdr_loc,
5178 &seg_hdr[0],
5179 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
5180
5181 ZASSERT_PDU_WRITE_TEST(history[1],
5182 pdu_buffer[0],
5183 pdu_write_loc,
5184 &testdata[sdu_read_loc],
5185 (pdu_write_size - pdu_write_loc));
5186
5187 seg_hdr[1] = seg_hdr[0];
5188 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
5189
5190 ZASSERT_PDU_WRITE_TEST(history[2],
5191 pdu_buffer[0],
5192 pdu_hdr_loc,
5193 &seg_hdr[1],
5194 PDU_ISO_SEG_HDR_SIZE);
5195
5196 /* PDU should not be emitted */
5197 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
5198
5199 /* PDU release not expected (No Error) */
5200 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5201
5202 /* SDU 1 Frag 2 ------------------------------------------------------*/
5203 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5204 sdu_timestamp += 10;
5205 testdata_indx += testdata_size;
5206 testdata_size += ((TEST_TX_PDU_PAYLOAD_MAX * 2) -
5207 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
5208 3;
5209
5210 isoal_test_create_sdu_fagment(BT_ISO_CONT,
5211 &testdata[testdata_indx],
5212 (testdata_size - testdata_indx),
5213 sdu_total_size,
5214 sdu_packet_number,
5215 sdu_timestamp,
5216 sdu_timestamp,
5217 ref_point,
5218 event_number,
5219 &tx_sdu_frag_buf.sdu_tx);
5220
5221 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5222
5223 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5224
5225 /* Test segmentation (Black Box) */
5226 /* Valid PDUs */
5227 /* PDU 1 */
5228 pdu_write_loc = pdu_write_size;
5229 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
5230 sdu_read_loc = testdata_indx;
5231
5232 ZASSERT_PDU_WRITE_TEST(history[3],
5233 pdu_buffer[0],
5234 pdu_write_loc,
5235 &testdata[sdu_read_loc],
5236 (pdu_write_size - pdu_write_loc));
5237
5238 /* PDU should not be allocated */
5239
5240 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
5241
5242 ZASSERT_PDU_WRITE_TEST(history[4],
5243 pdu_buffer[0],
5244 pdu_hdr_loc,
5245 &seg_hdr[1],
5246 PDU_ISO_SEG_HDR_SIZE);
5247
5248 ZASSERT_PDU_EMIT_TEST(history[0],
5249 &tx_pdu_meta_buf[0].node_tx,
5250 payload_number,
5251 sdu_fragments,
5252 PDU_BIS_LLID_FRAMED,
5253 pdu_write_size,
5254 isoal_global.source_state[source_hdl].session.handle);
5255
5256 /* PDU 2 */
5257 payload_number++;
5258 seg_hdr[2].sc = 1;
5259 seg_hdr[2].cmplt = 0;
5260 seg_hdr[2].timeoffset = 0;
5261 seg_hdr[2].len = 0;
5262 sdu_read_loc = (pdu_write_size - pdu_write_loc) + testdata_indx;
5263 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc) +
5264 PDU_ISO_SEG_HDR_SIZE;
5265 pdu_hdr_loc = 0;
5266 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE;
5267 sdu_fragments = 1;
5268
5269 ZASSERT_PDU_WRITE_TEST(history[5],
5270 pdu_buffer[1],
5271 pdu_hdr_loc,
5272 &seg_hdr[2],
5273 PDU_ISO_SEG_HDR_SIZE);
5274
5275 ZASSERT_PDU_WRITE_TEST(history[6],
5276 pdu_buffer[1],
5277 pdu_write_loc,
5278 &testdata[sdu_read_loc],
5279 (pdu_write_size - pdu_write_loc));
5280
5281 seg_hdr[3] = seg_hdr[2];
5282 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
5283
5284 ZASSERT_PDU_WRITE_TEST(history[7],
5285 pdu_buffer[1],
5286 pdu_hdr_loc,
5287 &seg_hdr[3],
5288 PDU_ISO_SEG_HDR_SIZE);
5289
5290 /* PDU should not be emitted */
5291 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1);
5292
5293 /* PDU release not expected (No Error) */
5294 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5295
5296 /* SDU 1 Frag 3 ------------------------------------------------------*/
5297 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5298 sdu_timestamp += 10;
5299 testdata_indx = testdata_size;
5300 testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) -
5301 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE);
5302
5303 isoal_test_create_sdu_fagment(BT_ISO_END,
5304 &testdata[testdata_indx],
5305 (testdata_size - testdata_indx),
5306 sdu_total_size,
5307 sdu_packet_number,
5308 sdu_timestamp,
5309 sdu_timestamp,
5310 ref_point,
5311 event_number,
5312 &tx_sdu_frag_buf.sdu_tx);
5313
5314 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5315
5316 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5317
5318 /* Test segmentation (Black Box) */
5319 /* Valid PDUs */
5320 /* PDU 2 */
5321 pdu_write_loc = pdu_write_size;
5322 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
5323 sdu_read_loc = testdata_indx;
5324 sdu_fragments++;
5325
5326 /* PDU should not be allocated */
5327
5328 ZASSERT_PDU_WRITE_TEST(history[8],
5329 pdu_buffer[1],
5330 pdu_write_loc,
5331 &testdata[sdu_read_loc],
5332 (pdu_write_size - pdu_write_loc));
5333
5334 seg_hdr[3].cmplt = 1;
5335 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
5336
5337 ZASSERT_PDU_WRITE_TEST(history[9],
5338 pdu_buffer[1],
5339 pdu_hdr_loc,
5340 &seg_hdr[3],
5341 PDU_ISO_SEG_HDR_SIZE);
5342
5343 ZASSERT_PDU_EMIT_TEST(history[1],
5344 &tx_pdu_meta_buf[1].node_tx,
5345 payload_number,
5346 sdu_fragments,
5347 PDU_BIS_LLID_FRAMED,
5348 pdu_write_size,
5349 isoal_global.source_state[source_hdl].session.handle);
5350
5351 /* PDU release not expected (No Error) */
5352 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5353
5354 /* SDU 2 Frag 1 ------------------------------------------------------*/
5355 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
5356 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
5357 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5358 sdu_packet_number++;
5359 event_number = 2000;
5360 sdu_timestamp = 9249 + sdu_interval;
5361 ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50;
5362 sdu_total_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) -
5363 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE);
5364 testdata_indx = 0;
5365 testdata_size = ((TEST_TX_PDU_PAYLOAD_MAX * 2) -
5366 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
5367 3;
5368 sdu_fragments = 0;
5369
5370 isoal_test_create_sdu_fagment(BT_ISO_START,
5371 &testdata[testdata_indx],
5372 (testdata_size - testdata_indx),
5373 sdu_total_size,
5374 sdu_packet_number,
5375 sdu_timestamp,
5376 sdu_timestamp,
5377 ref_point,
5378 event_number,
5379 &tx_sdu_frag_buf.sdu_tx);
5380
5381 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5382
5383 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5384
5385 /* Test segmentation (Black Box) */
5386 /* Valid PDUs */
5387 /* PDU 3 */
5388 payload_number++;
5389 seg_hdr[0].sc = 0;
5390 seg_hdr[0].cmplt = 0;
5391 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
5392 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
5393 pdu_hdr_loc = 0;
5394 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
5395 sdu_read_loc = 0;
5396 pdu_write_size = (((TEST_TX_PDU_PAYLOAD_MAX * 2) -
5397 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
5398 3) +
5399 pdu_write_loc;
5400 sdu_fragments++;
5401
5402 ZASSERT_PDU_WRITE_TEST(history[10],
5403 pdu_buffer[0],
5404 pdu_hdr_loc,
5405 &seg_hdr[0],
5406 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
5407
5408 ZASSERT_PDU_WRITE_TEST(history[11],
5409 pdu_buffer[0],
5410 pdu_write_loc,
5411 &testdata[sdu_read_loc],
5412 (pdu_write_size - pdu_write_loc));
5413
5414 seg_hdr[1] = seg_hdr[0];
5415 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
5416
5417 ZASSERT_PDU_WRITE_TEST(history[12],
5418 pdu_buffer[0],
5419 pdu_hdr_loc,
5420 &seg_hdr[1],
5421 PDU_ISO_SEG_HDR_SIZE);
5422
5423 /* PDU should not be emitted */
5424 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2);
5425
5426 /* PDU release not expected (No Error) */
5427 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5428
5429 /* SDU 2 Frag 2 ------------------------------------------------------*/
5430 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5431 sdu_timestamp += 10;
5432 testdata_indx += testdata_size;
5433 testdata_size += ((TEST_TX_PDU_PAYLOAD_MAX * 2) -
5434 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE)) /
5435 3;
5436
5437 isoal_test_create_sdu_fagment(BT_ISO_CONT,
5438 &testdata[testdata_indx],
5439 (testdata_size - testdata_indx),
5440 sdu_total_size,
5441 sdu_packet_number,
5442 sdu_timestamp,
5443 sdu_timestamp,
5444 ref_point,
5445 event_number,
5446 &tx_sdu_frag_buf.sdu_tx);
5447
5448 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5449
5450 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5451
5452 /* Test segmentation (Black Box) */
5453 /* Valid PDUs */
5454 /* PDU 3 */
5455 pdu_write_loc = pdu_write_size;
5456 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
5457 sdu_read_loc = testdata_indx;
5458
5459 /* PDU should not be allocated */
5460
5461 ZASSERT_PDU_WRITE_TEST(history[13],
5462 pdu_buffer[0],
5463 pdu_write_loc,
5464 &testdata[sdu_read_loc],
5465 (pdu_write_size - pdu_write_loc));
5466
5467 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
5468
5469 ZASSERT_PDU_WRITE_TEST(history[14],
5470 pdu_buffer[0],
5471 pdu_hdr_loc,
5472 &seg_hdr[1],
5473 PDU_ISO_SEG_HDR_SIZE);
5474
5475 ZASSERT_PDU_EMIT_TEST(history[2],
5476 &tx_pdu_meta_buf[0].node_tx,
5477 payload_number,
5478 sdu_fragments,
5479 PDU_BIS_LLID_FRAMED,
5480 pdu_write_size,
5481 isoal_global.source_state[source_hdl].session.handle);
5482
5483 /* PDU 4 */
5484 payload_number++;
5485 seg_hdr[2].sc = 1;
5486 seg_hdr[2].cmplt = 0;
5487 seg_hdr[2].timeoffset = 0;
5488 seg_hdr[2].len = 0;
5489 sdu_read_loc = (pdu_write_size - pdu_write_loc) + testdata_indx;
5490 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc) +
5491 PDU_ISO_SEG_HDR_SIZE;
5492 pdu_hdr_loc = 0;
5493 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE;
5494 sdu_fragments = 1;
5495
5496 ZASSERT_PDU_WRITE_TEST(history[15],
5497 pdu_buffer[1],
5498 pdu_hdr_loc,
5499 &seg_hdr[2],
5500 PDU_ISO_SEG_HDR_SIZE);
5501
5502 ZASSERT_PDU_WRITE_TEST(history[16],
5503 pdu_buffer[1],
5504 pdu_write_loc,
5505 &testdata[sdu_read_loc],
5506 (pdu_write_size - pdu_write_loc));
5507
5508 seg_hdr[3] = seg_hdr[2];
5509 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
5510
5511 ZASSERT_PDU_WRITE_TEST(history[17],
5512 pdu_buffer[1],
5513 pdu_hdr_loc,
5514 &seg_hdr[3],
5515 PDU_ISO_SEG_HDR_SIZE);
5516 /* PDU should not be emitted */
5517 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(3);
5518
5519 /* PDU release not expected (No Error) */
5520 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5521
5522 /* SDU 2 Frag 3 ------------------------------------------------------*/
5523 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5524 sdu_timestamp += 10;
5525 testdata_indx = testdata_size;
5526 testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) -
5527 ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE);
5528
5529 isoal_test_create_sdu_fagment(BT_ISO_END,
5530 &testdata[testdata_indx],
5531 (testdata_size - testdata_indx),
5532 sdu_total_size,
5533 sdu_packet_number,
5534 sdu_timestamp,
5535 sdu_timestamp,
5536 ref_point,
5537 event_number,
5538 &tx_sdu_frag_buf.sdu_tx);
5539
5540 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5541
5542 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5543
5544 /* Test segmentation (Black Box) */
5545 /* Valid PDUs */
5546 /* PDU 4 */
5547 pdu_write_loc = pdu_write_size;
5548 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
5549 sdu_read_loc = testdata_indx;
5550 sdu_fragments++;
5551
5552 /* PDU should not be allocated */
5553 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(4);
5554
5555 ZASSERT_PDU_WRITE_TEST(history[18],
5556 pdu_buffer[1],
5557 pdu_write_loc,
5558 &testdata[sdu_read_loc],
5559 (pdu_write_size - pdu_write_loc));
5560
5561 seg_hdr[3].cmplt = 1;
5562 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
5563
5564 ZASSERT_PDU_WRITE_TEST(history[19],
5565 pdu_buffer[1],
5566 pdu_hdr_loc,
5567 &seg_hdr[3],
5568 PDU_ISO_SEG_HDR_SIZE);
5569
5570 ZASSERT_PDU_EMIT_TEST(history[3],
5571 &tx_pdu_meta_buf[1].node_tx,
5572 payload_number,
5573 sdu_fragments,
5574 PDU_BIS_LLID_FRAMED,
5575 pdu_write_size,
5576 isoal_global.source_state[source_hdl].session.handle);
5577
5578 /* PDU release not expected (No Error) */
5579 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5580 }
5581
5582 /**
5583 * Test Suite : TX framed SDU segmentation
5584 *
5585 * Tests segmentation of two SDUs containing three fragments each
5586 * into two PDUs each where Max PDU is greater than the PDU buffer size
5587 * with padding
5588 */
ZTEST(test_tx_framed,test_tx_framed_2_sdu_3_frag_4_pdu_padding)5589 ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding)
5590 {
5591 const uint8_t number_of_pdus = 2;
5592 const uint8_t number_of_sdu_frags = 3;
5593 const uint8_t testdata_size_max = MAX_FRAMED_PDU_PAYLOAD(number_of_pdus);
5594 const uint8_t number_of_seg_hdr_buf = EXPECTED_SEG_HDR_WRITES * number_of_pdus;
5595
5596 struct tx_pdu_meta_buffer tx_pdu_meta_buf[number_of_pdus];
5597 struct pdu_iso_sdu_sh seg_hdr[number_of_seg_hdr_buf];
5598 struct isoal_pdu_buffer pdu_buffer[number_of_pdus];
5599 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
5600 uint8_t testdata[testdata_size_max];
5601 isoal_source_handle_t source_hdl;
5602 isoal_sdu_len_t sdu_total_size;
5603 isoal_pdu_len_t pdu_write_size;
5604 uint32_t stream_sync_delay;
5605 uint64_t sdu_packet_number;
5606 uint32_t group_sync_delay;
5607 uint8_t iso_interval_int;
5608 uint64_t payload_number;
5609 uint32_t sdu_timestamp;
5610 uint16_t testdata_indx;
5611 uint16_t testdata_size;
5612 uint16_t pdu_write_loc;
5613 uint16_t sdu_read_loc;
5614 uint64_t event_number;
5615 uint32_t sdu_interval;
5616 uint8_t sdu_fragments;
5617 uint16_t pdu_hdr_loc;
5618 uint32_t ref_point;
5619 isoal_status_t err;
5620 uint8_t max_octets;
5621 uint8_t role;
5622 uint8_t BN;
5623 uint8_t FT;
5624
5625 /* Settings */
5626 role = ISOAL_ROLE_PERIPHERAL;
5627 iso_interval_int = 2;
5628 sdu_interval = ISO_INT_UNIT_US + 50;
5629 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
5630 BN = 6;
5631 FT = 1;
5632 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
5633 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
5634
5635 /* SDU 1 Frag 1 ------------------------------------------------------*/
5636 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
5637 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
5638 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5639 init_test_data_buffer(testdata, testdata_size_max);
5640 (void)memset(&seg_hdr, 0, sizeof(seg_hdr));
5641 pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx;
5642 pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu;
5643 pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX;
5644 pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx;
5645 pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu;
5646 pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX;
5647 sdu_packet_number = 2000;
5648 event_number = 2000;
5649 sdu_timestamp = 9249;
5650 ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50;
5651 sdu_total_size = testdata_size_max;
5652 testdata_indx = 0;
5653 testdata_size = testdata_size_max / number_of_sdu_frags;
5654 sdu_fragments = 0;
5655
5656 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
5657 role, /* Role */
5658 true, /* Framed */
5659 BN, /* BN */
5660 FT, /* FT */
5661 max_octets, /* max_octets */
5662 sdu_interval, /* SDU Interval */
5663 iso_interval_int, /* ISO Interval */
5664 stream_sync_delay, /* Stream Sync Delay */
5665 group_sync_delay); /* Group Sync Delay */
5666
5667 isoal_test_create_sdu_fagment(BT_ISO_START,
5668 &testdata[testdata_indx],
5669 (testdata_size - testdata_indx),
5670 sdu_total_size,
5671 sdu_packet_number,
5672 sdu_timestamp,
5673 sdu_timestamp,
5674 ref_point,
5675 event_number,
5676 &tx_sdu_frag_buf.sdu_tx);
5677
5678 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
5679 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
5680 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
5681 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
5682 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
5683 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
5684 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
5685 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
5686 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
5687 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
5688
5689 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5690
5691 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5692
5693 /* Test segmentation (Black Box) */
5694 /* Valid PDUs */
5695 /* PDU 1 */
5696 payload_number = event_number * BN;
5697 seg_hdr[0].sc = 0;
5698 seg_hdr[0].cmplt = 0;
5699 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
5700 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
5701 pdu_hdr_loc = 0;
5702 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
5703 sdu_read_loc = 0;
5704 pdu_write_size = (testdata_size_max / number_of_sdu_frags) + pdu_write_loc;
5705 sdu_fragments++;
5706
5707 ZASSERT_PDU_WRITE_TEST(history[0],
5708 pdu_buffer[0],
5709 pdu_hdr_loc,
5710 &seg_hdr[0],
5711 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
5712
5713 ZASSERT_PDU_WRITE_TEST(history[1],
5714 pdu_buffer[0],
5715 pdu_write_loc,
5716 &testdata[sdu_read_loc],
5717 (pdu_write_size - pdu_write_loc));
5718
5719 seg_hdr[1] = seg_hdr[0];
5720 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
5721
5722 ZASSERT_PDU_WRITE_TEST(history[2],
5723 pdu_buffer[0],
5724 pdu_hdr_loc,
5725 &seg_hdr[1],
5726 PDU_ISO_SEG_HDR_SIZE);
5727
5728 /* PDU should not be emitted */
5729 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
5730
5731 /* PDU release not expected (No Error) */
5732 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5733
5734 /* SDU 1 Frag 2 ------------------------------------------------------*/
5735 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5736 sdu_timestamp += 10;
5737 testdata_indx += testdata_size;
5738 testdata_size += testdata_size_max / number_of_sdu_frags;
5739
5740 isoal_test_create_sdu_fagment(BT_ISO_CONT,
5741 &testdata[testdata_indx],
5742 (testdata_size - testdata_indx),
5743 sdu_total_size,
5744 sdu_packet_number,
5745 sdu_timestamp,
5746 sdu_timestamp,
5747 ref_point,
5748 event_number,
5749 &tx_sdu_frag_buf.sdu_tx);
5750
5751 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5752
5753 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5754
5755 /* Test segmentation (Black Box) */
5756 /* Valid PDUs */
5757 /* PDU 1 */
5758 pdu_write_loc = pdu_write_size;
5759 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
5760 sdu_read_loc = testdata_indx;
5761
5762 ZASSERT_PDU_WRITE_TEST(history[3],
5763 pdu_buffer[0],
5764 pdu_write_loc,
5765 &testdata[sdu_read_loc],
5766 (pdu_write_size - pdu_write_loc));
5767
5768 /* PDU should not be allocated */
5769
5770 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
5771
5772 ZASSERT_PDU_WRITE_TEST(history[4],
5773 pdu_buffer[0],
5774 pdu_hdr_loc,
5775 &seg_hdr[1],
5776 PDU_ISO_SEG_HDR_SIZE);
5777
5778 ZASSERT_PDU_EMIT_TEST(history[0],
5779 &tx_pdu_meta_buf[0].node_tx,
5780 payload_number,
5781 sdu_fragments,
5782 PDU_BIS_LLID_FRAMED,
5783 pdu_write_size,
5784 isoal_global.source_state[source_hdl].session.handle);
5785
5786 /* PDU 2 */
5787 payload_number++;
5788 seg_hdr[2].sc = 1;
5789 seg_hdr[2].cmplt = 0;
5790 seg_hdr[2].timeoffset = 0;
5791 seg_hdr[2].len = 0;
5792 sdu_read_loc = (pdu_write_size - pdu_write_loc) + testdata_indx;
5793 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc) +
5794 PDU_ISO_SEG_HDR_SIZE;
5795 pdu_hdr_loc = 0;
5796 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE;
5797 sdu_fragments = 1;
5798
5799 ZASSERT_PDU_WRITE_TEST(history[5],
5800 pdu_buffer[1],
5801 pdu_hdr_loc,
5802 &seg_hdr[2],
5803 PDU_ISO_SEG_HDR_SIZE);
5804
5805 ZASSERT_PDU_WRITE_TEST(history[6],
5806 pdu_buffer[1],
5807 pdu_write_loc,
5808 &testdata[sdu_read_loc],
5809 (pdu_write_size - pdu_write_loc));
5810
5811 seg_hdr[3] = seg_hdr[2];
5812 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
5813
5814 ZASSERT_PDU_WRITE_TEST(history[7],
5815 pdu_buffer[1],
5816 pdu_hdr_loc,
5817 &seg_hdr[3],
5818 PDU_ISO_SEG_HDR_SIZE);
5819
5820 /* PDU should not be emitted */
5821 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1);
5822
5823 /* PDU release not expected (No Error) */
5824 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5825
5826 /* SDU 1 Frag 3 ------------------------------------------------------*/
5827 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5828 sdu_timestamp += 10;
5829 testdata_indx = testdata_size;
5830 testdata_size = testdata_size_max;
5831
5832 isoal_test_create_sdu_fagment(BT_ISO_END,
5833 &testdata[testdata_indx],
5834 (testdata_size - testdata_indx),
5835 sdu_total_size,
5836 sdu_packet_number,
5837 sdu_timestamp,
5838 sdu_timestamp,
5839 ref_point,
5840 event_number,
5841 &tx_sdu_frag_buf.sdu_tx);
5842
5843 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5844
5845 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5846
5847 /* Test segmentation (Black Box) */
5848 /* Valid PDUs */
5849 /* PDU 2 */
5850 pdu_write_loc = pdu_write_size;
5851 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
5852 sdu_read_loc = testdata_indx;
5853 sdu_fragments++;
5854
5855 /* PDU should not be allocated */
5856
5857 ZASSERT_PDU_WRITE_TEST(history[8],
5858 pdu_buffer[1],
5859 pdu_write_loc,
5860 &testdata[sdu_read_loc],
5861 (pdu_write_size - pdu_write_loc));
5862
5863 seg_hdr[3].cmplt = 1;
5864 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
5865
5866 ZASSERT_PDU_WRITE_TEST(history[9],
5867 pdu_buffer[1],
5868 pdu_hdr_loc,
5869 &seg_hdr[3],
5870 PDU_ISO_SEG_HDR_SIZE);
5871
5872 ZASSERT_PDU_EMIT_TEST(history[1],
5873 &tx_pdu_meta_buf[1].node_tx,
5874 payload_number,
5875 sdu_fragments,
5876 PDU_BIS_LLID_FRAMED,
5877 pdu_write_size,
5878 isoal_global.source_state[source_hdl].session.handle);
5879
5880 /* PDU release not expected (No Error) */
5881 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5882
5883 /* SDU 2 Frag 1 ------------------------------------------------------*/
5884 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
5885 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
5886 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5887 sdu_packet_number++;
5888 event_number = 2000;
5889 sdu_timestamp = 9249 + sdu_interval;
5890 ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50;
5891 sdu_total_size = testdata_size_max;
5892 testdata_indx = 0;
5893 testdata_size = testdata_size_max / number_of_sdu_frags;
5894 sdu_fragments = 0;
5895
5896 isoal_test_create_sdu_fagment(BT_ISO_START,
5897 &testdata[testdata_indx],
5898 (testdata_size - testdata_indx),
5899 sdu_total_size,
5900 sdu_packet_number,
5901 sdu_timestamp,
5902 sdu_timestamp,
5903 ref_point,
5904 event_number,
5905 &tx_sdu_frag_buf.sdu_tx);
5906
5907 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5908
5909 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5910
5911 /* Test segmentation (Black Box) */
5912 /* Valid PDUs */
5913 /* PDU 3 */
5914 payload_number++;
5915 seg_hdr[0].sc = 0;
5916 seg_hdr[0].cmplt = 0;
5917 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
5918 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
5919 pdu_hdr_loc = 0;
5920 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
5921 sdu_read_loc = 0;
5922 pdu_write_size = (testdata_size_max / number_of_sdu_frags) + pdu_write_loc;
5923 sdu_fragments++;
5924
5925 ZASSERT_PDU_WRITE_TEST(history[10],
5926 pdu_buffer[0],
5927 pdu_hdr_loc,
5928 &seg_hdr[0],
5929 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
5930
5931 ZASSERT_PDU_WRITE_TEST(history[11],
5932 pdu_buffer[0],
5933 pdu_write_loc,
5934 &testdata[sdu_read_loc],
5935 (pdu_write_size - pdu_write_loc));
5936
5937 seg_hdr[1] = seg_hdr[0];
5938 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
5939
5940 ZASSERT_PDU_WRITE_TEST(history[12],
5941 pdu_buffer[0],
5942 pdu_hdr_loc,
5943 &seg_hdr[1],
5944 PDU_ISO_SEG_HDR_SIZE);
5945
5946 /* PDU should not be emitted */
5947 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2);
5948
5949 /* PDU release not expected (No Error) */
5950 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
5951
5952 /* SDU 2 Frag 2 ------------------------------------------------------*/
5953 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
5954 sdu_timestamp += 10;
5955 testdata_indx += testdata_size;
5956 testdata_size += testdata_size_max / number_of_sdu_frags;
5957
5958 isoal_test_create_sdu_fagment(BT_ISO_CONT,
5959 &testdata[testdata_indx],
5960 (testdata_size - testdata_indx),
5961 sdu_total_size,
5962 sdu_packet_number,
5963 sdu_timestamp,
5964 sdu_timestamp,
5965 ref_point,
5966 event_number,
5967 &tx_sdu_frag_buf.sdu_tx);
5968
5969 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
5970
5971 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5972
5973 /* Test segmentation (Black Box) */
5974 /* Valid PDUs */
5975 /* PDU 3 */
5976 pdu_write_loc = pdu_write_size;
5977 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
5978 sdu_read_loc = testdata_indx;
5979
5980 /* PDU should not be allocated */
5981
5982 ZASSERT_PDU_WRITE_TEST(history[13],
5983 pdu_buffer[0],
5984 pdu_write_loc,
5985 &testdata[sdu_read_loc],
5986 (pdu_write_size - pdu_write_loc));
5987
5988 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
5989
5990 ZASSERT_PDU_WRITE_TEST(history[14],
5991 pdu_buffer[0],
5992 pdu_hdr_loc,
5993 &seg_hdr[1],
5994 PDU_ISO_SEG_HDR_SIZE);
5995
5996 ZASSERT_PDU_EMIT_TEST(history[2],
5997 &tx_pdu_meta_buf[0].node_tx,
5998 payload_number,
5999 sdu_fragments,
6000 PDU_BIS_LLID_FRAMED,
6001 pdu_write_size,
6002 isoal_global.source_state[source_hdl].session.handle);
6003
6004 /* PDU 4 */
6005 payload_number++;
6006 seg_hdr[2].sc = 1;
6007 seg_hdr[2].cmplt = 0;
6008 seg_hdr[2].timeoffset = 0;
6009 seg_hdr[2].len = 0;
6010 sdu_read_loc = (pdu_write_size - pdu_write_loc) + testdata_indx;
6011 pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc) +
6012 PDU_ISO_SEG_HDR_SIZE;
6013 pdu_hdr_loc = 0;
6014 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE;
6015 sdu_fragments = 1;
6016
6017 ZASSERT_PDU_WRITE_TEST(history[15],
6018 pdu_buffer[1],
6019 pdu_hdr_loc,
6020 &seg_hdr[2],
6021 PDU_ISO_SEG_HDR_SIZE);
6022
6023 ZASSERT_PDU_WRITE_TEST(history[16],
6024 pdu_buffer[1],
6025 pdu_write_loc,
6026 &testdata[sdu_read_loc],
6027 (pdu_write_size - pdu_write_loc));
6028
6029 seg_hdr[3] = seg_hdr[2];
6030 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
6031
6032 ZASSERT_PDU_WRITE_TEST(history[17],
6033 pdu_buffer[1],
6034 pdu_hdr_loc,
6035 &seg_hdr[3],
6036 PDU_ISO_SEG_HDR_SIZE);
6037 /* PDU should not be emitted */
6038 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(3);
6039
6040 /* PDU release not expected (No Error) */
6041 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
6042
6043 /* SDU 2 Frag 3 ------------------------------------------------------*/
6044 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
6045 sdu_timestamp += 10;
6046 testdata_indx = testdata_size;
6047 testdata_size = testdata_size_max;
6048
6049 isoal_test_create_sdu_fagment(BT_ISO_END,
6050 &testdata[testdata_indx],
6051 (testdata_size - testdata_indx),
6052 sdu_total_size,
6053 sdu_packet_number,
6054 sdu_timestamp,
6055 sdu_timestamp,
6056 ref_point,
6057 event_number,
6058 &tx_sdu_frag_buf.sdu_tx);
6059
6060 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
6061
6062 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6063
6064 /* Test segmentation (Black Box) */
6065 /* Valid PDUs */
6066 /* PDU 4 */
6067 pdu_write_loc = pdu_write_size;
6068 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
6069 sdu_read_loc = testdata_indx;
6070 sdu_fragments++;
6071
6072 /* PDU should not be allocated */
6073 ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(4);
6074
6075 ZASSERT_PDU_WRITE_TEST(history[18],
6076 pdu_buffer[1],
6077 pdu_write_loc,
6078 &testdata[sdu_read_loc],
6079 (pdu_write_size - pdu_write_loc));
6080
6081 seg_hdr[3].cmplt = 1;
6082 seg_hdr[3].len += (pdu_write_size - pdu_write_loc);
6083
6084 ZASSERT_PDU_WRITE_TEST(history[19],
6085 pdu_buffer[1],
6086 pdu_hdr_loc,
6087 &seg_hdr[3],
6088 PDU_ISO_SEG_HDR_SIZE);
6089
6090 ZASSERT_PDU_EMIT_TEST(history[3],
6091 &tx_pdu_meta_buf[1].node_tx,
6092 payload_number,
6093 sdu_fragments,
6094 PDU_BIS_LLID_FRAMED,
6095 pdu_write_size,
6096 isoal_global.source_state[source_hdl].session.handle);
6097
6098 /* PDU release not expected (No Error) */
6099 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
6100
6101 /* Send Event Timeout ----------------------------------------------- */
6102 isoal_tx_event_prepare(source_hdl, event_number);
6103
6104 /* PDU 5 (Padding) */
6105 payload_number++;
6106 pdu_write_size = 0;
6107 sdu_fragments = 0;
6108
6109 /* PDU should not be written to */
6110 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(20);
6111
6112 ZASSERT_PDU_EMIT_TEST(history[4],
6113 &tx_pdu_meta_buf[0].node_tx,
6114 payload_number,
6115 sdu_fragments,
6116 PDU_BIS_LLID_FRAMED,
6117 pdu_write_size,
6118 isoal_global.source_state[source_hdl].session.handle);
6119
6120 /* PDU 6 (Padding) */
6121 payload_number++;
6122 sdu_fragments = 0;
6123
6124 /* PDU should not be written to */
6125 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(20);
6126
6127 ZASSERT_PDU_EMIT_TEST(history[5],
6128 &tx_pdu_meta_buf[1].node_tx,
6129 payload_number,
6130 sdu_fragments,
6131 PDU_BIS_LLID_FRAMED,
6132 pdu_write_size,
6133 isoal_global.source_state[source_hdl].session.handle);
6134 }
6135
6136 /**
6137 * Test Suite : TX framed SDU segmentation
6138 *
6139 * Tests segmentation of a single SDU contained in a single fragment
6140 * into a single PDU where Max PDU is greater than the PDU buffer size,
6141 * where the reference point has to be advanced due to the payload number not
6142 * matching the actual target event
6143 */
ZTEST(test_tx_framed,test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2)6144 ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2)
6145 {
6146 uint8_t testdata[(TEST_TX_PDU_PAYLOAD_MAX -
6147 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) *
6148 2];
6149 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
6150 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
6151 struct isoal_pdu_buffer pdu_buffer;
6152 isoal_source_handle_t source_hdl;
6153 struct pdu_iso_sdu_sh seg_hdr[2];
6154 isoal_sdu_len_t sdu_total_size;
6155 isoal_pdu_len_t pdu_write_size;
6156 uint32_t stream_sync_delay;
6157 uint64_t sdu_packet_number;
6158 uint32_t group_sync_delay;
6159 uint8_t iso_interval_int;
6160 uint64_t payload_number;
6161 uint32_t sdu_timestamp;
6162 uint16_t testdata_indx;
6163 uint16_t testdata_size;
6164 uint16_t pdu_write_loc;
6165 uint16_t sdu_read_loc;
6166 uint64_t event_number;
6167 uint32_t sdu_interval;
6168 uint8_t sdu_fragments;
6169 uint16_t pdu_hdr_loc;
6170 uint32_t ref_point;
6171 isoal_status_t err;
6172 uint8_t max_octets;
6173 uint8_t role;
6174 uint8_t BN;
6175 uint8_t FT;
6176
6177 /* Settings */
6178 role = ISOAL_ROLE_PERIPHERAL;
6179 iso_interval_int = 1;
6180 sdu_interval = ISO_INT_UNIT_US + 50;
6181 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
6182 BN = 1;
6183 FT = 1;
6184 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
6185 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
6186
6187 /* SDU 1 Frag 1 ------------------------------------------------------*/
6188 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
6189 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
6190 init_test_data_buffer(
6191 testdata,
6192 (TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) *
6193 2);
6194 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
6195 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
6196 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
6197 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
6198 sdu_packet_number = 2000;
6199 event_number = 2000;
6200 sdu_timestamp = 9249;
6201 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
6202 sdu_total_size =
6203 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6204 testdata_indx = 0;
6205 testdata_size =
6206 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6207 payload_number = event_number * BN;
6208
6209 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
6210 role, /* Role */
6211 true, /* Framed */
6212 BN, /* BN */
6213 FT, /* FT */
6214 max_octets, /* max_octets */
6215 sdu_interval, /* SDU Interval */
6216 iso_interval_int, /* ISO Interval */
6217 stream_sync_delay, /* Stream Sync Delay */
6218 group_sync_delay); /* Group Sync Delay */
6219
6220 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
6221 &testdata[testdata_indx],
6222 (testdata_size - testdata_indx),
6223 sdu_total_size,
6224 sdu_packet_number,
6225 sdu_timestamp,
6226 sdu_timestamp,
6227 ref_point,
6228 event_number,
6229 &tx_sdu_frag_buf.sdu_tx);
6230
6231 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
6232 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
6233 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
6234 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
6235 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
6236 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
6237
6238 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
6239
6240 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6241
6242 /* Test segmentation (Black Box) */
6243 /* Valid PDUs */
6244 /* PDU 1 */
6245 seg_hdr[0].sc = 0;
6246 seg_hdr[0].cmplt = 0;
6247 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
6248 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
6249 pdu_hdr_loc = 0;
6250 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
6251 sdu_read_loc = 0;
6252 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
6253 sdu_fragments = 1;
6254
6255 ZASSERT_PDU_WRITE_TEST(history[0],
6256 pdu_buffer,
6257 pdu_hdr_loc,
6258 &seg_hdr[0],
6259 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
6260
6261 ZASSERT_PDU_WRITE_TEST(history[1],
6262 pdu_buffer,
6263 pdu_write_loc,
6264 &testdata[sdu_read_loc],
6265 (pdu_write_size - pdu_write_loc));
6266
6267 seg_hdr[1] = seg_hdr[0];
6268 seg_hdr[1].cmplt = 1;
6269 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
6270
6271 ZASSERT_PDU_WRITE_TEST(history[2],
6272 pdu_buffer,
6273 pdu_hdr_loc,
6274 &seg_hdr[1],
6275 PDU_ISO_SEG_HDR_SIZE);
6276
6277 ZASSERT_PDU_EMIT_TEST(history[0],
6278 &tx_pdu_meta_buf.node_tx,
6279 payload_number,
6280 sdu_fragments,
6281 PDU_BIS_LLID_FRAMED,
6282 pdu_write_size,
6283 isoal_global.source_state[source_hdl].session.handle);
6284
6285 /* PDU release not expected (No Error) */
6286 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
6287
6288 /* SDU 2 Frag 1 ------------------------------------------------------*/
6289 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
6290 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
6291 memset(seg_hdr, 0, sizeof(seg_hdr));
6292 sdu_packet_number++;
6293 sdu_timestamp = 9249 + sdu_interval;
6294 sdu_total_size =
6295 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6296 testdata_indx = 0;
6297 testdata_size =
6298 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6299 payload_number = event_number * BN;
6300
6301 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
6302 &testdata[testdata_indx],
6303 (testdata_size - testdata_indx),
6304 sdu_total_size,
6305 sdu_packet_number,
6306 sdu_timestamp,
6307 sdu_timestamp,
6308 ref_point,
6309 event_number,
6310 &tx_sdu_frag_buf.sdu_tx);
6311
6312 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
6313
6314 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6315
6316 /* Test segmentation (Black Box) */
6317 /* Valid PDUs */
6318 /* PDU 2 */
6319 /* Advance the target event and the reference point to what it should be */
6320 event_number++;
6321 ref_point += iso_interval_int * ISO_INT_UNIT_US;
6322 payload_number++;
6323 seg_hdr[0].sc = 0;
6324 seg_hdr[0].cmplt = 0;
6325 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
6326 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
6327 pdu_hdr_loc = 0;
6328 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
6329 sdu_read_loc = 0;
6330 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
6331 sdu_fragments = 1;
6332
6333 ZASSERT_PDU_WRITE_TEST(history[3],
6334 pdu_buffer,
6335 pdu_hdr_loc,
6336 &seg_hdr[0],
6337 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
6338
6339 ZASSERT_PDU_WRITE_TEST(history[4],
6340 pdu_buffer,
6341 pdu_write_loc,
6342 &testdata[sdu_read_loc],
6343 (pdu_write_size - pdu_write_loc));
6344
6345 seg_hdr[1] = seg_hdr[0];
6346 seg_hdr[1].cmplt = 1;
6347 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
6348
6349 ZASSERT_PDU_WRITE_TEST(history[5],
6350 pdu_buffer,
6351 pdu_hdr_loc,
6352 &seg_hdr[1],
6353 PDU_ISO_SEG_HDR_SIZE);
6354
6355 ZASSERT_PDU_EMIT_TEST(history[1],
6356 &tx_pdu_meta_buf.node_tx,
6357 payload_number,
6358 sdu_fragments,
6359 PDU_BIS_LLID_FRAMED,
6360 pdu_write_size,
6361 isoal_global.source_state[source_hdl].session.handle);
6362
6363 /* PDU release not expected (No Error) */
6364 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
6365 }
6366
6367 /**
6368 * Test Suite : TX framed SDU segmentation
6369 *
6370 * Tests segmentation of a single SDU contained in a single fragment
6371 * into a single PDU where Max PDU is greater than the PDU buffer size,
6372 * where the reference point has to be advanced as it is earlier than the
6373 * time stamp
6374 */
ZTEST(test_tx_framed,test_tx_framed_1_sdu_1_frag_1_pdu_refPoint3)6375 ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_refPoint3)
6376 {
6377 uint8_t testdata[(TEST_TX_PDU_PAYLOAD_MAX -
6378 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) *
6379 2];
6380 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
6381 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
6382 struct isoal_pdu_buffer pdu_buffer;
6383 isoal_source_handle_t source_hdl;
6384 struct pdu_iso_sdu_sh seg_hdr[2];
6385 isoal_sdu_len_t sdu_total_size;
6386 isoal_pdu_len_t pdu_write_size;
6387 uint32_t stream_sync_delay;
6388 uint64_t sdu_packet_number;
6389 uint32_t group_sync_delay;
6390 uint8_t iso_interval_int;
6391 uint64_t payload_number;
6392 uint32_t sdu_timestamp;
6393 uint16_t testdata_indx;
6394 uint16_t testdata_size;
6395 uint16_t pdu_write_loc;
6396 uint16_t sdu_read_loc;
6397 uint64_t event_number;
6398 uint32_t sdu_interval;
6399 uint8_t sdu_fragments;
6400 uint16_t pdu_hdr_loc;
6401 uint32_t ref_point;
6402 isoal_status_t err;
6403 uint8_t max_octets;
6404 uint8_t role;
6405 uint8_t BN;
6406 uint8_t FT;
6407
6408 /* Settings */
6409 role = ISOAL_ROLE_PERIPHERAL;
6410 iso_interval_int = 1;
6411 sdu_interval = ISO_INT_UNIT_US + 50;
6412 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
6413 BN = 1;
6414 FT = 1;
6415 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
6416 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
6417
6418 /* SDU 1 Frag 1 ------------------------------------------------------*/
6419 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
6420 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
6421 init_test_data_buffer(
6422 testdata,
6423 (TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) *
6424 2);
6425 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
6426 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
6427 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
6428 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
6429 sdu_packet_number = 2000;
6430 event_number = 2000;
6431 sdu_timestamp = 9249;
6432 ref_point = sdu_timestamp - 50;
6433 sdu_total_size =
6434 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6435 testdata_indx = 0;
6436 testdata_size =
6437 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6438 payload_number = event_number * BN;
6439
6440 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
6441 role, /* Role */
6442 true, /* Framed */
6443 BN, /* BN */
6444 FT, /* FT */
6445 max_octets, /* max_octets */
6446 sdu_interval, /* SDU Interval */
6447 iso_interval_int, /* ISO Interval */
6448 stream_sync_delay, /* Stream Sync Delay */
6449 group_sync_delay); /* Group Sync Delay */
6450
6451 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
6452 &testdata[testdata_indx],
6453 (testdata_size - testdata_indx),
6454 sdu_total_size,
6455 sdu_packet_number,
6456 sdu_timestamp,
6457 sdu_timestamp,
6458 ref_point,
6459 event_number,
6460 &tx_sdu_frag_buf.sdu_tx);
6461
6462 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
6463 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
6464 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
6465 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
6466 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
6467
6468 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
6469
6470 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6471
6472 /* Test segmentation (Black Box) */
6473 /* Valid PDUs */
6474 /* PDU 1 */
6475 /* Advance the target event and the reference point to what it should be */
6476 event_number++;
6477 ref_point += iso_interval_int * ISO_INT_UNIT_US;
6478 payload_number = event_number * BN;
6479 seg_hdr[0].sc = 0;
6480 seg_hdr[0].cmplt = 0;
6481 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
6482 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
6483 pdu_hdr_loc = 0;
6484 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
6485 sdu_read_loc = 0;
6486 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
6487 sdu_fragments = 1;
6488
6489 ZASSERT_PDU_WRITE_TEST(history[0],
6490 pdu_buffer,
6491 pdu_hdr_loc,
6492 &seg_hdr[0],
6493 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
6494
6495 ZASSERT_PDU_WRITE_TEST(history[1],
6496 pdu_buffer,
6497 pdu_write_loc,
6498 &testdata[sdu_read_loc],
6499 (pdu_write_size - pdu_write_loc));
6500
6501 seg_hdr[1] = seg_hdr[0];
6502 seg_hdr[1].cmplt = 1;
6503 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
6504
6505 ZASSERT_PDU_WRITE_TEST(history[2],
6506 pdu_buffer,
6507 pdu_hdr_loc,
6508 &seg_hdr[1],
6509 PDU_ISO_SEG_HDR_SIZE);
6510
6511 ZASSERT_PDU_EMIT_TEST(history[0],
6512 &tx_pdu_meta_buf.node_tx,
6513 payload_number,
6514 sdu_fragments,
6515 PDU_BIS_LLID_FRAMED,
6516 pdu_write_size,
6517 isoal_global.source_state[source_hdl].session.handle);
6518
6519 /* PDU release not expected (No Error) */
6520 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
6521 }
6522
6523 /**
6524 * Test Suite : TX framed SDU segmentation
6525 *
6526 * Tests segmentation of a single SDU contained in a single fragment
6527 * into a single PDU where Max PDU is greater than the PDU buffer size,
6528 * where the reference point has to be advanced due to the payload number not
6529 * matching the actual target event with a focus on the wrapping point of the
6530 * controller's clock
6531 */
ZTEST(test_tx_framed,test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1)6532 ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1)
6533 {
6534 uint8_t testdata[(TEST_TX_PDU_PAYLOAD_MAX -
6535 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) *
6536 2];
6537 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
6538 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
6539 struct isoal_pdu_buffer pdu_buffer;
6540 isoal_source_handle_t source_hdl;
6541 struct pdu_iso_sdu_sh seg_hdr[2];
6542 isoal_sdu_len_t sdu_total_size;
6543 isoal_pdu_len_t pdu_write_size;
6544 uint32_t stream_sync_delay;
6545 uint64_t sdu_packet_number;
6546 uint32_t group_sync_delay;
6547 uint8_t iso_interval_int;
6548 uint64_t payload_number;
6549 uint32_t sdu_timestamp;
6550 uint16_t testdata_indx;
6551 uint16_t testdata_size;
6552 uint16_t pdu_write_loc;
6553 uint16_t sdu_read_loc;
6554 uint64_t event_number;
6555 uint32_t sdu_interval;
6556 uint8_t sdu_fragments;
6557 uint16_t pdu_hdr_loc;
6558 uint32_t ref_point;
6559 isoal_status_t err;
6560 uint8_t max_octets;
6561 uint8_t role;
6562 uint8_t BN;
6563 uint8_t FT;
6564
6565 /* Settings */
6566 role = ISOAL_ROLE_PERIPHERAL;
6567 iso_interval_int = 1;
6568 sdu_interval = ISO_INT_UNIT_US + 50;
6569 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
6570 BN = 1;
6571 FT = 1;
6572 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
6573 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
6574
6575 /* SDU 1 Frag 1 ------------------------------------------------------*/
6576 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
6577 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
6578 init_test_data_buffer(
6579 testdata,
6580 (TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)) *
6581 2);
6582 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
6583 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
6584 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
6585 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
6586 sdu_packet_number = 2000;
6587 event_number = 2000;
6588 sdu_timestamp = ISOAL_TIME_WRAPPING_POINT_US;
6589 ref_point = 100;
6590 sdu_total_size =
6591 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6592 testdata_indx = 0;
6593 testdata_size =
6594 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6595 payload_number = event_number * BN;
6596
6597 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
6598 role, /* Role */
6599 true, /* Framed */
6600 BN, /* BN */
6601 FT, /* FT */
6602 max_octets, /* max_octets */
6603 sdu_interval, /* SDU Interval */
6604 iso_interval_int, /* ISO Interval */
6605 stream_sync_delay, /* Stream Sync Delay */
6606 group_sync_delay); /* Group Sync Delay */
6607
6608 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
6609 &testdata[testdata_indx],
6610 (testdata_size - testdata_indx),
6611 sdu_total_size,
6612 sdu_packet_number,
6613 sdu_timestamp,
6614 sdu_timestamp,
6615 ref_point,
6616 event_number,
6617 &tx_sdu_frag_buf.sdu_tx);
6618
6619 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
6620 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
6621 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
6622 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
6623 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
6624 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
6625
6626 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
6627
6628 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6629
6630 /* Test segmentation (Black Box) */
6631 /* Valid PDUs */
6632 /* PDU 1 */
6633 seg_hdr[0].sc = 0;
6634 seg_hdr[0].cmplt = 0;
6635 seg_hdr[0].timeoffset = 101;
6636 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
6637 pdu_hdr_loc = 0;
6638 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
6639 sdu_read_loc = 0;
6640 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
6641 sdu_fragments = 1;
6642
6643 ZASSERT_PDU_WRITE_TEST(history[0],
6644 pdu_buffer,
6645 pdu_hdr_loc,
6646 &seg_hdr[0],
6647 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
6648
6649 ZASSERT_PDU_WRITE_TEST(history[1],
6650 pdu_buffer,
6651 pdu_write_loc,
6652 &testdata[sdu_read_loc],
6653 (pdu_write_size - pdu_write_loc));
6654
6655 seg_hdr[1] = seg_hdr[0];
6656 seg_hdr[1].cmplt = 1;
6657 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
6658
6659 ZASSERT_PDU_WRITE_TEST(history[2],
6660 pdu_buffer,
6661 pdu_hdr_loc,
6662 &seg_hdr[1],
6663 PDU_ISO_SEG_HDR_SIZE);
6664
6665 ZASSERT_PDU_EMIT_TEST(history[0],
6666 &tx_pdu_meta_buf.node_tx,
6667 payload_number,
6668 sdu_fragments,
6669 PDU_BIS_LLID_FRAMED,
6670 pdu_write_size,
6671 isoal_global.source_state[source_hdl].session.handle);
6672
6673 /* PDU release not expected (No Error) */
6674 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
6675
6676 /* SDU 2 Frag 1 ------------------------------------------------------*/
6677 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
6678 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
6679 memset(seg_hdr, 0, sizeof(seg_hdr));
6680 sdu_packet_number++;
6681 sdu_timestamp = sdu_interval - 1;
6682 sdu_total_size =
6683 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6684 testdata_indx = 0;
6685 testdata_size =
6686 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6687 payload_number = event_number * BN;
6688
6689 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
6690 &testdata[testdata_indx],
6691 (testdata_size - testdata_indx),
6692 sdu_total_size,
6693 sdu_packet_number,
6694 sdu_timestamp,
6695 sdu_timestamp,
6696 ref_point,
6697 event_number,
6698 &tx_sdu_frag_buf.sdu_tx);
6699
6700 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
6701
6702 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6703
6704 /* Test segmentation (Black Box) */
6705 /* Valid PDUs */
6706 /* PDU 2 */
6707 /* Advance the target event and the reference point to what it should be */
6708 event_number++;
6709 ref_point += iso_interval_int * ISO_INT_UNIT_US;
6710 payload_number++;
6711 seg_hdr[0].sc = 0;
6712 seg_hdr[0].cmplt = 0;
6713 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
6714 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
6715 pdu_hdr_loc = 0;
6716 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
6717 sdu_read_loc = 0;
6718 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX;
6719 sdu_fragments = 1;
6720
6721 ZASSERT_PDU_WRITE_TEST(history[3],
6722 pdu_buffer,
6723 pdu_hdr_loc,
6724 &seg_hdr[0],
6725 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
6726
6727 ZASSERT_PDU_WRITE_TEST(history[4],
6728 pdu_buffer,
6729 pdu_write_loc,
6730 &testdata[sdu_read_loc],
6731 (pdu_write_size - pdu_write_loc));
6732
6733 seg_hdr[1] = seg_hdr[0];
6734 seg_hdr[1].cmplt = 1;
6735 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
6736
6737 ZASSERT_PDU_WRITE_TEST(history[5],
6738 pdu_buffer,
6739 pdu_hdr_loc,
6740 &seg_hdr[1],
6741 PDU_ISO_SEG_HDR_SIZE);
6742
6743 ZASSERT_PDU_EMIT_TEST(history[1],
6744 &tx_pdu_meta_buf.node_tx,
6745 payload_number,
6746 sdu_fragments,
6747 PDU_BIS_LLID_FRAMED,
6748 pdu_write_size,
6749 isoal_global.source_state[source_hdl].session.handle);
6750 /* PDU release not expected (No Error) */
6751 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
6752 }
6753
6754 /**
6755 * Test Suite : TX framed SDU segmentation
6756 *
6757 * Tests segmentation of a single SDU contained in a single fragment
6758 * into a single PDU where Max PDU is less than the PDU buffer size
6759 */
ZTEST(test_tx_framed,test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU)6760 ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU)
6761 {
6762 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
6763 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
6764 struct isoal_pdu_buffer pdu_buffer;
6765 isoal_source_handle_t source_hdl;
6766 struct pdu_iso_sdu_sh seg_hdr[2];
6767 isoal_sdu_len_t sdu_total_size;
6768 isoal_pdu_len_t pdu_write_size;
6769 uint32_t stream_sync_delay;
6770 uint64_t sdu_packet_number;
6771 uint32_t group_sync_delay;
6772 uint8_t iso_interval_int;
6773 uint64_t payload_number;
6774 uint32_t sdu_timestamp;
6775 uint16_t testdata_indx;
6776 uint16_t testdata_size;
6777 uint16_t pdu_write_loc;
6778 uint16_t sdu_read_loc;
6779 uint64_t event_number;
6780 uint32_t sdu_interval;
6781 uint8_t sdu_fragments;
6782 uint16_t pdu_hdr_loc;
6783 uint8_t testdata[1];
6784 uint32_t ref_point;
6785 isoal_status_t err;
6786 uint8_t max_octets;
6787 uint8_t role;
6788 uint8_t BN;
6789 uint8_t FT;
6790
6791 /* Settings */
6792 role = ISOAL_ROLE_PERIPHERAL;
6793 iso_interval_int = 1;
6794 sdu_interval = ISO_INT_UNIT_US + 50;
6795 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
6796 BN = 1;
6797 FT = 1;
6798 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
6799 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
6800
6801 /* SDU Frag 1 --------------------------------------------------------*/
6802 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
6803 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
6804 init_test_data_buffer(testdata, 1);
6805 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
6806 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
6807 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
6808 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
6809 sdu_packet_number = 2000;
6810 event_number = 2000;
6811 sdu_timestamp = 9249;
6812 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
6813 sdu_total_size =
6814 TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6815 testdata_indx = 0;
6816 testdata_size = 0;
6817 payload_number = event_number * BN;
6818
6819 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
6820 role, /* Role */
6821 true, /* Framed */
6822 BN, /* BN */
6823 FT, /* FT */
6824 max_octets, /* max_octets */
6825 sdu_interval, /* SDU Interval */
6826 iso_interval_int, /* ISO Interval */
6827 stream_sync_delay, /* Stream Sync Delay */
6828 group_sync_delay); /* Group Sync Delay */
6829
6830 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
6831 &testdata[testdata_indx],
6832 (testdata_size - testdata_indx),
6833 sdu_total_size,
6834 sdu_packet_number,
6835 sdu_timestamp,
6836 sdu_timestamp,
6837 ref_point,
6838 event_number,
6839 &tx_sdu_frag_buf.sdu_tx);
6840
6841 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
6842 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
6843 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
6844 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
6845 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
6846
6847 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
6848
6849 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6850
6851 /* Test segmentation (Black Box) */
6852 /* Valid PDUs */
6853 /* PDU 1 */
6854 seg_hdr[0].sc = 0;
6855 seg_hdr[0].cmplt = 0;
6856 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
6857 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
6858 pdu_hdr_loc = 0;
6859 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
6860 sdu_read_loc = 0;
6861 pdu_write_size = pdu_write_loc;
6862 sdu_fragments = 1;
6863
6864 ZASSERT_PDU_WRITE_TEST(history[0],
6865 pdu_buffer,
6866 pdu_hdr_loc,
6867 &seg_hdr[0],
6868 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
6869
6870 seg_hdr[1] = seg_hdr[0];
6871 seg_hdr[1].cmplt = 1;
6872 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
6873
6874 ZASSERT_PDU_WRITE_TEST(history[1],
6875 pdu_buffer,
6876 pdu_hdr_loc,
6877 &seg_hdr[1],
6878 PDU_ISO_SEG_HDR_SIZE);
6879
6880 /* PDU should not be emitted */
6881 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
6882
6883 /* PDU release not expected (No Error) */
6884 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
6885
6886 /* Send Event Timeout ----------------------------------------------- */
6887 isoal_tx_event_prepare(source_hdl, event_number);
6888
6889 ZASSERT_PDU_EMIT_TEST(history[0],
6890 &tx_pdu_meta_buf.node_tx,
6891 payload_number,
6892 sdu_fragments,
6893 PDU_BIS_LLID_FRAMED,
6894 pdu_write_size,
6895 isoal_global.source_state[source_hdl].session.handle);
6896 }
6897
6898 /**
6899 * Test Suite : TX framed SDU segmentation
6900 *
6901 * Tests segmentation of a single SDU contained in a single fragment
6902 * into a single PDU followed by padding
6903 */
ZTEST(test_tx_framed,test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding)6904 ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding)
6905 {
6906 struct tx_pdu_meta_buffer tx_pdu_meta_buf[3];
6907 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
6908 struct isoal_pdu_buffer pdu_buffer[3];
6909 isoal_source_handle_t source_hdl;
6910 struct pdu_iso_sdu_sh seg_hdr[2];
6911 isoal_sdu_len_t sdu_total_size;
6912 isoal_pdu_len_t pdu_write_size;
6913 uint32_t stream_sync_delay;
6914 uint64_t sdu_packet_number;
6915 uint32_t group_sync_delay;
6916 uint8_t iso_interval_int;
6917 uint64_t payload_number;
6918 uint32_t sdu_timestamp;
6919 uint16_t testdata_indx;
6920 uint16_t testdata_size;
6921 uint16_t pdu_write_loc;
6922 uint16_t sdu_read_loc;
6923 uint64_t event_number;
6924 uint32_t sdu_interval;
6925 uint8_t sdu_fragments;
6926 uint16_t pdu_hdr_loc;
6927 uint8_t testdata[1];
6928 uint32_t ref_point;
6929 isoal_status_t err;
6930 uint8_t max_octets;
6931 uint8_t role;
6932 uint8_t BN;
6933 uint8_t FT;
6934
6935 /* Settings */
6936 role = ISOAL_ROLE_PERIPHERAL;
6937 iso_interval_int = 1;
6938 sdu_interval = ISO_INT_UNIT_US + 50;
6939 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
6940 BN = 3;
6941 FT = 1;
6942 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
6943 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
6944
6945 /* SDU Frag 1 --------------------------------------------------------*/
6946 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
6947 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
6948 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]);
6949 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
6950 init_test_data_buffer(testdata, 1);
6951 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
6952 pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx;
6953 pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu;
6954 pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX;
6955 pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx;
6956 pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu;
6957 pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX;
6958 pdu_buffer[2].handle = (void *)&tx_pdu_meta_buf[2].node_tx;
6959 pdu_buffer[2].pdu = (struct pdu_iso *)tx_pdu_meta_buf[2].node_tx.pdu;
6960 pdu_buffer[2].size = TEST_TX_PDU_PAYLOAD_MAX;
6961 sdu_packet_number = 2000;
6962 event_number = 2000;
6963 sdu_timestamp = 9249;
6964 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
6965 sdu_total_size =
6966 TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
6967 testdata_indx = 0;
6968 testdata_size = 0;
6969 payload_number = event_number * BN;
6970
6971 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
6972 role, /* Role */
6973 true, /* Framed */
6974 BN, /* BN */
6975 FT, /* FT */
6976 max_octets, /* max_octets */
6977 sdu_interval, /* SDU Interval */
6978 iso_interval_int, /* ISO Interval */
6979 stream_sync_delay, /* Stream Sync Delay */
6980 group_sync_delay); /* Group Sync Delay */
6981
6982 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
6983 &testdata[testdata_indx],
6984 (testdata_size - testdata_indx),
6985 sdu_total_size,
6986 sdu_packet_number,
6987 sdu_timestamp,
6988 sdu_timestamp,
6989 ref_point,
6990 event_number,
6991 &tx_sdu_frag_buf.sdu_tx);
6992
6993 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
6994 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
6995 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[2]);
6996 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
6997 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
6998 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
6999 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
7000
7001 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
7002
7003 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7004
7005 /* Test segmentation (Black Box) */
7006 /* Valid PDUs */
7007 /* PDU 1 */
7008 seg_hdr[0].sc = 0;
7009 seg_hdr[0].cmplt = 0;
7010 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
7011 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
7012 pdu_hdr_loc = 0;
7013 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
7014 sdu_read_loc = 0;
7015 pdu_write_size = pdu_write_loc;
7016 sdu_fragments = 1;
7017
7018 ZASSERT_PDU_WRITE_TEST(history[0],
7019 pdu_buffer[0],
7020 pdu_hdr_loc,
7021 &seg_hdr[0],
7022 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7023
7024 seg_hdr[1] = seg_hdr[0];
7025 seg_hdr[1].cmplt = 1;
7026 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
7027
7028 ZASSERT_PDU_WRITE_TEST(history[1],
7029 pdu_buffer[0],
7030 pdu_hdr_loc,
7031 &seg_hdr[1],
7032 PDU_ISO_SEG_HDR_SIZE);
7033
7034 /* PDU should not be emitted */
7035 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
7036
7037 /* PDU release not expected (No Error) */
7038 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
7039
7040 /* Send Event Timeout ----------------------------------------------- */
7041 isoal_tx_event_prepare(source_hdl, event_number);
7042
7043 ZASSERT_PDU_EMIT_TEST(history[0],
7044 &tx_pdu_meta_buf[0].node_tx,
7045 payload_number,
7046 sdu_fragments,
7047 PDU_BIS_LLID_FRAMED,
7048 pdu_write_size,
7049 isoal_global.source_state[source_hdl].session.handle);
7050
7051 /* PDU 2 (Padding) */
7052 payload_number++;
7053 pdu_write_size = 0;
7054 sdu_fragments = 0;
7055
7056 /* PDU should not be written to */
7057 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(2);
7058
7059 ZASSERT_PDU_EMIT_TEST(history[1],
7060 &tx_pdu_meta_buf[1].node_tx,
7061 payload_number,
7062 sdu_fragments,
7063 PDU_BIS_LLID_FRAMED,
7064 pdu_write_size,
7065 isoal_global.source_state[source_hdl].session.handle);
7066
7067 /* PDU 3 (Padding) */
7068 payload_number++;
7069 sdu_fragments = 0;
7070
7071 /* PDU should not be written to */
7072 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(2);
7073
7074 ZASSERT_PDU_EMIT_TEST(history[2],
7075 &tx_pdu_meta_buf[2].node_tx,
7076 payload_number,
7077 sdu_fragments,
7078 PDU_BIS_LLID_FRAMED,
7079 pdu_write_size,
7080 isoal_global.source_state[source_hdl].session.handle);
7081 }
7082
7083 /**
7084 * Test Suite : TX framed SDU segmentation
7085 *
7086 * Tests segmentation of a single SDU contained in a single fragment,
7087 * where PDU allocation fails
7088 */
ZTEST(test_tx_framed,test_tx_framed_1_sdu_1_frag_pdu_alloc_err)7089 ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_alloc_err)
7090 {
7091 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX - 5 -
7092 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)];
7093 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
7094 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
7095 struct isoal_pdu_buffer pdu_buffer;
7096 isoal_source_handle_t source_hdl;
7097 struct pdu_iso_sdu_sh seg_hdr[2];
7098 isoal_sdu_len_t sdu_total_size;
7099 isoal_pdu_len_t pdu_write_size;
7100 uint32_t stream_sync_delay;
7101 uint64_t sdu_packet_number;
7102 uint32_t group_sync_delay;
7103 uint8_t iso_interval_int;
7104 uint64_t payload_number;
7105 uint32_t sdu_timestamp;
7106 uint16_t testdata_indx;
7107 uint16_t testdata_size;
7108 uint16_t pdu_write_loc;
7109 uint16_t sdu_read_loc;
7110 uint64_t event_number;
7111 uint32_t sdu_interval;
7112 uint8_t sdu_fragments;
7113 uint16_t pdu_hdr_loc;
7114 uint32_t ref_point;
7115 isoal_status_t err;
7116 uint8_t max_octets;
7117 uint8_t role;
7118 uint8_t BN;
7119 uint8_t FT;
7120
7121 /* Settings */
7122 role = ISOAL_ROLE_PERIPHERAL;
7123 iso_interval_int = 1;
7124 sdu_interval = ISO_INT_UNIT_US + 50;
7125 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
7126 BN = 1;
7127 FT = 1;
7128 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
7129 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
7130
7131 /* SDU Frag 1 --------------------------------------------------------*/
7132 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
7133 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
7134 init_test_data_buffer(testdata,
7135 TEST_TX_PDU_PAYLOAD_MAX - 5 -
7136 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7137 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
7138 pdu_buffer.handle = NULL;
7139 pdu_buffer.pdu = NULL;
7140 pdu_buffer.size = 0;
7141 sdu_packet_number = 2000;
7142 event_number = 2000;
7143 sdu_timestamp = 9249;
7144 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
7145 sdu_total_size =
7146 TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
7147 testdata_indx = 0;
7148 testdata_size =
7149 TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
7150 payload_number = event_number * BN;
7151
7152 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
7153 role, /* Role */
7154 true, /* Framed */
7155 BN, /* BN */
7156 FT, /* FT */
7157 max_octets, /* max_octets */
7158 sdu_interval, /* SDU Interval */
7159 iso_interval_int, /* ISO Interval */
7160 stream_sync_delay, /* Stream Sync Delay */
7161 group_sync_delay); /* Group Sync Delay */
7162
7163 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
7164 &testdata[testdata_indx],
7165 (testdata_size - testdata_indx),
7166 sdu_total_size,
7167 sdu_packet_number,
7168 sdu_timestamp,
7169 sdu_timestamp,
7170 ref_point,
7171 event_number,
7172 &tx_sdu_frag_buf.sdu_tx);
7173
7174 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
7175 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_ERR_PDU_ALLOC);
7176 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
7177 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
7178 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
7179
7180 ztest_set_assert_valid(true);
7181
7182 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
7183
7184 ztest_set_assert_valid(false);
7185
7186 zassert_equal(err, ISOAL_STATUS_ERR_PDU_ALLOC, "err = 0x%02x", err);
7187
7188 /* Test segmentation (Black Box) */
7189 /* Valid PDUs */
7190 /* PDU 1 */
7191 seg_hdr[0].sc = 0;
7192 seg_hdr[0].cmplt = 0;
7193 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
7194 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
7195 pdu_hdr_loc = 0;
7196 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
7197 sdu_read_loc = 0;
7198 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
7199 sdu_fragments = 1;
7200
7201 /* PDU should not be written to */
7202 ZASSERT_PDU_WRITE_TEST_CALL_COUNT(0);
7203
7204 /* PDU should not be emitted */
7205 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
7206
7207 /* PDU release not expected (No Emit Error) */
7208 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
7209 }
7210
7211 /**
7212 * Test Suite : TX framed SDU segmentation
7213 *
7214 * Tests segmentation of a single SDU contained in a single fragment
7215 * into a single PDU where Max PDU is less than the PDU buffer size,
7216 * where PDU emit fails
7217 */
ZTEST(test_tx_framed,test_tx_framed_1_sdu_1_frag_pdu_emit_err)7218 ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_emit_err)
7219 {
7220 uint8_t testdata[TEST_TX_PDU_PAYLOAD_MAX - 5 -
7221 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)];
7222 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
7223 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
7224 struct isoal_pdu_buffer pdu_buffer;
7225 isoal_source_handle_t source_hdl;
7226 struct pdu_iso_sdu_sh seg_hdr[2];
7227 isoal_sdu_len_t sdu_total_size;
7228 isoal_pdu_len_t pdu_write_size;
7229 uint32_t stream_sync_delay;
7230 uint64_t sdu_packet_number;
7231 uint32_t group_sync_delay;
7232 uint8_t iso_interval_int;
7233 uint64_t payload_number;
7234 uint32_t sdu_timestamp;
7235 uint16_t testdata_indx;
7236 uint16_t testdata_size;
7237 uint16_t pdu_write_loc;
7238 uint16_t sdu_read_loc;
7239 uint64_t event_number;
7240 uint32_t sdu_interval;
7241 uint8_t sdu_fragments;
7242 uint16_t pdu_hdr_loc;
7243 uint32_t ref_point;
7244 isoal_status_t err;
7245 uint8_t max_octets;
7246 uint8_t role;
7247 uint8_t BN;
7248 uint8_t FT;
7249
7250 /* Settings */
7251 role = ISOAL_ROLE_PERIPHERAL;
7252 iso_interval_int = 1;
7253 sdu_interval = ISO_INT_UNIT_US + 50;
7254 max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5;
7255 BN = 1;
7256 FT = 1;
7257 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
7258 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
7259
7260 /* SDU Frag 1 --------------------------------------------------------*/
7261 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
7262 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
7263 init_test_data_buffer(testdata,
7264 TEST_TX_PDU_PAYLOAD_MAX - 5 -
7265 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7266 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
7267 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
7268 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
7269 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
7270 sdu_packet_number = 2000;
7271 event_number = 2000;
7272 sdu_timestamp = 9249;
7273 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
7274 sdu_total_size =
7275 TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
7276 testdata_indx = 0;
7277 testdata_size =
7278 TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
7279 payload_number = event_number * BN;
7280
7281 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
7282 role, /* Role */
7283 true, /* Framed */
7284 BN, /* BN */
7285 FT, /* FT */
7286 max_octets, /* max_octets */
7287 sdu_interval, /* SDU Interval */
7288 iso_interval_int, /* ISO Interval */
7289 stream_sync_delay, /* Stream Sync Delay */
7290 group_sync_delay); /* Group Sync Delay */
7291
7292 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
7293 &testdata[testdata_indx],
7294 (testdata_size - testdata_indx),
7295 sdu_total_size,
7296 sdu_packet_number,
7297 sdu_timestamp,
7298 sdu_timestamp,
7299 ref_point,
7300 event_number,
7301 &tx_sdu_frag_buf.sdu_tx);
7302
7303 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
7304 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
7305 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
7306 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_ERR_PDU_EMIT);
7307 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
7308
7309 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
7310
7311 zassert_equal(err, ISOAL_STATUS_ERR_PDU_EMIT, "err = 0x%02x", err);
7312
7313 /* Test segmentation (Black Box) */
7314 /* Valid PDUs */
7315 /* PDU 1 */
7316 seg_hdr[0].sc = 0;
7317 seg_hdr[0].cmplt = 0;
7318 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
7319 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
7320 pdu_hdr_loc = 0;
7321 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
7322 sdu_read_loc = 0;
7323 pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX - 5;
7324 sdu_fragments = 1;
7325
7326 ZASSERT_PDU_WRITE_TEST(history[0],
7327 pdu_buffer,
7328 pdu_hdr_loc,
7329 &seg_hdr[0],
7330 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7331
7332 ZASSERT_PDU_WRITE_TEST(history[1],
7333 pdu_buffer,
7334 pdu_write_loc,
7335 &testdata[sdu_read_loc],
7336 (pdu_write_size - pdu_write_loc));
7337
7338 seg_hdr[1] = seg_hdr[0];
7339 seg_hdr[1].cmplt = 1;
7340 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
7341
7342 ZASSERT_PDU_WRITE_TEST(history[2],
7343 pdu_buffer,
7344 pdu_hdr_loc,
7345 &seg_hdr[1],
7346 PDU_ISO_SEG_HDR_SIZE);
7347
7348 ZASSERT_PDU_EMIT_TEST(history[0],
7349 &tx_pdu_meta_buf.node_tx,
7350 payload_number,
7351 sdu_fragments,
7352 PDU_BIS_LLID_FRAMED,
7353 pdu_write_size,
7354 isoal_global.source_state[source_hdl].session.handle);
7355
7356 ZASSERT_PDU_RELEASE_TEST(
7357 history[0],
7358 &tx_pdu_meta_buf.node_tx,
7359 bt_iso_handle(isoal_global.source_state[source_hdl].session.handle),
7360 ISOAL_STATUS_ERR_PDU_EMIT);
7361 }
7362
7363 /**
7364 * Test Suite : TX framed SDU segmentation
7365 *
7366 * Tests segmentation of a single SDU contained in a single fragment
7367 * into a single PDU, relying on the ISO event deadline to release the PDU.
7368 */
ZTEST(test_tx_framed,test_tx_framed_2_sdu_1_frag_pdu_timeout)7369 ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout)
7370 {
7371 uint8_t testdata[40];
7372 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
7373 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
7374 struct isoal_pdu_buffer pdu_buffer;
7375 isoal_source_handle_t source_hdl;
7376 struct pdu_iso_sdu_sh seg_hdr[2];
7377 isoal_sdu_len_t sdu_total_size;
7378 isoal_pdu_len_t pdu_write_size;
7379 uint32_t stream_sync_delay;
7380 uint64_t sdu_packet_number;
7381 uint32_t group_sync_delay;
7382 uint16_t iso_interval_int;
7383 uint64_t payload_number;
7384 uint32_t sdu_timestamp;
7385 uint16_t testdata_indx;
7386 uint16_t testdata_size;
7387 uint16_t pdu_write_loc;
7388 uint16_t sdu_read_loc;
7389 uint64_t event_number;
7390 uint32_t sdu_interval;
7391 uint8_t sdu_fragments;
7392 uint16_t pdu_hdr_loc;
7393 uint32_t ref_point;
7394 isoal_status_t err;
7395 uint8_t max_octets;
7396 uint8_t role;
7397 uint8_t BN;
7398 uint8_t FT;
7399
7400 /* Settings */
7401 role = ISOAL_ROLE_PERIPHERAL;
7402 iso_interval_int = 800;
7403 sdu_interval = 500000;
7404 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
7405 BN = 1;
7406 FT = 1;
7407 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
7408 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
7409
7410 /* SDU 1 Frag 1 ------------------------------------------------------*/
7411 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
7412 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
7413 init_test_data_buffer(testdata, 40);
7414 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
7415 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
7416 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
7417 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
7418 sdu_packet_number = 0;
7419 event_number = 2000;
7420 sdu_timestamp = 9249;
7421 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
7422 sdu_total_size =
7423 TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
7424 testdata_indx = 0;
7425 testdata_size = 10;
7426 payload_number = event_number * BN;
7427
7428 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
7429 role, /* Role */
7430 true, /* Framed */
7431 BN, /* BN */
7432 FT, /* FT */
7433 max_octets, /* max_octets */
7434 sdu_interval, /* SDU Interval */
7435 iso_interval_int, /* ISO Interval */
7436 stream_sync_delay, /* Stream Sync Delay */
7437 group_sync_delay); /* Group Sync Delay */
7438
7439 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
7440 &testdata[testdata_indx],
7441 (testdata_size - testdata_indx),
7442 sdu_total_size,
7443 sdu_packet_number,
7444 sdu_timestamp,
7445 sdu_timestamp,
7446 ref_point,
7447 event_number,
7448 &tx_sdu_frag_buf.sdu_tx);
7449
7450 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
7451 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
7452 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
7453 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
7454 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
7455 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
7456
7457 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
7458
7459 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7460
7461 /* Test segmentation (Black Box) */
7462 /* Valid PDUs */
7463 /* PDU 1 */
7464 seg_hdr[0].sc = 0;
7465 seg_hdr[0].cmplt = 0;
7466 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
7467 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
7468 pdu_hdr_loc = 0;
7469 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
7470 sdu_read_loc = 0;
7471 pdu_write_size = pdu_write_loc + testdata_size;
7472 sdu_fragments = 1;
7473
7474 ZASSERT_PDU_WRITE_TEST(history[0],
7475 pdu_buffer,
7476 pdu_hdr_loc,
7477 &seg_hdr[0],
7478 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7479
7480 ZASSERT_PDU_WRITE_TEST(history[1],
7481 pdu_buffer,
7482 pdu_write_loc,
7483 &testdata[sdu_read_loc],
7484 (pdu_write_size - pdu_write_loc));
7485
7486 seg_hdr[1] = seg_hdr[0];
7487 seg_hdr[1].cmplt = 1;
7488 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
7489
7490 ZASSERT_PDU_WRITE_TEST(history[2],
7491 pdu_buffer,
7492 pdu_hdr_loc,
7493 &seg_hdr[1],
7494 PDU_ISO_SEG_HDR_SIZE);
7495
7496 /* PDU should not be emitted */
7497
7498 /* PDU release not expected (No Error) */
7499 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
7500
7501 /* Test PDU release */
7502 /* Simulate interleaving by setting context active flag */
7503 isoal_global.source_state[source_hdl].context_active = true;
7504 isoal_tx_event_prepare(source_hdl, event_number);
7505 isoal_global.source_state[source_hdl].context_active = false;
7506
7507 /* SDU 2 Frag 1 ------------------------------------------------------*/
7508 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
7509 memset(seg_hdr, 0, sizeof(seg_hdr));
7510 sdu_packet_number++;
7511 sdu_timestamp = 9249 + sdu_interval;
7512 sdu_total_size = 10;
7513 testdata_indx = testdata_size;
7514 testdata_size += 10;
7515
7516 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
7517 &testdata[testdata_indx],
7518 (testdata_size - testdata_indx),
7519 sdu_total_size,
7520 sdu_packet_number,
7521 sdu_timestamp,
7522 sdu_timestamp,
7523 ref_point,
7524 event_number,
7525 &tx_sdu_frag_buf.sdu_tx);
7526
7527 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
7528
7529 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7530
7531 /* Test segmentation (Black Box) */
7532 /* Valid PDUs */
7533 /* PDU 1 - Seg 2 */
7534 seg_hdr[0].sc = 0;
7535 seg_hdr[0].cmplt = 0;
7536 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
7537 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
7538 pdu_hdr_loc = 10 + PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
7539 pdu_write_loc = pdu_hdr_loc + PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
7540 sdu_read_loc = testdata_indx;
7541 pdu_write_size = pdu_write_loc + 10;
7542 sdu_fragments++;
7543
7544 /* PDU should not be allocated */
7545
7546 ZASSERT_PDU_WRITE_TEST(history[3],
7547 pdu_buffer,
7548 pdu_hdr_loc,
7549 &seg_hdr[0],
7550 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7551
7552 ZASSERT_PDU_WRITE_TEST(history[4],
7553 pdu_buffer,
7554 pdu_write_loc,
7555 &testdata[sdu_read_loc],
7556 (pdu_write_size - pdu_write_loc));
7557
7558 seg_hdr[1] = seg_hdr[0];
7559 seg_hdr[1].cmplt = 1;
7560 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
7561
7562 ZASSERT_PDU_WRITE_TEST(history[5],
7563 pdu_buffer,
7564 pdu_hdr_loc,
7565 &seg_hdr[1],
7566 PDU_ISO_SEG_HDR_SIZE);
7567
7568 ZASSERT_PDU_EMIT_TEST(history[0],
7569 &tx_pdu_meta_buf.node_tx,
7570 payload_number,
7571 sdu_fragments,
7572 PDU_BIS_LLID_FRAMED,
7573 pdu_write_size,
7574 isoal_global.source_state[source_hdl].session.handle);
7575
7576 /* PDU release not expected (No Error) */
7577 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
7578
7579 /* SDU 3 Frag 1 ------------------------------------------------------*/
7580 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
7581 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
7582 memset(seg_hdr, 0, sizeof(seg_hdr));
7583 event_number++;
7584 sdu_packet_number++;
7585 sdu_timestamp = sdu_timestamp + sdu_interval;
7586 ref_point = ref_point + (iso_interval_int * ISO_INT_UNIT_US);
7587 sdu_total_size = 20;
7588 testdata_indx = testdata_size;
7589 testdata_size += 20;
7590
7591 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
7592 &testdata[testdata_indx],
7593 (testdata_size - testdata_indx),
7594 sdu_total_size,
7595 sdu_packet_number,
7596 sdu_timestamp,
7597 sdu_timestamp,
7598 ref_point,
7599 event_number,
7600 &tx_sdu_frag_buf.sdu_tx);
7601
7602 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
7603
7604 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7605
7606 /* Test segmentation (Black Box) */
7607 /* Valid PDUs */
7608 /* PDU 1 - Seg 2 */
7609 seg_hdr[0].sc = 0;
7610 seg_hdr[0].cmplt = 0;
7611 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
7612 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
7613 pdu_hdr_loc = 0;
7614 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
7615 sdu_read_loc = testdata_indx;
7616 pdu_write_size = pdu_write_loc + sdu_total_size;
7617 sdu_fragments = 1;
7618 payload_number++;
7619
7620 ZASSERT_PDU_WRITE_TEST(history[6],
7621 pdu_buffer,
7622 pdu_hdr_loc,
7623 &seg_hdr[0],
7624 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7625
7626 ZASSERT_PDU_WRITE_TEST(history[7],
7627 pdu_buffer,
7628 pdu_write_loc,
7629 &testdata[sdu_read_loc],
7630 (pdu_write_size - pdu_write_loc));
7631
7632 seg_hdr[1] = seg_hdr[0];
7633 seg_hdr[1].cmplt = 1;
7634 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
7635
7636 ZASSERT_PDU_WRITE_TEST(history[8],
7637 pdu_buffer,
7638 pdu_hdr_loc,
7639 &seg_hdr[1],
7640 PDU_ISO_SEG_HDR_SIZE);
7641
7642 /* PDU emit not expected */
7643 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1);
7644
7645 /* PDU release not expected (No Error) */
7646 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
7647
7648 /* Test PDU release */
7649 isoal_tx_event_prepare(source_hdl, event_number);
7650
7651 ZASSERT_PDU_EMIT_TEST(history[1],
7652 &tx_pdu_meta_buf.node_tx,
7653 payload_number,
7654 sdu_fragments,
7655 PDU_BIS_LLID_FRAMED,
7656 pdu_write_size,
7657 isoal_global.source_state[source_hdl].session.handle);
7658 }
7659
7660 /**
7661 * Test Suite : TX framed SDU segmentation
7662 *
7663 * Tests that consecutive events are used irrespective of the target event info
7664 * as long as they are feasible.
7665 */
ZTEST(test_tx_framed,test_tx_framed_event_utilization_1)7666 ZTEST(test_tx_framed, test_tx_framed_event_utilization_1)
7667 {
7668 const uint8_t number_of_pdus = 3;
7669 const uint8_t sdu_fragment_data_size = 25;
7670 const uint8_t testdata_size_max = sdu_fragment_data_size * 4;
7671 /* Two SDUs and one that would overflow into a new PDU */
7672 const uint8_t number_of_seg_hdr_buf = 3;
7673
7674 struct tx_pdu_meta_buffer tx_pdu_meta_buf[number_of_pdus];
7675 struct pdu_iso_sdu_sh seg_hdr[number_of_seg_hdr_buf];
7676 struct isoal_pdu_buffer pdu_buffer[number_of_pdus];
7677 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
7678 uint8_t testdata[testdata_size_max];
7679 isoal_source_handle_t source_hdl;
7680 isoal_sdu_len_t sdu_total_size;
7681 isoal_pdu_len_t pdu_write_end;
7682 uint32_t stream_sync_delay;
7683 uint64_t sdu_packet_number;
7684 uint32_t group_sync_delay;
7685 uint64_t pdu_event_number;
7686 uint8_t iso_interval_int;
7687 uint32_t iso_interval_us;
7688 uint64_t payload_number;
7689 uint32_t pdu_ref_point;
7690 uint32_t sdu_timestamp;
7691 uint16_t testdata_indx;
7692 uint16_t testdata_size;
7693 uint16_t pdu_write_loc;
7694 uint16_t sdu_read_loc;
7695 uint64_t event_number;
7696 uint32_t sdu_interval;
7697 uint8_t sdu_fragments;
7698 uint16_t pdu_hdr_loc;
7699 uint32_t ref_point;
7700 isoal_status_t err;
7701 uint8_t max_octets;
7702 uint8_t role;
7703 uint8_t BN;
7704 uint8_t FT;
7705
7706 /* Settings */
7707 role = BT_CONN_ROLE_PERIPHERAL;
7708 iso_interval_int = 1;
7709 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
7710 sdu_interval = ISO_INT_UNIT_US - 50; /* Less than an ISO interval */
7711 max_octets = TEST_TX_PDU_PAYLOAD_MAX;
7712 BN = 2;
7713 FT = 1;
7714 stream_sync_delay = iso_interval_us - 200;
7715 group_sync_delay = iso_interval_us - 50;
7716
7717 /* SDU 0 -------------------------------------------------------------*/
7718 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
7719 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
7720 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]);
7721 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
7722 init_test_data_buffer(testdata, testdata_size_max);
7723 (void)memset(&seg_hdr, 0, sizeof(seg_hdr));
7724 pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx;
7725 pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu;
7726 pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX;
7727 pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx;
7728 pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu;
7729 pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX;
7730 pdu_buffer[2].handle = (void *)&tx_pdu_meta_buf[2].node_tx;
7731 pdu_buffer[2].pdu = (struct pdu_iso *)tx_pdu_meta_buf[2].node_tx.pdu;
7732 pdu_buffer[2].size = TEST_TX_PDU_PAYLOAD_MAX;
7733 sdu_packet_number = 0;
7734 event_number = 5;
7735 pdu_event_number = event_number;
7736 sdu_timestamp = 9249;
7737 ref_point = sdu_timestamp + iso_interval_us;
7738 pdu_ref_point = ref_point;
7739 sdu_total_size = sdu_fragment_data_size;
7740 testdata_indx = 0;
7741 testdata_size = sdu_fragment_data_size;
7742 sdu_fragments = 0;
7743
7744 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
7745 role, /* Role */
7746 true, /* Framed */
7747 BN, /* BN */
7748 FT, /* FT */
7749 max_octets, /* max_octets */
7750 sdu_interval, /* SDU Interval */
7751 iso_interval_int, /* ISO Interval */
7752 stream_sync_delay, /* Stream Sync Delay */
7753 group_sync_delay); /* Group Sync Delay */
7754
7755 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
7756 &testdata[testdata_indx],
7757 (testdata_size - testdata_indx),
7758 sdu_total_size,
7759 sdu_packet_number,
7760 sdu_timestamp,
7761 sdu_timestamp,
7762 ref_point,
7763 event_number,
7764 &tx_sdu_frag_buf.sdu_tx);
7765
7766 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
7767 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
7768 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
7769 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]);
7770 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[2]);
7771 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]);
7772 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
7773 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
7774 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
7775 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
7776
7777 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
7778
7779 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7780
7781 /* Test segmentation (Black Box) */
7782 /* Valid PDUs */
7783 /* PDU 0 */
7784 payload_number = event_number * BN;
7785 seg_hdr[0].sc = 0;
7786 seg_hdr[0].cmplt = 0;
7787 seg_hdr[0].timeoffset = pdu_ref_point - sdu_timestamp;
7788 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
7789 pdu_hdr_loc = 0;
7790 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
7791 sdu_read_loc = 0;
7792 pdu_write_end = sdu_fragment_data_size + pdu_write_loc;
7793 sdu_fragments++;
7794
7795 ZASSERT_PDU_WRITE_TEST(history[0],
7796 pdu_buffer[0],
7797 pdu_hdr_loc,
7798 &seg_hdr[0],
7799 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7800
7801 ZASSERT_PDU_WRITE_TEST(history[1],
7802 pdu_buffer[0],
7803 pdu_write_loc,
7804 &testdata[sdu_read_loc],
7805 (pdu_write_end - pdu_write_loc));
7806
7807 seg_hdr[0].cmplt = 1;
7808 seg_hdr[0].len += (pdu_write_end - pdu_write_loc);
7809
7810 ZASSERT_PDU_WRITE_TEST(history[2],
7811 pdu_buffer[0],
7812 pdu_hdr_loc,
7813 &seg_hdr[0],
7814 PDU_ISO_SEG_HDR_SIZE);
7815
7816 /* PDU should not be emitted */
7817 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
7818
7819 /* PDU release not expected (No Error) */
7820 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
7821
7822 /* SDU 1 -------------------------------------------------------------*/
7823 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
7824 sdu_packet_number++;
7825 event_number += 2;
7826 ref_point += iso_interval_us * 2;
7827 sdu_timestamp += sdu_interval;
7828 testdata_indx = testdata_size;
7829 testdata_size += sdu_fragment_data_size;
7830
7831 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
7832 &testdata[testdata_indx],
7833 (testdata_size - testdata_indx),
7834 sdu_total_size,
7835 sdu_packet_number,
7836 sdu_timestamp,
7837 sdu_timestamp,
7838 ref_point,
7839 event_number,
7840 &tx_sdu_frag_buf.sdu_tx);
7841
7842 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
7843
7844 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7845
7846 /* Test segmentation (Black Box) */
7847 /* Valid PDUs */
7848 /* PDU 10 */
7849 pdu_hdr_loc = pdu_write_end;
7850 seg_hdr[1].sc = 0;
7851 seg_hdr[1].cmplt = 0;
7852 seg_hdr[1].timeoffset = pdu_ref_point - sdu_timestamp;
7853 seg_hdr[1].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
7854 pdu_write_loc = pdu_write_end + (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
7855 pdu_write_end = TEST_TX_PDU_PAYLOAD_MAX;
7856 sdu_read_loc = testdata_indx;
7857
7858 ZASSERT_PDU_WRITE_TEST(history[3],
7859 pdu_buffer[0],
7860 pdu_hdr_loc,
7861 &seg_hdr[1],
7862 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7863
7864 ZASSERT_PDU_WRITE_TEST(history[4],
7865 pdu_buffer[0],
7866 pdu_write_loc,
7867 &testdata[sdu_read_loc],
7868 (pdu_write_end - pdu_write_loc));
7869
7870 /* PDU should not be allocated */
7871
7872 seg_hdr[1].len += (pdu_write_end - pdu_write_loc);
7873
7874 ZASSERT_PDU_WRITE_TEST(history[5],
7875 pdu_buffer[0],
7876 pdu_hdr_loc,
7877 &seg_hdr[1],
7878 PDU_ISO_SEG_HDR_SIZE);
7879
7880 ZASSERT_PDU_EMIT_TEST(history[0],
7881 &tx_pdu_meta_buf[0].node_tx,
7882 payload_number,
7883 sdu_fragments,
7884 PDU_BIS_LLID_FRAMED,
7885 pdu_write_end,
7886 isoal_global.source_state[source_hdl].session.handle);
7887
7888 /* PDU release not expected (No Error) */
7889 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
7890
7891 /* PDU 11 */
7892 payload_number++;
7893 seg_hdr[2].sc = 1;
7894 seg_hdr[2].cmplt = 0;
7895 seg_hdr[2].timeoffset = 0;
7896 seg_hdr[2].len = 0;
7897 sdu_read_loc += (pdu_write_end - pdu_write_loc);
7898 pdu_hdr_loc = 0;
7899 pdu_write_end = testdata_size - testdata_indx - (pdu_write_end - pdu_write_loc) +
7900 PDU_ISO_SEG_HDR_SIZE;
7901 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE;
7902 sdu_fragments = 1;
7903
7904 ZASSERT_PDU_WRITE_TEST(history[6],
7905 pdu_buffer[1],
7906 pdu_hdr_loc,
7907 &seg_hdr[2],
7908 PDU_ISO_SEG_HDR_SIZE);
7909
7910 ZASSERT_PDU_WRITE_TEST(history[7],
7911 pdu_buffer[1],
7912 pdu_write_loc,
7913 &testdata[sdu_read_loc],
7914 (pdu_write_end - pdu_write_loc));
7915
7916 seg_hdr[2].cmplt = 1;
7917 seg_hdr[2].len += (pdu_write_end - pdu_write_loc);
7918
7919 ZASSERT_PDU_WRITE_TEST(history[8],
7920 pdu_buffer[1],
7921 pdu_hdr_loc,
7922 &seg_hdr[2],
7923 PDU_ISO_SEG_HDR_SIZE);
7924
7925 /* PDU should not be emitted */
7926 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1);
7927
7928 /* PDU release not expected (No Error) */
7929 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
7930
7931 /* SDU 2 -------------------------------------------------------------*/
7932 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]);
7933 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
7934 sdu_packet_number++;
7935 event_number += 2;
7936 ref_point += iso_interval_us * 2;
7937 sdu_timestamp += sdu_interval;
7938 testdata_indx = testdata_size;
7939 testdata_size += sdu_fragment_data_size;
7940
7941 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
7942 &testdata[testdata_indx],
7943 (testdata_size - testdata_indx),
7944 sdu_total_size,
7945 sdu_packet_number,
7946 sdu_timestamp,
7947 sdu_timestamp,
7948 ref_point,
7949 event_number,
7950 &tx_sdu_frag_buf.sdu_tx);
7951
7952 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
7953
7954 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7955
7956 /* Test segmentation (Black Box) */
7957 /* Valid PDUs */
7958 /* PDU 11 */
7959
7960 ZASSERT_PDU_EMIT_TEST(history[1],
7961 &tx_pdu_meta_buf[1].node_tx,
7962 payload_number,
7963 sdu_fragments,
7964 PDU_BIS_LLID_FRAMED,
7965 pdu_write_end,
7966 isoal_global.source_state[source_hdl].session.handle);
7967
7968 /* PDU release not expected (No Error) */
7969 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
7970
7971 /* PDU 12 */
7972 payload_number++;
7973 pdu_event_number++;
7974 pdu_ref_point += iso_interval_us;
7975 seg_hdr[0].sc = 0;
7976 seg_hdr[0].cmplt = 0;
7977 seg_hdr[0].timeoffset = pdu_ref_point - sdu_timestamp;
7978 seg_hdr[0].len = 3;
7979 sdu_read_loc = testdata_indx;
7980 pdu_hdr_loc = 0;
7981 pdu_write_end = testdata_size - testdata_indx + PDU_ISO_SEG_HDR_SIZE +
7982 PDU_ISO_SEG_TIMEOFFSET_SIZE;
7983 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
7984 sdu_fragments = 1;
7985
7986 ZASSERT_PDU_WRITE_TEST(history[9],
7987 pdu_buffer[0],
7988 pdu_hdr_loc,
7989 &seg_hdr[0],
7990 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
7991
7992 ZASSERT_PDU_WRITE_TEST(history[10],
7993 pdu_buffer[0],
7994 pdu_write_loc,
7995 &testdata[sdu_read_loc],
7996 (pdu_write_end - pdu_write_loc));
7997
7998 seg_hdr[0].cmplt = 1;
7999 seg_hdr[0].len += (pdu_write_end - pdu_write_loc);
8000
8001 ZASSERT_PDU_WRITE_TEST(history[11],
8002 pdu_buffer[0],
8003 pdu_hdr_loc,
8004 &seg_hdr[0],
8005 PDU_ISO_SEG_HDR_SIZE);
8006
8007 /* PDU should not be emitted */
8008 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2);
8009
8010 /* PDU release not expected (No Error) */
8011 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
8012
8013 /* Send Event Timeout ----------------------------------------------- */
8014 isoal_tx_event_prepare(source_hdl, pdu_event_number - 1);
8015
8016 /* PDU should not be emitted */
8017 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2);
8018
8019 /* PDU release not expected (No Error) */
8020 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
8021
8022 /* SDU 3 -------------------------------------------------------------*/
8023 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]);
8024 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]);
8025 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
8026 sdu_packet_number++;
8027 event_number += 2;
8028 ref_point += iso_interval_us * 2;
8029 sdu_timestamp += sdu_interval;
8030 sdu_total_size = sdu_fragment_data_size;
8031 testdata_indx = testdata_size;
8032 testdata_size += sdu_fragment_data_size;
8033
8034 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
8035 &testdata[testdata_indx],
8036 (testdata_size - testdata_indx),
8037 sdu_total_size,
8038 sdu_packet_number,
8039 sdu_timestamp,
8040 sdu_timestamp,
8041 ref_point,
8042 event_number,
8043 &tx_sdu_frag_buf.sdu_tx);
8044
8045 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
8046
8047 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8048
8049 /* Test segmentation (Black Box) */
8050 /* Valid PDUs */
8051 /* PDU 12 */
8052 ZASSERT_PDU_EMIT_TEST(history[2],
8053 &tx_pdu_meta_buf[0].node_tx,
8054 payload_number,
8055 sdu_fragments,
8056 PDU_BIS_LLID_FRAMED,
8057 pdu_write_end,
8058 isoal_global.source_state[source_hdl].session.handle);
8059
8060 /* PDU 13 */
8061 payload_number++;
8062
8063 /* Padding PDU */
8064 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(4);
8065 ZASSERT_PDU_EMIT_TEST(history[3],
8066 &tx_pdu_meta_buf[1].node_tx,
8067 payload_number,
8068 0,
8069 PDU_BIS_LLID_FRAMED,
8070 0,
8071 isoal_global.source_state[source_hdl].session.handle);
8072
8073 /* PDU release not expected (No Error) */
8074 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
8075
8076 /* PDU 14 */
8077 payload_number++;
8078 pdu_event_number++;
8079 pdu_ref_point += iso_interval_us;
8080 seg_hdr[1].sc = 0;
8081 seg_hdr[1].cmplt = 0;
8082 seg_hdr[1].timeoffset = pdu_ref_point - sdu_timestamp;
8083 seg_hdr[1].len = 3;
8084 sdu_read_loc = testdata_indx;
8085 pdu_hdr_loc = 0;
8086 pdu_write_end = testdata_size - testdata_indx + PDU_ISO_SEG_HDR_SIZE +
8087 PDU_ISO_SEG_TIMEOFFSET_SIZE;
8088 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
8089 sdu_fragments = 1;
8090
8091 ZASSERT_PDU_WRITE_TEST(history[12],
8092 pdu_buffer[2],
8093 pdu_hdr_loc,
8094 &seg_hdr[1],
8095 PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE);
8096
8097 ZASSERT_PDU_WRITE_TEST(history[13],
8098 pdu_buffer[2],
8099 pdu_write_loc,
8100 &testdata[sdu_read_loc],
8101 (pdu_write_end - pdu_write_loc));
8102
8103 seg_hdr[1].cmplt = 1;
8104 seg_hdr[1].len += (pdu_write_end - pdu_write_loc);
8105
8106 ZASSERT_PDU_WRITE_TEST(history[14],
8107 pdu_buffer[2],
8108 pdu_hdr_loc,
8109 &seg_hdr[1],
8110 PDU_ISO_SEG_HDR_SIZE);
8111
8112 /* PDU should not be emitted */
8113 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(4);
8114
8115 /* PDU release not expected (No Error) */
8116 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
8117
8118 /* Send Event Timeout ----------------------------------------------- */
8119 isoal_tx_event_prepare(source_hdl, pdu_event_number);
8120
8121
8122 ZASSERT_PDU_EMIT_TEST(history[4],
8123 &tx_pdu_meta_buf[2].node_tx,
8124 payload_number,
8125 sdu_fragments,
8126 PDU_BIS_LLID_FRAMED,
8127 pdu_write_end,
8128 isoal_global.source_state[source_hdl].session.handle);
8129
8130 /* PDU 5 */
8131 payload_number++;
8132
8133 /* Padding PDU */
8134 ZASSERT_PDU_EMIT_TEST(history[5],
8135 &tx_pdu_meta_buf[0].node_tx,
8136 payload_number,
8137 0,
8138 PDU_BIS_LLID_FRAMED,
8139 0,
8140 isoal_global.source_state[source_hdl].session.handle);
8141
8142 /* PDU release not expected (No Error) */
8143 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
8144 }
8145
8146 /**
8147 * Test Suite : TX framed EBQ test IAL-CIS-FRA-PER-BV07C
8148 *
8149 * Tests packing multiple SDU segments into the same PDU and release on event
8150 * timeout.
8151 */
ZTEST(test_tx_framed_ebq,test_tx_framed_cis_fra_per_bv07c)8152 ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c)
8153 {
8154 uint8_t testdata[40];
8155 struct tx_pdu_meta_buffer tx_pdu_meta_buf;
8156 struct tx_sdu_frag_buffer tx_sdu_frag_buf;
8157 struct isoal_pdu_buffer pdu_buffer;
8158 isoal_source_handle_t source_hdl;
8159 struct pdu_iso_sdu_sh seg_hdr[2];
8160 isoal_sdu_len_t sdu_total_size;
8161 isoal_pdu_len_t pdu_write_size;
8162 uint32_t stream_sync_delay;
8163 uint64_t sdu_packet_number;
8164 uint32_t group_sync_delay;
8165 uint16_t iso_interval_int;
8166 uint64_t payload_number;
8167 uint32_t sdu_timestamp;
8168 uint16_t testdata_indx;
8169 uint16_t testdata_size;
8170 uint16_t pdu_write_loc;
8171 uint16_t sdu_read_loc;
8172 uint64_t event_number;
8173 uint32_t sdu_interval;
8174 uint8_t sdu_fragments;
8175 uint16_t pdu_hdr_loc;
8176 uint32_t ref_point;
8177 isoal_status_t err;
8178 uint8_t max_octets;
8179 uint8_t role;
8180 uint8_t BN;
8181 uint8_t FT;
8182
8183 /* Settings */
8184 role = ISOAL_ROLE_PERIPHERAL;
8185 iso_interval_int = 800;
8186 sdu_interval = 500000;
8187 max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5;
8188 BN = 1;
8189 FT = 1;
8190 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
8191 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
8192
8193 /* SDU 1 Frag 1 ------------------------------------------------------*/
8194 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
8195 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
8196 init_test_data_buffer(testdata, 40);
8197 (void)memset(seg_hdr, 0, sizeof(seg_hdr));
8198 pdu_buffer.handle = (void *)&tx_pdu_meta_buf.node_tx;
8199 pdu_buffer.pdu = (struct pdu_iso *)tx_pdu_meta_buf.node_tx.pdu;
8200 pdu_buffer.size = TEST_TX_PDU_PAYLOAD_MAX;
8201 sdu_packet_number = 0;
8202 event_number = 0;
8203 sdu_timestamp = 9249;
8204 ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50;
8205 sdu_total_size = 10;
8206 testdata_indx = 0;
8207 testdata_size = 10;
8208 payload_number = event_number * BN;
8209
8210 source_hdl = basic_tx_test_setup(0xADAD, /* Handle */
8211 role, /* Role */
8212 true, /* Framed */
8213 BN, /* BN */
8214 FT, /* FT */
8215 max_octets, /* max_octets */
8216 sdu_interval, /* SDU Interval */
8217 iso_interval_int, /* ISO Interval */
8218 stream_sync_delay, /* Stream Sync Delay */
8219 group_sync_delay); /* Group Sync Delay */
8220
8221 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
8222 &testdata[testdata_indx],
8223 (testdata_size - testdata_indx),
8224 sdu_total_size,
8225 sdu_packet_number,
8226 sdu_timestamp,
8227 sdu_timestamp,
8228 ref_point,
8229 event_number,
8230 &tx_sdu_frag_buf.sdu_tx);
8231
8232 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
8233 SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer);
8234 PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK);
8235 PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK);
8236 PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK);
8237 PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK);
8238
8239 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
8240
8241 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8242
8243 /* Test segmentation (Black Box) */
8244 /* Valid PDUs */
8245 /* PDU 1 */
8246 seg_hdr[0].sc = 0;
8247 seg_hdr[0].cmplt = 0;
8248 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
8249 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
8250 pdu_hdr_loc = 0;
8251 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
8252 sdu_read_loc = 0;
8253 pdu_write_size = pdu_write_loc + testdata_size;
8254 sdu_fragments = 1;
8255
8256 ZASSERT_PDU_WRITE_TEST(history[0],
8257 pdu_buffer,
8258 pdu_hdr_loc,
8259 &seg_hdr[0],
8260 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
8261
8262 ZASSERT_PDU_WRITE_TEST(history[1],
8263 pdu_buffer,
8264 pdu_write_loc,
8265 &testdata[sdu_read_loc],
8266 (pdu_write_size - pdu_write_loc));
8267
8268 seg_hdr[1] = seg_hdr[0];
8269 seg_hdr[1].cmplt = 1;
8270 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
8271
8272 ZASSERT_PDU_WRITE_TEST(history[2],
8273 pdu_buffer,
8274 pdu_hdr_loc,
8275 &seg_hdr[1],
8276 PDU_ISO_SEG_HDR_SIZE);
8277
8278 /* PDU should not be emitted */
8279 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
8280
8281 /* PDU release not expected (No Error) */
8282 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
8283
8284 /* SDU 2 Frag 1 ------------------------------------------------------*/
8285 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
8286 memset(seg_hdr, 0, sizeof(seg_hdr));
8287 sdu_packet_number++;
8288 sdu_timestamp = sdu_timestamp + sdu_interval;
8289 sdu_total_size = 10;
8290 testdata_indx = testdata_size;
8291 testdata_size += 10;
8292
8293 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
8294 &testdata[testdata_indx],
8295 (testdata_size - testdata_indx),
8296 sdu_total_size,
8297 sdu_packet_number,
8298 sdu_timestamp,
8299 sdu_timestamp,
8300 ref_point,
8301 event_number,
8302 &tx_sdu_frag_buf.sdu_tx);
8303
8304 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
8305
8306 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8307
8308 /* Test segmentation (Black Box) */
8309 /* Valid PDUs */
8310 /* PDU 1 - Seg 2 */
8311 seg_hdr[0].sc = 0;
8312 seg_hdr[0].cmplt = 0;
8313 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
8314 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
8315 pdu_hdr_loc = 10 + PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
8316 pdu_write_loc = pdu_hdr_loc + PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
8317 sdu_read_loc = testdata_indx;
8318 pdu_write_size = pdu_write_loc + 10;
8319 sdu_fragments++;
8320
8321 /* PDU should not be allocated */
8322
8323 ZASSERT_PDU_WRITE_TEST(history[3],
8324 pdu_buffer,
8325 pdu_hdr_loc,
8326 &seg_hdr[0],
8327 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
8328
8329 ZASSERT_PDU_WRITE_TEST(history[4],
8330 pdu_buffer,
8331 pdu_write_loc,
8332 &testdata[sdu_read_loc],
8333 (pdu_write_size - pdu_write_loc));
8334
8335 seg_hdr[1] = seg_hdr[0];
8336 seg_hdr[1].cmplt = 1;
8337 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
8338
8339 ZASSERT_PDU_WRITE_TEST(history[5],
8340 pdu_buffer,
8341 pdu_hdr_loc,
8342 &seg_hdr[1],
8343 PDU_ISO_SEG_HDR_SIZE);
8344
8345 /* PDU emit not expected */
8346 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0);
8347
8348 /* PDU release not expected (No Error) */
8349 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
8350
8351 /* Test PDU release */
8352 isoal_tx_event_prepare(source_hdl, event_number);
8353
8354 ZASSERT_PDU_EMIT_TEST(history[0],
8355 &tx_pdu_meta_buf.node_tx,
8356 payload_number,
8357 sdu_fragments,
8358 PDU_BIS_LLID_FRAMED,
8359 pdu_write_size,
8360 isoal_global.source_state[source_hdl].session.handle);
8361
8362 /* SDU 3 Frag 1 ------------------------------------------------------*/
8363 isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf);
8364 isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf);
8365 memset(seg_hdr, 0, sizeof(seg_hdr));
8366 event_number++;
8367 sdu_packet_number++;
8368 sdu_timestamp = sdu_timestamp + sdu_interval;
8369 ref_point = ref_point + (iso_interval_int * ISO_INT_UNIT_US);
8370 sdu_total_size = 20;
8371 testdata_indx = testdata_size;
8372 testdata_size += 20;
8373
8374 isoal_test_create_sdu_fagment(BT_ISO_SINGLE,
8375 &testdata[testdata_indx],
8376 (testdata_size - testdata_indx),
8377 sdu_total_size,
8378 sdu_packet_number,
8379 sdu_timestamp,
8380 sdu_timestamp,
8381 ref_point,
8382 event_number,
8383 &tx_sdu_frag_buf.sdu_tx);
8384
8385 err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx);
8386
8387 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8388
8389 /* Test segmentation (Black Box) */
8390 /* Valid PDUs */
8391 /* PDU 1 - Seg 2 */
8392 seg_hdr[0].sc = 0;
8393 seg_hdr[0].cmplt = 0;
8394 seg_hdr[0].timeoffset = ref_point - sdu_timestamp;
8395 seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE;
8396 pdu_hdr_loc = 0;
8397 pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE;
8398 sdu_read_loc = testdata_indx;
8399 pdu_write_size = pdu_write_loc + sdu_total_size;
8400 sdu_fragments = 1;
8401 payload_number++;
8402
8403 ZASSERT_PDU_WRITE_TEST(history[6],
8404 pdu_buffer,
8405 pdu_hdr_loc,
8406 &seg_hdr[0],
8407 (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE));
8408
8409 ZASSERT_PDU_WRITE_TEST(history[7],
8410 pdu_buffer,
8411 pdu_write_loc,
8412 &testdata[sdu_read_loc],
8413 (pdu_write_size - pdu_write_loc));
8414
8415 seg_hdr[1] = seg_hdr[0];
8416 seg_hdr[1].cmplt = 1;
8417 seg_hdr[1].len += (pdu_write_size - pdu_write_loc);
8418
8419 ZASSERT_PDU_WRITE_TEST(history[8],
8420 pdu_buffer,
8421 pdu_hdr_loc,
8422 &seg_hdr[1],
8423 PDU_ISO_SEG_HDR_SIZE);
8424
8425 /* PDU emit not expected */
8426 ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1);
8427
8428 /* PDU release not expected (No Error) */
8429 ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0);
8430
8431 /* Test PDU release */
8432 isoal_tx_event_prepare(source_hdl, event_number);
8433
8434 ZASSERT_PDU_EMIT_TEST(history[1],
8435 &tx_pdu_meta_buf.node_tx,
8436 payload_number,
8437 sdu_fragments,
8438 PDU_BIS_LLID_FRAMED,
8439 pdu_write_size,
8440 isoal_global.source_state[source_hdl].session.handle);
8441 }
8442