Skip to content

Commit 11b89ab

Browse files
committed
nimble/ll/test: Refactor ISO tests and implement test fixtures
This refactors the ISO test suite by introducing a dedicated test fixture, which ensures a clean state for every individual test case. By automating the reset process, we reduce boilerplate code and make the suite significantly easier to maintain and extend. Additionally, the ISO test buffer size has been re-evaluated and adjusted to properly accommodate both the payload data and the required ISO headers, preventing potential buffer overflows during testing.
1 parent ece8a7b commit 11b89ab

2 files changed

Lines changed: 308 additions & 246 deletions

File tree

nimble/controller/test/src/ble_ll_iso.c

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,41 @@ const struct test_ll_common_params test_ll_common_params_bn_1 = {
8080
.Sync_Timeout = 100,
8181
};
8282

83+
struct test_ll_iso_fixture {
84+
struct ble_ll_iso_conn conn;
85+
};
86+
87+
static void
88+
test_ll_iso_setup(struct test_ll_iso_fixture *fixture,
89+
const struct test_ll_common_params *params)
90+
{
91+
struct ble_ll_iso_conn_init_param conn_param = {
92+
.iso_interval_us = params->SDU_Interval * 1000,
93+
.sdu_interval_us = params->SDU_Interval * 1000,
94+
.conn_handle = 0x0001,
95+
.max_sdu = TSPX_max_tx_payload,
96+
.max_pdu = TSPX_max_tx_payload,
97+
.framing = params->Framing,
98+
.bn = params->BN
99+
};
100+
struct ble_ll_iso_conn *conn;
101+
102+
memset(fixture, 0, sizeof(*fixture));
103+
conn = &fixture->conn;
104+
105+
ble_ll_iso_conn_init(conn, &conn_param);
106+
}
107+
108+
static void
109+
test_ll_iso_teardown(struct test_ll_iso_fixture *fixture)
110+
{
111+
struct ble_ll_iso_conn *conn;
112+
113+
conn = &fixture->conn;
114+
115+
ble_ll_iso_conn_free(conn);
116+
}
117+
83118
TEST_CASE_SELF(test_ll_ist_brd_bv_01_c) {
84119
const uint8_t payload_types[] = {
85120
BLE_HCI_PAYLOAD_TYPE_ZERO_LENGTH,
@@ -93,23 +128,17 @@ TEST_CASE_SELF(test_ll_ist_brd_bv_01_c) {
93128
struct ble_hci_le_iso_transmit_test_rp iso_transmit_test_rp;
94129
struct ble_hci_le_iso_test_end_cp iso_test_end_cp;
95130
struct ble_hci_le_iso_test_end_rp iso_test_end_rp;
96-
struct ble_ll_iso_conn_init_param conn_param = {
97-
.iso_interval_us = params->SDU_Interval * 1000,
98-
.sdu_interval_us = params->SDU_Interval * 1000,
99-
.conn_handle = 0x0001,
100-
.max_sdu = TSPX_max_tx_payload,
101-
.max_pdu = TSPX_max_tx_payload,
102-
.framing = params->Framing,
103-
.bn = params->BN
104-
};
105-
struct ble_ll_iso_conn conn;
131+
struct test_ll_iso_fixture fixture;
132+
struct ble_ll_iso_conn *conn;
106133
uint8_t payload_type;
107134
uint8_t pdu[100];
108135
uint8_t llid;
109136
uint8_t rsplen = 0;
110137
int rc;
111138

112-
ble_ll_iso_conn_init(&conn, &conn_param);
139+
test_ll_iso_setup(&fixture, params);
140+
141+
conn = &fixture.conn;
113142

114143
for (uint8_t i = 0; i < ARRAY_SIZE(payload_types); i++) {
115144
payload_type = payload_types[i];
@@ -118,7 +147,7 @@ TEST_CASE_SELF(test_ll_ist_brd_bv_01_c) {
118147
* specified in Table 4.12-2 and receives a successful HCI_Command_Complete event from the IUT in response.
119148
*/
120149
rsplen = 0xFF;
121-
iso_transmit_test_cp.conn_handle = htole16(conn.handle);
150+
iso_transmit_test_cp.conn_handle = htole16(conn->handle);
122151
iso_transmit_test_cp.payload_type = payload_type;
123152
rc = ble_ll_iso_transmit_test((uint8_t *)&iso_transmit_test_cp, sizeof(iso_transmit_test_cp),
124153
(uint8_t *)&iso_transmit_test_rp, &rsplen);
@@ -131,32 +160,32 @@ TEST_CASE_SELF(test_ll_ist_brd_bv_01_c) {
131160
* 4. Repeat step 3 for a total of 5 payloads.
132161
*/
133162
for (uint8_t j = 0; j < 5; j++) {
134-
rc = ble_ll_iso_conn_event_start(&conn, 30000);
163+
rc = ble_ll_iso_conn_event_start(conn, 30000);
135164
TEST_ASSERT(rc == 0);
136165

137-
for (uint8_t k = 0; k < conn_param.bn; k++) {
166+
for (uint8_t k = 0; k < conn->mux.bn; k++) {
138167
llid = 0xFF;
139-
rc = ble_ll_iso_pdu_get(&conn, k, k, &llid, pdu);
168+
rc = ble_ll_iso_pdu_get(conn, k, k, &llid, pdu);
140169
if (payload_type == BLE_HCI_PAYLOAD_TYPE_ZERO_LENGTH) {
141170
TEST_ASSERT(rc == 0);
142171
TEST_ASSERT(llid == 0b00);
143172
} else if (payload_type == BLE_HCI_PAYLOAD_TYPE_VARIABLE_LENGTH) {
144173
TEST_ASSERT(rc >= 4);
145174
TEST_ASSERT(llid == 0b00);
146175
} else if (payload_type == BLE_HCI_PAYLOAD_TYPE_MAXIMUM_LENGTH) {
147-
TEST_ASSERT(rc == conn_param.max_pdu);
176+
TEST_ASSERT(rc == conn->mux.max_pdu);
148177
TEST_ASSERT(llid == 0b00);
149178
}
150179
}
151180

152-
rc = ble_ll_iso_conn_event_done(&conn);
181+
rc = ble_ll_iso_conn_event_done(conn);
153182
TEST_ASSERT(rc == 0);
154183
}
155184

156185
/* 5. The Upper Tester sends an HCI_LE_Setup_ISO_Data_Path command to the IUT.
157186
* 6. The IUT sends an HCI_Command_Complete event to the Upper Tester with Status set to 0x0C.
158187
*/
159-
setup_iso_data_path_cp.conn_handle = htole16(conn.handle);
188+
setup_iso_data_path_cp.conn_handle = htole16(conn->handle);
160189
setup_iso_data_path_cp.data_path_dir = 0x00;
161190
setup_iso_data_path_cp.data_path_id = 0x00;
162191
rc = ble_ll_iso_setup_iso_data_path((uint8_t *)&setup_iso_data_path_cp, sizeof(setup_iso_data_path_cp),
@@ -168,7 +197,7 @@ TEST_CASE_SELF(test_ll_ist_brd_bv_01_c) {
168197
* Received_SDU_Count, Missed_SDU_Count, and Failed_SDU_Count are all zero.
169198
*/
170199
rsplen = 0xFF;
171-
iso_test_end_cp.conn_handle = htole16(conn.handle);
200+
iso_test_end_cp.conn_handle = htole16(conn->handle);
172201
rc = ble_ll_iso_end_test((uint8_t *)&iso_test_end_cp, sizeof(iso_test_end_cp),
173202
(uint8_t *)&iso_test_end_rp, &rsplen);
174203
TEST_ASSERT(rc == 0);
@@ -179,7 +208,7 @@ TEST_CASE_SELF(test_ll_ist_brd_bv_01_c) {
179208
TEST_ASSERT(iso_test_end_rp.failed_sdu_count == 0);
180209
}
181210

182-
ble_ll_iso_conn_free(&conn);
211+
test_ll_iso_teardown(&fixture);
183212
}
184213

185214
TEST_SUITE(ble_ll_iso_test_suite) {

0 commit comments

Comments
 (0)