Skip to content

Commit a90a3cc

Browse files
jori-nordiccfriedt
authored andcommitted
Bluetooth: host: update l2cap stress test
Do these things: - use the proper macros for reserving the SDU header - make every L2CAP PDU fragment into 3 ACL packets - set tx data and verify rx matches the pattern - measure segment pool usage Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no> (cherry picked from commit 8bc0946)
1 parent fb5845a commit a90a3cc

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

tests/bluetooth/bsim_bt/bsim_test_l2cap_stress/prj.conf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
1818
# L2CAP MPS
1919
# 23+27+27=77 makes exactly three full packets
2020
CONFIG_BT_L2CAP_TX_MTU=77
21-
CONFIG_BT_BUF_ACL_TX_SIZE=77
21+
22+
# Use this to send L2CAP PDUs without any fragmentation.
23+
# In this particular case, we prefer fragmenting to test that code path.
24+
# CONFIG_BT_BUF_ACL_TX_SIZE=81
25+
26+
# L2CAP PDUs will be fragmented in 3 ACL packets.
27+
CONFIG_BT_BUF_ACL_TX_SIZE=27
28+
2229
CONFIG_BT_BUF_ACL_TX_COUNT=4
2330

2431
# The minimum value for this is
@@ -31,14 +38,12 @@ CONFIG_BT_BUF_ACL_RX_SIZE=81
3138
# to keep it that way as to stress the stack as much as possible.
3239
CONFIG_BT_L2CAP_TX_BUF_COUNT=6
3340

41+
CONFIG_BT_CTLR_DATA_LENGTH_MAX=27
3442
CONFIG_BT_CTLR_RX_BUFFERS=10
35-
# The ring buffer now has space for three times as much data
36-
# (default 27, 3*27=81), so that it does not run out of data
37-
# while waiting for new SDUs to be queued.
38-
CONFIG_BT_CTLR_DATA_LENGTH_MAX=81
3943

4044
CONFIG_BT_MAX_CONN=10
4145

4246
CONFIG_LOG=y
4347
CONFIG_ASSERT=y
4448
CONFIG_BT_DEBUG_LOG=y
49+
CONFIG_NET_BUF_POOL_USAGE=y

tests/bluetooth/bsim_bt/bsim_test_l2cap_stress/src/main.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ CREATE_FLAG(flag_l2cap_connected);
2121
#define INIT_CREDITS 10
2222
#define SDU_NUM 20
2323
#define SDU_LEN 1230
24-
#define NUM_SEGMENTS 30
24+
#define NUM_SEGMENTS 10
2525

2626
/* Only one SDU per link will be transmitted at a time */
2727
NET_BUF_POOL_DEFINE(sdu_tx_pool,
28-
CONFIG_BT_MAX_CONN, BT_L2CAP_BUF_SIZE(SDU_LEN),
28+
CONFIG_BT_MAX_CONN, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN),
2929
8, NULL);
3030

3131
NET_BUF_POOL_DEFINE(segment_pool,
32+
/* MTU + 4 l2cap hdr + 4 ACL hdr */
3233
NUM_SEGMENTS, BT_L2CAP_BUF_SIZE(CONFIG_BT_L2CAP_TX_MTU),
3334
8, NULL);
3435

3536
/* Only one SDU per link will be received at a time */
3637
NET_BUF_POOL_DEFINE(sdu_rx_pool,
37-
CONFIG_BT_MAX_CONN, BT_L2CAP_BUF_SIZE(SDU_LEN),
38+
CONFIG_BT_MAX_CONN, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN),
3839
8, NULL);
3940

4041
static struct bt_l2cap_le_chan l2cap_channels[L2CAP_CHANS];
@@ -56,7 +57,7 @@ int l2cap_chan_send(struct bt_l2cap_chan *chan, uint8_t *data, size_t len)
5657
return -ENOMEM;
5758
}
5859

59-
net_buf_reserve(buf, BT_L2CAP_CHAN_SEND_RESERVE);
60+
net_buf_reserve(buf, BT_L2CAP_SDU_CHAN_SEND_RESERVE);
6061
net_buf_add_mem(buf, data, len);
6162

6263
int ret = bt_l2cap_chan_send(chan, buf);
@@ -121,6 +122,9 @@ int recv_cb(struct bt_l2cap_chan *chan, struct net_buf *buf)
121122
LOG_DBG("len %d", buf->len);
122123
rx_cnt++;
123124

125+
/* Verify SDU data matches TX'd data. */
126+
ASSERT(memcmp(buf->data, tx_data, buf->len) == 0, "RX data doesn't match TX");
127+
124128
return 0;
125129
}
126130

@@ -267,6 +271,11 @@ static void test_peripheral_main(void)
267271
LOG_DBG("*L2CAP STRESS Peripheral started*");
268272
int err;
269273

274+
/* Prepare tx_data */
275+
for (size_t i = 0; i < sizeof(tx_data); i++) {
276+
tx_data[i] = (uint8_t)i;
277+
}
278+
270279
err = bt_enable(NULL);
271280
if (err) {
272281
FAIL("Can't enable Bluetooth (err %d)", err);
@@ -372,6 +381,11 @@ static void test_central_main(void)
372381
LOG_DBG("*L2CAP STRESS Central started*");
373382
int err;
374383

384+
/* Prepare tx_data */
385+
for (size_t i = 0; i < sizeof(tx_data); i++) {
386+
tx_data[i] = (uint8_t)i;
387+
}
388+
375389
err = bt_enable(NULL);
376390
ASSERT(err == 0, "Can't enable Bluetooth (err %d)\n", err);
377391
LOG_DBG("Central Bluetooth initialized.");

0 commit comments

Comments
 (0)