boards: bsim: fix bug with single settings file for few bsim devices
Reapply the part of4b5cd92312
that added new functionality/fixed the actual issues described in the original commit message withtout the further cleanup. There was also some cross-commit content from2b91ebe16e
as part of the cleanup in test_friendship.c which is also included. + added cleanup also to test_provision.c on request from Aleksandr. Original commit msg: ----------- Multiple bsim devices cannot store individual settings with the existing settings backend for bsim. Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no> ----------- Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
This commit is contained in:
parent
26d7d7c8c8
commit
9249609071
5 changed files with 36 additions and 18 deletions
|
@ -226,5 +226,15 @@ void nrfbsim_cleanup_args(void)
|
||||||
bs_cleanup_dynargs(&args_struct);
|
bs_cleanup_dynargs(&args_struct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *get_simid(void)
|
||||||
|
{
|
||||||
|
return arg.s_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int get_device_nbr(void)
|
||||||
|
{
|
||||||
|
return arg.global_device_nbr;
|
||||||
|
}
|
||||||
|
|
||||||
NATIVE_TASK(nrfbsim_register_args, PRE_BOOT_1, 0);
|
NATIVE_TASK(nrfbsim_register_args, PRE_BOOT_1, 0);
|
||||||
NATIVE_TASK(nrfbsim_cleanup_args, ON_EXIT, 10);
|
NATIVE_TASK(nrfbsim_cleanup_args, ON_EXIT, 10);
|
||||||
|
|
|
@ -26,6 +26,8 @@ struct NRF_bsim_args_t {
|
||||||
|
|
||||||
struct NRF_bsim_args_t *nrfbsim_argsparse(int argc, char *argv[]);
|
struct NRF_bsim_args_t *nrfbsim_argsparse(int argc, char *argv[]);
|
||||||
void bs_add_extra_dynargs(bs_args_struct_t *args_struct_toadd);
|
void bs_add_extra_dynargs(bs_args_struct_t *args_struct_toadd);
|
||||||
|
char *get_simid(void);
|
||||||
|
unsigned int get_device_nbr(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,22 +6,23 @@
|
||||||
|
|
||||||
#include "settings_test_backend.h"
|
#include "settings_test_backend.h"
|
||||||
|
|
||||||
#include "kernel.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <zephyr/types.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <zephyr.h>
|
|
||||||
|
|
||||||
#include <bluetooth/mesh.h>
|
#include "kernel.h"
|
||||||
|
#include "zephyr/types.h"
|
||||||
|
#include "errno.h"
|
||||||
|
#include "zephyr.h"
|
||||||
|
|
||||||
|
#include "bluetooth/mesh.h"
|
||||||
|
#include "argparse.h"
|
||||||
|
|
||||||
#define LOG_MODULE_NAME settings_test_backend
|
#define LOG_MODULE_NAME settings_test_backend
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#define SETTINGS_FILE "settings_data.log"
|
#define SETTINGS_FILE setting_file
|
||||||
#define SETTINGS_FILE_TMP "~settings_data.log"
|
#define SETTINGS_FILE_TMP setting_file_tmp
|
||||||
|
|
||||||
#define ENTRY_LEN_SIZE (4)
|
#define ENTRY_LEN_SIZE (4)
|
||||||
#define ENTRY_NAME_MAX_LEN (SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN)
|
#define ENTRY_NAME_MAX_LEN (SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN)
|
||||||
|
@ -33,6 +34,9 @@ struct line_read_ctx {
|
||||||
const uint8_t *val;
|
const uint8_t *val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static char setting_file[50];
|
||||||
|
static char setting_file_tmp[sizeof(setting_file) + 1];
|
||||||
|
|
||||||
static int entry_check_and_copy(FILE *fin, FILE *fout, const char *name)
|
static int entry_check_and_copy(FILE *fin, FILE *fout, const char *name)
|
||||||
{
|
{
|
||||||
char line[READ_LEN_MAX + 1];
|
char line[READ_LEN_MAX + 1];
|
||||||
|
@ -203,6 +207,9 @@ static struct settings_store settings_custom_store = {
|
||||||
|
|
||||||
int settings_backend_init(void)
|
int settings_backend_init(void)
|
||||||
{
|
{
|
||||||
|
snprintf(setting_file, sizeof(setting_file), "%s_%d.log", get_simid(), get_device_nbr());
|
||||||
|
snprintf(setting_file_tmp, sizeof(setting_file_tmp), "~%s", setting_file);
|
||||||
|
|
||||||
LOG_INF("file path: %s", SETTINGS_FILE);
|
LOG_INF("file path: %s", SETTINGS_FILE);
|
||||||
|
|
||||||
/* register custom backend */
|
/* register custom backend */
|
||||||
|
@ -213,9 +220,9 @@ int settings_backend_init(void)
|
||||||
|
|
||||||
void settings_test_backend_clear(void)
|
void settings_test_backend_clear(void)
|
||||||
{
|
{
|
||||||
FILE *fp = fopen(SETTINGS_FILE, "w");
|
snprintf(setting_file, sizeof(setting_file), "%s_%d.log", get_simid(), get_device_nbr());
|
||||||
|
|
||||||
if (fp) {
|
if (remove(setting_file)) {
|
||||||
fclose(fp);
|
LOG_INF("error deleting file: %s", setting_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "mesh/net.h"
|
#include "mesh/net.h"
|
||||||
#include "mesh/transport.h"
|
#include "mesh/transport.h"
|
||||||
#include <sys/byteorder.h>
|
#include <sys/byteorder.h>
|
||||||
|
#include "argparse.h"
|
||||||
|
|
||||||
#define LOG_MODULE_NAME test_friendship
|
#define LOG_MODULE_NAME test_friendship
|
||||||
|
|
||||||
|
@ -70,10 +71,8 @@ static void test_lpn_init(void)
|
||||||
* devkey based on the device number, which is guaranteed to be unique
|
* devkey based on the device number, which is guaranteed to be unique
|
||||||
* for each device in the simulation.
|
* for each device in the simulation.
|
||||||
*/
|
*/
|
||||||
extern uint global_device_nbr;
|
lpn_cfg.addr = LPN_ADDR_START + get_device_nbr();
|
||||||
|
lpn_cfg.dev_key[0] = get_device_nbr();
|
||||||
lpn_cfg.addr = LPN_ADDR_START + global_device_nbr;
|
|
||||||
lpn_cfg.dev_key[0] = global_device_nbr;
|
|
||||||
test_common_init(&lpn_cfg);
|
test_common_init(&lpn_cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +493,7 @@ static void test_lpn_msg_mesh(void)
|
||||||
test_model->pub->ttl = BT_MESH_TTL_DEFAULT;
|
test_model->pub->ttl = BT_MESH_TTL_DEFAULT;
|
||||||
|
|
||||||
net_buf_simple_reset(test_model->pub->msg);
|
net_buf_simple_reset(test_model->pub->msg);
|
||||||
bt_mesh_model_msg_init(test_model->pub->msg, TEST_MSG_OP);
|
bt_mesh_model_msg_init(test_model->pub->msg, TEST_MSG_OP_1);
|
||||||
ASSERT_OK(bt_mesh_model_publish(test_model));
|
ASSERT_OK(bt_mesh_model_publish(test_model));
|
||||||
|
|
||||||
PASS();
|
PASS();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
#include "mesh_test.h"
|
#include "mesh_test.h"
|
||||||
#include "mesh/net.h"
|
#include "mesh/net.h"
|
||||||
|
#include "argparse.h"
|
||||||
|
|
||||||
#include <sys/byteorder.h>
|
#include <sys/byteorder.h>
|
||||||
|
|
||||||
|
@ -29,7 +30,6 @@ enum test_flags {
|
||||||
static ATOMIC_DEFINE(flags, TEST_FLAGS);
|
static ATOMIC_DEFINE(flags, TEST_FLAGS);
|
||||||
extern const struct bt_mesh_comp comp;
|
extern const struct bt_mesh_comp comp;
|
||||||
extern const uint8_t test_net_key[16];
|
extern const uint8_t test_net_key[16];
|
||||||
extern uint global_device_nbr;
|
|
||||||
|
|
||||||
/* Timeout semaphore */
|
/* Timeout semaphore */
|
||||||
static struct k_sem prov_sem;
|
static struct k_sem prov_sem;
|
||||||
|
@ -42,7 +42,7 @@ static uint8_t dev_uuid[16] = { 0x6c, 0x69, 0x6e, 0x67, 0x61, 0x6f };
|
||||||
static void test_device_init(void)
|
static void test_device_init(void)
|
||||||
{
|
{
|
||||||
/* Ensure that the UUID is unique: */
|
/* Ensure that the UUID is unique: */
|
||||||
dev_uuid[6] = '0' + global_device_nbr;
|
dev_uuid[6] = '0' + get_device_nbr();
|
||||||
|
|
||||||
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
|
bt_mesh_test_cfg_set(NULL, WAIT_TIME);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue