From 97935bb0dcc621b6bcc2e65b5365b1f93c5993b4 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Mon, 22 May 2023 13:13:00 +0200 Subject: [PATCH] tests: Bluetooth: controller: updated ISO-AL tests for lost SDUs -- Updated test cases to include missing / lost SDUs. -- Included tests for receiving only framed padding PDUs. -- Removed tests linked to sink and source configuration params as these were unused and removed. Signed-off-by: Nirosharn Amarasinghe --- .../ctrl_isoal/src/isoal_test_debug.c | 2 +- .../ctrl_isoal/src/sub_sets/isoal_test_rx.c | 2562 +++++++++++++---- .../ctrl_isoal/src/sub_sets/isoal_test_tx.c | 76 +- 3 files changed, 1972 insertions(+), 668 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c index fa559f37f5e936..464d2586598481 100644 --- a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c +++ b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c @@ -86,7 +86,7 @@ void isoal_test_debug_print_rx_sdu(const struct isoal_sink *sink_ctx PRINT("\n"); PRINT("SDU %04d (%10d) | %12s [%10s] %03d: ", - sdu_frag->sdu.seqn, + sdu_frag->sdu.sn, sdu_frag->sdu.timestamp, STATE_TO_STR(sdu_frag->sdu_state), DU_ERR_TO_STR(sdu_frag->sdu.status), diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c index 67135071a064a2..c0074405bded8d 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c @@ -16,7 +16,7 @@ FAKE_VALUE_FUNC(isoal_status_t, struct isoal_sdu_buffer *); static struct { - struct isoal_sdu_buffer *out[5]; + struct isoal_sdu_buffer *out[6]; size_t buffer_size; size_t pos; @@ -174,10 +174,12 @@ static isoal_status_t custom_sink_sdu_emit_test(const struct isoal_sink *sink_ct _sdu_status, \ sink_sdu_emit_test_handler_fake.arg2_##_typ.collated_status) -#define ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(_expected) \ - zassert_equal(_expected, sink_sdu_emit_test_fake.call_count, \ - "Expected %u got %u", \ - _expected, sink_sdu_emit_test_fake.call_count) +#define ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(_expected) \ + zassert_equal(_expected, \ + sink_sdu_emit_test_fake.call_count, \ + "Expected %u got %u", \ + _expected, \ + sink_sdu_emit_test_fake.call_count) FAKE_VALUE_FUNC(isoal_status_t, sink_sdu_write_test, void *, const uint8_t *, const size_t); /** @@ -224,10 +226,12 @@ custom_sink_sdu_write_test(void *dbuf, const uint8_t *pdu_payload, const size_t _length, \ sink_sdu_write_test_fake.arg2_##_typ) -#define ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(_expected) \ - zassert_equal(_expected, sink_sdu_write_test_fake.call_count, \ - "Expected %u got %u", \ - _expected, sink_sdu_write_test_fake.call_count) +#define ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(_expected) \ + zassert_equal(_expected, \ + sink_sdu_write_test_fake.call_count, \ + "Expected %u got %u", \ + _expected, \ + sink_sdu_write_test_fake.call_count) /** * RX common setup before running tests @@ -274,7 +278,7 @@ static int32_t calc_rx_latency_by_role(uint8_t role, uint32_t iso_interval; latency = 0; - iso_interval = iso_interval_int * CONN_INT_UNIT_US; + iso_interval = iso_interval_int * ISO_INT_UNIT_US; switch (role) { case BT_CONN_ROLE_PERIPHERAL: @@ -321,6 +325,30 @@ static int32_t calc_rx_latency_by_role(uint8_t role, return latency; } +static uint32_t get_next_time_offset(uint32_t time_offset, + uint32_t iso_interval_us, + uint32_t sdu_interval_us, + bool next_event_expected) +{ + uint32_t result; + + if (time_offset > sdu_interval_us) { + result = time_offset - sdu_interval_us; +#if defined(DEBUG_TEST) + PRINT("Increment time offset for same event %lu --> %lu\n", time_offset, result); +#endif + zassert_false(next_event_expected); + } else { + result = time_offset + iso_interval_us - sdu_interval_us; +#if defined(DEBUG_TEST) + PRINT("Increment time offset for next event %lu --> %lu\n", time_offset, result); +#endif + zassert_true(next_event_expected); + } + + return result; +} + /** * @breif Wrapper to test time wrapping * @param time_now Current time value @@ -376,7 +404,7 @@ static isoal_sink_handle_t basic_rx_test_setup(uint16_t handle, framed ? "Framed" : "Unframed", burst_number, flush_timeout, - (iso_interval_int * CONN_INT_UNIT_US), + (iso_interval_int * ISO_INT_UNIT_US), sdu_interval, stream_sync_delay, group_sync_delay); @@ -453,8 +481,8 @@ ZTEST(test_rx_basics, test_sink_isoal_test_create_destroy) framed = false; sdu_interval_int = 1; iso_interval_int = 1; - iso_interval = iso_interval_int * CONN_INT_UNIT_US; - sdu_interval = sdu_interval_int * CONN_INT_UNIT_US; + iso_interval = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = sdu_interval_int * ISO_INT_UNIT_US; stream_sync_delay = iso_interval - 200; group_sync_delay = iso_interval - 50; latency = 0; @@ -521,21 +549,20 @@ ZTEST(test_rx_basics, test_sink_isoal_test_create_destroy) if (framed) { zassert_equal( - isoal_global.sink_state[sink_hdl[i]].session.latency_framed, + isoal_global.sink_state[sink_hdl[i]].session.sdu_sync_const, latency, "%s latency framed %d should be %d", ROLE_TO_STR(role), - isoal_global.sink_state[sink_hdl[i]].session.latency_framed, + isoal_global.sink_state[sink_hdl[i]].session.sdu_sync_const, latency); } else { - zassert_equal(isoal_global.sink_state[sink_hdl[i]] - .session.latency_unframed, - latency, - "%s latency unframed %d should be %d", - ROLE_TO_STR(role), - isoal_global.sink_state[sink_hdl[i]] - .session.latency_unframed, - latency); + zassert_equal( + isoal_global.sink_state[sink_hdl[i]].session.sdu_sync_const, + latency, + "%s latency unframed %d should be %d", + ROLE_TO_STR(role), + isoal_global.sink_state[sink_hdl[i]].session.sdu_sync_const, + latency); } zassert_equal(res, @@ -552,15 +579,13 @@ ZTEST(test_rx_basics, test_sink_isoal_test_create_destroy) i, ROLE_TO_STR(role)); - zassert_not_null(isoal_get_sink_param_ref(sink_hdl[i]), ""); - framed = !framed; burst_number++; flush_timeout = (flush_timeout % 3) + 1; sdu_interval_int++; iso_interval_int = iso_interval_int * sdu_interval_int; - sdu_interval = (sdu_interval_int * CONN_INT_UNIT_US) - (framed ? 100 : 0); - iso_interval = iso_interval_int * CONN_INT_UNIT_US; + sdu_interval = (sdu_interval_int * ISO_INT_UNIT_US) - (framed ? 100 : 0); + iso_interval = iso_interval_int * ISO_INT_UNIT_US; stream_sync_delay = iso_interval - (200 * i); group_sync_delay = iso_interval - 50; } @@ -605,9 +630,9 @@ ZTEST(test_rx_basics, test_sink_isoal_test_create_err) flush_timeout = 1; framed = false; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; - stream_sync_delay = CONN_INT_UNIT_US - 200; - group_sync_delay = CONN_INT_UNIT_US - 50; + sdu_interval = ISO_INT_UNIT_US; + stream_sync_delay = ISO_INT_UNIT_US - 200; + group_sync_delay = ISO_INT_UNIT_US - 50; res = isoal_init(); zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res); @@ -656,21 +681,6 @@ ZTEST(test_rx_basics, test_sink_isoal_test_create_err) "Sink creation did not return error as expected!"); } -/** - * Test Suite : RX basic test - * - * Test assertion when attempting to retrieve sink params for an invalid sink - * handle. - */ -ZTEST(test_rx_basics, test_sink_invalid_ref) -{ - ztest_set_assert_valid(true); - - isoal_get_sink_param_ref(99); - - ztest_set_assert_valid(false); -} - /** * Test Suite : RX basic test * @@ -703,11 +713,11 @@ ZTEST(test_rx_basics, test_sink_disable) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -725,7 +735,7 @@ ZTEST(test_rx_basics, test_sink_disable) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 23; sdu_size = 0; @@ -768,6 +778,12 @@ ZTEST(test_rx_basics, test_sink_disable) * Test Suite : RX unframed PDU reassembly * * Tests reassembly of a single valid RX PDU into an SDU. + * + * Expected Sequence: + * -- Total of 1 SDUs released across 1 events + * -- Event 1: PDU0 Valid SDU 0 Unframed Single + * -----> SDU 0 Valid (Released) + * */ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu) { @@ -798,13 +814,13 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); init_test_data_buffer(testdata, 23); @@ -820,7 +836,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 23; sdu_size = 23; @@ -856,6 +872,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -928,6 +945,12 @@ ZTEST(test_rx_unframed, test_rx_time_wrapping) * Test Suite : RX unframed PDU reassembly * * Tests time wrapping in reassembly of a single valid RX PDU into an SDU. + * + * Expected Sequence: + * -- Total of 1 SDUs released across 1 events + * -- Event 1: PDU0 Valid SDU 0 Unframed Single + * -----> SDU 0 Valid (Released) + * */ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap1) { @@ -958,13 +981,13 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); init_test_data_buffer(testdata, 23); @@ -983,7 +1006,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap1) pdu_timestamp = (ISOAL_TIME_WRAPPING_POINT_US - latency) + 1; sdu_timestamp = 0; - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 23; sdu_size = 23; @@ -1019,6 +1042,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -1056,6 +1080,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap1) * Test Suite : RX unframed PDU reassembly * * Tests time wrapping in reassembly of a single valid RX PDU into an SDU. + * + * Expected Sequence: + * -- Total of 1 SDUs released across 1 events + * -- Event 1: PDU0 Valid SDU 0 Unframed Single + * -----> SDU 0 Valid (Released) + * */ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap2) { @@ -1086,13 +1116,13 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap2) /* Settings */ role = BT_CONN_ROLE_CENTRAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); init_test_data_buffer(testdata, 23); @@ -1111,7 +1141,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap2) pdu_timestamp = (-latency) - 1; sdu_timestamp = ISOAL_TIME_WRAPPING_POINT_US; - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 23; sdu_size = 23; @@ -1147,6 +1177,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -1184,6 +1215,13 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_ts_wrap2) * Test Suite : RX unframed PDU reassembly * * Tests reassembly of two valid RX PDU into a single SDU. + * + * Expected Sequence: + * -- Total of 1 SDUs released across 1 events + * -- Event 1: PDU0 Valid SDU 0 Unframed Start + * PDU1 Valid SDU 0 Unframed End + * -----> SDU 0 Valid (Released) + * */ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu) { @@ -1214,13 +1252,13 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); init_test_data_buffer(testdata, 23); @@ -1236,7 +1274,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -1269,6 +1307,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -1282,6 +1321,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ /* No padding PDUs expected, so move to waiting for start fragment */ @@ -1291,7 +1331,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 2 -------------------------------------------------------------*/ + /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; testdata_indx = testdata_size; @@ -1317,8 +1357,10 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* Should not allocate a new SDU */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -1351,6 +1393,18 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu) * Test Suite : RX unframed PDU reassembly * * Tests reassembly of three SDUs where the end of the first two were not seen + * + * Expected Sequence: + * -- Total of 1 SDUs released across 1 events + * -- Event 1: PDU0 Valid SDU 0 Unframed Start + * PDU1 Valid SDU 0 Unframed Cont. + * -----> SDU 0 Bit Errors (Released) + * PDU2 Valid SDU 1 Unframed Start + * PDU3 Valid SDU 1 Unframed Cont. + * -----> SDU 1 Bit Errors (Released) + * -- Event 2: PDU4 Valid SDU 2 Unframed Single + * -----> SDU 2 Valid (Released) + * */ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) { @@ -1381,13 +1435,13 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US / 2; + sdu_interval = ISO_INT_UNIT_US / 2; BN = 4; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; - /* SDU 1 - PDU 1 -----------------------------------------------------*/ + /* SDU 0 - PDU 0 -----------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); init_test_data_buffer(testdata, 53); @@ -1403,7 +1457,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -1435,6 +1489,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -1447,6 +1502,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) (testdata_size - testdata_indx)); /* Size */ /* SDU should be not emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -1455,7 +1511,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* SDU 1 - PDU 2 -----------------------------------------------------*/ + /* SDU 0 - PDU 1 -----------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; testdata_indx = testdata_size; @@ -1480,7 +1536,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -1507,7 +1565,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_START)); - /* SDU 2 - PDU 3 -----------------------------------------------------*/ + /* SDU 1 - PDU 2 -----------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; @@ -1534,6 +1592,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 1 -------------------------------------------------------------*/ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -1546,6 +1605,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -1554,7 +1614,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* SDU 2 - PDU 4 */ + /* SDU 1 - PDU 3 -----------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; testdata_indx = testdata_size; @@ -1579,7 +1639,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 1 -------------------------------------------------------------*/ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(2); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -1606,12 +1668,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_START)); - /* SDU 3 - PDU 5 -----------------------------------------------------*/ + /* SDU 2 - PDU 4 -----------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; seqn++; - pdu_timestamp = 9249 + CONN_INT_UNIT_US; + pdu_timestamp = 9249 + ISO_INT_UNIT_US; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); testdata_indx = testdata_size; testdata_size += 10; @@ -1637,6 +1699,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 2 -------------------------------------------------------------*/ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -1673,6 +1736,16 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_split) * Test Suite : RX unframed PDU reassembly * * Tests reassembly of one SDUs in five fragments + * + * Expected Sequence: + * -- Total of 1 SDUs released across 1 events + * -- Event 1: PDU0 Valid SDU 0 Unframed Start + * PDU1 Valid SDU 0 Unframed Cont. + * PDU2 Valid SDU 0 Unframed Cont. + * PDU3 Valid SDU 0 Unframed Cont. + * PDU4 Valid SDU 0 Unframed End + * -----> SDU 0 Valid (Released) + * */ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) { @@ -1703,13 +1776,13 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 5; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); init_test_data_buffer(testdata, 53); @@ -1725,7 +1798,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -1757,6 +1830,8 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ + /* SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ @@ -1768,6 +1843,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -1776,7 +1852,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 2 -------------------------------------------------------------*/ + /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; testdata_indx = testdata_size; @@ -1798,7 +1874,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -1807,6 +1885,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -1837,7 +1916,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -1846,6 +1927,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -1854,7 +1936,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 4 -------------------------------------------------------------*/ + /* PDU 3 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; testdata_indx = testdata_size; @@ -1876,7 +1958,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -1885,6 +1969,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -1893,7 +1978,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 5 -------------------------------------------------------------*/ + /* PDU 4 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; testdata_indx = testdata_size; @@ -1918,7 +2003,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -1951,6 +2038,18 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split) * * Tests reassembly of one SDUs in five fragments where the SDU buffer size is * reached + * + * Expected Sequence: + * -- Total of 1 SDUs released across 1 events + * -- Event 1: PDU0 Valid SDU 0 Unframed Start + * PDU1 Valid SDU 0 Unframed Cont. + * -----> SDU 0 Valid Frag 1 (Released) + * PDU2 Valid SDU 0 Unframed Cont. + * -----> SDU 0 Valid Frag 2 (Released) + * PDU3 Valid SDU 0 Unframed Cont. + * PDU4 Valid SDU 0 Unframed End + * -----> SDU 0 Valid Frag 3 (Released) + * */ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) { @@ -1981,13 +2080,13 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 5; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); init_test_data_buffer(testdata, 100); @@ -2003,7 +2102,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 17; sdu_size = 17; @@ -2035,6 +2134,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 - Frag 1 ----------------------------------------------------*/ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -2047,6 +2147,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -2055,7 +2156,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 2 -------------------------------------------------------------*/ + /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; testdata_indx = testdata_size; @@ -2080,7 +2181,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 - Frag 1 ----------------------------------------------------*/ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -2107,7 +2210,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 3 -------------------------------------------------------------*/ + /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; @@ -2135,6 +2238,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 - Frag 2 ----------------------------------------------------*/ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -2165,7 +2269,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 4 -------------------------------------------------------------*/ + /* PDU 3 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; testdata_indx = testdata_size; @@ -2189,6 +2293,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 - Frag 3 ----------------------------------------------------*/ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -2201,6 +2306,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(2); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -2209,7 +2315,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 5 -------------------------------------------------------------*/ + /* PDU 4 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; testdata_indx = testdata_size; @@ -2234,7 +2340,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_multi_split_on_border) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 - Frag 3 ----------------------------------------------------*/ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(3); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -2297,11 +2405,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_long_pdu_short_sdu) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -2322,7 +2430,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_long_pdu_short_sdu) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 40; sdu_size = 20; @@ -2452,11 +2560,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_prem) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -2474,7 +2582,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_prem) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -2634,11 +2742,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -2656,7 +2764,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -2726,7 +2834,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; seqn++; - pdu_timestamp = 9249 + CONN_INT_UNIT_US; + pdu_timestamp = 9249 + ISO_INT_UNIT_US; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); testdata_indx = testdata_size; testdata_size += 10; @@ -2818,11 +2926,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_err) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -2840,7 +2948,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_err) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -2962,7 +3070,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_err) isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; seqn++; - pdu_timestamp = 9249 + CONN_INT_UNIT_US; + pdu_timestamp = 9249 + ISO_INT_UNIT_US; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); testdata_indx = testdata_size; testdata_size += 10; @@ -3047,11 +3155,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -3069,7 +3177,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err1) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -3190,7 +3298,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err1) isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; seqn++; - pdu_timestamp = 9249 + CONN_INT_UNIT_US; + pdu_timestamp = 9249 + ISO_INT_UNIT_US; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); testdata_indx = testdata_size; testdata_size += 10; @@ -3329,11 +3437,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err2) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -3351,7 +3459,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err2) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 40; sdu_size = 40; @@ -3491,7 +3599,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err2) isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; seqn++; - pdu_timestamp = 9249 + CONN_INT_UNIT_US; + pdu_timestamp = 9249 + ISO_INT_UNIT_US; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); testdata_indx = testdata_size; testdata_size += 10; @@ -3628,11 +3736,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 4; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -3650,7 +3758,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -3856,11 +3964,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_no_end) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -3878,7 +3986,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_no_end) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -4044,11 +4152,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_only) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4057,11 +4165,15 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_only) sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; payload_number = 1000 * BN; pdu_timestamp = 9249; - latency = calc_rx_latency_by_role(role, false, FT, - sdu_interval, iso_interval_int, - stream_sync_delay, group_sync_delay); + latency = calc_rx_latency_by_role(role, + false, + FT, + sdu_interval, + iso_interval_int, + stream_sync_delay, + group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 0; sdu_size = 0; @@ -4078,9 +4190,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_only) /* PDU padding 1 */ isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE, - NULL, 0, - payload_number, pdu_timestamp, ISOAL_PDU_STATUS_VALID, - &rx_pdu_meta_buf.pdu_meta); + NULL, + 0, + payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); @@ -4102,10 +4217,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_only) ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ - zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, ISOAL_CONTINUE, - "FSM state %s should be %s!", - FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), - FSM_TO_STR(ISOAL_CONTINUE)); + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_CONTINUE, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_CONTINUE)); /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4114,9 +4230,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_only) /* PDU padding 2 */ isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE, - NULL, 0, - payload_number, pdu_timestamp, ISOAL_PDU_STATUS_VALID, - &rx_pdu_meta_buf.pdu_meta); + NULL, + 0, + payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); @@ -4133,10 +4252,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_only) ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ - zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, ISOAL_CONTINUE, - "FSM state %s should be %s!", - FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), - FSM_TO_STR(ISOAL_CONTINUE)); + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_CONTINUE, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_CONTINUE)); /* PDU 3 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4147,9 +4267,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_only) /* PDU padding 3 */ isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE, - NULL, 0, - payload_number, pdu_timestamp, ISOAL_PDU_STATUS_VALID, - &rx_pdu_meta_buf.pdu_meta); + NULL, + 0, + payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; @@ -4160,30 +4283,32 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_only) /* Test recombine (Black Box) */ /* A new SDU should be allocated */ - ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ - &rx_pdu_meta_buf.pdu_meta); /* PDU */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ /* SDU should not be written to */ ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); /* SDU should be emitted */ - ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ - BT_ISO_SINGLE, /* Frag state */ - sdu_size, /* Frag size */ - ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ - sdu_timestamp, /* Timestamp */ - seqn, /* Seq. number */ - sdu_buffer.dbuf, /* Buffer */ - sdu_buffer.size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ - - /* Test recombine (White Box) */ - zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, ISOAL_START, - "FSM state %s should be %s!", - FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), - FSM_TO_STR(ISOAL_START)); + ZASSERT_ISOAL_SDU_EMIT_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + sdu_size, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer.dbuf, /* Buffer */ + sdu_buffer.size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_START, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); } /** @@ -4221,11 +4346,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_leading) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4235,11 +4360,15 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_leading) sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; payload_number = 1000 * BN; pdu_timestamp = 9249; - latency = calc_rx_latency_by_role(role, false, FT, - sdu_interval, iso_interval_int, - stream_sync_delay, group_sync_delay); + latency = calc_rx_latency_by_role(role, + false, + FT, + sdu_interval, + iso_interval_int, + stream_sync_delay, + group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 0; sdu_size = 0; @@ -4255,9 +4384,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_leading) group_sync_delay); /* Group Sync Delay */ isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE, - &testdata[testdata_indx], (testdata_size - testdata_indx), - payload_number, pdu_timestamp, ISOAL_PDU_STATUS_VALID, - &rx_pdu_meta_buf.pdu_meta); + &testdata[testdata_indx], + (testdata_size - testdata_indx), + payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); @@ -4279,10 +4411,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_leading) ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ - zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, ISOAL_CONTINUE, - "FSM state %s should be %s!", - FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), - FSM_TO_STR(ISOAL_CONTINUE)); + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_CONTINUE, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_CONTINUE)); /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4291,9 +4424,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_leading) /* PDU padding 1 */ isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE, - &testdata[testdata_indx], (testdata_size - testdata_indx), - payload_number, pdu_timestamp, ISOAL_PDU_STATUS_VALID, - &rx_pdu_meta_buf.pdu_meta); + &testdata[testdata_indx], + (testdata_size - testdata_indx), + payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); @@ -4310,10 +4446,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_leading) ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ - zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, ISOAL_CONTINUE, - "FSM state %s should be %s!", - FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), - FSM_TO_STR(ISOAL_CONTINUE)); + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_CONTINUE, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_CONTINUE)); /* PDU 3 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4324,9 +4461,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_leading) collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); isoal_test_create_unframed_pdu(PDU_BIS_LLID_START_CONTINUE, - &testdata[testdata_indx], (testdata_size - testdata_indx), - payload_number, pdu_timestamp, ISOAL_PDU_STATUS_VALID, - &rx_pdu_meta_buf.pdu_meta); + &testdata[testdata_indx], + (testdata_size - testdata_indx), + payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; @@ -4338,32 +4478,35 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_leading) /* Test recombine (Black Box) */ /* A new SDU should be allocated */ - ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ - &rx_pdu_meta_buf.pdu_meta); /* PDU */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ /* SDU payload should be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST(val, &rx_sdu_frag_buf, /* SDU buffer */ - &rx_pdu_meta_buf.pdu[3], /* PDU payload */ - (testdata_size - testdata_indx)); /* Size */ + ZASSERT_ISOAL_SDU_WRITE_TEST(val, + &rx_sdu_frag_buf, /* SDU buffer */ + &rx_pdu_meta_buf.pdu[3], /* PDU payload */ + (testdata_size - testdata_indx)); /* Size */ /* SDU should be emitted */ - ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ - BT_ISO_SINGLE, /* Frag state */ - sdu_size, /* Frag size */ - ISOAL_SDU_STATUS_ERRORS, /* Frag status */ - sdu_timestamp, /* Timestamp */ - seqn, /* Seq. number */ - sdu_buffer.dbuf, /* Buffer */ - sdu_buffer.size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ - - /* Test recombine (White Box) */ - zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, ISOAL_START, - "FSM state %s should be %s!", - FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), - FSM_TO_STR(ISOAL_START)); + ZASSERT_ISOAL_SDU_EMIT_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + sdu_size, /* Frag size */ + ISOAL_SDU_STATUS_ERRORS, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer.dbuf, /* Buffer */ + sdu_buffer.size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_START, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); } /** @@ -4401,11 +4544,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4423,7 +4566,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error1) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -4588,11 +4731,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error2) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4610,7 +4753,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error2) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -4776,11 +4919,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error3) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4798,7 +4941,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error3) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -4970,11 +5113,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_zero_len_packet) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -4992,7 +5135,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_zero_len_packet) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 0; sdu_size = 0; @@ -5090,11 +5233,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_err_zero_length) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -5112,7 +5255,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_err_zero_length) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -5232,7 +5375,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_err_zero_length) isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; seqn++; - pdu_timestamp = 9249 + CONN_INT_UNIT_US; + pdu_timestamp = 9249 + ISO_INT_UNIT_US; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); testdata_indx = testdata_size; sdu_size = 0; @@ -5326,11 +5469,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_no_end) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -5348,7 +5491,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_no_end) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -5487,11 +5630,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -5509,7 +5652,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid1) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -5577,11 +5720,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -5599,7 +5742,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -5713,11 +5856,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2_pdu_err) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -5735,7 +5878,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2_pdu_err) stream_sync_delay, group_sync_delay); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -5878,11 +6021,11 @@ ZTEST(test_rx_framed, test_rx_framed_single_pdu_single_sdu) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -5903,7 +6046,7 @@ ZTEST(test_rx_framed, test_rx_framed_single_pdu_single_sdu) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 23; sdu_size = 23; @@ -6009,11 +6152,11 @@ ZTEST(test_rx_framed, test_rx_framed_single_pdu_single_sdu_ts_wrap1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -6034,7 +6177,7 @@ ZTEST(test_rx_framed, test_rx_framed_single_pdu_single_sdu_ts_wrap1) sdu_timeoffset = group_sync_delay - 50; pdu_timestamp = ISOAL_TIME_WRAPPING_POINT_US - latency + sdu_timeoffset + 1; sdu_timestamp = 0; - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 23; sdu_size = 23; @@ -6141,11 +6284,11 @@ ZTEST(test_rx_framed, test_rx_framed_single_pdu_single_sdu_ts_wrap2) /* Settings */ role = BT_CONN_ROLE_CENTRAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -6166,7 +6309,7 @@ ZTEST(test_rx_framed, test_rx_framed_single_pdu_single_sdu_ts_wrap2) sdu_timeoffset = group_sync_delay - 50; pdu_timestamp = (-latency) + sdu_timeoffset - 1; sdu_timestamp = ISOAL_TIME_WRAPPING_POINT_US; - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 23; sdu_size = 23; @@ -6272,11 +6415,11 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -6297,7 +6440,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -6466,13 +6609,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu) uint8_t iso_interval_int; uint32_t sdu_timestamp[2]; uint16_t pdu_data_loc[5]; - isoal_sdu_cnt_t seqn[2]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; uint32_t pdu_timestamp; uint16_t testdata_indx; uint16_t testdata_size; + isoal_sdu_cnt_t seqn; uint32_t sdu_interval; uint8_t testdata[46]; isoal_status_t err; @@ -6484,11 +6628,12 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = (iso_interval_int * ISO_INT_UNIT_US); + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -6512,7 +6657,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size[0] = 13; @@ -6583,10 +6728,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[1] = seqn[0] + 1; testdata_indx = testdata_size; testdata_size += 13; sdu_size[1] = 13; @@ -6626,13 +6769,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ collated_status); /* SDU status */ /* SDU 2 */ + seqn++; /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -6696,7 +6840,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu) sdu_size[1], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[1], /* Timestamp */ - seqn[1], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[1].dbuf, /* Buffer */ sdu_buffer[1].size, /* Buffer size */ total_sdu_size, /* Total size */ @@ -6728,6 +6872,7 @@ ZTEST(test_rx_framed, test_rx_framed_zero_length_sdu) uint8_t iso_interval_int; uint32_t sdu_timestamp[3]; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; isoal_sdu_cnt_t seqn[3]; uint64_t payload_number; uint16_t total_sdu_size; @@ -6746,11 +6891,12 @@ ZTEST(test_rx_framed, test_rx_framed_zero_length_sdu) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -6777,7 +6923,7 @@ ZTEST(test_rx_framed, test_rx_framed_zero_length_sdu) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = 1; + seqn[0] = 0; testdata_indx = 0; testdata_size = 13; sdu_size[0] = 13; @@ -6848,8 +6994,7 @@ ZTEST(test_rx_framed, test_rx_framed_zero_length_sdu) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[1] = seqn[0] + 1; testdata_indx = testdata_size; @@ -6861,9 +7006,7 @@ ZTEST(test_rx_framed, test_rx_framed_zero_length_sdu) sdu_timeoffset, &rx_pdu_meta_buf.pdu_meta); - - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[2] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[2] = seqn[1] + 1; testdata_indx = testdata_size; @@ -7034,6 +7177,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_padding) isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -7053,11 +7197,12 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_padding) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -7078,7 +7223,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_padding) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -7166,10 +7311,13 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_padding) /* Test recombine (Black Box) */ /* SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); /* SDU should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -7184,8 +7332,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_padding) payload_number++; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; testdata_indx = testdata_size; @@ -7250,21 +7397,37 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_padding) /** * Test Suite : RX framed PDU recombination * - * Tests recombination of a single SDU from a single segmented PDU with errors, - * followed by a valid PDU + * Tests release of SDUs when receiving only padding PDUs + * + * Expected Sequence: + * -- Total of 3 SDUs released across 2 events + * -- Event 1: PDU0 Valid Framed Padding + * PDU1 Valid Framed Padding + * PDU2 Valid Framed Padding + * Event 2: PDU3 Valid SDU 3 Framed Single + * -----> SDU 0 Lost (Released) + * -----> SDU 1 Lost (Released) + * -----> SDU 2 Lost (Released) + * -----> SDU 3 Valid (Released) + * PDU4 N/A + * PDU5 N/A + * */ -ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) +ZTEST(test_rx_framed, test_rx_framed_padding_only) { + const uint8_t number_of_pdus = 3; + const uint8_t testdata_size_max = 20; + + struct rx_sdu_frag_buffer rx_sdu_frag_buf[4]; struct rx_pdu_meta_buffer rx_pdu_meta_buf; - struct rx_sdu_frag_buffer rx_sdu_frag_buf; - struct isoal_sdu_buffer sdu_buffer; + struct isoal_sdu_buffer sdu_buffer[4]; isoal_sdu_status_t collated_status; isoal_sink_handle_t sink_hdl; uint32_t stream_sync_delay; uint32_t group_sync_delay; isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; - uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -7272,9 +7435,10 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) uint32_t sdu_timestamp; uint16_t testdata_indx; uint16_t testdata_size; + uint16_t pdu_data_loc; uint32_t sdu_interval; isoal_sdu_cnt_t seqn; - uint8_t testdata[33]; + uint8_t testdata[testdata_size_max]; isoal_status_t err; uint32_t latency; uint8_t role; @@ -7284,20 +7448,31 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / number_of_pdus) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ + /* Padding PDU */ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); - isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); - init_test_data_buffer(testdata, 33); - memset(pdu_data_loc, 0, sizeof(pdu_data_loc)); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[3]); + init_test_data_buffer(testdata, testdata_size_max); + pdu_data_loc = 0; - sdu_buffer.dbuf = &rx_sdu_frag_buf; - sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0]; + sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1]; + sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2]; + sdu_buffer[3].dbuf = &rx_sdu_frag_buf[3]; + sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[3].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; payload_number = 1000 * BN; pdu_timestamp = 9249; latency = calc_rx_latency_by_role(role, @@ -7308,13 +7483,13 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) stream_sync_delay, group_sync_delay); sdu_timeoffset = group_sync_delay - 50; - sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; - testdata_indx = 0; - testdata_size = 23; + sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); + seqn = 0; + testdata_indx = testdata_size = 0; sdu_size = 0; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */ role, /* Role */ @@ -7326,19 +7501,14 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) stream_sync_delay, /* Stream Sync Delay */ group_sync_delay); /* Group Sync Delay */ - /* PDU with errors */ isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, - ISOAL_PDU_STATUS_ERRORS, + ISOAL_PDU_STATUS_VALID, &rx_pdu_meta_buf.pdu_meta); - pdu_data_loc[0] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx], - (testdata_size - testdata_indx), - sdu_timeoffset, - &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ - push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; + sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); @@ -7346,25 +7516,738 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ - /* A new SDU should be allocated */ - ZASSERT_ISOAL_SDU_ALLOC_TEST(val, - &isoal_global.sink_state[sink_hdl], /* Sink */ - &rx_pdu_meta_buf.pdu_meta); /* PDU */ + /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0); /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); - /* SDU should be emitted */ - ZASSERT_ISOAL_SDU_EMIT_TEST(val, - &isoal_global.sink_state[sink_hdl], /* Sink */ - BT_ISO_SINGLE, /* Frag state */ - sdu_size, /* Frag size */ - ISOAL_SDU_STATUS_ERRORS, /* Frag status */ - sdu_timestamp, /* Timestamp */ - seqn, /* Seq. number */ - sdu_buffer.dbuf, /* Buffer */ - sdu_buffer.size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ + /* SDU payload should not be emitted */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_START, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); + + /* PDU 1 -------------------------------------------------------------*/ + /* Padding PDU */ + isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); + + payload_number++; + + isoal_test_create_framed_pdu_base(payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); + + err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test recombine (Black Box) */ + /* SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0); + + /* SDU should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + + /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); + + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_START, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); + + /* PDU 2 -------------------------------------------------------------*/ + /* Padding PDU */ + isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); + + payload_number++; + + isoal_test_create_framed_pdu_base(payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); + + err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test recombine (Black Box) */ + /* SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0); + + /* SDU should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + + /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); + + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_START, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); + + /* SDU 0 -------------------------------------------------------------*/ + /* Missing */ + + /* SDU 1 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + + /* SDU 2 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + + /* PDU 3 -------------------------------------------------------------*/ + isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); + + payload_number++; + pdu_timestamp += iso_interval_us; + + testdata_indx = 0; + testdata_size = testdata_size_max; + sdu_size = testdata_size_max; + + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true); + + isoal_test_create_framed_pdu_base(payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); + pdu_data_loc = isoal_test_add_framed_pdu_single(&testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_timeoffset, + &rx_pdu_meta_buf.pdu_meta); + + /* Set callback function return values */ + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[3]); + sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; + sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; + sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; + + err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* SDU 0 -------------------------------------------------------------*/ + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[0], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[0], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[0].dbuf, /* Buffer */ + sdu_buffer[0].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 1 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + + sdu_timestamp += sdu_interval; + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 2 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + + sdu_timestamp += sdu_interval; + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[2].dbuf, /* Buffer */ + sdu_buffer[2].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 3 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); + + sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST(val, + &rx_sdu_frag_buf[3], /* SDU buffer */ + &rx_pdu_meta_buf.pdu[3 + pdu_data_loc], + /* PDU payload */ + (testdata_size - testdata_indx)); /* Size */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + sdu_size, /* Frag size */ + ISOAL_SDU_STATUS_VALID, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[3].dbuf, /* Buffer */ + sdu_buffer[3].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_START, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); +} + +/** + * Test Suite : RX framed PDU recombination + * + * Tests release of SDUs when receiving only padding PDUs + * + * Expected Sequence: + * -- Total of 3 SDUs released across 2 events + * -- Event 1: PDU0 Valid Framed Padding + * PDU1 Valid Framed Padding + * PDU2 Valid Framed Padding + * Event 2: PDU3 Errors SDU 3 Framed Single + * -----> SDU 0 Lost (Released) + * -----> SDU 1 Lost (Released) + * -----> SDU 2 Lost (Released) + * -----> SDU 3 Bit Errors (Released) + * PDU4 N/A + * PDU5 N/A + * + */ +ZTEST(test_rx_framed, test_rx_framed_padding_only_pdu_err) +{ + const uint8_t number_of_pdus = 3; + const uint8_t testdata_size_max = 20; + + struct rx_sdu_frag_buffer rx_sdu_frag_buf[3]; + struct rx_pdu_meta_buffer rx_pdu_meta_buf; + struct isoal_sdu_buffer sdu_buffer[4]; + isoal_sdu_status_t collated_status; + isoal_sink_handle_t sink_hdl; + uint32_t stream_sync_delay; + uint32_t group_sync_delay; + isoal_sdu_len_t sdu_size; + uint8_t iso_interval_int; + uint32_t iso_interval_us; + uint64_t payload_number; + uint16_t total_sdu_size; + uint32_t sdu_timeoffset; + uint32_t pdu_timestamp; + uint32_t sdu_timestamp; + uint16_t testdata_indx; + uint16_t testdata_size; + uint16_t pdu_data_loc; + uint32_t sdu_interval; + isoal_sdu_cnt_t seqn; + uint8_t testdata[testdata_size_max]; + isoal_status_t err; + uint32_t latency; + uint8_t role; + uint8_t BN; + uint8_t FT; + + /* Settings */ + role = BT_CONN_ROLE_PERIPHERAL; + iso_interval_int = 1; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / number_of_pdus) + 5; + BN = 3; + FT = 1; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; + + /* PDU 0 -------------------------------------------------------------*/ + /* Padding PDU */ + isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]); + init_test_data_buffer(testdata, testdata_size_max); + pdu_data_loc = 0; + + sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0]; + sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1]; + sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2]; + sdu_buffer[3].dbuf = &rx_sdu_frag_buf[2]; + sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[3].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + payload_number = 1000 * BN; + pdu_timestamp = 9249; + latency = calc_rx_latency_by_role(role, + true, + FT, + sdu_interval, + iso_interval_int, + stream_sync_delay, + group_sync_delay); + sdu_timeoffset = group_sync_delay - 50; + sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); + seqn = 0; + testdata_indx = testdata_size = 0; + sdu_size = 0; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + + sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */ + role, /* Role */ + true, /* Framed */ + BN, /* BN */ + FT, /* FT */ + sdu_interval, /* SDU Interval */ + iso_interval_int, /* ISO Interval */ + stream_sync_delay, /* Stream Sync Delay */ + group_sync_delay); /* Group Sync Delay */ + + isoal_test_create_framed_pdu_base(payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); + + /* Set callback function return values */ + sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; + sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; + sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; + + err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test recombine (Black Box) */ + /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0); + + /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + + /* SDU payload should not be emitted */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_START, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); + + /* PDU 1 -------------------------------------------------------------*/ + /* Padding PDU */ + isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); + + payload_number++; + + isoal_test_create_framed_pdu_base(payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); + + err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test recombine (Black Box) */ + /* SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0); + + /* SDU should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + + /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); + + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_START, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); + + /* PDU 2 -------------------------------------------------------------*/ + /* Padding PDU */ + isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); + + payload_number++; + + isoal_test_create_framed_pdu_base(payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_VALID, + &rx_pdu_meta_buf.pdu_meta); + + err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test recombine (Black Box) */ + /* SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0); + + /* SDU should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + + /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); + + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_START, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); + + /* SDU 0 -------------------------------------------------------------*/ + /* Missing */ + + /* SDU 1 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + + /* SDU 2 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + + /* PDU 3 -------------------------------------------------------------*/ + isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); + + payload_number++; + pdu_timestamp += iso_interval_us; + + testdata_indx = 0; + testdata_size = testdata_size_max; + sdu_size = testdata_size_max; + + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true); + + isoal_test_create_framed_pdu_base(payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_ERRORS, + &rx_pdu_meta_buf.pdu_meta); + pdu_data_loc = isoal_test_add_framed_pdu_single(&testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_timeoffset, + &rx_pdu_meta_buf.pdu_meta); + + /* Set callback function return values */ + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[3]); + sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; + sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; + sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; + + err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* SDU 0 -------------------------------------------------------------*/ + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[0], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[0], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[0].dbuf, /* Buffer */ + sdu_buffer[0].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 1 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + + sdu_timestamp += sdu_interval; + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 2 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + + sdu_timestamp += sdu_interval; + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[2].dbuf, /* Buffer */ + sdu_buffer[2].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + + /* SDU 3 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); + + sdu_timestamp += sdu_interval; + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_ERRORS, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[3].dbuf, /* Buffer */ + sdu_buffer[3].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* Test recombine (White Box) */ + zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, + ISOAL_ERR_SPOOL, + "FSM state %s should be %s!", + FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), + FSM_TO_STR(ISOAL_START)); +} + +/** + * Test Suite : RX framed PDU recombination + * + * Tests recombination of a single SDU from a single segmented PDU with errors, + * followed by a valid PDU + */ +ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) +{ + struct rx_pdu_meta_buffer rx_pdu_meta_buf; + struct rx_sdu_frag_buffer rx_sdu_frag_buf; + struct isoal_sdu_buffer sdu_buffer; + isoal_sdu_status_t collated_status; + isoal_sink_handle_t sink_hdl; + uint32_t stream_sync_delay; + uint32_t group_sync_delay; + isoal_sdu_len_t sdu_size; + uint8_t iso_interval_int; + uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; + uint64_t payload_number; + uint16_t total_sdu_size; + uint32_t sdu_timeoffset; + uint32_t pdu_timestamp; + uint32_t sdu_timestamp; + uint16_t testdata_indx; + uint16_t testdata_size; + uint32_t sdu_interval; + isoal_sdu_cnt_t seqn; + uint8_t testdata[33]; + isoal_status_t err; + uint32_t latency; + uint8_t role; + uint8_t BN; + uint8_t FT; + + /* Settings */ + role = BT_CONN_ROLE_PERIPHERAL; + iso_interval_int = 1; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; + BN = 3; + FT = 1; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; + + /* PDU 1 -------------------------------------------------------------*/ + isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); + init_test_data_buffer(testdata, 33); + memset(pdu_data_loc, 0, sizeof(pdu_data_loc)); + + sdu_buffer.dbuf = &rx_sdu_frag_buf; + sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + payload_number = 1000 * BN; + pdu_timestamp = 9249; + latency = calc_rx_latency_by_role(role, + true, + FT, + sdu_interval, + iso_interval_int, + stream_sync_delay, + group_sync_delay); + sdu_timeoffset = group_sync_delay - 50; + /* PDU will have errors. Time stamp is only an approximation */ + sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); + seqn = 0; + testdata_indx = 0; + testdata_size = 23; + sdu_size = 0; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); + + sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */ + role, /* Role */ + true, /* Framed */ + BN, /* BN */ + FT, /* FT */ + sdu_interval, /* SDU Interval */ + iso_interval_int, /* ISO Interval */ + stream_sync_delay, /* Stream Sync Delay */ + group_sync_delay); /* Group Sync Delay */ + + /* PDU with errors */ + isoal_test_create_framed_pdu_base(payload_number, + pdu_timestamp, + ISOAL_PDU_STATUS_ERRORS, + &rx_pdu_meta_buf.pdu_meta); + pdu_data_loc[0] = isoal_test_add_framed_pdu_single(&testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_timeoffset, + &rx_pdu_meta_buf.pdu_meta); + + /* Set callback function return values */ + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); + sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; + sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; + + err = isoal_rx_pdu_recombine(sink_hdl, &rx_pdu_meta_buf.pdu_meta); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should not be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + sdu_size, /* Frag size */ + ISOAL_SDU_STATUS_ERRORS, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer.dbuf, /* Buffer */ + sdu_buffer.size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -7379,8 +8262,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) payload_number++; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; testdata_indx = testdata_size; @@ -7460,6 +8342,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -7479,11 +8362,12 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -7503,8 +8387,9 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) stream_sync_delay, group_sync_delay); sdu_timeoffset = group_sync_delay - 50; - sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + /* PDU will have errors. Time stamp is only an approximation */ + sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); + seqn = 0; testdata_indx = 0; testdata_size = 23; sdu_size = 0; @@ -7576,8 +8461,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) payload_number++; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; testdata_indx = testdata_size; @@ -7680,11 +8564,11 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err3) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -7705,7 +8589,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err3) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 35; sdu_size = 35; @@ -7842,21 +8726,22 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err3) */ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) { + struct rx_sdu_frag_buffer rx_sdu_frag_buf[2]; struct rx_pdu_meta_buffer rx_pdu_meta_buf; - struct rx_sdu_frag_buffer rx_sdu_frag_buf; - struct isoal_sdu_buffer sdu_buffer; - isoal_sdu_status_t collated_status; + struct isoal_sdu_buffer sdu_buffer[2]; + isoal_sdu_status_t collated_status[2]; isoal_sink_handle_t sink_hdl; + isoal_sdu_len_t sdu_size[2]; + uint16_t total_sdu_size[2]; uint32_t stream_sync_delay; uint32_t group_sync_delay; - isoal_sdu_len_t sdu_size; + uint32_t sdu_timestamp[2]; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; uint64_t payload_number; - uint16_t total_sdu_size; uint32_t sdu_timeoffset; uint32_t pdu_timestamp; - uint32_t sdu_timestamp; uint16_t testdata_indx; uint16_t testdata_size; uint32_t sdu_interval; @@ -7871,20 +8756,24 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); - isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); init_test_data_buffer(testdata, 33); memset(pdu_data_loc, 0, sizeof(pdu_data_loc)); - sdu_buffer.dbuf = &rx_sdu_frag_buf; - sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0]; + sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1]; + sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; payload_number = 1000 * BN; pdu_timestamp = 9249; latency = calc_rx_latency_by_role(role, @@ -7895,13 +8784,13 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) stream_sync_delay, group_sync_delay); sdu_timeoffset = group_sync_delay - 50; - sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); + seqn = 0; testdata_indx = 0; testdata_size = 13; - sdu_size = 13; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); + sdu_size[0] = 13; + total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status[0] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */ role, /* Role */ @@ -7923,7 +8812,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ - push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; @@ -7940,7 +8829,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf, /* SDU buffer */ + &rx_sdu_frag_buf[0], /* SDU buffer */ &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[0]], /* PDU payload */ (testdata_size - testdata_indx)); /* Size */ @@ -7949,14 +8838,14 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ BT_ISO_SINGLE, /* Frag state */ - sdu_size, /* Frag size */ + sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ - sdu_timestamp, /* Timestamp */ + sdu_timestamp[0], /* Timestamp */ seqn, /* Seq. number */ - sdu_buffer.dbuf, /* Buffer */ - sdu_buffer.size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ + sdu_buffer[0].dbuf, /* Buffer */ + sdu_buffer[0].size, /* Buffer size */ + total_sdu_size[0], /* Total size */ + collated_status[0]); /* SDU status */ /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -7965,38 +8854,36 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_START)); - /* PDU 2 -------------------------------------------------------------*/ + /* PDU 1 -------------------------------------------------------------*/ /* Not transferred to the ISO-AL */ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); - isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); payload_number++; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; - sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - /* ISO-AL has no concept of time and is unable to detect than an SDU - * has been lost. Sequence number does not increment. - * seqn = seqn; - */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); + testdata_indx = testdata_size; testdata_size += 10; + sdu_size[0] = 0; + total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status[0] = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); - /* PDU 3 -------------------------------------------------------------*/ + /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); - isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); payload_number++; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; - sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn++; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); testdata_indx = testdata_size; testdata_size += 10; - sdu_size = 10; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); + sdu_size[1] = 10; + total_sdu_size[1] = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]); + collated_status[1] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, @@ -8008,7 +8895,8 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ - push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; @@ -8018,6 +8906,30 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ + /* SDU 2 -------------------------------------------------------------*/ + seqn++; + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should not be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + sdu_size[0], /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[0], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[0].dbuf, /* Buffer */ + sdu_buffer[0].size, /* Buffer size */ + total_sdu_size[0], /* Total size */ + collated_status[0]); /* SDU status */ + + /* SDU 3 -------------------------------------------------------------*/ + seqn++; /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -8025,7 +8937,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf, /* SDU buffer */ + &rx_sdu_frag_buf[1], /* SDU buffer */ &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]], /* PDU payload */ (testdata_size - testdata_indx)); /* Size */ @@ -8034,14 +8946,14 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ BT_ISO_SINGLE, /* Frag state */ - sdu_size, /* Frag size */ + sdu_size[1], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ - sdu_timestamp, /* Timestamp */ + sdu_timestamp[1], /* Timestamp */ seqn, /* Seq. number */ - sdu_buffer.dbuf, /* Buffer */ - sdu_buffer.size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size[1], /* Total size */ + collated_status[1]); /* SDU status */ /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -8068,6 +8980,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1) isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -8087,13 +9000,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = iso_interval_us + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); init_test_data_buffer(testdata, 46); @@ -8111,8 +9025,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1) stream_sync_delay, group_sync_delay); sdu_timeoffset = group_sync_delay - 50; - sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn = 1; + sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 0; @@ -8149,6 +9063,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -8177,7 +9092,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_ERR_SPOOL)); - /* PDU 2 -------------------------------------------------------------*/ + /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; @@ -8210,7 +9125,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_ERR_SPOOL)); - /* PDU 3 -------------------------------------------------------------*/ + /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; @@ -8243,14 +9158,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_ERR_SPOOL)); - /* PDU 4 -------------------------------------------------------------*/ + /* PDU 3 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; + pdu_timestamp += iso_interval_us; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; testdata_indx = testdata_size; @@ -8278,6 +9193,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 1 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -8329,6 +9245,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err2) isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -8348,11 +9265,12 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err2) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -8373,7 +9291,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err2) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -8517,8 +9435,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err2) payload_number++; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; testdata_indx = testdata_size; @@ -8597,6 +9514,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err3) isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -8616,11 +9534,12 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err3) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -8641,7 +9560,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err3) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -8794,8 +9713,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err3) payload_number++; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; testdata_indx = testdata_size; @@ -8874,6 +9792,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_seq_err1) isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -8893,11 +9812,12 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_seq_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -8918,7 +9838,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_seq_err1) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -9038,8 +9958,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_seq_err1) payload_number++; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; testdata_indx = testdata_size; @@ -9118,6 +10037,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_seq_err1) isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -9137,11 +10057,12 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_seq_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -9162,7 +10083,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_seq_err1) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -9282,8 +10203,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_seq_err1) payload_number++; - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; testdata_indx = testdata_size; @@ -9355,22 +10275,23 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) struct rx_pdu_meta_buffer rx_pdu_meta_buf; struct rx_sdu_frag_buffer rx_sdu_frag_buf[2]; struct isoal_sdu_buffer sdu_buffer[2]; - isoal_sdu_status_t collated_status; + isoal_sdu_status_t collated_status[2]; isoal_sink_handle_t sink_hdl; uint32_t stream_sync_delay; uint32_t group_sync_delay; isoal_sdu_len_t sdu_size[2]; + uint16_t total_sdu_size[2]; uint8_t iso_interval_int; uint32_t sdu_timestamp[2]; uint16_t pdu_data_loc[5]; - isoal_sdu_cnt_t seqn[2]; + uint32_t iso_interval_us; uint64_t payload_number; - uint16_t total_sdu_size; uint32_t sdu_timeoffset; uint32_t pdu_timestamp; uint16_t testdata_indx; uint16_t testdata_size; uint32_t sdu_interval; + isoal_sdu_cnt_t seqn; uint8_t testdata[63]; isoal_status_t err; uint32_t latency; @@ -9381,11 +10302,12 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -9408,13 +10330,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) stream_sync_delay, group_sync_delay); sdu_timeoffset = group_sync_delay - 50; - sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn[0] = 1; + /* PDU will have errors. Time stamp is only an approximation */ + sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size[0] = 0; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); + total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status[0] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */ role, /* Role */ @@ -9446,12 +10369,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ + /* SDU 1 -------------------------------------------------------------*/ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, @@ -9460,11 +10385,11 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_ERRORS, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ + total_sdu_size[0], /* Total size */ + collated_status[0]); /* SDU status */ /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -9489,10 +10414,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[1] = seqn[0] + 1; testdata_indx = testdata_size; testdata_size += 17; sdu_size[1] = 17; @@ -9512,12 +10435,13 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ - /* SDU 1 */ - /* SDU should not be written to */ + /* SDU 1 -------------------------------------------------------------*/ + /* SDU payload should not be written */ /* SDU shold not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1); - /* SDU 2 */ + /* SDU 2 -------------------------------------------------------------*/ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -9546,8 +10470,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) testdata_indx = testdata_size; testdata_size += 10; sdu_size[1] += 10; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); + total_sdu_size[1] = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]); + collated_status[1] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, @@ -9566,7 +10490,10 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ + /* SDU 2 -------------------------------------------------------------*/ + seqn++; /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(2); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -9582,11 +10509,11 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) sdu_size[1], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[1], /* Timestamp */ - seqn[1], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[1].dbuf, /* Buffer */ sdu_buffer[1].size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ + total_sdu_size[1], /* Total size */ + collated_status[1]); /* SDU status */ /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -9595,22 +10522,28 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_START)); + /* SDU 3 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); + sdu_size[1] = 0; + total_sdu_size[1] = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]); + collated_status[1] = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + /* PDU 4 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); payload_number++; - pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); - - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + pdu_timestamp = 9249 + iso_interval_us; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true); sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = seqn[1] + 1; testdata_indx = testdata_size; testdata_size += 13; sdu_size[0] = 13; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); + total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status[0] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, @@ -9622,6 +10555,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; @@ -9632,6 +10566,30 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ + /* SDU 3 -------------------------------------------------------------*/ + seqn++; + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should not be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + sdu_size[1], /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[1], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size[1], /* Total size */ + collated_status[1]); /* SDU status */ + + /* SDU 4 -------------------------------------------------------------*/ + seqn++; /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -9651,11 +10609,11 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ + total_sdu_size[0], /* Total size */ + collated_status[0]); /* SDU status */ /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -9668,22 +10626,38 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) /** * Test Suite : RX framed PDU recombination * - * Tests recombination of two SDUs from three segmented PDUs + * Tests handling errors in the middle of a stream, where the errors occur + * across the end of one SDU and into the start of the next SDU. + * + * Expected Sequence: + * -- Total of 4 SDUs released across 2 events + * -- Event 1: PDU0 Valid SDU 0 Framed Start + * PDU1 Errors SDU 0 Framed End + * SDU 1 Framed Start + * -----> SDU 0 Bit Errors (Released) + * PDU2 Valid SDU 1 Framed End + * Missing SDU 2 + * Event 2: PDU3 Valid SDU 3 Framed Single + * -----> SDU 1 Lost (Released) + * -----> SDU 2 Lost (Released) + * -----> SDU 3 Valid (Released) + * PDU4 N/A + * PDU5 N/A */ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) { struct rx_pdu_meta_buffer rx_pdu_meta_buf; - struct rx_sdu_frag_buffer rx_sdu_frag_buf[2]; - struct isoal_sdu_buffer sdu_buffer[2]; + struct rx_sdu_frag_buffer rx_sdu_frag_buf[3]; + struct isoal_sdu_buffer sdu_buffer[3]; isoal_sdu_status_t collated_status; isoal_sink_handle_t sink_hdl; uint32_t stream_sync_delay; uint32_t group_sync_delay; isoal_sdu_len_t sdu_size[2]; uint8_t iso_interval_int; - uint32_t sdu_timestamp[2]; + uint32_t sdu_timestamp[3]; uint16_t pdu_data_loc[5]; - isoal_sdu_cnt_t seqn[2]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -9691,6 +10665,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) uint16_t testdata_indx; uint16_t testdata_size; uint32_t sdu_interval; + isoal_sdu_cnt_t seqn; uint8_t testdata[63]; isoal_status_t err; uint32_t latency; @@ -9701,23 +10676,27 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]); init_test_data_buffer(testdata, 63); memset(pdu_data_loc, 0, sizeof(pdu_data_loc)); sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0]; sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1]; + sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2]; sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; payload_number = 1000 * BN; pdu_timestamp = 9249; latency = calc_rx_latency_by_role(role, @@ -9729,7 +10708,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size[0] = 13; @@ -9763,6 +10742,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -9785,7 +10765,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 2 -------------------------------------------------------------*/ + /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; @@ -9803,10 +10783,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[1] = seqn[0]; testdata_indx = testdata_size; testdata_size += 17; sdu_size[1] = 0; @@ -9823,8 +10801,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ - /* SDU 1 */ /* A new SDU should not be allocated */ /* SDU payload should not be written */ @@ -9836,13 +10814,13 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_ERRORS, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ collated_status); /* SDU status */ - /* SDU 2 */ + /* SDU 1 -------------------------------------------------------------*/ /* A new SDU should not be allocated */ /* SDU payload should not be written */ @@ -9856,7 +10834,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_ERR_SPOOL)); - /* PDU 3 -------------------------------------------------------------*/ + /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; @@ -9875,6 +10853,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 1 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* Should not allocate a new SDU */ @@ -9889,22 +10868,23 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_ERR_SPOOL)); + /* SDU 2 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + sdu_timestamp[2] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); + /* PDU 4 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); payload_number++; - pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); + pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true); sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = seqn[1] + 1; testdata_indx = testdata_size; testdata_size += 13; sdu_size[0] = 13; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, @@ -9916,6 +10896,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]); push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; @@ -9925,6 +10907,58 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 1 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[1], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 2 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[2], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[2].dbuf, /* Buffer */ + sdu_buffer[2].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 3 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -9945,7 +10979,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ @@ -9962,7 +10996,23 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) /** * Test Suite : RX framed PDU recombination * - * Tests recombination of two SDUs from three segmented PDUs + * Tests handling errors in the middle of a stream, where the errors occur + * at the end of the SDU. + * + * Expected Sequence: + * -- Total of 4 SDUs released across 2 events + * -- Event 1: PDU0 Valid SDU 0 Framed Start + * PDU1 Valid SDU 0 Framed End + * SDU 1 Framed Start + * -----> SDU 0 Valid (Released) + * PDU2 Errors SDU 1 Framed End + * -----> SDU 1 Bit Errors (Released) + * Missing SDU 2 + * Event 2: PDU3 Valid SDU 3 Framed Single + * -----> SDU 2 Lost (Released) + * -----> SDU 3 Valid (Released) + * PDU4 N/A + * PDU5 N/A */ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) { @@ -9977,7 +11027,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) uint8_t iso_interval_int; uint32_t sdu_timestamp[2]; uint16_t pdu_data_loc[5]; - isoal_sdu_cnt_t seqn[2]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -9985,6 +11035,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) uint16_t testdata_indx; uint16_t testdata_size; uint32_t sdu_interval; + isoal_sdu_cnt_t seqn; uint8_t testdata[63]; isoal_status_t err; uint32_t latency; @@ -9995,13 +11046,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); @@ -10023,7 +11075,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size[0] = 13; @@ -10056,6 +11108,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -10078,7 +11131,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 2 -------------------------------------------------------------*/ + /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; @@ -10094,10 +11147,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[1] = seqn[0] + 1; testdata_indx = testdata_size; testdata_size += 17; sdu_size[1] = 17; @@ -10117,8 +11168,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ - /* SDU 1 */ total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); @@ -10138,13 +11189,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ collated_status); /* SDU status */ - /* SDU 2 */ + /* SDU 1 -------------------------------------------------------------*/ + seqn++; /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1], &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -10166,7 +11218,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 3 -------------------------------------------------------------*/ + /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; @@ -10191,6 +11243,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 1 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should not be allocated */ @@ -10203,7 +11256,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) sdu_size[1], /* Frag size */ ISOAL_SDU_STATUS_ERRORS, /* Frag status */ sdu_timestamp[1], /* Timestamp */ - seqn[1], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[1].dbuf, /* Buffer */ sdu_buffer[1].size, /* Buffer size */ total_sdu_size, /* Total size */ @@ -10216,22 +11269,23 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_ERR_SPOOL)); - /* PDU 4 -------------------------------------------------------------*/ + /* SDU 2 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); + + /* PDU 3 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); payload_number++; - pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); + pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true); sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = seqn[1] + 1; testdata_indx = testdata_size; testdata_size += 13; sdu_size[0] = 13; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, @@ -10243,6 +11297,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; @@ -10252,6 +11307,36 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 2 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should not be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[1], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 3 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -10272,7 +11357,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ @@ -10289,22 +11374,39 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) /** * Test Suite : RX framed PDU recombination * - * Tests recombination of two SDUs from three segmented PDUs with errors + * Tests handling missing PDU (sequence) errors in the middle of a stream, where + * the errors occur across the end of one SDU and into the start of the next + * SDU. + * + * Expected Sequence: + * -- Total of 4 SDUs released across 2 events + * -- Event 1: PDU0 Valid SDU 0 Framed Start + * PDU1 Missing SDU 0 Framed End + * SDU 1 Framed Start + * -----> SDU 0 Valid (Released) + * PDU2 Valid SDU 1 Framed End + * Missing SDU 2 + * Event 2: PDU3 Valid SDU 3 Framed Single + * -----> SDU 1 Lost (Released) + * -----> SDU 2 Lost (Released) + * -----> SDU 3 Valid (Released) + * PDU4 N/A + * PDU5 N/A */ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) { + struct rx_sdu_frag_buffer rx_sdu_frag_buf[3]; struct rx_pdu_meta_buffer rx_pdu_meta_buf; - struct rx_sdu_frag_buffer rx_sdu_frag_buf[2]; - struct isoal_sdu_buffer sdu_buffer[2]; + struct isoal_sdu_buffer sdu_buffer[3]; isoal_sdu_status_t collated_status; isoal_sink_handle_t sink_hdl; + isoal_sdu_len_t sdu_size[2]; uint32_t stream_sync_delay; uint32_t group_sync_delay; - isoal_sdu_len_t sdu_size[2]; uint8_t iso_interval_int; - uint32_t sdu_timestamp[2]; + uint32_t sdu_timestamp[3]; uint16_t pdu_data_loc[5]; - isoal_sdu_cnt_t seqn[2]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -10312,6 +11414,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) uint16_t testdata_indx; uint16_t testdata_size; uint32_t sdu_interval; + isoal_sdu_cnt_t seqn; uint8_t testdata[63]; isoal_status_t err; uint32_t latency; @@ -10322,23 +11425,27 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]); init_test_data_buffer(testdata, 63); memset(pdu_data_loc, 0, sizeof(pdu_data_loc)); sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0]; sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1]; + sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2]; sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; payload_number = 1000 * BN; pdu_timestamp = 9249; latency = calc_rx_latency_by_role(role, @@ -10350,7 +11457,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size[0] = 13; @@ -10383,6 +11490,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -10397,6 +11505,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -10413,13 +11522,10 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) testdata_size += 10; /* No change in SDU 1 size */ - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + /* SDU 1 -------------------------------------------------------------*/ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - /* ISO-AL has no concept of time and is unable to detect than an SDU - * has been lost. Sequence number does not increment. - */ - seqn[1] = seqn[0]; + testdata_indx = testdata_size; testdata_size += 17; sdu_size[1] = 0; @@ -10450,11 +11556,13 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ - /* SDU 1 */ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1); /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1); /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, @@ -10463,13 +11571,19 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ collated_status); /* SDU status */ - /* SDU 2 - lost */ + /* SDU 1 -------------------------------------------------------------*/ + /* Lost */ + + /* SDU 2 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + sdu_timestamp[2] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -10483,12 +11597,10 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); payload_number++; - pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); + pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true); sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = seqn[1] + 1; testdata_indx = testdata_size; testdata_size += 13; sdu_size[0] = 13; @@ -10505,6 +11617,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]); push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; @@ -10514,6 +11628,62 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 1 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU should not be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[1], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 2 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU should not be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[2], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[2].dbuf, /* Buffer */ + sdu_buffer[2].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 3 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -10534,7 +11704,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ @@ -10551,22 +11721,39 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) /** * Test Suite : RX framed PDU recombination * - * Tests recombination of two SDUs from three segmented PDUs with errors + * Tests handling missing PDU (sequence) errors followed by bit errors in the + * middle of a stream, where the errors occur across the end of one SDU and + * into the start of the next SDU. + * + * Expected Sequence: + * -- Total of 4 SDUs released across 2 events + * -- Event 1: PDU0 Valid SDU 0 Framed Start + * PDU1 Missing SDU 0 Framed End + * SDU 1 Framed Start + * -----> SDU 0 Lost (Released) + * PDU2 Errors SDU 1 Framed End + * Missing SDU 2 + * Event 2: PDU3 Valid SDU 3 Framed Single + * -----> SDU 1 Lost (Released) + * -----> SDU 2 Lost (Released) + * -----> SDU 3 Valid (Released) + * PDU4 N/A + * PDU5 N/A */ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) { + struct rx_sdu_frag_buffer rx_sdu_frag_buf[3]; struct rx_pdu_meta_buffer rx_pdu_meta_buf; - struct rx_sdu_frag_buffer rx_sdu_frag_buf[2]; - struct isoal_sdu_buffer sdu_buffer[2]; + struct isoal_sdu_buffer sdu_buffer[3]; isoal_sdu_status_t collated_status; isoal_sink_handle_t sink_hdl; uint32_t stream_sync_delay; uint32_t group_sync_delay; isoal_sdu_len_t sdu_size[2]; uint8_t iso_interval_int; - uint32_t sdu_timestamp[2]; + uint32_t sdu_timestamp[3]; uint16_t pdu_data_loc[5]; - isoal_sdu_cnt_t seqn[2]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -10574,6 +11761,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) uint16_t testdata_indx; uint16_t testdata_size; uint32_t sdu_interval; + isoal_sdu_cnt_t seqn; uint8_t testdata[63]; isoal_status_t err; uint32_t latency; @@ -10584,23 +11772,27 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[2]); init_test_data_buffer(testdata, 63); memset(pdu_data_loc, 0, sizeof(pdu_data_loc)); sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0]; sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1]; + sdu_buffer[2].dbuf = &rx_sdu_frag_buf[2]; sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[2].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; payload_number = 1000 * BN; pdu_timestamp = 9249; latency = calc_rx_latency_by_role(role, @@ -10612,7 +11804,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size[0] = 13; @@ -10646,6 +11838,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -10660,6 +11853,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -10674,15 +11868,12 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) payload_number++; testdata_indx = testdata_size; testdata_size += 10; - /* No change in SDU 1 size */ + /* No change in SDU 0 size */ - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + /* SDU 1 -------------------------------------------------------------*/ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - /* ISO-AL has no concept of time and is unable to detect than an SDU - * has been lost. Sequence number does not increment. - */ - seqn[1] = seqn[0]; + testdata_indx = testdata_size; testdata_size += 17; sdu_size[1] = 0; @@ -10713,11 +11904,13 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ - /* SDU 1 */ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, @@ -10726,13 +11919,19 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ collated_status); /* SDU status */ - /* SDU 2 - lost */ + /* SDU 1 -------------------------------------------------------------*/ + /* Lost */ + + /* SDU 2 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + sdu_timestamp[2] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -10746,17 +11945,13 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); payload_number++; - pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); + pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true); sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = seqn[1] + 1; testdata_indx = testdata_size; testdata_size += 13; sdu_size[0] = 13; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, @@ -10768,6 +11963,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[2]); push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; @@ -10777,6 +11974,58 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 1 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[1], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[1], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 2 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[2], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[2].dbuf, /* Buffer */ + sdu_buffer[2].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 3 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -10797,7 +12046,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ @@ -10848,11 +12097,11 @@ ZTEST(test_rx_framed, test_rx_framed_single_invalid_pdu_single_sdu) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -10873,7 +12122,7 @@ ZTEST(test_rx_framed, test_rx_framed_single_invalid_pdu_single_sdu) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size = 13; @@ -11009,11 +12258,11 @@ ZTEST(test_rx_framed, test_rx_framed_single_invalid_pdu_single_sdu_hdr_err) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + sdu_interval = ((iso_interval_int * ISO_INT_UNIT_US) / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -11034,7 +12283,7 @@ ZTEST(test_rx_framed, test_rx_framed_single_invalid_pdu_single_sdu_hdr_err) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn = 1; + seqn = 0; testdata_indx = 0; testdata_size = 3; sdu_size = 3; @@ -11164,8 +12413,17 @@ ZTEST(test_rx_framed, test_rx_framed_single_invalid_pdu_single_sdu_hdr_err) /** * Test Suite : RX framed PDU recombination * - * Tests recombination of two SDUs from three segmented PDUs where there is a - * length error in the first SDU's segments + * Tests handling an error in the length of an SDU seqment where the CRC check + * does not fail. + * + * Expected Sequence: + * -- Total of 2 SDUs released across 1 event + * -- Event 1: PDU0 valid SDU 0 Framed Start (Seg Error) + * -----> SDU 0 Lost (Released) + * PDU1 Valid SDU 0 Framed End + * SDU 1 Framed Start + * PDU2 Valid SDU 1 Framed End + * -----> SDU 1 Valid (Released) * * Qualification: * IAL/CIS/FRA/PER/BI-01-C @@ -11184,6 +12442,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) uint8_t iso_interval_int; uint32_t sdu_timestamp[2]; uint16_t pdu_data_loc[5]; + uint32_t iso_interval_us; isoal_sdu_cnt_t seqn[2]; uint64_t payload_number; uint16_t total_sdu_size; @@ -11202,13 +12461,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; - /* PDU 1 -------------------------------------------------------------*/ + /* PDU 0 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); @@ -11229,8 +12489,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) stream_sync_delay, group_sync_delay); sdu_timeoffset = group_sync_delay - 50; - sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency); - seqn[0] = 1; + sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); + seqn[0] = 0; testdata_indx = 0; testdata_size = 13; sdu_size[0] = 0; @@ -11270,6 +12530,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -11298,7 +12559,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_ERR_SPOOL)); - /* PDU 2 -------------------------------------------------------------*/ + /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; @@ -11314,8 +12575,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[1] = seqn[0] + 1; testdata_indx = testdata_size; @@ -11336,15 +12596,15 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ - /* SDU 1 */ /* A new SDU should not be allocated */ /* SDU payload should not be written */ /* SDU should not be emitted */ - /* SDU 2 */ + /* SDU 1 -------------------------------------------------------------*/ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -11358,6 +12618,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(1); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -11366,7 +12627,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) FSM_TO_STR(isoal_global.sink_state[sink_hdl].sdu_production.fsm), FSM_TO_STR(ISOAL_CONTINUE)); - /* PDU 3 -------------------------------------------------------------*/ + /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); payload_number++; @@ -11392,8 +12653,10 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 1 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(2); /* SDU payload should be written */ ZASSERT_ISOAL_SDU_WRITE_TEST(val, @@ -11427,7 +12690,23 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) * Test Suite : RX framed PDU recombination * * Tests recombination of two SDUs from three segmented PDUs where there is a - * length error in the second SDU's segments + * length error in the second SDU's segments that does not cause the CRC to + * fail. + * + * Expected Sequence: + * -- Total of 4 SDUs released across 2 event + * -- Event 1: PDU0 valid SDU 0 Framed Start + * PDU1 Valid SDU 0 Framed End + * SDU 1 Framed Start (Seg Error) + * -----> SDU 0 Valid (Released) + * -----> SDU 1 Lost (Released) + * PDU2 Valid SDU 1 Framed End + * Missing SDU 2 + * -- Event 2: PDU3 valid SDU 3 Framed Single + * -----> SDU 2 Lost (Released) + * -----> SDU 3 Valid (Released) + * PDU4 N/A + * PDU5 N/A * * Qualification: * IAL/CIS/FRA/PER/BI-01-C @@ -11435,18 +12714,18 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) */ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) { - struct rx_pdu_meta_buffer rx_pdu_meta_buf; struct rx_sdu_frag_buffer rx_sdu_frag_buf[2]; + struct rx_pdu_meta_buffer rx_pdu_meta_buf; struct isoal_sdu_buffer sdu_buffer[2]; isoal_sdu_status_t collated_status; isoal_sink_handle_t sink_hdl; + isoal_sdu_len_t sdu_size[2]; uint32_t stream_sync_delay; uint32_t group_sync_delay; - isoal_sdu_len_t sdu_size[2]; - uint8_t iso_interval_int; uint32_t sdu_timestamp[2]; + uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; - isoal_sdu_cnt_t seqn[2]; + uint32_t iso_interval_us; uint64_t payload_number; uint16_t total_sdu_size; uint32_t sdu_timeoffset; @@ -11454,6 +12733,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) uint16_t testdata_indx; uint16_t testdata_size; uint32_t sdu_interval; + isoal_sdu_cnt_t seqn; uint8_t testdata[63]; isoal_status_t err; uint32_t latency; @@ -11464,11 +12744,12 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ((iso_interval_int * CONN_INT_UNIT_US) / 3) + 5; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (iso_interval_us / 3) + 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); @@ -11492,7 +12773,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = 1; + seqn = 0; testdata_indx = 0; testdata_size = 13; sdu_size[0] = 13; @@ -11526,6 +12807,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 0 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -11540,6 +12822,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) (testdata_size - testdata_indx)); /* Size */ /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -11564,10 +12847,8 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); sdu_timestamp[1] = sdu_timestamp[0] + sdu_interval; - seqn[1] = seqn[0] + 1; testdata_indx = testdata_size; testdata_size += 17; sdu_size[1] = 0; @@ -11590,10 +12871,10 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); - /* Test recombine (Black Box) */ - /* SDU 1 */ + /* SDU 0 -------------------------------------------------------------*/ total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); + /* Test recombine (Black Box) */ /* A new SDU should not be allocated */ @@ -11611,13 +12892,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ collated_status); /* SDU status */ - /* SDU 2 */ + /* SDU 1 -------------------------------------------------------------*/ + seqn++; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); @@ -11627,6 +12909,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) &rx_pdu_meta_buf.pdu_meta); /* PDU */ /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(2); /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, @@ -11635,7 +12918,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) sdu_size[1], /* Frag size */ ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ sdu_timestamp[1], /* Timestamp */ - seqn[1], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[1].dbuf, /* Buffer */ sdu_buffer[1].size, /* Buffer size */ total_sdu_size, /* Total size */ @@ -11668,12 +12951,21 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 2 -------------------------------------------------------------*/ + /* Missing */ + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); + sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); + + /* SDU 1 -------------------------------------------------------------*/ /* Test recombine (Black Box) */ /* Should not allocate a new SDU */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(2); /* SDU should not be written to */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(2); /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(2); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -11687,17 +12979,14 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); payload_number++; - pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); + pdu_timestamp = 9249 + (iso_interval_int * ISO_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : - sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; + sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, true); sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn[0] = seqn[1] + 1; + testdata_indx = testdata_size; testdata_size += 13; sdu_size[0] = 13; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, @@ -11709,6 +12998,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; @@ -11718,6 +13008,34 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + /* SDU 2 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(0, 0); + collated_status = + COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); + /* Test recombine (Black Box) */ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[2], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + 0, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[1], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ + + /* SDU 3 -------------------------------------------------------------*/ + seqn++; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); /* Test recombine (Black Box) */ /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, @@ -11738,7 +13056,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) sdu_size[0], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ sdu_timestamp[0], /* Timestamp */ - seqn[0], /* Seq. number */ + seqn, /* Seq. number */ sdu_buffer[0].dbuf, /* Buffer */ sdu_buffer[0].size, /* Buffer size */ total_sdu_size, /* Total size */ diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c index e20de78ae4aeb0..42fc0af89a8f17 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c @@ -9,11 +9,10 @@ * */ - /* Each segment header in a test would usually be written to when it is first * inserted and again when the segment is finalized. */ -#define EXPECTED_SEG_HDR_WRITES (2) +#define EXPECTED_SEG_HDR_WRITES (2) /*------------------ PDU Allocation Callback ---------------------------------*/ /* Fake function */ @@ -601,8 +600,6 @@ ZTEST(test_tx_basics, test_source_isoal_test_create_destroy) i, ROLE_TO_STR(role)); - zassert_not_null(isoal_get_source_param_ref(source_hdl[i]), ""); - framed = !framed; burst_number++; flush_timeout = (flush_timeout % 3) + 1; @@ -712,21 +709,6 @@ ZTEST(test_tx_basics, test_source_isoal_test_create_err) "Source creation did not return error as expected!"); } -/** - * Test Suite : TX basic test - * - * Test assertion when attempting to retrieve source params for an invalid source - * handle. - */ -ZTEST(test_tx_basics, test_source_invalid_ref) -{ - ztest_set_assert_valid(true); - - isoal_get_source_param_ref(99); - - ztest_set_assert_valid(false); -} - /** * Test Suite : TX unframed SDU fragmentation * @@ -3167,6 +3149,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) uint8_t role; uint8_t BN; uint8_t FT; + /* Settings */ role = BT_CONN_ROLE_PERIPHERAL; iso_interval_int = 1; @@ -5095,9 +5078,9 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) */ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) { - const uint8_t number_of_pdus = 2; - const uint8_t number_of_sdu_frags = 3; - const uint8_t testdata_size_max = MAX_FRAMED_PDU_PAYLOAD(number_of_pdus); + const uint8_t number_of_pdus = 2; + const uint8_t number_of_sdu_frags = 3; + const uint8_t testdata_size_max = MAX_FRAMED_PDU_PAYLOAD(number_of_pdus); const uint8_t number_of_seg_hdr_buf = EXPECTED_SEG_HDR_WRITES * number_of_pdus; struct tx_pdu_meta_buffer tx_pdu_meta_buf[number_of_pdus]; @@ -6390,7 +6373,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU) isoal_global.source_state[source_hdl].session.handle); } - /** * Test Suite : TX framed SDU segmentation * @@ -6520,10 +6502,11 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) seg_hdr[1].cmplt = 1; seg_hdr[1].len += (pdu_write_size - pdu_write_loc); - ZASSERT_PDU_WRITE_TEST(history[1], pdu_buffer[0], - pdu_hdr_loc, - &seg_hdr[1], - PDU_ISO_SEG_HDR_SIZE); + ZASSERT_PDU_WRITE_TEST(history[1], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[1], + PDU_ISO_SEG_HDR_SIZE); /* PDU should not be emitted */ ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0); @@ -6534,12 +6517,13 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) /* Send Event Timeout ----------------------------------------------- */ isoal_tx_event_prepare(source_hdl, event_number); - ZASSERT_PDU_EMIT_TEST(history[0], &tx_pdu_meta_buf[0].node_tx, - payload_number, - sdu_fragments, - PDU_BIS_LLID_FRAMED, - pdu_write_size, - isoal_global.source_state[source_hdl].session.handle); + ZASSERT_PDU_EMIT_TEST(history[0], + &tx_pdu_meta_buf[0].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); /* PDU 2 (Padding) */ payload_number++; @@ -6549,12 +6533,13 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) /* PDU should not be written to */ ZASSERT_PDU_WRITE_TEST_CALL_COUNT(2); - ZASSERT_PDU_EMIT_TEST(history[1], &tx_pdu_meta_buf[1].node_tx, - payload_number, - sdu_fragments, - PDU_BIS_LLID_FRAMED, - pdu_write_size, - isoal_global.source_state[source_hdl].session.handle); + ZASSERT_PDU_EMIT_TEST(history[1], + &tx_pdu_meta_buf[1].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); /* PDU 3 (Padding) */ payload_number++; @@ -6563,12 +6548,13 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) /* PDU should not be written to */ ZASSERT_PDU_WRITE_TEST_CALL_COUNT(2); - ZASSERT_PDU_EMIT_TEST(history[2], &tx_pdu_meta_buf[2].node_tx, - payload_number, - sdu_fragments, - PDU_BIS_LLID_FRAMED, - pdu_write_size, - isoal_global.source_state[source_hdl].session.handle); + ZASSERT_PDU_EMIT_TEST(history[2], + &tx_pdu_meta_buf[2].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); } /**