-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bluetooth: Host: add unregister connection callback function
[Description] tests: shell: Restart bt will register the same connection callback twice. Callback next node point to itself, when link established callback function loop infinitely. [Fix] Unregister the previous callback to avoid register repeatedly. [Test] After bt init/disable times, create connection successfully. Signed-off-by: huajiang zheng <[email protected]>
- Loading branch information
huajiang zheng
authored and
Huajiang Zheng
committed
Jan 31, 2024
1 parent
69787da
commit e857483
Showing
10 changed files
with
421 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/bsim/bluetooth/host/misc/unregister_conn_cb/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(bsim_test_unregister_conn_cb) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources} ) | ||
|
||
zephyr_include_directories( | ||
${BSIM_COMPONENTS_PATH}/libUtilv1/src/ | ||
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/ | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CONFIG_BT=y | ||
CONFIG_BT_DEVICE_NAME="conn tester" | ||
CONFIG_BT_PERIPHERAL=y | ||
CONFIG_BT_CENTRAL=y |
20 changes: 20 additions & 0 deletions
20
tests/bsim/bluetooth/host/misc/unregister_conn_cb/src/common.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2022 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "common.h" | ||
|
||
void test_tick(bs_time_t HW_device_time) | ||
{ | ||
if (bst_result != Passed) { | ||
FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); | ||
} | ||
} | ||
|
||
void test_init(void) | ||
{ | ||
bst_ticker_set_next_tick_absolute(WAIT_TIME); | ||
bst_result = In_progress; | ||
} |
55 changes: 55 additions & 0 deletions
55
tests/bsim/bluetooth/host/misc/unregister_conn_cb/src/common.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Common functions and helpers for unregister connection callback tests | ||
* | ||
* Copyright (c) 2024 NXP | ||
* Copyright (c) 2022 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
|
||
#include "bs_types.h" | ||
#include "bs_tracing.h" | ||
#include "time_machine.h" | ||
#include "bstests.h" | ||
|
||
#include <zephyr/types.h> | ||
#include <stddef.h> | ||
#include <errno.h> | ||
|
||
#include <zephyr/bluetooth/bluetooth.h> | ||
#include <zephyr/bluetooth/hci.h> | ||
#include <zephyr/bluetooth/conn.h> | ||
|
||
extern enum bst_result_t bst_result; | ||
|
||
#define WAIT_SECONDS (30) /*seconds*/ | ||
#define WAIT_TIME (WAIT_SECONDS * USEC_PER_SEC) /* microseconds*/ | ||
|
||
#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t) false | ||
#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) | ||
#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) | ||
#define WAIT_FOR_FLAG(flag) \ | ||
while (!(bool)atomic_get(&flag)) { \ | ||
(void)k_sleep(K_MSEC(1)); \ | ||
} | ||
#define WAIT_FOR_FLAG_UNSET(flag) \ | ||
while ((bool)atomic_get(&flag)) { \ | ||
(void)k_sleep(K_MSEC(1)); \ | ||
} | ||
|
||
#define FAIL(...) \ | ||
do { \ | ||
bst_result = Failed; \ | ||
bs_trace_error_time_line(__VA_ARGS__); \ | ||
} while (0) | ||
|
||
#define PASS(...) \ | ||
do { \ | ||
bst_result = Passed; \ | ||
bs_trace_info_time(1, __VA_ARGS__); \ | ||
} while (0) | ||
|
||
void test_tick(bs_time_t HW_device_time); | ||
void test_init(void); |
Oops, something went wrong.