Skip to content

Commit e6000e6

Browse files
trond-snekvikjhedberg
authored andcommitted
Bluetooth: Mesh: Test provisioning multiple devices
Adds a BabbleSim test for provisioning multiple devices in a row. This scenario had a regression in #33782, which is fixed in #35405. Signed-off-by: Trond Einar Snekvik <[email protected]>
1 parent 4fcec51 commit e6000e6

File tree

3 files changed

+74
-11
lines changed

3 files changed

+74
-11
lines changed

tests/bluetooth/bsim_bt/bsim_test_mesh/prj.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ CONFIG_BT_MESH_PB_ADV=y
3838
CONFIG_BT_MESH_PROVISIONER=y
3939
CONFIG_BT_MESH_PROV_DEVICE=y
4040
CONFIG_BT_MESH_CDB=y
41-
CONFIG_BT_MESH_CDB_NODE_COUNT=3
41+
CONFIG_BT_MESH_CDB_NODE_COUNT=4
4242

4343
CONFIG_BT_MESH_DEBUG=y

tests/bluetooth/bsim_bt/bsim_test_mesh/src/test_provision.c

+59-10
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,67 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
1717
* Tests both the provisioner and device role in various scenarios.
1818
*/
1919

20+
#define PROV_MULTI_COUNT 3
21+
22+
enum test_flags {
23+
IS_PROVISIONER,
24+
25+
TEST_FLAGS,
26+
};
27+
28+
static ATOMIC_DEFINE(flags, TEST_FLAGS);
29+
extern const struct bt_mesh_comp comp;
30+
extern const uint8_t test_net_key[16];
31+
extern uint global_device_nbr;
32+
2033
/* Timeout semaphore */
2134
static struct k_sem prov_sem;
35+
static uint16_t prov_addr = 0x0002;
36+
static const uint8_t dev_key[16] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
37+
static uint8_t dev_uuid[16] = { 0x6c, 0x69, 0x6e, 0x67, 0x61, 0x6f };
2238

2339
#define WAIT_TIME 60 /*seconds*/
2440

2541
static void test_device_init(void)
2642
{
43+
/* Ensure that the UUID is unique: */
44+
dev_uuid[6] = '0' + global_device_nbr;
45+
2746
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
2847
}
2948

3049
static void test_provisioner_init(void)
3150
{
51+
atomic_set_bit(flags, IS_PROVISIONER);
3252
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
3353
}
3454

3555
static void unprovisioned_beacon(uint8_t uuid[16],
3656
bt_mesh_prov_oob_info_t oob_info,
3757
uint32_t *uri_hash)
3858
{
39-
bt_mesh_provision_adv(uuid, 0, 0, 0);
59+
if (!atomic_test_bit(flags, IS_PROVISIONER)) {
60+
return;
61+
}
62+
63+
bt_mesh_provision_adv(uuid, 0, prov_addr, 0);
4064
}
4165

4266
static void prov_complete(uint16_t net_idx, uint16_t addr)
4367
{
44-
k_sem_give(&prov_sem);
68+
if (!atomic_test_bit(flags, IS_PROVISIONER)) {
69+
k_sem_give(&prov_sem);
70+
}
4571
}
4672

4773
static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr,
4874
uint8_t num_elem)
4975
{
76+
LOG_INF("Device 0x%04x provisioned", prov_addr);
77+
prov_addr++;
5078
k_sem_give(&prov_sem);
5179
}
5280

53-
extern const struct bt_mesh_comp comp;
54-
extern const uint8_t test_net_key[16];
55-
static const uint8_t dev_key[16] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
56-
static const uint8_t dev_uuid[16] = { 0x6c, 0x69, 0x6e, 0x67, 0x61, 0x6f };
5781
static struct bt_mesh_prov prov = {
5882
.uuid = dev_uuid,
5983
.unprovisioned_beacon = unprovisioned_beacon,
@@ -95,7 +119,8 @@ static void test_device_pb_adv_no_oob(void)
95119

96120
LOG_INF("Mesh initialized\n");
97121

98-
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20)),
122+
/* Keep a long timeout so the prov multi case has time to finish: */
123+
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40)),
99124
"Device provision fail");
100125

101126
PASS();
@@ -117,14 +142,36 @@ static void test_provisioner_pb_adv_no_oob(void)
117142
err = bt_mesh_provision(test_net_key, 0, 0, 0, 0x0001, dev_key);
118143
ASSERT_OK(err, "Provisioning failed (err %d)", err);
119144

120-
k_sem_take(&prov_sem, K_NO_WAIT);
121-
122-
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20)),
145+
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(5)),
123146
"Provisioner provision fail");
124147

125148
PASS();
126149
}
127150

151+
/** @brief Verify that the provisioner can provision multiple devices in a row
152+
*/
153+
static void test_provisioner_pb_adv_multi(void)
154+
{
155+
int err;
156+
157+
k_sem_init(&prov_sem, 0, 1);
158+
159+
bt_mesh_device_setup();
160+
161+
err = bt_mesh_cdb_create(test_net_key);
162+
ASSERT_OK(err, "Failed to create CDB (err %d)\n", err);
163+
164+
err = bt_mesh_provision(test_net_key, 0, 0, 0, 0x0001, dev_key);
165+
ASSERT_OK(err, "Provisioning failed (err %d)", err);
166+
167+
for (int i = 0; i < PROV_MULTI_COUNT; i++) {
168+
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20)),
169+
"Provisioner provision #%d fail", i);
170+
}
171+
172+
PASS();
173+
}
174+
128175
#define TEST_CASE(role, name, description) \
129176
{ \
130177
.test_id = "prov_" #role "_" #name, .test_descr = description, \
@@ -139,6 +186,8 @@ static const struct bst_test_instance test_connect[] = {
139186

140187
TEST_CASE(provisioner, pb_adv_no_oob,
141188
"Provisioner: pb-adv provisioning use no-oob method"),
189+
TEST_CASE(provisioner, pb_adv_multi,
190+
"Provisioner: pb-adv provisioning multiple devices"),
142191

143192
BSTEST_END_MARKER
144193
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021 Nordic Semiconductor
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh
6+
7+
# Provision 3 devices in succession:
8+
# Note that the number of devices must match the
9+
# PROV_MULTI_COUNT define in test_provision.c
10+
RunTest mesh_provision_pb_adv_multi \
11+
prov_provisioner_pb_adv_multi \
12+
prov_device_pb_adv_no_oob \
13+
prov_device_pb_adv_no_oob \
14+
prov_device_pb_adv_no_oob \

0 commit comments

Comments
 (0)