-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Bluetooth: Add some more tests for bt_le_create_conn()
Adds coverage for attempting to connect while already connecting or connecting to a device that already exists. Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
- Loading branch information
1 parent
c297e2d
commit 90c16c9
Showing
5 changed files
with
229 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
CONFIG_ASSERT=y | ||
CONFIG_BT=y | ||
CONFIG_BT_CENTRAL=y | ||
CONFIG_BT_PERIPHERAL=y |
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,62 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "bstests.h" | ||
#include "babblekit/testcase.h" | ||
#include <zephyr/bluetooth/conn.h> | ||
|
||
static K_SEM_DEFINE(sem_connected, 0, 1); | ||
|
||
static void connected_cb(struct bt_conn *conn, uint8_t err) | ||
{ | ||
TEST_ASSERT(conn); | ||
TEST_ASSERT(err == 0, "Expected success"); | ||
|
||
k_sem_give(&sem_connected); | ||
bt_conn_unref(conn); | ||
} | ||
|
||
static struct bt_conn_cb conn_cb = { | ||
.connected = connected_cb, | ||
}; | ||
|
||
static void test_peripheral_dummy(void) | ||
{ | ||
int err; | ||
const struct bt_data ad[] = { | ||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR))}; | ||
|
||
bt_conn_cb_register(&conn_cb); | ||
|
||
bt_addr_le_t addr = {.type = BT_ADDR_LE_RANDOM, | ||
.a.val = {0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0}}; | ||
|
||
err = bt_id_create(&addr, NULL); | ||
TEST_ASSERT(err == 0, "Failed to create iD (err %d)", err); | ||
|
||
/* Initialize Bluetooth */ | ||
err = bt_enable(NULL); | ||
TEST_ASSERT(err == 0, "Can't enable Bluetooth (err %d)", err); | ||
|
||
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, ARRAY_SIZE(ad), NULL, 0); | ||
TEST_ASSERT(err == 0, "Advertising failed to start (err %d)", err); | ||
|
||
err = k_sem_take(&sem_connected, K_FOREVER); | ||
TEST_ASSERT(err == 0, "Failed getting connected timeout", err); | ||
|
||
TEST_PASS("Passed"); | ||
} | ||
|
||
static const struct bst_test_instance test_def[] = {{.test_id = "peripheral_dummy", | ||
.test_descr = "Connectable peripheral", | ||
.test_tick_f = bst_tick, | ||
.test_main_f = test_peripheral_dummy}, | ||
BSTEST_END_MARKER}; | ||
|
||
struct bst_test_list *test_peripheral_install(struct bst_test_list *tests) | ||
{ | ||
return bst_add_tests(tests, test_def); | ||
} |
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
21 changes: 21 additions & 0 deletions
21
tests/bsim/bluetooth/host/central/tests_scripts/run_central_connect_to_existing.sh
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,21 @@ | ||
#!/usr/bin/env bash | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source | ||
|
||
simulation_id="central_connect_timeout_to_existing" | ||
verbosity_level=2 | ||
|
||
cd ${BSIM_OUT_PATH}/bin | ||
|
||
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_central_prj_conf \ | ||
-v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central_connect_to_existing | ||
|
||
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_central_prj_conf \ | ||
-v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral_dummy | ||
|
||
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ | ||
-D=2 -sim_length=60e6 $@ | ||
|
||
wait_for_background_jobs |
18 changes: 18 additions & 0 deletions
18
tests/bsim/bluetooth/host/central/tests_scripts/run_central_connect_when_connecting.sh
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,18 @@ | ||
#!/usr/bin/env bash | ||
# Copyright (c) 2024 Nordic Semiconductor | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source | ||
|
||
simulation_id="central_connect_when_connecting" | ||
verbosity_level=2 | ||
|
||
cd ${BSIM_OUT_PATH}/bin | ||
|
||
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_central_prj_conf \ | ||
-v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central_connect_when_connecting | ||
|
||
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ | ||
-D=1 -sim_length=60e6 $@ | ||
|
||
wait_for_background_jobs |