1 /*
2 * Copyright (c) 2022 Demant
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 FAKE_VALUE_FUNC(isoal_status_t,
8 sink_sdu_alloc_test,
9 const struct isoal_sink *,
10 const struct isoal_pdu_rx *,
11 struct isoal_sdu_buffer *);
12
13 static struct {
14 struct isoal_sdu_buffer *out[6];
15 size_t buffer_size;
16 size_t pos;
17
18 } custom_sink_sdu_alloc_test_output_buffer;
19
push_custom_sink_sdu_alloc_test_output_buffer(struct isoal_sdu_buffer * buf)20 static void push_custom_sink_sdu_alloc_test_output_buffer(struct isoal_sdu_buffer *buf)
21 {
22 custom_sink_sdu_alloc_test_output_buffer
23 .out[custom_sink_sdu_alloc_test_output_buffer.buffer_size++] = buf;
24 zassert_true(custom_sink_sdu_alloc_test_output_buffer.buffer_size <=
25 ARRAY_SIZE(custom_sink_sdu_alloc_test_output_buffer.out),
26 NULL);
27 }
28 /**
29 * Callback test fixture to be provided for RX sink creation. Allocates a new
30 * SDU buffer.
31 * @param[in] sink_ctx Sink context provided by ISO-AL
32 * @param[in] valid_pdu PDU currently being reassembled
33 * @param[out] sdu_buffer SDU buffer information return structure
34 * @return Status of operation
35 */
custom_sink_sdu_alloc_test(const struct isoal_sink * sink_ctx,const struct isoal_pdu_rx * valid_pdu,struct isoal_sdu_buffer * sdu_buffer)36 static isoal_status_t custom_sink_sdu_alloc_test(const struct isoal_sink *sink_ctx,
37 const struct isoal_pdu_rx *valid_pdu,
38 struct isoal_sdu_buffer *sdu_buffer)
39 {
40 isoal_test_debug_trace_func_call(__func__, "IN");
41
42 /* Return SDU buffer details as provided by the test */
43 zassert_not_null(sdu_buffer, NULL);
44 zassert_true(custom_sink_sdu_alloc_test_output_buffer.pos <
45 custom_sink_sdu_alloc_test_output_buffer.buffer_size,
46 NULL);
47 memcpy(sdu_buffer,
48 custom_sink_sdu_alloc_test_output_buffer
49 .out[custom_sink_sdu_alloc_test_output_buffer.pos++],
50 sizeof(*sdu_buffer));
51
52 return sink_sdu_alloc_test_fake.return_val;
53 }
54
55 #define ZASSERT_ISOAL_SDU_ALLOC_TEST(_typ, _sink, _pdu) \
56 zassert_equal_ptr(_sink, \
57 sink_sdu_alloc_test_fake.arg0_##_typ, \
58 "\t\tExpected alloc sink at %p, got %p.", \
59 _sink, \
60 sink_sdu_alloc_test_fake.arg0_##_typ); \
61 zassert_equal_ptr(_pdu, \
62 sink_sdu_alloc_test_fake.arg1_##_typ, \
63 "\t\tExpected alloc PDU buffer at %p, got %p.", \
64 _pdu, \
65 sink_sdu_alloc_test_fake.arg1_##_typ)
66
67 #define ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(_expected) \
68 zassert_equal(_expected, \
69 sink_sdu_alloc_test_fake.call_count, \
70 "Expected alloc called %u times, actual %u.", \
71 _expected, \
72 sink_sdu_alloc_test_fake.call_count)
73
74 FAKE_VALUE_FUNC(isoal_status_t,
75 sink_sdu_emit_test,
76 const struct isoal_sink *,
77 const struct isoal_emitted_sdu_frag *,
78 const struct isoal_emitted_sdu *);
79
80 /**
81 * This handler is called by custom_sink_sdu_emit_test using the non pointer versions of the
82 * function's arguments. The tests are asserting on the argument content, since sink_sdu_emit_test()
83 * is called multiple times with the same pointer (but different content) this additional fake is
84 * used to store the history of the content.
85 */
86 FAKE_VOID_FUNC(sink_sdu_emit_test_handler,
87 struct isoal_sink,
88 struct isoal_emitted_sdu_frag,
89 struct isoal_emitted_sdu);
90
91 /**
92 * Callback test fixture to be provided for RX sink creation. Emits provided
93 * SDU in buffer
94 * @param[in] sink_ctx Sink context provided by ISO-AL
95 * @param[in] valid_sdu SDU buffer and details of SDU to be emitted
96 * @return Status of operation
97 */
custom_sink_sdu_emit_test(const struct isoal_sink * sink_ctx,const struct isoal_emitted_sdu_frag * sdu_frag,const struct isoal_emitted_sdu * sdu)98 static isoal_status_t custom_sink_sdu_emit_test(const struct isoal_sink *sink_ctx,
99 const struct isoal_emitted_sdu_frag *sdu_frag,
100 const struct isoal_emitted_sdu *sdu)
101 {
102 isoal_test_debug_trace_func_call(__func__, "IN");
103
104 isoal_test_debug_print_rx_sdu(sink_ctx, sdu_frag, sdu);
105 sink_sdu_emit_test_handler(*sink_ctx, *sdu_frag, *sdu);
106
107 return sink_sdu_emit_test_fake.return_val;
108 }
109
110 #define ZASSERT_ISOAL_SDU_EMIT_TEST(_typ, \
111 _sink, \
112 _state, \
113 _frag_sz, \
114 _frag_status, \
115 _timestamp, \
116 _sn, \
117 _dbuf, \
118 _dbuf_sz, \
119 _total_sz, \
120 _sdu_status) \
121 zassert_equal_ptr(_sink, \
122 sink_sdu_emit_test_fake.arg0_##_typ, \
123 "\t\tExpected sink at %p, got %p.", \
124 _sink, \
125 sink_sdu_emit_test_fake.arg0_##_typ); \
126 zassert_equal(_state, \
127 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_state, \
128 "\t\tExpected SDU state '%s', got '%s'.", \
129 STATE_TO_STR(_state), \
130 STATE_TO_STR(sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_state)); \
131 zassert_equal(_frag_sz, \
132 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_frag_size, \
133 "\t\tExpected SDU frag of size %u, got %u.", \
134 _frag_sz, \
135 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_frag_size); \
136 zassert_equal(_frag_status, \
137 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.status, \
138 "\t\tExpected SDU with status '%s', got '%s'.", \
139 DU_ERR_TO_STR(_frag_status), \
140 DU_ERR_TO_STR(sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.status)); \
141 zassert_equal(_timestamp, \
142 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.timestamp, \
143 "\t\tExpected SDU with timestamp %u, got %u.", \
144 _timestamp, \
145 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.timestamp); \
146 zassert_equal(_sn, \
147 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.sn, \
148 "\t\tExpected SDU with sequence number %u, got %u.", \
149 _sn, \
150 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.sn); \
151 zassert_equal_ptr(_dbuf, \
152 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf, \
153 "\t\tExpected SDU data buffer at %p, got %p.", \
154 _dbuf, \
155 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf); \
156 zassert_equal(_dbuf_sz, \
157 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.size, \
158 "\t\tExpected SDU data buffer of size %u, got %u.", \
159 _dbuf_sz, \
160 sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.size); \
161 zassert_equal(_total_sz, \
162 sink_sdu_emit_test_handler_fake.arg2_##_typ.total_sdu_size, \
163 "\t\tExpected total size of SDU %u,got %u.", \
164 _total_sz, \
165 sink_sdu_emit_test_handler_fake.arg2_##_typ.total_sdu_size); \
166 zassert_equal(_sdu_status, \
167 sink_sdu_emit_test_handler_fake.arg2_##_typ.collated_status, \
168 "\t\tExpected SDU with status '%s', got '%s'.", \
169 DU_ERR_TO_STR(_sdu_status), \
170 DU_ERR_TO_STR(sink_sdu_emit_test_handler_fake.arg2_##_typ.collated_status))
171
172 #define ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(_expected) \
173 zassert_equal(_expected, \
174 sink_sdu_emit_test_fake.call_count, \
175 "Expected emit called %u times, actual %u.", \
176 _expected, \
177 sink_sdu_emit_test_fake.call_count)
178
179 FAKE_VALUE_FUNC(isoal_status_t, sink_sdu_write_test, void *, const size_t,
180 const uint8_t *, const size_t);
181 /**
182 * Callback test fixture to be provided for RX sink creation. Writes provided
183 * data into target SDU buffer.
184 * @param dbuf SDU buffer (Includes current write location field)
185 * @param sdu_written Number of bytes already written to this SDU
186 * @param pdu_payload Current PDU being reassembled by ISO-AL
187 * @param consume_len Length of data to transfer
188 * @return Status of the operation
189 */
190 static isoal_status_t
custom_sink_sdu_write_test(void * dbuf,const size_t sdu_written,const uint8_t * pdu_payload,const size_t consume_len)191 custom_sink_sdu_write_test(void *dbuf, const size_t sdu_written,
192 const uint8_t *pdu_payload, const size_t consume_len)
193 {
194 isoal_test_debug_trace_func_call(__func__, "IN");
195
196 #if defined(DEBUG_TEST)
197 zassert_not_null(dbuf, "");
198 zassert_not_null(pdu_payload, "");
199
200 struct rx_sdu_frag_buffer *rx_sdu_frag_buf;
201
202 rx_sdu_frag_buf = (struct rx_sdu_frag_buffer *)dbuf;
203 memcpy(&rx_sdu_frag_buf->sdu[rx_sdu_frag_buf->write_loc], pdu_payload, consume_len);
204 rx_sdu_frag_buf->write_loc += consume_len;
205 #endif
206
207 return sink_sdu_write_test_fake.return_val;
208 }
209
210 #define ZASSERT_ISOAL_SDU_WRITE_TEST(_typ, _frag_buf, _sdu_written, _payload_buf, _length) \
211 zassert_equal_ptr(_frag_buf, \
212 sink_sdu_write_test_fake.arg0_##_typ, \
213 "\t\tExpected write buffer at %p, got %p.", \
214 _frag_buf, \
215 sink_sdu_write_test_fake.arg0_##_typ); \
216 zassert_equal(_sdu_written, \
217 sink_sdu_write_test_fake.arg1_##_typ, \
218 "\t\tExpected sdu_written of %u, got %u.", \
219 _sdu_written, \
220 sink_sdu_write_test_fake.arg1_##_typ); \
221 zassert_equal_ptr(_payload_buf, \
222 sink_sdu_write_test_fake.arg2_##_typ, \
223 "\t\tExpected write source at %p, got %p.", \
224 _payload_buf, \
225 sink_sdu_write_test_fake.arg2_##_typ); \
226 zassert_equal(_length, \
227 sink_sdu_write_test_fake.arg3_##_typ, \
228 "\t\tExpected write length of %u, got %u.", \
229 _length, \
230 sink_sdu_write_test_fake.arg3_##_typ)
231
232 #define ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(_expected) \
233 zassert_equal(_expected, \
234 sink_sdu_write_test_fake.call_count, \
235 "Expected write called %u times, actual %u.", \
236 _expected, \
237 sink_sdu_write_test_fake.call_count)
238
239 /**
240 * RX common setup before running tests
241 * @param f Input configuration parameters
242 */
isoal_test_rx_common_before(void * f)243 static void isoal_test_rx_common_before(void *f)
244 {
245 ARG_UNUSED(f);
246
247 custom_sink_sdu_alloc_test_output_buffer.buffer_size = 0;
248 custom_sink_sdu_alloc_test_output_buffer.pos = 0;
249 RESET_FAKE(sink_sdu_alloc_test);
250 RESET_FAKE(sink_sdu_write_test);
251 RESET_FAKE(sink_sdu_emit_test);
252 RESET_FAKE(sink_sdu_emit_test_handler);
253
254 FFF_RESET_HISTORY();
255
256 sink_sdu_alloc_test_fake.custom_fake = custom_sink_sdu_alloc_test;
257 sink_sdu_write_test_fake.custom_fake = custom_sink_sdu_write_test;
258 sink_sdu_emit_test_fake.custom_fake = custom_sink_sdu_emit_test;
259 }
260
261 /**
262 * Cacluate RX latency based on role and framing
263 * @param role Peripheral / Central / Broadcast
264 * @param framed PDU framing (Framed / Unframed)
265 * @param flush_timeout FT
266 * @param sdu_interval SDU Interval (us)
267 * @param iso_interval_int ISO Interval (Integer multiple of 1250us)
268 * @param stream_sync_delay CIS / BIS sync delay
269 * @param group_sync_delay CIG / BIG sync delay
270 * @return Latency (signed)
271 */
calc_rx_latency_by_role(uint8_t role,uint8_t framed,uint8_t flush_timeout,uint32_t sdu_interval,uint16_t iso_interval_int,uint32_t stream_sync_delay,uint32_t group_sync_delay)272 static int32_t calc_rx_latency_by_role(uint8_t role,
273 uint8_t framed,
274 uint8_t flush_timeout,
275 uint32_t sdu_interval,
276 uint16_t iso_interval_int,
277 uint32_t stream_sync_delay,
278 uint32_t group_sync_delay)
279 {
280 int32_t latency;
281 uint32_t iso_interval;
282
283 latency = 0;
284 iso_interval = iso_interval_int * ISO_INT_UNIT_US;
285
286 switch (role) {
287 case ISOAL_ROLE_PERIPHERAL:
288 if (framed) {
289 latency = stream_sync_delay + sdu_interval + (flush_timeout * iso_interval);
290 } else {
291 latency = stream_sync_delay + ((flush_timeout - 1) * iso_interval);
292 }
293 break;
294
295 case ISOAL_ROLE_CENTRAL:
296 if (framed) {
297 latency = stream_sync_delay - group_sync_delay;
298 } else {
299 latency = stream_sync_delay - group_sync_delay -
300 (((iso_interval / sdu_interval) - 1) * iso_interval);
301 }
302 break;
303
304 case ISOAL_ROLE_BROADCAST_SINK:
305 if (framed) {
306 latency = group_sync_delay + sdu_interval + iso_interval;
307 } else {
308 latency = group_sync_delay;
309 }
310 break;
311
312 default:
313 zassert_unreachable("Invalid role!");
314 break;
315 }
316
317 #if defined(DEBUG_TEST)
318 PRINT("Latency %s calculated %dus.\n", framed ? "framed" : "unframed", latency);
319 PRINT("\tFT %d\n\tISO Interval %dus\n\tSDU Interval %dus"
320 "\n\tStream Sync Delay %dus\n\tGroup Sync Delay %dus\n\n",
321 flush_timeout,
322 iso_interval,
323 sdu_interval,
324 stream_sync_delay,
325 group_sync_delay);
326 #endif
327
328 return latency;
329 }
330
get_next_time_offset(uint32_t time_offset,uint32_t iso_interval_us,uint32_t sdu_interval_us,bool next_event_expected)331 static uint32_t get_next_time_offset(uint32_t time_offset,
332 uint32_t iso_interval_us,
333 uint32_t sdu_interval_us,
334 bool next_event_expected)
335 {
336 uint32_t result;
337
338 if (time_offset > sdu_interval_us) {
339 result = time_offset - sdu_interval_us;
340 #if defined(DEBUG_TEST)
341 PRINT("Increment time offset for same event %lu --> %lu\n", time_offset, result);
342 #endif
343 zassert_false(next_event_expected);
344 } else {
345 result = time_offset + iso_interval_us - sdu_interval_us;
346 #if defined(DEBUG_TEST)
347 PRINT("Increment time offset for next event %lu --> %lu\n", time_offset, result);
348 #endif
349 zassert_true(next_event_expected);
350 }
351
352 return result;
353 }
354
355 /**
356 * @breif Wrapper to test time wrapping
357 * @param time_now Current time value
358 * @param time_diff Time difference (signed)
359 * @return Wrapped time after difference
360 */
isoal_get_wrapped_time_test(uint32_t time_now,int32_t time_diff)361 static uint32_t isoal_get_wrapped_time_test(uint32_t time_now, int32_t time_diff)
362 {
363 uint32_t result = isoal_get_wrapped_time_us(time_now, time_diff);
364
365 #if defined(DEBUG_TEST)
366 PRINT("[isoal_get_wrapped_time_us] time_now %12lu time_diff %12ld result %lu\n",
367 time_now,
368 time_diff,
369 result);
370 #endif
371
372 return result;
373 }
374
375 /**
376 * Basic setup of a single sink for any RX test
377 * @param handle Stream handle
378 * @param role Peripheral / Central / Broadcast
379 * @param framed PDU framing
380 * @param burst_number BN
381 * @param flush_timeout FT
382 * @param sdu_interval SDU Interval (us)
383 * @param iso_interval_int ISO Interval (integer multiple of 1250us)
384 * @param stream_sync_delay CIS / BIS sync delay
385 * @param group_sync_delay CIG / BIG sync delay
386 * @return Newly created sink handle
387 */
basic_rx_test_setup(uint16_t handle,uint8_t role,uint8_t framed,uint8_t burst_number,uint8_t flush_timeout,uint32_t sdu_interval,uint16_t iso_interval_int,uint32_t stream_sync_delay,uint32_t group_sync_delay)388 static isoal_sink_handle_t basic_rx_test_setup(uint16_t handle,
389 uint8_t role,
390 uint8_t framed,
391 uint8_t burst_number,
392 uint8_t flush_timeout,
393 uint32_t sdu_interval,
394 uint16_t iso_interval_int,
395 uint32_t stream_sync_delay,
396 uint32_t group_sync_delay)
397 {
398 isoal_sink_handle_t sink_hdl;
399 isoal_status_t err;
400
401 #if defined(DEBUG_TEST)
402 PRINT("RX Test Setup:\n\tHandle 0x%04x\n\tRole %s\n\tFraming %s"
403 "\n\tBN %u\n\tFT %d\n\tISO Interval %dus\n\tSDU Interval %dus"
404 "\n\tStream Sync Delay %dus\n\tGroup Sync Delay %dus\n\n",
405 handle,
406 ROLE_TO_STR(role),
407 framed ? "Framed" : "Unframed",
408 burst_number,
409 flush_timeout,
410 (iso_interval_int * ISO_INT_UNIT_US),
411 sdu_interval,
412 stream_sync_delay,
413 group_sync_delay);
414 #endif
415
416 ztest_set_assert_valid(false);
417
418 err = isoal_init();
419 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
420
421 err = isoal_reset();
422 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
423
424 /* Create a sink based on global parameters */
425 err = isoal_sink_create(handle,
426 role,
427 framed,
428 burst_number,
429 flush_timeout,
430 sdu_interval,
431 iso_interval_int,
432 stream_sync_delay,
433 group_sync_delay,
434 sink_sdu_alloc_test,
435 sink_sdu_emit_test,
436 sink_sdu_write_test,
437 &sink_hdl);
438 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
439
440 /* Enable newly created sink */
441 isoal_sink_enable(sink_hdl);
442
443 return sink_hdl;
444 }
445
446 /**
447 * Test Suite : RX basic test
448 *
449 * Test creating and destroying sinks upto the maximum with randomized
450 * configuration parameters.
451 */
ZTEST(test_rx_basics,test_sink_isoal_test_create_destroy)452 ZTEST(test_rx_basics, test_sink_isoal_test_create_destroy)
453 {
454 isoal_sink_handle_t sink_hdl[CONFIG_BT_CTLR_ISOAL_SINKS];
455 uint32_t stream_sync_delay;
456 uint32_t group_sync_delay;
457 uint8_t sdu_interval_int;
458 uint8_t iso_interval_int;
459 uint8_t flush_timeout;
460 uint32_t iso_interval;
461 uint32_t sdu_interval;
462 uint8_t burst_number;
463 uint8_t pdus_per_sdu;
464 isoal_status_t res;
465 uint16_t handle;
466 int32_t latency;
467 bool framed;
468
469 res = isoal_init();
470 zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res);
471
472 res = isoal_reset();
473 zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res);
474
475 for (int role = 0; role <= 3; role++) {
476 /* 0 Central
477 * 1 Peripheral
478 * 2 Broadcast
479 * 3 Undefined
480 */
481 handle = 0x8000;
482 burst_number = 0;
483 flush_timeout = 1;
484 framed = false;
485 sdu_interval_int = 1;
486 iso_interval_int = 1;
487 iso_interval = iso_interval_int * ISO_INT_UNIT_US;
488 sdu_interval = sdu_interval_int * ISO_INT_UNIT_US;
489 stream_sync_delay = iso_interval - 200;
490 group_sync_delay = iso_interval - 50;
491 latency = 0;
492
493 ztest_set_assert_valid(false);
494
495 for (int i = 0; i < CONFIG_BT_CTLR_ISOAL_SINKS; i++) {
496 res = ISOAL_STATUS_ERR_UNSPECIFIED;
497 sink_hdl[i] = 0xFF;
498
499 pdus_per_sdu = (burst_number * sdu_interval) / iso_interval;
500
501 switch (role) {
502 case ISOAL_ROLE_PERIPHERAL:
503 case ISOAL_ROLE_CENTRAL:
504 case ISOAL_ROLE_BROADCAST_SINK:
505 latency = calc_rx_latency_by_role(role,
506 framed,
507 flush_timeout,
508 sdu_interval,
509 iso_interval_int,
510 stream_sync_delay,
511 group_sync_delay);
512 break;
513
514 default:
515 ztest_set_assert_valid(true);
516 break;
517 }
518
519 res = isoal_sink_create(handle,
520 role,
521 framed,
522 burst_number,
523 flush_timeout,
524 sdu_interval,
525 iso_interval_int,
526 stream_sync_delay,
527 group_sync_delay,
528 sink_sdu_alloc_test,
529 sink_sdu_emit_test,
530 sink_sdu_write_test,
531 &sink_hdl[i]);
532
533 zassert_equal(isoal_global.sink_allocated[sink_hdl[i]],
534 ISOAL_ALLOC_STATE_TAKEN,
535 "");
536
537 zassert_equal(isoal_global.sink_state[sink_hdl[i]].session.pdus_per_sdu,
538 pdus_per_sdu,
539 "%s pdus_per_sdu %d should be %d for:\n\tBN %d\n\tFT %d"
540 "\n\tISO Interval %dus\n\tSDU Interval %dus\n\tStream Sync "
541 "Delay %dus"
542 "\n\tGroup Sync Delay %dus",
543 (framed ? "Framed" : "Unframed"),
544 isoal_global.sink_state[sink_hdl[i]].session.pdus_per_sdu,
545 pdus_per_sdu,
546 burst_number,
547 flush_timeout,
548 iso_interval,
549 sdu_interval,
550 stream_sync_delay,
551 group_sync_delay);
552
553 if (framed) {
554 zassert_equal(
555 isoal_global.sink_state[sink_hdl[i]].session.sdu_sync_const,
556 latency,
557 "%s latency framed %d should be %d",
558 ROLE_TO_STR(role),
559 isoal_global.sink_state[sink_hdl[i]].session.sdu_sync_const,
560 latency);
561 } else {
562 zassert_equal(
563 isoal_global.sink_state[sink_hdl[i]].session.sdu_sync_const,
564 latency,
565 "%s latency unframed %d should be %d",
566 ROLE_TO_STR(role),
567 isoal_global.sink_state[sink_hdl[i]].session.sdu_sync_const,
568 latency);
569 }
570
571 zassert_equal(res,
572 ISOAL_STATUS_OK,
573 "Sink %d in role %s creation failed!",
574 i,
575 ROLE_TO_STR(role));
576
577 isoal_sink_enable(sink_hdl[i]);
578
579 zassert_equal(isoal_global.sink_state[sink_hdl[i]].sdu_production.mode,
580 ISOAL_PRODUCTION_MODE_ENABLED,
581 "Sink %d in role %s enable failed!",
582 i,
583 ROLE_TO_STR(role));
584
585 framed = !framed;
586 burst_number++;
587 flush_timeout = (flush_timeout % 3) + 1;
588 sdu_interval_int++;
589 iso_interval_int = iso_interval_int * sdu_interval_int;
590 sdu_interval = (sdu_interval_int * ISO_INT_UNIT_US) - (framed ? 100 : 0);
591 iso_interval = iso_interval_int * ISO_INT_UNIT_US;
592 stream_sync_delay = iso_interval - (200 * i);
593 group_sync_delay = iso_interval - 50;
594 }
595
596 /* Destroy in order */
597 for (int i = 0; i < CONFIG_BT_CTLR_ISOAL_SINKS; i++) {
598 isoal_sink_destroy(sink_hdl[i]);
599
600 zassert_equal(isoal_global.sink_allocated[sink_hdl[i]],
601 ISOAL_ALLOC_STATE_FREE,
602 "Sink destruction failed!");
603
604 zassert_equal(isoal_global.sink_state[sink_hdl[i]].sdu_production.mode,
605 ISOAL_PRODUCTION_MODE_DISABLED,
606 "Sink disable failed!");
607 }
608 }
609 }
610
611 /**
612 * Test Suite : RX basic test
613 *
614 * Test error return on exceeding the maximum number of sinks available.
615 */
ZTEST(test_rx_basics,test_sink_isoal_test_create_err)616 ZTEST(test_rx_basics, test_sink_isoal_test_create_err)
617 {
618 isoal_sink_handle_t sink_hdl[CONFIG_BT_CTLR_ISOAL_SINKS + 1];
619 uint32_t stream_sync_delay;
620 uint32_t group_sync_delay;
621 uint8_t iso_interval_int;
622 uint8_t flush_timeout;
623 uint32_t sdu_interval;
624 uint8_t burst_number;
625 isoal_status_t res;
626 uint16_t handle;
627 uint8_t role;
628 bool framed;
629
630 handle = 0x8000;
631 role = ISOAL_ROLE_PERIPHERAL;
632 burst_number = 1;
633 flush_timeout = 1;
634 framed = false;
635 iso_interval_int = 1;
636 sdu_interval = ISO_INT_UNIT_US;
637 stream_sync_delay = ISO_INT_UNIT_US - 200;
638 group_sync_delay = ISO_INT_UNIT_US - 50;
639
640 res = isoal_init();
641 zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res);
642
643 res = isoal_reset();
644 zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res);
645
646 for (int i = 0; i < CONFIG_BT_CTLR_ISOAL_SINKS; i++) {
647 res = isoal_sink_create(handle,
648 role,
649 framed,
650 burst_number,
651 flush_timeout,
652 sdu_interval,
653 iso_interval_int,
654 stream_sync_delay,
655 group_sync_delay,
656 sink_sdu_alloc_test,
657 sink_sdu_emit_test,
658 sink_sdu_write_test,
659 &sink_hdl[i]);
660
661 zassert_equal(res,
662 ISOAL_STATUS_OK,
663 "Sink %d in role %s creation failed!",
664 i,
665 ROLE_TO_STR(role));
666 }
667
668 res = isoal_sink_create(handle,
669 role,
670 framed,
671 burst_number,
672 flush_timeout,
673 sdu_interval,
674 iso_interval_int,
675 stream_sync_delay,
676 group_sync_delay,
677 sink_sdu_alloc_test,
678 sink_sdu_emit_test,
679 sink_sdu_write_test,
680 &sink_hdl[CONFIG_BT_CTLR_ISOAL_SINKS]);
681
682 zassert_equal(res,
683 ISOAL_STATUS_ERR_SINK_ALLOC,
684 "Sink creation did not return error as expected!");
685 }
686
687 /**
688 * Test Suite : RX basic test
689 *
690 * Test error return when receiving PDUs for a disabled sink.
691 */
ZTEST(test_rx_basics,test_sink_disable)692 ZTEST(test_rx_basics, test_sink_disable)
693 {
694 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
695 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
696 struct isoal_sdu_buffer sdu_buffer;
697 isoal_sink_handle_t sink_hdl;
698 uint32_t stream_sync_delay;
699 uint32_t group_sync_delay;
700 isoal_sdu_len_t sdu_size;
701 uint8_t iso_interval_int;
702 uint64_t payload_number;
703 uint32_t pdu_timestamp;
704 uint32_t sdu_timestamp;
705 uint16_t testdata_indx;
706 uint16_t testdata_size;
707 uint32_t sdu_interval;
708 isoal_sdu_cnt_t seqn;
709 uint8_t testdata[23];
710 isoal_status_t err;
711 uint32_t latency;
712 uint8_t role;
713 uint8_t BN;
714 uint8_t FT;
715
716 /* Settings */
717 role = ISOAL_ROLE_PERIPHERAL;
718 iso_interval_int = 1;
719 sdu_interval = ISO_INT_UNIT_US;
720 BN = 1;
721 FT = 1;
722 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
723 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
724
725 /* PDU 1 -------------------------------------------------------------*/
726 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
727 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
728 init_test_data_buffer(testdata, 23);
729 sdu_buffer.dbuf = &rx_sdu_frag_buf;
730 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
731 payload_number = 2000;
732 pdu_timestamp = 9249;
733 latency = calc_rx_latency_by_role(role,
734 false,
735 FT,
736 sdu_interval,
737 iso_interval_int,
738 stream_sync_delay,
739 group_sync_delay);
740 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
741 seqn = 0;
742 testdata_indx = 0;
743 testdata_size = 23;
744 sdu_size = 0;
745
746 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
747 role, /* Role */
748 false, /* Framed */
749 BN, /* BN */
750 FT, /* FT */
751 sdu_interval, /* SDU Interval */
752 iso_interval_int, /* ISO Interval */
753 stream_sync_delay, /* Stream Sync Delay */
754 group_sync_delay); /* Group Sync Delay */
755
756 /* Disable the sink */
757 isoal_sink_disable(sink_hdl);
758
759 /* Send SDU in a single PDU */
760 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
761 &testdata[testdata_indx],
762 (testdata_size - testdata_indx),
763 payload_number,
764 pdu_timestamp,
765 ISOAL_PDU_STATUS_VALID,
766 &rx_pdu_meta_buf.pdu_meta);
767
768 /* Test recombine (Black Box) */
769 /* Should not allocate a new SDU */
770
771 /* SDU should not be written to */
772
773 /* SDU should not be emitted */
774
775 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
776
777 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
778 }
779
780 /**
781 * Test Suite : RX unframed PDU reassembly
782 *
783 * Tests reassembly of a single valid RX PDU into an SDU.
784 *
785 * Expected Sequence:
786 * -- Total of 1 SDUs released across 1 events
787 * -- Event 1: PDU0 Valid SDU 0 Unframed Single
788 * -----> SDU 0 Valid (Released)
789 *
790 */
ZTEST(test_rx_unframed,test_rx_unframed_single_pdu)791 ZTEST(test_rx_unframed, test_rx_unframed_single_pdu)
792 {
793 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
794 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
795 struct isoal_sdu_buffer sdu_buffer;
796 isoal_sdu_status_t collated_status;
797 isoal_sink_handle_t sink_hdl;
798 uint32_t stream_sync_delay;
799 uint32_t group_sync_delay;
800 isoal_sdu_len_t sdu_size;
801 uint8_t iso_interval_int;
802 uint64_t payload_number;
803 uint16_t total_sdu_size;
804 uint32_t pdu_timestamp;
805 uint32_t sdu_timestamp;
806 uint16_t testdata_indx;
807 uint16_t testdata_size;
808 uint32_t sdu_interval;
809 isoal_sdu_cnt_t seqn;
810 uint8_t testdata[23];
811 isoal_status_t err;
812 uint32_t latency;
813 uint8_t role;
814 uint8_t BN;
815 uint8_t FT;
816
817 /* Settings */
818 role = ISOAL_ROLE_PERIPHERAL;
819 iso_interval_int = 1;
820 sdu_interval = ISO_INT_UNIT_US;
821 BN = 1;
822 FT = 1;
823 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
824 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
825
826 /* PDU 0 -------------------------------------------------------------*/
827 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
828 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
829 init_test_data_buffer(testdata, 23);
830 sdu_buffer.dbuf = &rx_sdu_frag_buf;
831 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
832 payload_number = 2000;
833 pdu_timestamp = 9249;
834 latency = calc_rx_latency_by_role(role,
835 false,
836 FT,
837 sdu_interval,
838 iso_interval_int,
839 stream_sync_delay,
840 group_sync_delay);
841 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
842 seqn = 0;
843 testdata_indx = 0;
844 testdata_size = 23;
845 sdu_size = 23;
846 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
847 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
848
849 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
850 role, /* Role */
851 false, /* Framed */
852 BN, /* BN */
853 FT, /* FT */
854 sdu_interval, /* SDU Interval */
855 iso_interval_int, /* ISO Interval */
856 stream_sync_delay, /* Stream Sync Delay */
857 group_sync_delay); /* Group Sync Delay */
858
859 /* Send SDU in a single PDU */
860 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
861 &testdata[testdata_indx],
862 (testdata_size - testdata_indx),
863 payload_number,
864 pdu_timestamp,
865 ISOAL_PDU_STATUS_VALID,
866 &rx_pdu_meta_buf.pdu_meta);
867
868 /* Set callback function return values */
869 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
870 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
871 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
872 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
873
874 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
875
876 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
877
878 /* SDU 0 -------------------------------------------------------------*/
879 /* Test recombine (Black Box) */
880 /* A new SDU should be allocated */
881 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
882 &isoal_global.sink_state[sink_hdl], /* Sink */
883 &rx_pdu_meta_buf.pdu_meta); /* PDU */
884
885 /* SDU payload should be written */
886 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
887 &rx_sdu_frag_buf, /* SDU buffer */
888 0, /* SDU written */
889 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
890 (testdata_size - testdata_indx)); /* Size */
891 /* SDU should be emitted */
892 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
893 &isoal_global.sink_state[sink_hdl], /* Sink */
894 BT_ISO_SINGLE, /* Frag state */
895 sdu_size, /* Frag size */
896 ISOAL_SDU_STATUS_VALID, /* Frag status */
897 sdu_timestamp, /* Timestamp */
898 seqn, /* Seq. number */
899 sdu_buffer.dbuf, /* Buffer */
900 sdu_buffer.size, /* Buffer size */
901 total_sdu_size, /* Total size */
902 collated_status); /* SDU status */
903
904 /* Test recombine (White Box) */
905 /* No padding PDUs expected, so move to waiting for start fragment */
906 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
907 ISOAL_START,
908 "FSM state %s should be %s!",
909 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
910 FSM_TO_STR(ISOAL_START));
911 }
912
913 /**
914 * Test Suite : RX unframed PDU reassembly
915 *
916 * Tests boundary conditions of time wrapping function
917 */
ZTEST(test_rx_unframed,test_rx_time_wrapping)918 ZTEST(test_rx_unframed, test_rx_time_wrapping)
919 {
920 const uint32_t time_wrapping_point = ISOAL_TIME_WRAPPING_POINT_US;
921 uint32_t expected_result;
922 int32_t time_diff;
923 uint32_t time_now;
924 uint32_t result;
925
926 /* Maximum negative difference from 0 */
927 time_now = 0;
928 time_diff = (time_wrapping_point == UINT32_MAX) ?
929 INT32_MIN :
930 -((int64_t)ISOAL_TIME_WRAPPING_POINT_US);
931 expected_result = ISOAL_TIME_WRAPPING_POINT_US + time_diff + 1;
932 result = isoal_get_wrapped_time_test(time_now, time_diff);
933 zassert_equal(result, expected_result, "%lu != %lu", result, expected_result);
934
935 /* Maximum negative difference from maximum time */
936 time_now = ISOAL_TIME_WRAPPING_POINT_US;
937 time_diff = (time_wrapping_point == UINT32_MAX) ?
938 INT32_MIN :
939 -((int64_t)ISOAL_TIME_WRAPPING_POINT_US);
940 expected_result = ISOAL_TIME_WRAPPING_POINT_US + time_diff;
941 result = isoal_get_wrapped_time_test(time_now, time_diff);
942 zassert_equal(result, expected_result, "%lu != %lu", result, expected_result);
943
944 /* Maximum positive difference from maximum time */
945 time_now = ISOAL_TIME_WRAPPING_POINT_US;
946 time_diff = (time_wrapping_point == UINT32_MAX ? INT32_MAX : ISOAL_TIME_WRAPPING_POINT_US);
947 expected_result = time_diff - 1;
948 result = isoal_get_wrapped_time_test(time_now, time_diff);
949 zassert_equal(result, expected_result, "%lu != %lu", result, expected_result);
950 }
951
952 /**
953 * Test Suite : RX unframed PDU reassembly
954 *
955 * Tests time wrapping in reassembly of a single valid RX PDU into an SDU.
956 *
957 * Expected Sequence:
958 * -- Total of 1 SDUs released across 1 events
959 * -- Event 1: PDU0 Valid SDU 0 Unframed Single
960 * -----> SDU 0 Valid (Released)
961 *
962 */
ZTEST(test_rx_unframed,test_rx_unframed_single_pdu_ts_wrap1)963 ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap1)
964 {
965 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
966 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
967 struct isoal_sdu_buffer sdu_buffer;
968 isoal_sdu_status_t collated_status;
969 isoal_sink_handle_t sink_hdl;
970 uint32_t stream_sync_delay;
971 uint32_t group_sync_delay;
972 isoal_sdu_len_t sdu_size;
973 uint8_t iso_interval_int;
974 uint64_t payload_number;
975 uint16_t total_sdu_size;
976 uint32_t pdu_timestamp;
977 uint32_t sdu_timestamp;
978 uint16_t testdata_indx;
979 uint16_t testdata_size;
980 uint32_t sdu_interval;
981 isoal_sdu_cnt_t seqn;
982 uint8_t testdata[23];
983 isoal_status_t err;
984 uint32_t latency;
985 uint8_t role;
986 uint8_t BN;
987 uint8_t FT;
988
989 /* Settings */
990 role = ISOAL_ROLE_PERIPHERAL;
991 iso_interval_int = 1;
992 sdu_interval = ISO_INT_UNIT_US;
993 BN = 1;
994 FT = 1;
995 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
996 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
997
998 /* PDU 0 -------------------------------------------------------------*/
999 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1000 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
1001 init_test_data_buffer(testdata, 23);
1002 sdu_buffer.dbuf = &rx_sdu_frag_buf;
1003 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
1004 payload_number = 2000;
1005 latency = calc_rx_latency_by_role(role,
1006 false,
1007 FT,
1008 sdu_interval,
1009 iso_interval_int,
1010 stream_sync_delay,
1011 group_sync_delay);
1012
1013 /* SDU time stamp should wrap back to 0 */
1014 pdu_timestamp = (ISOAL_TIME_WRAPPING_POINT_US - latency) + 1;
1015 sdu_timestamp = 0;
1016
1017 seqn = 0;
1018 testdata_indx = 0;
1019 testdata_size = 23;
1020 sdu_size = 23;
1021 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
1022 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
1023
1024 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
1025 role, /* Role */
1026 false, /* Framed */
1027 BN, /* BN */
1028 FT, /* FT */
1029 sdu_interval, /* SDU Interval */
1030 iso_interval_int, /* ISO Interval */
1031 stream_sync_delay, /* Stream Sync Delay */
1032 group_sync_delay); /* Group Sync Delay */
1033
1034 /* Send SDU in a single PDU */
1035 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
1036 &testdata[testdata_indx],
1037 (testdata_size - testdata_indx),
1038 payload_number,
1039 pdu_timestamp,
1040 ISOAL_PDU_STATUS_VALID,
1041 &rx_pdu_meta_buf.pdu_meta);
1042
1043 /* Set callback function return values */
1044 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
1045 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
1046 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1047 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
1048
1049 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1050
1051 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1052
1053 /* SDU 0 -------------------------------------------------------------*/
1054 /* Test recombine (Black Box) */
1055 /* A new SDU should be allocated */
1056 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
1057 &isoal_global.sink_state[sink_hdl], /* Sink */
1058 &rx_pdu_meta_buf.pdu_meta); /* PDU */
1059
1060 /* SDU payload should be written */
1061 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1062 &rx_sdu_frag_buf, /* SDU buffer */
1063 0, /* SDU written */
1064 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1065 (testdata_size - testdata_indx)); /* Size */
1066 /* SDU should be emitted */
1067 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
1068 &isoal_global.sink_state[sink_hdl], /* Sink */
1069 BT_ISO_SINGLE, /* Frag state */
1070 sdu_size, /* Frag size */
1071 ISOAL_SDU_STATUS_VALID, /* Frag status */
1072 sdu_timestamp, /* Timestamp */
1073 seqn, /* Seq. number */
1074 sdu_buffer.dbuf, /* Buffer */
1075 sdu_buffer.size, /* Buffer size */
1076 total_sdu_size, /* Total size */
1077 collated_status); /* SDU status */
1078
1079 /* Test recombine (White Box) */
1080 /* No padding PDUs expected, so move to waiting for start fragment */
1081 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1082 ISOAL_START,
1083 "FSM state %s should be %s!",
1084 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1085 FSM_TO_STR(ISOAL_START));
1086 }
1087
1088 /**
1089 * Test Suite : RX unframed PDU reassembly
1090 *
1091 * Tests time wrapping in reassembly of a single valid RX PDU into an SDU.
1092 *
1093 * Expected Sequence:
1094 * -- Total of 1 SDUs released across 1 events
1095 * -- Event 1: PDU0 Valid SDU 0 Unframed Single
1096 * -----> SDU 0 Valid (Released)
1097 *
1098 */
ZTEST(test_rx_unframed,test_rx_unframed_single_pdu_ts_wrap2)1099 ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap2)
1100 {
1101 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
1102 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
1103 struct isoal_sdu_buffer sdu_buffer;
1104 isoal_sdu_status_t collated_status;
1105 isoal_sink_handle_t sink_hdl;
1106 uint32_t stream_sync_delay;
1107 uint32_t group_sync_delay;
1108 isoal_sdu_len_t sdu_size;
1109 uint8_t iso_interval_int;
1110 uint64_t payload_number;
1111 uint16_t total_sdu_size;
1112 uint32_t pdu_timestamp;
1113 uint32_t sdu_timestamp;
1114 uint16_t testdata_indx;
1115 uint16_t testdata_size;
1116 uint32_t sdu_interval;
1117 isoal_sdu_cnt_t seqn;
1118 uint8_t testdata[23];
1119 isoal_status_t err;
1120 uint32_t latency;
1121 uint8_t role;
1122 uint8_t BN;
1123 uint8_t FT;
1124
1125 /* Settings */
1126 role = ISOAL_ROLE_CENTRAL;
1127 iso_interval_int = 1;
1128 sdu_interval = ISO_INT_UNIT_US;
1129 BN = 1;
1130 FT = 1;
1131 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
1132 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
1133
1134 /* PDU 0 -------------------------------------------------------------*/
1135 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1136 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
1137 init_test_data_buffer(testdata, 23);
1138 sdu_buffer.dbuf = &rx_sdu_frag_buf;
1139 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
1140 payload_number = 2000;
1141 latency = calc_rx_latency_by_role(role,
1142 false,
1143 FT,
1144 sdu_interval,
1145 iso_interval_int,
1146 stream_sync_delay,
1147 group_sync_delay);
1148
1149 /* SDU time stamp should wrap back to max time */
1150 pdu_timestamp = (-latency) - 1;
1151 sdu_timestamp = ISOAL_TIME_WRAPPING_POINT_US;
1152
1153 seqn = 0;
1154 testdata_indx = 0;
1155 testdata_size = 23;
1156 sdu_size = 23;
1157 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
1158 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
1159
1160 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
1161 role, /* Role */
1162 false, /* Framed */
1163 BN, /* BN */
1164 FT, /* FT */
1165 sdu_interval, /* SDU Interval */
1166 iso_interval_int, /* ISO Interval */
1167 stream_sync_delay, /* Stream Sync Delay */
1168 group_sync_delay); /* Group Sync Delay */
1169
1170 /* Send SDU in a single PDU */
1171 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
1172 &testdata[testdata_indx],
1173 (testdata_size - testdata_indx),
1174 payload_number,
1175 pdu_timestamp,
1176 ISOAL_PDU_STATUS_VALID,
1177 &rx_pdu_meta_buf.pdu_meta);
1178
1179 /* Set callback function return values */
1180 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
1181 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
1182 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1183 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
1184
1185 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1186
1187 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1188
1189 /* SDU 0 -------------------------------------------------------------*/
1190 /* Test recombine (Black Box) */
1191 /* A new SDU should be allocated */
1192 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
1193 &isoal_global.sink_state[sink_hdl], /* Sink */
1194 &rx_pdu_meta_buf.pdu_meta); /* PDU */
1195
1196 /* SDU payload should be written */
1197 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1198 &rx_sdu_frag_buf, /* SDU buffer */
1199 0, /* SDU written */
1200 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1201 (testdata_size - testdata_indx)); /* Size */
1202 /* SDU should be emitted */
1203 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
1204 &isoal_global.sink_state[sink_hdl], /* Sink */
1205 BT_ISO_SINGLE, /* Frag state */
1206 sdu_size, /* Frag size */
1207 ISOAL_SDU_STATUS_VALID, /* Frag status */
1208 sdu_timestamp, /* Timestamp */
1209 seqn, /* Seq. number */
1210 sdu_buffer.dbuf, /* Buffer */
1211 sdu_buffer.size, /* Buffer size */
1212 total_sdu_size, /* Total size */
1213 collated_status); /* SDU status */
1214
1215 /* Test recombine (White Box) */
1216 /* No padding PDUs expected, so move to waiting for start fragment */
1217 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1218 ISOAL_START,
1219 "FSM state %s should be %s!",
1220 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1221 FSM_TO_STR(ISOAL_START));
1222 }
1223
1224 /**
1225 * Test Suite : RX unframed PDU reassembly
1226 *
1227 * Tests reassembly of two valid RX PDU into a single SDU.
1228 *
1229 * Expected Sequence:
1230 * -- Total of 1 SDUs released across 1 events
1231 * -- Event 1: PDU0 Valid SDU 0 Unframed Start
1232 * PDU1 Valid SDU 0 Unframed End
1233 * -----> SDU 0 Valid (Released)
1234 *
1235 */
ZTEST(test_rx_unframed,test_rx_unframed_dbl_pdu)1236 ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu)
1237 {
1238 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
1239 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
1240 struct isoal_sdu_buffer sdu_buffer;
1241 isoal_sdu_status_t collated_status;
1242 isoal_sink_handle_t sink_hdl;
1243 uint32_t stream_sync_delay;
1244 uint32_t group_sync_delay;
1245 isoal_sdu_len_t sdu_size;
1246 uint8_t iso_interval_int;
1247 uint64_t payload_number;
1248 uint16_t total_sdu_size;
1249 uint16_t sdu_written = 0;
1250 uint32_t pdu_timestamp;
1251 uint32_t sdu_timestamp;
1252 uint16_t testdata_indx;
1253 uint16_t testdata_size;
1254 uint32_t sdu_interval;
1255 isoal_sdu_cnt_t seqn;
1256 uint8_t testdata[23];
1257 isoal_status_t err;
1258 uint32_t latency;
1259 uint8_t role;
1260 uint8_t BN;
1261 uint8_t FT;
1262
1263 /* Settings */
1264 role = ISOAL_ROLE_PERIPHERAL;
1265 iso_interval_int = 1;
1266 sdu_interval = ISO_INT_UNIT_US;
1267 BN = 2;
1268 FT = 1;
1269 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
1270 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
1271
1272 /* PDU 0 -------------------------------------------------------------*/
1273 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1274 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
1275 init_test_data_buffer(testdata, 23);
1276 sdu_buffer.dbuf = &rx_sdu_frag_buf;
1277 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
1278 payload_number = 2000;
1279 pdu_timestamp = 9249;
1280 latency = calc_rx_latency_by_role(role,
1281 false,
1282 FT,
1283 sdu_interval,
1284 iso_interval_int,
1285 stream_sync_delay,
1286 group_sync_delay);
1287 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
1288 seqn = 0;
1289 testdata_indx = 0;
1290 testdata_size = 13;
1291 sdu_size = 13;
1292
1293 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
1294 role, /* Role */
1295 false, /* Framed */
1296 BN, /* BN */
1297 FT, /* FT */
1298 sdu_interval, /* SDU Interval */
1299 iso_interval_int, /* ISO Interval */
1300 stream_sync_delay, /* Stream Sync Delay */
1301 group_sync_delay); /* Group Sync Delay */
1302
1303 /* Send PDU with start fragment */
1304 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
1305 &testdata[testdata_indx],
1306 (testdata_size - testdata_indx),
1307 payload_number,
1308 pdu_timestamp,
1309 ISOAL_PDU_STATUS_VALID,
1310 &rx_pdu_meta_buf.pdu_meta);
1311
1312 /* Set callback function return values */
1313 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
1314 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
1315 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1316
1317 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1318
1319 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1320
1321 /* SDU 0 -------------------------------------------------------------*/
1322 /* Test recombine (Black Box) */
1323 /* A new SDU should be allocated */
1324 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
1325 &isoal_global.sink_state[sink_hdl], /* Sink */
1326 &rx_pdu_meta_buf.pdu_meta); /* PDU */
1327
1328 /* SDU payload should be written */
1329 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1330 &rx_sdu_frag_buf, /* SDU buffer */
1331 sdu_written, /* SDU written */
1332 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1333 (testdata_size - testdata_indx)); /* Size */
1334
1335 /* SDU should not be emitted */
1336 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
1337
1338 /* Test recombine (White Box) */
1339 /* No padding PDUs expected, so move to waiting for start fragment */
1340 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1341 ISOAL_CONTINUE,
1342 "FSM state %s should be %s!",
1343 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1344 FSM_TO_STR(ISOAL_CONTINUE));
1345
1346 /* PDU 1 -------------------------------------------------------------*/
1347 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1348 sdu_written += (testdata_size - testdata_indx);
1349 payload_number++;
1350 testdata_indx = testdata_size;
1351 testdata_size += 10;
1352 sdu_size += 10;
1353 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
1354 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
1355
1356 /* Send PDU with end fragment */
1357 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
1358 &testdata[testdata_indx],
1359 (testdata_size - testdata_indx),
1360 payload_number,
1361 pdu_timestamp,
1362 ISOAL_PDU_STATUS_VALID,
1363 &rx_pdu_meta_buf.pdu_meta);
1364
1365 /* Set callback function return values */
1366 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1367 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
1368
1369 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1370
1371 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1372
1373 /* SDU 0 -------------------------------------------------------------*/
1374 /* Test recombine (Black Box) */
1375 /* Should not allocate a new SDU */
1376 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
1377
1378 /* SDU payload should be written */
1379 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1380 &rx_sdu_frag_buf, /* SDU buffer */
1381 sdu_written, /* SDU written */
1382 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1383 (testdata_size - testdata_indx)); /* Size */
1384 /* SDU should be emitted */
1385 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
1386 &isoal_global.sink_state[sink_hdl], /* Sink */
1387 BT_ISO_SINGLE, /* Frag state */
1388 sdu_size, /* Frag size */
1389 ISOAL_SDU_STATUS_VALID, /* Frag status */
1390 sdu_timestamp, /* Timestamp */
1391 seqn, /* Seq. number */
1392 sdu_buffer.dbuf, /* Buffer */
1393 sdu_buffer.size, /* Buffer size */
1394 total_sdu_size, /* Total size */
1395 collated_status); /* SDU status */
1396
1397 /* Test recombine (White Box) */
1398 /* As two PDUs per SDU, no padding is expected */
1399 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1400 ISOAL_START,
1401 "FSM state %s should be %s!",
1402 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1403 FSM_TO_STR(ISOAL_START));
1404 }
1405
1406 /**
1407 * Test Suite : RX unframed PDU reassembly
1408 *
1409 * Tests reassembly of three SDUs where the end of the first two were not seen
1410 *
1411 * Expected Sequence:
1412 * -- Total of 1 SDUs released across 1 events
1413 * -- Event 1: PDU0 Valid SDU 0 Unframed Start
1414 * PDU1 Valid SDU 0 Unframed Cont.
1415 * -----> SDU 0 Bit Errors (Released)
1416 * PDU2 Valid SDU 1 Unframed Start
1417 * PDU3 Valid SDU 1 Unframed Cont.
1418 * -----> SDU 1 Bit Errors (Released)
1419 * -- Event 2: PDU4 Valid SDU 2 Unframed Single
1420 * -----> SDU 2 Valid (Released)
1421 *
1422 */
ZTEST(test_rx_unframed,test_rx_unframed_dbl_split)1423 ZTEST(test_rx_unframed, test_rx_unframed_dbl_split)
1424 {
1425 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
1426 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
1427 struct isoal_sdu_buffer sdu_buffer;
1428 isoal_sdu_status_t collated_status;
1429 isoal_sink_handle_t sink_hdl;
1430 uint32_t stream_sync_delay;
1431 uint32_t group_sync_delay;
1432 isoal_sdu_len_t sdu_size;
1433 uint8_t iso_interval_int;
1434 uint64_t payload_number;
1435 uint16_t total_sdu_size;
1436 uint16_t sdu_written = 0;
1437 uint32_t pdu_timestamp;
1438 uint32_t sdu_timestamp;
1439 uint16_t testdata_indx;
1440 uint16_t testdata_size;
1441 uint32_t sdu_interval;
1442 isoal_sdu_cnt_t seqn;
1443 uint8_t testdata[53];
1444 isoal_status_t err;
1445 uint32_t latency;
1446 uint8_t role;
1447 uint8_t BN;
1448 uint8_t FT;
1449
1450 /* Settings */
1451 role = ISOAL_ROLE_PERIPHERAL;
1452 iso_interval_int = 1;
1453 sdu_interval = ISO_INT_UNIT_US / 2;
1454 BN = 4;
1455 FT = 1;
1456 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
1457 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
1458
1459 /* SDU 0 - PDU 0 -----------------------------------------------------*/
1460 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1461 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
1462 init_test_data_buffer(testdata, 53);
1463 sdu_buffer.dbuf = &rx_sdu_frag_buf;
1464 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
1465 payload_number = 2000;
1466 pdu_timestamp = 9249;
1467 latency = calc_rx_latency_by_role(role,
1468 false,
1469 FT,
1470 sdu_interval,
1471 iso_interval_int,
1472 stream_sync_delay,
1473 group_sync_delay);
1474 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
1475 seqn = 0;
1476 testdata_indx = 0;
1477 testdata_size = 13;
1478 sdu_size = 13;
1479
1480 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
1481 role, /* Role */
1482 false, /* Framed */
1483 BN, /* BN */
1484 FT, /* FT */
1485 sdu_interval, /* SDU Interval */
1486 iso_interval_int, /* ISO Interval */
1487 stream_sync_delay, /* Stream Sync Delay */
1488 group_sync_delay); /* Group Sync Delay */
1489
1490 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
1491 &testdata[testdata_indx],
1492 (testdata_size - testdata_indx),
1493 payload_number,
1494 pdu_timestamp,
1495 ISOAL_PDU_STATUS_VALID,
1496 &rx_pdu_meta_buf.pdu_meta);
1497
1498 /* Set callback function return values */
1499 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
1500 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
1501 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1502
1503 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1504
1505 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1506
1507 /* SDU 0 -------------------------------------------------------------*/
1508 /* A new SDU should be allocated */
1509 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
1510 &isoal_global.sink_state[sink_hdl], /* Sink */
1511 &rx_pdu_meta_buf.pdu_meta); /* PDU */
1512
1513 /* SDU payload should be written */
1514 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1515 &rx_sdu_frag_buf, /* SDU buffer */
1516 sdu_written, /* SDU written */
1517 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1518 (testdata_size - testdata_indx)); /* Size */
1519
1520 /* SDU should be not emitted */
1521 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
1522
1523 /* Test recombine (White Box) */
1524 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1525 ISOAL_CONTINUE,
1526 "FSM state %s should be %s!",
1527 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1528 FSM_TO_STR(ISOAL_CONTINUE));
1529
1530 /* SDU 0 - PDU 1 -----------------------------------------------------*/
1531 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1532 sdu_written += (testdata_size - testdata_indx);
1533 payload_number++;
1534 testdata_indx = testdata_size;
1535 testdata_size += 10;
1536 sdu_size += 10;
1537 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
1538 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
1539
1540 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
1541 &testdata[testdata_indx],
1542 (testdata_size - testdata_indx),
1543 payload_number,
1544 pdu_timestamp,
1545 ISOAL_PDU_STATUS_VALID,
1546 &rx_pdu_meta_buf.pdu_meta);
1547
1548 /* Set callback function return values */
1549 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1550 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
1551
1552 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1553
1554 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1555
1556 /* SDU 0 -------------------------------------------------------------*/
1557 /* A new SDU should not be allocated */
1558 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
1559
1560 /* SDU payload should be written */
1561 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1562 &rx_sdu_frag_buf, /* SDU buffer */
1563 sdu_written, /* SDU written */
1564 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1565 (testdata_size - testdata_indx)); /* Size */
1566 /* SDU should be emitted */
1567 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
1568 &isoal_global.sink_state[sink_hdl], /* Sink */
1569 BT_ISO_SINGLE, /* Frag state */
1570 sdu_size, /* Frag size */
1571 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
1572 sdu_timestamp, /* Timestamp */
1573 seqn, /* Seq. number */
1574 sdu_buffer.dbuf, /* Buffer */
1575 sdu_buffer.size, /* Buffer size */
1576 total_sdu_size, /* Total size */
1577 collated_status); /* SDU status */
1578
1579 /* Test recombine (White Box) */
1580 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1581 ISOAL_START,
1582 "FSM state %s should be %s!",
1583 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1584 FSM_TO_STR(ISOAL_START));
1585
1586 /* SDU 1 - PDU 2 -----------------------------------------------------*/
1587 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1588 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
1589 sdu_written = 0;
1590 payload_number++;
1591 seqn++;
1592 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency + sdu_interval);
1593 testdata_indx = testdata_size;
1594 testdata_size += 10;
1595 sdu_size = 10;
1596
1597 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
1598 &testdata[testdata_indx],
1599 (testdata_size - testdata_indx),
1600 payload_number,
1601 pdu_timestamp,
1602 ISOAL_PDU_STATUS_VALID,
1603 &rx_pdu_meta_buf.pdu_meta);
1604
1605 /* Set callback function return values */
1606 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
1607 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
1608 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1609
1610 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1611
1612 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1613
1614 /* SDU 1 -------------------------------------------------------------*/
1615 /* A new SDU should be allocated */
1616 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
1617 &isoal_global.sink_state[sink_hdl], /* Sink */
1618 &rx_pdu_meta_buf.pdu_meta); /* PDU */
1619
1620 /* SDU payload should be written */
1621 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1622 &rx_sdu_frag_buf, /* SDU buffer */
1623 sdu_written, /* SDU written */
1624 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1625 (testdata_size - testdata_indx)); /* Size */
1626
1627 /* SDU should not be emitted */
1628 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1);
1629
1630 /* Test recombine (White Box) */
1631 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1632 ISOAL_CONTINUE,
1633 "FSM state %s should be %s!",
1634 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1635 FSM_TO_STR(ISOAL_CONTINUE));
1636
1637 /* SDU 1 - PDU 3 -----------------------------------------------------*/
1638 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1639 sdu_written += (testdata_size - testdata_indx);
1640 payload_number++;
1641 testdata_indx = testdata_size;
1642 testdata_size += 10;
1643 sdu_size += 10;
1644 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
1645 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
1646
1647 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
1648 &testdata[testdata_indx],
1649 (testdata_size - testdata_indx),
1650 payload_number,
1651 pdu_timestamp,
1652 ISOAL_PDU_STATUS_VALID,
1653 &rx_pdu_meta_buf.pdu_meta);
1654
1655 /* Set callback function return values */
1656 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1657 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
1658
1659 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1660
1661 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1662
1663 /* SDU 1 -------------------------------------------------------------*/
1664 /* A new SDU should not be allocated */
1665 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(2);
1666
1667 /* SDU payload should be written */
1668 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1669 &rx_sdu_frag_buf, /* SDU buffer */
1670 sdu_written, /* SDU written */
1671 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1672 (testdata_size - testdata_indx)); /* Size */
1673 /* SDU should be emitted */
1674 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
1675 &isoal_global.sink_state[sink_hdl], /* Sink */
1676 BT_ISO_SINGLE, /* Frag state */
1677 sdu_size, /* Frag size */
1678 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
1679 sdu_timestamp, /* Timestamp */
1680 seqn, /* Seq. number */
1681 sdu_buffer.dbuf, /* Buffer */
1682 sdu_buffer.size, /* Buffer size */
1683 total_sdu_size, /* Total size */
1684 collated_status); /* SDU status */
1685
1686 /* Test recombine (White Box) */
1687 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1688 ISOAL_START,
1689 "FSM state %s should be %s!",
1690 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1691 FSM_TO_STR(ISOAL_START));
1692
1693 /* SDU 2 - PDU 4 -----------------------------------------------------*/
1694 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1695 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
1696 sdu_written = 0;
1697 payload_number++;
1698 seqn++;
1699 pdu_timestamp = 9249 + ISO_INT_UNIT_US;
1700 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
1701 testdata_indx = testdata_size;
1702 testdata_size += 10;
1703 sdu_size = 10;
1704 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
1705 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
1706
1707 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
1708 &testdata[testdata_indx],
1709 (testdata_size - testdata_indx),
1710 payload_number,
1711 pdu_timestamp,
1712 ISOAL_PDU_STATUS_VALID,
1713 &rx_pdu_meta_buf.pdu_meta);
1714
1715 /* Set callback function return values */
1716 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
1717 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
1718 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1719 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
1720
1721 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1722
1723 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1724
1725 /* SDU 2 -------------------------------------------------------------*/
1726 /* A new SDU should be allocated */
1727 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
1728 &isoal_global.sink_state[sink_hdl], /* Sink */
1729 &rx_pdu_meta_buf.pdu_meta); /* PDU */
1730
1731 /* SDU payload should be written */
1732 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1733 &rx_sdu_frag_buf, /* SDU buffer */
1734 sdu_written, /* SDU written */
1735 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1736 (testdata_size - testdata_indx)); /* Size */
1737 /* SDU should be emitted */
1738 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
1739 &isoal_global.sink_state[sink_hdl], /* Sink */
1740 BT_ISO_SINGLE, /* Frag state */
1741 sdu_size, /* Frag size */
1742 ISOAL_SDU_STATUS_VALID, /* Frag status */
1743 sdu_timestamp, /* Timestamp */
1744 seqn, /* Seq. number */
1745 sdu_buffer.dbuf, /* Buffer */
1746 sdu_buffer.size, /* Buffer size */
1747 total_sdu_size, /* Total size */
1748 collated_status); /* SDU status */
1749
1750 /* Test recombine (White Box) */
1751 /* Expecting padding PDU as PDUs per SDU is 2 */
1752 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1753 ISOAL_ERR_SPOOL,
1754 "FSM state %s should be %s!",
1755 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1756 FSM_TO_STR(ISOAL_ERR_SPOOL));
1757 }
1758
1759 /**
1760 * Test Suite : RX unframed PDU reassembly
1761 *
1762 * Tests reassembly of one SDUs in five fragments
1763 *
1764 * Expected Sequence:
1765 * -- Total of 1 SDUs released across 1 events
1766 * -- Event 1: PDU0 Valid SDU 0 Unframed Start
1767 * PDU1 Valid SDU 0 Unframed Cont.
1768 * PDU2 Valid SDU 0 Unframed Cont.
1769 * PDU3 Valid SDU 0 Unframed Cont.
1770 * PDU4 Valid SDU 0 Unframed End
1771 * -----> SDU 0 Valid (Released)
1772 *
1773 */
ZTEST(test_rx_unframed,test_rx_unframed_multi_split)1774 ZTEST(test_rx_unframed, test_rx_unframed_multi_split)
1775 {
1776 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
1777 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
1778 struct isoal_sdu_buffer sdu_buffer;
1779 isoal_sdu_status_t collated_status;
1780 isoal_sink_handle_t sink_hdl;
1781 uint32_t stream_sync_delay;
1782 uint32_t group_sync_delay;
1783 isoal_sdu_len_t sdu_size;
1784 uint8_t iso_interval_int;
1785 uint64_t payload_number;
1786 uint16_t total_sdu_size;
1787 uint16_t sdu_written = 0;
1788 uint32_t pdu_timestamp;
1789 uint32_t sdu_timestamp;
1790 uint16_t testdata_indx;
1791 uint16_t testdata_size;
1792 uint32_t sdu_interval;
1793 isoal_sdu_cnt_t seqn;
1794 uint8_t testdata[53];
1795 isoal_status_t err;
1796 uint32_t latency;
1797 uint8_t role;
1798 uint8_t BN;
1799 uint8_t FT;
1800
1801 /* Settings */
1802 role = ISOAL_ROLE_PERIPHERAL;
1803 iso_interval_int = 1;
1804 sdu_interval = ISO_INT_UNIT_US;
1805 BN = 5;
1806 FT = 1;
1807 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
1808 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
1809
1810 /* PDU 0 -------------------------------------------------------------*/
1811 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1812 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
1813 init_test_data_buffer(testdata, 53);
1814 sdu_buffer.dbuf = &rx_sdu_frag_buf;
1815 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
1816 payload_number = 2000;
1817 pdu_timestamp = 9249;
1818 latency = calc_rx_latency_by_role(role,
1819 false,
1820 FT,
1821 sdu_interval,
1822 iso_interval_int,
1823 stream_sync_delay,
1824 group_sync_delay);
1825 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
1826 seqn = 0;
1827 testdata_indx = 0;
1828 testdata_size = 13;
1829 sdu_size = 13;
1830
1831 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
1832 role, /* Role */
1833 false, /* Framed */
1834 BN, /* BN */
1835 FT, /* FT */
1836 sdu_interval, /* SDU Interval */
1837 iso_interval_int, /* ISO Interval */
1838 stream_sync_delay, /* Stream Sync Delay */
1839 group_sync_delay); /* Group Sync Delay */
1840
1841 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
1842 &testdata[testdata_indx],
1843 (testdata_size - testdata_indx),
1844 payload_number,
1845 pdu_timestamp,
1846 ISOAL_PDU_STATUS_VALID,
1847 &rx_pdu_meta_buf.pdu_meta);
1848
1849 /* Set callback function return values */
1850 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
1851 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
1852 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1853
1854 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1855
1856 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1857
1858 /* SDU 0 -------------------------------------------------------------*/
1859 /* SDU should be allocated */
1860 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
1861 &isoal_global.sink_state[sink_hdl], /* Sink */
1862 &rx_pdu_meta_buf.pdu_meta); /* PDU */
1863
1864 /* SDU payload should be written */
1865 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1866 &rx_sdu_frag_buf, /* SDU buffer */
1867 sdu_written, /* SDU written */
1868 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1869 (testdata_size - testdata_indx)); /* Size */
1870
1871 /* SDU should not be emitted */
1872 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
1873
1874 /* Test recombine (White Box) */
1875 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1876 ISOAL_CONTINUE,
1877 "FSM state %s should be %s!",
1878 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1879 FSM_TO_STR(ISOAL_CONTINUE));
1880
1881 /* PDU 1 -------------------------------------------------------------*/
1882 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1883 sdu_written += (testdata_size - testdata_indx);
1884 payload_number++;
1885 testdata_indx = testdata_size;
1886 testdata_size += 10;
1887 sdu_size += 10;
1888
1889 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
1890 &testdata[testdata_indx],
1891 (testdata_size - testdata_indx),
1892 payload_number,
1893 pdu_timestamp,
1894 ISOAL_PDU_STATUS_VALID,
1895 &rx_pdu_meta_buf.pdu_meta);
1896
1897 /* Set callback function return values */
1898 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1899
1900 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1901
1902 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1903
1904 /* SDU 0 -------------------------------------------------------------*/
1905 /* A new SDU should not be allocated */
1906 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
1907
1908 /* SDU payload should be written */
1909 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1910 &rx_sdu_frag_buf, /* SDU buffer */
1911 sdu_written, /* SDU written */
1912 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1913 (testdata_size - testdata_indx)); /* Size */
1914
1915 /* SDU should not be emitted */
1916 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
1917
1918 /* Test recombine (White Box) */
1919 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1920 ISOAL_CONTINUE,
1921 "FSM state %s should be %s!",
1922 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1923 FSM_TO_STR(ISOAL_CONTINUE));
1924
1925 /* PDU 3 -------------------------------------------------------------*/
1926 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1927 sdu_written += (testdata_size - testdata_indx);
1928 payload_number++;
1929 testdata_indx = testdata_size;
1930 testdata_size += 10;
1931 sdu_size += 10;
1932
1933 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
1934 &testdata[testdata_indx],
1935 (testdata_size - testdata_indx),
1936 payload_number,
1937 pdu_timestamp,
1938 ISOAL_PDU_STATUS_VALID,
1939 &rx_pdu_meta_buf.pdu_meta);
1940
1941 /* Set callback function return values */
1942 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1943
1944 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1945
1946 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1947
1948 /* SDU 0 -------------------------------------------------------------*/
1949 /* A new SDU should not be allocated */
1950 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
1951
1952 /* SDU payload should be written */
1953 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1954 &rx_sdu_frag_buf, /* SDU buffer */
1955 sdu_written, /* SDU written */
1956 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
1957 (testdata_size - testdata_indx)); /* Size */
1958
1959 /* SDU should not be emitted */
1960 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
1961
1962 /* Test recombine (White Box) */
1963 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
1964 ISOAL_CONTINUE,
1965 "FSM state %s should be %s!",
1966 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
1967 FSM_TO_STR(ISOAL_CONTINUE));
1968
1969 /* PDU 3 -------------------------------------------------------------*/
1970 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
1971 sdu_written += (testdata_size - testdata_indx);
1972 payload_number++;
1973 testdata_indx = testdata_size;
1974 testdata_size += 10;
1975 sdu_size += 10;
1976
1977 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
1978 &testdata[testdata_indx],
1979 (testdata_size - testdata_indx),
1980 payload_number,
1981 pdu_timestamp,
1982 ISOAL_PDU_STATUS_VALID,
1983 &rx_pdu_meta_buf.pdu_meta);
1984
1985 /* Set callback function return values */
1986 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
1987
1988 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
1989
1990 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
1991
1992 /* SDU 0 -------------------------------------------------------------*/
1993 /* A new SDU should not be allocated */
1994 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
1995
1996 /* SDU payload should be written */
1997 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
1998 &rx_sdu_frag_buf, /* SDU buffer */
1999 sdu_written, /* SDU written */
2000 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2001 (testdata_size - testdata_indx)); /* Size */
2002
2003 /* SDU should not be emitted */
2004 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
2005
2006 /* Test recombine (White Box) */
2007 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2008 ISOAL_CONTINUE,
2009 "FSM state %s should be %s!",
2010 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2011 FSM_TO_STR(ISOAL_CONTINUE));
2012
2013 /* PDU 4 -------------------------------------------------------------*/
2014 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2015 sdu_written += (testdata_size - testdata_indx);
2016 payload_number++;
2017 testdata_indx = testdata_size;
2018 testdata_size += 10;
2019 sdu_size += 10;
2020 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
2021 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
2022
2023 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
2024 &testdata[testdata_indx],
2025 (testdata_size - testdata_indx),
2026 payload_number,
2027 pdu_timestamp,
2028 ISOAL_PDU_STATUS_VALID,
2029 &rx_pdu_meta_buf.pdu_meta);
2030
2031 /* Set callback function return values */
2032 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2033 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
2034
2035 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2036
2037 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2038
2039 /* SDU 0 -------------------------------------------------------------*/
2040 /* A new SDU should not be allocated */
2041 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
2042
2043 /* SDU payload should be written */
2044 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
2045 &rx_sdu_frag_buf, /* SDU buffer */
2046 sdu_written, /* SDU written */
2047 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2048 (testdata_size - testdata_indx)); /* Size */
2049 /* SDU should be emitted */
2050 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
2051 &isoal_global.sink_state[sink_hdl], /* Sink */
2052 BT_ISO_SINGLE, /* Frag state */
2053 sdu_size, /* Frag size */
2054 ISOAL_SDU_STATUS_VALID, /* Frag status */
2055 sdu_timestamp, /* Timestamp */
2056 seqn, /* Seq. number */
2057 sdu_buffer.dbuf, /* Buffer */
2058 sdu_buffer.size, /* Buffer size */
2059 total_sdu_size, /* Total size */
2060 collated_status); /* SDU status */
2061
2062 /* Test recombine (White Box) */
2063 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2064 ISOAL_START,
2065 "FSM state %s should be %s!",
2066 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2067 FSM_TO_STR(ISOAL_START));
2068 }
2069
2070 /**
2071 * Test Suite : RX unframed PDU reassembly
2072 *
2073 * Tests reassembly of one SDUs in five fragments where the SDU buffer size is
2074 * reached
2075 *
2076 * Expected Sequence:
2077 * -- Total of 1 SDUs released across 1 events
2078 * -- Event 1: PDU0 Valid SDU 0 Unframed Start
2079 * PDU1 Valid SDU 0 Unframed Cont.
2080 * -----> SDU 0 Valid Frag 1 (Released)
2081 * PDU2 Valid SDU 0 Unframed Cont.
2082 * -----> SDU 0 Valid Frag 2 (Released)
2083 * PDU3 Valid SDU 0 Unframed Cont.
2084 * PDU4 Valid SDU 0 Unframed End
2085 * -----> SDU 0 Valid Frag 3 (Released)
2086 *
2087 */
ZTEST(test_rx_unframed,test_rx_unframed_multi_split_on_border)2088 ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border)
2089 {
2090 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
2091 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
2092 struct isoal_sdu_buffer sdu_buffer;
2093 isoal_sdu_status_t collated_status;
2094 isoal_sink_handle_t sink_hdl;
2095 uint32_t stream_sync_delay;
2096 uint32_t group_sync_delay;
2097 isoal_sdu_len_t sdu_size;
2098 uint8_t iso_interval_int;
2099 uint64_t payload_number;
2100 uint16_t total_sdu_size;
2101 uint16_t sdu_written = 0;
2102 uint32_t pdu_timestamp;
2103 uint32_t sdu_timestamp;
2104 uint16_t testdata_indx;
2105 uint16_t testdata_size;
2106 uint32_t sdu_interval;
2107 isoal_sdu_cnt_t seqn;
2108 uint8_t testdata[100];
2109 isoal_status_t err;
2110 uint32_t latency;
2111 uint8_t role;
2112 uint8_t BN;
2113 uint8_t FT;
2114
2115 /* Settings */
2116 role = ISOAL_ROLE_PERIPHERAL;
2117 iso_interval_int = 1;
2118 sdu_interval = ISO_INT_UNIT_US;
2119 BN = 5;
2120 FT = 1;
2121 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
2122 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
2123
2124 /* PDU 0 -------------------------------------------------------------*/
2125 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2126 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
2127 init_test_data_buffer(testdata, 100);
2128 sdu_buffer.dbuf = &rx_sdu_frag_buf;
2129 sdu_buffer.size = 40;
2130 payload_number = 2000;
2131 pdu_timestamp = 9249;
2132 latency = calc_rx_latency_by_role(role,
2133 false,
2134 FT,
2135 sdu_interval,
2136 iso_interval_int,
2137 stream_sync_delay,
2138 group_sync_delay);
2139 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
2140 seqn = 0;
2141 testdata_indx = 0;
2142 testdata_size = 17;
2143 sdu_size = 17;
2144
2145 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
2146 role, /* Role */
2147 false, /* Framed */
2148 BN, /* BN */
2149 FT, /* FT */
2150 sdu_interval, /* SDU Interval */
2151 iso_interval_int, /* ISO Interval */
2152 stream_sync_delay, /* Stream Sync Delay */
2153 group_sync_delay); /* Group Sync Delay */
2154
2155 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
2156 &testdata[testdata_indx],
2157 (testdata_size - testdata_indx),
2158 payload_number,
2159 pdu_timestamp,
2160 ISOAL_PDU_STATUS_VALID,
2161 &rx_pdu_meta_buf.pdu_meta);
2162
2163 /* Set callback function return values */
2164 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
2165 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
2166 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2167
2168 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2169
2170 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2171
2172 /* SDU 0 - Frag 1 ----------------------------------------------------*/
2173 /* A new SDU should be allocated */
2174 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
2175 &isoal_global.sink_state[sink_hdl], /* Sink */
2176 &rx_pdu_meta_buf.pdu_meta); /* PDU */
2177
2178 /* SDU payload should be written */
2179 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
2180 &rx_sdu_frag_buf, /* SDU buffer */
2181 sdu_written, /* SDU written */
2182 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2183 (testdata_size - testdata_indx)); /* Size */
2184
2185 /* SDU should not be emitted */
2186 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
2187
2188 /* Test recombine (White Box) */
2189 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2190 ISOAL_CONTINUE,
2191 "FSM state %s should be %s!",
2192 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2193 FSM_TO_STR(ISOAL_CONTINUE));
2194
2195 /* PDU 1 -------------------------------------------------------------*/
2196 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2197 sdu_written += (testdata_size - testdata_indx);
2198 payload_number++;
2199 testdata_indx = testdata_size;
2200 testdata_size += 23;
2201 sdu_size += 23;
2202 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 100);
2203 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
2204
2205 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
2206 &testdata[testdata_indx],
2207 (testdata_size - testdata_indx),
2208 payload_number,
2209 pdu_timestamp,
2210 ISOAL_PDU_STATUS_VALID,
2211 &rx_pdu_meta_buf.pdu_meta);
2212
2213 /* Set callback function return values */
2214 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2215 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
2216
2217 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2218
2219 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2220
2221 /* SDU 0 - Frag 1 ----------------------------------------------------*/
2222 /* A new SDU should not be allocated */
2223 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
2224
2225 /* SDU payload should be written */
2226 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
2227 &rx_sdu_frag_buf, /* SDU buffer */
2228 sdu_written, /* SDU written */
2229 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2230 (testdata_size - testdata_indx)); /* Size */
2231 /* SDU should be emitted */
2232 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
2233 &isoal_global.sink_state[sink_hdl], /* Sink */
2234 BT_ISO_START, /* Frag state */
2235 sdu_size, /* Frag size */
2236 ISOAL_SDU_STATUS_VALID, /* Frag status */
2237 sdu_timestamp, /* Timestamp */
2238 seqn, /* Seq. number */
2239 sdu_buffer.dbuf, /* Buffer */
2240 sdu_buffer.size, /* Buffer size */
2241 total_sdu_size, /* Total size */
2242 collated_status); /* SDU status */
2243
2244 /* Test recombine (White Box) */
2245 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2246 ISOAL_CONTINUE,
2247 "FSM state %s should be %s!",
2248 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2249 FSM_TO_STR(ISOAL_CONTINUE));
2250
2251 /* PDU 2 -------------------------------------------------------------*/
2252 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2253 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
2254 sdu_written = 0;
2255 payload_number++;
2256 testdata_indx = testdata_size;
2257 testdata_size += 40;
2258 sdu_size = 40;
2259 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 100);
2260 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
2261
2262 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
2263 &testdata[testdata_indx],
2264 (testdata_size - testdata_indx),
2265 payload_number,
2266 pdu_timestamp,
2267 ISOAL_PDU_STATUS_VALID,
2268 &rx_pdu_meta_buf.pdu_meta);
2269
2270 /* Set callback function return values */
2271 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
2272 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
2273 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2274 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
2275
2276 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2277
2278 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2279
2280 /* SDU 0 - Frag 2 ----------------------------------------------------*/
2281 /* A new SDU should be allocated */
2282 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
2283 &isoal_global.sink_state[sink_hdl], /* Sink */
2284 &rx_pdu_meta_buf.pdu_meta); /* PDU */
2285
2286 /* SDU payload should be written */
2287 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
2288 &rx_sdu_frag_buf, /* SDU buffer */
2289 sdu_written, /* SDU written */
2290 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2291 (testdata_size - testdata_indx)); /* Size */
2292 /* SDU should be emitted */
2293 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
2294 &isoal_global.sink_state[sink_hdl], /* Sink */
2295 BT_ISO_CONT, /* Frag state */
2296 sdu_size, /* Frag size */
2297 ISOAL_SDU_STATUS_VALID, /* Frag status */
2298 sdu_timestamp, /* Timestamp */
2299 seqn, /* Seq. number */
2300 sdu_buffer.dbuf, /* Buffer */
2301 sdu_buffer.size, /* Buffer size */
2302 total_sdu_size, /* Total size */
2303 collated_status); /* SDU status */
2304
2305 /* Test recombine (White Box) */
2306 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2307 ISOAL_CONTINUE,
2308 "FSM state %s should be %s!",
2309 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2310 FSM_TO_STR(ISOAL_CONTINUE));
2311
2312 /* PDU 3 -------------------------------------------------------------*/
2313 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2314 sdu_written = 0;
2315 payload_number++;
2316 testdata_indx = testdata_size;
2317 testdata_size += 10;
2318 sdu_size = 10;
2319
2320 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
2321 &testdata[testdata_indx],
2322 (testdata_size - testdata_indx),
2323 payload_number,
2324 pdu_timestamp,
2325 ISOAL_PDU_STATUS_VALID,
2326 &rx_pdu_meta_buf.pdu_meta);
2327
2328 /* Set callback function return values */
2329 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
2330 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
2331 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2332
2333 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2334
2335 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2336
2337 /* SDU 0 - Frag 3 ----------------------------------------------------*/
2338 /* A new SDU should be allocated */
2339 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
2340 &isoal_global.sink_state[sink_hdl], /* Sink */
2341 &rx_pdu_meta_buf.pdu_meta); /* PDU */
2342
2343 /* SDU payload should be written */
2344 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
2345 &rx_sdu_frag_buf, /* SDU buffer */
2346 sdu_written, /* SDU written */
2347 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2348 (testdata_size - testdata_indx)); /* Size */
2349
2350 /* SDU should not be emitted */
2351 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(2);
2352
2353 /* Test recombine (White Box) */
2354 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2355 ISOAL_CONTINUE,
2356 "FSM state %s should be %s!",
2357 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2358 FSM_TO_STR(ISOAL_CONTINUE));
2359
2360 /* PDU 4 -------------------------------------------------------------*/
2361 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2362 sdu_written += (testdata_size - testdata_indx);
2363 payload_number++;
2364 testdata_indx = testdata_size;
2365 testdata_size += 10;
2366 sdu_size += 10;
2367 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 100);
2368 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
2369
2370 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
2371 &testdata[testdata_indx],
2372 (testdata_size - testdata_indx),
2373 payload_number,
2374 pdu_timestamp,
2375 ISOAL_PDU_STATUS_VALID,
2376 &rx_pdu_meta_buf.pdu_meta);
2377
2378 /* Set callback function return values */
2379 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2380 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
2381
2382 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2383
2384 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2385
2386 /* SDU 0 - Frag 3 ----------------------------------------------------*/
2387 /* A new SDU should not be allocated */
2388 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(3);
2389
2390 /* SDU payload should be written */
2391 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
2392 &rx_sdu_frag_buf, /* SDU buffer */
2393 sdu_written, /* SDU written */
2394 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2395 (testdata_size - testdata_indx)); /* Size */
2396 /* SDU should be emitted */
2397 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
2398 &isoal_global.sink_state[sink_hdl], /* Sink */
2399 BT_ISO_END, /* Frag state */
2400 sdu_size, /* Frag size */
2401 ISOAL_SDU_STATUS_VALID, /* Frag status */
2402 sdu_timestamp, /* Timestamp */
2403 seqn, /* Seq. number */
2404 sdu_buffer.dbuf, /* Buffer */
2405 sdu_buffer.size, /* Buffer size */
2406 total_sdu_size, /* Total size */
2407 collated_status); /* SDU status */
2408
2409 /* Test recombine (White Box) */
2410 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2411 ISOAL_START,
2412 "FSM state %s should be %s!",
2413 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2414 FSM_TO_STR(ISOAL_START));
2415 }
2416
2417 /**
2418 * Test Suite : RX unframed PDU reassembly
2419 *
2420 * Tests reassembly of one SDUs sent in one PDU when the SDU fragment size is
2421 * small, resulting in multiple SDU fragments released during reassembly
2422 */
ZTEST(test_rx_unframed,test_rx_unframed_long_pdu_short_sdu)2423 ZTEST(test_rx_unframed, test_rx_unframed_long_pdu_short_sdu)
2424 {
2425 struct rx_sdu_frag_buffer rx_sdu_frag_buf[2];
2426 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
2427 struct isoal_sdu_buffer sdu_buffer[2];
2428 isoal_sdu_status_t collated_status;
2429 isoal_sink_handle_t sink_hdl;
2430 uint32_t stream_sync_delay;
2431 uint32_t group_sync_delay;
2432 isoal_sdu_len_t sdu_size;
2433 uint8_t iso_interval_int;
2434 uint64_t payload_number;
2435 uint16_t total_sdu_size;
2436 uint32_t pdu_timestamp;
2437 uint32_t sdu_timestamp;
2438 uint16_t testdata_indx;
2439 uint16_t testdata_size;
2440 uint32_t sdu_interval;
2441 isoal_sdu_cnt_t seqn;
2442 uint8_t testdata[40];
2443 isoal_status_t err;
2444 uint32_t latency;
2445 uint8_t role;
2446 uint8_t BN;
2447 uint8_t FT;
2448
2449 /* Settings */
2450 role = ISOAL_ROLE_PERIPHERAL;
2451 iso_interval_int = 1;
2452 sdu_interval = ISO_INT_UNIT_US;
2453 BN = 1;
2454 FT = 1;
2455 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
2456 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
2457
2458 /* PDU 1 -------------------------------------------------------------*/
2459 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2460 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
2461 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
2462 init_test_data_buffer(testdata, 40);
2463 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
2464 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
2465 sdu_buffer[0].size = 20;
2466 sdu_buffer[1].size = 20;
2467 payload_number = 2000;
2468 pdu_timestamp = 9249;
2469 latency = calc_rx_latency_by_role(role,
2470 false,
2471 FT,
2472 sdu_interval,
2473 iso_interval_int,
2474 stream_sync_delay,
2475 group_sync_delay);
2476 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
2477 seqn = 0;
2478 testdata_indx = 0;
2479 testdata_size = 40;
2480 sdu_size = 20;
2481 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 40);
2482 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
2483
2484 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
2485 role, /* Role */
2486 false, /* Framed */
2487 BN, /* BN */
2488 FT, /* FT */
2489 sdu_interval, /* SDU Interval */
2490 iso_interval_int, /* ISO Interval */
2491 stream_sync_delay, /* Stream Sync Delay */
2492 group_sync_delay); /* Group Sync Delay */
2493
2494 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
2495 &testdata[testdata_indx],
2496 (testdata_size - testdata_indx),
2497 payload_number,
2498 pdu_timestamp,
2499 ISOAL_PDU_STATUS_VALID,
2500 &rx_pdu_meta_buf.pdu_meta);
2501
2502 /* Set callback function return values */
2503 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
2504 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
2505 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
2506 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2507 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
2508
2509 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2510
2511 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2512
2513 /* Test recombine (Black Box) */
2514 /* SDU 1 */
2515 /* A new SDU should be allocated */
2516 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[0],
2517 &isoal_global.sink_state[sink_hdl], /* Sink */
2518 &rx_pdu_meta_buf.pdu_meta); /* PDU */
2519
2520 /* SDU payload should be written */
2521 ZASSERT_ISOAL_SDU_WRITE_TEST(history[0],
2522 &rx_sdu_frag_buf[0], /* SDU buffer */
2523 0, /* SDU written */
2524 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2525 20); /* Size */
2526 /* SDU should be emitted */
2527 ZASSERT_ISOAL_SDU_EMIT_TEST(history[0],
2528 &isoal_global.sink_state[sink_hdl], /* Sink */
2529 BT_ISO_START, /* Frag state */
2530 sdu_size, /* Frag size */
2531 ISOAL_SDU_STATUS_VALID, /* Frag status */
2532 sdu_timestamp, /* Timestamp */
2533 seqn, /* Seq. number */
2534 sdu_buffer[0].dbuf, /* Buffer */
2535 sdu_buffer[0].size, /* Buffer size */
2536 total_sdu_size, /* Total size */
2537 collated_status); /* SDU status */
2538
2539 /* SDU 2 */
2540 sdu_size = 20;
2541 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 40);
2542
2543 /* A new SDU should be allocated */
2544 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1],
2545 &isoal_global.sink_state[sink_hdl], /* Sink */
2546 &rx_pdu_meta_buf.pdu_meta); /* PDU */
2547
2548 /* SDU payload should be written */
2549 ZASSERT_ISOAL_SDU_WRITE_TEST(history[1],
2550 &rx_sdu_frag_buf[1], /* SDU buffer */
2551 0, /* SDU written */
2552 &rx_pdu_meta_buf.pdu[3 + 20], /* PDU payload */
2553 20); /* Size */
2554 /* SDU should be emitted */
2555 ZASSERT_ISOAL_SDU_EMIT_TEST(history[1],
2556 &isoal_global.sink_state[sink_hdl], /* Sink */
2557 BT_ISO_END, /* Frag state */
2558 sdu_size, /* Frag size */
2559 ISOAL_SDU_STATUS_VALID, /* Frag status */
2560 sdu_timestamp, /* Timestamp */
2561 seqn, /* Seq. number */
2562 sdu_buffer[1].dbuf, /* Buffer */
2563 sdu_buffer[1].size, /* Buffer size */
2564 total_sdu_size, /* Total size */
2565 collated_status); /* SDU status */
2566
2567 /* Test recombine (White Box) */
2568 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2569 ISOAL_START,
2570 "FSM state %s should be %s!",
2571 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2572 FSM_TO_STR(ISOAL_START));
2573 }
2574
2575 /**
2576 * Test Suite : RX unframed PDU reassembly
2577 *
2578 * Tests reassembly of two SDUs where the end fragment of the first was not seen
2579 */
ZTEST(test_rx_unframed,test_rx_unframed_dbl_pdu_prem)2580 ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_prem)
2581 {
2582 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
2583 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
2584 struct isoal_sdu_buffer sdu_buffer;
2585 isoal_sdu_status_t collated_status;
2586 isoal_sink_handle_t sink_hdl;
2587 uint32_t stream_sync_delay;
2588 uint32_t group_sync_delay;
2589 isoal_sdu_len_t sdu_size;
2590 uint8_t iso_interval_int;
2591 uint64_t payload_number;
2592 uint16_t total_sdu_size;
2593 uint32_t pdu_timestamp;
2594 uint32_t sdu_timestamp;
2595 uint16_t testdata_indx;
2596 uint16_t testdata_size;
2597 uint32_t sdu_interval;
2598 isoal_sdu_cnt_t seqn;
2599 uint8_t testdata[23];
2600 isoal_status_t err;
2601 uint32_t latency;
2602 uint8_t role;
2603 uint8_t BN;
2604 uint8_t FT;
2605
2606 /* Settings */
2607 role = ISOAL_ROLE_PERIPHERAL;
2608 iso_interval_int = 1;
2609 sdu_interval = ISO_INT_UNIT_US;
2610 BN = 1;
2611 FT = 1;
2612 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
2613 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
2614
2615 /* PDU 1 -------------------------------------------------------------*/
2616 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2617 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
2618 init_test_data_buffer(testdata, 23);
2619 sdu_buffer.dbuf = &rx_sdu_frag_buf;
2620 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
2621 payload_number = 2000;
2622 pdu_timestamp = 9249;
2623 latency = calc_rx_latency_by_role(role,
2624 false,
2625 FT,
2626 sdu_interval,
2627 iso_interval_int,
2628 stream_sync_delay,
2629 group_sync_delay);
2630 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
2631 seqn = 0;
2632 testdata_indx = 0;
2633 testdata_size = 13;
2634 sdu_size = 13;
2635 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
2636 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
2637
2638 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
2639 role, /* Role */
2640 false, /* Framed */
2641 BN, /* BN */
2642 FT, /* FT */
2643 sdu_interval, /* SDU Interval */
2644 iso_interval_int, /* ISO Interval */
2645 stream_sync_delay, /* Stream Sync Delay */
2646 group_sync_delay); /* Group Sync Delay */
2647
2648 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
2649 &testdata[testdata_indx],
2650 (testdata_size - testdata_indx),
2651 payload_number,
2652 pdu_timestamp,
2653 ISOAL_PDU_STATUS_VALID,
2654 &rx_pdu_meta_buf.pdu_meta);
2655
2656 /* Set callback function return values */
2657 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
2658 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
2659 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2660 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
2661
2662 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2663
2664 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2665
2666 /* A new SDU should be allocated */
2667 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
2668 &isoal_global.sink_state[sink_hdl], /* Sink */
2669 &rx_pdu_meta_buf.pdu_meta); /* PDU */
2670
2671 /* SDU payload should be written */
2672 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
2673 &rx_sdu_frag_buf, /* SDU buffer */
2674 0, /* SDU written */
2675 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2676 (testdata_size - testdata_indx)); /* Size */
2677 /* SDU should be emitted */
2678 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
2679 &isoal_global.sink_state[sink_hdl], /* Sink */
2680 BT_ISO_SINGLE, /* Frag state */
2681 sdu_size, /* Frag size */
2682 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
2683 sdu_timestamp, /* Timestamp */
2684 seqn, /* Seq. number */
2685 sdu_buffer.dbuf, /* Buffer */
2686 sdu_buffer.size, /* Buffer size */
2687 total_sdu_size, /* Total size */
2688 collated_status); /* SDU status */
2689
2690 /* Test recombine (White Box) */
2691 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2692 ISOAL_START,
2693 "FSM state %s should be %s!",
2694 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2695 FSM_TO_STR(ISOAL_START));
2696
2697 /* PDU 2 -------------------------------------------------------------*/
2698 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2699 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
2700 payload_number++;
2701 seqn++;
2702 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
2703 testdata_indx = testdata_size;
2704 testdata_size += 10;
2705 sdu_size = 10;
2706 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
2707 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
2708
2709 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
2710 &testdata[testdata_indx],
2711 (testdata_size - testdata_indx),
2712 payload_number,
2713 pdu_timestamp,
2714 ISOAL_PDU_STATUS_VALID,
2715 &rx_pdu_meta_buf.pdu_meta);
2716
2717 /* Set callback function return values */
2718 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
2719 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
2720 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2721 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
2722
2723 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2724
2725 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2726
2727 /* A new SDU should be allocated */
2728 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
2729 &isoal_global.sink_state[sink_hdl], /* Sink */
2730 &rx_pdu_meta_buf.pdu_meta); /* PDU */
2731
2732 /* SDU payload should be written */
2733 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
2734 &rx_sdu_frag_buf, /* SDU buffer */
2735 0, /* SDU written */
2736 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
2737 (testdata_size - testdata_indx)); /* Size */
2738 /* SDU should be emitted */
2739 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
2740 &isoal_global.sink_state[sink_hdl], /* Sink */
2741 BT_ISO_SINGLE, /* Frag state */
2742 sdu_size, /* Frag size */
2743 ISOAL_SDU_STATUS_VALID, /* Frag status */
2744 sdu_timestamp, /* Timestamp */
2745 seqn, /* Seq. number */
2746 sdu_buffer.dbuf, /* Buffer */
2747 sdu_buffer.size, /* Buffer size */
2748 total_sdu_size, /* Total size */
2749 collated_status); /* SDU status */
2750
2751 /* Test recombine (White Box) */
2752 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2753 ISOAL_START,
2754 "FSM state %s should be %s!",
2755 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2756 FSM_TO_STR(ISOAL_START));
2757 }
2758
2759 /**
2760 * Test Suite : RX unframed PDU reassembly
2761 *
2762 * Tests reassembly of SDUs with PDU errors
2763 */
ZTEST(test_rx_unframed,test_rx_unframed_single_pdu_err)2764 ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err)
2765 {
2766 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
2767 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
2768 struct isoal_sdu_buffer sdu_buffer;
2769 isoal_sdu_status_t collated_status;
2770 isoal_sink_handle_t sink_hdl;
2771 uint32_t stream_sync_delay;
2772 uint32_t group_sync_delay;
2773 isoal_sdu_len_t sdu_size;
2774 uint8_t iso_interval_int;
2775 uint64_t payload_number;
2776 uint16_t total_sdu_size;
2777 uint32_t pdu_timestamp;
2778 uint32_t sdu_timestamp;
2779 uint16_t testdata_indx;
2780 uint16_t testdata_size;
2781 uint32_t sdu_interval;
2782 isoal_sdu_cnt_t seqn;
2783 uint8_t testdata[23];
2784 isoal_status_t err;
2785 uint32_t latency;
2786 uint8_t role;
2787 uint8_t BN;
2788 uint8_t FT;
2789
2790 /* Settings */
2791 role = ISOAL_ROLE_PERIPHERAL;
2792 iso_interval_int = 1;
2793 sdu_interval = ISO_INT_UNIT_US;
2794 BN = 1;
2795 FT = 1;
2796 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
2797 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
2798
2799 /* PDU 1 -------------------------------------------------------------*/
2800 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2801 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
2802 init_test_data_buffer(testdata, 23);
2803 sdu_buffer.dbuf = &rx_sdu_frag_buf;
2804 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
2805 payload_number = 2000;
2806 pdu_timestamp = 9249;
2807 latency = calc_rx_latency_by_role(role,
2808 false,
2809 FT,
2810 sdu_interval,
2811 iso_interval_int,
2812 stream_sync_delay,
2813 group_sync_delay);
2814 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
2815 seqn = 0;
2816 testdata_indx = 0;
2817 testdata_size = 13;
2818 sdu_size = 0;
2819 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
2820 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
2821
2822 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
2823 role, /* Role */
2824 false, /* Framed */
2825 BN, /* BN */
2826 FT, /* FT */
2827 sdu_interval, /* SDU Interval */
2828 iso_interval_int, /* ISO Interval */
2829 stream_sync_delay, /* Stream Sync Delay */
2830 group_sync_delay); /* Group Sync Delay */
2831
2832 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
2833 &testdata[testdata_indx],
2834 (testdata_size - testdata_indx),
2835 payload_number,
2836 pdu_timestamp,
2837 ISOAL_PDU_STATUS_ERRORS,
2838 &rx_pdu_meta_buf.pdu_meta);
2839
2840 /* Set callback function return values */
2841 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
2842 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
2843 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2844 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
2845
2846 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2847
2848 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2849
2850 /* A new SDU should be allocated */
2851 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
2852 &isoal_global.sink_state[sink_hdl], /* Sink */
2853 &rx_pdu_meta_buf.pdu_meta); /* PDU */
2854
2855 /* SDU payload should not be written */
2856 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
2857
2858 /* SDU should be emitted */
2859 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
2860 &isoal_global.sink_state[sink_hdl], /* Sink */
2861 BT_ISO_SINGLE, /* Frag state */
2862 sdu_size, /* Frag size */
2863 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
2864 sdu_timestamp, /* Timestamp */
2865 seqn, /* Seq. number */
2866 sdu_buffer.dbuf, /* Buffer */
2867 sdu_buffer.size, /* Buffer size */
2868 total_sdu_size, /* Total size */
2869 collated_status); /* SDU status */
2870
2871 /* Test recombine (White Box) */
2872 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2873 ISOAL_START,
2874 "FSM state %s should be %s!",
2875 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2876 FSM_TO_STR(ISOAL_START));
2877
2878 /* PDU 2 -------------------------------------------------------------*/
2879 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2880 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
2881 payload_number++;
2882 seqn++;
2883 pdu_timestamp = 9249 + ISO_INT_UNIT_US;
2884 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
2885 testdata_indx = testdata_size;
2886 testdata_size += 10;
2887 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
2888 collated_status =
2889 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
2890
2891 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
2892 &testdata[testdata_indx],
2893 (testdata_size - testdata_indx),
2894 payload_number,
2895 pdu_timestamp,
2896 ISOAL_PDU_STATUS_LOST_DATA,
2897 &rx_pdu_meta_buf.pdu_meta);
2898
2899 /* Set callback function return values */
2900 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
2901 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
2902 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
2903 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
2904
2905 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
2906
2907 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
2908
2909 /* A new SDU should be allocated */
2910 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
2911 &isoal_global.sink_state[sink_hdl], /* Sink */
2912 &rx_pdu_meta_buf.pdu_meta); /* PDU */
2913
2914 /* SDU payload should not be written */
2915 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
2916
2917 /* SDU should be emitted */
2918 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
2919 &isoal_global.sink_state[sink_hdl], /* Sink */
2920 BT_ISO_SINGLE, /* Frag state */
2921 sdu_size, /* Frag size */
2922 ISOAL_PDU_STATUS_LOST_DATA, /* Frag status */
2923 sdu_timestamp, /* Timestamp */
2924 seqn, /* Seq. number */
2925 sdu_buffer.dbuf, /* Buffer */
2926 sdu_buffer.size, /* Buffer size */
2927 total_sdu_size, /* Total size */
2928 collated_status); /* SDU status */
2929
2930 /* Test recombine (White Box) */
2931 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
2932 ISOAL_START,
2933 "FSM state %s should be %s!",
2934 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
2935 FSM_TO_STR(ISOAL_START));
2936 }
2937
2938 /**
2939 * Test Suite : RX unframed PDU reassembly
2940 *
2941 * Tests reassembly of SDUs where PDUs are not in sequence
2942 */
ZTEST(test_rx_unframed,test_rx_unframed_seq_err)2943 ZTEST(test_rx_unframed, test_rx_unframed_seq_err)
2944 {
2945 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
2946 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
2947 struct isoal_sdu_buffer sdu_buffer;
2948 isoal_sdu_status_t collated_status;
2949 isoal_sink_handle_t sink_hdl;
2950 uint32_t stream_sync_delay;
2951 uint32_t group_sync_delay;
2952 isoal_sdu_len_t sdu_size;
2953 uint8_t iso_interval_int;
2954 uint64_t payload_number;
2955 uint16_t total_sdu_size;
2956 uint16_t sdu_written = 0;
2957 uint32_t pdu_timestamp;
2958 uint32_t sdu_timestamp;
2959 uint16_t testdata_indx;
2960 uint16_t testdata_size;
2961 uint32_t sdu_interval;
2962 isoal_sdu_cnt_t seqn;
2963 uint8_t testdata[43];
2964 isoal_status_t err;
2965 uint32_t latency;
2966 uint8_t role;
2967 uint8_t BN;
2968 uint8_t FT;
2969
2970 /* Settings */
2971 role = ISOAL_ROLE_PERIPHERAL;
2972 iso_interval_int = 1;
2973 sdu_interval = ISO_INT_UNIT_US;
2974 BN = 3;
2975 FT = 1;
2976 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
2977 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
2978
2979 /* PDU 1 -------------------------------------------------------------*/
2980 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
2981 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
2982 init_test_data_buffer(testdata, 43);
2983 sdu_buffer.dbuf = &rx_sdu_frag_buf;
2984 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
2985 payload_number = 2000;
2986 pdu_timestamp = 9249;
2987 latency = calc_rx_latency_by_role(role,
2988 false,
2989 FT,
2990 sdu_interval,
2991 iso_interval_int,
2992 stream_sync_delay,
2993 group_sync_delay);
2994 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
2995 seqn = 0;
2996 testdata_indx = 0;
2997 testdata_size = 13;
2998 sdu_size = 13;
2999
3000 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
3001 role, /* Role */
3002 false, /* Framed */
3003 BN, /* BN */
3004 FT, /* FT */
3005 sdu_interval, /* SDU Interval */
3006 iso_interval_int, /* ISO Interval */
3007 stream_sync_delay, /* Stream Sync Delay */
3008 group_sync_delay); /* Group Sync Delay */
3009
3010 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
3011 &testdata[testdata_indx],
3012 (testdata_size - testdata_indx),
3013 payload_number,
3014 pdu_timestamp,
3015 ISOAL_PDU_STATUS_VALID,
3016 &rx_pdu_meta_buf.pdu_meta);
3017
3018 /* Set callback function return values */
3019 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3020 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3021 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3022
3023 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3024
3025 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3026
3027 /* A new SDU should be allocated */
3028 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
3029 &isoal_global.sink_state[sink_hdl], /* Sink */
3030 &rx_pdu_meta_buf.pdu_meta); /* PDU */
3031
3032 /* SDU payload should be written */
3033 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3034 &rx_sdu_frag_buf, /* SDU buffer */
3035 sdu_written, /* SDU written */
3036 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3037 (testdata_size - testdata_indx)); /* Size */
3038
3039 /* SDU should not be emitted */
3040
3041 /* Test recombine (White Box) */
3042 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3043 ISOAL_CONTINUE,
3044 "FSM state %s should be %s!",
3045 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3046 FSM_TO_STR(ISOAL_CONTINUE));
3047
3048 /* PDU 2 Not transferred to ISO-AL ------------------------------------*/
3049 sdu_written += (testdata_size - testdata_indx);
3050 payload_number++;
3051 testdata_indx = testdata_size;
3052 testdata_size += 10;
3053
3054 /* PDU 3 -------------------------------------------------------------*/
3055 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3056 payload_number++;
3057 testdata_indx = testdata_size;
3058 testdata_size += 10;
3059 sdu_size += 10;
3060 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
3061 collated_status =
3062 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
3063
3064 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
3065 &testdata[testdata_indx],
3066 (testdata_size - testdata_indx),
3067 payload_number,
3068 pdu_timestamp,
3069 ISOAL_PDU_STATUS_VALID,
3070 &rx_pdu_meta_buf.pdu_meta);
3071
3072 /* Set callback function return values */
3073 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3074 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3075 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3076 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
3077
3078 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3079
3080 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3081
3082 /* Test recombine (Black Box) */
3083 /* A new SDU should not be allocated */
3084
3085 /* SDU payload should be written */
3086 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3087 &rx_sdu_frag_buf, /* SDU buffer */
3088 sdu_written, /* SDU written */
3089 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3090 (testdata_size - testdata_indx)); /* Size */
3091 /* SDU should be emitted */
3092 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
3093 &isoal_global.sink_state[sink_hdl], /* Sink */
3094 BT_ISO_SINGLE, /* Frag state */
3095 sdu_size, /* Frag size */
3096 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
3097 sdu_timestamp, /* Timestamp */
3098 seqn, /* Seq. number */
3099 sdu_buffer.dbuf, /* Buffer */
3100 sdu_buffer.size, /* Buffer size */
3101 total_sdu_size, /* Total size */
3102 collated_status); /* SDU status */
3103
3104 /* Test recombine (White Box) */
3105 /* PDU count will not have reached 3 as one PDU was not received, so
3106 * last_pdu will not be set and the state should remain in Error
3107 * Spooling.
3108 */
3109 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3110 ISOAL_ERR_SPOOL,
3111 "FSM state %s should be %s!",
3112 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3113 FSM_TO_STR(ISOAL_ERR_SPOOL));
3114
3115 /* PDU 4 -------------------------------------------------------------*/
3116 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3117 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
3118 sdu_written = 0;
3119 payload_number++;
3120 seqn++;
3121 pdu_timestamp = 9249 + ISO_INT_UNIT_US;
3122 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
3123 testdata_indx = testdata_size;
3124 testdata_size += 10;
3125 sdu_size = 10;
3126
3127 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
3128 &testdata[testdata_indx],
3129 (testdata_size - testdata_indx),
3130 payload_number,
3131 pdu_timestamp,
3132 ISOAL_PDU_STATUS_VALID,
3133 &rx_pdu_meta_buf.pdu_meta);
3134
3135 /* Set callback function return values */
3136 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3137 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3138 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3139 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
3140
3141 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3142
3143 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3144
3145 /* Test recombine (Black Box) */
3146 /* A new SDU should be allocated */
3147 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
3148 &isoal_global.sink_state[sink_hdl], /* Sink */
3149 &rx_pdu_meta_buf.pdu_meta); /* PDU */
3150
3151 /* SDU payload should be written */
3152 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3153 &rx_sdu_frag_buf, /* SDU buffer */
3154 sdu_written, /* SDU written */
3155 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3156 (testdata_size - testdata_indx)); /* Size */
3157 /* SDU should not be emitted */
3158
3159 /* Test recombine (White Box) */
3160 /* Detecting the transition from an end fragment to a start fragment
3161 * should have triggered the monitoring code to pull the state machine
3162 * out of Eroor spooling and directly into the start of a new SDU. As
3163 * this was not an end fragment, the next state should be continue.
3164 */
3165 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3166 ISOAL_CONTINUE,
3167 "FSM state %s should be %s!",
3168 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3169 FSM_TO_STR(ISOAL_CONTINUE));
3170 }
3171
3172 /**
3173 * Test Suite : RX unframed PDU reassembly
3174 *
3175 * Tests reassembly of SDUs where PDUs are not in sequence with errors
3176 * Tests error prioritization
3177 */
ZTEST(test_rx_unframed,test_rx_unframed_seq_pdu_err1)3178 ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err1)
3179 {
3180 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
3181 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
3182 struct isoal_sdu_buffer sdu_buffer;
3183 isoal_sdu_status_t collated_status;
3184 isoal_sink_handle_t sink_hdl;
3185 uint32_t stream_sync_delay;
3186 uint32_t group_sync_delay;
3187 isoal_sdu_len_t sdu_size;
3188 uint8_t iso_interval_int;
3189 uint64_t payload_number;
3190 uint16_t total_sdu_size;
3191 uint16_t sdu_written = 0;
3192 uint32_t pdu_timestamp;
3193 uint32_t sdu_timestamp;
3194 uint16_t testdata_indx;
3195 uint16_t testdata_size;
3196 uint32_t sdu_interval;
3197 isoal_sdu_cnt_t seqn;
3198 uint8_t testdata[43];
3199 isoal_status_t err;
3200 uint32_t latency;
3201 uint8_t role;
3202 uint8_t BN;
3203 uint8_t FT;
3204
3205 /* Settings */
3206 role = ISOAL_ROLE_PERIPHERAL;
3207 iso_interval_int = 1;
3208 sdu_interval = ISO_INT_UNIT_US;
3209 BN = 3;
3210 FT = 1;
3211 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
3212 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
3213
3214 /* PDU 1 -------------------------------------------------------------*/
3215 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3216 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
3217 init_test_data_buffer(testdata, 43);
3218 sdu_buffer.dbuf = &rx_sdu_frag_buf;
3219 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
3220 payload_number = 1000 * BN;
3221 pdu_timestamp = 9249;
3222 latency = calc_rx_latency_by_role(role,
3223 false,
3224 FT,
3225 sdu_interval,
3226 iso_interval_int,
3227 stream_sync_delay,
3228 group_sync_delay);
3229 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
3230 seqn = 0;
3231 testdata_indx = 0;
3232 testdata_size = 13;
3233 sdu_size = 13;
3234
3235 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
3236 role, /* Role */
3237 false, /* Framed */
3238 BN, /* BN */
3239 FT, /* FT */
3240 sdu_interval, /* SDU Interval */
3241 iso_interval_int, /* ISO Interval */
3242 stream_sync_delay, /* Stream Sync Delay */
3243 group_sync_delay); /* Group Sync Delay */
3244
3245 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
3246 &testdata[testdata_indx],
3247 (testdata_size - testdata_indx),
3248 payload_number,
3249 pdu_timestamp,
3250 ISOAL_PDU_STATUS_VALID,
3251 &rx_pdu_meta_buf.pdu_meta);
3252
3253 /* Set callback function return values */
3254 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3255 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3256 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3257
3258 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3259
3260 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3261
3262 /* Test recombine (Black Box) */
3263 /* A new SDU should be allocated */
3264 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
3265 &isoal_global.sink_state[sink_hdl], /* Sink */
3266 &rx_pdu_meta_buf.pdu_meta); /* PDU */
3267
3268 /* SDU payload should be written */
3269 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3270 &rx_sdu_frag_buf, /* SDU buffer */
3271 sdu_written, /* SDU written */
3272 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3273 (testdata_size - testdata_indx)); /* Size */
3274 /* SDU should not be emitted */
3275
3276 /* Test recombine (White Box) */
3277 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3278 ISOAL_CONTINUE,
3279 "FSM state %s should be %s!",
3280 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3281 FSM_TO_STR(ISOAL_CONTINUE));
3282
3283 /* PDU 2 Not transferred to ISO-AL ------------------------------------*/
3284 payload_number++;
3285 testdata_indx = testdata_size;
3286 testdata_size += 10;
3287
3288 /* PDU 3 -------------------------------------------------------------*/
3289 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3290 payload_number++;
3291 testdata_indx = testdata_size;
3292 testdata_size += 10;
3293 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
3294 collated_status =
3295 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
3296
3297 /* PDU status ISOAL_PDU_STATUS_ERRORS */
3298 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
3299 &testdata[testdata_indx],
3300 (testdata_size - testdata_indx),
3301 payload_number,
3302 pdu_timestamp,
3303 ISOAL_PDU_STATUS_ERRORS,
3304 &rx_pdu_meta_buf.pdu_meta);
3305
3306 /* Set callback function return values */
3307 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3308 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
3309
3310 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3311
3312 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3313
3314 /* Test recombine (Black Box) */
3315 /* A new SDU should not be allocated */
3316 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
3317
3318 /* SDU payload should not be written */
3319 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1);
3320
3321 /* SDU should be emitted */
3322 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
3323 &isoal_global.sink_state[sink_hdl], /* Sink */
3324 BT_ISO_SINGLE, /* Frag state */
3325 sdu_size, /* Frag size */
3326 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
3327 sdu_timestamp, /* Timestamp */
3328 seqn, /* Seq. number */
3329 sdu_buffer.dbuf, /* Buffer */
3330 sdu_buffer.size, /* Buffer size */
3331 total_sdu_size, /* Total size */
3332 collated_status); /* SDU status */
3333
3334 /* Test recombine (White Box) */
3335 /* PDU count will not have reached 3 as one PDU was not received, so
3336 * last_pdu will not be set and the state should remain in Error
3337 * Spooling.
3338 */
3339 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3340 ISOAL_ERR_SPOOL,
3341 "FSM state %s should be %s!",
3342 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3343 FSM_TO_STR(ISOAL_ERR_SPOOL));
3344
3345 /* PDU 4 -------------------------------------------------------------*/
3346 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3347 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
3348 sdu_written = 0;
3349 payload_number++;
3350 seqn++;
3351 pdu_timestamp = 9249 + ISO_INT_UNIT_US;
3352 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
3353 testdata_indx = testdata_size;
3354 testdata_size += 10;
3355 sdu_size = 10;
3356
3357 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
3358 &testdata[testdata_indx],
3359 (testdata_size - testdata_indx),
3360 payload_number,
3361 pdu_timestamp,
3362 ISOAL_PDU_STATUS_VALID,
3363 &rx_pdu_meta_buf.pdu_meta);
3364
3365 /* Set callback function return values */
3366 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3367 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3368 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3369
3370 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3371
3372 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3373
3374 /* Test recombine (Black Box) */
3375 /* A new SDU should be allocated */
3376 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
3377 &isoal_global.sink_state[sink_hdl], /* Sink */
3378 &rx_pdu_meta_buf.pdu_meta); /* PDU */
3379
3380 /* SDU payload should be written */
3381 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3382 &rx_sdu_frag_buf, /* SDU buffer */
3383 sdu_written, /* SDU written */
3384 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3385 (testdata_size - testdata_indx)); /* Size */
3386 /* SDU should not be emitted */
3387
3388 /* Test recombine (White Box) */
3389 /* Detecting the transition from an end fragment to a start fragment
3390 * should have triggered the monitoring code to pull the state machine
3391 * out of Eroor spooling and directly into the start of a new SDU. As
3392 * this was not an end fragment, the next state should be continue.
3393 */
3394 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3395 ISOAL_CONTINUE,
3396 "FSM state %s should be %s!",
3397 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3398 FSM_TO_STR(ISOAL_CONTINUE));
3399
3400 /* PDU 5 -------------------------------------------------------------*/
3401 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3402 sdu_written += (testdata_size - testdata_indx);
3403 payload_number++;
3404 testdata_indx = testdata_size;
3405 testdata_size += 10;
3406 sdu_size += 10;
3407 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
3408 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
3409
3410 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
3411 &testdata[testdata_indx],
3412 (testdata_size - testdata_indx),
3413 payload_number,
3414 pdu_timestamp,
3415 ISOAL_PDU_STATUS_VALID,
3416 &rx_pdu_meta_buf.pdu_meta);
3417
3418 /* Set callback function return values */
3419 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3420 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
3421
3422 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3423
3424 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3425
3426 /* Test recombine (Black Box) */
3427 /* A new SDU should not be allocated */
3428
3429 /* SDU payload should be written */
3430 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3431 &rx_sdu_frag_buf, /* SDU buffer */
3432 sdu_written, /* SDU written */
3433 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3434 (testdata_size - testdata_indx)); /* Size */
3435 /* SDU should be emitted */
3436 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
3437 &isoal_global.sink_state[sink_hdl], /* Sink */
3438 BT_ISO_SINGLE, /* Frag state */
3439 sdu_size, /* Frag size */
3440 ISOAL_SDU_STATUS_VALID, /* Frag status */
3441 sdu_timestamp, /* Timestamp */
3442 seqn, /* Seq. number */
3443 sdu_buffer.dbuf, /* Buffer */
3444 sdu_buffer.size, /* Buffer size */
3445 total_sdu_size, /* Total size */
3446 collated_status); /* SDU status */
3447
3448 /* Test recombine (White Box) */
3449 /* Expecting padding so state should be Error Spooling */
3450 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3451 ISOAL_ERR_SPOOL,
3452 "FSM state %s should be %s!",
3453 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3454 FSM_TO_STR(ISOAL_ERR_SPOOL));
3455 }
3456
3457 /**
3458 * Test Suite : RX unframed PDU reassembly
3459 *
3460 * Tests reassembly of SDUs where PDUs are not in sequence with errors
3461 * Tests releasing and collating information for buffered SDUs when an error in
3462 * reception occurs.
3463 */
ZTEST(test_rx_unframed,test_rx_unframed_seq_pdu_err2)3464 ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err2)
3465 {
3466 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
3467 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
3468 struct isoal_sdu_buffer sdu_buffer;
3469 isoal_sdu_status_t collated_status;
3470 isoal_sink_handle_t sink_hdl;
3471 uint32_t stream_sync_delay;
3472 uint32_t group_sync_delay;
3473 isoal_sdu_len_t sdu_size;
3474 uint8_t iso_interval_int;
3475 uint64_t payload_number;
3476 uint16_t total_sdu_size;
3477 uint16_t sdu_written = 0;
3478 uint32_t pdu_timestamp;
3479 uint32_t sdu_timestamp;
3480 uint16_t testdata_indx;
3481 uint16_t testdata_size;
3482 uint32_t sdu_interval;
3483 isoal_sdu_cnt_t seqn;
3484 uint8_t testdata[80];
3485 isoal_status_t err;
3486 uint32_t latency;
3487 uint8_t role;
3488 uint8_t BN;
3489 uint8_t FT;
3490
3491 /* Settings */
3492 role = ISOAL_ROLE_PERIPHERAL;
3493 iso_interval_int = 1;
3494 sdu_interval = ISO_INT_UNIT_US;
3495 BN = 3;
3496 FT = 1;
3497 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
3498 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
3499
3500 /* PDU 1 -------------------------------------------------------------*/
3501 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3502 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
3503 init_test_data_buffer(testdata, 80);
3504 sdu_buffer.dbuf = &rx_sdu_frag_buf;
3505 sdu_buffer.size = 40;
3506 payload_number = 1000 * BN;
3507 pdu_timestamp = 9249;
3508 latency = calc_rx_latency_by_role(role,
3509 false,
3510 FT,
3511 sdu_interval,
3512 iso_interval_int,
3513 stream_sync_delay,
3514 group_sync_delay);
3515 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
3516 seqn = 0;
3517 testdata_indx = 0;
3518 testdata_size = 40;
3519 sdu_size = 40;
3520 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 50);
3521 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_LOST_DATA);
3522
3523 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
3524 role, /* Role */
3525 false, /* Framed */
3526 BN, /* BN */
3527 FT, /* FT */
3528 sdu_interval, /* SDU Interval */
3529 iso_interval_int, /* ISO Interval */
3530 stream_sync_delay, /* Stream Sync Delay */
3531 group_sync_delay); /* Group Sync Delay */
3532
3533 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
3534 &testdata[testdata_indx],
3535 (testdata_size - testdata_indx),
3536 payload_number,
3537 pdu_timestamp,
3538 ISOAL_PDU_STATUS_VALID,
3539 &rx_pdu_meta_buf.pdu_meta);
3540
3541 /* Set callback function return values */
3542 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3543 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3544 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3545 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
3546
3547 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3548
3549 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3550
3551 /* Test recombine (Black Box) */
3552 /* A new SDU should be allocated */
3553 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
3554 &isoal_global.sink_state[sink_hdl], /* Sink */
3555 &rx_pdu_meta_buf.pdu_meta); /* PDU */
3556
3557 /* SDU payload should be written */
3558 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3559 &rx_sdu_frag_buf, /* SDU buffer */
3560 sdu_written, /* SDU written */
3561 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3562 (testdata_size - testdata_indx)); /* Size */
3563 /* SDU should be emitted */
3564 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
3565 &isoal_global.sink_state[sink_hdl], /* Sink */
3566 BT_ISO_START, /* Frag state */
3567 sdu_size, /* Frag size */
3568 ISOAL_SDU_STATUS_VALID, /* Frag status */
3569 sdu_timestamp, /* Timestamp */
3570 seqn, /* Seq. number */
3571 sdu_buffer.dbuf, /* Buffer */
3572 sdu_buffer.size, /* Buffer size */
3573 total_sdu_size, /* Total size */
3574 collated_status); /* SDU status */
3575
3576 /* Test recombine (White Box) */
3577 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3578 ISOAL_CONTINUE,
3579 "FSM state %s should be %s!",
3580 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3581 FSM_TO_STR(ISOAL_CONTINUE));
3582
3583 /* PDU 2 Not transferred to ISO-AL ------------------------------------*/
3584 payload_number++;
3585 testdata_indx = testdata_size;
3586 testdata_size += 10;
3587
3588 /* PDU 3 -------------------------------------------------------------*/
3589 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3590 payload_number++;
3591 testdata_indx = testdata_size;
3592 testdata_size += 10;
3593 sdu_size = 0;
3594 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 50);
3595 collated_status =
3596 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
3597
3598 /* PDU status ISOAL_PDU_STATUS_ERRORS */
3599 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
3600 &testdata[testdata_indx],
3601 (testdata_size - testdata_indx),
3602 payload_number,
3603 pdu_timestamp,
3604 ISOAL_PDU_STATUS_ERRORS,
3605 &rx_pdu_meta_buf.pdu_meta);
3606
3607 /* Set callback function return values */
3608 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3609 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3610 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3611 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
3612
3613 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3614
3615 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3616
3617 /* Test recombine (Black Box) */
3618 /* A new SDU should be allocated */
3619 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
3620 &isoal_global.sink_state[sink_hdl], /* Sink */
3621 &rx_pdu_meta_buf.pdu_meta); /* PDU */
3622
3623 /* SDU payload should not be written */
3624 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1);
3625
3626 /* SDU should be emitted */
3627 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
3628 &isoal_global.sink_state[sink_hdl], /* Sink */
3629 BT_ISO_END, /* Frag state */
3630 sdu_size, /* Frag size */
3631 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
3632 sdu_timestamp, /* Timestamp */
3633 seqn, /* Seq. number */
3634 sdu_buffer.dbuf, /* Buffer */
3635 sdu_buffer.size, /* Buffer size */
3636 total_sdu_size, /* Total size */
3637 collated_status); /* SDU status */
3638
3639 /* Test recombine (White Box) */
3640 /* PDU count will not have reached 3 as one PDU was not received, so
3641 * last_pdu will not be set and the state should remain in Error
3642 * Spooling.
3643 */
3644 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3645 ISOAL_ERR_SPOOL,
3646 "FSM state %s should be %s!",
3647 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3648 FSM_TO_STR(ISOAL_ERR_SPOOL));
3649
3650 /* PDU 4 -------------------------------------------------------------*/
3651 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3652 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
3653 sdu_written = 0;
3654 payload_number++;
3655 seqn++;
3656 pdu_timestamp = 9249 + ISO_INT_UNIT_US;
3657 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
3658 testdata_indx = testdata_size;
3659 testdata_size += 10;
3660 sdu_size = 10;
3661
3662 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
3663 &testdata[testdata_indx],
3664 (testdata_size - testdata_indx),
3665 payload_number,
3666 pdu_timestamp,
3667 ISOAL_PDU_STATUS_VALID,
3668 &rx_pdu_meta_buf.pdu_meta);
3669
3670 /* Set callback function return values */
3671 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3672 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3673 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3674
3675 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3676
3677 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3678
3679 /* Test recombine (Black Box) */
3680 /* A new SDU should be allocated */
3681 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
3682 &isoal_global.sink_state[sink_hdl], /* Sink */
3683 &rx_pdu_meta_buf.pdu_meta); /* PDU */
3684
3685 /* SDU payload should be written */
3686 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3687 &rx_sdu_frag_buf, /* SDU buffer */
3688 sdu_written, /* SDU written */
3689 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3690 (testdata_size - testdata_indx)); /* Size */
3691 /* SDU should not be emitted */
3692
3693 /* Test recombine (White Box) */
3694 /* Detecting the transition from an end fragment to a start fragment
3695 * should have triggered the monitoring code to pull the state machine
3696 * out of Eroor spooling and directly into the start of a new SDU. As
3697 * this was not an end fragment, the next state should be continue.
3698 */
3699 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3700 ISOAL_CONTINUE,
3701 "FSM state %s should be %s!",
3702 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3703 FSM_TO_STR(ISOAL_CONTINUE));
3704
3705 /* PDU 5 -------------------------------------------------------------*/
3706 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3707 sdu_written += (testdata_size - testdata_indx);
3708 payload_number++;
3709 testdata_indx = testdata_size;
3710 testdata_size += 10;
3711 sdu_size += 10;
3712 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
3713 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
3714
3715 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
3716 &testdata[testdata_indx],
3717 (testdata_size - testdata_indx),
3718 payload_number,
3719 pdu_timestamp,
3720 ISOAL_PDU_STATUS_VALID,
3721 &rx_pdu_meta_buf.pdu_meta);
3722
3723 /* Set callback function return values */
3724 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3725 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
3726
3727 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3728
3729 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3730
3731 /* Test recombine (Black Box) */
3732 /* Should not allocate a new SDU */
3733
3734 /* SDU payload should be written */
3735 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3736 &rx_sdu_frag_buf, /* SDU buffer */
3737 sdu_written, /* SDU written */
3738 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3739 (testdata_size - testdata_indx)); /* Size */
3740 /* SDU should be emitted */
3741 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
3742 &isoal_global.sink_state[sink_hdl], /* Sink */
3743 BT_ISO_SINGLE, /* Frag state */
3744 sdu_size, /* Frag size */
3745 ISOAL_SDU_STATUS_VALID, /* Frag status */
3746 sdu_timestamp, /* Timestamp */
3747 seqn, /* Seq. number */
3748 sdu_buffer.dbuf, /* Buffer */
3749 sdu_buffer.size, /* Buffer size */
3750 total_sdu_size, /* Total size */
3751 collated_status); /* SDU status */
3752
3753 /* Test recombine (White Box) */
3754 /* Expecting padding so state should be Error Spooling */
3755 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3756 ISOAL_ERR_SPOOL,
3757 "FSM state %s should be %s!",
3758 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3759 FSM_TO_STR(ISOAL_ERR_SPOOL));
3760 }
3761
3762 /**
3763 * Test Suite : RX unframed PDU reassembly
3764 *
3765 * Tests reassembly of SDUs where valid PDUs are followed by padding
3766 */
ZTEST(test_rx_unframed,test_rx_unframed_padding)3767 ZTEST(test_rx_unframed, test_rx_unframed_padding)
3768 {
3769 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
3770 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
3771 struct isoal_sdu_buffer sdu_buffer;
3772 isoal_sdu_status_t collated_status;
3773 isoal_sink_handle_t sink_hdl;
3774 uint32_t stream_sync_delay;
3775 uint32_t group_sync_delay;
3776 isoal_sdu_len_t sdu_size;
3777 uint8_t iso_interval_int;
3778 uint64_t payload_number;
3779 uint16_t total_sdu_size;
3780 uint16_t sdu_written = 0;
3781 uint32_t pdu_timestamp;
3782 uint32_t sdu_timestamp;
3783 uint16_t testdata_indx;
3784 uint16_t testdata_size;
3785 uint32_t sdu_interval;
3786 isoal_sdu_cnt_t seqn;
3787 uint8_t testdata[43];
3788 isoal_status_t err;
3789 uint32_t latency;
3790 uint8_t role;
3791 uint8_t BN;
3792 uint8_t FT;
3793
3794 /* Settings */
3795 role = ISOAL_ROLE_PERIPHERAL;
3796 iso_interval_int = 1;
3797 sdu_interval = ISO_INT_UNIT_US;
3798 BN = 4;
3799 FT = 1;
3800 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
3801 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
3802
3803 /* PDU 1 -------------------------------------------------------------*/
3804 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3805 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
3806 init_test_data_buffer(testdata, 43);
3807 sdu_buffer.dbuf = &rx_sdu_frag_buf;
3808 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
3809 payload_number = 1000 * BN;
3810 pdu_timestamp = 9249;
3811 latency = calc_rx_latency_by_role(role,
3812 false,
3813 FT,
3814 sdu_interval,
3815 iso_interval_int,
3816 stream_sync_delay,
3817 group_sync_delay);
3818 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
3819 seqn = 0;
3820 testdata_indx = 0;
3821 testdata_size = 13;
3822 sdu_size = 13;
3823
3824 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
3825 role, /* Role */
3826 false, /* Framed */
3827 BN, /* BN */
3828 FT, /* FT */
3829 sdu_interval, /* SDU Interval */
3830 iso_interval_int, /* ISO Interval */
3831 stream_sync_delay, /* Stream Sync Delay */
3832 group_sync_delay); /* Group Sync Delay */
3833
3834 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
3835 &testdata[testdata_indx],
3836 (testdata_size - testdata_indx),
3837 payload_number,
3838 pdu_timestamp,
3839 ISOAL_PDU_STATUS_VALID,
3840 &rx_pdu_meta_buf.pdu_meta);
3841
3842 /* Set callback function return values */
3843 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3844 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3845 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3846
3847 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3848
3849 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3850
3851 /* Test recombine (Black Box) */
3852 /* A new SDU should be allocated */
3853 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
3854 &isoal_global.sink_state[sink_hdl], /* Sink */
3855 &rx_pdu_meta_buf.pdu_meta); /* PDU */
3856
3857 /* SDU payload should be written */
3858 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3859 &rx_sdu_frag_buf, /* SDU buffer */
3860 sdu_written, /* SDU written */
3861 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3862 (testdata_size - testdata_indx)); /* Size */
3863 /* SDU should not be emitted */
3864
3865 /* Test recombine (White Box) */
3866 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3867 ISOAL_CONTINUE,
3868 "FSM state %s should be %s!",
3869 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3870 FSM_TO_STR(ISOAL_CONTINUE));
3871
3872 /* PDU 2 -------------------------------------------------------------*/
3873 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3874 sdu_written += (testdata_size - testdata_indx);
3875 payload_number++;
3876 testdata_indx = testdata_size;
3877 testdata_size += 10;
3878 sdu_size += 10;
3879 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
3880 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
3881
3882 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
3883 &testdata[testdata_indx],
3884 (testdata_size - testdata_indx),
3885 payload_number,
3886 pdu_timestamp,
3887 ISOAL_PDU_STATUS_VALID,
3888 &rx_pdu_meta_buf.pdu_meta);
3889
3890 /* Set callback function return values */
3891 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
3892 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
3893 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
3894 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
3895
3896 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3897
3898 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3899
3900 /* Test recombine (Black Box) */
3901 /* A new SDU should not be allocated */
3902
3903 /* SDU payload should be written */
3904 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
3905 &rx_sdu_frag_buf, /* SDU buffer */
3906 sdu_written, /* SDU written */
3907 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
3908 (testdata_size - testdata_indx)); /* Size */
3909 /* SDU should be emitted */
3910 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
3911 &isoal_global.sink_state[sink_hdl], /* Sink */
3912 BT_ISO_SINGLE, /* Frag state */
3913 sdu_size, /* Frag size */
3914 ISOAL_SDU_STATUS_VALID, /* Frag status */
3915 sdu_timestamp, /* Timestamp */
3916 seqn, /* Seq. number */
3917 sdu_buffer.dbuf, /* Buffer */
3918 sdu_buffer.size, /* Buffer size */
3919 total_sdu_size, /* Total size */
3920 collated_status); /* SDU status */
3921
3922 /* Test recombine (White Box) */
3923 /* Expecting padding PDUs so should be in Error Spool state */
3924 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3925 ISOAL_ERR_SPOOL,
3926 "FSM state %s should be %s!",
3927 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3928 FSM_TO_STR(ISOAL_ERR_SPOOL));
3929
3930 /* PDU 3 -------------------------------------------------------------*/
3931 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3932 payload_number++;
3933 testdata_indx = testdata_size;
3934
3935 /* PDU padding 1 */
3936 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
3937 &testdata[testdata_indx],
3938 (testdata_size - testdata_indx),
3939 payload_number,
3940 pdu_timestamp,
3941 ISOAL_PDU_STATUS_VALID,
3942 &rx_pdu_meta_buf.pdu_meta);
3943
3944 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3945
3946 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3947
3948 /* Test recombine (Black Box) */
3949 /* Should not allocate a new SDU */
3950
3951 /* SDU should not be written to */
3952
3953 /* SDU should not be emitted */
3954
3955 /* Test recombine (White Box) */
3956 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3957 ISOAL_ERR_SPOOL,
3958 "FSM state %s should be %s!",
3959 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3960 FSM_TO_STR(ISOAL_ERR_SPOOL));
3961
3962 /* PDU 4 -------------------------------------------------------------*/
3963 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
3964 payload_number++;
3965
3966 /* PDU padding 2 */
3967 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
3968 &testdata[testdata_indx],
3969 (testdata_size - testdata_indx),
3970 payload_number,
3971 pdu_timestamp,
3972 ISOAL_PDU_STATUS_VALID,
3973 &rx_pdu_meta_buf.pdu_meta);
3974
3975 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
3976
3977 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
3978
3979 /* Test recombine (Black Box) */
3980 /* Should not allocate a new SDU */
3981
3982 /* SDU should not be written to */
3983
3984 /* SDU should not be emitted */
3985
3986 /* Test recombine (White Box) */
3987 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
3988 ISOAL_START,
3989 "FSM state %s should be %s!",
3990 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
3991 FSM_TO_STR(ISOAL_START));
3992 }
3993
3994 /**
3995 * Test Suite : RX unframed PDU reassembly
3996 *
3997 * Tests reassembly of SDUs with padding where the end was not seen
3998 */
ZTEST(test_rx_unframed,test_rx_unframed_padding_no_end)3999 ZTEST(test_rx_unframed, test_rx_unframed_padding_no_end)
4000 {
4001 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
4002 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
4003 struct isoal_sdu_buffer sdu_buffer;
4004 isoal_sdu_status_t collated_status;
4005 isoal_sink_handle_t sink_hdl;
4006 uint32_t stream_sync_delay;
4007 uint32_t group_sync_delay;
4008 isoal_sdu_len_t sdu_size;
4009 uint8_t iso_interval_int;
4010 uint64_t payload_number;
4011 uint16_t total_sdu_size;
4012 uint32_t pdu_timestamp;
4013 uint32_t sdu_timestamp;
4014 uint16_t testdata_indx;
4015 uint16_t testdata_size;
4016 uint32_t sdu_interval;
4017 isoal_sdu_cnt_t seqn;
4018 uint8_t testdata[33];
4019 isoal_status_t err;
4020 uint32_t latency;
4021 uint8_t role;
4022 uint8_t BN;
4023 uint8_t FT;
4024
4025 /* Settings */
4026 role = ISOAL_ROLE_PERIPHERAL;
4027 iso_interval_int = 1;
4028 sdu_interval = ISO_INT_UNIT_US;
4029 BN = 3;
4030 FT = 1;
4031 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4032 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4033
4034 /* PDU 1 -------------------------------------------------------------*/
4035 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4036 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
4037 init_test_data_buffer(testdata, 33);
4038 sdu_buffer.dbuf = &rx_sdu_frag_buf;
4039 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
4040 payload_number = 1000 * BN;
4041 pdu_timestamp = 9249;
4042 latency = calc_rx_latency_by_role(role,
4043 false,
4044 FT,
4045 sdu_interval,
4046 iso_interval_int,
4047 stream_sync_delay,
4048 group_sync_delay);
4049 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
4050 seqn = 0;
4051 testdata_indx = 0;
4052 testdata_size = 13;
4053 sdu_size = 13;
4054
4055 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
4056 role, /* Role */
4057 false, /* Framed */
4058 BN, /* BN */
4059 FT, /* FT */
4060 sdu_interval, /* SDU Interval */
4061 iso_interval_int, /* ISO Interval */
4062 stream_sync_delay, /* Stream Sync Delay */
4063 group_sync_delay); /* Group Sync Delay */
4064
4065 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4066 &testdata[testdata_indx],
4067 (testdata_size - testdata_indx),
4068 payload_number,
4069 pdu_timestamp,
4070 ISOAL_PDU_STATUS_VALID,
4071 &rx_pdu_meta_buf.pdu_meta);
4072
4073 /* Set callback function return values */
4074 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
4075 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
4076 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
4077
4078 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4079
4080 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4081
4082 /* Test recombine (Black Box) */
4083 /* A new SDU should be allocated */
4084 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
4085 &isoal_global.sink_state[sink_hdl], /* Sink */
4086 &rx_pdu_meta_buf.pdu_meta); /* PDU */
4087
4088 /* SDU payload should be written */
4089 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
4090 &rx_sdu_frag_buf, /* SDU buffer */
4091 0, /* SDU written */
4092 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
4093 (testdata_size - testdata_indx)); /* Size */
4094 /* SDU should not be emitted */
4095
4096 /* Test recombine (White Box) */
4097 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4098 ISOAL_CONTINUE,
4099 "FSM state %s should be %s!",
4100 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4101 FSM_TO_STR(ISOAL_CONTINUE));
4102
4103 /* PDU 2 -------------------------------------------------------------*/
4104 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4105 payload_number++;
4106 testdata_indx = testdata_size;
4107
4108 /* PDU padding 1 */
4109 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4110 &testdata[testdata_indx],
4111 (testdata_size - testdata_indx),
4112 payload_number,
4113 pdu_timestamp,
4114 ISOAL_PDU_STATUS_VALID,
4115 &rx_pdu_meta_buf.pdu_meta);
4116
4117 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4118
4119 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4120
4121 /* Test recombine (Black Box) */
4122 /* Should not allocate a new SDU */
4123
4124 /* SDU should not be written to */
4125
4126 /* SDU should not be emitted */
4127
4128 /* Test recombine (White Box) */
4129 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4130 ISOAL_CONTINUE,
4131 "FSM state %s should be %s!",
4132 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4133 FSM_TO_STR(ISOAL_CONTINUE));
4134
4135 /* PDU 3 -------------------------------------------------------------*/
4136 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4137 payload_number++;
4138 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
4139 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
4140
4141 /* PDU padding 2 */
4142 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4143 &testdata[testdata_indx],
4144 (testdata_size - testdata_indx),
4145 payload_number,
4146 pdu_timestamp,
4147 ISOAL_PDU_STATUS_VALID,
4148 &rx_pdu_meta_buf.pdu_meta);
4149
4150 /* Set callback function return values */
4151 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
4152
4153 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4154
4155 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4156
4157 /* Test recombine (Black Box) */
4158 /* A new SDU should not be allocated */
4159
4160 /* SDU payload should not be written */
4161
4162 /* SDU should be emitted */
4163 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
4164 &isoal_global.sink_state[sink_hdl], /* Sink */
4165 BT_ISO_SINGLE, /* Frag state */
4166 sdu_size, /* Frag size */
4167 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
4168 sdu_timestamp, /* Timestamp */
4169 seqn, /* Seq. number */
4170 sdu_buffer.dbuf, /* Buffer */
4171 sdu_buffer.size, /* Buffer size */
4172 total_sdu_size, /* Total size */
4173 collated_status); /* SDU status */
4174
4175 /* Test recombine (White Box) */
4176 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4177 ISOAL_START,
4178 "FSM state %s should be %s!",
4179 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4180 FSM_TO_STR(ISOAL_START));
4181 }
4182
4183 /**
4184 * Test Suite : RX unframed PDU reassembly
4185 *
4186 * Tests reassembly of SDUs where only padding has been received without any
4187 * other valid PDUs.
4188 */
ZTEST(test_rx_unframed,test_rx_unframed_padding_only)4189 ZTEST(test_rx_unframed, test_rx_unframed_padding_only)
4190 {
4191 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
4192 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
4193 struct isoal_sdu_buffer sdu_buffer;
4194 isoal_sdu_status_t collated_status;
4195 isoal_sink_handle_t sink_hdl;
4196 uint32_t stream_sync_delay;
4197 uint32_t group_sync_delay;
4198 isoal_sdu_len_t sdu_size;
4199 uint8_t iso_interval_int;
4200 uint64_t payload_number;
4201 uint16_t total_sdu_size;
4202 uint32_t pdu_timestamp;
4203 uint32_t sdu_timestamp;
4204 uint16_t testdata_indx;
4205 uint16_t testdata_size;
4206 uint32_t sdu_interval;
4207 isoal_sdu_cnt_t seqn;
4208 isoal_status_t err;
4209 uint32_t latency;
4210 uint8_t role;
4211 uint8_t BN;
4212 uint8_t FT;
4213
4214 /* Settings */
4215 role = BT_CONN_ROLE_PERIPHERAL;
4216 iso_interval_int = 1;
4217 sdu_interval = ISO_INT_UNIT_US;
4218 BN = 3;
4219 FT = 1;
4220 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4221 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4222
4223 /* PDU 1 -------------------------------------------------------------*/
4224 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4225 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
4226 sdu_buffer.dbuf = &rx_sdu_frag_buf;
4227 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
4228 payload_number = 1000 * BN;
4229 pdu_timestamp = 9249;
4230 latency = calc_rx_latency_by_role(role,
4231 false,
4232 FT,
4233 sdu_interval,
4234 iso_interval_int,
4235 stream_sync_delay,
4236 group_sync_delay);
4237 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
4238 seqn = 0;
4239 testdata_indx = 0;
4240 testdata_size = 0;
4241 sdu_size = 0;
4242
4243 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
4244 role, /* Role */
4245 false, /* Framed */
4246 BN, /* BN */
4247 FT, /* FT */
4248 sdu_interval, /* SDU Interval */
4249 iso_interval_int, /* ISO Interval */
4250 stream_sync_delay, /* Stream Sync Delay */
4251 group_sync_delay); /* Group Sync Delay */
4252
4253 /* PDU padding 1 */
4254 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4255 NULL,
4256 0,
4257 payload_number,
4258 pdu_timestamp,
4259 ISOAL_PDU_STATUS_VALID,
4260 &rx_pdu_meta_buf.pdu_meta);
4261
4262 /* Set callback function return values */
4263 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
4264 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
4265 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
4266
4267 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4268
4269 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4270
4271 /* Test recombine (Black Box) */
4272 /* Should not allocate a new SDU */
4273 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
4274
4275 /* SDU should not be written to */
4276 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
4277
4278 /* SDU should not be emitted */
4279 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
4280
4281 /* Test recombine (White Box) */
4282 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4283 ISOAL_CONTINUE,
4284 "FSM state %s should be %s!",
4285 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4286 FSM_TO_STR(ISOAL_CONTINUE));
4287
4288 /* PDU 2 -------------------------------------------------------------*/
4289 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4290 payload_number++;
4291 testdata_indx = testdata_size;
4292
4293 /* PDU padding 2 */
4294 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4295 NULL,
4296 0,
4297 payload_number,
4298 pdu_timestamp,
4299 ISOAL_PDU_STATUS_VALID,
4300 &rx_pdu_meta_buf.pdu_meta);
4301
4302 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4303
4304 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4305
4306 /* Test recombine (Black Box) */
4307 /* Should not allocate a new SDU */
4308 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
4309
4310 /* SDU should not be written to */
4311 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
4312
4313 /* SDU should not be emitted */
4314 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
4315
4316 /* Test recombine (White Box) */
4317 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4318 ISOAL_CONTINUE,
4319 "FSM state %s should be %s!",
4320 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4321 FSM_TO_STR(ISOAL_CONTINUE));
4322
4323 /* PDU 3 -------------------------------------------------------------*/
4324 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4325 payload_number++;
4326 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
4327 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA,
4328 ISOAL_SDU_STATUS_LOST_DATA);
4329
4330 /* PDU padding 3 */
4331 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4332 NULL,
4333 0,
4334 payload_number,
4335 pdu_timestamp,
4336 ISOAL_PDU_STATUS_VALID,
4337 &rx_pdu_meta_buf.pdu_meta);
4338
4339 /* Set callback function return values */
4340 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
4341
4342 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4343
4344 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4345
4346 /* Test recombine (Black Box) */
4347 /* A new SDU should be allocated */
4348 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
4349 &isoal_global.sink_state[sink_hdl], /* Sink */
4350 &rx_pdu_meta_buf.pdu_meta); /* PDU */
4351
4352 /* SDU should not be written to */
4353 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
4354
4355 /* SDU should be emitted */
4356 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
4357 &isoal_global.sink_state[sink_hdl], /* Sink */
4358 BT_ISO_SINGLE, /* Frag state */
4359 sdu_size, /* Frag size */
4360 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
4361 sdu_timestamp, /* Timestamp */
4362 seqn, /* Seq. number */
4363 sdu_buffer.dbuf, /* Buffer */
4364 sdu_buffer.size, /* Buffer size */
4365 total_sdu_size, /* Total size */
4366 collated_status); /* SDU status */
4367
4368 /* Test recombine (White Box) */
4369 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4370 ISOAL_START,
4371 "FSM state %s should be %s!",
4372 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4373 FSM_TO_STR(ISOAL_START));
4374 }
4375
4376 /**
4377 * Test Suite : RX unframed PDU reassembly
4378 *
4379 * Tests reassembly of SDUs with padding where the end was not seen where
4380 * padding is leads the data (not an expected case).
4381 */
ZTEST(test_rx_unframed,test_rx_unframed_padding_leading)4382 ZTEST(test_rx_unframed, test_rx_unframed_padding_leading)
4383 {
4384 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
4385 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
4386 struct isoal_sdu_buffer sdu_buffer;
4387 isoal_sdu_status_t collated_status;
4388 isoal_sink_handle_t sink_hdl;
4389 uint32_t stream_sync_delay;
4390 uint32_t group_sync_delay;
4391 isoal_sdu_len_t sdu_size;
4392 uint8_t iso_interval_int;
4393 uint64_t payload_number;
4394 uint16_t total_sdu_size;
4395 uint32_t pdu_timestamp;
4396 uint32_t sdu_timestamp;
4397 uint16_t testdata_indx;
4398 uint16_t testdata_size;
4399 uint32_t sdu_interval;
4400 isoal_sdu_cnt_t seqn;
4401 uint8_t testdata[33];
4402 isoal_status_t err;
4403 uint32_t latency;
4404 uint8_t role;
4405 uint8_t BN;
4406 uint8_t FT;
4407
4408 /* Settings */
4409 role = BT_CONN_ROLE_PERIPHERAL;
4410 iso_interval_int = 1;
4411 sdu_interval = ISO_INT_UNIT_US;
4412 BN = 3;
4413 FT = 1;
4414 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4415 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4416
4417 /* PDU 1 -------------------------------------------------------------*/
4418 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4419 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
4420 init_test_data_buffer(testdata, 33);
4421 sdu_buffer.dbuf = &rx_sdu_frag_buf;
4422 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
4423 payload_number = 1000 * BN;
4424 pdu_timestamp = 9249;
4425 latency = calc_rx_latency_by_role(role,
4426 false,
4427 FT,
4428 sdu_interval,
4429 iso_interval_int,
4430 stream_sync_delay,
4431 group_sync_delay);
4432 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
4433 seqn = 0;
4434 testdata_indx = 0;
4435 testdata_size = 0;
4436 sdu_size = 0;
4437
4438 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
4439 role, /* Role */
4440 false, /* Framed */
4441 BN, /* BN */
4442 FT, /* FT */
4443 sdu_interval, /* SDU Interval */
4444 iso_interval_int, /* ISO Interval */
4445 stream_sync_delay, /* Stream Sync Delay */
4446 group_sync_delay); /* Group Sync Delay */
4447
4448 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4449 &testdata[testdata_indx],
4450 (testdata_size - testdata_indx),
4451 payload_number,
4452 pdu_timestamp,
4453 ISOAL_PDU_STATUS_VALID,
4454 &rx_pdu_meta_buf.pdu_meta);
4455
4456 /* Set callback function return values */
4457 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
4458 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
4459 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
4460
4461 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4462
4463 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4464
4465 /* Test recombine (Black Box) */
4466 /* Should not allocate a new SDU */
4467 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
4468
4469 /* SDU should not be written to */
4470 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
4471
4472 /* SDU should not be emitted */
4473 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
4474
4475 /* Test recombine (White Box) */
4476 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4477 ISOAL_CONTINUE,
4478 "FSM state %s should be %s!",
4479 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4480 FSM_TO_STR(ISOAL_CONTINUE));
4481
4482 /* PDU 2 -------------------------------------------------------------*/
4483 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4484 payload_number++;
4485 testdata_indx = testdata_size;
4486
4487 /* PDU padding 1 */
4488 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4489 &testdata[testdata_indx],
4490 (testdata_size - testdata_indx),
4491 payload_number,
4492 pdu_timestamp,
4493 ISOAL_PDU_STATUS_VALID,
4494 &rx_pdu_meta_buf.pdu_meta);
4495
4496 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4497
4498 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4499
4500 /* Test recombine (Black Box) */
4501 /* Should not allocate a new SDU */
4502 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
4503
4504 /* SDU should not be written to */
4505 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
4506
4507 /* SDU should not be emitted */
4508 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
4509
4510 /* Test recombine (White Box) */
4511 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4512 ISOAL_CONTINUE,
4513 "FSM state %s should be %s!",
4514 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4515 FSM_TO_STR(ISOAL_CONTINUE));
4516
4517 /* PDU 3 -------------------------------------------------------------*/
4518 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4519 payload_number++;
4520 testdata_size = 13;
4521 sdu_size = 13;
4522 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
4523 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
4524
4525 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4526 &testdata[testdata_indx],
4527 (testdata_size - testdata_indx),
4528 payload_number,
4529 pdu_timestamp,
4530 ISOAL_PDU_STATUS_VALID,
4531 &rx_pdu_meta_buf.pdu_meta);
4532
4533 /* Set callback function return values */
4534 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
4535
4536 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4537
4538 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4539
4540 /* Test recombine (Black Box) */
4541
4542 /* A new SDU should be allocated */
4543 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
4544 &isoal_global.sink_state[sink_hdl], /* Sink */
4545 &rx_pdu_meta_buf.pdu_meta); /* PDU */
4546
4547 /* SDU payload should be written */
4548 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
4549 &rx_sdu_frag_buf, /* SDU buffer */
4550 0, /* SDU written */
4551 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
4552 (testdata_size - testdata_indx)); /* Size */
4553
4554 /* SDU should be emitted */
4555 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
4556 &isoal_global.sink_state[sink_hdl], /* Sink */
4557 BT_ISO_SINGLE, /* Frag state */
4558 sdu_size, /* Frag size */
4559 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
4560 sdu_timestamp, /* Timestamp */
4561 seqn, /* Seq. number */
4562 sdu_buffer.dbuf, /* Buffer */
4563 sdu_buffer.size, /* Buffer size */
4564 total_sdu_size, /* Total size */
4565 collated_status); /* SDU status */
4566
4567 /* Test recombine (White Box) */
4568 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4569 ISOAL_START,
4570 "FSM state %s should be %s!",
4571 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4572 FSM_TO_STR(ISOAL_START));
4573 }
4574
4575 /**
4576 * Test Suite : RX unframed PDU reassembly
4577 *
4578 * Tests reassembly of a SDU where there is an error in the first PDU followed
4579 * by valid padding PDUs
4580 */
ZTEST(test_rx_unframed,test_rx_unframed_padding_error1)4581 ZTEST(test_rx_unframed, test_rx_unframed_padding_error1)
4582 {
4583 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
4584 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
4585 struct isoal_sdu_buffer sdu_buffer;
4586 isoal_sdu_status_t collated_status;
4587 isoal_sink_handle_t sink_hdl;
4588 uint32_t stream_sync_delay;
4589 uint32_t group_sync_delay;
4590 isoal_sdu_len_t sdu_size;
4591 uint8_t iso_interval_int;
4592 uint64_t payload_number;
4593 uint16_t total_sdu_size;
4594 uint32_t pdu_timestamp;
4595 uint32_t sdu_timestamp;
4596 uint16_t testdata_indx;
4597 uint16_t testdata_size;
4598 uint32_t sdu_interval;
4599 isoal_sdu_cnt_t seqn;
4600 uint8_t testdata[13];
4601 isoal_status_t err;
4602 uint32_t latency;
4603 uint8_t role;
4604 uint8_t BN;
4605 uint8_t FT;
4606
4607 /* Settings */
4608 role = ISOAL_ROLE_PERIPHERAL;
4609 iso_interval_int = 1;
4610 sdu_interval = ISO_INT_UNIT_US;
4611 BN = 3;
4612 FT = 1;
4613 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4614 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4615
4616 /* PDU 1 -------------------------------------------------------------*/
4617 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4618 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
4619 init_test_data_buffer(testdata, 13);
4620 sdu_buffer.dbuf = &rx_sdu_frag_buf;
4621 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
4622 payload_number = 1000 * BN;
4623 pdu_timestamp = 9249;
4624 latency = calc_rx_latency_by_role(role,
4625 false,
4626 FT,
4627 sdu_interval,
4628 iso_interval_int,
4629 stream_sync_delay,
4630 group_sync_delay);
4631 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
4632 seqn = 0;
4633 testdata_indx = 0;
4634 testdata_size = 13;
4635 sdu_size = 0;
4636 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
4637 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
4638
4639 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
4640 role, /* Role */
4641 false, /* Framed */
4642 BN, /* BN */
4643 FT, /* FT */
4644 sdu_interval, /* SDU Interval */
4645 iso_interval_int, /* ISO Interval */
4646 stream_sync_delay, /* Stream Sync Delay */
4647 group_sync_delay); /* Group Sync Delay */
4648
4649 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4650 &testdata[testdata_indx],
4651 (testdata_size - testdata_indx),
4652 payload_number,
4653 pdu_timestamp,
4654 ISOAL_PDU_STATUS_ERRORS,
4655 &rx_pdu_meta_buf.pdu_meta);
4656
4657 /* Set callback function return values */
4658 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
4659 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
4660 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
4661 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
4662
4663 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4664
4665 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4666
4667 /* Test recombine (Black Box) */
4668 /* A new SDU should be allocated */
4669 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
4670 &isoal_global.sink_state[sink_hdl], /* Sink */
4671 &rx_pdu_meta_buf.pdu_meta); /* PDU */
4672
4673 /* SDU payload should not be written */
4674 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
4675
4676 /* SDU should be emitted */
4677 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
4678 &isoal_global.sink_state[sink_hdl], /* Sink */
4679 BT_ISO_SINGLE, /* Frag state */
4680 sdu_size, /* Frag size */
4681 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
4682 sdu_timestamp, /* Timestamp */
4683 seqn, /* Seq. number */
4684 sdu_buffer.dbuf, /* Buffer */
4685 sdu_buffer.size, /* Buffer size */
4686 total_sdu_size, /* Total size */
4687 collated_status); /* SDU status */
4688
4689 /* Test recombine (White Box) */
4690 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4691 ISOAL_ERR_SPOOL,
4692 "FSM state %s should be %s!",
4693 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4694 FSM_TO_STR(ISOAL_ERR_SPOOL));
4695
4696 /* PDU 2 -------------------------------------------------------------*/
4697 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4698 payload_number++;
4699 testdata_indx = testdata_size;
4700
4701 /* PDU padding 1 */
4702 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4703 &testdata[testdata_indx],
4704 (testdata_size - testdata_indx),
4705 payload_number,
4706 pdu_timestamp,
4707 ISOAL_PDU_STATUS_VALID,
4708 &rx_pdu_meta_buf.pdu_meta);
4709
4710 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4711
4712 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4713
4714 /* Test recombine (Black Box) */
4715 /* Should not allocate a new SDU */
4716
4717 /* SDU should not be written to */
4718
4719 /* SDU should not be emitted */
4720
4721 /* Test recombine (White Box) */
4722 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4723 ISOAL_ERR_SPOOL,
4724 "FSM state %s should be %s!",
4725 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4726 FSM_TO_STR(ISOAL_ERR_SPOOL));
4727
4728 /* PDU 3 -------------------------------------------------------------*/
4729 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4730 payload_number++;
4731
4732 /* PDU padding 2 */
4733 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4734 &testdata[testdata_indx],
4735 (testdata_size - testdata_indx),
4736 payload_number,
4737 pdu_timestamp,
4738 ISOAL_PDU_STATUS_VALID,
4739 &rx_pdu_meta_buf.pdu_meta);
4740
4741 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4742
4743 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4744
4745 /* Test recombine (Black Box) */
4746 /* Should not allocate a new SDU */
4747
4748 /* SDU should not be written to */
4749
4750 /* SDU should not be emitted */
4751
4752 /* Test recombine (White Box) */
4753 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4754 ISOAL_START,
4755 "FSM state %s should be %s!",
4756 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4757 FSM_TO_STR(ISOAL_START));
4758 }
4759
4760 /**
4761 * Test Suite : RX unframed PDU reassembly
4762 *
4763 * Tests reassembly of a SDU where the second PDU is corrupted and appears to
4764 * be a padding PDU
4765 */
ZTEST(test_rx_unframed,test_rx_unframed_padding_error2)4766 ZTEST(test_rx_unframed, test_rx_unframed_padding_error2)
4767 {
4768 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
4769 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
4770 struct isoal_sdu_buffer sdu_buffer;
4771 isoal_sdu_status_t collated_status;
4772 isoal_sink_handle_t sink_hdl;
4773 uint32_t stream_sync_delay;
4774 uint32_t group_sync_delay;
4775 isoal_sdu_len_t sdu_size;
4776 uint8_t iso_interval_int;
4777 uint64_t payload_number;
4778 uint16_t total_sdu_size;
4779 uint32_t pdu_timestamp;
4780 uint32_t sdu_timestamp;
4781 uint16_t testdata_indx;
4782 uint16_t testdata_size;
4783 uint32_t sdu_interval;
4784 isoal_sdu_cnt_t seqn;
4785 uint8_t testdata[13];
4786 isoal_status_t err;
4787 uint32_t latency;
4788 uint8_t role;
4789 uint8_t BN;
4790 uint8_t FT;
4791
4792 /* Settings */
4793 role = ISOAL_ROLE_PERIPHERAL;
4794 iso_interval_int = 1;
4795 sdu_interval = ISO_INT_UNIT_US;
4796 BN = 3;
4797 FT = 1;
4798 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4799 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4800
4801 /* PDU 1 -------------------------------------------------------------*/
4802 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4803 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
4804 init_test_data_buffer(testdata, 13);
4805 sdu_buffer.dbuf = &rx_sdu_frag_buf;
4806 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
4807 payload_number = 1000 * BN;
4808 pdu_timestamp = 9249;
4809 latency = calc_rx_latency_by_role(role,
4810 false,
4811 FT,
4812 sdu_interval,
4813 iso_interval_int,
4814 stream_sync_delay,
4815 group_sync_delay);
4816 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
4817 seqn = 0;
4818 testdata_indx = 0;
4819 testdata_size = 13;
4820 sdu_size = 13;
4821
4822 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
4823 role, /* Role */
4824 false, /* Framed */
4825 BN, /* BN */
4826 FT, /* FT */
4827 sdu_interval, /* SDU Interval */
4828 iso_interval_int, /* ISO Interval */
4829 stream_sync_delay, /* Stream Sync Delay */
4830 group_sync_delay); /* Group Sync Delay */
4831
4832 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4833 &testdata[testdata_indx],
4834 (testdata_size - testdata_indx),
4835 payload_number,
4836 pdu_timestamp,
4837 ISOAL_PDU_STATUS_VALID,
4838 &rx_pdu_meta_buf.pdu_meta);
4839
4840 /* Set callback function return values */
4841 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
4842 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
4843 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
4844
4845 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4846
4847 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4848
4849 /* Test recombine (Black Box) */
4850 /* A new SDU should be allocated */
4851 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
4852 &isoal_global.sink_state[sink_hdl], /* Sink */
4853 &rx_pdu_meta_buf.pdu_meta); /* PDU */
4854
4855 /* SDU payload should be written */
4856 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
4857 &rx_sdu_frag_buf, /* SDU buffer */
4858 0, /* SDU written */
4859 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
4860 (testdata_size - testdata_indx)); /* Size */
4861 /* SDU should not be emitted */
4862
4863 /* Test recombine (White Box) */
4864 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4865 ISOAL_CONTINUE,
4866 "FSM state %s should be %s!",
4867 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4868 FSM_TO_STR(ISOAL_CONTINUE));
4869
4870 /* PDU 2 -------------------------------------------------------------*/
4871 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4872 payload_number++;
4873 testdata_indx = testdata_size;
4874 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
4875 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
4876
4877 /* PDU with errors that appears as padding */
4878 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4879 &testdata[testdata_indx],
4880 (testdata_size - testdata_indx),
4881 payload_number,
4882 pdu_timestamp,
4883 ISOAL_PDU_STATUS_ERRORS,
4884 &rx_pdu_meta_buf.pdu_meta);
4885
4886 /* Set callback function return values */
4887 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
4888
4889 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4890
4891 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4892
4893 /* Test recombine (Black Box) */
4894 /* A new SDU should not be allocated */
4895
4896 /* SDU payload should not be written */
4897
4898 /* SDU should be emitted */
4899 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
4900 &isoal_global.sink_state[sink_hdl], /* Sink */
4901 BT_ISO_SINGLE, /* Frag state */
4902 sdu_size, /* Frag size */
4903 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
4904 sdu_timestamp, /* Timestamp */
4905 seqn, /* Seq. number */
4906 sdu_buffer.dbuf, /* Buffer */
4907 sdu_buffer.size, /* Buffer size */
4908 total_sdu_size, /* Total size */
4909 collated_status); /* SDU status */
4910
4911 /* Test recombine (White Box) */
4912 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4913 ISOAL_ERR_SPOOL,
4914 "FSM state %s should be %s!",
4915 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4916 FSM_TO_STR(ISOAL_ERR_SPOOL));
4917
4918 /* PDU 3 -------------------------------------------------------------*/
4919 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4920 payload_number++;
4921
4922 /* PDU padding 1 */
4923 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
4924 &testdata[testdata_indx],
4925 (testdata_size - testdata_indx),
4926 payload_number,
4927 pdu_timestamp,
4928 ISOAL_PDU_STATUS_VALID,
4929 &rx_pdu_meta_buf.pdu_meta);
4930
4931 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
4932
4933 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
4934
4935 /* Test recombine (Black Box) */
4936 /* Should not allocate a new SDU */
4937
4938 /* SDU should not be written to */
4939
4940 /* SDU should not be emitted */
4941
4942 /* Test recombine (White Box) */
4943 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
4944 ISOAL_START,
4945 "FSM state %s should be %s!",
4946 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
4947 FSM_TO_STR(ISOAL_START));
4948 }
4949
4950 /**
4951 * Test Suite : RX unframed PDU reassembly
4952 *
4953 * Tests reassembly of a SDU where only the padding PDU has errors
4954 */
ZTEST(test_rx_unframed,test_rx_unframed_padding_error3)4955 ZTEST(test_rx_unframed, test_rx_unframed_padding_error3)
4956 {
4957 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
4958 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
4959 struct isoal_sdu_buffer sdu_buffer;
4960 isoal_sdu_status_t collated_status;
4961 isoal_sink_handle_t sink_hdl;
4962 uint32_t stream_sync_delay;
4963 uint32_t group_sync_delay;
4964 isoal_sdu_len_t sdu_size;
4965 uint8_t iso_interval_int;
4966 uint64_t payload_number;
4967 uint16_t total_sdu_size;
4968 uint16_t sdu_written = 0;
4969 uint32_t pdu_timestamp;
4970 uint32_t sdu_timestamp;
4971 uint16_t testdata_indx;
4972 uint16_t testdata_size;
4973 uint32_t sdu_interval;
4974 isoal_sdu_cnt_t seqn;
4975 uint8_t testdata[23];
4976 isoal_status_t err;
4977 uint32_t latency;
4978 uint8_t role;
4979 uint8_t BN;
4980 uint8_t FT;
4981
4982 /* Settings */
4983 role = ISOAL_ROLE_PERIPHERAL;
4984 iso_interval_int = 1;
4985 sdu_interval = ISO_INT_UNIT_US;
4986 BN = 3;
4987 FT = 1;
4988 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
4989 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
4990
4991 /* PDU 1 -------------------------------------------------------------*/
4992 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
4993 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
4994 init_test_data_buffer(testdata, 23);
4995 sdu_buffer.dbuf = &rx_sdu_frag_buf;
4996 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
4997 payload_number = 1000 * BN;
4998 pdu_timestamp = 9249;
4999 latency = calc_rx_latency_by_role(role,
5000 false,
5001 FT,
5002 sdu_interval,
5003 iso_interval_int,
5004 stream_sync_delay,
5005 group_sync_delay);
5006 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
5007 seqn = 0;
5008 testdata_indx = 0;
5009 testdata_size = 13;
5010 sdu_size = 13;
5011
5012 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
5013 role, /* Role */
5014 false, /* Framed */
5015 BN, /* BN */
5016 FT, /* FT */
5017 sdu_interval, /* SDU Interval */
5018 iso_interval_int, /* ISO Interval */
5019 stream_sync_delay, /* Stream Sync Delay */
5020 group_sync_delay); /* Group Sync Delay */
5021
5022 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
5023 &testdata[testdata_indx],
5024 (testdata_size - testdata_indx),
5025 payload_number,
5026 pdu_timestamp,
5027 ISOAL_PDU_STATUS_VALID,
5028 &rx_pdu_meta_buf.pdu_meta);
5029
5030 /* Set callback function return values */
5031 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
5032 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
5033 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
5034
5035 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5036
5037 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5038
5039 /* Test recombine (Black Box) */
5040 /* A new SDU should be allocated */
5041 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
5042 &isoal_global.sink_state[sink_hdl], /* Sink */
5043 &rx_pdu_meta_buf.pdu_meta); /* PDU */
5044
5045 /* SDU payload should be written */
5046 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
5047 &rx_sdu_frag_buf, /* SDU buffer */
5048 sdu_written, /* SDU written */
5049 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
5050 (testdata_size - testdata_indx)); /* Size */
5051 /* SDU should not be emitted */
5052
5053 /* Test recombine (White Box) */
5054 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5055 ISOAL_CONTINUE,
5056 "FSM state %s should be %s!",
5057 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5058 FSM_TO_STR(ISOAL_CONTINUE));
5059
5060 /* PDU 2 -------------------------------------------------------------*/
5061 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5062 sdu_written += (testdata_size - testdata_indx);
5063 payload_number++;
5064 testdata_indx = testdata_size;
5065 testdata_size += 10;
5066 sdu_size += 10;
5067 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
5068 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
5069
5070 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
5071 &testdata[testdata_indx],
5072 (testdata_size - testdata_indx),
5073 payload_number,
5074 pdu_timestamp,
5075 ISOAL_PDU_STATUS_VALID,
5076 &rx_pdu_meta_buf.pdu_meta);
5077
5078 /* Set callback function return values */
5079 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
5080 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
5081
5082 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5083
5084 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5085
5086 /* Test recombine (Black Box) */
5087 /* A new SDU should not be allocated */
5088
5089 /* SDU payload should be written */
5090 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
5091 &rx_sdu_frag_buf, /* SDU buffer */
5092 sdu_written, /* SDU written */
5093 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
5094 (testdata_size - testdata_indx)); /* Size */
5095 /* SDU should be emitted */
5096 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
5097 &isoal_global.sink_state[sink_hdl], /* Sink */
5098 BT_ISO_SINGLE, /* Frag state */
5099 sdu_size, /* Frag size */
5100 ISOAL_SDU_STATUS_VALID, /* Frag status */
5101 sdu_timestamp, /* Timestamp */
5102 seqn, /* Seq. number */
5103 sdu_buffer.dbuf, /* Buffer */
5104 sdu_buffer.size, /* Buffer size */
5105 total_sdu_size, /* Total size */
5106 collated_status); /* SDU status */
5107
5108 /* Test recombine (White Box) */
5109 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5110 ISOAL_ERR_SPOOL,
5111 "FSM state %s should be %s!",
5112 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5113 FSM_TO_STR(ISOAL_ERR_SPOOL));
5114
5115 /* PDU 3 -------------------------------------------------------------*/
5116 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5117 payload_number++;
5118 testdata_indx = testdata_size;
5119
5120 /* PDU padding with errors */
5121 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
5122 &testdata[testdata_indx],
5123 (testdata_size - testdata_indx),
5124 payload_number,
5125 pdu_timestamp,
5126 ISOAL_PDU_STATUS_ERRORS,
5127 &rx_pdu_meta_buf.pdu_meta);
5128
5129 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5130
5131 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5132
5133 /* Test recombine (Black Box) */
5134 /* Should not allocate a new SDU */
5135
5136 /* SDU should not be written to */
5137
5138 /* SDU should not be emitted */
5139
5140 /* Test recombine (White Box) */
5141 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5142 ISOAL_START,
5143 "FSM state %s should be %s!",
5144 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5145 FSM_TO_STR(ISOAL_START));
5146 }
5147
5148 /**
5149 * Test Suite : RX unframed PDU reassembly
5150 *
5151 * Tests reassembly of a zero length SDU
5152 */
ZTEST(test_rx_unframed,test_rx_unframed_zero_len_packet)5153 ZTEST(test_rx_unframed, test_rx_unframed_zero_len_packet)
5154 {
5155 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
5156 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
5157 struct isoal_sdu_buffer sdu_buffer;
5158 isoal_sdu_status_t collated_status;
5159 isoal_sink_handle_t sink_hdl;
5160 uint32_t stream_sync_delay;
5161 uint32_t group_sync_delay;
5162 isoal_sdu_len_t sdu_size;
5163 uint8_t iso_interval_int;
5164 uint64_t payload_number;
5165 uint16_t total_sdu_size;
5166 uint32_t pdu_timestamp;
5167 uint32_t sdu_timestamp;
5168 uint16_t testdata_indx;
5169 uint16_t testdata_size;
5170 uint32_t sdu_interval;
5171 isoal_sdu_cnt_t seqn;
5172 uint8_t testdata[13];
5173 isoal_status_t err;
5174 uint32_t latency;
5175 uint8_t role;
5176 uint8_t BN;
5177 uint8_t FT;
5178
5179 /* Settings */
5180 role = ISOAL_ROLE_PERIPHERAL;
5181 iso_interval_int = 1;
5182 sdu_interval = ISO_INT_UNIT_US;
5183 BN = 1;
5184 FT = 1;
5185 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
5186 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
5187
5188 /* PDU 1 -------------------------------------------------------------*/
5189 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5190 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
5191 init_test_data_buffer(testdata, 13);
5192 sdu_buffer.dbuf = &rx_sdu_frag_buf;
5193 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
5194 payload_number = 1000 * BN;
5195 pdu_timestamp = 9249;
5196 latency = calc_rx_latency_by_role(role,
5197 false,
5198 FT,
5199 sdu_interval,
5200 iso_interval_int,
5201 stream_sync_delay,
5202 group_sync_delay);
5203 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
5204 seqn = 0;
5205 testdata_indx = 0;
5206 testdata_size = 0;
5207 sdu_size = 0;
5208 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
5209 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
5210
5211 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
5212 role, /* Role */
5213 false, /* Framed */
5214 BN, /* BN */
5215 FT, /* FT */
5216 sdu_interval, /* SDU Interval */
5217 iso_interval_int, /* ISO Interval */
5218 stream_sync_delay, /* Stream Sync Delay */
5219 group_sync_delay); /* Group Sync Delay */
5220
5221 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
5222 &testdata[testdata_indx],
5223 (testdata_size - testdata_indx),
5224 payload_number,
5225 pdu_timestamp,
5226 ISOAL_PDU_STATUS_VALID,
5227 &rx_pdu_meta_buf.pdu_meta);
5228
5229 /* Set callback function return values */
5230 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
5231 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
5232 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
5233
5234 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5235
5236 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5237
5238 /* Test recombine (Black Box) */
5239 /* A new SDU should be allocated */
5240 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
5241 &isoal_global.sink_state[sink_hdl], /* Sink */
5242 &rx_pdu_meta_buf.pdu_meta); /* PDU */
5243
5244 /* SDU payload should not be written */
5245
5246 /* SDU should be emitted */
5247 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
5248 &isoal_global.sink_state[sink_hdl], /* Sink */
5249 BT_ISO_SINGLE, /* Frag state */
5250 sdu_size, /* Frag size */
5251 ISOAL_SDU_STATUS_VALID, /* Frag status */
5252 sdu_timestamp, /* Timestamp */
5253 seqn, /* Seq. number */
5254 sdu_buffer.dbuf, /* Buffer */
5255 sdu_buffer.size, /* Buffer size */
5256 total_sdu_size, /* Total size */
5257 collated_status); /* SDU status */
5258
5259 /* Test recombine (White Box) */
5260 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5261 ISOAL_START,
5262 "FSM state %s should be %s!",
5263 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5264 FSM_TO_STR(ISOAL_START));
5265 }
5266
5267 /**
5268 * Test Suite : RX unframed PDU reassembly
5269 *
5270 * Tests reassembly of SDUs where PDUs are not in sequence followed by a zero
5271 * length SDU
5272 */
ZTEST(test_rx_unframed,test_rx_unframed_seq_err_zero_length)5273 ZTEST(test_rx_unframed, test_rx_unframed_seq_err_zero_length)
5274 {
5275 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
5276 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
5277 struct isoal_sdu_buffer sdu_buffer;
5278 isoal_sdu_status_t collated_status;
5279 isoal_sink_handle_t sink_hdl;
5280 uint32_t stream_sync_delay;
5281 uint32_t group_sync_delay;
5282 isoal_sdu_len_t sdu_size;
5283 uint8_t iso_interval_int;
5284 uint64_t payload_number;
5285 uint16_t total_sdu_size;
5286 uint16_t sdu_written = 0;
5287 uint32_t pdu_timestamp;
5288 uint32_t sdu_timestamp;
5289 uint16_t testdata_indx;
5290 uint16_t testdata_size;
5291 uint32_t sdu_interval;
5292 isoal_sdu_cnt_t seqn;
5293 uint8_t testdata[43];
5294 isoal_status_t err;
5295 uint32_t latency;
5296 uint8_t role;
5297 uint8_t BN;
5298 uint8_t FT;
5299
5300 /* Settings */
5301 role = ISOAL_ROLE_PERIPHERAL;
5302 iso_interval_int = 1;
5303 sdu_interval = ISO_INT_UNIT_US;
5304 BN = 3;
5305 FT = 1;
5306 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
5307 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
5308
5309 /* PDU 1 -------------------------------------------------------------*/
5310 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5311 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
5312 init_test_data_buffer(testdata, 43);
5313 sdu_buffer.dbuf = &rx_sdu_frag_buf;
5314 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
5315 payload_number = 2000;
5316 pdu_timestamp = 9249;
5317 latency = calc_rx_latency_by_role(role,
5318 false,
5319 FT,
5320 sdu_interval,
5321 iso_interval_int,
5322 stream_sync_delay,
5323 group_sync_delay);
5324 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
5325 seqn = 0;
5326 testdata_indx = 0;
5327 testdata_size = 13;
5328 sdu_size = 13;
5329
5330 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
5331 role, /* Role */
5332 false, /* Framed */
5333 BN, /* BN */
5334 FT, /* FT */
5335 sdu_interval, /* SDU Interval */
5336 iso_interval_int, /* ISO Interval */
5337 stream_sync_delay, /* Stream Sync Delay */
5338 group_sync_delay); /* Group Sync Delay */
5339
5340 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
5341 &testdata[testdata_indx],
5342 (testdata_size - testdata_indx),
5343 payload_number,
5344 pdu_timestamp,
5345 ISOAL_PDU_STATUS_VALID,
5346 &rx_pdu_meta_buf.pdu_meta);
5347
5348 /* Set callback function return values */
5349 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
5350 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
5351 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
5352
5353 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5354
5355 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5356
5357 /* Test recombine (Black Box) */
5358 /* A new SDU should be allocated */
5359 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
5360 &isoal_global.sink_state[sink_hdl], /* Sink */
5361 &rx_pdu_meta_buf.pdu_meta); /* PDU */
5362
5363 /* SDU payload should be written */
5364 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
5365 &rx_sdu_frag_buf, /* SDU buffer */
5366 sdu_written, /* SDU written */
5367 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
5368 (testdata_size - testdata_indx)); /* Size */
5369 /* SDU should not be emitted */
5370
5371 /* Test recombine (White Box) */
5372 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5373 ISOAL_CONTINUE,
5374 "FSM state %s should be %s!",
5375 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5376 FSM_TO_STR(ISOAL_CONTINUE));
5377
5378 /* PDU 2 Not transferred to ISO-AL ------------------------------------*/
5379 sdu_written += (testdata_size - testdata_indx);
5380 payload_number++;
5381 testdata_indx = testdata_size;
5382 testdata_size += 10;
5383
5384 /* PDU 3 -------------------------------------------------------------*/
5385 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5386 payload_number++;
5387 testdata_indx = testdata_size;
5388 testdata_size += 10;
5389 sdu_size += 10;
5390 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
5391 collated_status =
5392 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
5393
5394 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
5395 &testdata[testdata_indx],
5396 (testdata_size - testdata_indx),
5397 payload_number,
5398 pdu_timestamp,
5399 ISOAL_PDU_STATUS_VALID,
5400 &rx_pdu_meta_buf.pdu_meta);
5401
5402 /* Set callback function return values */
5403 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
5404 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
5405
5406 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5407
5408 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5409
5410 /* Test recombine (Black Box) */
5411 /* A new SDU should not be allocated */
5412
5413 /* SDU payload should be written */
5414 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
5415 &rx_sdu_frag_buf, /* SDU buffer */
5416 sdu_written, /* SDU written */
5417 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
5418 (testdata_size - testdata_indx)); /* Size */
5419 /* SDU should be emitted */
5420 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
5421 &isoal_global.sink_state[sink_hdl], /* Sink */
5422 BT_ISO_SINGLE, /* Frag state */
5423 sdu_size, /* Frag size */
5424 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
5425 sdu_timestamp, /* Timestamp */
5426 seqn, /* Seq. number */
5427 sdu_buffer.dbuf, /* Buffer */
5428 sdu_buffer.size, /* Buffer size */
5429 total_sdu_size, /* Total size */
5430 collated_status); /* SDU status */
5431
5432 /* Test recombine (White Box) */
5433 /* PDU count will not have reached 3 as one PDU was not received, so
5434 * last_pdu will not be set and the state should remain in Error
5435 * Spooling.
5436 */
5437 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5438 ISOAL_ERR_SPOOL,
5439 "FSM state %s should be %s!",
5440 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5441 FSM_TO_STR(ISOAL_ERR_SPOOL));
5442
5443 /* PDU 4 -------------------------------------------------------------*/
5444 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5445 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
5446 payload_number++;
5447 seqn++;
5448 pdu_timestamp = 9249 + ISO_INT_UNIT_US;
5449 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
5450 testdata_indx = testdata_size;
5451 sdu_size = 0;
5452 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
5453 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
5454
5455 isoal_test_create_unframed_pdu(PDU_BIS_LLID_COMPLETE_END,
5456 &testdata[testdata_indx],
5457 (testdata_size - testdata_indx),
5458 payload_number,
5459 pdu_timestamp,
5460 ISOAL_PDU_STATUS_VALID,
5461 &rx_pdu_meta_buf.pdu_meta);
5462
5463 /* Set callback function return values */
5464 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
5465 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
5466 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
5467
5468 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5469
5470 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5471
5472 /* Test recombine (Black Box) */
5473 /* A new SDU should be allocated */
5474 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
5475 &isoal_global.sink_state[sink_hdl], /* Sink */
5476 &rx_pdu_meta_buf.pdu_meta); /* PDU */
5477
5478 /* SDU payload should not be written */
5479
5480 /* SDU should be emitted */
5481 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
5482 &isoal_global.sink_state[sink_hdl], /* Sink */
5483 BT_ISO_SINGLE, /* Frag state */
5484 sdu_size, /* Frag size */
5485 ISOAL_SDU_STATUS_VALID, /* Frag status */
5486 sdu_timestamp, /* Timestamp */
5487 seqn, /* Seq. number */
5488 sdu_buffer.dbuf, /* Buffer */
5489 sdu_buffer.size, /* Buffer size */
5490 total_sdu_size, /* Total size */
5491 collated_status); /* SDU status */
5492
5493 /* Test recombine (White Box) */
5494 /* Detecting the transition from an end fragment to a start fragment
5495 * should have triggered the monitoring code to pull the state machine
5496 * out of Eroor spooling and directly into the start of a new SDU. As
5497 * this was not a zero length SDU, the next state should be Error
5498 * Spooling to dispense with padding PDUs.
5499 */
5500 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5501 ISOAL_ERR_SPOOL,
5502 "FSM state %s should be %s!",
5503 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5504 FSM_TO_STR(ISOAL_ERR_SPOOL));
5505 }
5506
5507 /**
5508 * Test Suite : RX unframed PDU reassembly
5509 *
5510 * Tests reassembly of a SDU in two PDUs where the end was not seen and BN is
5511 * two which should return to FSM start after reassembly
5512 */
ZTEST(test_rx_unframed,test_rx_unframed_dbl_pdu_no_end)5513 ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_no_end)
5514 {
5515 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
5516 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
5517 struct isoal_sdu_buffer sdu_buffer;
5518 isoal_sdu_status_t collated_status;
5519 isoal_sink_handle_t sink_hdl;
5520 uint32_t stream_sync_delay;
5521 uint32_t group_sync_delay;
5522 isoal_sdu_len_t sdu_size;
5523 uint8_t iso_interval_int;
5524 uint64_t payload_number;
5525 uint16_t total_sdu_size;
5526 uint16_t sdu_written = 0;
5527 uint32_t pdu_timestamp;
5528 uint32_t sdu_timestamp;
5529 uint16_t testdata_indx;
5530 uint16_t testdata_size;
5531 uint32_t sdu_interval;
5532 isoal_sdu_cnt_t seqn;
5533 uint8_t testdata[23];
5534 isoal_status_t err;
5535 uint32_t latency;
5536 uint8_t role;
5537 uint8_t BN;
5538 uint8_t FT;
5539
5540 /* Settings */
5541 role = ISOAL_ROLE_PERIPHERAL;
5542 iso_interval_int = 1;
5543 sdu_interval = ISO_INT_UNIT_US;
5544 BN = 2;
5545 FT = 1;
5546 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
5547 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
5548
5549 /* PDU 1 -------------------------------------------------------------*/
5550 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5551 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
5552 init_test_data_buffer(testdata, 23);
5553 sdu_buffer.dbuf = &rx_sdu_frag_buf;
5554 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
5555 payload_number = 1000 * BN;
5556 pdu_timestamp = 9249;
5557 latency = calc_rx_latency_by_role(role,
5558 false,
5559 FT,
5560 sdu_interval,
5561 iso_interval_int,
5562 stream_sync_delay,
5563 group_sync_delay);
5564 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
5565 seqn = 0;
5566 testdata_indx = 0;
5567 testdata_size = 13;
5568 sdu_size = 13;
5569
5570 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
5571 role, /* Role */
5572 false, /* Framed */
5573 BN, /* BN */
5574 FT, /* FT */
5575 sdu_interval, /* SDU Interval */
5576 iso_interval_int, /* ISO Interval */
5577 stream_sync_delay, /* Stream Sync Delay */
5578 group_sync_delay); /* Group Sync Delay */
5579
5580 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
5581 &testdata[testdata_indx],
5582 (testdata_size - testdata_indx),
5583 payload_number,
5584 pdu_timestamp,
5585 ISOAL_PDU_STATUS_VALID,
5586 &rx_pdu_meta_buf.pdu_meta);
5587
5588 /* Set callback function return values */
5589 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
5590 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
5591 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
5592
5593 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5594
5595 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5596
5597 /* Test recombine (Black Box) */
5598 /* A new SDU should be allocated */
5599 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
5600 &isoal_global.sink_state[sink_hdl], /* Sink */
5601 &rx_pdu_meta_buf.pdu_meta); /* PDU */
5602
5603 /* SDU payload should be written */
5604 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
5605 &rx_sdu_frag_buf, /* SDU buffer */
5606 sdu_written, /* SDU written */
5607 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
5608 (testdata_size - testdata_indx)); /* Size */
5609 /* SDU should not be emitted */
5610
5611 /* Test recombine (White Box) */
5612 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5613 ISOAL_CONTINUE,
5614 "FSM state %s should be %s!",
5615 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5616 FSM_TO_STR(ISOAL_CONTINUE));
5617
5618 /* PDU 2 -------------------------------------------------------------*/
5619 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5620 sdu_written += (testdata_size - testdata_indx);
5621 payload_number++;
5622 testdata_indx = testdata_size;
5623 testdata_size += 10;
5624 sdu_size += 10;
5625 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
5626 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
5627
5628 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
5629 &testdata[testdata_indx],
5630 (testdata_size - testdata_indx),
5631 payload_number,
5632 pdu_timestamp,
5633 ISOAL_PDU_STATUS_VALID,
5634 &rx_pdu_meta_buf.pdu_meta);
5635
5636 /* Set callback function return values */
5637 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
5638 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
5639
5640 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5641
5642 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5643
5644 /* Test recombine (Black Box) */
5645 /* A new SDU should not be allocated */
5646
5647 /* SDU payload should be written */
5648 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
5649 &rx_sdu_frag_buf, /* SDU buffer */
5650 sdu_written, /* SDU written */
5651 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
5652 (testdata_size - testdata_indx)); /* Size */
5653 /* SDU should be emitted */
5654 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
5655 &isoal_global.sink_state[sink_hdl], /* Sink */
5656 BT_ISO_SINGLE, /* Frag state */
5657 sdu_size, /* Frag size */
5658 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
5659 sdu_timestamp, /* Timestamp */
5660 seqn, /* Seq. number */
5661 sdu_buffer.dbuf, /* Buffer */
5662 sdu_buffer.size, /* Buffer size */
5663 total_sdu_size, /* Total size */
5664 collated_status); /* SDU status */
5665
5666 /* Test recombine (White Box) */
5667 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5668 ISOAL_START,
5669 "FSM state %s should be %s!",
5670 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5671 FSM_TO_STR(ISOAL_START));
5672 }
5673
5674 /**
5675 * Test Suite : RX unframed PDU reassembly
5676 *
5677 * Tests assertion on receiving a PDU with an invalid LLID without errors as
5678 * the first PDU of the SDU
5679 */
ZTEST(test_rx_unframed,test_rx_unframed_dbl_pdu_invalid_llid1)5680 ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid1)
5681 {
5682 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
5683 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
5684 struct isoal_sdu_buffer sdu_buffer;
5685 isoal_sink_handle_t sink_hdl;
5686 uint32_t stream_sync_delay;
5687 uint32_t group_sync_delay;
5688 isoal_sdu_len_t sdu_size;
5689 uint8_t iso_interval_int;
5690 uint64_t payload_number;
5691 uint32_t pdu_timestamp;
5692 uint32_t sdu_timestamp;
5693 uint16_t testdata_indx;
5694 uint16_t testdata_size;
5695 uint32_t sdu_interval;
5696 isoal_sdu_cnt_t seqn;
5697 uint8_t testdata[13];
5698 isoal_status_t err;
5699 uint32_t latency;
5700 uint8_t role;
5701 uint8_t BN;
5702 uint8_t FT;
5703
5704 /* Settings */
5705 role = ISOAL_ROLE_PERIPHERAL;
5706 iso_interval_int = 1;
5707 sdu_interval = ISO_INT_UNIT_US;
5708 BN = 2;
5709 FT = 1;
5710 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
5711 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
5712
5713 /* PDU 1 -------------------------------------------------------------*/
5714 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5715 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
5716 init_test_data_buffer(testdata, 13);
5717 sdu_buffer.dbuf = &rx_sdu_frag_buf;
5718 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
5719 payload_number = 1000 * BN;
5720 pdu_timestamp = 9249;
5721 latency = calc_rx_latency_by_role(role,
5722 false,
5723 FT,
5724 sdu_interval,
5725 iso_interval_int,
5726 stream_sync_delay,
5727 group_sync_delay);
5728 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
5729 seqn = 0;
5730 testdata_indx = 0;
5731 testdata_size = 13;
5732 sdu_size = 13;
5733
5734 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
5735 role, /* Role */
5736 false, /* Framed */
5737 BN, /* BN */
5738 FT, /* FT */
5739 sdu_interval, /* SDU Interval */
5740 iso_interval_int, /* ISO Interval */
5741 stream_sync_delay, /* Stream Sync Delay */
5742 group_sync_delay); /* Group Sync Delay */
5743
5744 /* Invalid LLID - Valid PDU*/
5745 isoal_test_create_unframed_pdu(PDU_BIS_LLID_FRAMED,
5746 &testdata[testdata_indx],
5747 (testdata_size - testdata_indx),
5748 payload_number,
5749 pdu_timestamp,
5750 ISOAL_PDU_STATUS_VALID,
5751 &rx_pdu_meta_buf.pdu_meta);
5752
5753 /* Test recombine (Black Box) */
5754 /* expecting an assertion */
5755 ztest_set_assert_valid(true);
5756
5757 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5758
5759 ztest_set_assert_valid(false);
5760 }
5761
5762 /**
5763 * Test Suite : RX unframed PDU reassembly
5764 *
5765 * Tests assertion on receiving a PDU with an invalid LLID without errors as
5766 * the second PDU of the SDU
5767 */
ZTEST(test_rx_unframed,test_rx_unframed_dbl_pdu_invalid_llid2)5768 ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2)
5769 {
5770 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
5771 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
5772 struct isoal_sdu_buffer sdu_buffer;
5773 isoal_sdu_status_t collated_status;
5774 isoal_sink_handle_t sink_hdl;
5775 uint32_t stream_sync_delay;
5776 uint32_t group_sync_delay;
5777 isoal_sdu_len_t sdu_size;
5778 uint8_t iso_interval_int;
5779 uint64_t payload_number;
5780 uint16_t total_sdu_size;
5781 uint32_t pdu_timestamp;
5782 uint32_t sdu_timestamp;
5783 uint16_t testdata_indx;
5784 uint16_t testdata_size;
5785 uint32_t sdu_interval;
5786 isoal_sdu_cnt_t seqn;
5787 uint8_t testdata[23];
5788 isoal_status_t err;
5789 uint32_t latency;
5790 uint8_t role;
5791 uint8_t BN;
5792 uint8_t FT;
5793
5794 /* Settings */
5795 role = ISOAL_ROLE_PERIPHERAL;
5796 iso_interval_int = 1;
5797 sdu_interval = ISO_INT_UNIT_US;
5798 BN = 2;
5799 FT = 1;
5800 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
5801 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
5802
5803 /* PDU 1 -------------------------------------------------------------*/
5804 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5805 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
5806 init_test_data_buffer(testdata, 23);
5807 sdu_buffer.dbuf = &rx_sdu_frag_buf;
5808 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
5809 payload_number = 1000 * BN;
5810 pdu_timestamp = 9249;
5811 latency = calc_rx_latency_by_role(role,
5812 false,
5813 FT,
5814 sdu_interval,
5815 iso_interval_int,
5816 stream_sync_delay,
5817 group_sync_delay);
5818 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
5819 seqn = 0;
5820 testdata_indx = 0;
5821 testdata_size = 13;
5822 sdu_size = 13;
5823 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
5824 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
5825
5826 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
5827 role, /* Role */
5828 false, /* Framed */
5829 BN, /* BN */
5830 FT, /* FT */
5831 sdu_interval, /* SDU Interval */
5832 iso_interval_int, /* ISO Interval */
5833 stream_sync_delay, /* Stream Sync Delay */
5834 group_sync_delay); /* Group Sync Delay */
5835
5836 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
5837 &testdata[testdata_indx],
5838 (testdata_size - testdata_indx),
5839 payload_number,
5840 pdu_timestamp,
5841 ISOAL_PDU_STATUS_VALID,
5842 &rx_pdu_meta_buf.pdu_meta);
5843
5844 /* Set callback function return values */
5845 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
5846 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
5847 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
5848
5849 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5850
5851 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5852
5853 /* Test recombine (Black Box) */
5854 /* A new SDU should be allocated */
5855 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
5856 &isoal_global.sink_state[sink_hdl], /* Sink */
5857 &rx_pdu_meta_buf.pdu_meta); /* PDU */
5858
5859 /* SDU payload should be written */
5860 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
5861 &rx_sdu_frag_buf, /* SDU buffer */
5862 0, /* SDU written */
5863 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
5864 (testdata_size - testdata_indx)); /* Size */
5865 /* SDU should not be emitted */
5866
5867 /* Test recombine (White Box) */
5868 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
5869 ISOAL_CONTINUE,
5870 "FSM state %s should be %s!",
5871 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
5872 FSM_TO_STR(ISOAL_CONTINUE));
5873
5874 /* PDU 2 -------------------------------------------------------------*/
5875 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5876 payload_number++;
5877 testdata_indx = testdata_size;
5878 testdata_size += 10;
5879 sdu_size += 10;
5880
5881 /* Invalid LLID - Valid PDU */
5882 isoal_test_create_unframed_pdu(PDU_BIS_LLID_FRAMED,
5883 &testdata[testdata_indx],
5884 (testdata_size - testdata_indx),
5885 payload_number,
5886 pdu_timestamp,
5887 ISOAL_PDU_STATUS_VALID,
5888 &rx_pdu_meta_buf.pdu_meta);
5889
5890 /* Test recombine (Black Box) */
5891 /* Expecting an assertion */
5892 ztest_set_assert_valid(true);
5893
5894 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5895
5896 ztest_set_assert_valid(false);
5897 }
5898
5899 /**
5900 * Test Suite : RX unframed PDU reassembly
5901 *
5902 * Tests receiving a PDU with an invalid LLID with errors. This should not
5903 * result in a assertion as it could happen if a RX reaches it's flush timeout.
5904 */
ZTEST(test_rx_unframed,test_rx_unframed_dbl_pdu_invalid_llid2_pdu_err)5905 ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2_pdu_err)
5906 {
5907 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
5908 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
5909 struct isoal_sdu_buffer sdu_buffer;
5910 isoal_sdu_status_t collated_status;
5911 isoal_sink_handle_t sink_hdl;
5912 uint32_t stream_sync_delay;
5913 uint32_t group_sync_delay;
5914 isoal_sdu_len_t sdu_size;
5915 uint8_t iso_interval_int;
5916 uint64_t payload_number;
5917 uint16_t total_sdu_size;
5918 uint32_t pdu_timestamp;
5919 uint32_t sdu_timestamp;
5920 uint16_t testdata_indx;
5921 uint16_t testdata_size;
5922 uint32_t sdu_interval;
5923 isoal_sdu_cnt_t seqn;
5924 uint8_t testdata[23];
5925 isoal_status_t err;
5926 uint32_t latency;
5927 uint8_t role;
5928 uint8_t BN;
5929 uint8_t FT;
5930
5931 /* Settings */
5932 role = ISOAL_ROLE_PERIPHERAL;
5933 iso_interval_int = 1;
5934 sdu_interval = ISO_INT_UNIT_US;
5935 BN = 2;
5936 FT = 1;
5937 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
5938 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
5939
5940 /* PDU 1 -------------------------------------------------------------*/
5941 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
5942 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
5943 init_test_data_buffer(testdata, 23);
5944 sdu_buffer.dbuf = &rx_sdu_frag_buf;
5945 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
5946 payload_number = 1000 * BN;
5947 pdu_timestamp = 9249;
5948 latency = calc_rx_latency_by_role(role,
5949 false,
5950 FT,
5951 sdu_interval,
5952 iso_interval_int,
5953 stream_sync_delay,
5954 group_sync_delay);
5955 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency);
5956 seqn = 0;
5957 testdata_indx = 0;
5958 testdata_size = 13;
5959 sdu_size = 13;
5960
5961 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
5962 role, /* Role */
5963 false, /* Framed */
5964 BN, /* BN */
5965 FT, /* FT */
5966 sdu_interval, /* SDU Interval */
5967 iso_interval_int, /* ISO Interval */
5968 stream_sync_delay, /* Stream Sync Delay */
5969 group_sync_delay); /* Group Sync Delay */
5970
5971 isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE,
5972 &testdata[testdata_indx],
5973 (testdata_size - testdata_indx),
5974 payload_number,
5975 pdu_timestamp,
5976 ISOAL_PDU_STATUS_VALID,
5977 &rx_pdu_meta_buf.pdu_meta);
5978
5979 /* Set callback function return values */
5980 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
5981 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
5982 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
5983
5984 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
5985
5986 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
5987
5988 /* Test recombine (Black Box) */
5989 /* A new SDU should be allocated */
5990 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
5991 &isoal_global.sink_state[sink_hdl], /* Sink */
5992 &rx_pdu_meta_buf.pdu_meta); /* PDU */
5993
5994 /* SDU payload should be written */
5995 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
5996 &rx_sdu_frag_buf, /* SDU buffer */
5997 0, /* SDU written */
5998 &rx_pdu_meta_buf.pdu[3], /* PDU payload */
5999 (testdata_size - testdata_indx)); /* Size */
6000 /* SDU should not be emitted */
6001
6002 /* Test recombine (White Box) */
6003 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6004 ISOAL_CONTINUE,
6005 "FSM state %s should be %s!",
6006 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6007 FSM_TO_STR(ISOAL_CONTINUE));
6008
6009 /* PDU 2 -------------------------------------------------------------*/
6010 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6011 payload_number++;
6012 testdata_indx = testdata_size;
6013 testdata_size += 10;
6014 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
6015 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
6016
6017 /* Invalid LLID - Valid PDU */
6018 isoal_test_create_unframed_pdu(PDU_BIS_LLID_FRAMED,
6019 &testdata[testdata_indx],
6020 (testdata_size - testdata_indx),
6021 payload_number,
6022 pdu_timestamp,
6023 ISOAL_PDU_STATUS_ERRORS,
6024 &rx_pdu_meta_buf.pdu_meta);
6025
6026 /* Set callback function return values */
6027 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6028 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
6029
6030 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6031
6032 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6033
6034 /* Test recombine (Black Box) */
6035 /* A new SDU should not be allocated */
6036 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
6037
6038 /* SDU payload should not be written */
6039 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1);
6040
6041 /* SDU should be emitted */
6042 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
6043 &isoal_global.sink_state[sink_hdl], /* Sink */
6044 BT_ISO_SINGLE, /* Frag state */
6045 sdu_size, /* Frag size */
6046 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
6047 sdu_timestamp, /* Timestamp */
6048 seqn, /* Seq. number */
6049 sdu_buffer.dbuf, /* Buffer */
6050 sdu_buffer.size, /* Buffer size */
6051 total_sdu_size, /* Total size */
6052 collated_status); /* SDU status */
6053
6054 /* Test recombine (White Box) */
6055 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6056 ISOAL_START,
6057 "FSM state %s should be %s!",
6058 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6059 FSM_TO_STR(ISOAL_START));
6060 }
6061
6062 /**
6063 * Test Suite : RX framed PDU recombination
6064 *
6065 * Tests recombination of a single SDU from a single segmented PDU
6066 */
ZTEST(test_rx_framed,test_rx_framed_single_pdu_single_sdu)6067 ZTEST(test_rx_framed, test_rx_framed_single_pdu_single_sdu)
6068 {
6069 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
6070 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
6071 struct isoal_sdu_buffer sdu_buffer;
6072 isoal_sdu_status_t collated_status;
6073 isoal_sink_handle_t sink_hdl;
6074 uint32_t stream_sync_delay;
6075 uint32_t group_sync_delay;
6076 isoal_sdu_len_t sdu_size;
6077 uint8_t iso_interval_int;
6078 uint16_t pdu_data_loc[5];
6079 uint64_t payload_number;
6080 uint16_t total_sdu_size;
6081 uint32_t sdu_timeoffset;
6082 uint32_t pdu_timestamp;
6083 uint32_t sdu_timestamp;
6084 uint16_t testdata_indx;
6085 uint16_t testdata_size;
6086 uint32_t sdu_interval;
6087 isoal_sdu_cnt_t seqn;
6088 uint8_t testdata[23];
6089 isoal_status_t err;
6090 uint32_t latency;
6091 uint8_t role;
6092 uint8_t BN;
6093 uint8_t FT;
6094
6095 /* Settings */
6096 role = ISOAL_ROLE_PERIPHERAL;
6097 iso_interval_int = 1;
6098 sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5;
6099 BN = 3;
6100 FT = 1;
6101 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
6102 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
6103
6104 /* PDU 1 -------------------------------------------------------------*/
6105 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6106 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
6107 init_test_data_buffer(testdata, 23);
6108 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
6109
6110 sdu_buffer.dbuf = &rx_sdu_frag_buf;
6111 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
6112 payload_number = 1000 * BN;
6113 pdu_timestamp = 9249;
6114 latency = calc_rx_latency_by_role(role,
6115 true,
6116 FT,
6117 sdu_interval,
6118 iso_interval_int,
6119 stream_sync_delay,
6120 group_sync_delay);
6121 sdu_timeoffset = group_sync_delay - 50;
6122 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
6123 seqn = 0;
6124 testdata_indx = 0;
6125 testdata_size = 23;
6126 sdu_size = 23;
6127 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
6128 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
6129
6130 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
6131 role, /* Role */
6132 true, /* Framed */
6133 BN, /* BN */
6134 FT, /* FT */
6135 sdu_interval, /* SDU Interval */
6136 iso_interval_int, /* ISO Interval */
6137 stream_sync_delay, /* Stream Sync Delay */
6138 group_sync_delay); /* Group Sync Delay */
6139
6140 isoal_test_create_framed_pdu_base(payload_number,
6141 pdu_timestamp,
6142 ISOAL_PDU_STATUS_VALID,
6143 &rx_pdu_meta_buf.pdu_meta);
6144 pdu_data_loc[0] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
6145 (testdata_size - testdata_indx),
6146 sdu_timeoffset,
6147 &rx_pdu_meta_buf.pdu_meta);
6148
6149 /* Set callback function return values */
6150 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
6151 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
6152 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6153 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
6154
6155 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6156
6157 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6158
6159 /* Test recombine (Black Box) */
6160 /* A new SDU should be allocated */
6161 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
6162 &isoal_global.sink_state[sink_hdl], /* Sink */
6163 &rx_pdu_meta_buf.pdu_meta); /* PDU */
6164
6165 /* SDU payload should be written */
6166 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
6167 &rx_sdu_frag_buf, /* SDU buffer */
6168 0, /* SDU written */
6169 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
6170 /* PDU payload */
6171 (testdata_size - testdata_indx)); /* Size */
6172
6173 /* SDU should be emitted */
6174 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
6175 &isoal_global.sink_state[sink_hdl], /* Sink */
6176 BT_ISO_SINGLE, /* Frag state */
6177 sdu_size, /* Frag size */
6178 ISOAL_SDU_STATUS_VALID, /* Frag status */
6179 sdu_timestamp, /* Timestamp */
6180 seqn, /* Seq. number */
6181 sdu_buffer.dbuf, /* Buffer */
6182 sdu_buffer.size, /* Buffer size */
6183 total_sdu_size, /* Total size */
6184 collated_status); /* SDU status */
6185
6186 /* Test recombine (White Box) */
6187 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6188 ISOAL_START,
6189 "FSM state %s should be %s!",
6190 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6191 FSM_TO_STR(ISOAL_START));
6192 }
6193
6194 /**
6195 * Test Suite : RX framed PDU recombination
6196 *
6197 * Tests time wrapping recombination of a single SDU from a single segmented PDU
6198 */
ZTEST(test_rx_framed,test_rx_framed_single_pdu_single_sdu_ts_wrap1)6199 ZTEST(test_rx_framed, test_rx_framed_single_pdu_single_sdu_ts_wrap1)
6200 {
6201 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
6202 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
6203 struct isoal_sdu_buffer sdu_buffer;
6204 isoal_sdu_status_t collated_status;
6205 isoal_sink_handle_t sink_hdl;
6206 uint32_t stream_sync_delay;
6207 uint32_t group_sync_delay;
6208 isoal_sdu_len_t sdu_size;
6209 uint8_t iso_interval_int;
6210 uint16_t pdu_data_loc[5];
6211 uint64_t payload_number;
6212 uint16_t total_sdu_size;
6213 uint32_t sdu_timeoffset;
6214 uint32_t pdu_timestamp;
6215 uint32_t sdu_timestamp;
6216 uint16_t testdata_indx;
6217 uint16_t testdata_size;
6218 uint32_t sdu_interval;
6219 isoal_sdu_cnt_t seqn;
6220 uint8_t testdata[23];
6221 isoal_status_t err;
6222 uint32_t latency;
6223 uint8_t role;
6224 uint8_t BN;
6225 uint8_t FT;
6226
6227 /* Settings */
6228 role = ISOAL_ROLE_PERIPHERAL;
6229 iso_interval_int = 1;
6230 sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5;
6231 BN = 3;
6232 FT = 1;
6233 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
6234 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
6235
6236 /* PDU 1 -------------------------------------------------------------*/
6237 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6238 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
6239 init_test_data_buffer(testdata, 23);
6240 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
6241
6242 sdu_buffer.dbuf = &rx_sdu_frag_buf;
6243 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
6244 payload_number = 1000 * BN;
6245 latency = calc_rx_latency_by_role(role,
6246 true,
6247 FT,
6248 sdu_interval,
6249 iso_interval_int,
6250 stream_sync_delay,
6251 group_sync_delay);
6252 sdu_timeoffset = group_sync_delay - 50;
6253 pdu_timestamp = ISOAL_TIME_WRAPPING_POINT_US - latency + sdu_timeoffset + 1;
6254 sdu_timestamp = 0;
6255 seqn = 0;
6256 testdata_indx = 0;
6257 testdata_size = 23;
6258 sdu_size = 23;
6259 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
6260 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
6261
6262 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
6263 role, /* Role */
6264 true, /* Framed */
6265 BN, /* BN */
6266 FT, /* FT */
6267 sdu_interval, /* SDU Interval */
6268 iso_interval_int, /* ISO Interval */
6269 stream_sync_delay, /* Stream Sync Delay */
6270 group_sync_delay); /* Group Sync Delay */
6271
6272 isoal_test_create_framed_pdu_base(payload_number,
6273 pdu_timestamp,
6274 ISOAL_PDU_STATUS_VALID,
6275 &rx_pdu_meta_buf.pdu_meta);
6276 pdu_data_loc[0] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
6277 (testdata_size - testdata_indx),
6278 sdu_timeoffset,
6279 &rx_pdu_meta_buf.pdu_meta);
6280
6281 /* Set callback function return values */
6282 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
6283 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
6284 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6285 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
6286
6287 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6288
6289 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6290
6291 /* Test recombine (Black Box) */
6292 /* A new SDU should be allocated */
6293 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
6294 &isoal_global.sink_state[sink_hdl], /* Sink */
6295 &rx_pdu_meta_buf.pdu_meta); /* PDU */
6296
6297 /* SDU payload should be written */
6298 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
6299 &rx_sdu_frag_buf, /* SDU buffer */
6300 0, /* SDU written */
6301 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
6302 /* PDU payload */
6303 (testdata_size - testdata_indx)); /* Size */
6304
6305 /* SDU should be emitted */
6306 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
6307 &isoal_global.sink_state[sink_hdl], /* Sink */
6308 BT_ISO_SINGLE, /* Frag state */
6309 sdu_size, /* Frag size */
6310 ISOAL_SDU_STATUS_VALID, /* Frag status */
6311 sdu_timestamp, /* Timestamp */
6312 seqn, /* Seq. number */
6313 sdu_buffer.dbuf, /* Buffer */
6314 sdu_buffer.size, /* Buffer size */
6315 total_sdu_size, /* Total size */
6316 collated_status); /* SDU status */
6317
6318 /* Test recombine (White Box) */
6319 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6320 ISOAL_START,
6321 "FSM state %s should be %s!",
6322 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6323 FSM_TO_STR(ISOAL_START));
6324 }
6325
6326 /**
6327 * Test Suite : RX framed PDU recombination
6328 *
6329 * Tests reverse time wrapping in reassembly of a single valid RX PDU into an
6330 * SDU.
6331 */
ZTEST(test_rx_framed,test_rx_framed_single_pdu_single_sdu_ts_wrap2)6332 ZTEST(test_rx_framed, test_rx_framed_single_pdu_single_sdu_ts_wrap2)
6333 {
6334 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
6335 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
6336 struct isoal_sdu_buffer sdu_buffer;
6337 isoal_sdu_status_t collated_status;
6338 isoal_sink_handle_t sink_hdl;
6339 uint32_t stream_sync_delay;
6340 uint32_t group_sync_delay;
6341 isoal_sdu_len_t sdu_size;
6342 uint8_t iso_interval_int;
6343 uint16_t pdu_data_loc[5];
6344 uint64_t payload_number;
6345 uint16_t total_sdu_size;
6346 uint32_t sdu_timeoffset;
6347 uint32_t pdu_timestamp;
6348 uint32_t sdu_timestamp;
6349 uint16_t testdata_indx;
6350 uint16_t testdata_size;
6351 uint32_t sdu_interval;
6352 isoal_sdu_cnt_t seqn;
6353 uint8_t testdata[23];
6354 isoal_status_t err;
6355 uint32_t latency;
6356 uint8_t role;
6357 uint8_t BN;
6358 uint8_t FT;
6359
6360 /* Settings */
6361 role = ISOAL_ROLE_CENTRAL;
6362 iso_interval_int = 1;
6363 sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5;
6364 BN = 3;
6365 FT = 1;
6366 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
6367 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
6368
6369 /* PDU 1 -------------------------------------------------------------*/
6370 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6371 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
6372 init_test_data_buffer(testdata, 23);
6373 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
6374
6375 sdu_buffer.dbuf = &rx_sdu_frag_buf;
6376 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
6377 payload_number = 1000 * BN;
6378 latency = calc_rx_latency_by_role(role,
6379 true,
6380 FT,
6381 sdu_interval,
6382 iso_interval_int,
6383 stream_sync_delay,
6384 group_sync_delay);
6385 sdu_timeoffset = group_sync_delay - 50;
6386 pdu_timestamp = (-latency) + sdu_timeoffset - 1;
6387 sdu_timestamp = ISOAL_TIME_WRAPPING_POINT_US;
6388 seqn = 0;
6389 testdata_indx = 0;
6390 testdata_size = 23;
6391 sdu_size = 23;
6392 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
6393 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
6394
6395 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
6396 role, /* Role */
6397 true, /* Framed */
6398 BN, /* BN */
6399 FT, /* FT */
6400 sdu_interval, /* SDU Interval */
6401 iso_interval_int, /* ISO Interval */
6402 stream_sync_delay, /* Stream Sync Delay */
6403 group_sync_delay); /* Group Sync Delay */
6404
6405 isoal_test_create_framed_pdu_base(payload_number,
6406 pdu_timestamp,
6407 ISOAL_PDU_STATUS_VALID,
6408 &rx_pdu_meta_buf.pdu_meta);
6409 pdu_data_loc[0] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
6410 (testdata_size - testdata_indx),
6411 sdu_timeoffset,
6412 &rx_pdu_meta_buf.pdu_meta);
6413
6414 /* Set callback function return values */
6415 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
6416 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
6417 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6418 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
6419
6420 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6421
6422 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6423
6424 /* Test recombine (Black Box) */
6425 /* A new SDU should be allocated */
6426 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
6427 &isoal_global.sink_state[sink_hdl], /* Sink */
6428 &rx_pdu_meta_buf.pdu_meta); /* PDU */
6429
6430 /* SDU payload should be written */
6431 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
6432 &rx_sdu_frag_buf, /* SDU buffer */
6433 0, /* SDU written */
6434 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
6435 /* PDU payload */
6436 (testdata_size - testdata_indx)); /* Size */
6437
6438 /* SDU should be emitted */
6439 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
6440 &isoal_global.sink_state[sink_hdl], /* Sink */
6441 BT_ISO_SINGLE, /* Frag state */
6442 sdu_size, /* Frag size */
6443 ISOAL_SDU_STATUS_VALID, /* Frag status */
6444 sdu_timestamp, /* Timestamp */
6445 seqn, /* Seq. number */
6446 sdu_buffer.dbuf, /* Buffer */
6447 sdu_buffer.size, /* Buffer size */
6448 total_sdu_size, /* Total size */
6449 collated_status); /* SDU status */
6450
6451 /* Test recombine (White Box) */
6452 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6453 ISOAL_START,
6454 "FSM state %s should be %s!",
6455 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6456 FSM_TO_STR(ISOAL_START));
6457 }
6458
6459 /**
6460 * Test Suite : RX framed PDU recombination
6461 *
6462 * Tests recombination of a single SDU from three segmented PDUs
6463 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_single_sdu)6464 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu)
6465 {
6466 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
6467 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
6468 struct isoal_sdu_buffer sdu_buffer;
6469 isoal_sdu_status_t collated_status;
6470 isoal_sink_handle_t sink_hdl;
6471 uint32_t stream_sync_delay;
6472 uint32_t group_sync_delay;
6473 isoal_sdu_len_t sdu_size;
6474 uint8_t iso_interval_int;
6475 uint16_t pdu_data_loc[5];
6476 uint64_t payload_number;
6477 uint16_t total_sdu_size;
6478 uint16_t sdu_written = 0;
6479 uint32_t sdu_timeoffset;
6480 uint32_t pdu_timestamp;
6481 uint32_t sdu_timestamp;
6482 uint16_t testdata_indx;
6483 uint16_t testdata_size;
6484 uint32_t sdu_interval;
6485 isoal_sdu_cnt_t seqn;
6486 uint8_t testdata[33];
6487 isoal_status_t err;
6488 uint32_t latency;
6489 uint8_t role;
6490 uint8_t BN;
6491 uint8_t FT;
6492
6493 /* Settings */
6494 role = ISOAL_ROLE_PERIPHERAL;
6495 iso_interval_int = 1;
6496 sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5;
6497 BN = 3;
6498 FT = 1;
6499 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
6500 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
6501
6502 /* PDU 1 -------------------------------------------------------------*/
6503 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6504 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
6505 init_test_data_buffer(testdata, 33);
6506 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
6507
6508 sdu_buffer.dbuf = &rx_sdu_frag_buf;
6509 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
6510 payload_number = 1000 * BN;
6511 pdu_timestamp = 9249;
6512 latency = calc_rx_latency_by_role(role,
6513 true,
6514 FT,
6515 sdu_interval,
6516 iso_interval_int,
6517 stream_sync_delay,
6518 group_sync_delay);
6519 sdu_timeoffset = group_sync_delay - 50;
6520 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
6521 seqn = 0;
6522 testdata_indx = 0;
6523 testdata_size = 13;
6524 sdu_size = 13;
6525
6526 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
6527 role, /* Role */
6528 true, /* Framed */
6529 BN, /* BN */
6530 FT, /* FT */
6531 sdu_interval, /* SDU Interval */
6532 iso_interval_int, /* ISO Interval */
6533 stream_sync_delay, /* Stream Sync Delay */
6534 group_sync_delay); /* Group Sync Delay */
6535
6536 isoal_test_create_framed_pdu_base(payload_number,
6537 pdu_timestamp,
6538 ISOAL_PDU_STATUS_VALID,
6539 &rx_pdu_meta_buf.pdu_meta);
6540 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
6541 (testdata_size - testdata_indx),
6542 sdu_timeoffset,
6543 &rx_pdu_meta_buf.pdu_meta);
6544
6545 /* Set callback function return values */
6546 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
6547 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
6548 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6549
6550 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6551
6552 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6553
6554 /* Test recombine (Black Box) */
6555 /* A new SDU should be allocated */
6556 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
6557 &isoal_global.sink_state[sink_hdl], /* Sink */
6558 &rx_pdu_meta_buf.pdu_meta); /* PDU */
6559
6560 /* SDU payload should be written */
6561 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
6562 &rx_sdu_frag_buf, /* SDU buffer */
6563 sdu_written, /* SDU written */
6564 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
6565 /* PDU payload */
6566 (testdata_size - testdata_indx)); /* Size */
6567 /* SDU should not be emitted */
6568
6569 /* Test recombine (White Box) */
6570 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6571 ISOAL_CONTINUE,
6572 "FSM state %s should be %s!",
6573 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6574 FSM_TO_STR(ISOAL_CONTINUE));
6575
6576 /* PDU 2 -------------------------------------------------------------*/
6577 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6578
6579 sdu_written += (testdata_size - testdata_indx);
6580 payload_number++;
6581 testdata_indx = testdata_size;
6582 testdata_size += 10;
6583 sdu_size += 10;
6584
6585 isoal_test_create_framed_pdu_base(payload_number,
6586 pdu_timestamp,
6587 ISOAL_PDU_STATUS_VALID,
6588 &rx_pdu_meta_buf.pdu_meta);
6589 pdu_data_loc[1] = isoal_test_add_framed_pdu_cont(&testdata[testdata_indx],
6590 (testdata_size - testdata_indx),
6591 &rx_pdu_meta_buf.pdu_meta);
6592
6593 /* Set callback function return values */
6594 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6595
6596 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6597
6598 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6599
6600 /* Test recombine (Black Box) */
6601 /* A new SDU should not be allocated */
6602
6603 /* SDU payload should be written */
6604 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
6605 &rx_sdu_frag_buf, /* SDU buffer */
6606 sdu_written, /* SDU written */
6607 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
6608 /* PDU payload */
6609 (testdata_size - testdata_indx)); /* Size */
6610 /* SDU should not be emitted */
6611
6612 /* Test recombine (White Box) */
6613 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6614 ISOAL_CONTINUE,
6615 "FSM state %s should be %s!",
6616 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6617 FSM_TO_STR(ISOAL_CONTINUE));
6618
6619 /* PDU 3 -------------------------------------------------------------*/
6620 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6621
6622 sdu_written += (testdata_size - testdata_indx);
6623 payload_number++;
6624 testdata_indx = testdata_size;
6625 testdata_size += 10;
6626 sdu_size += 10;
6627 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
6628 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
6629
6630 isoal_test_create_framed_pdu_base(payload_number,
6631 pdu_timestamp,
6632 ISOAL_PDU_STATUS_VALID,
6633 &rx_pdu_meta_buf.pdu_meta);
6634 pdu_data_loc[2] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
6635 (testdata_size - testdata_indx),
6636 &rx_pdu_meta_buf.pdu_meta);
6637
6638 /* Set callback function return values */
6639 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6640 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
6641
6642 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6643
6644 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6645
6646 /* Test recombine (Black Box) */
6647 /* A new SDU should not be allocated */
6648
6649 /* SDU payload should be written */
6650 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
6651 &rx_sdu_frag_buf, /* SDU buffer */
6652 sdu_written, /* SDU written */
6653 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[2]],
6654 /* PDU payload */
6655 (testdata_size - testdata_indx)); /* Size */
6656 /* SDU should be emitted */
6657 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
6658 &isoal_global.sink_state[sink_hdl], /* Sink */
6659 BT_ISO_SINGLE, /* Frag state */
6660 sdu_size, /* Frag size */
6661 ISOAL_SDU_STATUS_VALID, /* Frag status */
6662 sdu_timestamp, /* Timestamp */
6663 seqn, /* Seq. number */
6664 sdu_buffer.dbuf, /* Buffer */
6665 sdu_buffer.size, /* Buffer size */
6666 total_sdu_size, /* Total size */
6667 collated_status); /* SDU status */
6668
6669 /* Test recombine (White Box) */
6670 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6671 ISOAL_START,
6672 "FSM state %s should be %s!",
6673 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6674 FSM_TO_STR(ISOAL_START));
6675 }
6676
6677 /**
6678 * Test Suite : RX framed PDU recombination
6679 *
6680 * Tests recombination of two SDUs from three segmented PDUs
6681 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_dbl_sdu)6682 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu)
6683 {
6684 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
6685 struct rx_sdu_frag_buffer rx_sdu_frag_buf[2];
6686 struct isoal_sdu_buffer sdu_buffer[2];
6687 isoal_sdu_status_t collated_status;
6688 isoal_sink_handle_t sink_hdl;
6689 uint32_t stream_sync_delay;
6690 uint32_t group_sync_delay;
6691 isoal_sdu_len_t sdu_size[2];
6692 uint8_t iso_interval_int;
6693 uint32_t sdu_timestamp[2];
6694 uint16_t pdu_data_loc[5];
6695 uint32_t iso_interval_us;
6696 uint64_t payload_number;
6697 uint16_t total_sdu_size;
6698 uint16_t sdu_written = 0;
6699 uint32_t sdu_timeoffset;
6700 uint32_t pdu_timestamp;
6701 uint16_t testdata_indx;
6702 uint16_t testdata_size;
6703 isoal_sdu_cnt_t seqn;
6704 uint32_t sdu_interval;
6705 uint8_t testdata[46];
6706 isoal_status_t err;
6707 uint32_t latency;
6708 uint8_t role;
6709 uint8_t BN;
6710 uint8_t FT;
6711
6712 /* Settings */
6713 role = ISOAL_ROLE_PERIPHERAL;
6714 iso_interval_int = 1;
6715 iso_interval_us = (iso_interval_int * ISO_INT_UNIT_US);
6716 sdu_interval = (iso_interval_us / 3) + 5;
6717 BN = 3;
6718 FT = 1;
6719 stream_sync_delay = iso_interval_us - 200;
6720 group_sync_delay = iso_interval_us - 50;
6721
6722 /* PDU 1 -------------------------------------------------------------*/
6723 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6724 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
6725 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
6726 init_test_data_buffer(testdata, 46);
6727 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
6728
6729 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
6730 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
6731 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
6732 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
6733 payload_number = 1000 * BN;
6734 pdu_timestamp = 9249;
6735 latency = calc_rx_latency_by_role(role,
6736 true,
6737 FT,
6738 sdu_interval,
6739 iso_interval_int,
6740 stream_sync_delay,
6741 group_sync_delay);
6742 sdu_timeoffset = group_sync_delay - 50;
6743 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
6744 seqn = 0;
6745 testdata_indx = 0;
6746 testdata_size = 13;
6747 sdu_size[0] = 13;
6748
6749 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
6750 role, /* Role */
6751 true, /* Framed */
6752 BN, /* BN */
6753 FT, /* FT */
6754 sdu_interval, /* SDU Interval */
6755 iso_interval_int, /* ISO Interval */
6756 stream_sync_delay, /* Stream Sync Delay */
6757 group_sync_delay); /* Group Sync Delay */
6758
6759 isoal_test_create_framed_pdu_base(payload_number,
6760 pdu_timestamp,
6761 ISOAL_PDU_STATUS_VALID,
6762 &rx_pdu_meta_buf.pdu_meta);
6763 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
6764 (testdata_size - testdata_indx),
6765 sdu_timeoffset,
6766 &rx_pdu_meta_buf.pdu_meta);
6767
6768 /* Set callback function return values */
6769 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
6770 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
6771 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6772
6773 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6774
6775 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6776
6777 /* Test recombine (Black Box) */
6778 /* A new SDU should be allocated */
6779 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
6780 &isoal_global.sink_state[sink_hdl], /* Sink */
6781 &rx_pdu_meta_buf.pdu_meta); /* PDU */
6782
6783 /* SDU payload should be written */
6784 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
6785 &rx_sdu_frag_buf[0], /* SDU buffer */
6786 sdu_written, /* SDU written */
6787 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
6788 /* PDU payload */
6789 (testdata_size - testdata_indx)); /* Size */
6790
6791 /* SDU should not be emitted */
6792
6793 /* Test recombine (White Box) */
6794 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6795 ISOAL_CONTINUE,
6796 "FSM state %s should be %s!",
6797 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6798 FSM_TO_STR(ISOAL_CONTINUE));
6799
6800 /* PDU 2 -------------------------------------------------------------*/
6801 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6802
6803 sdu_written += (testdata_size - testdata_indx);
6804 payload_number++;
6805 testdata_indx = testdata_size;
6806 testdata_size += 10;
6807 sdu_size[0] += 10;
6808
6809 isoal_test_create_framed_pdu_base(payload_number,
6810 pdu_timestamp,
6811 ISOAL_PDU_STATUS_VALID,
6812 &rx_pdu_meta_buf.pdu_meta);
6813 pdu_data_loc[1] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
6814 (testdata_size - testdata_indx),
6815 &rx_pdu_meta_buf.pdu_meta);
6816
6817 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
6818 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
6819 testdata_indx = testdata_size;
6820 testdata_size += 13;
6821 sdu_size[1] = 13;
6822 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
6823 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
6824
6825 pdu_data_loc[2] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
6826 (testdata_size - testdata_indx),
6827 sdu_timeoffset,
6828 &rx_pdu_meta_buf.pdu_meta);
6829
6830 /* Set callback function return values */
6831 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
6832 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
6833 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6834 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
6835
6836 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6837
6838 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6839
6840 /* Test recombine (Black Box) */
6841
6842 /* SDU 1 */
6843 /* A new SDU should not be allocated */
6844
6845 /* SDU payload should be written */
6846 ZASSERT_ISOAL_SDU_WRITE_TEST(history[1],
6847 &rx_sdu_frag_buf[0], /* SDU buffer */
6848 sdu_written, /* SDU written */
6849 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
6850 /* PDU payload */
6851 10); /* Size */
6852 /* SDU should be emitted */
6853 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
6854 &isoal_global.sink_state[sink_hdl], /* Sink */
6855 BT_ISO_SINGLE, /* Frag state */
6856 sdu_size[0], /* Frag size */
6857 ISOAL_SDU_STATUS_VALID, /* Frag status */
6858 sdu_timestamp[0], /* Timestamp */
6859 seqn, /* Seq. number */
6860 sdu_buffer[0].dbuf, /* Buffer */
6861 sdu_buffer[0].size, /* Buffer size */
6862 total_sdu_size, /* Total size */
6863 collated_status); /* SDU status */
6864
6865 /* SDU 2 */
6866 sdu_written = 0;
6867 seqn++;
6868 /* A new SDU should be allocated */
6869 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
6870 &isoal_global.sink_state[sink_hdl], /* Sink */
6871 &rx_pdu_meta_buf.pdu_meta); /* PDU */
6872
6873 /* SDU payload should be written */
6874 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
6875 &rx_sdu_frag_buf[1], /* SDU buffer */
6876 sdu_written, /* SDU written */
6877 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[2]],
6878 /* PDU payload */
6879 (testdata_size - testdata_indx)); /* Size */
6880
6881 /* SDU should not be emitted */
6882
6883 /* Test recombine (White Box) */
6884 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6885 ISOAL_CONTINUE,
6886 "FSM state %s should be %s!",
6887 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6888 FSM_TO_STR(ISOAL_CONTINUE));
6889
6890 /* PDU 3 -------------------------------------------------------------*/
6891 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6892
6893 sdu_written += (testdata_size - testdata_indx);
6894 payload_number++;
6895 testdata_indx = testdata_size;
6896 testdata_size += 10;
6897 sdu_size[1] += 10;
6898 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]);
6899
6900 isoal_test_create_framed_pdu_base(payload_number,
6901 pdu_timestamp,
6902 ISOAL_PDU_STATUS_VALID,
6903 &rx_pdu_meta_buf.pdu_meta);
6904 pdu_data_loc[3] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
6905 (testdata_size - testdata_indx),
6906 &rx_pdu_meta_buf.pdu_meta);
6907
6908 /* Set callback function return values */
6909 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
6910 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
6911
6912 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
6913
6914 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
6915
6916 /* Test recombine (Black Box) */
6917 /* A new SDU should not be allocated */
6918
6919 /* SDU payload should be written */
6920 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
6921 &rx_sdu_frag_buf[1], /* SDU buffer */
6922 sdu_written, /* SDU written */
6923 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
6924 /* PDU payload */
6925 (testdata_size - testdata_indx)); /* Size */
6926
6927 /* SDU should be emitted */
6928 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
6929 &isoal_global.sink_state[sink_hdl], /* Sink */
6930 BT_ISO_SINGLE, /* Frag state */
6931 sdu_size[1], /* Frag size */
6932 ISOAL_SDU_STATUS_VALID, /* Frag status */
6933 sdu_timestamp[1], /* Timestamp */
6934 seqn, /* Seq. number */
6935 sdu_buffer[1].dbuf, /* Buffer */
6936 sdu_buffer[1].size, /* Buffer size */
6937 total_sdu_size, /* Total size */
6938 collated_status); /* SDU status */
6939
6940 /* Test recombine (White Box) */
6941 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
6942 ISOAL_START,
6943 "FSM state %s should be %s!",
6944 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
6945 FSM_TO_STR(ISOAL_START));
6946 }
6947
6948 /**
6949 * Test Suite : RX framed PDU recombination
6950 *
6951 * Tests recombination of a zero length SDU
6952 */
ZTEST(test_rx_framed,test_rx_framed_zero_length_sdu)6953 ZTEST(test_rx_framed, test_rx_framed_zero_length_sdu)
6954 {
6955 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
6956 struct rx_sdu_frag_buffer rx_sdu_frag_buf[3];
6957 struct isoal_sdu_buffer sdu_buffer[3];
6958 isoal_sdu_status_t collated_status;
6959 isoal_sink_handle_t sink_hdl;
6960 uint32_t stream_sync_delay;
6961 uint32_t group_sync_delay;
6962 isoal_sdu_len_t sdu_size[3];
6963 uint8_t iso_interval_int;
6964 uint32_t sdu_timestamp[3];
6965 uint16_t pdu_data_loc[5];
6966 uint32_t iso_interval_us;
6967 isoal_sdu_cnt_t seqn[3];
6968 uint64_t payload_number;
6969 uint16_t total_sdu_size;
6970 uint16_t sdu_written = 0;
6971 uint32_t sdu_timeoffset;
6972 uint32_t pdu_timestamp;
6973 uint16_t testdata_indx;
6974 uint16_t testdata_size;
6975 uint32_t sdu_interval;
6976 uint8_t testdata[46];
6977 isoal_status_t err;
6978 uint32_t latency;
6979 uint8_t role;
6980 uint8_t BN;
6981 uint8_t FT;
6982
6983 /* Settings */
6984 role = ISOAL_ROLE_PERIPHERAL;
6985 iso_interval_int = 1;
6986 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
6987 sdu_interval = (iso_interval_us / 3) + 5;
6988 BN = 3;
6989 FT = 1;
6990 stream_sync_delay = iso_interval_us - 200;
6991 group_sync_delay = iso_interval_us - 50;
6992
6993 /* PDU 1 -------------------------------------------------------------*/
6994 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
6995 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
6996 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
6997 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]);
6998 init_test_data_buffer(testdata, 46);
6999 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
7000
7001 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
7002 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
7003 sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2];
7004 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7005 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7006 sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7007 payload_number = 1000 * BN;
7008 pdu_timestamp = 9249;
7009 latency = calc_rx_latency_by_role(role,
7010 true,
7011 FT,
7012 sdu_interval,
7013 iso_interval_int,
7014 stream_sync_delay,
7015 group_sync_delay);
7016 sdu_timeoffset = group_sync_delay - 50;
7017 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
7018 seqn[0] = 0;
7019 testdata_indx = 0;
7020 testdata_size = 13;
7021 sdu_size[0] = 13;
7022
7023 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
7024 role, /* Role */
7025 true, /* Framed */
7026 BN, /* BN */
7027 FT, /* FT */
7028 sdu_interval, /* SDU Interval */
7029 iso_interval_int, /* ISO Interval */
7030 stream_sync_delay, /* Stream Sync Delay */
7031 group_sync_delay); /* Group Sync Delay */
7032
7033 isoal_test_create_framed_pdu_base(payload_number,
7034 pdu_timestamp,
7035 ISOAL_PDU_STATUS_VALID,
7036 &rx_pdu_meta_buf.pdu_meta);
7037 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
7038 (testdata_size - testdata_indx),
7039 sdu_timeoffset,
7040 &rx_pdu_meta_buf.pdu_meta);
7041
7042 /* Set callback function return values */
7043 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
7044 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
7045 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
7046
7047 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7048
7049 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7050
7051 /* Test recombine (Black Box) */
7052 /* A new SDU should be allocated */
7053 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
7054 &isoal_global.sink_state[sink_hdl], /* Sink */
7055 &rx_pdu_meta_buf.pdu_meta); /* PDU */
7056
7057 /* SDU payload should be written */
7058 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
7059 &rx_sdu_frag_buf[0], /* SDU buffer */
7060 sdu_written, /* SDU written */
7061 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
7062 /* PDU payload */
7063 (testdata_size - testdata_indx)); /* Size */
7064
7065 /* SDU should not be emitted */
7066
7067 /* Test recombine (White Box) */
7068 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7069 ISOAL_CONTINUE,
7070 "FSM state %s should be %s!",
7071 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7072 FSM_TO_STR(ISOAL_CONTINUE));
7073
7074 /* PDU 2 -------------------------------------------------------------*/
7075 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7076
7077 sdu_written += (testdata_size - testdata_indx);
7078 payload_number++;
7079 testdata_indx = testdata_size;
7080 testdata_size += 10;
7081 sdu_size[0] += 10;
7082
7083 isoal_test_create_framed_pdu_base(payload_number,
7084 pdu_timestamp,
7085 ISOAL_PDU_STATUS_VALID,
7086 &rx_pdu_meta_buf.pdu_meta);
7087 pdu_data_loc[1] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
7088 (testdata_size - testdata_indx),
7089 &rx_pdu_meta_buf.pdu_meta);
7090
7091 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
7092 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
7093 seqn[1] = seqn[0] + 1;
7094 testdata_indx = testdata_size;
7095 sdu_size[1] = 0;
7096
7097 /* Zero length SDU */
7098 pdu_data_loc[2] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
7099 (testdata_size - testdata_indx),
7100 sdu_timeoffset,
7101 &rx_pdu_meta_buf.pdu_meta);
7102
7103 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
7104 sdu_timestamp[2] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
7105 seqn[2] = seqn[1] + 1;
7106 testdata_indx = testdata_size;
7107 testdata_size += 10;
7108 sdu_size[2] = 10;
7109
7110 pdu_data_loc[3] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
7111 (testdata_size - testdata_indx),
7112 sdu_timeoffset,
7113 &rx_pdu_meta_buf.pdu_meta);
7114
7115 /* Set callback function return values */
7116 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
7117 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]);
7118 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
7119 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
7120 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
7121
7122 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7123
7124 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7125
7126 /* Test recombine (Black Box) */
7127 /* SDU 1 */
7128 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
7129 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
7130
7131 /* A new SDU should not be allocated */
7132
7133 /* SDU payload should be written */
7134 ZASSERT_ISOAL_SDU_WRITE_TEST(history[1],
7135 &rx_sdu_frag_buf[0], /* SDU buffer */
7136 sdu_written, /* SDU written */
7137 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
7138 /* PDU payload */
7139 10); /* Size */
7140
7141 /* SDU should be emitted */
7142 ZASSERT_ISOAL_SDU_EMIT_TEST(history[0],
7143 &isoal_global.sink_state[sink_hdl], /* Sink */
7144 BT_ISO_SINGLE, /* Frag state */
7145 sdu_size[0], /* Frag size */
7146 ISOAL_SDU_STATUS_VALID, /* Frag status */
7147 sdu_timestamp[0], /* Timestamp */
7148 seqn[0], /* Seq. number */
7149 sdu_buffer[0].dbuf, /* Buffer */
7150 sdu_buffer[0].size, /* Buffer size */
7151 total_sdu_size, /* Total size */
7152 collated_status); /* SDU status */
7153
7154 /* SDU 2 */
7155 sdu_written = 0;
7156 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]);
7157 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
7158
7159 /* A new SDU should be allocated */
7160 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1],
7161 &isoal_global.sink_state[sink_hdl], /* Sink */
7162 &rx_pdu_meta_buf.pdu_meta); /* PDU */
7163
7164 /* SDU payload should not be written */
7165
7166 /* SDU should be emitted */
7167 ZASSERT_ISOAL_SDU_EMIT_TEST(history[1],
7168 &isoal_global.sink_state[sink_hdl], /* Sink */
7169 BT_ISO_SINGLE, /* Frag state */
7170 sdu_size[1], /* Frag size */
7171 ISOAL_SDU_STATUS_VALID, /* Frag status */
7172 sdu_timestamp[1], /* Timestamp */
7173 seqn[1], /* Seq. number */
7174 sdu_buffer[1].dbuf, /* Buffer */
7175 sdu_buffer[1].size, /* Buffer size */
7176 total_sdu_size, /* Total size */
7177 collated_status); /* SDU status */
7178
7179 /* SDU 3 */
7180 /* A new SDU should be allocated */
7181 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
7182 &isoal_global.sink_state[sink_hdl], /* Sink */
7183 &rx_pdu_meta_buf.pdu_meta); /* PDU */
7184
7185 /* SDU payload should be written */
7186 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
7187 &rx_sdu_frag_buf[2], /* SDU buffer */
7188 sdu_written, /* SDU written */
7189 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
7190 /* PDU payload */
7191 (testdata_size - testdata_indx)); /* Size */
7192
7193 /* SDU should not be emitted */
7194
7195 /* Test recombine (White Box) */
7196 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7197 ISOAL_CONTINUE,
7198 "FSM state %s should be %s!",
7199 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7200 FSM_TO_STR(ISOAL_CONTINUE));
7201
7202 /* PDU 3 -------------------------------------------------------------*/
7203 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7204
7205 sdu_written += (testdata_size - testdata_indx);
7206 payload_number++;
7207 testdata_indx = testdata_size;
7208 testdata_size += 10;
7209 sdu_size[2] += 10;
7210 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[2], sdu_size[2]);
7211 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
7212
7213 isoal_test_create_framed_pdu_base(payload_number,
7214 pdu_timestamp,
7215 ISOAL_PDU_STATUS_VALID,
7216 &rx_pdu_meta_buf.pdu_meta);
7217 pdu_data_loc[3] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
7218 (testdata_size - testdata_indx),
7219 &rx_pdu_meta_buf.pdu_meta);
7220
7221 /* Set callback function return values */
7222 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
7223 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
7224
7225 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7226
7227 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7228
7229 /* Test recombine (Black Box) */
7230 /* A new SDU should not be allocated */
7231
7232 /* SDU payload should be written */
7233 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
7234 &rx_sdu_frag_buf[2], /* SDU buffer */
7235 sdu_written, /* SDU written */
7236 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
7237 /* PDU payload */
7238 (testdata_size - testdata_indx)); /* Size */
7239
7240 /* SDU should be emitted */
7241 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
7242 &isoal_global.sink_state[sink_hdl], /* Sink */
7243 BT_ISO_SINGLE, /* Frag state */
7244 sdu_size[2], /* Frag size */
7245 ISOAL_SDU_STATUS_VALID, /* Frag status */
7246 sdu_timestamp[2], /* Timestamp */
7247 seqn[2], /* Seq. number */
7248 sdu_buffer[2].dbuf, /* Buffer */
7249 sdu_buffer[2].size, /* Buffer size */
7250 total_sdu_size, /* Total size */
7251 collated_status); /* SDU status */
7252
7253 /* Test recombine (White Box) */
7254 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7255 ISOAL_START,
7256 "FSM state %s should be %s!",
7257 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7258 FSM_TO_STR(ISOAL_START));
7259 }
7260
7261 /**
7262 * Test Suite : RX framed PDU recombination
7263 *
7264 * Tests recombination of a single SDU from a single segmented PDU followed by
7265 * padding
7266 */
ZTEST(test_rx_framed,test_rx_framed_dbl_pdu_dbl_sdu_padding)7267 ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_padding)
7268 {
7269 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
7270 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
7271 struct isoal_sdu_buffer sdu_buffer;
7272 isoal_sdu_status_t collated_status;
7273 isoal_sink_handle_t sink_hdl;
7274 uint32_t stream_sync_delay;
7275 uint32_t group_sync_delay;
7276 isoal_sdu_len_t sdu_size;
7277 uint8_t iso_interval_int;
7278 uint16_t pdu_data_loc[5];
7279 uint32_t iso_interval_us;
7280 uint64_t payload_number;
7281 uint16_t total_sdu_size;
7282 uint32_t sdu_timeoffset;
7283 uint32_t pdu_timestamp;
7284 uint32_t sdu_timestamp;
7285 uint16_t testdata_indx;
7286 uint16_t testdata_size;
7287 uint32_t sdu_interval;
7288 isoal_sdu_cnt_t seqn;
7289 uint8_t testdata[33];
7290 isoal_status_t err;
7291 uint32_t latency;
7292 uint8_t role;
7293 uint8_t BN;
7294 uint8_t FT;
7295
7296 /* Settings */
7297 role = ISOAL_ROLE_PERIPHERAL;
7298 iso_interval_int = 1;
7299 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
7300 sdu_interval = (iso_interval_us / 3) + 5;
7301 BN = 3;
7302 FT = 1;
7303 stream_sync_delay = iso_interval_us - 200;
7304 group_sync_delay = iso_interval_us - 50;
7305
7306 /* PDU 1 -------------------------------------------------------------*/
7307 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7308 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
7309 init_test_data_buffer(testdata, 33);
7310 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
7311
7312 sdu_buffer.dbuf = &rx_sdu_frag_buf;
7313 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7314 payload_number = 1000 * BN;
7315 pdu_timestamp = 9249;
7316 latency = calc_rx_latency_by_role(role,
7317 true,
7318 FT,
7319 sdu_interval,
7320 iso_interval_int,
7321 stream_sync_delay,
7322 group_sync_delay);
7323 sdu_timeoffset = group_sync_delay - 50;
7324 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
7325 seqn = 0;
7326 testdata_indx = 0;
7327 testdata_size = 13;
7328 sdu_size = 13;
7329 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
7330 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
7331
7332 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
7333 role, /* Role */
7334 true, /* Framed */
7335 BN, /* BN */
7336 FT, /* FT */
7337 sdu_interval, /* SDU Interval */
7338 iso_interval_int, /* ISO Interval */
7339 stream_sync_delay, /* Stream Sync Delay */
7340 group_sync_delay); /* Group Sync Delay */
7341
7342 isoal_test_create_framed_pdu_base(payload_number,
7343 pdu_timestamp,
7344 ISOAL_PDU_STATUS_VALID,
7345 &rx_pdu_meta_buf.pdu_meta);
7346 pdu_data_loc[0] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
7347 (testdata_size - testdata_indx),
7348 sdu_timeoffset,
7349 &rx_pdu_meta_buf.pdu_meta);
7350
7351 /* Set callback function return values */
7352 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
7353 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
7354 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
7355 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
7356
7357 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7358
7359 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7360
7361 /* Test recombine (Black Box) */
7362 /* A new SDU should be allocated */
7363 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
7364 &isoal_global.sink_state[sink_hdl], /* Sink */
7365 &rx_pdu_meta_buf.pdu_meta); /* PDU */
7366
7367 /* SDU payload should be written */
7368 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
7369 &rx_sdu_frag_buf, /* SDU buffer */
7370 0, /* SDU written */
7371 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
7372 /* PDU payload */
7373 (testdata_size - testdata_indx)); /* Size */
7374
7375 /* SDU should be emitted */
7376 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
7377 &isoal_global.sink_state[sink_hdl], /* Sink */
7378 BT_ISO_SINGLE, /* Frag state */
7379 sdu_size, /* Frag size */
7380 ISOAL_SDU_STATUS_VALID, /* Frag status */
7381 sdu_timestamp, /* Timestamp */
7382 seqn, /* Seq. number */
7383 sdu_buffer.dbuf, /* Buffer */
7384 sdu_buffer.size, /* Buffer size */
7385 total_sdu_size, /* Total size */
7386 collated_status); /* SDU status */
7387
7388 /* Test recombine (White Box) */
7389 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7390 ISOAL_START,
7391 "FSM state %s should be %s!",
7392 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7393 FSM_TO_STR(ISOAL_START));
7394
7395 /* PDU 2 -------------------------------------------------------------*/
7396 /* Padding PDU */
7397 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7398 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
7399
7400 payload_number++;
7401 testdata_indx = testdata_size;
7402
7403 isoal_test_create_framed_pdu_base(payload_number,
7404 pdu_timestamp,
7405 ISOAL_PDU_STATUS_VALID,
7406 &rx_pdu_meta_buf.pdu_meta);
7407
7408 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7409
7410 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7411
7412 /* Test recombine (Black Box) */
7413 /* SDU should not be allocated */
7414 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
7415
7416 /* SDU should not be written */
7417 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1);
7418
7419 /* SDU should not be emitted */
7420 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1);
7421
7422 /* Test recombine (White Box) */
7423 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7424 ISOAL_START,
7425 "FSM state %s should be %s!",
7426 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7427 FSM_TO_STR(ISOAL_START));
7428
7429 /* PDU 3 -------------------------------------------------------------*/
7430 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7431 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
7432
7433 payload_number++;
7434
7435 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
7436 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
7437 seqn++;
7438 testdata_indx = testdata_size;
7439 testdata_size += 10;
7440 sdu_size = 10;
7441 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
7442 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
7443
7444 isoal_test_create_framed_pdu_base(payload_number,
7445 pdu_timestamp,
7446 ISOAL_PDU_STATUS_VALID,
7447 &rx_pdu_meta_buf.pdu_meta);
7448 pdu_data_loc[1] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
7449 (testdata_size - testdata_indx),
7450 sdu_timeoffset,
7451 &rx_pdu_meta_buf.pdu_meta);
7452
7453 /* Set callback function return values */
7454 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
7455 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
7456 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
7457 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
7458
7459 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7460
7461 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7462
7463 /* Test recombine (Black Box) */
7464 /* A new SDU should be allocated */
7465 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
7466 &isoal_global.sink_state[sink_hdl], /* Sink */
7467 &rx_pdu_meta_buf.pdu_meta); /* PDU */
7468
7469 /* SDU payload should be written */
7470 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
7471 &rx_sdu_frag_buf, /* SDU buffer */
7472 0, /* SDU written */
7473 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
7474 /* PDU payload */
7475 (testdata_size - testdata_indx)); /* Size */
7476
7477 /* SDU should be emitted */
7478 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
7479 &isoal_global.sink_state[sink_hdl], /* Sink */
7480 BT_ISO_SINGLE, /* Frag state */
7481 sdu_size, /* Frag size */
7482 ISOAL_SDU_STATUS_VALID, /* Frag status */
7483 sdu_timestamp, /* Timestamp */
7484 seqn, /* Seq. number */
7485 sdu_buffer.dbuf, /* Buffer */
7486 sdu_buffer.size, /* Buffer size */
7487 total_sdu_size, /* Total size */
7488 collated_status); /* SDU status */
7489
7490 /* Test recombine (White Box) */
7491 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7492 ISOAL_START,
7493 "FSM state %s should be %s!",
7494 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7495 FSM_TO_STR(ISOAL_START));
7496 }
7497
7498 /**
7499 * Test Suite : RX framed PDU recombination
7500 *
7501 * Tests release of SDUs when receiving only padding PDUs
7502 *
7503 * Expected Sequence:
7504 * -- Total of 3 SDUs released across 2 events
7505 * -- Event 1: PDU0 Valid Framed Padding
7506 * PDU1 Valid Framed Padding
7507 * PDU2 Valid Framed Padding
7508 * Event 2: PDU3 Valid SDU 3 Framed Single
7509 * -----> SDU 0 Lost (Released)
7510 * -----> SDU 1 Lost (Released)
7511 * -----> SDU 2 Lost (Released)
7512 * -----> SDU 3 Valid (Released)
7513 * PDU4 N/A
7514 * PDU5 N/A
7515 *
7516 */
ZTEST(test_rx_framed,test_rx_framed_padding_only)7517 ZTEST(test_rx_framed, test_rx_framed_padding_only)
7518 {
7519 const uint8_t number_of_pdus = 3;
7520 const uint8_t testdata_size_max = 20;
7521
7522 struct rx_sdu_frag_buffer rx_sdu_frag_buf[4];
7523 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
7524 struct isoal_sdu_buffer sdu_buffer[4];
7525 isoal_sdu_status_t collated_status;
7526 isoal_sink_handle_t sink_hdl;
7527 uint32_t stream_sync_delay;
7528 uint32_t group_sync_delay;
7529 isoal_sdu_len_t sdu_size;
7530 uint8_t iso_interval_int;
7531 uint32_t iso_interval_us;
7532 uint64_t payload_number;
7533 uint16_t total_sdu_size;
7534 uint32_t sdu_timeoffset;
7535 uint32_t pdu_timestamp;
7536 uint32_t sdu_timestamp;
7537 uint16_t testdata_indx;
7538 uint16_t testdata_size;
7539 uint16_t pdu_data_loc;
7540 uint32_t sdu_interval;
7541 isoal_sdu_cnt_t seqn;
7542 uint8_t testdata[testdata_size_max];
7543 isoal_status_t err;
7544 uint32_t latency;
7545 uint8_t role;
7546 uint8_t BN;
7547 uint8_t FT;
7548
7549 /* Settings */
7550 role = BT_CONN_ROLE_PERIPHERAL;
7551 iso_interval_int = 1;
7552 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
7553 sdu_interval = (iso_interval_us / number_of_pdus) + 5;
7554 BN = 3;
7555 FT = 1;
7556 stream_sync_delay = iso_interval_us - 200;
7557 group_sync_delay = iso_interval_us - 50;
7558
7559 /* PDU 0 -------------------------------------------------------------*/
7560 /* Padding PDU */
7561 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7562 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
7563 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
7564 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]);
7565 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[3]);
7566 init_test_data_buffer(testdata, testdata_size_max);
7567 pdu_data_loc = 0;
7568
7569 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
7570 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
7571 sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2];
7572 sdu_buffer[3].dbuf = &rx_sdu_frag_buf[3];
7573 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7574 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7575 sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7576 sdu_buffer[3].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7577 payload_number = 1000 * BN;
7578 pdu_timestamp = 9249;
7579 latency = calc_rx_latency_by_role(role,
7580 true,
7581 FT,
7582 sdu_interval,
7583 iso_interval_int,
7584 stream_sync_delay,
7585 group_sync_delay);
7586 sdu_timeoffset = group_sync_delay - 50;
7587 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us);
7588 seqn = 0;
7589 testdata_indx = testdata_size = 0;
7590 sdu_size = 0;
7591 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
7592 collated_status =
7593 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
7594
7595 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
7596 role, /* Role */
7597 true, /* Framed */
7598 BN, /* BN */
7599 FT, /* FT */
7600 sdu_interval, /* SDU Interval */
7601 iso_interval_int, /* ISO Interval */
7602 stream_sync_delay, /* Stream Sync Delay */
7603 group_sync_delay); /* Group Sync Delay */
7604
7605 isoal_test_create_framed_pdu_base(payload_number,
7606 pdu_timestamp,
7607 ISOAL_PDU_STATUS_VALID,
7608 &rx_pdu_meta_buf.pdu_meta);
7609
7610 /* Set callback function return values */
7611 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
7612 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
7613 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
7614
7615 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7616
7617 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7618
7619 /* Test recombine (Black Box) */
7620 /* A new SDU should not be allocated */
7621 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
7622
7623 /* SDU payload should not be written */
7624 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
7625
7626 /* SDU payload should not be emitted */
7627 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
7628
7629 /* Test recombine (White Box) */
7630 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7631 ISOAL_START,
7632 "FSM state %s should be %s!",
7633 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7634 FSM_TO_STR(ISOAL_START));
7635
7636 /* PDU 1 -------------------------------------------------------------*/
7637 /* Padding PDU */
7638 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7639
7640 payload_number++;
7641
7642 isoal_test_create_framed_pdu_base(payload_number,
7643 pdu_timestamp,
7644 ISOAL_PDU_STATUS_VALID,
7645 &rx_pdu_meta_buf.pdu_meta);
7646
7647 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7648
7649 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7650
7651 /* Test recombine (Black Box) */
7652 /* SDU should not be allocated */
7653 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
7654
7655 /* SDU should not be written */
7656 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
7657
7658 /* SDU should not be emitted */
7659 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
7660
7661 /* Test recombine (White Box) */
7662 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7663 ISOAL_START,
7664 "FSM state %s should be %s!",
7665 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7666 FSM_TO_STR(ISOAL_START));
7667
7668 /* PDU 2 -------------------------------------------------------------*/
7669 /* Padding PDU */
7670 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7671
7672 payload_number++;
7673
7674 isoal_test_create_framed_pdu_base(payload_number,
7675 pdu_timestamp,
7676 ISOAL_PDU_STATUS_VALID,
7677 &rx_pdu_meta_buf.pdu_meta);
7678
7679 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7680
7681 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7682
7683 /* Test recombine (Black Box) */
7684 /* SDU should not be allocated */
7685 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
7686
7687 /* SDU should not be written */
7688 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
7689
7690 /* SDU should not be emitted */
7691 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
7692
7693 /* Test recombine (White Box) */
7694 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7695 ISOAL_START,
7696 "FSM state %s should be %s!",
7697 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7698 FSM_TO_STR(ISOAL_START));
7699
7700 /* SDU 0 -------------------------------------------------------------*/
7701 /* Missing */
7702
7703 /* SDU 1 -------------------------------------------------------------*/
7704 /* Missing */
7705 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
7706
7707 /* SDU 2 -------------------------------------------------------------*/
7708 /* Missing */
7709 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
7710
7711 /* PDU 3 -------------------------------------------------------------*/
7712 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7713
7714 payload_number++;
7715 pdu_timestamp += iso_interval_us;
7716
7717 testdata_indx = 0;
7718 testdata_size = testdata_size_max;
7719 sdu_size = testdata_size_max;
7720
7721 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true);
7722
7723 isoal_test_create_framed_pdu_base(payload_number,
7724 pdu_timestamp,
7725 ISOAL_PDU_STATUS_VALID,
7726 &rx_pdu_meta_buf.pdu_meta);
7727 pdu_data_loc = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
7728 (testdata_size - testdata_indx),
7729 sdu_timeoffset,
7730 &rx_pdu_meta_buf.pdu_meta);
7731
7732 /* Set callback function return values */
7733 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
7734 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
7735 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]);
7736 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[3]);
7737 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
7738 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
7739 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
7740
7741 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7742
7743 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7744
7745 /* SDU 0 -------------------------------------------------------------*/
7746 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
7747 collated_status =
7748 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
7749
7750 /* Test recombine (Black Box) */
7751 /* A new SDU should be allocated */
7752 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[0],
7753 &isoal_global.sink_state[sink_hdl], /* Sink */
7754 &rx_pdu_meta_buf.pdu_meta); /* PDU */
7755
7756 /* SDU payload should be written */
7757
7758 /* SDU should be emitted */
7759 ZASSERT_ISOAL_SDU_EMIT_TEST(history[0],
7760 &isoal_global.sink_state[sink_hdl], /* Sink */
7761 BT_ISO_SINGLE, /* Frag state */
7762 0, /* Frag size */
7763 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
7764 sdu_timestamp, /* Timestamp */
7765 seqn, /* Seq. number */
7766 sdu_buffer[0].dbuf, /* Buffer */
7767 sdu_buffer[0].size, /* Buffer size */
7768 total_sdu_size, /* Total size */
7769 collated_status); /* SDU status */
7770
7771 /* SDU 1 -------------------------------------------------------------*/
7772 seqn++;
7773 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
7774 collated_status =
7775 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
7776
7777 sdu_timestamp += sdu_interval;
7778 /* Test recombine (Black Box) */
7779 /* A new SDU should be allocated */
7780 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1],
7781 &isoal_global.sink_state[sink_hdl], /* Sink */
7782 &rx_pdu_meta_buf.pdu_meta); /* PDU */
7783
7784 /* SDU payload should be written */
7785
7786 /* SDU should be emitted */
7787 ZASSERT_ISOAL_SDU_EMIT_TEST(history[1],
7788 &isoal_global.sink_state[sink_hdl], /* Sink */
7789 BT_ISO_SINGLE, /* Frag state */
7790 0, /* Frag size */
7791 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
7792 sdu_timestamp, /* Timestamp */
7793 seqn, /* Seq. number */
7794 sdu_buffer[1].dbuf, /* Buffer */
7795 sdu_buffer[1].size, /* Buffer size */
7796 total_sdu_size, /* Total size */
7797 collated_status); /* SDU status */
7798
7799 /* SDU 2 -------------------------------------------------------------*/
7800 seqn++;
7801 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
7802 collated_status =
7803 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
7804
7805 sdu_timestamp += sdu_interval;
7806 /* Test recombine (Black Box) */
7807 /* A new SDU should be allocated */
7808 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2],
7809 &isoal_global.sink_state[sink_hdl], /* Sink */
7810 &rx_pdu_meta_buf.pdu_meta); /* PDU */
7811
7812 /* SDU payload should be written */
7813
7814 /* SDU should be emitted */
7815 ZASSERT_ISOAL_SDU_EMIT_TEST(history[2],
7816 &isoal_global.sink_state[sink_hdl], /* Sink */
7817 BT_ISO_SINGLE, /* Frag state */
7818 0, /* Frag size */
7819 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
7820 sdu_timestamp, /* Timestamp */
7821 seqn, /* Seq. number */
7822 sdu_buffer[2].dbuf, /* Buffer */
7823 sdu_buffer[2].size, /* Buffer size */
7824 total_sdu_size, /* Total size */
7825 collated_status); /* SDU status */
7826
7827 /* SDU 3 -------------------------------------------------------------*/
7828 seqn++;
7829 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
7830 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
7831
7832 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
7833 /* Test recombine (Black Box) */
7834 /* A new SDU should be allocated */
7835 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
7836 &isoal_global.sink_state[sink_hdl], /* Sink */
7837 &rx_pdu_meta_buf.pdu_meta); /* PDU */
7838
7839 /* SDU payload should be written */
7840 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
7841 &rx_sdu_frag_buf[3], /* SDU buffer */
7842 0, /* SDU written */
7843 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc],
7844 /* PDU payload */
7845 (testdata_size - testdata_indx)); /* Size */
7846
7847 /* SDU should be emitted */
7848 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
7849 &isoal_global.sink_state[sink_hdl], /* Sink */
7850 BT_ISO_SINGLE, /* Frag state */
7851 sdu_size, /* Frag size */
7852 ISOAL_SDU_STATUS_VALID, /* Frag status */
7853 sdu_timestamp, /* Timestamp */
7854 seqn, /* Seq. number */
7855 sdu_buffer[3].dbuf, /* Buffer */
7856 sdu_buffer[3].size, /* Buffer size */
7857 total_sdu_size, /* Total size */
7858 collated_status); /* SDU status */
7859
7860 /* Test recombine (White Box) */
7861 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
7862 ISOAL_START,
7863 "FSM state %s should be %s!",
7864 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
7865 FSM_TO_STR(ISOAL_START));
7866 }
7867
7868 /**
7869 * Test Suite : RX framed PDU recombination
7870 *
7871 * Tests release of SDUs when receiving only padding PDUs
7872 *
7873 * Expected Sequence:
7874 * -- Total of 3 SDUs released across 2 events
7875 * -- Event 1: PDU0 Valid Framed Padding
7876 * PDU1 Valid Framed Padding
7877 * PDU2 Valid Framed Padding
7878 * Event 2: PDU3 Errors SDU 3 Framed Single
7879 * -----> SDU 0 Lost (Released)
7880 * -----> SDU 1 Lost (Released)
7881 * -----> SDU 2 Lost (Released)
7882 * -----> SDU 3 Bit Errors (Released)
7883 * PDU4 N/A
7884 * PDU5 N/A
7885 *
7886 */
ZTEST(test_rx_framed,test_rx_framed_padding_only_pdu_err)7887 ZTEST(test_rx_framed, test_rx_framed_padding_only_pdu_err)
7888 {
7889 const uint8_t number_of_pdus = 3;
7890 const uint8_t testdata_size_max = 20;
7891
7892 struct rx_sdu_frag_buffer rx_sdu_frag_buf[3];
7893 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
7894 struct isoal_sdu_buffer sdu_buffer[4];
7895 isoal_sdu_status_t collated_status;
7896 isoal_sink_handle_t sink_hdl;
7897 uint32_t stream_sync_delay;
7898 uint32_t group_sync_delay;
7899 isoal_sdu_len_t sdu_size;
7900 uint8_t iso_interval_int;
7901 uint32_t iso_interval_us;
7902 uint64_t payload_number;
7903 uint16_t total_sdu_size;
7904 uint32_t sdu_timeoffset;
7905 uint32_t pdu_timestamp;
7906 uint32_t sdu_timestamp;
7907 uint16_t testdata_indx;
7908 uint16_t testdata_size;
7909 uint16_t pdu_data_loc;
7910 uint32_t sdu_interval;
7911 isoal_sdu_cnt_t seqn;
7912 uint8_t testdata[testdata_size_max];
7913 isoal_status_t err;
7914 uint32_t latency;
7915 uint8_t role;
7916 uint8_t BN;
7917 uint8_t FT;
7918
7919 /* Settings */
7920 role = BT_CONN_ROLE_PERIPHERAL;
7921 iso_interval_int = 1;
7922 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
7923 sdu_interval = (iso_interval_us / number_of_pdus) + 5;
7924 BN = 3;
7925 FT = 1;
7926 stream_sync_delay = iso_interval_us - 200;
7927 group_sync_delay = iso_interval_us - 50;
7928
7929 /* PDU 0 -------------------------------------------------------------*/
7930 /* Padding PDU */
7931 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
7932 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
7933 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
7934 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]);
7935 init_test_data_buffer(testdata, testdata_size_max);
7936 pdu_data_loc = 0;
7937
7938 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
7939 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
7940 sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2];
7941 sdu_buffer[3].dbuf = &rx_sdu_frag_buf[2];
7942 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7943 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7944 sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7945 sdu_buffer[3].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
7946 payload_number = 1000 * BN;
7947 pdu_timestamp = 9249;
7948 latency = calc_rx_latency_by_role(role,
7949 true,
7950 FT,
7951 sdu_interval,
7952 iso_interval_int,
7953 stream_sync_delay,
7954 group_sync_delay);
7955 sdu_timeoffset = group_sync_delay - 50;
7956 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us);
7957 seqn = 0;
7958 testdata_indx = testdata_size = 0;
7959 sdu_size = 0;
7960 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
7961 collated_status =
7962 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
7963
7964 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
7965 role, /* Role */
7966 true, /* Framed */
7967 BN, /* BN */
7968 FT, /* FT */
7969 sdu_interval, /* SDU Interval */
7970 iso_interval_int, /* ISO Interval */
7971 stream_sync_delay, /* Stream Sync Delay */
7972 group_sync_delay); /* Group Sync Delay */
7973
7974 isoal_test_create_framed_pdu_base(payload_number,
7975 pdu_timestamp,
7976 ISOAL_PDU_STATUS_VALID,
7977 &rx_pdu_meta_buf.pdu_meta);
7978
7979 /* Set callback function return values */
7980 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
7981 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
7982 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
7983
7984 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
7985
7986 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
7987
7988 /* Test recombine (Black Box) */
7989 /* A new SDU should not be allocated */
7990 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
7991
7992 /* SDU payload should not be written */
7993 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
7994
7995 /* SDU payload should not be emitted */
7996 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
7997
7998 /* Test recombine (White Box) */
7999 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8000 ISOAL_START,
8001 "FSM state %s should be %s!",
8002 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8003 FSM_TO_STR(ISOAL_START));
8004
8005 /* PDU 1 -------------------------------------------------------------*/
8006 /* Padding PDU */
8007 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8008
8009 payload_number++;
8010
8011 isoal_test_create_framed_pdu_base(payload_number,
8012 pdu_timestamp,
8013 ISOAL_PDU_STATUS_VALID,
8014 &rx_pdu_meta_buf.pdu_meta);
8015
8016 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8017
8018 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8019
8020 /* Test recombine (Black Box) */
8021 /* SDU should not be allocated */
8022 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
8023
8024 /* SDU should not be written */
8025 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
8026
8027 /* SDU should not be emitted */
8028 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
8029
8030 /* Test recombine (White Box) */
8031 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8032 ISOAL_START,
8033 "FSM state %s should be %s!",
8034 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8035 FSM_TO_STR(ISOAL_START));
8036
8037 /* PDU 2 -------------------------------------------------------------*/
8038 /* Padding PDU */
8039 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8040
8041 payload_number++;
8042
8043 isoal_test_create_framed_pdu_base(payload_number,
8044 pdu_timestamp,
8045 ISOAL_PDU_STATUS_VALID,
8046 &rx_pdu_meta_buf.pdu_meta);
8047
8048 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8049
8050 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8051
8052 /* Test recombine (Black Box) */
8053 /* SDU should not be allocated */
8054 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
8055
8056 /* SDU should not be written */
8057 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
8058
8059 /* SDU should not be emitted */
8060 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
8061
8062 /* Test recombine (White Box) */
8063 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8064 ISOAL_START,
8065 "FSM state %s should be %s!",
8066 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8067 FSM_TO_STR(ISOAL_START));
8068
8069 /* SDU 0 -------------------------------------------------------------*/
8070 /* Missing */
8071
8072 /* SDU 1 -------------------------------------------------------------*/
8073 /* Missing */
8074 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
8075
8076 /* SDU 2 -------------------------------------------------------------*/
8077 /* Missing */
8078 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
8079
8080 /* PDU 3 -------------------------------------------------------------*/
8081 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8082
8083 payload_number++;
8084 pdu_timestamp += iso_interval_us;
8085
8086 testdata_indx = 0;
8087 testdata_size = testdata_size_max;
8088 sdu_size = testdata_size_max;
8089
8090 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true);
8091
8092 isoal_test_create_framed_pdu_base(payload_number,
8093 pdu_timestamp,
8094 ISOAL_PDU_STATUS_ERRORS,
8095 &rx_pdu_meta_buf.pdu_meta);
8096 pdu_data_loc = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
8097 (testdata_size - testdata_indx),
8098 sdu_timeoffset,
8099 &rx_pdu_meta_buf.pdu_meta);
8100
8101 /* Set callback function return values */
8102 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
8103 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
8104 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]);
8105 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[3]);
8106 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
8107 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
8108 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
8109
8110 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8111
8112 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8113
8114 /* SDU 0 -------------------------------------------------------------*/
8115 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
8116 collated_status =
8117 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
8118
8119 /* Test recombine (Black Box) */
8120 /* A new SDU should be allocated */
8121 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[0],
8122 &isoal_global.sink_state[sink_hdl], /* Sink */
8123 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8124
8125 /* SDU payload should be written */
8126
8127 /* SDU should be emitted */
8128 ZASSERT_ISOAL_SDU_EMIT_TEST(history[0],
8129 &isoal_global.sink_state[sink_hdl], /* Sink */
8130 BT_ISO_SINGLE, /* Frag state */
8131 0, /* Frag size */
8132 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
8133 sdu_timestamp, /* Timestamp */
8134 seqn, /* Seq. number */
8135 sdu_buffer[0].dbuf, /* Buffer */
8136 sdu_buffer[0].size, /* Buffer size */
8137 total_sdu_size, /* Total size */
8138 collated_status); /* SDU status */
8139
8140 /* SDU 1 -------------------------------------------------------------*/
8141 seqn++;
8142 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
8143 collated_status =
8144 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
8145
8146 sdu_timestamp += sdu_interval;
8147 /* Test recombine (Black Box) */
8148 /* A new SDU should be allocated */
8149 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1],
8150 &isoal_global.sink_state[sink_hdl], /* Sink */
8151 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8152
8153 /* SDU payload should be written */
8154
8155 /* SDU should be emitted */
8156 ZASSERT_ISOAL_SDU_EMIT_TEST(history[1],
8157 &isoal_global.sink_state[sink_hdl], /* Sink */
8158 BT_ISO_SINGLE, /* Frag state */
8159 0, /* Frag size */
8160 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
8161 sdu_timestamp, /* Timestamp */
8162 seqn, /* Seq. number */
8163 sdu_buffer[1].dbuf, /* Buffer */
8164 sdu_buffer[1].size, /* Buffer size */
8165 total_sdu_size, /* Total size */
8166 collated_status); /* SDU status */
8167
8168 /* SDU 2 -------------------------------------------------------------*/
8169 seqn++;
8170 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
8171 collated_status =
8172 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
8173
8174 sdu_timestamp += sdu_interval;
8175 /* Test recombine (Black Box) */
8176 /* A new SDU should be allocated */
8177 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2],
8178 &isoal_global.sink_state[sink_hdl], /* Sink */
8179 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8180
8181 /* SDU payload should be written */
8182
8183 /* SDU should be emitted */
8184 ZASSERT_ISOAL_SDU_EMIT_TEST(history[2],
8185 &isoal_global.sink_state[sink_hdl], /* Sink */
8186 BT_ISO_SINGLE, /* Frag state */
8187 0, /* Frag size */
8188 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
8189 sdu_timestamp, /* Timestamp */
8190 seqn, /* Seq. number */
8191 sdu_buffer[2].dbuf, /* Buffer */
8192 sdu_buffer[2].size, /* Buffer size */
8193 total_sdu_size, /* Total size */
8194 collated_status); /* SDU status */
8195
8196
8197 /* SDU 3 -------------------------------------------------------------*/
8198 seqn++;
8199 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
8200 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
8201
8202 sdu_timestamp += sdu_interval;
8203 /* Test recombine (Black Box) */
8204 /* A new SDU should be allocated */
8205 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
8206 &isoal_global.sink_state[sink_hdl], /* Sink */
8207 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8208
8209 /* SDU payload should be written */
8210
8211 /* SDU should be emitted */
8212 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
8213 &isoal_global.sink_state[sink_hdl], /* Sink */
8214 BT_ISO_SINGLE, /* Frag state */
8215 0, /* Frag size */
8216 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
8217 sdu_timestamp, /* Timestamp */
8218 seqn, /* Seq. number */
8219 sdu_buffer[3].dbuf, /* Buffer */
8220 sdu_buffer[3].size, /* Buffer size */
8221 total_sdu_size, /* Total size */
8222 collated_status); /* SDU status */
8223
8224 /* Test recombine (White Box) */
8225 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8226 ISOAL_ERR_SPOOL,
8227 "FSM state %s should be %s!",
8228 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8229 FSM_TO_STR(ISOAL_START));
8230 }
8231
8232 /**
8233 * Test Suite : RX framed PDU recombination
8234 *
8235 * Tests recombination of a single SDU from a single segmented PDU with errors,
8236 * followed by a valid PDU
8237 */
ZTEST(test_rx_framed,test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1)8238 ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1)
8239 {
8240 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
8241 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
8242 struct isoal_sdu_buffer sdu_buffer;
8243 isoal_sdu_status_t collated_status;
8244 isoal_sink_handle_t sink_hdl;
8245 uint32_t stream_sync_delay;
8246 uint32_t group_sync_delay;
8247 isoal_sdu_len_t sdu_size;
8248 uint8_t iso_interval_int;
8249 uint16_t pdu_data_loc[5];
8250 uint32_t iso_interval_us;
8251 uint64_t payload_number;
8252 uint16_t total_sdu_size;
8253 uint32_t sdu_timeoffset;
8254 uint32_t pdu_timestamp;
8255 uint32_t sdu_timestamp;
8256 uint16_t testdata_indx;
8257 uint16_t testdata_size;
8258 uint32_t sdu_interval;
8259 isoal_sdu_cnt_t seqn;
8260 uint8_t testdata[33];
8261 isoal_status_t err;
8262 uint32_t latency;
8263 uint8_t role;
8264 uint8_t BN;
8265 uint8_t FT;
8266
8267 /* Settings */
8268 role = ISOAL_ROLE_PERIPHERAL;
8269 iso_interval_int = 1;
8270 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
8271 sdu_interval = (iso_interval_us / 3) + 5;
8272 BN = 3;
8273 FT = 1;
8274 stream_sync_delay = iso_interval_us - 200;
8275 group_sync_delay = iso_interval_us - 50;
8276
8277 /* PDU 1 -------------------------------------------------------------*/
8278 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8279 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
8280 init_test_data_buffer(testdata, 33);
8281 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
8282
8283 sdu_buffer.dbuf = &rx_sdu_frag_buf;
8284 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
8285 payload_number = 1000 * BN;
8286 pdu_timestamp = 9249;
8287 latency = calc_rx_latency_by_role(role,
8288 true,
8289 FT,
8290 sdu_interval,
8291 iso_interval_int,
8292 stream_sync_delay,
8293 group_sync_delay);
8294 sdu_timeoffset = group_sync_delay - 50;
8295 /* PDU will have errors. Time stamp is only an approximation */
8296 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us);
8297 seqn = 0;
8298 testdata_indx = 0;
8299 testdata_size = 23;
8300 sdu_size = 0;
8301 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
8302 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
8303
8304 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
8305 role, /* Role */
8306 true, /* Framed */
8307 BN, /* BN */
8308 FT, /* FT */
8309 sdu_interval, /* SDU Interval */
8310 iso_interval_int, /* ISO Interval */
8311 stream_sync_delay, /* Stream Sync Delay */
8312 group_sync_delay); /* Group Sync Delay */
8313
8314 /* PDU with errors */
8315 isoal_test_create_framed_pdu_base(payload_number,
8316 pdu_timestamp,
8317 ISOAL_PDU_STATUS_ERRORS,
8318 &rx_pdu_meta_buf.pdu_meta);
8319 pdu_data_loc[0] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
8320 (testdata_size - testdata_indx),
8321 sdu_timeoffset,
8322 &rx_pdu_meta_buf.pdu_meta);
8323
8324 /* Set callback function return values */
8325 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
8326 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
8327 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
8328
8329 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8330
8331 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8332
8333 /* Test recombine (Black Box) */
8334 /* A new SDU should be allocated */
8335 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
8336 &isoal_global.sink_state[sink_hdl], /* Sink */
8337 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8338
8339 /* SDU payload should not be written */
8340
8341 /* SDU should be emitted */
8342 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
8343 &isoal_global.sink_state[sink_hdl], /* Sink */
8344 BT_ISO_SINGLE, /* Frag state */
8345 sdu_size, /* Frag size */
8346 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
8347 sdu_timestamp, /* Timestamp */
8348 seqn, /* Seq. number */
8349 sdu_buffer.dbuf, /* Buffer */
8350 sdu_buffer.size, /* Buffer size */
8351 total_sdu_size, /* Total size */
8352 collated_status); /* SDU status */
8353
8354 /* Test recombine (White Box) */
8355 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8356 ISOAL_ERR_SPOOL,
8357 "FSM state %s should be %s!",
8358 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8359 FSM_TO_STR(ISOAL_ERR_SPOOL));
8360
8361 /* PDU 2 -------------------------------------------------------------*/
8362 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8363 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
8364
8365 payload_number++;
8366
8367 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
8368 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
8369 seqn++;
8370 testdata_indx = testdata_size;
8371 testdata_size += 10;
8372 sdu_size = 10;
8373 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
8374 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
8375
8376 isoal_test_create_framed_pdu_base(payload_number,
8377 pdu_timestamp,
8378 ISOAL_PDU_STATUS_VALID,
8379 &rx_pdu_meta_buf.pdu_meta);
8380 pdu_data_loc[1] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
8381 (testdata_size - testdata_indx),
8382 sdu_timeoffset,
8383 &rx_pdu_meta_buf.pdu_meta);
8384
8385 /* Set callback function return values */
8386 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
8387 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
8388 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
8389 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
8390
8391 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8392
8393 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8394
8395 /* Test recombine (Black Box) */
8396 /* A new SDU should be allocated */
8397 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
8398 &isoal_global.sink_state[sink_hdl], /* Sink */
8399 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8400
8401 /* SDU payload should be written */
8402 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
8403 &rx_sdu_frag_buf, /* SDU buffer */
8404 0, /* SDU written */
8405 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
8406 /* PDU payload */
8407 (testdata_size - testdata_indx)); /* Size */
8408
8409 /* SDU should be emitted */
8410 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
8411 &isoal_global.sink_state[sink_hdl], /* Sink */
8412 BT_ISO_SINGLE, /* Frag state */
8413 sdu_size, /* Frag size */
8414 ISOAL_SDU_STATUS_VALID, /* Frag status */
8415 sdu_timestamp, /* Timestamp */
8416 seqn, /* Seq. number */
8417 sdu_buffer.dbuf, /* Buffer */
8418 sdu_buffer.size, /* Buffer size */
8419 total_sdu_size, /* Total size */
8420 collated_status); /* SDU status */
8421
8422 /* Test recombine (White Box) */
8423 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8424 ISOAL_START,
8425 "FSM state %s should be %s!",
8426 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8427 FSM_TO_STR(ISOAL_START));
8428 }
8429
8430 /**
8431 * Test Suite : RX framed PDU recombination
8432 *
8433 * Tests recombination of a single SDU from a single segmented PDU with errors,
8434 * followed by a valid PDU
8435 */
ZTEST(test_rx_framed,test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2)8436 ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2)
8437 {
8438 const uint8_t test_data_size = 33;
8439 const uint8_t max_sdu_burst = 2;
8440
8441 struct rx_sdu_frag_buffer rx_sdu_frag_buf[max_sdu_burst];
8442 struct isoal_sdu_buffer sdu_buffer[max_sdu_burst];
8443 isoal_sdu_status_t collated_status[max_sdu_burst];
8444 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
8445 isoal_sdu_len_t sdu_size[max_sdu_burst];
8446 uint16_t total_sdu_size[max_sdu_burst];
8447 uint32_t sdu_timestamp[max_sdu_burst];
8448 uint8_t testdata[test_data_size];
8449 isoal_sink_handle_t sink_hdl;
8450 uint32_t stream_sync_delay;
8451 uint32_t group_sync_delay;
8452 uint8_t iso_interval_int;
8453 uint16_t pdu_data_loc[5];
8454 uint32_t iso_interval_us;
8455 uint64_t payload_number;
8456 uint32_t sdu_timeoffset;
8457 uint32_t pdu_timestamp;
8458 uint16_t testdata_indx;
8459 uint16_t testdata_size;
8460 uint32_t sdu_interval;
8461 isoal_sdu_cnt_t seqn;
8462 isoal_status_t err;
8463 uint32_t latency;
8464 uint8_t role;
8465 uint8_t BN;
8466 uint8_t FT;
8467
8468 /* Settings */
8469 role = ISOAL_ROLE_PERIPHERAL;
8470 iso_interval_int = 1;
8471 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
8472 sdu_interval = (iso_interval_us / 3) + 5;
8473 BN = 3;
8474 FT = 1;
8475 stream_sync_delay = iso_interval_us - 200;
8476 group_sync_delay = iso_interval_us - 50;
8477
8478 /* PDU 1 -------------------------------------------------------------*/
8479 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8480 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
8481 init_test_data_buffer(testdata, test_data_size);
8482 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
8483
8484 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
8485 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
8486 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
8487 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
8488 payload_number = 1000 * BN;
8489 pdu_timestamp = 9249;
8490 latency = calc_rx_latency_by_role(role,
8491 true,
8492 FT,
8493 sdu_interval,
8494 iso_interval_int,
8495 stream_sync_delay,
8496 group_sync_delay);
8497 sdu_timeoffset = group_sync_delay - 50;
8498 /* PDU will have errors. Time stamp is only an approximation */
8499 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us);
8500 seqn = 0;
8501 testdata_indx = 0;
8502 testdata_size = 23;
8503 sdu_size[0] = 0;
8504 total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
8505 collated_status[0] =
8506 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
8507
8508 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
8509 role, /* Role */
8510 true, /* Framed */
8511 BN, /* BN */
8512 FT, /* FT */
8513 sdu_interval, /* SDU Interval */
8514 iso_interval_int, /* ISO Interval */
8515 stream_sync_delay, /* Stream Sync Delay */
8516 group_sync_delay); /* Group Sync Delay */
8517
8518 /* PDU with errors */
8519 isoal_test_create_framed_pdu_base(payload_number,
8520 pdu_timestamp,
8521 ISOAL_PDU_STATUS_LOST_DATA,
8522 &rx_pdu_meta_buf.pdu_meta);
8523 pdu_data_loc[0] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
8524 (testdata_size - testdata_indx),
8525 sdu_timeoffset,
8526 &rx_pdu_meta_buf.pdu_meta);
8527
8528 /* Set callback function return values */
8529 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
8530 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
8531 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
8532 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
8533
8534 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8535
8536 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8537
8538 /* Test recombine (Black Box) */
8539 /* A new SDU should not be allocated */
8540 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0);
8541
8542 /* SDU payload should not be written */
8543 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
8544
8545 /* SDU should not be emitted */
8546 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
8547
8548 /* Test recombine (White Box) */
8549 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8550 ISOAL_ERR_SPOOL,
8551 "FSM state %s should be %s!",
8552 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8553 FSM_TO_STR(ISOAL_ERR_SPOOL));
8554
8555 /* PDU 2 -------------------------------------------------------------*/
8556 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8557 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
8558
8559 payload_number++;
8560
8561 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
8562 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
8563 testdata_indx = testdata_size;
8564 testdata_size += 10;
8565 sdu_size[1] = 10;
8566 total_sdu_size[1] = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]);
8567 collated_status[1] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
8568
8569 isoal_test_create_framed_pdu_base(payload_number,
8570 pdu_timestamp,
8571 ISOAL_PDU_STATUS_VALID,
8572 &rx_pdu_meta_buf.pdu_meta);
8573 pdu_data_loc[1] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
8574 (testdata_size - testdata_indx),
8575 sdu_timeoffset,
8576 &rx_pdu_meta_buf.pdu_meta);
8577
8578 /* Set callback function return values */
8579 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
8580 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
8581 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
8582 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
8583
8584 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8585
8586 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8587
8588 /* Test recombine (Black Box) */
8589 /* SDU 0 -------------------------------------------------------------*/
8590 /* A new SDU should be allocated */
8591 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[0],
8592 &isoal_global.sink_state[sink_hdl], /* Sink */
8593 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8594
8595 /* SDU payload should not be written */
8596
8597 /* SDU should be emitted */
8598 ZASSERT_ISOAL_SDU_EMIT_TEST(history[0],
8599 &isoal_global.sink_state[sink_hdl], /* Sink */
8600 BT_ISO_SINGLE, /* Frag state */
8601 sdu_size[0], /* Frag size */
8602 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
8603 sdu_timestamp[0], /* Timestamp */
8604 seqn, /* Seq. number */
8605 sdu_buffer[0].dbuf, /* Buffer */
8606 sdu_buffer[0].size, /* Buffer size */
8607 total_sdu_size[0], /* Total size */
8608 collated_status[0]); /* SDU status */
8609
8610 /* SDU 1 -------------------------------------------------------------*/
8611 seqn++;
8612 /* A new SDU should be allocated */
8613 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
8614 &isoal_global.sink_state[sink_hdl], /* Sink */
8615 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8616
8617 /* SDU payload should be written */
8618 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1);
8619 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
8620 &rx_sdu_frag_buf[1], /* SDU buffer */
8621 0, /* SDU written */
8622 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
8623 /* PDU payload */
8624 (testdata_size - testdata_indx)); /* Size */
8625
8626 /* SDU should be emitted */
8627 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
8628 &isoal_global.sink_state[sink_hdl], /* Sink */
8629 BT_ISO_SINGLE, /* Frag state */
8630 sdu_size[1], /* Frag size */
8631 ISOAL_SDU_STATUS_VALID, /* Frag status */
8632 sdu_timestamp[1], /* Timestamp */
8633 seqn, /* Seq. number */
8634 sdu_buffer[1].dbuf, /* Buffer */
8635 sdu_buffer[1].size, /* Buffer size */
8636 total_sdu_size[1], /* Total size */
8637 collated_status[1]); /* SDU status */
8638
8639 /* Test recombine (White Box) */
8640 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8641 ISOAL_START,
8642 "FSM state %s should be %s!",
8643 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8644 FSM_TO_STR(ISOAL_START));
8645 }
8646
8647 /**
8648 * Test Suite : RX framed PDU recombination
8649 *
8650 * Tests recombination of a single SDU from a single segmented PDU with errors,
8651 * mainly focussing on the release of SDUs buffered before the PDU with errors
8652 * was received. The first PDU triggers a release of a filled SDU and the
8653 * reception of the second PDU is expected to trigger allocation and release of
8654 * a new SDU to indicate the error and the status information should be collated
8655 * accordingly.
8656 */
ZTEST(test_rx_framed,test_rx_framed_dbl_pdu_dbl_sdu_pdu_err3)8657 ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err3)
8658 {
8659 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
8660 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
8661 struct isoal_sdu_buffer sdu_buffer;
8662 isoal_sdu_status_t collated_status;
8663 isoal_sink_handle_t sink_hdl;
8664 uint32_t stream_sync_delay;
8665 uint32_t group_sync_delay;
8666 isoal_sdu_len_t sdu_size;
8667 uint8_t iso_interval_int;
8668 uint16_t pdu_data_loc[5];
8669 uint64_t payload_number;
8670 uint16_t total_sdu_size;
8671 uint32_t sdu_timeoffset;
8672 uint32_t pdu_timestamp;
8673 uint32_t sdu_timestamp;
8674 uint16_t testdata_indx;
8675 uint16_t testdata_size;
8676 uint32_t sdu_interval;
8677 isoal_sdu_cnt_t seqn;
8678 uint8_t testdata[50];
8679 isoal_status_t err;
8680 uint32_t latency;
8681 uint8_t role;
8682 uint8_t BN;
8683 uint8_t FT;
8684
8685 /* Settings */
8686 role = ISOAL_ROLE_PERIPHERAL;
8687 iso_interval_int = 1;
8688 sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5;
8689 BN = 3;
8690 FT = 1;
8691 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
8692 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
8693
8694 /* PDU 1 -------------------------------------------------------------*/
8695 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8696 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
8697 init_test_data_buffer(testdata, 50);
8698 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
8699
8700 sdu_buffer.dbuf = &rx_sdu_frag_buf;
8701 sdu_buffer.size = 35;
8702 payload_number = 1000 * BN;
8703 pdu_timestamp = 9249;
8704 latency = calc_rx_latency_by_role(role,
8705 true,
8706 FT,
8707 sdu_interval,
8708 iso_interval_int,
8709 stream_sync_delay,
8710 group_sync_delay);
8711 sdu_timeoffset = group_sync_delay - 50;
8712 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
8713 seqn = 0;
8714 testdata_indx = 0;
8715 testdata_size = 35;
8716 sdu_size = 35;
8717 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 35);
8718 collated_status = COLLATED_RX_SDU_INFO(ISOAL_PDU_STATUS_VALID, ISOAL_SDU_STATUS_LOST_DATA);
8719
8720 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
8721 role, /* Role */
8722 true, /* Framed */
8723 BN, /* BN */
8724 FT, /* FT */
8725 sdu_interval, /* SDU Interval */
8726 iso_interval_int, /* ISO Interval */
8727 stream_sync_delay, /* Stream Sync Delay */
8728 group_sync_delay); /* Group Sync Delay */
8729
8730 /* PDU with errors */
8731 isoal_test_create_framed_pdu_base(payload_number,
8732 pdu_timestamp,
8733 ISOAL_PDU_STATUS_VALID,
8734 &rx_pdu_meta_buf.pdu_meta);
8735 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
8736 (testdata_size - testdata_indx),
8737 sdu_timeoffset,
8738 &rx_pdu_meta_buf.pdu_meta);
8739
8740 /* Set callback function return values */
8741 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
8742 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
8743 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
8744 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
8745
8746 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8747
8748 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8749
8750 /* Test recombine (Black Box) */
8751 /* A new SDU should be allocated */
8752 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
8753 &isoal_global.sink_state[sink_hdl], /* Sink */
8754 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8755
8756 /* SDU payload should be written */
8757 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
8758 &rx_sdu_frag_buf, /* SDU buffer */
8759 0, /* SDU written */
8760 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
8761 /* PDU payload */
8762 (testdata_size - testdata_indx)); /* Size */
8763
8764 /* SDU should be emitted */
8765 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
8766 &isoal_global.sink_state[sink_hdl], /* Sink */
8767 BT_ISO_START, /* Frag state */
8768 sdu_size, /* Frag size */
8769 ISOAL_SDU_STATUS_VALID, /* Frag status */
8770 sdu_timestamp, /* Timestamp */
8771 seqn, /* Seq. number */
8772 sdu_buffer.dbuf, /* Buffer */
8773 sdu_buffer.size, /* Buffer size */
8774 total_sdu_size, /* Total size */
8775 collated_status); /* SDU status */
8776
8777 /* Test recombine (White Box) */
8778 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8779 ISOAL_CONTINUE,
8780 "FSM state %s should be %s!",
8781 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8782 FSM_TO_STR(ISOAL_CONTINUE));
8783
8784 /* PDU 2 -------------------------------------------------------------*/
8785 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8786
8787 payload_number++;
8788
8789 testdata_indx = testdata_size;
8790 testdata_size += 15;
8791 sdu_size = 0;
8792 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 35);
8793 collated_status =
8794 COLLATED_RX_SDU_INFO(ISOAL_PDU_STATUS_LOST_DATA, ISOAL_PDU_STATUS_LOST_DATA);
8795
8796 isoal_test_create_framed_pdu_base(payload_number,
8797 pdu_timestamp,
8798 ISOAL_PDU_STATUS_LOST_DATA,
8799 &rx_pdu_meta_buf.pdu_meta);
8800 pdu_data_loc[1] = isoal_test_add_framed_pdu_cont(&testdata[testdata_indx],
8801 (testdata_size - testdata_indx),
8802 &rx_pdu_meta_buf.pdu_meta);
8803
8804 /* Set callback function return values */
8805 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
8806 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
8807 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
8808 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
8809
8810 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8811
8812 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8813
8814 /* Test recombine (Black Box) */
8815 /* A new SDU should be allocated */
8816 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
8817 &isoal_global.sink_state[sink_hdl], /* Sink */
8818 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8819
8820 /* SDU payload should not be written */
8821
8822 /* SDU should be emitted */
8823 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
8824 &isoal_global.sink_state[sink_hdl], /* Sink */
8825 BT_ISO_END, /* Frag state */
8826 sdu_size, /* Frag size */
8827 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
8828 sdu_timestamp, /* Timestamp */
8829 seqn, /* Seq. number */
8830 sdu_buffer.dbuf, /* Buffer */
8831 sdu_buffer.size, /* Buffer size */
8832 total_sdu_size, /* Total size */
8833 collated_status); /* SDU status */
8834
8835 /* Test recombine (White Box) */
8836 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8837 ISOAL_ERR_SPOOL,
8838 "FSM state %s should be %s!",
8839 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8840 FSM_TO_STR(ISOAL_ERR_SPOOL));
8841 }
8842
8843 /**
8844 * Test Suite : RX framed PDU recombination
8845 *
8846 * Tests recombination of a single SDU from a single segmented PDU with errors,
8847 * followed by a valid PDU
8848 */
ZTEST(test_rx_framed,test_rx_framed_dbl_pdu_dbl_sdu_seq_err1)8849 ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1)
8850 {
8851 struct rx_sdu_frag_buffer rx_sdu_frag_buf[2];
8852 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
8853 struct isoal_sdu_buffer sdu_buffer[2];
8854 isoal_sdu_status_t collated_status[2];
8855 isoal_sink_handle_t sink_hdl;
8856 isoal_sdu_len_t sdu_size[2];
8857 uint16_t total_sdu_size[2];
8858 uint32_t stream_sync_delay;
8859 uint32_t group_sync_delay;
8860 uint32_t sdu_timestamp[2];
8861 uint8_t iso_interval_int;
8862 uint16_t pdu_data_loc[5];
8863 uint32_t iso_interval_us;
8864 uint64_t payload_number;
8865 uint32_t sdu_timeoffset;
8866 uint32_t pdu_timestamp;
8867 uint16_t testdata_indx;
8868 uint16_t testdata_size;
8869 uint32_t sdu_interval;
8870 isoal_sdu_cnt_t seqn;
8871 uint8_t testdata[33];
8872 isoal_status_t err;
8873 uint32_t latency;
8874 uint8_t role;
8875 uint8_t BN;
8876 uint8_t FT;
8877
8878 /* Settings */
8879 role = ISOAL_ROLE_PERIPHERAL;
8880 iso_interval_int = 1;
8881 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
8882 sdu_interval = (iso_interval_us / 3) + 5;
8883 BN = 3;
8884 FT = 1;
8885 stream_sync_delay = iso_interval_us - 200;
8886 group_sync_delay = iso_interval_us - 50;
8887
8888 /* PDU 0 -------------------------------------------------------------*/
8889 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8890 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
8891 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
8892 init_test_data_buffer(testdata, 33);
8893 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
8894
8895 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
8896 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
8897 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
8898 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
8899 payload_number = 1000 * BN;
8900 pdu_timestamp = 9249;
8901 latency = calc_rx_latency_by_role(role,
8902 true,
8903 FT,
8904 sdu_interval,
8905 iso_interval_int,
8906 stream_sync_delay,
8907 group_sync_delay);
8908 sdu_timeoffset = group_sync_delay - 50;
8909 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
8910 seqn = 0;
8911 testdata_indx = 0;
8912 testdata_size = 13;
8913 sdu_size[0] = 13;
8914 total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
8915 collated_status[0] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
8916
8917 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
8918 role, /* Role */
8919 true, /* Framed */
8920 BN, /* BN */
8921 FT, /* FT */
8922 sdu_interval, /* SDU Interval */
8923 iso_interval_int, /* ISO Interval */
8924 stream_sync_delay, /* Stream Sync Delay */
8925 group_sync_delay); /* Group Sync Delay */
8926
8927 isoal_test_create_framed_pdu_base(payload_number,
8928 pdu_timestamp,
8929 ISOAL_PDU_STATUS_VALID,
8930 &rx_pdu_meta_buf.pdu_meta);
8931 pdu_data_loc[0] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
8932 (testdata_size - testdata_indx),
8933 sdu_timeoffset,
8934 &rx_pdu_meta_buf.pdu_meta);
8935
8936 /* Set callback function return values */
8937 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
8938 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
8939 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
8940 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
8941
8942 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
8943
8944 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
8945
8946 /* Test recombine (Black Box) */
8947 /* A new SDU should be allocated */
8948 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
8949 &isoal_global.sink_state[sink_hdl], /* Sink */
8950 &rx_pdu_meta_buf.pdu_meta); /* PDU */
8951
8952 /* SDU payload should be written */
8953 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
8954 &rx_sdu_frag_buf[0], /* SDU buffer */
8955 0, /* SDU written */
8956 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
8957 /* PDU payload */
8958 (testdata_size - testdata_indx)); /* Size */
8959
8960 /* SDU should be emitted */
8961 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
8962 &isoal_global.sink_state[sink_hdl], /* Sink */
8963 BT_ISO_SINGLE, /* Frag state */
8964 sdu_size[0], /* Frag size */
8965 ISOAL_SDU_STATUS_VALID, /* Frag status */
8966 sdu_timestamp[0], /* Timestamp */
8967 seqn, /* Seq. number */
8968 sdu_buffer[0].dbuf, /* Buffer */
8969 sdu_buffer[0].size, /* Buffer size */
8970 total_sdu_size[0], /* Total size */
8971 collated_status[0]); /* SDU status */
8972
8973 /* Test recombine (White Box) */
8974 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
8975 ISOAL_START,
8976 "FSM state %s should be %s!",
8977 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
8978 FSM_TO_STR(ISOAL_START));
8979
8980 /* PDU 1 -------------------------------------------------------------*/
8981 /* Not transferred to the ISO-AL */
8982 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8983 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
8984
8985 payload_number++;
8986
8987 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
8988 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
8989
8990 testdata_indx = testdata_size;
8991 testdata_size += 10;
8992 sdu_size[0] = 0;
8993 total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
8994 collated_status[0] =
8995 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
8996
8997 /* PDU 2 -------------------------------------------------------------*/
8998 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
8999 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
9000
9001 payload_number++;
9002
9003 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
9004 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
9005 testdata_indx = testdata_size;
9006 testdata_size += 10;
9007 sdu_size[1] = 10;
9008 total_sdu_size[1] = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]);
9009 collated_status[1] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
9010
9011 isoal_test_create_framed_pdu_base(payload_number,
9012 pdu_timestamp,
9013 ISOAL_PDU_STATUS_VALID,
9014 &rx_pdu_meta_buf.pdu_meta);
9015 pdu_data_loc[1] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
9016 (testdata_size - testdata_indx),
9017 sdu_timeoffset,
9018 &rx_pdu_meta_buf.pdu_meta);
9019
9020 /* Set callback function return values */
9021 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
9022 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
9023 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
9024 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
9025 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
9026
9027 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9028
9029 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9030
9031 /* Test recombine (Black Box) */
9032 /* SDU 2 -------------------------------------------------------------*/
9033 seqn++;
9034 /* A new SDU should be allocated */
9035 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1],
9036 &isoal_global.sink_state[sink_hdl], /* Sink */
9037 &rx_pdu_meta_buf.pdu_meta); /* PDU */
9038
9039 /* SDU payload should not be written */
9040
9041 /* SDU should be emitted */
9042 ZASSERT_ISOAL_SDU_EMIT_TEST(history[1],
9043 &isoal_global.sink_state[sink_hdl], /* Sink */
9044 BT_ISO_SINGLE, /* Frag state */
9045 sdu_size[0], /* Frag size */
9046 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
9047 sdu_timestamp[0], /* Timestamp */
9048 seqn, /* Seq. number */
9049 sdu_buffer[0].dbuf, /* Buffer */
9050 sdu_buffer[0].size, /* Buffer size */
9051 total_sdu_size[0], /* Total size */
9052 collated_status[0]); /* SDU status */
9053
9054 /* SDU 3 -------------------------------------------------------------*/
9055 seqn++;
9056 /* A new SDU should be allocated */
9057 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
9058 &isoal_global.sink_state[sink_hdl], /* Sink */
9059 &rx_pdu_meta_buf.pdu_meta); /* PDU */
9060
9061 /* SDU payload should be written */
9062 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
9063 &rx_sdu_frag_buf[1], /* SDU buffer */
9064 0, /* SDU written */
9065 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
9066 /* PDU payload */
9067 (testdata_size - testdata_indx)); /* Size */
9068
9069 /* SDU should be emitted */
9070 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
9071 &isoal_global.sink_state[sink_hdl], /* Sink */
9072 BT_ISO_SINGLE, /* Frag state */
9073 sdu_size[1], /* Frag size */
9074 ISOAL_SDU_STATUS_VALID, /* Frag status */
9075 sdu_timestamp[1], /* Timestamp */
9076 seqn, /* Seq. number */
9077 sdu_buffer[1].dbuf, /* Buffer */
9078 sdu_buffer[1].size, /* Buffer size */
9079 total_sdu_size[1], /* Total size */
9080 collated_status[1]); /* SDU status */
9081
9082 /* Test recombine (White Box) */
9083 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9084 ISOAL_START,
9085 "FSM state %s should be %s!",
9086 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9087 FSM_TO_STR(ISOAL_START));
9088 }
9089
9090 /**
9091 * Test Suite : RX framed PDU recombination
9092 *
9093 * Tests recombination of a single SDU from three segmented PDUs with errors
9094 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_single_sdu_pdu_err1)9095 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1)
9096 {
9097 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
9098 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
9099 struct isoal_sdu_buffer sdu_buffer;
9100 isoal_sdu_status_t collated_status;
9101 isoal_sink_handle_t sink_hdl;
9102 uint32_t stream_sync_delay;
9103 uint32_t group_sync_delay;
9104 isoal_sdu_len_t sdu_size;
9105 uint8_t iso_interval_int;
9106 uint16_t pdu_data_loc[5];
9107 uint32_t iso_interval_us;
9108 uint64_t payload_number;
9109 uint16_t total_sdu_size;
9110 uint32_t sdu_timeoffset;
9111 uint32_t pdu_timestamp;
9112 uint32_t sdu_timestamp;
9113 uint16_t testdata_indx;
9114 uint16_t testdata_size;
9115 uint32_t sdu_interval;
9116 isoal_sdu_cnt_t seqn;
9117 uint8_t testdata[46];
9118 isoal_status_t err;
9119 uint32_t latency;
9120 uint8_t role;
9121 uint8_t BN;
9122 uint8_t FT;
9123
9124 /* Settings */
9125 role = ISOAL_ROLE_PERIPHERAL;
9126 iso_interval_int = 1;
9127 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
9128 sdu_interval = iso_interval_us + 5;
9129 BN = 3;
9130 FT = 1;
9131 stream_sync_delay = iso_interval_us - 200;
9132 group_sync_delay = iso_interval_us - 50;
9133
9134 /* PDU 0 -------------------------------------------------------------*/
9135 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9136 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
9137 init_test_data_buffer(testdata, 46);
9138 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
9139
9140 sdu_buffer.dbuf = &rx_sdu_frag_buf;
9141 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
9142 payload_number = 1000 * BN;
9143 pdu_timestamp = 9249;
9144 latency = calc_rx_latency_by_role(role,
9145 true,
9146 FT,
9147 sdu_interval,
9148 iso_interval_int,
9149 stream_sync_delay,
9150 group_sync_delay);
9151 sdu_timeoffset = group_sync_delay - 50;
9152 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us);
9153 seqn = 0;
9154 testdata_indx = 0;
9155 testdata_size = 13;
9156 sdu_size = 0;
9157 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
9158 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
9159
9160 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
9161 role, /* Role */
9162 true, /* Framed */
9163 BN, /* BN */
9164 FT, /* FT */
9165 sdu_interval, /* SDU Interval */
9166 iso_interval_int, /* ISO Interval */
9167 stream_sync_delay, /* Stream Sync Delay */
9168 group_sync_delay); /* Group Sync Delay */
9169
9170 /* PDU with errors */
9171 isoal_test_create_framed_pdu_base(payload_number,
9172 pdu_timestamp,
9173 ISOAL_PDU_STATUS_ERRORS,
9174 &rx_pdu_meta_buf.pdu_meta);
9175 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
9176 (testdata_size - testdata_indx),
9177 sdu_timeoffset,
9178 &rx_pdu_meta_buf.pdu_meta);
9179
9180 /* Set callback function return values */
9181 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
9182 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
9183 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
9184 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
9185
9186 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9187
9188 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9189
9190 /* SDU 0 -------------------------------------------------------------*/
9191 /* Test recombine (Black Box) */
9192 /* A new SDU should be allocated */
9193 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
9194 &isoal_global.sink_state[sink_hdl], /* Sink */
9195 &rx_pdu_meta_buf.pdu_meta); /* PDU */
9196
9197 /* SDU payload should not be written */
9198
9199 /* SDU should be emitted */
9200 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
9201 &isoal_global.sink_state[sink_hdl], /* Sink */
9202 BT_ISO_SINGLE, /* Frag state */
9203 sdu_size, /* Frag size */
9204 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
9205 sdu_timestamp, /* Timestamp */
9206 seqn, /* Seq. number */
9207 sdu_buffer.dbuf, /* Buffer */
9208 sdu_buffer.size, /* Buffer size */
9209 total_sdu_size, /* Total size */
9210 collated_status); /* SDU status */
9211
9212 /* Test recombine (White Box) */
9213 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9214 ISOAL_ERR_SPOOL,
9215 "FSM state %s should be %s!",
9216 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9217 FSM_TO_STR(ISOAL_ERR_SPOOL));
9218
9219 /* PDU 1 -------------------------------------------------------------*/
9220 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9221
9222 payload_number++;
9223 testdata_indx = testdata_size;
9224 testdata_size += 10;
9225
9226 isoal_test_create_framed_pdu_base(payload_number,
9227 pdu_timestamp,
9228 ISOAL_PDU_STATUS_VALID,
9229 &rx_pdu_meta_buf.pdu_meta);
9230 pdu_data_loc[1] = isoal_test_add_framed_pdu_cont(&testdata[testdata_indx],
9231 (testdata_size - testdata_indx),
9232 &rx_pdu_meta_buf.pdu_meta);
9233
9234 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9235
9236 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9237
9238 /* Test recombine (Black Box) */
9239 /* Should not allocate a new SDU */
9240
9241 /* SDU should not be written to */
9242
9243 /* SDU should not be emitted */
9244
9245 /* Test recombine (White Box) */
9246 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9247 ISOAL_ERR_SPOOL,
9248 "FSM state %s should be %s!",
9249 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9250 FSM_TO_STR(ISOAL_ERR_SPOOL));
9251
9252 /* PDU 2 -------------------------------------------------------------*/
9253 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9254
9255 payload_number++;
9256 testdata_indx = testdata_size;
9257 testdata_size += 10;
9258
9259 isoal_test_create_framed_pdu_base(payload_number,
9260 pdu_timestamp,
9261 ISOAL_PDU_STATUS_VALID,
9262 &rx_pdu_meta_buf.pdu_meta);
9263 pdu_data_loc[2] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
9264 (testdata_size - testdata_indx),
9265 &rx_pdu_meta_buf.pdu_meta);
9266
9267 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9268
9269 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9270
9271 /* Test recombine (Black Box) */
9272 /* Should not allocate a new SDU */
9273
9274 /* SDU should not be written to */
9275
9276 /* SDU should not be emitted */
9277
9278 /* Test recombine (White Box) */
9279 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9280 ISOAL_ERR_SPOOL,
9281 "FSM state %s should be %s!",
9282 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9283 FSM_TO_STR(ISOAL_ERR_SPOOL));
9284
9285 /* PDU 3 -------------------------------------------------------------*/
9286 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9287 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
9288
9289 payload_number++;
9290 pdu_timestamp += iso_interval_us;
9291
9292 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true);
9293 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
9294 seqn++;
9295 testdata_indx = testdata_size;
9296 testdata_size += 13;
9297 sdu_size = 13;
9298 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
9299 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
9300
9301 isoal_test_create_framed_pdu_base(payload_number,
9302 pdu_timestamp,
9303 ISOAL_PDU_STATUS_VALID,
9304 &rx_pdu_meta_buf.pdu_meta);
9305 pdu_data_loc[3] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
9306 (testdata_size - testdata_indx),
9307 sdu_timeoffset,
9308 &rx_pdu_meta_buf.pdu_meta);
9309
9310 /* Set callback function return values */
9311 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
9312 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
9313 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
9314 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
9315
9316 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9317
9318 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9319
9320 /* SDU 1 -------------------------------------------------------------*/
9321 /* Test recombine (Black Box) */
9322 /* A new SDU should be allocated */
9323 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
9324 &isoal_global.sink_state[sink_hdl], /* Sink */
9325 &rx_pdu_meta_buf.pdu_meta); /* PDU */
9326
9327 /* SDU payload should be written */
9328 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
9329 &rx_sdu_frag_buf, /* SDU buffer */
9330 0, /* SDU written */
9331 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
9332 /* PDU payload */
9333 (testdata_size - testdata_indx)); /* Size */
9334
9335 /* SDU should be emitted */
9336 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
9337 &isoal_global.sink_state[sink_hdl], /* Sink */
9338 BT_ISO_SINGLE, /* Frag state */
9339 sdu_size, /* Frag size */
9340 ISOAL_SDU_STATUS_VALID, /* Frag status */
9341 sdu_timestamp, /* Timestamp */
9342 seqn, /* Seq. number */
9343 sdu_buffer.dbuf, /* Buffer */
9344 sdu_buffer.size, /* Buffer size */
9345 total_sdu_size, /* Total size */
9346 collated_status); /* SDU status */
9347
9348 /* Test recombine (White Box) */
9349 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9350 ISOAL_START,
9351 "FSM state %s should be %s!",
9352 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9353 FSM_TO_STR(ISOAL_START));
9354 }
9355
9356 /**
9357 * Test Suite : RX framed PDU recombination
9358 *
9359 * Tests recombination of a single SDU from three segmented PDUs with errors
9360 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_single_sdu_pdu_err2)9361 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err2)
9362 {
9363 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
9364 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
9365 struct isoal_sdu_buffer sdu_buffer;
9366 isoal_sdu_status_t collated_status;
9367 isoal_sink_handle_t sink_hdl;
9368 uint32_t stream_sync_delay;
9369 uint32_t group_sync_delay;
9370 isoal_sdu_len_t sdu_size;
9371 uint8_t iso_interval_int;
9372 uint16_t pdu_data_loc[5];
9373 uint32_t iso_interval_us;
9374 uint64_t payload_number;
9375 uint16_t total_sdu_size;
9376 uint32_t sdu_timeoffset;
9377 uint32_t pdu_timestamp;
9378 uint32_t sdu_timestamp;
9379 uint16_t testdata_indx;
9380 uint16_t testdata_size;
9381 uint32_t sdu_interval;
9382 isoal_sdu_cnt_t seqn;
9383 uint8_t testdata[46];
9384 isoal_status_t err;
9385 uint32_t latency;
9386 uint8_t role;
9387 uint8_t BN;
9388 uint8_t FT;
9389
9390 /* Settings */
9391 role = ISOAL_ROLE_PERIPHERAL;
9392 iso_interval_int = 1;
9393 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
9394 sdu_interval = (iso_interval_us / 3) + 5;
9395 BN = 3;
9396 FT = 1;
9397 stream_sync_delay = iso_interval_us - 200;
9398 group_sync_delay = iso_interval_us - 50;
9399
9400 /* PDU 1 -------------------------------------------------------------*/
9401 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9402 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
9403 init_test_data_buffer(testdata, 46);
9404 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
9405
9406 sdu_buffer.dbuf = &rx_sdu_frag_buf;
9407 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
9408 payload_number = 1000 * BN;
9409 pdu_timestamp = 9249;
9410 latency = calc_rx_latency_by_role(role,
9411 true,
9412 FT,
9413 sdu_interval,
9414 iso_interval_int,
9415 stream_sync_delay,
9416 group_sync_delay);
9417 sdu_timeoffset = group_sync_delay - 50;
9418 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
9419 seqn = 0;
9420 testdata_indx = 0;
9421 testdata_size = 13;
9422 sdu_size = 13;
9423
9424 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
9425 role, /* Role */
9426 true, /* Framed */
9427 BN, /* BN */
9428 FT, /* FT */
9429 sdu_interval, /* SDU Interval */
9430 iso_interval_int, /* ISO Interval */
9431 stream_sync_delay, /* Stream Sync Delay */
9432 group_sync_delay); /* Group Sync Delay */
9433
9434 /* PDU with errors */
9435 isoal_test_create_framed_pdu_base(payload_number,
9436 pdu_timestamp,
9437 ISOAL_PDU_STATUS_VALID,
9438 &rx_pdu_meta_buf.pdu_meta);
9439 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
9440 (testdata_size - testdata_indx),
9441 sdu_timeoffset,
9442 &rx_pdu_meta_buf.pdu_meta);
9443
9444 /* Set callback function return values */
9445 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
9446 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
9447 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
9448
9449 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9450
9451 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9452
9453 /* Test recombine (Black Box) */
9454 /* A new SDU should be allocated */
9455 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
9456 &isoal_global.sink_state[sink_hdl], /* Sink */
9457 &rx_pdu_meta_buf.pdu_meta); /* PDU */
9458
9459 /* SDU payload should be written */
9460 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
9461 &rx_sdu_frag_buf, /* SDU buffer */
9462 0, /* SDU written */
9463 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
9464 /* PDU payload */
9465 (testdata_size - testdata_indx)); /* Size */
9466
9467 /* SDU should not be emitted */
9468
9469 /* Test recombine (White Box) */
9470 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9471 ISOAL_CONTINUE,
9472 "FSM state %s should be %s!",
9473 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9474 FSM_TO_STR(ISOAL_CONTINUE));
9475
9476 /* PDU 2 -------------------------------------------------------------*/
9477 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9478
9479 payload_number++;
9480 testdata_indx = testdata_size;
9481 testdata_size += 10;
9482 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
9483 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
9484
9485 isoal_test_create_framed_pdu_base(payload_number,
9486 pdu_timestamp,
9487 ISOAL_PDU_STATUS_ERRORS,
9488 &rx_pdu_meta_buf.pdu_meta);
9489 pdu_data_loc[1] = isoal_test_add_framed_pdu_cont(&testdata[testdata_indx],
9490 (testdata_size - testdata_indx),
9491 &rx_pdu_meta_buf.pdu_meta);
9492
9493 /* Set callback function return values */
9494 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
9495
9496 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9497
9498 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9499
9500 /* Test recombine (Black Box) */
9501 /* A new SDU should not be allocated */
9502
9503 /* SDU payload should not be written */
9504
9505 /* SDU should be emitted */
9506 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
9507 &isoal_global.sink_state[sink_hdl], /* Sink */
9508 BT_ISO_SINGLE, /* Frag state */
9509 sdu_size, /* Frag size */
9510 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
9511 sdu_timestamp, /* Timestamp */
9512 seqn, /* Seq. number */
9513 sdu_buffer.dbuf, /* Buffer */
9514 sdu_buffer.size, /* Buffer size */
9515 total_sdu_size, /* Total size */
9516 collated_status); /* SDU status */
9517
9518 /* Test recombine (White Box) */
9519 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9520 ISOAL_ERR_SPOOL,
9521 "FSM state %s should be %s!",
9522 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9523 FSM_TO_STR(ISOAL_ERR_SPOOL));
9524
9525 /* PDU 3 -------------------------------------------------------------*/
9526 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9527
9528 payload_number++;
9529 testdata_indx = testdata_size;
9530 testdata_size += 10;
9531
9532 isoal_test_create_framed_pdu_base(payload_number,
9533 pdu_timestamp,
9534 ISOAL_PDU_STATUS_VALID,
9535 &rx_pdu_meta_buf.pdu_meta);
9536 pdu_data_loc[2] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
9537 (testdata_size - testdata_indx),
9538 &rx_pdu_meta_buf.pdu_meta);
9539
9540 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9541
9542 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9543
9544 /* Test recombine (Black Box) */
9545 /* Should not allocate a new SDU */
9546
9547 /* SDU should not be written to */
9548
9549 /* SDU should not be emitted */
9550
9551 /* Test recombine (White Box) */
9552 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9553 ISOAL_ERR_SPOOL,
9554 "FSM state %s should be %s!",
9555 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9556 FSM_TO_STR(ISOAL_ERR_SPOOL));
9557
9558 /* PDU 4 -------------------------------------------------------------*/
9559 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9560 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
9561
9562 payload_number++;
9563
9564 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
9565 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
9566 seqn++;
9567 testdata_indx = testdata_size;
9568 testdata_size += 13;
9569 sdu_size = 13;
9570 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
9571 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
9572
9573 isoal_test_create_framed_pdu_base(payload_number,
9574 pdu_timestamp,
9575 ISOAL_PDU_STATUS_VALID,
9576 &rx_pdu_meta_buf.pdu_meta);
9577 pdu_data_loc[3] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
9578 (testdata_size - testdata_indx),
9579 sdu_timeoffset,
9580 &rx_pdu_meta_buf.pdu_meta);
9581
9582 /* Set callback function return values */
9583 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
9584 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
9585 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
9586 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
9587
9588 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9589
9590 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9591
9592 /* Test recombine (Black Box) */
9593 /* A new SDU should be allocated */
9594 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
9595 &isoal_global.sink_state[sink_hdl], /* Sink */
9596 &rx_pdu_meta_buf.pdu_meta); /* PDU */
9597
9598 /* SDU payload should be written */
9599 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
9600 &rx_sdu_frag_buf, /* SDU buffer */
9601 0, /* SDU written */
9602 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
9603 /* PDU payload */
9604 (testdata_size - testdata_indx)); /* Size */
9605
9606 /* SDU should be emitted */
9607 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
9608 &isoal_global.sink_state[sink_hdl], /* Sink */
9609 BT_ISO_SINGLE, /* Frag state */
9610 sdu_size, /* Frag size */
9611 ISOAL_SDU_STATUS_VALID, /* Frag status */
9612 sdu_timestamp, /* Timestamp */
9613 seqn, /* Seq. number */
9614 sdu_buffer.dbuf, /* Buffer */
9615 sdu_buffer.size, /* Buffer size */
9616 total_sdu_size, /* Total size */
9617 collated_status); /* SDU status */
9618
9619 /* Test recombine (White Box) */
9620 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9621 ISOAL_START,
9622 "FSM state %s should be %s!",
9623 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9624 FSM_TO_STR(ISOAL_START));
9625 }
9626
9627 /**
9628 * Test Suite : RX framed PDU recombination
9629 *
9630 * Tests recombination of a single SDU from three segmented PDUs with errors
9631 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_single_sdu_pdu_err3)9632 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err3)
9633 {
9634 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
9635 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
9636 struct isoal_sdu_buffer sdu_buffer;
9637 isoal_sdu_status_t collated_status;
9638 isoal_sink_handle_t sink_hdl;
9639 uint32_t stream_sync_delay;
9640 uint32_t group_sync_delay;
9641 isoal_sdu_len_t sdu_size;
9642 uint8_t iso_interval_int;
9643 uint16_t pdu_data_loc[5];
9644 uint32_t iso_interval_us;
9645 uint64_t payload_number;
9646 uint16_t total_sdu_size;
9647 uint16_t sdu_written = 0;
9648 uint32_t sdu_timeoffset;
9649 uint32_t pdu_timestamp;
9650 uint32_t sdu_timestamp;
9651 uint16_t testdata_indx;
9652 uint16_t testdata_size;
9653 uint32_t sdu_interval;
9654 isoal_sdu_cnt_t seqn;
9655 uint8_t testdata[46];
9656 isoal_status_t err;
9657 uint32_t latency;
9658 uint8_t role;
9659 uint8_t BN;
9660 uint8_t FT;
9661
9662 /* Settings */
9663 role = ISOAL_ROLE_PERIPHERAL;
9664 iso_interval_int = 1;
9665 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
9666 sdu_interval = (iso_interval_us / 3) + 5;
9667 BN = 3;
9668 FT = 1;
9669 stream_sync_delay = iso_interval_us - 200;
9670 group_sync_delay = iso_interval_us - 50;
9671
9672 /* PDU 1 -------------------------------------------------------------*/
9673 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9674 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
9675 init_test_data_buffer(testdata, 46);
9676 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
9677
9678 sdu_buffer.dbuf = &rx_sdu_frag_buf;
9679 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
9680 payload_number = 1000 * BN;
9681 pdu_timestamp = 9249;
9682 latency = calc_rx_latency_by_role(role,
9683 true,
9684 FT,
9685 sdu_interval,
9686 iso_interval_int,
9687 stream_sync_delay,
9688 group_sync_delay);
9689 sdu_timeoffset = group_sync_delay - 50;
9690 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
9691 seqn = 0;
9692 testdata_indx = 0;
9693 testdata_size = 13;
9694 sdu_size = 13;
9695
9696 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
9697 role, /* Role */
9698 true, /* Framed */
9699 BN, /* BN */
9700 FT, /* FT */
9701 sdu_interval, /* SDU Interval */
9702 iso_interval_int, /* ISO Interval */
9703 stream_sync_delay, /* Stream Sync Delay */
9704 group_sync_delay); /* Group Sync Delay */
9705
9706 /* PDU with errors */
9707 isoal_test_create_framed_pdu_base(payload_number,
9708 pdu_timestamp,
9709 ISOAL_PDU_STATUS_VALID,
9710 &rx_pdu_meta_buf.pdu_meta);
9711 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
9712 (testdata_size - testdata_indx),
9713 sdu_timeoffset,
9714 &rx_pdu_meta_buf.pdu_meta);
9715
9716 /* Set callback function return values */
9717 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
9718 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
9719 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
9720
9721 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9722
9723 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9724
9725 /* Test recombine (Black Box) */
9726 /* A new SDU should be allocated */
9727 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
9728 &isoal_global.sink_state[sink_hdl], /* Sink */
9729 &rx_pdu_meta_buf.pdu_meta); /* PDU */
9730
9731 /* SDU payload should be written */
9732 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
9733 &rx_sdu_frag_buf, /* SDU buffer */
9734 sdu_written, /* SDU written */
9735 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
9736 /* PDU payload */
9737 (testdata_size - testdata_indx)); /* Size */
9738
9739 /* SDU should not be emitted */
9740
9741 /* Test recombine (White Box) */
9742 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9743 ISOAL_CONTINUE,
9744 "FSM state %s should be %s!",
9745 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9746 FSM_TO_STR(ISOAL_CONTINUE));
9747
9748 /* PDU 2 -------------------------------------------------------------*/
9749 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9750
9751 sdu_written += (testdata_size - testdata_indx);
9752 payload_number++;
9753 testdata_indx = testdata_size;
9754 testdata_size += 10;
9755 sdu_size += 10;
9756
9757 isoal_test_create_framed_pdu_base(payload_number,
9758 pdu_timestamp,
9759 ISOAL_PDU_STATUS_VALID,
9760 &rx_pdu_meta_buf.pdu_meta);
9761 pdu_data_loc[1] = isoal_test_add_framed_pdu_cont(&testdata[testdata_indx],
9762 (testdata_size - testdata_indx),
9763 &rx_pdu_meta_buf.pdu_meta);
9764
9765 /* Set callback function return values */
9766 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
9767
9768 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9769
9770 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9771
9772 /* Test recombine (Black Box) */
9773 /* A new SDU should not be allocated */
9774
9775 /* SDU payload should be written */
9776 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
9777 &rx_sdu_frag_buf, /* SDU buffer */
9778 sdu_written, /* SDU written */
9779 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
9780 /* PDU payload */
9781 (testdata_size - testdata_indx)); /* Size */
9782
9783 /* SDU should not be emitted */
9784
9785 /* Test recombine (White Box) */
9786 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9787 ISOAL_CONTINUE,
9788 "FSM state %s should be %s!",
9789 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9790 FSM_TO_STR(ISOAL_CONTINUE));
9791
9792 /* PDU 3 -------------------------------------------------------------*/
9793 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9794
9795 payload_number++;
9796 testdata_indx = testdata_size;
9797 testdata_size += 10;
9798 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
9799 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
9800
9801 isoal_test_create_framed_pdu_base(payload_number,
9802 pdu_timestamp,
9803 ISOAL_PDU_STATUS_ERRORS,
9804 &rx_pdu_meta_buf.pdu_meta);
9805 pdu_data_loc[2] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
9806 (testdata_size - testdata_indx),
9807 &rx_pdu_meta_buf.pdu_meta);
9808
9809 /* Set callback function return values */
9810 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
9811
9812 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9813
9814 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9815
9816 /* Test recombine (Black Box) */
9817 /* A new SDU should not be allocated */
9818
9819 /* SDU payload should not be written */
9820
9821 /* SDU should be emitted */
9822 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
9823 &isoal_global.sink_state[sink_hdl], /* Sink */
9824 BT_ISO_SINGLE, /* Frag state */
9825 sdu_size, /* Frag size */
9826 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
9827 sdu_timestamp, /* Timestamp */
9828 seqn, /* Seq. number */
9829 sdu_buffer.dbuf, /* Buffer */
9830 sdu_buffer.size, /* Buffer size */
9831 total_sdu_size, /* Total size */
9832 collated_status); /* SDU status */
9833
9834 /* Test recombine (White Box) */
9835 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9836 ISOAL_ERR_SPOOL,
9837 "FSM state %s should be %s!",
9838 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9839 FSM_TO_STR(ISOAL_ERR_SPOOL));
9840
9841 /* PDU 4 -------------------------------------------------------------*/
9842 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9843 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
9844
9845 sdu_written = 0;
9846 payload_number++;
9847
9848 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
9849 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
9850 seqn++;
9851 testdata_indx = testdata_size;
9852 testdata_size += 13;
9853 sdu_size = 13;
9854 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
9855 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
9856
9857 isoal_test_create_framed_pdu_base(payload_number,
9858 pdu_timestamp,
9859 ISOAL_PDU_STATUS_VALID,
9860 &rx_pdu_meta_buf.pdu_meta);
9861 pdu_data_loc[3] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
9862 (testdata_size - testdata_indx),
9863 sdu_timeoffset,
9864 &rx_pdu_meta_buf.pdu_meta);
9865
9866 /* Set callback function return values */
9867 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
9868 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
9869 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
9870 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
9871
9872 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
9873
9874 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
9875
9876 /* Test recombine (Black Box) */
9877 /* A new SDU should be allocated */
9878 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
9879 &isoal_global.sink_state[sink_hdl], /* Sink */
9880 &rx_pdu_meta_buf.pdu_meta); /* PDU */
9881
9882 /* SDU payload should be written */
9883 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
9884 &rx_sdu_frag_buf, /* SDU buffer */
9885 sdu_written, /* SDU written */
9886 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
9887 /* PDU payload */
9888 (testdata_size - testdata_indx)); /* Size */
9889
9890 /* SDU should be emitted */
9891 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
9892 &isoal_global.sink_state[sink_hdl], /* Sink */
9893 BT_ISO_SINGLE, /* Frag state */
9894 sdu_size, /* Frag size */
9895 ISOAL_SDU_STATUS_VALID, /* Frag status */
9896 sdu_timestamp, /* Timestamp */
9897 seqn, /* Seq. number */
9898 sdu_buffer.dbuf, /* Buffer */
9899 sdu_buffer.size, /* Buffer size */
9900 total_sdu_size, /* Total size */
9901 collated_status); /* SDU status */
9902
9903 /* Test recombine (White Box) */
9904 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
9905 ISOAL_START,
9906 "FSM state %s should be %s!",
9907 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
9908 FSM_TO_STR(ISOAL_START));
9909 }
9910
9911 /**
9912 * Test Suite : RX framed PDU recombination
9913 *
9914 * Tests recombination of a single SDU from three segmented PDUs with errors
9915 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_single_sdu_seq_err1)9916 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_seq_err1)
9917 {
9918 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
9919 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
9920 struct isoal_sdu_buffer sdu_buffer;
9921 isoal_sdu_status_t collated_status;
9922 isoal_sink_handle_t sink_hdl;
9923 uint32_t stream_sync_delay;
9924 uint32_t group_sync_delay;
9925 isoal_sdu_len_t sdu_size;
9926 uint8_t iso_interval_int;
9927 uint16_t pdu_data_loc[5];
9928 uint32_t iso_interval_us;
9929 uint64_t payload_number;
9930 uint16_t total_sdu_size;
9931 uint32_t sdu_timeoffset;
9932 uint32_t pdu_timestamp;
9933 uint32_t sdu_timestamp;
9934 uint16_t testdata_indx;
9935 uint16_t testdata_size;
9936 uint32_t sdu_interval;
9937 isoal_sdu_cnt_t seqn;
9938 uint8_t testdata[46];
9939 isoal_status_t err;
9940 uint32_t latency;
9941 uint8_t role;
9942 uint8_t BN;
9943 uint8_t FT;
9944
9945 /* Settings */
9946 role = ISOAL_ROLE_PERIPHERAL;
9947 iso_interval_int = 1;
9948 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
9949 sdu_interval = (iso_interval_us / 3) + 5;
9950 BN = 3;
9951 FT = 1;
9952 stream_sync_delay = iso_interval_us - 200;
9953 group_sync_delay = iso_interval_us - 50;
9954
9955 /* PDU 1 -------------------------------------------------------------*/
9956 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
9957 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
9958 init_test_data_buffer(testdata, 46);
9959 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
9960
9961 sdu_buffer.dbuf = &rx_sdu_frag_buf;
9962 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
9963 payload_number = 1000 * BN;
9964 pdu_timestamp = 9249;
9965 latency = calc_rx_latency_by_role(role,
9966 true,
9967 FT,
9968 sdu_interval,
9969 iso_interval_int,
9970 stream_sync_delay,
9971 group_sync_delay);
9972 sdu_timeoffset = group_sync_delay - 50;
9973 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
9974 seqn = 0;
9975 testdata_indx = 0;
9976 testdata_size = 13;
9977 sdu_size = 13;
9978
9979 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
9980 role, /* Role */
9981 true, /* Framed */
9982 BN, /* BN */
9983 FT, /* FT */
9984 sdu_interval, /* SDU Interval */
9985 iso_interval_int, /* ISO Interval */
9986 stream_sync_delay, /* Stream Sync Delay */
9987 group_sync_delay); /* Group Sync Delay */
9988
9989 /* PDU with errors */
9990 isoal_test_create_framed_pdu_base(payload_number,
9991 pdu_timestamp,
9992 ISOAL_PDU_STATUS_VALID,
9993 &rx_pdu_meta_buf.pdu_meta);
9994 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
9995 (testdata_size - testdata_indx),
9996 sdu_timeoffset,
9997 &rx_pdu_meta_buf.pdu_meta);
9998
9999 /* Set callback function return values */
10000 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
10001 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
10002 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
10003
10004 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10005
10006 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10007
10008 /* Test recombine (Black Box) */
10009 /* A new SDU should be allocated */
10010 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
10011 &isoal_global.sink_state[sink_hdl], /* Sink */
10012 &rx_pdu_meta_buf.pdu_meta); /* PDU */
10013
10014 /* SDU payload should be written */
10015 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
10016 &rx_sdu_frag_buf, /* SDU buffer */
10017 0, /* SDU written */
10018 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
10019 /* PDU payload */
10020 (testdata_size - testdata_indx)); /* Size */
10021
10022 /* SDU should not be emitted */
10023
10024 /* Test recombine (White Box) */
10025 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10026 ISOAL_CONTINUE,
10027 "FSM state %s should be %s!",
10028 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10029 FSM_TO_STR(ISOAL_CONTINUE));
10030
10031 /* PDU 2 -------------------------------------------------------------*/
10032 /* PDU not transferred to the ISO-AL */
10033 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10034
10035 payload_number++;
10036 testdata_indx = testdata_size;
10037 testdata_size += 10;
10038
10039 /* PDU 3 -------------------------------------------------------------*/
10040 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10041
10042 payload_number++;
10043 testdata_indx = testdata_size;
10044 testdata_size += 10;
10045 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
10046 collated_status =
10047 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
10048
10049 isoal_test_create_framed_pdu_base(payload_number,
10050 pdu_timestamp,
10051 ISOAL_PDU_STATUS_VALID,
10052 &rx_pdu_meta_buf.pdu_meta);
10053 pdu_data_loc[2] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
10054 (testdata_size - testdata_indx),
10055 &rx_pdu_meta_buf.pdu_meta);
10056
10057 /* Set callback function return values */
10058 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
10059
10060 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10061
10062 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10063
10064 /* Test recombine (Black Box) */
10065 /* A new SDU should not be allocated */
10066
10067 /* SDU payload should not be written */
10068
10069 /* SDU should be emitted */
10070 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
10071 &isoal_global.sink_state[sink_hdl], /* Sink */
10072 BT_ISO_SINGLE, /* Frag state */
10073 sdu_size, /* Frag size */
10074 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
10075 sdu_timestamp, /* Timestamp */
10076 seqn, /* Seq. number */
10077 sdu_buffer.dbuf, /* Buffer */
10078 sdu_buffer.size, /* Buffer size */
10079 total_sdu_size, /* Total size */
10080 collated_status); /* SDU status */
10081
10082 /* Test recombine (White Box) */
10083 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10084 ISOAL_ERR_SPOOL,
10085 "FSM state %s should be %s!",
10086 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10087 FSM_TO_STR(ISOAL_ERR_SPOOL));
10088
10089 /* PDU 4 -------------------------------------------------------------*/
10090 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10091 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
10092
10093 payload_number++;
10094
10095 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
10096 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
10097 seqn++;
10098 testdata_indx = testdata_size;
10099 testdata_size += 13;
10100 sdu_size = 13;
10101 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
10102 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
10103
10104 isoal_test_create_framed_pdu_base(payload_number,
10105 pdu_timestamp,
10106 ISOAL_PDU_STATUS_VALID,
10107 &rx_pdu_meta_buf.pdu_meta);
10108 pdu_data_loc[3] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
10109 (testdata_size - testdata_indx),
10110 sdu_timeoffset,
10111 &rx_pdu_meta_buf.pdu_meta);
10112
10113 /* Set callback function return values */
10114 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
10115 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
10116 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
10117 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
10118
10119 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10120
10121 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10122
10123 /* Test recombine (Black Box) */
10124 /* A new SDU should be allocated */
10125 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
10126 &isoal_global.sink_state[sink_hdl], /* Sink */
10127 &rx_pdu_meta_buf.pdu_meta); /* PDU */
10128
10129 /* SDU payload should be written */
10130 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
10131 &rx_sdu_frag_buf, /* SDU buffer */
10132 0, /* SDU written */
10133 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
10134 /* PDU payload */
10135 (testdata_size - testdata_indx)); /* Size */
10136
10137 /* SDU should be emitted */
10138 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
10139 &isoal_global.sink_state[sink_hdl], /* Sink */
10140 BT_ISO_SINGLE, /* Frag state */
10141 sdu_size, /* Frag size */
10142 ISOAL_SDU_STATUS_VALID, /* Frag status */
10143 sdu_timestamp, /* Timestamp */
10144 seqn, /* Seq. number */
10145 sdu_buffer.dbuf, /* Buffer */
10146 sdu_buffer.size, /* Buffer size */
10147 total_sdu_size, /* Total size */
10148 collated_status); /* SDU status */
10149
10150 /* Test recombine (White Box) */
10151 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10152 ISOAL_START,
10153 "FSM state %s should be %s!",
10154 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10155 FSM_TO_STR(ISOAL_START));
10156 }
10157
10158 /**
10159 * Test Suite : RX framed PDU recombination
10160 *
10161 * Tests recombination of a single SDU from three segmented PDUs with errors
10162 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_single_sdu_pdu_seq_err1)10163 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_seq_err1)
10164 {
10165 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
10166 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
10167 struct isoal_sdu_buffer sdu_buffer;
10168 isoal_sdu_status_t collated_status;
10169 isoal_sink_handle_t sink_hdl;
10170 uint32_t stream_sync_delay;
10171 uint32_t group_sync_delay;
10172 isoal_sdu_len_t sdu_size;
10173 uint8_t iso_interval_int;
10174 uint16_t pdu_data_loc[5];
10175 uint32_t iso_interval_us;
10176 uint64_t payload_number;
10177 uint16_t total_sdu_size;
10178 uint32_t sdu_timeoffset;
10179 uint32_t pdu_timestamp;
10180 uint32_t sdu_timestamp;
10181 uint16_t testdata_indx;
10182 uint16_t testdata_size;
10183 uint32_t sdu_interval;
10184 isoal_sdu_cnt_t seqn;
10185 uint8_t testdata[46];
10186 isoal_status_t err;
10187 uint32_t latency;
10188 uint8_t role;
10189 uint8_t BN;
10190 uint8_t FT;
10191
10192 /* Settings */
10193 role = ISOAL_ROLE_PERIPHERAL;
10194 iso_interval_int = 1;
10195 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
10196 sdu_interval = (iso_interval_us / 3) + 5;
10197 BN = 3;
10198 FT = 1;
10199 stream_sync_delay = iso_interval_us - 200;
10200 group_sync_delay = iso_interval_us - 50;
10201
10202 /* PDU 1 -------------------------------------------------------------*/
10203 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10204 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
10205 init_test_data_buffer(testdata, 46);
10206 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
10207
10208 sdu_buffer.dbuf = &rx_sdu_frag_buf;
10209 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
10210 payload_number = 1000 * BN;
10211 pdu_timestamp = 9249;
10212 latency = calc_rx_latency_by_role(role,
10213 true,
10214 FT,
10215 sdu_interval,
10216 iso_interval_int,
10217 stream_sync_delay,
10218 group_sync_delay);
10219 sdu_timeoffset = group_sync_delay - 50;
10220 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
10221 seqn = 0;
10222 testdata_indx = 0;
10223 testdata_size = 13;
10224 sdu_size = 13;
10225
10226 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
10227 role, /* Role */
10228 true, /* Framed */
10229 BN, /* BN */
10230 FT, /* FT */
10231 sdu_interval, /* SDU Interval */
10232 iso_interval_int, /* ISO Interval */
10233 stream_sync_delay, /* Stream Sync Delay */
10234 group_sync_delay); /* Group Sync Delay */
10235
10236 /* PDU with errors */
10237 isoal_test_create_framed_pdu_base(payload_number,
10238 pdu_timestamp,
10239 ISOAL_PDU_STATUS_VALID,
10240 &rx_pdu_meta_buf.pdu_meta);
10241 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
10242 (testdata_size - testdata_indx),
10243 sdu_timeoffset,
10244 &rx_pdu_meta_buf.pdu_meta);
10245
10246 /* Set callback function return values */
10247 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
10248 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
10249 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
10250
10251 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10252
10253 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10254
10255 /* Test recombine (Black Box) */
10256 /* A new SDU should be allocated */
10257 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
10258 &isoal_global.sink_state[sink_hdl], /* Sink */
10259 &rx_pdu_meta_buf.pdu_meta); /* PDU */
10260
10261 /* SDU payload should be written */
10262 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
10263 &rx_sdu_frag_buf, /* SDU buffer */
10264 0, /* SDU written */
10265 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
10266 /* PDU payload */
10267 (testdata_size - testdata_indx)); /* Size */
10268
10269 /* SDU should not be emitted */
10270
10271 /* Test recombine (White Box) */
10272 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10273 ISOAL_CONTINUE,
10274 "FSM state %s should be %s!",
10275 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10276 FSM_TO_STR(ISOAL_CONTINUE));
10277
10278 /* PDU 2 -------------------------------------------------------------*/
10279 /* PDU not transferred to the ISO-AL */
10280 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10281
10282 payload_number++;
10283 testdata_indx = testdata_size;
10284 testdata_size += 10;
10285
10286 /* PDU 3 -------------------------------------------------------------*/
10287 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10288
10289 payload_number++;
10290 testdata_indx = testdata_size;
10291 testdata_size += 10;
10292 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
10293 collated_status =
10294 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
10295
10296 isoal_test_create_framed_pdu_base(payload_number,
10297 pdu_timestamp,
10298 ISOAL_PDU_STATUS_ERRORS,
10299 &rx_pdu_meta_buf.pdu_meta);
10300 pdu_data_loc[2] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
10301 (testdata_size - testdata_indx),
10302 &rx_pdu_meta_buf.pdu_meta);
10303
10304 /* Set callback function return values */
10305 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
10306
10307 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10308
10309 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10310
10311 /* Test recombine (Black Box) */
10312 /* A new SDU should not be allocated */
10313
10314 /* SDU payload should not be written */
10315
10316 /* SDU should be emitted */
10317 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
10318 &isoal_global.sink_state[sink_hdl], /* Sink */
10319 BT_ISO_SINGLE, /* Frag state */
10320 sdu_size, /* Frag size */
10321 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
10322 sdu_timestamp, /* Timestamp */
10323 seqn, /* Seq. number */
10324 sdu_buffer.dbuf, /* Buffer */
10325 sdu_buffer.size, /* Buffer size */
10326 total_sdu_size, /* Total size */
10327 collated_status); /* SDU status */
10328
10329 /* Test recombine (White Box) */
10330 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10331 ISOAL_ERR_SPOOL,
10332 "FSM state %s should be %s!",
10333 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10334 FSM_TO_STR(ISOAL_ERR_SPOOL));
10335
10336 /* PDU 4 -------------------------------------------------------------*/
10337 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10338 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
10339
10340 payload_number++;
10341
10342 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
10343 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
10344 seqn++;
10345 testdata_indx = testdata_size;
10346 testdata_size += 13;
10347 sdu_size = 13;
10348 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
10349 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
10350
10351 isoal_test_create_framed_pdu_base(payload_number,
10352 pdu_timestamp,
10353 ISOAL_PDU_STATUS_VALID,
10354 &rx_pdu_meta_buf.pdu_meta);
10355 pdu_data_loc[3] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
10356 (testdata_size - testdata_indx),
10357 sdu_timeoffset,
10358 &rx_pdu_meta_buf.pdu_meta);
10359
10360 /* Set callback function return values */
10361 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
10362 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
10363 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
10364 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
10365
10366 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10367
10368 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10369
10370 /* Test recombine (Black Box) */
10371 /* A new SDU should be allocated */
10372 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
10373 &isoal_global.sink_state[sink_hdl], /* Sink */
10374 &rx_pdu_meta_buf.pdu_meta); /* PDU */
10375
10376 /* SDU payload should be written */
10377 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
10378 &rx_sdu_frag_buf, /* SDU buffer */
10379 0, /* SDU written */
10380 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
10381 /* PDU payload */
10382 (testdata_size - testdata_indx)); /* Size */
10383
10384 /* SDU should be emitted */
10385 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
10386 &isoal_global.sink_state[sink_hdl], /* Sink */
10387 BT_ISO_SINGLE, /* Frag state */
10388 sdu_size, /* Frag size */
10389 ISOAL_SDU_STATUS_VALID, /* Frag status */
10390 sdu_timestamp, /* Timestamp */
10391 seqn, /* Seq. number */
10392 sdu_buffer.dbuf, /* Buffer */
10393 sdu_buffer.size, /* Buffer size */
10394 total_sdu_size, /* Total size */
10395 collated_status); /* SDU status */
10396
10397 /* Test recombine (White Box) */
10398 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10399 ISOAL_START,
10400 "FSM state %s should be %s!",
10401 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10402 FSM_TO_STR(ISOAL_START));
10403 }
10404
10405 /**
10406 * Test Suite : RX framed PDU recombination
10407 *
10408 * Tests recombination of two SDUs from three segmented PDUs
10409 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1)10410 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1)
10411 {
10412 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
10413 struct rx_sdu_frag_buffer rx_sdu_frag_buf[2];
10414 struct isoal_sdu_buffer sdu_buffer[2];
10415 isoal_sdu_status_t collated_status[2];
10416 isoal_sink_handle_t sink_hdl;
10417 uint32_t stream_sync_delay;
10418 uint32_t group_sync_delay;
10419 isoal_sdu_len_t sdu_size[2];
10420 uint16_t total_sdu_size[2];
10421 uint16_t sdu_written = 0;
10422 uint8_t iso_interval_int;
10423 uint32_t sdu_timestamp[2];
10424 uint16_t pdu_data_loc[5];
10425 uint32_t iso_interval_us;
10426 uint64_t payload_number;
10427 uint32_t sdu_timeoffset;
10428 uint32_t pdu_timestamp;
10429 uint16_t testdata_indx;
10430 uint16_t testdata_size;
10431 uint32_t sdu_interval;
10432 isoal_sdu_cnt_t seqn;
10433 uint8_t testdata[63];
10434 isoal_status_t err;
10435 uint32_t latency;
10436 uint8_t role;
10437 uint8_t BN;
10438 uint8_t FT;
10439
10440 /* Settings */
10441 role = ISOAL_ROLE_PERIPHERAL;
10442 iso_interval_int = 1;
10443 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
10444 sdu_interval = (iso_interval_us / 3) + 5;
10445 BN = 3;
10446 FT = 1;
10447 stream_sync_delay = iso_interval_us - 200;
10448 group_sync_delay = iso_interval_us - 50;
10449
10450 /* PDU 1 -------------------------------------------------------------*/
10451 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10452 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
10453 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
10454 init_test_data_buffer(testdata, 63);
10455 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
10456
10457 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
10458 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
10459 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
10460 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
10461 payload_number = 1000 * BN;
10462 pdu_timestamp = 9249;
10463 latency = calc_rx_latency_by_role(role,
10464 true,
10465 FT,
10466 sdu_interval,
10467 iso_interval_int,
10468 stream_sync_delay,
10469 group_sync_delay);
10470 sdu_timeoffset = group_sync_delay - 50;
10471 /* PDU will have errors. Time stamp is only an approximation */
10472 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us);
10473 seqn = 0;
10474 testdata_indx = 0;
10475 testdata_size = 13;
10476 sdu_size[0] = 0;
10477 total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
10478 collated_status[0] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
10479
10480 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
10481 role, /* Role */
10482 true, /* Framed */
10483 BN, /* BN */
10484 FT, /* FT */
10485 sdu_interval, /* SDU Interval */
10486 iso_interval_int, /* ISO Interval */
10487 stream_sync_delay, /* Stream Sync Delay */
10488 group_sync_delay); /* Group Sync Delay */
10489
10490 /* PDU with errors */
10491 isoal_test_create_framed_pdu_base(payload_number,
10492 pdu_timestamp,
10493 ISOAL_PDU_STATUS_ERRORS,
10494 &rx_pdu_meta_buf.pdu_meta);
10495 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
10496 (testdata_size - testdata_indx),
10497 sdu_timeoffset,
10498 &rx_pdu_meta_buf.pdu_meta);
10499
10500 /* Set callback function return values */
10501 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
10502 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
10503 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
10504
10505 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10506
10507 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10508
10509 /* Test recombine (Black Box) */
10510 /* SDU 1 -------------------------------------------------------------*/
10511 /* A new SDU should be allocated */
10512 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
10513 &isoal_global.sink_state[sink_hdl], /* Sink */
10514 &rx_pdu_meta_buf.pdu_meta); /* PDU */
10515
10516 /* SDU payload should not be written */
10517 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0);
10518
10519 /* SDU should be emitted */
10520 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
10521 &isoal_global.sink_state[sink_hdl], /* Sink */
10522 BT_ISO_SINGLE, /* Frag state */
10523 sdu_size[0], /* Frag size */
10524 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
10525 sdu_timestamp[0], /* Timestamp */
10526 seqn, /* Seq. number */
10527 sdu_buffer[0].dbuf, /* Buffer */
10528 sdu_buffer[0].size, /* Buffer size */
10529 total_sdu_size[0], /* Total size */
10530 collated_status[0]); /* SDU status */
10531
10532 /* Test recombine (White Box) */
10533 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10534 ISOAL_ERR_SPOOL,
10535 "FSM state %s should be %s!",
10536 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10537 FSM_TO_STR(ISOAL_ERR_SPOOL));
10538
10539 /* PDU 2 -------------------------------------------------------------*/
10540 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10541
10542 payload_number++;
10543 testdata_indx = testdata_size;
10544 testdata_size += 10;
10545 sdu_size[0] += 10;
10546
10547 isoal_test_create_framed_pdu_base(payload_number,
10548 pdu_timestamp,
10549 ISOAL_PDU_STATUS_VALID,
10550 &rx_pdu_meta_buf.pdu_meta);
10551 pdu_data_loc[1] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
10552 (testdata_size - testdata_indx),
10553 &rx_pdu_meta_buf.pdu_meta);
10554
10555 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
10556 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
10557 testdata_indx = testdata_size;
10558 testdata_size += 17;
10559 sdu_size[1] = 17;
10560
10561 pdu_data_loc[2] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
10562 (testdata_size - testdata_indx),
10563 sdu_timeoffset,
10564 &rx_pdu_meta_buf.pdu_meta);
10565
10566 /* Set callback function return values */
10567 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
10568 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
10569 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
10570
10571 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10572
10573 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10574
10575 /* Test recombine (Black Box) */
10576 /* SDU 1 -------------------------------------------------------------*/
10577 /* SDU payload should not be written */
10578
10579 /* SDU shold not be emitted */
10580 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1);
10581
10582 /* SDU 2 -------------------------------------------------------------*/
10583 /* A new SDU should be allocated */
10584 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
10585 &isoal_global.sink_state[sink_hdl], /* Sink */
10586 &rx_pdu_meta_buf.pdu_meta); /* PDU */
10587
10588 /* SDU payload should be written */
10589 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
10590 &rx_sdu_frag_buf[1], /* SDU buffer */
10591 sdu_written, /* SDU written */
10592 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[2]],
10593 /* PDU payload */
10594 (testdata_size - testdata_indx)); /* Size */
10595
10596 /* SDU should not be emitted */
10597
10598 /* Test recombine (White Box) */
10599 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10600 ISOAL_CONTINUE,
10601 "FSM state %s should be %s!",
10602 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10603 FSM_TO_STR(ISOAL_CONTINUE));
10604
10605 /* PDU 3 -------------------------------------------------------------*/
10606 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10607
10608 sdu_written += (testdata_size - testdata_indx);
10609 payload_number++;
10610 testdata_indx = testdata_size;
10611 testdata_size += 10;
10612 sdu_size[1] += 10;
10613 total_sdu_size[1] = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]);
10614 collated_status[1] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
10615
10616 isoal_test_create_framed_pdu_base(payload_number,
10617 pdu_timestamp,
10618 ISOAL_PDU_STATUS_VALID,
10619 &rx_pdu_meta_buf.pdu_meta);
10620 pdu_data_loc[3] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
10621 (testdata_size - testdata_indx),
10622 &rx_pdu_meta_buf.pdu_meta);
10623
10624 /* Set callback function return values */
10625 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
10626 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
10627
10628 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10629
10630 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10631
10632 /* Test recombine (Black Box) */
10633 /* SDU 2 -------------------------------------------------------------*/
10634 seqn++;
10635 /* A new SDU should not be allocated */
10636 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(2);
10637
10638 /* SDU payload should be written */
10639 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
10640 &rx_sdu_frag_buf[1], /* SDU buffer */
10641 sdu_written, /* SDU written */
10642 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
10643 /* PDU payload */
10644 (testdata_size - testdata_indx)); /* Size */
10645
10646 /* SDU should be emitted */
10647 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
10648 &isoal_global.sink_state[sink_hdl], /* Sink */
10649 BT_ISO_SINGLE, /* Frag state */
10650 sdu_size[1], /* Frag size */
10651 ISOAL_SDU_STATUS_VALID, /* Frag status */
10652 sdu_timestamp[1], /* Timestamp */
10653 seqn, /* Seq. number */
10654 sdu_buffer[1].dbuf, /* Buffer */
10655 sdu_buffer[1].size, /* Buffer size */
10656 total_sdu_size[1], /* Total size */
10657 collated_status[1]); /* SDU status */
10658
10659 /* Test recombine (White Box) */
10660 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10661 ISOAL_START,
10662 "FSM state %s should be %s!",
10663 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10664 FSM_TO_STR(ISOAL_START));
10665
10666 /* SDU 3 -------------------------------------------------------------*/
10667 /* Missing */
10668 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
10669 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
10670 sdu_size[1] = 0;
10671 total_sdu_size[1] = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]);
10672 collated_status[1] =
10673 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
10674
10675 /* PDU 4 -------------------------------------------------------------*/
10676 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10677 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
10678
10679 sdu_written = 0;
10680 payload_number++;
10681 pdu_timestamp = 9249 + iso_interval_us;
10682 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true);
10683 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
10684 testdata_indx = testdata_size;
10685 testdata_size += 13;
10686 sdu_size[0] = 13;
10687 total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
10688 collated_status[0] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
10689
10690 isoal_test_create_framed_pdu_base(payload_number,
10691 pdu_timestamp,
10692 ISOAL_PDU_STATUS_VALID,
10693 &rx_pdu_meta_buf.pdu_meta);
10694 pdu_data_loc[4] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
10695 (testdata_size - testdata_indx),
10696 sdu_timeoffset,
10697 &rx_pdu_meta_buf.pdu_meta);
10698
10699 /* Set callback function return values */
10700 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
10701 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
10702 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
10703 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
10704 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
10705
10706 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10707
10708 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10709
10710 /* Test recombine (Black Box) */
10711 /* SDU 3 -------------------------------------------------------------*/
10712 seqn++;
10713 /* A new SDU should be allocated */
10714 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2],
10715 &isoal_global.sink_state[sink_hdl], /* Sink */
10716 &rx_pdu_meta_buf.pdu_meta); /* PDU */
10717
10718 /* SDU payload should not be written */
10719
10720 /* SDU should be emitted */
10721 ZASSERT_ISOAL_SDU_EMIT_TEST(history[2],
10722 &isoal_global.sink_state[sink_hdl], /* Sink */
10723 BT_ISO_SINGLE, /* Frag state */
10724 sdu_size[1], /* Frag size */
10725 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
10726 sdu_timestamp[1], /* Timestamp */
10727 seqn, /* Seq. number */
10728 sdu_buffer[1].dbuf, /* Buffer */
10729 sdu_buffer[1].size, /* Buffer size */
10730 total_sdu_size[1], /* Total size */
10731 collated_status[1]); /* SDU status */
10732
10733 /* SDU 4 -------------------------------------------------------------*/
10734 seqn++;
10735 /* A new SDU should be allocated */
10736 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
10737 &isoal_global.sink_state[sink_hdl], /* Sink */
10738 &rx_pdu_meta_buf.pdu_meta); /* PDU */
10739
10740 /* SDU payload should be written */
10741 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
10742 &rx_sdu_frag_buf[0], /* SDU buffer */
10743 sdu_written, /* SDU written */
10744 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[4]],
10745 /* PDU payload */
10746 (testdata_size - testdata_indx)); /* Size */
10747
10748 /* SDU should be emitted */
10749 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
10750 &isoal_global.sink_state[sink_hdl], /* Sink */
10751 BT_ISO_SINGLE, /* Frag state */
10752 sdu_size[0], /* Frag size */
10753 ISOAL_SDU_STATUS_VALID, /* Frag status */
10754 sdu_timestamp[0], /* Timestamp */
10755 seqn, /* Seq. number */
10756 sdu_buffer[0].dbuf, /* Buffer */
10757 sdu_buffer[0].size, /* Buffer size */
10758 total_sdu_size[0], /* Total size */
10759 collated_status[0]); /* SDU status */
10760
10761 /* Test recombine (White Box) */
10762 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10763 ISOAL_START,
10764 "FSM state %s should be %s!",
10765 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10766 FSM_TO_STR(ISOAL_START));
10767 }
10768
10769 /**
10770 * Test Suite : RX framed PDU recombination
10771 *
10772 * Tests handling errors in the middle of a stream, where the errors occur
10773 * across the end of one SDU and into the start of the next SDU.
10774 *
10775 * Expected Sequence:
10776 * -- Total of 4 SDUs released across 2 events
10777 * -- Event 1: PDU0 Valid SDU 0 Framed Start
10778 * PDU1 Errors SDU 0 Framed End
10779 * SDU 1 Framed Start
10780 * -----> SDU 0 Bit Errors (Released)
10781 * PDU2 Valid SDU 1 Framed End
10782 * Missing SDU 2
10783 * Event 2: PDU3 Valid SDU 3 Framed Single
10784 * -----> SDU 1 Lost (Released)
10785 * -----> SDU 2 Lost (Released)
10786 * -----> SDU 3 Valid (Released)
10787 * PDU4 N/A
10788 * PDU5 N/A
10789 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2)10790 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2)
10791 {
10792 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
10793 struct rx_sdu_frag_buffer rx_sdu_frag_buf[3];
10794 struct isoal_sdu_buffer sdu_buffer[3];
10795 isoal_sdu_status_t collated_status;
10796 isoal_sink_handle_t sink_hdl;
10797 uint32_t stream_sync_delay;
10798 uint32_t group_sync_delay;
10799 isoal_sdu_len_t sdu_size[2];
10800 uint8_t iso_interval_int;
10801 uint32_t sdu_timestamp[3];
10802 uint16_t pdu_data_loc[5];
10803 uint32_t iso_interval_us;
10804 uint64_t payload_number;
10805 uint16_t total_sdu_size;
10806 uint32_t sdu_timeoffset;
10807 uint32_t pdu_timestamp;
10808 uint16_t testdata_indx;
10809 uint16_t testdata_size;
10810 uint32_t sdu_interval;
10811 isoal_sdu_cnt_t seqn;
10812 uint8_t testdata[63];
10813 isoal_status_t err;
10814 uint32_t latency;
10815 uint8_t role;
10816 uint8_t BN;
10817 uint8_t FT;
10818
10819 /* Settings */
10820 role = ISOAL_ROLE_PERIPHERAL;
10821 iso_interval_int = 1;
10822 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
10823 sdu_interval = (iso_interval_us / 3) + 5;
10824 BN = 3;
10825 FT = 1;
10826 stream_sync_delay = iso_interval_us - 200;
10827 group_sync_delay = iso_interval_us - 50;
10828
10829 /* PDU 0 -------------------------------------------------------------*/
10830 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10831 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
10832 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
10833 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]);
10834 init_test_data_buffer(testdata, 63);
10835 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
10836
10837 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
10838 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
10839 sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2];
10840 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
10841 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
10842 sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
10843 payload_number = 1000 * BN;
10844 pdu_timestamp = 9249;
10845 latency = calc_rx_latency_by_role(role,
10846 true,
10847 FT,
10848 sdu_interval,
10849 iso_interval_int,
10850 stream_sync_delay,
10851 group_sync_delay);
10852 sdu_timeoffset = group_sync_delay - 50;
10853 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
10854 seqn = 0;
10855 testdata_indx = 0;
10856 testdata_size = 13;
10857 sdu_size[0] = 13;
10858
10859 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
10860 role, /* Role */
10861 true, /* Framed */
10862 BN, /* BN */
10863 FT, /* FT */
10864 sdu_interval, /* SDU Interval */
10865 iso_interval_int, /* ISO Interval */
10866 stream_sync_delay, /* Stream Sync Delay */
10867 group_sync_delay); /* Group Sync Delay */
10868
10869 isoal_test_create_framed_pdu_base(payload_number,
10870 pdu_timestamp,
10871 ISOAL_PDU_STATUS_VALID,
10872 &rx_pdu_meta_buf.pdu_meta);
10873 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
10874 (testdata_size - testdata_indx),
10875 sdu_timeoffset,
10876 &rx_pdu_meta_buf.pdu_meta);
10877
10878 /* Set callback function return values */
10879 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
10880 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
10881 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
10882 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
10883
10884 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10885
10886 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10887
10888 /* SDU 0 -------------------------------------------------------------*/
10889 /* Test recombine (Black Box) */
10890 /* A new SDU should be allocated */
10891 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
10892 &isoal_global.sink_state[sink_hdl], /* Sink */
10893 &rx_pdu_meta_buf.pdu_meta); /* PDU */
10894
10895 /* SDU payload should be written */
10896 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
10897 &rx_sdu_frag_buf[0], /* SDU buffer */
10898 0, /* SDU written */
10899 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
10900 /* PDU payload */
10901 (testdata_size - testdata_indx)); /* Size */
10902
10903 /* SDU should not be emitted */
10904
10905 /* Test recombine (White Box) */
10906 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10907 ISOAL_CONTINUE,
10908 "FSM state %s should be %s!",
10909 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10910 FSM_TO_STR(ISOAL_CONTINUE));
10911
10912 /* PDU 1 -------------------------------------------------------------*/
10913 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10914
10915 payload_number++;
10916 testdata_indx = testdata_size;
10917 testdata_size += 10;
10918 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
10919 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
10920
10921 /* PDU with errors */
10922 isoal_test_create_framed_pdu_base(payload_number,
10923 pdu_timestamp,
10924 ISOAL_PDU_STATUS_ERRORS,
10925 &rx_pdu_meta_buf.pdu_meta);
10926 pdu_data_loc[1] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
10927 (testdata_size - testdata_indx),
10928 &rx_pdu_meta_buf.pdu_meta);
10929
10930 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
10931 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
10932 testdata_indx = testdata_size;
10933 testdata_size += 17;
10934 sdu_size[1] = 0;
10935
10936 pdu_data_loc[2] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
10937 (testdata_size - testdata_indx),
10938 sdu_timeoffset,
10939 &rx_pdu_meta_buf.pdu_meta);
10940
10941 /* Set callback function return values */
10942 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
10943
10944 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10945
10946 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10947
10948 /* SDU 0 -------------------------------------------------------------*/
10949 /* Test recombine (Black Box) */
10950 /* A new SDU should not be allocated */
10951
10952 /* SDU payload should not be written */
10953
10954 /* SDU should be emitted */
10955 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
10956 &isoal_global.sink_state[sink_hdl], /* Sink */
10957 BT_ISO_SINGLE, /* Frag state */
10958 sdu_size[0], /* Frag size */
10959 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
10960 sdu_timestamp[0], /* Timestamp */
10961 seqn, /* Seq. number */
10962 sdu_buffer[0].dbuf, /* Buffer */
10963 sdu_buffer[0].size, /* Buffer size */
10964 total_sdu_size, /* Total size */
10965 collated_status); /* SDU status */
10966
10967 /* SDU 1 -------------------------------------------------------------*/
10968 /* A new SDU should not be allocated */
10969
10970 /* SDU payload should not be written */
10971
10972 /* SDU should not be emitted */
10973
10974 /* Test recombine (White Box) */
10975 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
10976 ISOAL_ERR_SPOOL,
10977 "FSM state %s should be %s!",
10978 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
10979 FSM_TO_STR(ISOAL_ERR_SPOOL));
10980
10981 /* PDU 2 -------------------------------------------------------------*/
10982 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
10983
10984 payload_number++;
10985 testdata_indx = testdata_size;
10986 testdata_size += 10;
10987
10988 isoal_test_create_framed_pdu_base(payload_number,
10989 pdu_timestamp,
10990 ISOAL_PDU_STATUS_VALID,
10991 &rx_pdu_meta_buf.pdu_meta);
10992 pdu_data_loc[3] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
10993 (testdata_size - testdata_indx),
10994 &rx_pdu_meta_buf.pdu_meta);
10995
10996 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
10997
10998 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
10999
11000 /* SDU 1 -------------------------------------------------------------*/
11001 /* Test recombine (Black Box) */
11002 /* Should not allocate a new SDU */
11003
11004 /* SDU should not be written to */
11005
11006 /* SDU should not be emitted */
11007
11008 /* Test recombine (White Box) */
11009 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
11010 ISOAL_ERR_SPOOL,
11011 "FSM state %s should be %s!",
11012 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
11013 FSM_TO_STR(ISOAL_ERR_SPOOL));
11014
11015 /* SDU 2 -------------------------------------------------------------*/
11016 /* Missing */
11017 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
11018 sdu_timestamp[2] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11019
11020 /* PDU 4 -------------------------------------------------------------*/
11021 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11022 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
11023
11024 payload_number++;
11025 pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US);
11026
11027 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true);
11028 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11029 testdata_indx = testdata_size;
11030 testdata_size += 13;
11031 sdu_size[0] = 13;
11032
11033 isoal_test_create_framed_pdu_base(payload_number,
11034 pdu_timestamp,
11035 ISOAL_PDU_STATUS_VALID,
11036 &rx_pdu_meta_buf.pdu_meta);
11037 pdu_data_loc[4] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
11038 (testdata_size - testdata_indx),
11039 sdu_timeoffset,
11040 &rx_pdu_meta_buf.pdu_meta);
11041
11042 /* Set callback function return values */
11043 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
11044 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]);
11045 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
11046 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
11047 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
11048 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
11049
11050 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
11051
11052 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
11053
11054 /* SDU 1 -------------------------------------------------------------*/
11055 seqn++;
11056 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
11057 collated_status =
11058 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
11059 /* Test recombine (Black Box) */
11060 /* A new SDU should be allocated */
11061 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1],
11062 &isoal_global.sink_state[sink_hdl], /* Sink */
11063 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11064
11065 /* SDU should be emitted */
11066 ZASSERT_ISOAL_SDU_EMIT_TEST(history[1],
11067 &isoal_global.sink_state[sink_hdl], /* Sink */
11068 BT_ISO_SINGLE, /* Frag state */
11069 0, /* Frag size */
11070 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
11071 sdu_timestamp[1], /* Timestamp */
11072 seqn, /* Seq. number */
11073 sdu_buffer[1].dbuf, /* Buffer */
11074 sdu_buffer[1].size, /* Buffer size */
11075 total_sdu_size, /* Total size */
11076 collated_status); /* SDU status */
11077
11078 /* SDU 2 -------------------------------------------------------------*/
11079 seqn++;
11080 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
11081 collated_status =
11082 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
11083 /* Test recombine (Black Box) */
11084 /* A new SDU should be allocated */
11085 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2],
11086 &isoal_global.sink_state[sink_hdl], /* Sink */
11087 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11088
11089 /* SDU should be emitted */
11090 ZASSERT_ISOAL_SDU_EMIT_TEST(history[2],
11091 &isoal_global.sink_state[sink_hdl], /* Sink */
11092 BT_ISO_SINGLE, /* Frag state */
11093 0, /* Frag size */
11094 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
11095 sdu_timestamp[2], /* Timestamp */
11096 seqn, /* Seq. number */
11097 sdu_buffer[2].dbuf, /* Buffer */
11098 sdu_buffer[2].size, /* Buffer size */
11099 total_sdu_size, /* Total size */
11100 collated_status); /* SDU status */
11101
11102 /* SDU 3 -------------------------------------------------------------*/
11103 seqn++;
11104 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
11105 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
11106 /* Test recombine (Black Box) */
11107 /* A new SDU should be allocated */
11108 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
11109 &isoal_global.sink_state[sink_hdl], /* Sink */
11110 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11111
11112 /* SDU payload should be written */
11113 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
11114 &rx_sdu_frag_buf[0], /* SDU buffer */
11115 0, /* SDU written */
11116 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[4]],
11117 /* PDU payload */
11118 (testdata_size - testdata_indx)); /* Size */
11119
11120 /* SDU should be emitted */
11121 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
11122 &isoal_global.sink_state[sink_hdl], /* Sink */
11123 BT_ISO_SINGLE, /* Frag state */
11124 sdu_size[0], /* Frag size */
11125 ISOAL_SDU_STATUS_VALID, /* Frag status */
11126 sdu_timestamp[0], /* Timestamp */
11127 seqn, /* Seq. number */
11128 sdu_buffer[0].dbuf, /* Buffer */
11129 sdu_buffer[0].size, /* Buffer size */
11130 total_sdu_size, /* Total size */
11131 collated_status); /* SDU status */
11132
11133 /* Test recombine (White Box) */
11134 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
11135 ISOAL_START,
11136 "FSM state %s should be %s!",
11137 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
11138 FSM_TO_STR(ISOAL_START));
11139 }
11140
11141 /**
11142 * Test Suite : RX framed PDU recombination
11143 *
11144 * Tests handling errors in the middle of a stream, where the errors occur
11145 * at the end of the SDU.
11146 *
11147 * Expected Sequence:
11148 * -- Total of 4 SDUs released across 2 events
11149 * -- Event 1: PDU0 Valid SDU 0 Framed Start
11150 * PDU1 Valid SDU 0 Framed End
11151 * SDU 1 Framed Start
11152 * -----> SDU 0 Valid (Released)
11153 * PDU2 Errors SDU 1 Framed End
11154 * -----> SDU 1 Bit Errors (Released)
11155 * Missing SDU 2
11156 * Event 2: PDU3 Valid SDU 3 Framed Single
11157 * -----> SDU 2 Lost (Released)
11158 * -----> SDU 3 Valid (Released)
11159 * PDU4 N/A
11160 * PDU5 N/A
11161 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3)11162 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3)
11163 {
11164 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
11165 struct rx_sdu_frag_buffer rx_sdu_frag_buf[2];
11166 struct isoal_sdu_buffer sdu_buffer[2];
11167 isoal_sdu_status_t collated_status;
11168 isoal_sink_handle_t sink_hdl;
11169 uint32_t stream_sync_delay;
11170 uint32_t group_sync_delay;
11171 isoal_sdu_len_t sdu_size[2];
11172 uint8_t iso_interval_int;
11173 uint32_t sdu_timestamp[2];
11174 uint16_t pdu_data_loc[5];
11175 uint32_t iso_interval_us;
11176 uint64_t payload_number;
11177 uint16_t total_sdu_size;
11178 uint16_t sdu_written = 0;
11179 uint32_t sdu_timeoffset;
11180 uint32_t pdu_timestamp;
11181 uint16_t testdata_indx;
11182 uint16_t testdata_size;
11183 uint32_t sdu_interval;
11184 isoal_sdu_cnt_t seqn;
11185 uint8_t testdata[63];
11186 isoal_status_t err;
11187 uint32_t latency;
11188 uint8_t role;
11189 uint8_t BN;
11190 uint8_t FT;
11191
11192 /* Settings */
11193 role = ISOAL_ROLE_PERIPHERAL;
11194 iso_interval_int = 1;
11195 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
11196 sdu_interval = (iso_interval_us / 3) + 5;
11197 BN = 3;
11198 FT = 1;
11199 stream_sync_delay = iso_interval_us - 200;
11200 group_sync_delay = iso_interval_us - 50;
11201
11202 /* PDU 0 -------------------------------------------------------------*/
11203 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11204 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
11205 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
11206 init_test_data_buffer(testdata, 63);
11207 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
11208
11209 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
11210 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
11211 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
11212 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
11213 payload_number = 1000 * BN;
11214 pdu_timestamp = 9249;
11215 latency = calc_rx_latency_by_role(role,
11216 true,
11217 FT,
11218 sdu_interval,
11219 iso_interval_int,
11220 stream_sync_delay,
11221 group_sync_delay);
11222 sdu_timeoffset = group_sync_delay - 50;
11223 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11224 seqn = 0;
11225 testdata_indx = 0;
11226 testdata_size = 13;
11227 sdu_size[0] = 13;
11228
11229 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
11230 role, /* Role */
11231 true, /* Framed */
11232 BN, /* BN */
11233 FT, /* FT */
11234 sdu_interval, /* SDU Interval */
11235 iso_interval_int, /* ISO Interval */
11236 stream_sync_delay, /* Stream Sync Delay */
11237 group_sync_delay); /* Group Sync Delay */
11238
11239 isoal_test_create_framed_pdu_base(payload_number,
11240 pdu_timestamp,
11241 ISOAL_PDU_STATUS_VALID,
11242 &rx_pdu_meta_buf.pdu_meta);
11243 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
11244 (testdata_size - testdata_indx),
11245 sdu_timeoffset,
11246 &rx_pdu_meta_buf.pdu_meta);
11247
11248 /* Set callback function return values */
11249 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
11250 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
11251 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
11252
11253 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
11254
11255 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
11256
11257 /* SDU 0 -------------------------------------------------------------*/
11258 /* Test recombine (Black Box) */
11259 /* A new SDU should be allocated */
11260 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
11261 &isoal_global.sink_state[sink_hdl], /* Sink */
11262 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11263
11264 /* SDU payload should be written */
11265 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
11266 &rx_sdu_frag_buf[0], /* SDU buffer */
11267 sdu_written, /* SDU written */
11268 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
11269 /* PDU payload */
11270 (testdata_size - testdata_indx)); /* Size */
11271
11272 /* SDU should not be emitted */
11273
11274 /* Test recombine (White Box) */
11275 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
11276 ISOAL_CONTINUE,
11277 "FSM state %s should be %s!",
11278 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
11279 FSM_TO_STR(ISOAL_CONTINUE));
11280
11281 /* PDU 1 -------------------------------------------------------------*/
11282 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11283
11284 sdu_written += (testdata_size - testdata_indx);
11285 payload_number++;
11286 testdata_indx = testdata_size;
11287 testdata_size += 10;
11288 sdu_size[0] += 10;
11289
11290 isoal_test_create_framed_pdu_base(payload_number,
11291 pdu_timestamp,
11292 ISOAL_PDU_STATUS_VALID,
11293 &rx_pdu_meta_buf.pdu_meta);
11294 pdu_data_loc[1] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
11295 (testdata_size - testdata_indx),
11296 &rx_pdu_meta_buf.pdu_meta);
11297
11298 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
11299 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11300 testdata_indx = testdata_size;
11301 testdata_size += 17;
11302 sdu_size[1] = 17;
11303
11304 pdu_data_loc[2] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
11305 (testdata_size - testdata_indx),
11306 sdu_timeoffset,
11307 &rx_pdu_meta_buf.pdu_meta);
11308
11309 /* Set callback function return values */
11310 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
11311 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
11312 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
11313 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
11314
11315 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
11316
11317 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
11318
11319 /* SDU 0 -------------------------------------------------------------*/
11320 /* Test recombine (Black Box) */
11321 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
11322 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
11323
11324 /* A new SDU should not be allocated */
11325
11326 /* SDU payload should be written */
11327 ZASSERT_ISOAL_SDU_WRITE_TEST(history[1],
11328 &rx_sdu_frag_buf[0], /* SDU buffer */
11329 sdu_written, /* SDU written */
11330 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
11331 /* PDU payload */
11332 10); /* Size */
11333
11334 /* SDU should be emitted */
11335 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
11336 &isoal_global.sink_state[sink_hdl], /* Sink */
11337 BT_ISO_SINGLE, /* Frag state */
11338 sdu_size[0], /* Frag size */
11339 ISOAL_SDU_STATUS_VALID, /* Frag status */
11340 sdu_timestamp[0], /* Timestamp */
11341 seqn, /* Seq. number */
11342 sdu_buffer[0].dbuf, /* Buffer */
11343 sdu_buffer[0].size, /* Buffer size */
11344 total_sdu_size, /* Total size */
11345 collated_status); /* SDU status */
11346
11347 /* SDU 1 -------------------------------------------------------------*/
11348 sdu_written = 0;
11349 seqn++;
11350 /* A new SDU should be allocated */
11351 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1],
11352 &isoal_global.sink_state[sink_hdl], /* Sink */
11353 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11354
11355 /* SDU payload should be written */
11356 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
11357 &rx_sdu_frag_buf[1], /* SDU buffer */
11358 sdu_written, /* SDU written */
11359 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[2]],
11360 /* PDU payload */
11361 (testdata_size - testdata_indx)); /* Size */
11362
11363 /* SDU should not be emitted */
11364
11365 /* Test recombine (White Box) */
11366 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
11367 ISOAL_CONTINUE,
11368 "FSM state %s should be %s!",
11369 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
11370 FSM_TO_STR(ISOAL_CONTINUE));
11371
11372 /* PDU 2 -------------------------------------------------------------*/
11373 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11374
11375 payload_number++;
11376 testdata_indx = testdata_size;
11377 testdata_size += 10;
11378 /* SDU size does not change */
11379 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]);
11380 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS);
11381
11382 isoal_test_create_framed_pdu_base(payload_number,
11383 pdu_timestamp,
11384 ISOAL_PDU_STATUS_ERRORS,
11385 &rx_pdu_meta_buf.pdu_meta);
11386 pdu_data_loc[3] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
11387 (testdata_size - testdata_indx),
11388 &rx_pdu_meta_buf.pdu_meta);
11389
11390 /* Set callback function return values */
11391 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
11392
11393 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
11394
11395 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
11396
11397 /* SDU 1 -------------------------------------------------------------*/
11398 /* Test recombine (Black Box) */
11399 /* A new SDU should not be allocated */
11400
11401 /* SDU payload should not be written */
11402
11403 /* SDU should be emitted */
11404 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
11405 &isoal_global.sink_state[sink_hdl], /* Sink */
11406 BT_ISO_SINGLE, /* Frag state */
11407 sdu_size[1], /* Frag size */
11408 ISOAL_SDU_STATUS_ERRORS, /* Frag status */
11409 sdu_timestamp[1], /* Timestamp */
11410 seqn, /* Seq. number */
11411 sdu_buffer[1].dbuf, /* Buffer */
11412 sdu_buffer[1].size, /* Buffer size */
11413 total_sdu_size, /* Total size */
11414 collated_status); /* SDU status */
11415
11416 /* Test recombine (White Box) */
11417 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
11418 ISOAL_ERR_SPOOL,
11419 "FSM state %s should be %s!",
11420 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
11421 FSM_TO_STR(ISOAL_ERR_SPOOL));
11422
11423 /* SDU 2 -------------------------------------------------------------*/
11424 /* Missing */
11425 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
11426 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11427
11428 /* PDU 3 -------------------------------------------------------------*/
11429 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11430 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
11431
11432 payload_number++;
11433 pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US);
11434
11435 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true);
11436 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11437 testdata_indx = testdata_size;
11438 testdata_size += 13;
11439 sdu_size[0] = 13;
11440
11441 isoal_test_create_framed_pdu_base(payload_number,
11442 pdu_timestamp,
11443 ISOAL_PDU_STATUS_VALID,
11444 &rx_pdu_meta_buf.pdu_meta);
11445 pdu_data_loc[4] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
11446 (testdata_size - testdata_indx),
11447 sdu_timeoffset,
11448 &rx_pdu_meta_buf.pdu_meta);
11449
11450 /* Set callback function return values */
11451 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
11452 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
11453 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
11454 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
11455 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
11456
11457 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
11458
11459 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
11460
11461 /* SDU 2 -------------------------------------------------------------*/
11462 seqn++;
11463 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
11464 collated_status =
11465 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
11466 /* Test recombine (Black Box) */
11467 /* A new SDU should be allocated */
11468 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2],
11469 &isoal_global.sink_state[sink_hdl], /* Sink */
11470 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11471
11472 /* SDU payload should not be written */
11473
11474 /* SDU should be emitted */
11475 ZASSERT_ISOAL_SDU_EMIT_TEST(history[2],
11476 &isoal_global.sink_state[sink_hdl], /* Sink */
11477 BT_ISO_SINGLE, /* Frag state */
11478 0, /* Frag size */
11479 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
11480 sdu_timestamp[1], /* Timestamp */
11481 seqn, /* Seq. number */
11482 sdu_buffer[1].dbuf, /* Buffer */
11483 sdu_buffer[1].size, /* Buffer size */
11484 total_sdu_size, /* Total size */
11485 collated_status); /* SDU status */
11486
11487 /* SDU 3 -------------------------------------------------------------*/
11488 sdu_written = 0;
11489 seqn++;
11490 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
11491 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
11492 /* Test recombine (Black Box) */
11493 /* A new SDU should be allocated */
11494 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
11495 &isoal_global.sink_state[sink_hdl], /* Sink */
11496 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11497
11498 /* SDU payload should be written */
11499 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
11500 &rx_sdu_frag_buf[0], /* SDU buffer */
11501 sdu_written, /* SDU written */
11502 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[4]],
11503 /* PDU payload */
11504 (testdata_size - testdata_indx)); /* Size */
11505
11506 /* SDU should be emitted */
11507 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
11508 &isoal_global.sink_state[sink_hdl], /* Sink */
11509 BT_ISO_SINGLE, /* Frag state */
11510 sdu_size[0], /* Frag size */
11511 ISOAL_SDU_STATUS_VALID, /* Frag status */
11512 sdu_timestamp[0], /* Timestamp */
11513 seqn, /* Seq. number */
11514 sdu_buffer[0].dbuf, /* Buffer */
11515 sdu_buffer[0].size, /* Buffer size */
11516 total_sdu_size, /* Total size */
11517 collated_status); /* SDU status */
11518
11519 /* Test recombine (White Box) */
11520 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
11521 ISOAL_START,
11522 "FSM state %s should be %s!",
11523 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
11524 FSM_TO_STR(ISOAL_START));
11525 }
11526
11527 /**
11528 * Test Suite : RX framed PDU recombination
11529 *
11530 * Tests handling missing PDU (sequence) errors in the middle of a stream, where
11531 * the errors occur across the end of one SDU and into the start of the next
11532 * SDU.
11533 *
11534 * Expected Sequence:
11535 * -- Total of 4 SDUs released across 2 events
11536 * -- Event 1: PDU0 Valid SDU 0 Framed Start
11537 * PDU1 Missing SDU 0 Framed End
11538 * SDU 1 Framed Start
11539 * -----> SDU 0 Valid (Released)
11540 * PDU2 Valid SDU 1 Framed End
11541 * Missing SDU 2
11542 * Event 2: PDU3 Valid SDU 3 Framed Single
11543 * -----> SDU 1 Lost (Released)
11544 * -----> SDU 2 Lost (Released)
11545 * -----> SDU 3 Valid (Released)
11546 * PDU4 N/A
11547 * PDU5 N/A
11548 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_dbl_sdu_seq_err1)11549 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1)
11550 {
11551 struct rx_sdu_frag_buffer rx_sdu_frag_buf[3];
11552 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
11553 struct isoal_sdu_buffer sdu_buffer[3];
11554 isoal_sdu_status_t collated_status;
11555 isoal_sink_handle_t sink_hdl;
11556 isoal_sdu_len_t sdu_size[2];
11557 uint32_t stream_sync_delay;
11558 uint32_t group_sync_delay;
11559 uint8_t iso_interval_int;
11560 uint32_t sdu_timestamp[3];
11561 uint16_t pdu_data_loc[5];
11562 uint32_t iso_interval_us;
11563 uint64_t payload_number;
11564 uint16_t total_sdu_size;
11565 uint32_t sdu_timeoffset;
11566 uint32_t pdu_timestamp;
11567 uint16_t testdata_indx;
11568 uint16_t testdata_size;
11569 uint32_t sdu_interval;
11570 isoal_sdu_cnt_t seqn;
11571 uint8_t testdata[63];
11572 isoal_status_t err;
11573 uint32_t latency;
11574 uint8_t role;
11575 uint8_t BN;
11576 uint8_t FT;
11577
11578 /* Settings */
11579 role = ISOAL_ROLE_PERIPHERAL;
11580 iso_interval_int = 1;
11581 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
11582 sdu_interval = (iso_interval_us / 3) + 5;
11583 BN = 3;
11584 FT = 1;
11585 stream_sync_delay = iso_interval_us - 200;
11586 group_sync_delay = iso_interval_us - 50;
11587
11588 /* PDU 0 -------------------------------------------------------------*/
11589 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11590 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
11591 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
11592 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]);
11593 init_test_data_buffer(testdata, 63);
11594 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
11595
11596 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
11597 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
11598 sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2];
11599 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
11600 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
11601 sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
11602 payload_number = 1000 * BN;
11603 pdu_timestamp = 9249;
11604 latency = calc_rx_latency_by_role(role,
11605 true,
11606 FT,
11607 sdu_interval,
11608 iso_interval_int,
11609 stream_sync_delay,
11610 group_sync_delay);
11611 sdu_timeoffset = group_sync_delay - 50;
11612 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11613 seqn = 0;
11614 testdata_indx = 0;
11615 testdata_size = 13;
11616 sdu_size[0] = 13;
11617
11618 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
11619 role, /* Role */
11620 true, /* Framed */
11621 BN, /* BN */
11622 FT, /* FT */
11623 sdu_interval, /* SDU Interval */
11624 iso_interval_int, /* ISO Interval */
11625 stream_sync_delay, /* Stream Sync Delay */
11626 group_sync_delay); /* Group Sync Delay */
11627
11628 isoal_test_create_framed_pdu_base(payload_number,
11629 pdu_timestamp,
11630 ISOAL_PDU_STATUS_VALID,
11631 &rx_pdu_meta_buf.pdu_meta);
11632 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
11633 (testdata_size - testdata_indx),
11634 sdu_timeoffset,
11635 &rx_pdu_meta_buf.pdu_meta);
11636
11637 /* Set callback function return values */
11638 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
11639 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
11640 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
11641
11642 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
11643
11644 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
11645
11646 /* SDU 0 -------------------------------------------------------------*/
11647 /* Test recombine (Black Box) */
11648 /* A new SDU should be allocated */
11649 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
11650 &isoal_global.sink_state[sink_hdl], /* Sink */
11651 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11652
11653 /* SDU payload should be written */
11654 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
11655 &rx_sdu_frag_buf, /* SDU buffer */
11656 0, /* SDU written */
11657 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
11658 /* PDU payload */
11659 (testdata_size - testdata_indx)); /* Size */
11660
11661 /* SDU should not be emitted */
11662 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
11663
11664 /* Test recombine (White Box) */
11665 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
11666 ISOAL_CONTINUE,
11667 "FSM state %s should be %s!",
11668 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
11669 FSM_TO_STR(ISOAL_CONTINUE));
11670
11671 /* PDU 2 -------------------------------------------------------------*/
11672 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11673
11674 payload_number++;
11675 testdata_indx = testdata_size;
11676 testdata_size += 10;
11677 /* No change in SDU 1 size */
11678
11679 /* SDU 1 -------------------------------------------------------------*/
11680 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
11681 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11682
11683 testdata_indx = testdata_size;
11684 testdata_size += 17;
11685 sdu_size[1] = 0;
11686
11687 /* PDU 3 -------------------------------------------------------------*/
11688 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11689
11690 payload_number++;
11691 testdata_indx = testdata_size;
11692 testdata_size += 10;
11693 /* SDU size does not change */
11694 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
11695 collated_status =
11696 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
11697
11698 isoal_test_create_framed_pdu_base(payload_number,
11699 pdu_timestamp,
11700 ISOAL_PDU_STATUS_VALID,
11701 &rx_pdu_meta_buf.pdu_meta);
11702 pdu_data_loc[3] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
11703 (testdata_size - testdata_indx),
11704 &rx_pdu_meta_buf.pdu_meta);
11705
11706 /* Set callback function return values */
11707 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
11708
11709 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
11710
11711 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
11712
11713 /* SDU 0 -------------------------------------------------------------*/
11714 /* Test recombine (Black Box) */
11715 /* A new SDU should not be allocated */
11716 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1);
11717
11718 /* SDU payload should not be written */
11719 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1);
11720
11721 /* SDU should be emitted */
11722 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
11723 &isoal_global.sink_state[sink_hdl], /* Sink */
11724 BT_ISO_SINGLE, /* Frag state */
11725 sdu_size[0], /* Frag size */
11726 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
11727 sdu_timestamp[0], /* Timestamp */
11728 seqn, /* Seq. number */
11729 sdu_buffer[0].dbuf, /* Buffer */
11730 sdu_buffer[0].size, /* Buffer size */
11731 total_sdu_size, /* Total size */
11732 collated_status); /* SDU status */
11733
11734 /* SDU 1 -------------------------------------------------------------*/
11735 /* Lost */
11736
11737 /* SDU 2 -------------------------------------------------------------*/
11738 /* Missing */
11739 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
11740 sdu_timestamp[2] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11741
11742 /* Test recombine (White Box) */
11743 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
11744 ISOAL_ERR_SPOOL,
11745 "FSM state %s should be %s!",
11746 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
11747 FSM_TO_STR(ISOAL_ERR_SPOOL));
11748
11749 /* PDU 4 -------------------------------------------------------------*/
11750 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11751 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
11752
11753 payload_number++;
11754 pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US);
11755
11756 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true);
11757 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11758 testdata_indx = testdata_size;
11759 testdata_size += 13;
11760 sdu_size[0] = 13;
11761 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
11762 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
11763
11764 isoal_test_create_framed_pdu_base(payload_number,
11765 pdu_timestamp,
11766 ISOAL_PDU_STATUS_VALID,
11767 &rx_pdu_meta_buf.pdu_meta);
11768 pdu_data_loc[4] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
11769 (testdata_size - testdata_indx),
11770 sdu_timeoffset,
11771 &rx_pdu_meta_buf.pdu_meta);
11772
11773 /* Set callback function return values */
11774 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
11775 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]);
11776 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
11777 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
11778 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
11779 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
11780
11781 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
11782
11783 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
11784
11785 /* SDU 1 -------------------------------------------------------------*/
11786 seqn++;
11787 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
11788 collated_status =
11789 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
11790 /* Test recombine (Black Box) */
11791 /* A new SDU should be allocated */
11792 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1],
11793 &isoal_global.sink_state[sink_hdl], /* Sink */
11794 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11795
11796 /* SDU should not be written */
11797
11798 /* SDU should be emitted */
11799 ZASSERT_ISOAL_SDU_EMIT_TEST(history[1],
11800 &isoal_global.sink_state[sink_hdl], /* Sink */
11801 BT_ISO_SINGLE, /* Frag state */
11802 0, /* Frag size */
11803 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
11804 sdu_timestamp[1], /* Timestamp */
11805 seqn, /* Seq. number */
11806 sdu_buffer[1].dbuf, /* Buffer */
11807 sdu_buffer[1].size, /* Buffer size */
11808 total_sdu_size, /* Total size */
11809 collated_status); /* SDU status */
11810
11811 /* SDU 2 -------------------------------------------------------------*/
11812 seqn++;
11813 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
11814 collated_status =
11815 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
11816 /* Test recombine (Black Box) */
11817 /* A new SDU should be allocated */
11818 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2],
11819 &isoal_global.sink_state[sink_hdl], /* Sink */
11820 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11821
11822 /* SDU should not be written */
11823
11824 /* SDU should be emitted */
11825 ZASSERT_ISOAL_SDU_EMIT_TEST(history[2],
11826 &isoal_global.sink_state[sink_hdl], /* Sink */
11827 BT_ISO_SINGLE, /* Frag state */
11828 0, /* Frag size */
11829 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
11830 sdu_timestamp[2], /* Timestamp */
11831 seqn, /* Seq. number */
11832 sdu_buffer[2].dbuf, /* Buffer */
11833 sdu_buffer[2].size, /* Buffer size */
11834 total_sdu_size, /* Total size */
11835 collated_status); /* SDU status */
11836
11837 /* SDU 3 -------------------------------------------------------------*/
11838 seqn++;
11839 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
11840 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
11841 /* Test recombine (Black Box) */
11842 /* A new SDU should be allocated */
11843 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
11844 &isoal_global.sink_state[sink_hdl], /* Sink */
11845 &rx_pdu_meta_buf.pdu_meta); /* PDU */
11846
11847 /* SDU payload should be written */
11848 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
11849 &rx_sdu_frag_buf[0], /* SDU buffer */
11850 0, /* SDU written */
11851 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[4]],
11852 /* PDU payload */
11853 (testdata_size - testdata_indx)); /* Size */
11854
11855 /* SDU should be emitted */
11856 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
11857 &isoal_global.sink_state[sink_hdl], /* Sink */
11858 BT_ISO_SINGLE, /* Frag state */
11859 sdu_size[0], /* Frag size */
11860 ISOAL_SDU_STATUS_VALID, /* Frag status */
11861 sdu_timestamp[0], /* Timestamp */
11862 seqn, /* Seq. number */
11863 sdu_buffer[0].dbuf, /* Buffer */
11864 sdu_buffer[0].size, /* Buffer size */
11865 total_sdu_size, /* Total size */
11866 collated_status); /* SDU status */
11867
11868 /* Test recombine (White Box) */
11869 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
11870 ISOAL_START,
11871 "FSM state %s should be %s!",
11872 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
11873 FSM_TO_STR(ISOAL_ERR_SPOOL));
11874 }
11875
11876 /**
11877 * Test Suite : RX framed PDU recombination
11878 *
11879 * Tests handling missing PDU (sequence) errors followed by bit errors in the
11880 * middle of a stream, where the errors occur across the end of one SDU and
11881 * into the start of the next SDU.
11882 *
11883 * Expected Sequence:
11884 * -- Total of 4 SDUs released across 2 events
11885 * -- Event 1: PDU0 Valid SDU 0 Framed Start
11886 * PDU1 Missing SDU 0 Framed End
11887 * SDU 1 Framed Start
11888 * -----> SDU 0 Lost (Released)
11889 * PDU2 Errors SDU 1 Framed End
11890 * Missing SDU 2
11891 * Event 2: PDU3 Valid SDU 3 Framed Single
11892 * -----> SDU 1 Lost (Released)
11893 * -----> SDU 2 Lost (Released)
11894 * -----> SDU 3 Valid (Released)
11895 * PDU4 N/A
11896 * PDU5 N/A
11897 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1)11898 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1)
11899 {
11900 struct rx_sdu_frag_buffer rx_sdu_frag_buf[3];
11901 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
11902 struct isoal_sdu_buffer sdu_buffer[3];
11903 isoal_sdu_status_t collated_status;
11904 isoal_sink_handle_t sink_hdl;
11905 uint32_t stream_sync_delay;
11906 uint32_t group_sync_delay;
11907 isoal_sdu_len_t sdu_size[2];
11908 uint8_t iso_interval_int;
11909 uint32_t sdu_timestamp[3];
11910 uint16_t pdu_data_loc[5];
11911 uint32_t iso_interval_us;
11912 uint64_t payload_number;
11913 uint16_t total_sdu_size;
11914 uint32_t sdu_timeoffset;
11915 uint32_t pdu_timestamp;
11916 uint16_t testdata_indx;
11917 uint16_t testdata_size;
11918 uint32_t sdu_interval;
11919 isoal_sdu_cnt_t seqn;
11920 uint8_t testdata[63];
11921 isoal_status_t err;
11922 uint32_t latency;
11923 uint8_t role;
11924 uint8_t BN;
11925 uint8_t FT;
11926
11927 /* Settings */
11928 role = ISOAL_ROLE_PERIPHERAL;
11929 iso_interval_int = 1;
11930 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
11931 sdu_interval = (iso_interval_us / 3) + 5;
11932 BN = 3;
11933 FT = 1;
11934 stream_sync_delay = iso_interval_us - 200;
11935 group_sync_delay = iso_interval_us - 50;
11936
11937 /* PDU 1 -------------------------------------------------------------*/
11938 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
11939 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
11940 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
11941 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]);
11942 init_test_data_buffer(testdata, 63);
11943 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
11944
11945 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
11946 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
11947 sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2];
11948 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
11949 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
11950 sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
11951 payload_number = 1000 * BN;
11952 pdu_timestamp = 9249;
11953 latency = calc_rx_latency_by_role(role,
11954 true,
11955 FT,
11956 sdu_interval,
11957 iso_interval_int,
11958 stream_sync_delay,
11959 group_sync_delay);
11960 sdu_timeoffset = group_sync_delay - 50;
11961 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
11962 seqn = 0;
11963 testdata_indx = 0;
11964 testdata_size = 13;
11965 sdu_size[0] = 13;
11966
11967 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
11968 role, /* Role */
11969 true, /* Framed */
11970 BN, /* BN */
11971 FT, /* FT */
11972 sdu_interval, /* SDU Interval */
11973 iso_interval_int, /* ISO Interval */
11974 stream_sync_delay, /* Stream Sync Delay */
11975 group_sync_delay); /* Group Sync Delay */
11976
11977 isoal_test_create_framed_pdu_base(payload_number,
11978 pdu_timestamp,
11979 ISOAL_PDU_STATUS_VALID,
11980 &rx_pdu_meta_buf.pdu_meta);
11981 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
11982 (testdata_size - testdata_indx),
11983 sdu_timeoffset,
11984 &rx_pdu_meta_buf.pdu_meta);
11985
11986 /* Set callback function return values */
11987 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
11988 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
11989 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
11990 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
11991
11992 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
11993
11994 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
11995
11996 /* SDU 0 -------------------------------------------------------------*/
11997 /* Test recombine (Black Box) */
11998 /* A new SDU should be allocated */
11999 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
12000 &isoal_global.sink_state[sink_hdl], /* Sink */
12001 &rx_pdu_meta_buf.pdu_meta); /* PDU */
12002
12003 /* SDU payload should be written */
12004 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
12005 &rx_sdu_frag_buf[0], /* SDU buffer */
12006 0, /* SDU written */
12007 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
12008 /* PDU payload */
12009 (testdata_size - testdata_indx)); /* Size */
12010
12011 /* SDU should not be emitted */
12012 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
12013
12014 /* Test recombine (White Box) */
12015 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
12016 ISOAL_CONTINUE,
12017 "FSM state %s should be %s!",
12018 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
12019 FSM_TO_STR(ISOAL_CONTINUE));
12020
12021 /* PDU 2 -------------------------------------------------------------*/
12022 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
12023
12024 payload_number++;
12025 testdata_indx = testdata_size;
12026 testdata_size += 10;
12027 /* No change in SDU 0 size */
12028
12029 /* SDU 1 -------------------------------------------------------------*/
12030 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
12031 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
12032
12033 testdata_indx = testdata_size;
12034 testdata_size += 17;
12035 sdu_size[1] = 0;
12036
12037 /* PDU 3 -------------------------------------------------------------*/
12038 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
12039
12040 payload_number++;
12041 testdata_indx = testdata_size;
12042 testdata_size += 10;
12043 /* SDU size does not change */
12044 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
12045 collated_status =
12046 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
12047
12048 isoal_test_create_framed_pdu_base(payload_number,
12049 pdu_timestamp,
12050 ISOAL_PDU_STATUS_ERRORS,
12051 &rx_pdu_meta_buf.pdu_meta);
12052 pdu_data_loc[3] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
12053 (testdata_size - testdata_indx),
12054 &rx_pdu_meta_buf.pdu_meta);
12055
12056 /* Set callback function return values */
12057 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
12058
12059 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
12060
12061 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
12062
12063 /* SDU 0 -------------------------------------------------------------*/
12064 /* Test recombine (Black Box) */
12065 /* A new SDU should not be allocated */
12066 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1);
12067
12068 /* SDU payload should not be written */
12069 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1);
12070
12071 /* SDU should be emitted */
12072 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
12073 &isoal_global.sink_state[sink_hdl], /* Sink */
12074 BT_ISO_SINGLE, /* Frag state */
12075 sdu_size[0], /* Frag size */
12076 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
12077 sdu_timestamp[0], /* Timestamp */
12078 seqn, /* Seq. number */
12079 sdu_buffer[0].dbuf, /* Buffer */
12080 sdu_buffer[0].size, /* Buffer size */
12081 total_sdu_size, /* Total size */
12082 collated_status); /* SDU status */
12083
12084 /* SDU 1 -------------------------------------------------------------*/
12085 /* Lost */
12086
12087 /* SDU 2 -------------------------------------------------------------*/
12088 /* Missing */
12089 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
12090 sdu_timestamp[2] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
12091
12092 /* Test recombine (White Box) */
12093 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
12094 ISOAL_ERR_SPOOL,
12095 "FSM state %s should be %s!",
12096 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
12097 FSM_TO_STR(ISOAL_ERR_SPOOL));
12098
12099 /* PDU 4 -------------------------------------------------------------*/
12100 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
12101 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
12102
12103 payload_number++;
12104 pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US);
12105
12106 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true);
12107 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
12108 testdata_indx = testdata_size;
12109 testdata_size += 13;
12110 sdu_size[0] = 13;
12111
12112 isoal_test_create_framed_pdu_base(payload_number,
12113 pdu_timestamp,
12114 ISOAL_PDU_STATUS_VALID,
12115 &rx_pdu_meta_buf.pdu_meta);
12116 pdu_data_loc[4] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
12117 (testdata_size - testdata_indx),
12118 sdu_timeoffset,
12119 &rx_pdu_meta_buf.pdu_meta);
12120
12121 /* Set callback function return values */
12122 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
12123 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]);
12124 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
12125 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
12126 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
12127 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
12128
12129 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
12130
12131 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
12132
12133 /* SDU 1 -------------------------------------------------------------*/
12134 seqn++;
12135 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
12136 collated_status =
12137 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
12138 /* Test recombine (Black Box) */
12139 /* A new SDU should be allocated */
12140 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1],
12141 &isoal_global.sink_state[sink_hdl], /* Sink */
12142 &rx_pdu_meta_buf.pdu_meta); /* PDU */
12143
12144 /* SDU should be emitted */
12145 ZASSERT_ISOAL_SDU_EMIT_TEST(history[1],
12146 &isoal_global.sink_state[sink_hdl], /* Sink */
12147 BT_ISO_SINGLE, /* Frag state */
12148 0, /* Frag size */
12149 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
12150 sdu_timestamp[1], /* Timestamp */
12151 seqn, /* Seq. number */
12152 sdu_buffer[1].dbuf, /* Buffer */
12153 sdu_buffer[1].size, /* Buffer size */
12154 total_sdu_size, /* Total size */
12155 collated_status); /* SDU status */
12156
12157 /* SDU 2 -------------------------------------------------------------*/
12158 seqn++;
12159 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
12160 collated_status =
12161 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
12162 /* Test recombine (Black Box) */
12163 /* A new SDU should be allocated */
12164 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2],
12165 &isoal_global.sink_state[sink_hdl], /* Sink */
12166 &rx_pdu_meta_buf.pdu_meta); /* PDU */
12167
12168 /* SDU should be emitted */
12169 ZASSERT_ISOAL_SDU_EMIT_TEST(history[2],
12170 &isoal_global.sink_state[sink_hdl], /* Sink */
12171 BT_ISO_SINGLE, /* Frag state */
12172 0, /* Frag size */
12173 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
12174 sdu_timestamp[2], /* Timestamp */
12175 seqn, /* Seq. number */
12176 sdu_buffer[2].dbuf, /* Buffer */
12177 sdu_buffer[2].size, /* Buffer size */
12178 total_sdu_size, /* Total size */
12179 collated_status); /* SDU status */
12180
12181 /* SDU 3 -------------------------------------------------------------*/
12182 seqn++;
12183 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
12184 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
12185 /* Test recombine (Black Box) */
12186 /* A new SDU should be allocated */
12187 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
12188 &isoal_global.sink_state[sink_hdl], /* Sink */
12189 &rx_pdu_meta_buf.pdu_meta); /* PDU */
12190
12191 /* SDU payload should be written */
12192 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
12193 &rx_sdu_frag_buf, /* SDU buffer */
12194 0, /* SDU written */
12195 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[4]],
12196 /* PDU payload */
12197 (testdata_size - testdata_indx)); /* Size */
12198
12199 /* SDU should be emitted */
12200 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
12201 &isoal_global.sink_state[sink_hdl], /* Sink */
12202 BT_ISO_SINGLE, /* Frag state */
12203 sdu_size[0], /* Frag size */
12204 ISOAL_SDU_STATUS_VALID, /* Frag status */
12205 sdu_timestamp[0], /* Timestamp */
12206 seqn, /* Seq. number */
12207 sdu_buffer[0].dbuf, /* Buffer */
12208 sdu_buffer[0].size, /* Buffer size */
12209 total_sdu_size, /* Total size */
12210 collated_status); /* SDU status */
12211
12212 /* Test recombine (White Box) */
12213 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
12214 ISOAL_START,
12215 "FSM state %s should be %s!",
12216 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
12217 FSM_TO_STR(ISOAL_START));
12218 }
12219
12220 /**
12221 * Test Suite : RX framed PDU recombination
12222 *
12223 * Tests recombination of a single SDU from a single segmented PDU which is
12224 * invalid as it contains multiple segments from the same SDU.
12225 */
ZTEST(test_rx_framed,test_rx_framed_single_invalid_pdu_single_sdu)12226 ZTEST(test_rx_framed, test_rx_framed_single_invalid_pdu_single_sdu)
12227 {
12228 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
12229 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
12230 struct isoal_sdu_buffer sdu_buffer;
12231 isoal_sdu_status_t collated_status;
12232 isoal_sink_handle_t sink_hdl;
12233 uint32_t stream_sync_delay;
12234 uint32_t group_sync_delay;
12235 isoal_sdu_len_t sdu_size;
12236 uint8_t iso_interval_int;
12237 uint16_t pdu_data_loc[5];
12238 uint64_t payload_number;
12239 uint16_t total_sdu_size;
12240 uint16_t sdu_written = 0;
12241 uint32_t sdu_timeoffset;
12242 uint32_t pdu_timestamp;
12243 uint32_t sdu_timestamp;
12244 uint16_t testdata_indx;
12245 uint16_t testdata_size;
12246 uint32_t sdu_interval;
12247 isoal_sdu_cnt_t seqn;
12248 uint8_t testdata[25];
12249 isoal_status_t err;
12250 uint32_t latency;
12251 uint8_t role;
12252 uint8_t BN;
12253 uint8_t FT;
12254
12255 /* Settings */
12256 role = ISOAL_ROLE_PERIPHERAL;
12257 iso_interval_int = 1;
12258 sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5;
12259 BN = 3;
12260 FT = 1;
12261 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
12262 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
12263
12264 /* PDU 1 -------------------------------------------------------------*/
12265 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
12266 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
12267 init_test_data_buffer(testdata, 25);
12268 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
12269
12270 sdu_buffer.dbuf = &rx_sdu_frag_buf;
12271 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
12272 payload_number = 1000 * BN;
12273 pdu_timestamp = 9249;
12274 latency = calc_rx_latency_by_role(role,
12275 true,
12276 FT,
12277 sdu_interval,
12278 iso_interval_int,
12279 stream_sync_delay,
12280 group_sync_delay);
12281 sdu_timeoffset = group_sync_delay - 50;
12282 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
12283 seqn = 0;
12284 testdata_indx = 0;
12285 testdata_size = 13;
12286 sdu_size = 13;
12287
12288 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
12289 role, /* Role */
12290 true, /* Framed */
12291 BN, /* BN */
12292 FT, /* FT */
12293 sdu_interval, /* SDU Interval */
12294 iso_interval_int, /* ISO Interval */
12295 stream_sync_delay, /* Stream Sync Delay */
12296 group_sync_delay); /* Group Sync Delay */
12297
12298 isoal_test_create_framed_pdu_base(payload_number,
12299 pdu_timestamp,
12300 ISOAL_PDU_STATUS_VALID,
12301 &rx_pdu_meta_buf.pdu_meta);
12302 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
12303 (testdata_size - testdata_indx),
12304 sdu_timeoffset,
12305 &rx_pdu_meta_buf.pdu_meta);
12306
12307 testdata_indx = testdata_size;
12308 testdata_size += 5;
12309 sdu_size += 5;
12310
12311 pdu_data_loc[1] = isoal_test_add_framed_pdu_cont(&testdata[testdata_indx],
12312 (testdata_size - testdata_indx),
12313 &rx_pdu_meta_buf.pdu_meta);
12314
12315 testdata_indx = testdata_size;
12316 testdata_size += 7;
12317 sdu_size += 7;
12318 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
12319 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
12320
12321 pdu_data_loc[2] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
12322 (testdata_size - testdata_indx),
12323 &rx_pdu_meta_buf.pdu_meta);
12324
12325 /* Set callback function return values */
12326 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
12327 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
12328 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
12329 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
12330
12331 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
12332
12333 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
12334
12335 /* Test recombine (Black Box) */
12336 /* A new SDU should be allocated */
12337 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
12338 &isoal_global.sink_state[sink_hdl], /* Sink */
12339 &rx_pdu_meta_buf.pdu_meta); /* PDU */
12340
12341 /* SDU payload should be written */
12342 ZASSERT_ISOAL_SDU_WRITE_TEST(history[0],
12343 &rx_sdu_frag_buf, /* SDU buffer */
12344 sdu_written, /* SDU written */
12345 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
12346 /* PDU payload */
12347 13); /* Size */
12348 sdu_written += 13;
12349
12350 ZASSERT_ISOAL_SDU_WRITE_TEST(history[1],
12351 &rx_sdu_frag_buf, /* SDU buffer */
12352 sdu_written, /* SDU written */
12353 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
12354 /* PDU payload */
12355 5); /* Size */
12356 sdu_written += 5;
12357
12358 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
12359 &rx_sdu_frag_buf, /* SDU buffer */
12360 sdu_written, /* SDU written */
12361 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[2]],
12362 /* PDU payload */
12363 (testdata_size - testdata_indx)); /* Size */
12364
12365 /* SDU should be emitted */
12366 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
12367 &isoal_global.sink_state[sink_hdl], /* Sink */
12368 BT_ISO_SINGLE, /* Frag state */
12369 sdu_size, /* Frag size */
12370 ISOAL_SDU_STATUS_VALID, /* Frag status */
12371 sdu_timestamp, /* Timestamp */
12372 seqn, /* Seq. number */
12373 sdu_buffer.dbuf, /* Buffer */
12374 sdu_buffer.size, /* Buffer size */
12375 total_sdu_size, /* Total size */
12376 collated_status); /* SDU status */
12377
12378 /* Test recombine (White Box) */
12379 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
12380 ISOAL_START,
12381 "FSM state %s should be %s!",
12382 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
12383 FSM_TO_STR(ISOAL_START));
12384 }
12385
12386 /**
12387 * Test Suite : RX framed PDU recombination
12388 *
12389 * Tests recombination of a single SDU from a single segmented PDU which is
12390 * invalid as it contains multiple segments from the same SDU with incorrect
12391 * header info
12392 */
ZTEST(test_rx_framed,test_rx_framed_single_invalid_pdu_single_sdu_hdr_err)12393 ZTEST(test_rx_framed, test_rx_framed_single_invalid_pdu_single_sdu_hdr_err)
12394 {
12395 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
12396 struct rx_sdu_frag_buffer rx_sdu_frag_buf;
12397 struct isoal_sdu_buffer sdu_buffer;
12398 isoal_sdu_status_t collated_status;
12399 isoal_sink_handle_t sink_hdl;
12400 uint32_t stream_sync_delay;
12401 uint32_t group_sync_delay;
12402 isoal_sdu_len_t sdu_size;
12403 uint8_t iso_interval_int;
12404 uint16_t pdu_data_loc[5];
12405 uint64_t payload_number;
12406 uint16_t total_sdu_size;
12407 uint16_t sdu_written = 0;
12408 uint32_t sdu_timeoffset;
12409 uint32_t pdu_timestamp;
12410 uint32_t sdu_timestamp;
12411 uint16_t testdata_indx;
12412 uint16_t testdata_size;
12413 uint32_t sdu_interval;
12414 isoal_sdu_cnt_t seqn;
12415 uint8_t testdata[21];
12416 isoal_status_t err;
12417 uint32_t latency;
12418 uint8_t role;
12419 uint8_t BN;
12420 uint8_t FT;
12421
12422 /* Settings */
12423 role = ISOAL_ROLE_PERIPHERAL;
12424 iso_interval_int = 1;
12425 sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5;
12426 BN = 3;
12427 FT = 1;
12428 stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200;
12429 group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50;
12430
12431 /* PDU 1 -------------------------------------------------------------*/
12432 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
12433 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf);
12434 init_test_data_buffer(testdata, 21);
12435 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
12436
12437 sdu_buffer.dbuf = &rx_sdu_frag_buf;
12438 sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
12439 payload_number = 1000 * BN;
12440 pdu_timestamp = 9249;
12441 latency = calc_rx_latency_by_role(role,
12442 true,
12443 FT,
12444 sdu_interval,
12445 iso_interval_int,
12446 stream_sync_delay,
12447 group_sync_delay);
12448 sdu_timeoffset = group_sync_delay - 50;
12449 sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
12450 seqn = 0;
12451 testdata_indx = 0;
12452 testdata_size = 3;
12453 sdu_size = 3;
12454
12455 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
12456 role, /* Role */
12457 true, /* Framed */
12458 BN, /* BN */
12459 FT, /* FT */
12460 sdu_interval, /* SDU Interval */
12461 iso_interval_int, /* ISO Interval */
12462 stream_sync_delay, /* Stream Sync Delay */
12463 group_sync_delay); /* Group Sync Delay */
12464
12465 isoal_test_create_framed_pdu_base(payload_number,
12466 pdu_timestamp,
12467 ISOAL_PDU_STATUS_VALID,
12468 &rx_pdu_meta_buf.pdu_meta);
12469 pdu_data_loc[0] = isoal_test_add_framed_pdu_cont(&testdata[testdata_indx],
12470 (testdata_size - testdata_indx),
12471 &rx_pdu_meta_buf.pdu_meta);
12472
12473 testdata_indx = testdata_size;
12474 testdata_size += 4;
12475 sdu_size += 4;
12476
12477 pdu_data_loc[1] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
12478 (testdata_size - testdata_indx),
12479 sdu_timeoffset,
12480 &rx_pdu_meta_buf.pdu_meta);
12481
12482 testdata_indx = testdata_size;
12483 testdata_size += 4;
12484 sdu_size += 4;
12485
12486 pdu_data_loc[2] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
12487 (testdata_size - testdata_indx),
12488 sdu_timeoffset,
12489 &rx_pdu_meta_buf.pdu_meta);
12490
12491 testdata_indx = testdata_size;
12492 testdata_size += 4;
12493 sdu_size += 4;
12494
12495 pdu_data_loc[3] = isoal_test_add_framed_pdu_cont(&testdata[testdata_indx],
12496 (testdata_size - testdata_indx),
12497 &rx_pdu_meta_buf.pdu_meta);
12498
12499 testdata_indx = testdata_size;
12500 testdata_size += 6;
12501 sdu_size += 6;
12502 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size);
12503 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
12504
12505 pdu_data_loc[4] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
12506 (testdata_size - testdata_indx),
12507 &rx_pdu_meta_buf.pdu_meta);
12508
12509 /* Set callback function return values */
12510 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer);
12511 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
12512 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
12513 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
12514
12515 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
12516
12517 zassert_equal(err, ISOAL_STATUS_ERR_UNSPECIFIED, "err = 0x%02x", err);
12518
12519 /* Test recombine (Black Box) */
12520 /* A new SDU should be allocated */
12521 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
12522 &isoal_global.sink_state[sink_hdl], /* Sink */
12523 &rx_pdu_meta_buf.pdu_meta); /* PDU */
12524
12525 /* SDU payload should be written */
12526 ZASSERT_ISOAL_SDU_WRITE_TEST(history[0],
12527 &rx_sdu_frag_buf, /* SDU buffer */
12528 sdu_written, /* SDU written */
12529 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
12530 /* PDU payload */
12531 3); /* Size */
12532 sdu_written += 3;
12533
12534 ZASSERT_ISOAL_SDU_WRITE_TEST(history[1],
12535 &rx_sdu_frag_buf, /* SDU buffer */
12536 sdu_written, /* SDU written */
12537 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
12538 /* PDU payload */
12539 4); /* Size */
12540 sdu_written += 4;
12541
12542 ZASSERT_ISOAL_SDU_WRITE_TEST(history[2],
12543 &rx_sdu_frag_buf, /* SDU buffer */
12544 sdu_written, /* SDU written */
12545 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[2]],
12546 /* PDU payload */
12547 4); /* Size */
12548 sdu_written += 4;
12549
12550 ZASSERT_ISOAL_SDU_WRITE_TEST(history[3],
12551 &rx_sdu_frag_buf, /* SDU buffer */
12552 sdu_written, /* SDU written */
12553 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
12554 /* PDU payload */
12555 4); /* Size */
12556 sdu_written += 4;
12557
12558 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
12559 &rx_sdu_frag_buf, /* SDU buffer */
12560 sdu_written, /* SDU written */
12561 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[4]],
12562 /* PDU payload */
12563 (testdata_size - testdata_indx)); /* Size */
12564
12565 /* SDU should be emitted */
12566 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
12567 &isoal_global.sink_state[sink_hdl], /* Sink */
12568 BT_ISO_SINGLE, /* Frag state */
12569 sdu_size, /* Frag size */
12570 ISOAL_SDU_STATUS_VALID, /* Frag status */
12571 sdu_timestamp, /* Timestamp */
12572 seqn, /* Seq. number */
12573 sdu_buffer.dbuf, /* Buffer */
12574 sdu_buffer.size, /* Buffer size */
12575 total_sdu_size, /* Total size */
12576 collated_status); /* SDU status */
12577
12578 /* Test recombine (White Box) */
12579 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
12580 ISOAL_START,
12581 "FSM state %s should be %s!",
12582 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
12583 FSM_TO_STR(ISOAL_START));
12584 }
12585
12586 /**
12587 * Test Suite : RX framed PDU recombination
12588 *
12589 * Tests handling an error in the length of an SDU seqment where the CRC check
12590 * does not fail.
12591 *
12592 * Expected Sequence:
12593 * -- Total of 2 SDUs released across 1 event
12594 * -- Event 1: PDU0 valid SDU 0 Framed Start (Seg Error)
12595 * -----> SDU 0 Lost (Released)
12596 * PDU1 Valid SDU 0 Framed End
12597 * SDU 1 Framed Start
12598 * PDU2 Valid SDU 1 Framed End
12599 * -----> SDU 1 Valid (Released)
12600 *
12601 * Qualification:
12602 * IAL/CIS/FRA/PER/BI-01-C
12603 * IAL/CIS/FRA/PER/BI-02-C
12604 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_dbl_sdu_seg_err1)12605 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1)
12606 {
12607 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
12608 struct rx_sdu_frag_buffer rx_sdu_frag_buf[2];
12609 struct isoal_sdu_buffer sdu_buffer[2];
12610 isoal_sdu_status_t collated_status;
12611 isoal_sink_handle_t sink_hdl;
12612 uint32_t stream_sync_delay;
12613 uint32_t group_sync_delay;
12614 isoal_sdu_len_t sdu_size[2];
12615 uint8_t iso_interval_int;
12616 uint32_t sdu_timestamp[2];
12617 uint16_t pdu_data_loc[5];
12618 uint32_t iso_interval_us;
12619 isoal_sdu_cnt_t seqn[2];
12620 uint64_t payload_number;
12621 uint16_t total_sdu_size;
12622 uint16_t sdu_written = 0;
12623 uint32_t sdu_timeoffset;
12624 uint32_t pdu_timestamp;
12625 uint16_t testdata_indx;
12626 uint16_t testdata_size;
12627 uint32_t sdu_interval;
12628 uint8_t testdata[63];
12629 isoal_status_t err;
12630 uint32_t latency;
12631 uint8_t role;
12632 uint8_t BN;
12633 uint8_t FT;
12634
12635 /* Settings */
12636 role = ISOAL_ROLE_PERIPHERAL;
12637 iso_interval_int = 1;
12638 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
12639 sdu_interval = (iso_interval_us / 3) + 5;
12640 BN = 3;
12641 FT = 1;
12642 stream_sync_delay = iso_interval_us - 200;
12643 group_sync_delay = iso_interval_us - 50;
12644
12645 /* PDU 0 -------------------------------------------------------------*/
12646 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
12647 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
12648 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
12649 init_test_data_buffer(testdata, 63);
12650 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
12651
12652 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
12653 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
12654 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
12655 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
12656 payload_number = 1000 * BN;
12657 pdu_timestamp = 9249;
12658 latency = calc_rx_latency_by_role(role,
12659 true,
12660 FT,
12661 sdu_interval,
12662 iso_interval_int,
12663 stream_sync_delay,
12664 group_sync_delay);
12665 sdu_timeoffset = group_sync_delay - 50;
12666 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us);
12667 seqn[0] = 0;
12668 testdata_indx = 0;
12669 testdata_size = 13;
12670 sdu_size[0] = 0;
12671 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
12672 collated_status =
12673 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
12674
12675 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
12676 role, /* Role */
12677 true, /* Framed */
12678 BN, /* BN */
12679 FT, /* FT */
12680 sdu_interval, /* SDU Interval */
12681 iso_interval_int, /* ISO Interval */
12682 stream_sync_delay, /* Stream Sync Delay */
12683 group_sync_delay); /* Group Sync Delay */
12684
12685 /* PDU with errors */
12686 isoal_test_create_framed_pdu_base(payload_number,
12687 pdu_timestamp,
12688 ISOAL_PDU_STATUS_VALID,
12689 &rx_pdu_meta_buf.pdu_meta);
12690 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
12691 (testdata_size - testdata_indx),
12692 sdu_timeoffset,
12693 &rx_pdu_meta_buf.pdu_meta);
12694
12695 /* Set an invalid length and incomplete header */
12696 rx_pdu_meta_buf.pdu_meta.pdu->len = 3;
12697
12698 /* Set callback function return values */
12699 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
12700 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
12701 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
12702
12703 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
12704
12705 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
12706
12707 /* SDU 0 -------------------------------------------------------------*/
12708 /* Test recombine (Black Box) */
12709 /* A new SDU should be allocated */
12710 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
12711 &isoal_global.sink_state[sink_hdl], /* Sink */
12712 &rx_pdu_meta_buf.pdu_meta); /* PDU */
12713
12714 /* SDU payload should not be written */
12715
12716 /* SDU should be emitted */
12717 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
12718 &isoal_global.sink_state[sink_hdl], /* Sink */
12719 BT_ISO_SINGLE, /* Frag state */
12720 sdu_size[0], /* Frag size */
12721 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
12722 sdu_timestamp[0], /* Timestamp */
12723 seqn[0], /* Seq. number */
12724 sdu_buffer[0].dbuf, /* Buffer */
12725 sdu_buffer[0].size, /* Buffer size */
12726 total_sdu_size, /* Total size */
12727 collated_status); /* SDU status */
12728
12729 /* Test recombine (White Box) */
12730 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
12731 ISOAL_ERR_SPOOL,
12732 "FSM state %s should be %s!",
12733 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
12734 FSM_TO_STR(ISOAL_ERR_SPOOL));
12735
12736 /* PDU 1 -------------------------------------------------------------*/
12737 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
12738
12739 payload_number++;
12740 testdata_indx = testdata_size;
12741 testdata_size += 10;
12742 sdu_size[0] += 10;
12743
12744 isoal_test_create_framed_pdu_base(payload_number,
12745 pdu_timestamp,
12746 ISOAL_PDU_STATUS_VALID,
12747 &rx_pdu_meta_buf.pdu_meta);
12748 pdu_data_loc[1] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
12749 (testdata_size - testdata_indx),
12750 &rx_pdu_meta_buf.pdu_meta);
12751
12752 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
12753 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
12754 seqn[1] = seqn[0] + 1;
12755 testdata_indx = testdata_size;
12756 testdata_size += 17;
12757 sdu_size[1] = 17;
12758
12759 pdu_data_loc[2] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
12760 (testdata_size - testdata_indx),
12761 sdu_timeoffset,
12762 &rx_pdu_meta_buf.pdu_meta);
12763
12764 /* Set callback function return values */
12765 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
12766 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
12767 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
12768
12769 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
12770
12771 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
12772
12773 /* SDU 0 -------------------------------------------------------------*/
12774 /* Test recombine (Black Box) */
12775 /* A new SDU should not be allocated */
12776
12777 /* SDU payload should not be written */
12778
12779 /* SDU should not be emitted */
12780
12781 /* SDU 1 -------------------------------------------------------------*/
12782 /* A new SDU should be allocated */
12783 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
12784 &isoal_global.sink_state[sink_hdl], /* Sink */
12785 &rx_pdu_meta_buf.pdu_meta); /* PDU */
12786
12787 /* SDU payload should be written */
12788 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
12789 &rx_sdu_frag_buf[1], /* SDU buffer */
12790 sdu_written, /* SDU written */
12791 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[2]],
12792 /* PDU payload */
12793 (testdata_size - testdata_indx)); /* Size */
12794
12795 /* SDU should not be emitted */
12796 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1);
12797
12798 /* Test recombine (White Box) */
12799 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
12800 ISOAL_CONTINUE,
12801 "FSM state %s should be %s!",
12802 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
12803 FSM_TO_STR(ISOAL_CONTINUE));
12804
12805 /* PDU 2 -------------------------------------------------------------*/
12806 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
12807
12808 sdu_written += (testdata_size - testdata_indx);
12809 payload_number++;
12810 testdata_indx = testdata_size;
12811 testdata_size += 10;
12812 sdu_size[1] += 10;
12813 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]);
12814 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
12815
12816 isoal_test_create_framed_pdu_base(payload_number,
12817 pdu_timestamp,
12818 ISOAL_PDU_STATUS_VALID,
12819 &rx_pdu_meta_buf.pdu_meta);
12820 pdu_data_loc[3] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
12821 (testdata_size - testdata_indx),
12822 &rx_pdu_meta_buf.pdu_meta);
12823
12824 /* Set callback function return values */
12825 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
12826 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
12827
12828 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
12829
12830 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
12831
12832 /* SDU 1 -------------------------------------------------------------*/
12833 /* Test recombine (Black Box) */
12834 /* A new SDU should not be allocated */
12835 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(2);
12836
12837 /* SDU payload should be written */
12838 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
12839 &rx_sdu_frag_buf[1], /* SDU buffer */
12840 sdu_written, /* SDU written */
12841 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[3]],
12842 /* PDU payload */
12843 (testdata_size - testdata_indx)); /* Size */
12844
12845 /* SDU should be emitted */
12846 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
12847 &isoal_global.sink_state[sink_hdl], /* Sink */
12848 BT_ISO_SINGLE, /* Frag state */
12849 sdu_size[1], /* Frag size */
12850 ISOAL_SDU_STATUS_VALID, /* Frag status */
12851 sdu_timestamp[1], /* Timestamp */
12852 seqn[1], /* Seq. number */
12853 sdu_buffer[1].dbuf, /* Buffer */
12854 sdu_buffer[1].size, /* Buffer size */
12855 total_sdu_size, /* Total size */
12856 collated_status); /* SDU status */
12857
12858 /* Test recombine (White Box) */
12859 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
12860 ISOAL_START,
12861 "FSM state %s should be %s!",
12862 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
12863 FSM_TO_STR(ISOAL_START));
12864 }
12865
12866 /**
12867 * Test Suite : RX framed PDU recombination
12868 *
12869 * Tests recombination of two SDUs from three segmented PDUs where there is a
12870 * length error in the second SDU's segments that does not cause the CRC to
12871 * fail.
12872 *
12873 * Expected Sequence:
12874 * -- Total of 4 SDUs released across 2 event
12875 * -- Event 1: PDU0 valid SDU 0 Framed Start
12876 * PDU1 Valid SDU 0 Framed End
12877 * SDU 1 Framed Start (Seg Error)
12878 * -----> SDU 0 Valid (Released)
12879 * -----> SDU 1 Lost (Released)
12880 * PDU2 Valid SDU 1 Framed End
12881 * Missing SDU 2
12882 * -- Event 2: PDU3 valid SDU 3 Framed Single
12883 * -----> SDU 2 Lost (Released)
12884 * -----> SDU 3 Valid (Released)
12885 * PDU4 N/A
12886 * PDU5 N/A
12887 *
12888 * Qualification:
12889 * IAL/CIS/FRA/PER/BI-01-C
12890 * IAL/CIS/FRA/PER/BI-02-C
12891 */
ZTEST(test_rx_framed,test_rx_framed_trppl_pdu_dbl_sdu_seg_err2)12892 ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2)
12893 {
12894 struct rx_sdu_frag_buffer rx_sdu_frag_buf[2];
12895 struct rx_pdu_meta_buffer rx_pdu_meta_buf;
12896 struct isoal_sdu_buffer sdu_buffer[2];
12897 isoal_sdu_status_t collated_status;
12898 isoal_sink_handle_t sink_hdl;
12899 isoal_sdu_len_t sdu_size[2];
12900 uint32_t stream_sync_delay;
12901 uint32_t group_sync_delay;
12902 uint32_t sdu_timestamp[2];
12903 uint8_t iso_interval_int;
12904 uint16_t pdu_data_loc[5];
12905 uint32_t iso_interval_us;
12906 uint64_t payload_number;
12907 uint16_t total_sdu_size;
12908 uint16_t sdu_written = 0;
12909 uint32_t sdu_timeoffset;
12910 uint32_t pdu_timestamp;
12911 uint16_t testdata_indx;
12912 uint16_t testdata_size;
12913 uint32_t sdu_interval;
12914 isoal_sdu_cnt_t seqn;
12915 uint8_t testdata[63];
12916 isoal_status_t err;
12917 uint32_t latency;
12918 uint8_t role;
12919 uint8_t BN;
12920 uint8_t FT;
12921
12922 /* Settings */
12923 role = ISOAL_ROLE_PERIPHERAL;
12924 iso_interval_int = 1;
12925 iso_interval_us = iso_interval_int * ISO_INT_UNIT_US;
12926 sdu_interval = (iso_interval_us / 3) + 5;
12927 BN = 3;
12928 FT = 1;
12929 stream_sync_delay = iso_interval_us - 200;
12930 group_sync_delay = iso_interval_us - 50;
12931
12932 /* PDU 1 -------------------------------------------------------------*/
12933 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
12934 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
12935 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]);
12936 init_test_data_buffer(testdata, 63);
12937 memset(pdu_data_loc, 0, sizeof(pdu_data_loc));
12938
12939 sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0];
12940 sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1];
12941 sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
12942 sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX;
12943 payload_number = 1000 * BN;
12944 pdu_timestamp = 9249;
12945 latency = calc_rx_latency_by_role(role,
12946 true,
12947 FT,
12948 sdu_interval,
12949 iso_interval_int,
12950 stream_sync_delay,
12951 group_sync_delay);
12952 sdu_timeoffset = group_sync_delay - 50;
12953 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
12954 seqn = 0;
12955 testdata_indx = 0;
12956 testdata_size = 13;
12957 sdu_size[0] = 13;
12958
12959 sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */
12960 role, /* Role */
12961 true, /* Framed */
12962 BN, /* BN */
12963 FT, /* FT */
12964 sdu_interval, /* SDU Interval */
12965 iso_interval_int, /* ISO Interval */
12966 stream_sync_delay, /* Stream Sync Delay */
12967 group_sync_delay); /* Group Sync Delay */
12968
12969 isoal_test_create_framed_pdu_base(payload_number,
12970 pdu_timestamp,
12971 ISOAL_PDU_STATUS_VALID,
12972 &rx_pdu_meta_buf.pdu_meta);
12973 pdu_data_loc[0] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
12974 (testdata_size - testdata_indx),
12975 sdu_timeoffset,
12976 &rx_pdu_meta_buf.pdu_meta);
12977
12978 /* Set callback function return values */
12979 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
12980 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
12981 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
12982 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
12983
12984 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
12985
12986 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
12987
12988 /* SDU 0 -------------------------------------------------------------*/
12989 /* Test recombine (Black Box) */
12990 /* A new SDU should be allocated */
12991 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
12992 &isoal_global.sink_state[sink_hdl], /* Sink */
12993 &rx_pdu_meta_buf.pdu_meta); /* PDU */
12994
12995 /* SDU payload should be written */
12996 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
12997 &rx_sdu_frag_buf[0], /* SDU buffer */
12998 sdu_written, /* SDU written */
12999 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]],
13000 /* PDU payload */
13001 (testdata_size - testdata_indx)); /* Size */
13002
13003 /* SDU should not be emitted */
13004 ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0);
13005
13006 /* Test recombine (White Box) */
13007 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
13008 ISOAL_CONTINUE,
13009 "FSM state %s should be %s!",
13010 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
13011 FSM_TO_STR(ISOAL_CONTINUE));
13012
13013 /* PDU 2 -------------------------------------------------------------*/
13014 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
13015
13016 sdu_written += (testdata_size - testdata_indx);
13017 payload_number++;
13018 testdata_indx = testdata_size;
13019 testdata_size += 10;
13020 sdu_size[0] += 10;
13021
13022 isoal_test_create_framed_pdu_base(payload_number,
13023 pdu_timestamp,
13024 ISOAL_PDU_STATUS_VALID,
13025 &rx_pdu_meta_buf.pdu_meta);
13026 pdu_data_loc[1] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
13027 (testdata_size - testdata_indx),
13028 &rx_pdu_meta_buf.pdu_meta);
13029
13030 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
13031 sdu_timestamp[1] = sdu_timestamp[0] + sdu_interval;
13032 testdata_indx = testdata_size;
13033 testdata_size += 17;
13034 sdu_size[1] = 0;
13035
13036 pdu_data_loc[2] = isoal_test_add_framed_pdu_start(&testdata[testdata_indx],
13037 (testdata_size - testdata_indx),
13038 sdu_timeoffset,
13039 &rx_pdu_meta_buf.pdu_meta);
13040
13041 /* Set an invalid length */
13042 rx_pdu_meta_buf.pdu_meta.pdu->len -= 5;
13043
13044 /* Set callback function return values */
13045 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
13046 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
13047 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
13048 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
13049
13050 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
13051
13052 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
13053
13054 /* SDU 0 -------------------------------------------------------------*/
13055 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
13056 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
13057 /* Test recombine (Black Box) */
13058
13059 /* A new SDU should not be allocated */
13060
13061 /* SDU payload should be written */
13062 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
13063 &rx_sdu_frag_buf[0], /* SDU buffer */
13064 sdu_written, /* SDU written */
13065 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]],
13066 /* PDU payload */
13067 10); /* Size */
13068
13069 /* SDU should be emitted */
13070 ZASSERT_ISOAL_SDU_EMIT_TEST(history[0],
13071 &isoal_global.sink_state[sink_hdl], /* Sink */
13072 BT_ISO_SINGLE, /* Frag state */
13073 sdu_size[0], /* Frag size */
13074 ISOAL_SDU_STATUS_VALID, /* Frag status */
13075 sdu_timestamp[0], /* Timestamp */
13076 seqn, /* Seq. number */
13077 sdu_buffer[0].dbuf, /* Buffer */
13078 sdu_buffer[0].size, /* Buffer size */
13079 total_sdu_size, /* Total size */
13080 collated_status); /* SDU status */
13081
13082 /* SDU 1 -------------------------------------------------------------*/
13083 seqn++;
13084 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]);
13085 collated_status =
13086 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
13087 /* A new SDU should be allocated */
13088 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
13089 &isoal_global.sink_state[sink_hdl], /* Sink */
13090 &rx_pdu_meta_buf.pdu_meta); /* PDU */
13091
13092 /* SDU payload should not be written */
13093 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(2);
13094
13095 /* SDU should be emitted */
13096 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
13097 &isoal_global.sink_state[sink_hdl], /* Sink */
13098 BT_ISO_SINGLE, /* Frag state */
13099 sdu_size[1], /* Frag size */
13100 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
13101 sdu_timestamp[1], /* Timestamp */
13102 seqn, /* Seq. number */
13103 sdu_buffer[1].dbuf, /* Buffer */
13104 sdu_buffer[1].size, /* Buffer size */
13105 total_sdu_size, /* Total size */
13106 collated_status); /* SDU status */
13107
13108 /* Test recombine (White Box) */
13109 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
13110 ISOAL_ERR_SPOOL,
13111 "FSM state %s should be %s!",
13112 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
13113 FSM_TO_STR(ISOAL_ERR_SPOOL));
13114
13115 /* PDU 3 -------------------------------------------------------------*/
13116 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
13117
13118 payload_number++;
13119 testdata_indx = testdata_size;
13120 testdata_size += 10;
13121 /* SDU size does not change */
13122
13123 isoal_test_create_framed_pdu_base(payload_number,
13124 pdu_timestamp,
13125 ISOAL_PDU_STATUS_VALID,
13126 &rx_pdu_meta_buf.pdu_meta);
13127 pdu_data_loc[3] = isoal_test_add_framed_pdu_end(&testdata[testdata_indx],
13128 (testdata_size - testdata_indx),
13129 &rx_pdu_meta_buf.pdu_meta);
13130
13131 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
13132
13133 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
13134
13135 /* SDU 2 -------------------------------------------------------------*/
13136 /* Missing */
13137 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false);
13138 sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
13139
13140 /* SDU 1 -------------------------------------------------------------*/
13141 /* Test recombine (Black Box) */
13142 /* Should not allocate a new SDU */
13143 ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(2);
13144
13145 /* SDU should not be written to */
13146 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(2);
13147
13148 /* SDU should not be emitted */
13149 ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(2);
13150
13151 /* Test recombine (White Box) */
13152 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
13153 ISOAL_ERR_SPOOL,
13154 "FSM state %s should be %s!",
13155 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
13156 FSM_TO_STR(ISOAL_ERR_SPOOL));
13157
13158 /* PDU 4 -------------------------------------------------------------*/
13159 isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf);
13160 isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]);
13161
13162 payload_number++;
13163 pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US);
13164
13165 sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true);
13166 sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset);
13167
13168 testdata_indx = testdata_size;
13169 testdata_size += 13;
13170 sdu_size[0] = 13;
13171
13172 isoal_test_create_framed_pdu_base(payload_number,
13173 pdu_timestamp,
13174 ISOAL_PDU_STATUS_VALID,
13175 &rx_pdu_meta_buf.pdu_meta);
13176 pdu_data_loc[4] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx],
13177 (testdata_size - testdata_indx),
13178 sdu_timeoffset,
13179 &rx_pdu_meta_buf.pdu_meta);
13180
13181 /* Set callback function return values */
13182 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]);
13183 push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]);
13184 sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK;
13185 sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK;
13186 sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK;
13187
13188 err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta);
13189
13190 zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err);
13191
13192 /* SDU 2 -------------------------------------------------------------*/
13193 seqn++;
13194 total_sdu_size = COLLATED_RX_SDU_INFO(0, 0);
13195 collated_status =
13196 COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA);
13197 /* Test recombine (Black Box) */
13198 /* A new SDU should be allocated */
13199 ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2],
13200 &isoal_global.sink_state[sink_hdl], /* Sink */
13201 &rx_pdu_meta_buf.pdu_meta); /* PDU */
13202
13203 /* SDU should be emitted */
13204 ZASSERT_ISOAL_SDU_EMIT_TEST(history[2],
13205 &isoal_global.sink_state[sink_hdl], /* Sink */
13206 BT_ISO_SINGLE, /* Frag state */
13207 0, /* Frag size */
13208 ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */
13209 sdu_timestamp[1], /* Timestamp */
13210 seqn, /* Seq. number */
13211 sdu_buffer[1].dbuf, /* Buffer */
13212 sdu_buffer[1].size, /* Buffer size */
13213 total_sdu_size, /* Total size */
13214 collated_status); /* SDU status */
13215
13216 /* SDU 3 -------------------------------------------------------------*/
13217 sdu_written = 0;
13218 seqn++;
13219 total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]);
13220 collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID);
13221 /* Test recombine (Black Box) */
13222 /* A new SDU should be allocated */
13223 ZASSERT_ISOAL_SDU_ALLOC_TEST(val,
13224 &isoal_global.sink_state[sink_hdl], /* Sink */
13225 &rx_pdu_meta_buf.pdu_meta); /* PDU */
13226
13227 /* SDU payload should be written */
13228 ZASSERT_ISOAL_SDU_WRITE_TEST(val,
13229 &rx_sdu_frag_buf[0], /* SDU buffer */
13230 sdu_written, /* SDU written */
13231 &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[4]],
13232 /* PDU payload */
13233 (testdata_size - testdata_indx)); /* Size */
13234
13235 /* SDU should be emitted */
13236 ZASSERT_ISOAL_SDU_EMIT_TEST(val,
13237 &isoal_global.sink_state[sink_hdl], /* Sink */
13238 BT_ISO_SINGLE, /* Frag state */
13239 sdu_size[0], /* Frag size */
13240 ISOAL_SDU_STATUS_VALID, /* Frag status */
13241 sdu_timestamp[0], /* Timestamp */
13242 seqn, /* Seq. number */
13243 sdu_buffer[0].dbuf, /* Buffer */
13244 sdu_buffer[0].size, /* Buffer size */
13245 total_sdu_size, /* Total size */
13246 collated_status); /* SDU status */
13247
13248 /* Test recombine (White Box) */
13249 zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm,
13250 ISOAL_START,
13251 "FSM state %s should be %s!",
13252 FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm),
13253 FSM_TO_STR(ISOAL_START));
13254 }
13255