Skip to content

Commit 7a6872d

Browse files
jori-nordiccarlescufi
authored andcommitted
Bluetooth: host: add l2cap stress-test
This test reproduces more-or-less #34600. It has a central that connects to multiple peripherals, opens one l2cap CoC channel per connection, and transmits a few SDUs largely exceeding the MPS of the channel. In this commit, the test doesn't pass, but when it passes (after the subsequent commits), error and warning messages are expected from the stack, as this is not the happy path. We can later debate on whether these particular error messages should be downgraded to debug. Signed-off-by: Jonathan Rico <[email protected]>
1 parent b15e645 commit 7a6872d

File tree

7 files changed

+623
-0
lines changed

7 files changed

+623
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH})
6+
message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\
7+
the environment variable BSIM_COMPONENTS_PATH to point to its components \
8+
folder. More information can be found in\
9+
https://babblesim.github.io/folder_structure_and_env.html")
10+
endif()
11+
12+
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
13+
project(bsim_test_l2cap_stress)
14+
15+
FILE(GLOB app_sources src/*.c)
16+
target_sources(app PRIVATE ${app_sources} )
17+
18+
zephyr_include_directories(
19+
$ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/
20+
$ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/
21+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
CONFIG_BT=y
2+
CONFIG_BT_CENTRAL=y
3+
CONFIG_BT_PERIPHERAL=y
4+
CONFIG_BT_DEVICE_NAME="L2CAP stress test"
5+
6+
CONFIG_BT_EATT=n
7+
CONFIG_BT_L2CAP_ECRED=n
8+
9+
CONFIG_BT_SMP=y # Next config depends on it
10+
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
11+
12+
# Disable auto-initiated procedures so they don't
13+
# mess with the test's execution.
14+
CONFIG_BT_AUTO_PHY_UPDATE=n
15+
CONFIG_BT_AUTO_DATA_LEN_UPDATE=n
16+
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
17+
18+
# L2CAP MPS
19+
# 23+27+27=77 makes exactly three full packets
20+
CONFIG_BT_L2CAP_TX_MTU=77
21+
CONFIG_BT_BUF_ACL_TX_SIZE=77
22+
CONFIG_BT_BUF_ACL_TX_COUNT=4
23+
24+
# The minimum value for this is
25+
# L2AP MPS + L2CAP header (4)
26+
CONFIG_BT_BUF_ACL_RX_SIZE=81
27+
28+
# TODO: find out why we can't use 16 buffers. It should fit.
29+
30+
CONFIG_BT_L2CAP_TX_BUF_COUNT=30
31+
# CONFIG_BT_L2CAP_TX_BUF_COUNT=100
32+
33+
CONFIG_BT_BUF_ACL_TX_COUNT=4
34+
35+
CONFIG_BT_CTLR_RX_BUFFERS=10
36+
# The ring buffer now has space for three times as much data
37+
# (default 27, 3*27=81), so that it does not run out of data
38+
# while waiting for new SDUs to be queued.
39+
CONFIG_BT_CTLR_DATA_LENGTH_MAX=81
40+
41+
CONFIG_BT_MAX_CONN=10
42+
43+
CONFIG_LOG=y
44+
CONFIG_ASSERT=y
45+
CONFIG_BT_DEBUG_LOG=y
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "common.h"
8+
9+
extern enum bst_result_t bst_result;
10+
11+
void test_init(void)
12+
{
13+
bst_ticker_set_next_tick_absolute(WAIT_TIME);
14+
bst_result = In_progress;
15+
}
16+
17+
void test_tick(bs_time_t HW_device_time)
18+
{
19+
if (bst_result != Passed) {
20+
FAIL("test failed (not passed after %i seconds)\n", WAIT_SECONDS);
21+
}
22+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Common functions and helpers for L2CAP tests
3+
*
4+
* Copyright (c) 2022 Nordic Semiconductor ASA
5+
*
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
#include <stddef.h>
10+
11+
#include <zephyr/types.h>
12+
#include <zephyr/sys/util.h>
13+
#include <zephyr/sys/byteorder.h>
14+
15+
#include <zephyr/bluetooth/bluetooth.h>
16+
#include <zephyr/bluetooth/hci.h>
17+
#include <zephyr/bluetooth/l2cap.h>
18+
#include "bs_types.h"
19+
#include "bs_tracing.h"
20+
#include "bstests.h"
21+
#include "bs_pc_backchannel.h"
22+
23+
extern enum bst_result_t bst_result;
24+
25+
#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false
26+
#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true)
27+
#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false)
28+
#define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t)true)
29+
#define WAIT_FOR_FLAG_SET(flag) \
30+
while (!(bool)atomic_get(&flag)) { \
31+
(void)k_sleep(K_MSEC(1)); \
32+
}
33+
#define WAIT_FOR_FLAG_UNSET(flag) \
34+
while ((bool)atomic_get(&flag)) { \
35+
(void)k_sleep(K_MSEC(1)); \
36+
}
37+
38+
39+
#define WAIT_SECONDS 120 /* seconds */
40+
#define WAIT_TIME (WAIT_SECONDS * USEC_PER_SEC) /* microseconds*/
41+
42+
#define FAIL(...) \
43+
do { \
44+
bst_result = Failed; \
45+
bs_trace_error_time_line(__VA_ARGS__); \
46+
} while (0)
47+
48+
#define PASS(...) \
49+
do { \
50+
bst_result = Passed; \
51+
bs_trace_info_time(1, __VA_ARGS__); \
52+
} while (0)
53+
54+
#define ASSERT(expr, ...) if (!(expr)) {FAIL(__VA_ARGS__); }
55+
56+
void test_init(void);
57+
void test_tick(bs_time_t HW_device_time);

0 commit comments

Comments
 (0)