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>
This commit is contained in:
parent
ca51439cd1
commit
8bc094610c
2 changed files with 35 additions and 9 deletions
|
@ -18,7 +18,14 @@ CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
|
||||||
# L2CAP MPS
|
# L2CAP MPS
|
||||||
# 23+27+27=77 makes exactly three full packets
|
# 23+27+27=77 makes exactly three full packets
|
||||||
CONFIG_BT_L2CAP_TX_MTU=77
|
CONFIG_BT_L2CAP_TX_MTU=77
|
||||||
CONFIG_BT_BUF_ACL_TX_SIZE=77
|
|
||||||
|
# Use this to send L2CAP PDUs without any fragmentation.
|
||||||
|
# In this particular case, we prefer fragmenting to test that code path.
|
||||||
|
# CONFIG_BT_BUF_ACL_TX_SIZE=81
|
||||||
|
|
||||||
|
# L2CAP PDUs will be fragmented in 3 ACL packets.
|
||||||
|
CONFIG_BT_BUF_ACL_TX_SIZE=27
|
||||||
|
|
||||||
CONFIG_BT_BUF_ACL_TX_COUNT=4
|
CONFIG_BT_BUF_ACL_TX_COUNT=4
|
||||||
|
|
||||||
# The minimum value for this is
|
# The minimum value for this is
|
||||||
|
@ -31,14 +38,12 @@ CONFIG_BT_BUF_ACL_RX_SIZE=81
|
||||||
# to keep it that way as to stress the stack as much as possible.
|
# to keep it that way as to stress the stack as much as possible.
|
||||||
CONFIG_BT_L2CAP_TX_BUF_COUNT=6
|
CONFIG_BT_L2CAP_TX_BUF_COUNT=6
|
||||||
|
|
||||||
|
CONFIG_BT_CTLR_DATA_LENGTH_MAX=27
|
||||||
CONFIG_BT_CTLR_RX_BUFFERS=10
|
CONFIG_BT_CTLR_RX_BUFFERS=10
|
||||||
# The ring buffer now has space for three times as much data
|
|
||||||
# (default 27, 3*27=81), so that it does not run out of data
|
|
||||||
# while waiting for new SDUs to be queued.
|
|
||||||
CONFIG_BT_CTLR_DATA_LENGTH_MAX=81
|
|
||||||
|
|
||||||
CONFIG_BT_MAX_CONN=10
|
CONFIG_BT_MAX_CONN=10
|
||||||
|
|
||||||
CONFIG_LOG=y
|
CONFIG_LOG=y
|
||||||
CONFIG_ASSERT=y
|
CONFIG_ASSERT=y
|
||||||
CONFIG_BT_DEBUG_LOG=y
|
CONFIG_BT_DEBUG_LOG=y
|
||||||
|
CONFIG_NET_BUF_POOL_USAGE=y
|
||||||
|
|
|
@ -21,20 +21,21 @@ CREATE_FLAG(flag_l2cap_connected);
|
||||||
#define INIT_CREDITS 10
|
#define INIT_CREDITS 10
|
||||||
#define SDU_NUM 20
|
#define SDU_NUM 20
|
||||||
#define SDU_LEN 1230
|
#define SDU_LEN 1230
|
||||||
#define NUM_SEGMENTS 30
|
#define NUM_SEGMENTS 10
|
||||||
|
|
||||||
/* Only one SDU per link will be transmitted at a time */
|
/* Only one SDU per link will be transmitted at a time */
|
||||||
NET_BUF_POOL_DEFINE(sdu_tx_pool,
|
NET_BUF_POOL_DEFINE(sdu_tx_pool,
|
||||||
CONFIG_BT_MAX_CONN, BT_L2CAP_BUF_SIZE(SDU_LEN),
|
CONFIG_BT_MAX_CONN, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN),
|
||||||
8, NULL);
|
8, NULL);
|
||||||
|
|
||||||
NET_BUF_POOL_DEFINE(segment_pool,
|
NET_BUF_POOL_DEFINE(segment_pool,
|
||||||
|
/* MTU + 4 l2cap hdr + 4 ACL hdr */
|
||||||
NUM_SEGMENTS, BT_L2CAP_BUF_SIZE(CONFIG_BT_L2CAP_TX_MTU),
|
NUM_SEGMENTS, BT_L2CAP_BUF_SIZE(CONFIG_BT_L2CAP_TX_MTU),
|
||||||
8, NULL);
|
8, NULL);
|
||||||
|
|
||||||
/* Only one SDU per link will be received at a time */
|
/* Only one SDU per link will be received at a time */
|
||||||
NET_BUF_POOL_DEFINE(sdu_rx_pool,
|
NET_BUF_POOL_DEFINE(sdu_rx_pool,
|
||||||
CONFIG_BT_MAX_CONN, BT_L2CAP_BUF_SIZE(SDU_LEN),
|
CONFIG_BT_MAX_CONN, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN),
|
||||||
8, NULL);
|
8, NULL);
|
||||||
|
|
||||||
static struct bt_l2cap_le_chan l2cap_channels[L2CAP_CHANS];
|
static struct bt_l2cap_le_chan l2cap_channels[L2CAP_CHANS];
|
||||||
|
@ -44,6 +45,7 @@ static uint8_t tx_data[SDU_LEN];
|
||||||
static uint8_t tx_left[L2CAP_CHANS];
|
static uint8_t tx_left[L2CAP_CHANS];
|
||||||
static uint16_t rx_cnt;
|
static uint16_t rx_cnt;
|
||||||
static uint8_t disconnect_counter;
|
static uint8_t disconnect_counter;
|
||||||
|
static uint32_t max_seg_allocated;
|
||||||
|
|
||||||
int l2cap_chan_send(struct bt_l2cap_chan *chan, uint8_t *data, size_t len)
|
int l2cap_chan_send(struct bt_l2cap_chan *chan, uint8_t *data, size_t len)
|
||||||
{
|
{
|
||||||
|
@ -56,7 +58,7 @@ int l2cap_chan_send(struct bt_l2cap_chan *chan, uint8_t *data, size_t len)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_buf_reserve(buf, BT_L2CAP_CHAN_SEND_RESERVE);
|
net_buf_reserve(buf, BT_L2CAP_SDU_CHAN_SEND_RESERVE);
|
||||||
net_buf_add_mem(buf, data, len);
|
net_buf_add_mem(buf, data, len);
|
||||||
|
|
||||||
int ret = bt_l2cap_chan_send(chan, buf);
|
int ret = bt_l2cap_chan_send(chan, buf);
|
||||||
|
@ -74,6 +76,10 @@ struct net_buf *alloc_seg_cb(struct bt_l2cap_chan *chan)
|
||||||
{
|
{
|
||||||
struct net_buf *buf = net_buf_alloc(&segment_pool, K_NO_WAIT);
|
struct net_buf *buf = net_buf_alloc(&segment_pool, K_NO_WAIT);
|
||||||
|
|
||||||
|
if ((NUM_SEGMENTS - segment_pool.avail_count) > max_seg_allocated) {
|
||||||
|
max_seg_allocated++;
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT(buf, "Ran out of segment buffers");
|
ASSERT(buf, "Ran out of segment buffers");
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -121,6 +127,9 @@ int recv_cb(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
||||||
LOG_DBG("len %d", buf->len);
|
LOG_DBG("len %d", buf->len);
|
||||||
rx_cnt++;
|
rx_cnt++;
|
||||||
|
|
||||||
|
/* Verify SDU data matches TX'd data. */
|
||||||
|
ASSERT(memcmp(buf->data, tx_data, buf->len) == 0, "RX data doesn't match TX");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +276,11 @@ static void test_peripheral_main(void)
|
||||||
LOG_DBG("*L2CAP STRESS Peripheral started*");
|
LOG_DBG("*L2CAP STRESS Peripheral started*");
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
/* Prepare tx_data */
|
||||||
|
for (size_t i = 0; i < sizeof(tx_data); i++) {
|
||||||
|
tx_data[i] = (uint8_t)i;
|
||||||
|
}
|
||||||
|
|
||||||
err = bt_enable(NULL);
|
err = bt_enable(NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
FAIL("Can't enable Bluetooth (err %d)", err);
|
FAIL("Can't enable Bluetooth (err %d)", err);
|
||||||
|
@ -372,6 +386,11 @@ static void test_central_main(void)
|
||||||
LOG_DBG("*L2CAP STRESS Central started*");
|
LOG_DBG("*L2CAP STRESS Central started*");
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
/* Prepare tx_data */
|
||||||
|
for (size_t i = 0; i < sizeof(tx_data); i++) {
|
||||||
|
tx_data[i] = (uint8_t)i;
|
||||||
|
}
|
||||||
|
|
||||||
err = bt_enable(NULL);
|
err = bt_enable(NULL);
|
||||||
ASSERT(err == 0, "Can't enable Bluetooth (err %d)\n", err);
|
ASSERT(err == 0, "Can't enable Bluetooth (err %d)\n", err);
|
||||||
LOG_DBG("Central Bluetooth initialized.");
|
LOG_DBG("Central Bluetooth initialized.");
|
||||||
|
@ -409,6 +428,8 @@ static void test_central_main(void)
|
||||||
}
|
}
|
||||||
LOG_DBG("All peripherals disconnected.");
|
LOG_DBG("All peripherals disconnected.");
|
||||||
|
|
||||||
|
LOG_DBG("Max segment pool usage: %u bufs", max_seg_allocated);
|
||||||
|
|
||||||
PASS("L2CAP STRESS Central passed\n");
|
PASS("L2CAP STRESS Central passed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue