Skip to content

Commit 79af744

Browse files
PavelVPVcfriedt
authored andcommitted
tests: Bluetooth: Mesh: Make mesh initialization function generic
This commit makes this small piece of code reusable in other tests. Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent 71b2748 commit 79af744

File tree

3 files changed

+32
-44
lines changed

3 files changed

+32
-44
lines changed

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,11 @@ const uint8_t test_net_key[16] = { 1, 2, 3 };
167167
const uint8_t test_app_key[16] = { 4, 5, 6 };
168168
const uint8_t test_va_uuid[16] = "Mesh Label UUID";
169169

170-
static void bt_enabled(void)
170+
static void bt_mesh_device_provision_and_configure(void)
171171
{
172-
static struct bt_mesh_prov prov;
173172
uint8_t status;
174173
int err;
175174

176-
net_buf_simple_init(pub.msg, 0);
177-
net_buf_simple_init(vnd_pub.msg, 0);
178-
179-
err = bt_mesh_init(&prov, &comp);
180-
if (err) {
181-
FAIL("Initializing mesh failed (err %d)", err);
182-
return;
183-
}
184-
185-
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
186-
LOG_INF("Loading stored settings");
187-
settings_load();
188-
}
189-
190175
err = bt_mesh_provision(test_net_key, 0, 0, 0, cfg->addr, cfg->dev_key);
191176
if (err == -EALREADY) {
192177
LOG_INF("Using stored settings");
@@ -196,8 +181,6 @@ static void bt_enabled(void)
196181
return;
197182
}
198183

199-
LOG_INF("Mesh initialized");
200-
201184
/* Self configure */
202185

203186
err = bt_mesh_cfg_app_key_add(0, cfg->addr, 0, 0, test_app_key,
@@ -223,7 +206,7 @@ static void bt_enabled(void)
223206
}
224207
}
225208

226-
void bt_mesh_test_setup(void)
209+
void bt_mesh_device_setup(const struct bt_mesh_prov *prov, const struct bt_mesh_comp *comp)
227210
{
228211
int err;
229212

@@ -235,7 +218,29 @@ void bt_mesh_test_setup(void)
235218

236219
LOG_INF("Bluetooth initialized");
237220

238-
bt_enabled();
221+
err = bt_mesh_init(prov, comp);
222+
if (err) {
223+
FAIL("Initializing mesh failed (err %d)", err);
224+
return;
225+
}
226+
227+
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
228+
LOG_INF("Loading stored settings");
229+
settings_load();
230+
}
231+
232+
LOG_INF("Mesh initialized");
233+
}
234+
235+
void bt_mesh_test_setup(void)
236+
{
237+
static struct bt_mesh_prov prov;
238+
239+
net_buf_simple_init(pub.msg, 0);
240+
net_buf_simple_init(vnd_pub.msg, 0);
241+
242+
bt_mesh_device_setup(&prov, &comp);
243+
bt_mesh_device_provision_and_configure();
239244
}
240245

241246
void bt_mesh_test_timeout(bs_time_t HW_device_time)

tests/bluetooth/bsim_bt/bsim_test_mesh/src/mesh_test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ void bt_mesh_test_cfg_set(const struct bt_mesh_test_cfg *cfg, int wait_time);
111111
void bt_mesh_test_setup(void);
112112
void bt_mesh_test_timeout(bs_time_t HW_device_time);
113113

114+
void bt_mesh_device_setup(const struct bt_mesh_prov *prov, const struct bt_mesh_comp *comp);
115+
114116
int bt_mesh_test_recv(uint16_t len, uint16_t dst, k_timeout_t timeout);
115117
int bt_mesh_test_recv_msg(struct bt_mesh_test_msg *msg, k_timeout_t timeout);
116118
int bt_mesh_test_recv_clear(void);

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,6 @@ static struct bt_mesh_prov prov = {
8686
.node_added = prov_node_added,
8787
};
8888

89-
static void bt_mesh_device_setup(void)
90-
{
91-
int err;
92-
93-
err = bt_enable(NULL);
94-
if (err) {
95-
FAIL("Bluetooth init failed (err %d)", err);
96-
return;
97-
}
98-
99-
LOG_INF("Bluetooth initialized");
100-
101-
err = bt_mesh_init(&prov, &comp);
102-
if (err) {
103-
FAIL("Initializing mesh failed (err %d)", err);
104-
return;
105-
}
106-
}
107-
10889
/** @brief Verify that this device pb-adv provision.
10990
*/
11091
static void test_device_pb_adv_no_oob(void)
@@ -113,7 +94,7 @@ static void test_device_pb_adv_no_oob(void)
11394

11495
k_sem_init(&prov_sem, 0, 1);
11596

116-
bt_mesh_device_setup();
97+
bt_mesh_device_setup(&prov, &comp);
11798

11899
err = bt_mesh_prov_enable(BT_MESH_PROV_ADV);
119100
ASSERT_OK(err, "Device PB-ADV Enable failed (err %d)", err);
@@ -135,7 +116,7 @@ static void test_provisioner_pb_adv_no_oob(void)
135116

136117
k_sem_init(&prov_sem, 0, 1);
137118

138-
bt_mesh_device_setup();
119+
bt_mesh_device_setup(&prov, &comp);
139120

140121
err = bt_mesh_cdb_create(test_net_key);
141122
ASSERT_OK(err, "Failed to create CDB (err %d)\n", err);
@@ -157,7 +138,7 @@ static void test_provisioner_pb_adv_multi(void)
157138

158139
k_sem_init(&prov_sem, 0, 1);
159140

160-
bt_mesh_device_setup();
141+
bt_mesh_device_setup(&prov, &comp);
161142

162143
err = bt_mesh_cdb_create(test_net_key);
163144
ASSERT_OK(err, "Failed to create CDB (err %d)\n", err);
@@ -181,7 +162,7 @@ static void test_provisioner_iv_update_flag_zero(void)
181162
int err;
182163
uint8_t flags = 0x00;
183164

184-
bt_mesh_device_setup();
165+
bt_mesh_device_setup(&prov, &comp);
185166

186167
err = bt_mesh_provision(test_net_key, 0, flags, 0, 0x0001, dev_key);
187168
ASSERT_OK(err, "Provisioning failed (err %d)", err);
@@ -201,7 +182,7 @@ static void test_provisioner_iv_update_flag_one(void)
201182
int err;
202183
uint8_t flags = 0x02; /* IV Update flag bit set to 1 */
203184

204-
bt_mesh_device_setup();
185+
bt_mesh_device_setup(&prov, &comp);
205186

206187
err = bt_mesh_provision(test_net_key, 0, flags, 0, 0x0001, dev_key);
207188
ASSERT_OK(err, "Provisioning failed (err %d)", err);

0 commit comments

Comments
 (0)