Skip to content

Commit cd294c1

Browse files
PavelVPVcfriedt
authored andcommitted
tests: Bluetooth: Mesh: Verify that all stored mesh entries removed
This ensures that all mesh settings were removed from persistent storage after node reset. Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent f82086f commit cd294c1

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

subsys/bluetooth/mesh/net.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,13 +1066,22 @@ void bt_mesh_net_pending_seq_store(void)
10661066
struct seq_val seq;
10671067
int err;
10681068

1069-
sys_put_le24(bt_mesh.seq, seq.val);
1069+
if (atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) {
1070+
sys_put_le24(bt_mesh.seq, seq.val);
10701071

1071-
err = settings_save_one("bt/mesh/Seq", &seq, sizeof(seq));
1072-
if (err) {
1073-
BT_ERR("Failed to stor Seq value");
1072+
err = settings_save_one("bt/mesh/Seq", &seq, sizeof(seq));
1073+
if (err) {
1074+
BT_ERR("Failed to stor Seq value");
1075+
} else {
1076+
BT_DBG("Stored Seq value");
1077+
}
10741078
} else {
1075-
BT_DBG("Stored Seq value");
1079+
err = settings_delete("bt/mesh/Seq");
1080+
if (err) {
1081+
BT_ERR("Failed to clear Seq value");
1082+
} else {
1083+
BT_DBG("Cleared Seq value");
1084+
}
10761085
}
10771086
}
10781087

@@ -1081,6 +1090,7 @@ void bt_mesh_net_clear(void)
10811090
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_NET_PENDING);
10821091
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_IV_PENDING);
10831092
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_CFG_PENDING);
1093+
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_SEQ_PENDING);
10841094
}
10851095

10861096
void bt_mesh_net_settings_commit(void)

tests/bluetooth/bsim_bt/bsim_test_mesh/prj_pst.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ CONFIG_BT_MESH_PROVISIONER=y
4747
CONFIG_BT_MESH_PROV_DEVICE=y
4848
CONFIG_BT_MESH_CDB=y
4949
CONFIG_BT_MESH_CDB_NODE_COUNT=3
50+
CONFIG_BT_MESH_CDB_SUBNET_COUNT=2
51+
CONFIG_BT_MESH_SUBNET_COUNT=2
5052
CONFIG_BT_MESH_GATT_PROXY=y
5153
CONFIG_BT_MESH_TX_SEG_RETRANS_COUNT=1
54+
CONFIG_BT_MESH_SEQ_STORE_RATE=1
55+
CONFIG_BT_MESH_RPL_STORE_TIMEOUT=1
56+
CONFIG_BT_MESH_STORE_TIMEOUT=1
5257

5358
CONFIG_BT_MESH_DEBUG=y

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,27 +155,29 @@ static int settings_custom_save(struct settings_store *cs, const char *name,
155155
}
156156
}
157157

158-
char bufvname[ENTRY_NAME_MAX_LEN + ENTRY_LEN_SIZE + 3];
158+
if (val_len) {
159+
char bufvname[ENTRY_NAME_MAX_LEN + ENTRY_LEN_SIZE + 3];
159160

160-
snprintk(bufvname, sizeof(bufvname), "%s=", name);
161-
if (fputs(bufvname, fnew != NULL ? fnew : fcur) < 0) {
162-
return -1;
163-
}
161+
snprintk(bufvname, sizeof(bufvname), "%s=", name);
162+
if (fputs(bufvname, fnew != NULL ? fnew : fcur) < 0) {
163+
return -1;
164+
}
164165

165-
char bufval[ENTRY_VAL_MAX_LEN + 2] = {};
166-
size_t valcnt = 0;
166+
char bufval[ENTRY_VAL_MAX_LEN + 2] = {};
167+
size_t valcnt = 0;
167168

168-
while (valcnt < (val_len * 2)) {
169-
valcnt += snprintk(&bufval[valcnt], 3, "%02x",
170-
(uint8_t)value[valcnt / 2]);
171-
};
169+
while (valcnt < (val_len * 2)) {
170+
valcnt += snprintk(&bufval[valcnt], 3, "%02x",
171+
(uint8_t)value[valcnt / 2]);
172+
};
172173

173-
/* helps in making settings file redable */
174-
bufval[valcnt++] = '\n';
175-
bufval[valcnt] = 0;
174+
/* helps in making settings file redable */
175+
bufval[valcnt++] = '\n';
176+
bufval[valcnt] = 0;
176177

177-
if (fputs(bufval, fnew != NULL ? fnew : fcur) < 0) {
178-
return -1;
178+
if (fputs(bufval, fnew != NULL ? fnew : fcur) < 0) {
179+
return -1;
180+
}
179181
}
180182

181183
if (fnew != NULL) {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,14 @@ static void test_cfg_load(void)
900900
PASS();
901901
}
902902

903+
static int mesh_settings_load_cb(const char *key, size_t len, settings_read_cb read_cb,
904+
void *cb_arg, void *param)
905+
{
906+
ASSERT_TRUE(len == 0);
907+
908+
return 0;
909+
}
910+
903911
/** @brief Test reprovisioning with persistent storage, device side.
904912
*
905913
* Wait for being provisioned and configured, then wait for the node reset and store settings.
@@ -926,6 +934,9 @@ static void test_reprovisioning_device(void)
926934

927935
k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT));
928936

937+
/* Check that all mesh settings were removed. */
938+
settings_load_subtree_direct("bt/mesh", mesh_settings_load_cb, NULL);
939+
929940
PASS();
930941
}
931942

@@ -960,6 +971,9 @@ static void test_reprovisioning_provisioner(void)
960971
FAIL("Reset failed (err %d, status: %d)", err, status);
961972
}
962973

974+
/* Let the remote device store configuration. */
975+
k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT * 2));
976+
963977
PASS();
964978
}
965979

0 commit comments

Comments
 (0)