Skip to content

Commit 14200f8

Browse files
theob-pronashif
authored andcommitted
Bluetooth: Tests: New bsim test for ID
Add a new BabbleSim test checking that the value of the Bluetooth identity stored in the settings is correct. Signed-off-by: Théo Battrel <[email protected]>
1 parent 3636767 commit 14200f8

File tree

8 files changed

+243
-0
lines changed

8 files changed

+243
-0
lines changed

tests/bsim/bluetooth/host/compile.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ app=tests/bsim/bluetooth/host/security/bond_overwrite_denied compile
6565
app=tests/bsim/bluetooth/host/security/ccc_update compile
6666
app=tests/bsim/bluetooth/host/security/ccc_update conf_file=prj_2.conf compile
6767

68+
app=tests/bsim/bluetooth/host/id/settings compile
69+
6870
wait_for_background_jobs
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 HINTS $ENV{ZEPHYR_BASE})
6+
project(bsim_test_id_settings)
7+
8+
target_sources(app PRIVATE
9+
src/main.c
10+
src/dut.c
11+
)
12+
13+
zephyr_include_directories(
14+
$ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/
15+
$ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/
16+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CONFIG_BT=y
2+
CONFIG_BT_PERIPHERAL=y
3+
CONFIG_BT_DEVICE_NAME="ID Settings Test"
4+
5+
CONFIG_LOG=y
6+
7+
CONFIG_BT_ID_MAX=2
8+
9+
CONFIG_FLASH=y
10+
CONFIG_FLASH_PAGE_LAYOUT=y
11+
CONFIG_FLASH_MAP=y
12+
CONFIG_NVS=y
13+
CONFIG_SETTINGS=y
14+
CONFIG_BT_SETTINGS=y
15+
16+
# Increased stack due to settings API usage
17+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Copyright (c) 2023 Nordic Semiconductor ASA
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
#include "bs_tracing.h"
6+
#include "bstests.h"
7+
8+
#define FAIL(...) \
9+
do { \
10+
bst_result = Failed; \
11+
bs_trace_error_time_line(__VA_ARGS__); \
12+
} while (0)
13+
14+
#define PASS(...) \
15+
do { \
16+
bst_result = Passed; \
17+
bs_trace_info_time(1, __VA_ARGS__); \
18+
} while (0)
19+
20+
extern enum bst_result_t bst_result;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* Copyright (c) 2023 Nordic Semiconductor ASA
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
#include <zephyr/kernel.h>
6+
#include <zephyr/irq.h>
7+
8+
#include <zephyr/logging/log.h>
9+
#include <zephyr/settings/settings.h>
10+
11+
#include <zephyr/bluetooth/bluetooth.h>
12+
#include <zephyr/bluetooth/addr.h>
13+
14+
#include "common.h"
15+
16+
LOG_MODULE_DECLARE(bt_bsim_id_settings, LOG_LEVEL_DBG);
17+
18+
void run_dut1(void)
19+
{
20+
int err;
21+
size_t bt_id_count;
22+
23+
LOG_DBG("Starting DUT 1");
24+
25+
err = bt_enable(NULL);
26+
if (err) {
27+
FAIL("Bluetooth init failed (err %d)\n", err);
28+
}
29+
30+
LOG_DBG("Bluetooth initialised");
31+
32+
err = settings_load();
33+
if (err) {
34+
FAIL("Failed to load settings (err %d)\n", err);
35+
}
36+
37+
bt_id_get(NULL, &bt_id_count);
38+
LOG_DBG("Number of Bluetooth identities after settings load: %d", bt_id_count);
39+
40+
err = bt_id_create(NULL, NULL);
41+
if (err < 0) {
42+
FAIL("Failed to create a new identity (err %d)\n", err);
43+
}
44+
45+
bt_id_get(NULL, &bt_id_count);
46+
LOG_DBG("Number of Bluetooth identities after identity creation: %d", bt_id_count);
47+
48+
/* Wait for the workqueue to complete before switching device */
49+
k_msleep(100);
50+
51+
PASS("Test passed (DUT 1)\n");
52+
}
53+
54+
void run_dut2(void)
55+
{
56+
int err;
57+
size_t bt_id_count;
58+
size_t expected_id_count = 2;
59+
60+
LOG_DBG("Starting DUT 2");
61+
62+
err = bt_enable(NULL);
63+
if (err) {
64+
FAIL("Bluetooth init failed (err %d)\n", err);
65+
}
66+
67+
LOG_DBG("Bluetooth initialised");
68+
69+
err = settings_load();
70+
if (err) {
71+
FAIL("Failed to load settings (err %d)\n", err);
72+
}
73+
74+
LOG_DBG("Settings loaded");
75+
76+
bt_id_get(NULL, &bt_id_count);
77+
if (bt_id_count != expected_id_count) {
78+
FAIL("Wrong ID count (got %d; expected %d)\n", bt_id_count, expected_id_count);
79+
}
80+
81+
PASS("Test passed (DUT 2)\n");
82+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Copyright (c) 2023 Nordic Semiconductor ASA
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
#include <zephyr/kernel.h>
6+
7+
#include "bs_types.h"
8+
#include "bs_tracing.h"
9+
#include "bstests.h"
10+
#include <string.h>
11+
12+
#include <zephyr/logging/log.h>
13+
14+
#include "common.h"
15+
16+
#define WAIT_TIME_S 60
17+
#define WAIT_TIME (WAIT_TIME_S * 1e6)
18+
19+
LOG_MODULE_REGISTER(bt_bsim_id_settings, LOG_LEVEL_DBG);
20+
21+
extern void run_dut1(void);
22+
extern void run_dut2(void);
23+
24+
void test_tick(bs_time_t HW_device_time)
25+
{
26+
if (bst_result != Passed) {
27+
FAIL("Test failed (not passed after %d seconds)\n", WAIT_TIME_S);
28+
}
29+
}
30+
31+
static void test_id_settings_init(void)
32+
{
33+
bst_ticker_set_next_tick_absolute(WAIT_TIME);
34+
}
35+
36+
static const struct bst_test_instance test_def[] = {
37+
{
38+
.test_id = "dut1",
39+
.test_descr = "DUT 1",
40+
.test_post_init_f = test_id_settings_init,
41+
.test_tick_f = test_tick,
42+
.test_main_f = run_dut1,
43+
},
44+
{
45+
.test_id = "dut2",
46+
.test_descr = "DUT 2",
47+
.test_post_init_f = test_id_settings_init,
48+
.test_tick_f = test_tick,
49+
.test_main_f = run_dut2,
50+
},
51+
BSTEST_END_MARKER};
52+
53+
struct bst_test_list *test_id_settings_install(struct bst_test_list *tests)
54+
{
55+
return bst_add_tests(tests, test_def);
56+
}
57+
58+
bst_test_install_t test_installers[] = {test_id_settings_install, NULL};
59+
60+
void main(void)
61+
{
62+
bst_main();
63+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2023 Nordic Semiconductor ASA
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set -eu
6+
bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
7+
8+
bsim_bin="${BSIM_OUT_PATH}/bin"
9+
BOARD="${BOARD:-nrf52_bsim}"
10+
test_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_id_settings_prj_conf"
11+
12+
west build -b nrf52_bsim -d build && \
13+
cp -v build/zephyr/zephyr.exe "${test_exe}"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2023 Nordic Semiconductor ASA
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
6+
7+
test_exe="bs_${BOARD}_tests_bsim_bluetooth_host_id_settings_prj_conf"
8+
simulation_id="id_settings"
9+
verbosity_level=2
10+
EXECUTE_TIMEOUT=30
11+
12+
cd ${BSIM_OUT_PATH}/bin
13+
14+
Execute "./${test_exe}" \
15+
-v=${verbosity_level} -s="${simulation_id}_1" -d=0 -testid=dut1 \
16+
-flash="${simulation_id}.log.bin"
17+
18+
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}_1" \
19+
-D=1 -sim_length=60e6
20+
21+
wait_for_background_jobs
22+
23+
Execute "./${test_exe}" \
24+
-v=${verbosity_level} -s="${simulation_id}_2" -d=0 -testid=dut2 \
25+
-flash="${simulation_id}.log.bin" -flash_rm
26+
27+
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}_2" \
28+
-D=1 -sim_length=60e6
29+
30+
wait_for_background_jobs

0 commit comments

Comments
 (0)