boards: bsim: fix bug with single settings file for few bsim devices

Multiple bsim devices cannot store individual settings
with the existing settings backend for bsim.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
This commit is contained in:
Aleksandr Khromykh 2021-08-23 15:03:46 +02:00 committed by Christopher Friedt
commit 4b5cd92312
7 changed files with 39 additions and 25 deletions

View file

@ -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);

View file

@ -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
} }

View file

@ -57,8 +57,6 @@ void posix_exit(int exit_code)
exit(inner_main_clean_up(exit_code)); exit(inner_main_clean_up(exit_code));
} }
uint global_device_nbr;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
/* /*
@ -79,7 +77,6 @@ int main(int argc, char *argv[])
struct NRF_bsim_args_t *args; struct NRF_bsim_args_t *args;
args = nrfbsim_argsparse(argc, argv); args = nrfbsim_argsparse(argc, argv);
global_device_nbr = args->global_device_nbr;
bs_read_function_names_from_Tsymbols(argv[0]); bs_read_function_names_from_Tsymbols(argv[0]);

View file

@ -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);
} }
} }

View 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();

View file

@ -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);
} }

View file

@ -20,6 +20,7 @@
#include "bs_utils.h" #include "bs_utils.h"
#include "bs_oswrap.h" #include "bs_oswrap.h"
#include "bs_pc_base_fifo_user.h" #include "bs_pc_base_fifo_user.h"
#include "argparse.h"
/* Recheck if something arrived from the EDTT every 5ms */ /* Recheck if something arrived from the EDTT every 5ms */
#define EDTT_IF_RECHECK_DELTA 5 /* ms */ #define EDTT_IF_RECHECK_DELTA 5 /* ms */
@ -42,8 +43,6 @@ static int edtt_autoshutdown;
static int fifo[2] = { -1, -1 }; static int fifo[2] = { -1, -1 };
static char *fifo_path[2] = {NULL, NULL}; static char *fifo_path[2] = {NULL, NULL};
extern unsigned int global_device_nbr;
static void edttd_clean_up(void); static void edttd_clean_up(void);
static void edptd_create_fifo_if(void); static void edptd_create_fifo_if(void);
static int fifo_low_level_read(uint8_t *bufptr, int size); static int fifo_low_level_read(uint8_t *bufptr, int size);
@ -192,9 +191,9 @@ static void edptd_create_fifo_if(void)
fifo_path[TO_BRIDGE] = (char *)bs_calloc(pb_com_path_length + 30, fifo_path[TO_BRIDGE] = (char *)bs_calloc(pb_com_path_length + 30,
sizeof(char)); sizeof(char));
sprintf(fifo_path[TO_DEVICE], "%s/Device%i.PTTin", sprintf(fifo_path[TO_DEVICE], "%s/Device%i.PTTin",
pb_com_path, global_device_nbr); pb_com_path, get_device_nbr());
sprintf(fifo_path[TO_BRIDGE], "%s/Device%i.PTTout", sprintf(fifo_path[TO_BRIDGE], "%s/Device%i.PTTout",
pb_com_path, global_device_nbr); pb_com_path, get_device_nbr());
if ((pb_create_fifo_if_not_there(fifo_path[TO_DEVICE]) != 0) if ((pb_create_fifo_if_not_there(fifo_path[TO_DEVICE]) != 0)
|| (pb_create_fifo_if_not_there(fifo_path[TO_BRIDGE]) != 0)) { || (pb_create_fifo_if_not_there(fifo_path[TO_BRIDGE]) != 0)) {