Skip to content

Commit c1baa82

Browse files
jori-nordicjhedberg
authored andcommitted
tests: Bluetooth: Add ATT sequential procedures test
The purpose of this test is to prove that the zephyr host can handle the behavior described in the Bluetooth Core Specification Vol.3 Part.F 3.3.2 "Sequential protocol". The host should be able to handle all of those in parallel: one indication, one write request, multiple commands and multiple notifications. The "tester" part had to be written with a "tiny host" implementation instead of the Zephyr host, as the ZH conflates GATT client and server and doesn't allow a device to enqueue an ATT request + an ATT indication on the same bearer. Signed-off-by: Jonathan Rico <[email protected]>
1 parent 7093538 commit c1baa82

File tree

11 files changed

+1231
-0
lines changed

11 files changed

+1231
-0
lines changed

subsys/bluetooth/host/hci_core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,6 +3938,13 @@ static void rx_work_handler(struct k_work *work)
39383938
}
39393939
#endif /* !CONFIG_BT_RECV_BLOCKING */
39403940

3941+
#if defined(CONFIG_BT_TESTING)
3942+
k_tid_t bt_testing_tx_tid_get(void)
3943+
{
3944+
return &tx_thread_data;
3945+
}
3946+
#endif
3947+
39413948
int bt_enable(bt_ready_cb_t cb)
39423949
{
39433950
int err;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2023 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "bs_tracing.h"
8+
#include "bs_types.h"
9+
#include "bstests.h"
10+
11+
#define BS_SECONDS(dur_sec) ((bs_time_t)dur_sec * USEC_PER_SEC)
12+
#define TEST_TIMEOUT_SIMULATED BS_SECONDS(10)
13+
14+
extern enum bst_result_t bst_result;
15+
16+
#define DECLARE_FLAG(flag) extern atomic_t flag
17+
#define DEFINE_FLAG(flag) atomic_t flag = (atomic_t) false
18+
#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true)
19+
#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false)
20+
21+
#define WAIT_FOR_VAL(var, val) \
22+
while (atomic_get(&var) != val) { \
23+
(void)k_sleep(K_MSEC(1)); \
24+
}
25+
#define WAIT_FOR_FLAG(flag) \
26+
while (!(bool)atomic_get(&flag)) { \
27+
(void)k_sleep(K_MSEC(1)); \
28+
}
29+
#define WAIT_FOR_FLAG_UNSET(flag) \
30+
while ((bool)atomic_get(&flag)) { \
31+
(void)k_sleep(K_MSEC(1)); \
32+
}
33+
#define TAKE_FLAG(flag) \
34+
while (!(bool)atomic_cas(&flag, true, false)) { \
35+
(void)k_sleep(K_MSEC(1)); \
36+
}
37+
38+
#define ASSERT(expr, ...) \
39+
do { \
40+
if (!(expr)) { \
41+
FAIL(__VA_ARGS__); \
42+
} \
43+
} while (0)
44+
45+
#define FAIL(...) \
46+
do { \
47+
bst_result = Failed; \
48+
bs_trace_error_time_line(__VA_ARGS__); \
49+
} while (0)
50+
51+
#define PASS(...) \
52+
do { \
53+
bst_result = Passed; \
54+
bs_trace_info_time(1, __VA_ARGS__); \
55+
} while (0)
56+
57+
#define HVX_HANDLE 0x0012
58+
#define INDICATION_PAYLOAD "indication"
59+
#define NOTIFICATION_PAYLOAD "notification"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(bsim_test_sequential_dut)
7+
8+
target_sources(app PRIVATE
9+
src/main.c
10+
)
11+
12+
zephyr_include_directories(
13+
../common/
14+
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
15+
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
16+
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
CONFIG_LOG=y
2+
CONFIG_ASSERT=y
3+
4+
CONFIG_BT=y
5+
CONFIG_BT_CENTRAL=y
6+
CONFIG_BT_PERIPHERAL=y
7+
CONFIG_BT_DEVICE_NAME="Sequential"
8+
9+
CONFIG_BT_GATT_CLIENT=y
10+
CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION=n
11+
12+
# Enable bt_testing_tx_tid_get()
13+
CONFIG_BT_TESTING=y
14+
15+
# Replace `Execute` with `gdb --args` in the shell script
16+
# and get a nice backtrace on assert
17+
CONFIG_ARCH_POSIX_TRAP_ON_FATAL=y
18+
19+
# Prepend logs with thread names
20+
CONFIG_THREAD_NAME=y
21+
CONFIG_LOG_THREAD_ID_PREFIX=y
22+
23+
# Enable those as needed
24+
# CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y
25+
# CONFIG_BT_ATT_LOG_LEVEL_DBG=y
26+
# CONFIG_BT_GATT_LOG_LEVEL_DBG=y
27+
28+
# Allow whole L2CAP PDUs to fit on-air
29+
CONFIG_BT_BUF_ACL_TX_SIZE=251
30+
CONFIG_BT_BUF_ACL_RX_SIZE=251
31+
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
32+
CONFIG_BT_DATA_LEN_UPDATE=y
33+
CONFIG_BT_USER_DATA_LEN_UPDATE=y
34+
35+
# Disable auto-initiated procedures so they don't
36+
# mess with the test's execution.
37+
CONFIG_BT_AUTO_PHY_UPDATE=n
38+
CONFIG_BT_AUTO_DATA_LEN_UPDATE=n
39+
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
40+
41+
CONFIG_BT_MAX_CONN=1

0 commit comments

Comments
 (0)