Skip to content

Commit f3dcea9

Browse files
nimble/host: Fix L2CAP unit tests
1 parent 153a7f6 commit f3dcea9

File tree

2 files changed

+13
-43
lines changed

2 files changed

+13
-43
lines changed

nimble/host/test/src/ble_hs_test_util.c

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ ble_hs_test_util_prev_tx_dequeue(void)
104104
pb = BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc);
105105
TEST_ASSERT_FATAL(pb == BLE_HCI_PB_FIRST_NON_FLUSH);
106106

107-
rc = ble_l2cap_parse_hdr(om, 0, &l2cap_hdr);
107+
rc = ble_l2cap_parse_hdr(om, &l2cap_hdr);
108108
TEST_ASSERT_FATAL(rc == 0);
109109

110110
os_mbuf_adj(om, BLE_L2CAP_HDR_SZ);
@@ -670,36 +670,13 @@ ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
670670
struct hci_data_hdr *hci_hdr,
671671
struct os_mbuf *om)
672672
{
673-
struct ble_hs_conn *conn;
674-
ble_l2cap_rx_fn *rx_cb;
675-
int reject_cid;
673+
uint8_t pb;
676674
int rc;
677675

678-
ble_hs_lock();
679-
680-
conn = ble_hs_conn_find(conn_handle);
681-
if (conn != NULL) {
682-
rc = ble_l2cap_rx(conn, hci_hdr, om, &rx_cb, &reject_cid);
683-
} else {
684-
rc = os_mbuf_free_chain(om);
685-
TEST_ASSERT_FATAL(rc == 0);
686-
}
687-
688-
ble_hs_unlock();
689-
690-
if (conn == NULL) {
691-
rc = BLE_HS_ENOTCONN;
692-
} else if (rc == 0) {
693-
TEST_ASSERT_FATAL(rx_cb != NULL);
694-
rc = rx_cb(conn->bhc_rx_chan);
695-
ble_l2cap_remove_rx(conn, conn->bhc_rx_chan);
696-
} else if (rc == BLE_HS_EAGAIN) {
697-
/* More fragments on the way. */
676+
pb = BLE_HCI_DATA_PB(hci_hdr->hdh_handle_pb_bc);
677+
rc = ble_l2cap_rx(conn_handle, pb, om);
678+
if (rc == BLE_HS_EAGAIN) {
698679
rc = 0;
699-
} else {
700-
if (reject_cid != -1) {
701-
ble_l2cap_sig_reject_invalid_cid_tx(conn_handle, 0, 0, reject_cid);
702-
}
703680
}
704681

705682
return rc;
@@ -1787,7 +1764,6 @@ ble_hs_test_util_mbuf_count(const struct ble_hs_test_util_mbuf_params *params)
17871764
{
17881765
const struct ble_att_prep_entry *prep;
17891766
const struct os_mbuf_pkthdr *omp;
1790-
const struct ble_l2cap_chan *chan;
17911767
const struct ble_hs_conn *conn;
17921768
const struct os_mbuf *om;
17931769
int count;
@@ -1813,9 +1789,7 @@ ble_hs_test_util_mbuf_count(const struct ble_hs_test_util_mbuf_params *params)
18131789
}
18141790

18151791
if (params->rx_queue) {
1816-
SLIST_FOREACH(chan, &conn->bhc_channels, next) {
1817-
count += ble_hs_test_util_mbuf_chain_len(chan->rx_buf);
1818-
}
1792+
count += ble_hs_test_util_mbuf_chain_len(conn->rx_frags);
18191793
}
18201794

18211795
if (params->prep_list) {

nimble/host/test/src/ble_l2cap_test.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ ble_l2cap_test_util_verify_tx_update_conn(
124124
}
125125

126126
static int
127-
ble_l2cap_test_util_dummy_rx(struct ble_l2cap_chan *chan)
127+
ble_l2cap_test_util_dummy_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
128128
{
129129
return 0;
130130
}
@@ -220,8 +220,7 @@ ble_l2cap_test_util_verify_first_frag(uint16_t conn_handle,
220220

221221
conn = ble_hs_conn_find(conn_handle);
222222
TEST_ASSERT_FATAL(conn != NULL);
223-
TEST_ASSERT(conn->bhc_rx_chan != NULL &&
224-
conn->bhc_rx_chan->scid == BLE_L2CAP_TEST_CID);
223+
TEST_ASSERT(conn->rx_len && conn->rx_cid == BLE_L2CAP_TEST_CID);
225224

226225
ble_hs_unlock();
227226
}
@@ -240,8 +239,7 @@ ble_l2cap_test_util_verify_middle_frag(uint16_t conn_handle,
240239

241240
conn = ble_hs_conn_find(conn_handle);
242241
TEST_ASSERT_FATAL(conn != NULL);
243-
TEST_ASSERT(conn->bhc_rx_chan != NULL &&
244-
conn->bhc_rx_chan->scid == BLE_L2CAP_TEST_CID);
242+
TEST_ASSERT(conn->rx_len && conn->rx_cid == BLE_L2CAP_TEST_CID);
245243

246244
ble_hs_unlock();
247245
}
@@ -260,7 +258,7 @@ ble_l2cap_test_util_verify_last_frag(uint16_t conn_handle,
260258

261259
conn = ble_hs_conn_find(conn_handle);
262260
TEST_ASSERT_FATAL(conn != NULL);
263-
TEST_ASSERT(conn->bhc_rx_chan == NULL);
261+
TEST_ASSERT(conn->rx_len == 0);
264262

265263
ble_hs_unlock();
266264
}
@@ -279,7 +277,7 @@ TEST_CASE_SELF(ble_l2cap_test_case_bad_header)
279277
NULL, NULL);
280278

281279
rc = ble_l2cap_test_util_rx_first_frag(2, 14, 1234, 10);
282-
TEST_ASSERT(rc == BLE_HS_ENOENT);
280+
TEST_ASSERT(rc == BLE_HS_EBADDATA);
283281

284282
ble_hs_test_util_assert_mbufs_freed(NULL);
285283
}
@@ -386,8 +384,7 @@ TEST_CASE_SELF(ble_l2cap_test_case_frag_channels)
386384
ble_hs_lock();
387385
conn = ble_hs_conn_find(2);
388386
TEST_ASSERT_FATAL(conn != NULL);
389-
TEST_ASSERT(conn->bhc_rx_chan != NULL &&
390-
conn->bhc_rx_chan->scid == BLE_L2CAP_TEST_CID);
387+
TEST_ASSERT(conn->rx_len && conn->rx_cid == BLE_L2CAP_TEST_CID);
391388
ble_hs_unlock();
392389

393390
/* Receive a starting fragment on a different channel. The first fragment
@@ -400,8 +397,7 @@ TEST_CASE_SELF(ble_l2cap_test_case_frag_channels)
400397
ble_hs_lock();
401398
conn = ble_hs_conn_find(2);
402399
TEST_ASSERT_FATAL(conn != NULL);
403-
TEST_ASSERT(conn->bhc_rx_chan != NULL &&
404-
conn->bhc_rx_chan->scid == BLE_L2CAP_CID_ATT);
400+
TEST_ASSERT(conn->rx_len && conn->rx_cid == BLE_L2CAP_CID_ATT);
405401
ble_hs_unlock();
406402

407403
/* Terminate the connection. The received fragments should get freed.

0 commit comments

Comments
 (0)