subsys/settings: change processing to const char

The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.

It is an alternative to #16609

The possibility is introduced to register handler including a
separator, or to register a handler for each variable.

The ability is introduced to load a subtree from flash or even to load
a single item.

Two ways to operate on variable and settings_handler names are provided:

settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.

settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.

A mutex is added to make settings thread-safe

The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.

A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.

Tests have been updated to reflect changes in the settings api.

Updates after meeting:
1. Removed settings_deregister

2. Changed settings_name_split() in settings_name_next:

int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.

3. New functional test added

Update in settings.h: settings_name_next() changed position -> index

Added some comments in settings.h (settings_name_steq())

Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.

Corrected some documentation in header.

Changed registration of handlers to be non ordered.

Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
This commit is contained in:
Laczen JMS 2019-06-08 21:24:42 +02:00 committed by Carles Cufí
commit 36edf92ca8
20 changed files with 753 additions and 154 deletions

View file

@ -26,7 +26,8 @@ extern "C" {
#define SETTINGS_MAX_DIR_DEPTH 8 /* max depth of settings tree */ #define SETTINGS_MAX_DIR_DEPTH 8 /* max depth of settings tree */
#define SETTINGS_MAX_NAME_LEN (8 * SETTINGS_MAX_DIR_DEPTH) #define SETTINGS_MAX_NAME_LEN (8 * SETTINGS_MAX_DIR_DEPTH)
#define SETTINGS_MAX_VAL_LEN 256 #define SETTINGS_MAX_VAL_LEN 256
#define SETTINGS_NAME_SEPARATOR "/" #define SETTINGS_NAME_SEPARATOR '/'
#define SETTINGS_NAME_END '='
/* pleace for settings additions: /* pleace for settings additions:
* up to 7 separators, '=', '\0' * up to 7 separators, '=', '\0'
@ -47,26 +48,27 @@ struct settings_handler {
char *name; char *name;
/**< Name of subtree. */ /**< Name of subtree. */
int (*h_get)(int argc, char **argv, char *val, int val_len_max); int (*h_get)(const char *key, char *val, int val_len_max);
/**< Get values handler of settings items identified by keyword names. /**< Get values handler of settings items identified by keyword names.
* *
* Parameters: * Parameters:
* - argc - count of item in argv. * - key[in] the name with skipped part that was used as name in
* - argv - array of pointers to keyword names. * handler registration
* - val - buffer for a value. * - val[out] buffer to receive value.
* - val_len_max - size of that buffer. * - val_len_max[in] size of that buffer.
*/ */
int (*h_set)(int argc, char **argv, size_t len, int (*h_set)(const char *key, size_t len, settings_read_cb read_cb,
settings_read_cb read_cb, void *cb_arg); void *cb_arg);
/**< Set value handler of settings items identified by keyword names. /**< Set value handler of settings items identified by keyword names.
* *
* Parameters: * Parameters:
* - argc - count of item in argv. * - key[in] the name with skipped part that was used as name in
* - argv - array of pointers to keyword names. * handler registration
* - len - the size of the data found in the backend. * - len[in] the size of the data found in the backend.
* - read_cb - function provided to read the data from the backend. * - read_cb[in] function provided to read the data from the backend.
* - cb_arg - arguments for the read function provided by the backend. * - cb_arg[in] arguments for the read function provided by the
* backend.
*/ */
int (*h_commit)(void); int (*h_commit)(void);
@ -121,8 +123,18 @@ int settings_register(struct settings_handler *cf);
int settings_load(void); int settings_load(void);
/** /**
* Save currently running serialized items. All serialized items which are different * Load limited set of serialized items from registered persistence sources.
* from currently persisted values will be saved. * Handlers for serialized item subtrees registered earlier will be called for
* encountered values that belong to the subtree.
*
* @param[in] subtree name of the subtree to be loaded.
* @return 0 on success, non-zero on failure.
*/
int settings_load_subtree(const char *subtree);
/**
* Save currently running serialized items. All serialized items which are
* different from currently persisted values will be saved.
* *
* @return 0 on success, non-zero on failure. * @return 0 on success, non-zero on failure.
*/ */
@ -161,6 +173,16 @@ int settings_delete(const char *name);
*/ */
int settings_commit(void); int settings_commit(void);
/**
* Call commit for settings handler that belong to subtree.
* This should apply all settings which has been set, but not applied yet.
*
* @param[in] subtree name of the subtree to be committed.
*
* @return 0 on success, non-zero on failure.
*/
int settings_commit_subtree(const char *subtree);
/** /**
* @} settings * @} settings
*/ */
@ -191,8 +213,9 @@ struct settings_store {
* Destinations are registered using a call to @ref settings_dst_register. * Destinations are registered using a call to @ref settings_dst_register.
*/ */
struct settings_store_itf { struct settings_store_itf {
int (*csi_load)(struct settings_store *cs); int (*csi_load)(struct settings_store *cs, const char *subtree);
/**< Loads all values from storage. /**< Loads values from storage limited to subtree defined by subtree. If
* subtree = NULL loads all values.
* *
* Parameters: * Parameters:
* - cs - Corresponding backend handler node * - cs - Corresponding backend handler node
@ -248,16 +271,53 @@ void settings_dst_register(struct settings_store *cs);
/** /**
* Parses a key to an array of elements and locate corresponding module handler. * Parses a key to an array of elements and locate corresponding module handler.
* *
* @param name Key in string format * @param[in] name in string format
* @param name_argc Parsed number of elements. * @param[out] next remaining of name after matched handler
* @param name_argv Parsed array of elements.
* *
* @return settings_handler node on success, NULL on failure. * @return settings_handler node on success, NULL on failure.
*/ */
struct settings_handler *settings_parse_and_lookup(char *name, int *name_argc, struct settings_handler *settings_parse_and_lookup(const char *name,
char *name_argv[]); const char **next);
/*
* API for const name processing
*/
/**
* Compares the start of name with a key
*
* @param[in] name in string format
* @param[in] key comparison string
* @param[out] next pointer to remaining of name, when the remaining part
* starts with a separator the separator is removed from next
*
* Some examples:
* settings_name_steq("bt/btmesh/iv", "b", &next) returns 1, next="t/btmesh/iv"
* settings_name_steq("bt/btmesh/iv", "bt", &next) returns 1, next="btmesh/iv"
* settings_name_steq("bt/btmesh/iv", "bt/", &next) returns 0, next=NULL
* settings_name_steq("bt/btmesh/iv", "bta", &next) returns 0, next=NULL
*
* REMARK: This routine could be simplified if the settings_handler names
* would include a separator at the end.
*
* @return 0: no match
* 1: match, next can be used to check if match is full
*/
int settings_name_steq(const char *name, const char *key, const char **next);
/**
* determine the number of characters before the first separator
*
* @param[in] name in string format
* @param[out] next pointer to remaining of name (excluding separator)
*
* @return index of the first separator, in case no separator was found this
* is the size of name
*
*/
int settings_name_next(const char *name, const char **next);
/* /*
* API for runtime settings * API for runtime settings
*/ */

View file

@ -18,10 +18,9 @@
LOG_MODULE_REGISTER(settings, CONFIG_SETTINGS_LOG_LEVEL); LOG_MODULE_REGISTER(settings, CONFIG_SETTINGS_LOG_LEVEL);
sys_slist_t settings_handlers; sys_slist_t settings_handlers;
struct k_mutex settings_lock;
static struct settings_handler *settings_handler_lookup(char *name);
void settings_store_init(void); void settings_store_init(void);
void settings_init(void) void settings_init(void)
@ -32,70 +31,119 @@ void settings_init(void)
int settings_register(struct settings_handler *handler) int settings_register(struct settings_handler *handler)
{ {
if (settings_handler_lookup(handler->name)) { int rc;
return -EEXIST;
}
sys_slist_prepend(&settings_handlers, &handler->node);
return 0;
}
/*
* Find settings_handler based on name.
*/
static struct settings_handler *settings_handler_lookup(char *name)
{
struct settings_handler *ch; struct settings_handler *ch;
k_mutex_lock(&settings_lock, K_FOREVER);
SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) { SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) {
if (!strcmp(name, ch->name)) { if (strcmp(handler->name, ch->name) == 0) {
return ch; rc = -EEXIST;
goto end;
} }
} }
return NULL; sys_slist_append(&settings_handlers, &handler->node);
rc = 0;
end:
k_mutex_unlock(&settings_lock);
return rc;
} }
/* int settings_name_steq(const char *name, const char *key, const char **next)
* Separate string into argv array.
*/
int settings_parse_name(char *name, int *name_argc, char *name_argv[])
{ {
int i = 0; if (next) {
*next = NULL;
while (name) {
name_argv[i++] = name;
while (1) {
if (*name == '\0') {
name = NULL;
break;
}
if (*name == *SETTINGS_NAME_SEPARATOR) {
*name = '\0';
name++;
break;
}
name++;
}
} }
*name_argc = i; if ((!name) || (!key)) {
return 0;
}
/* name might come from flash directly, in flash the name would end
* with '=' or '\0' depending how storage is done. Flash reading is
* limited to what can be read
*/
while ((*key != '\0') && (*key == *name) &&
(*name != '\0') && (*name != SETTINGS_NAME_END)) {
key++;
name++;
}
if (*key != '\0') {
return 0;
}
if (*name == SETTINGS_NAME_SEPARATOR) {
if (next) {
*next = name + 1;
}
return 1;
}
if ((*name == SETTINGS_NAME_END) || (*name == '\0')) {
return 1;
}
return 0; return 0;
} }
struct settings_handler *settings_parse_and_lookup(char *name, int settings_name_next(const char *name, const char **next)
int *name_argc,
char *name_argv[])
{ {
int rc; int rc = 0;
rc = settings_parse_name(name, name_argc, name_argv); if (next) {
if (rc) { *next = NULL;
return NULL;
} }
return settings_handler_lookup(name_argv[0]);
if (!name) {
return 0;
}
/* name might come from flash directly, in flash the name would end
* with '=' or '\0' depending how storage is done. Flash reading is
* limited to what can be read
*/
while ((*name != '\0') && (*name != SETTINGS_NAME_END) &&
(*name != SETTINGS_NAME_SEPARATOR)) {
rc++;
name++;
}
if (*name == SETTINGS_NAME_SEPARATOR) {
if (next) {
*next = name + 1;
}
return rc;
}
return rc;
}
struct settings_handler *settings_parse_and_lookup(const char *name,
const char **next)
{
struct settings_handler *ch, *bestmatch;
const char *tmpnext;
bestmatch = NULL;
if (next) {
*next = NULL;
}
SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) {
if (settings_name_steq(name, ch->name, &tmpnext)) {
if ((!bestmatch) ||
(settings_name_steq(ch->name,
bestmatch->name, NULL))) {
bestmatch = ch;
if (next) {
*next = tmpnext;
}
}
}
}
return bestmatch;
} }
int settings_commit(void) int settings_commit(void)
@ -115,3 +163,25 @@ int settings_commit(void)
} }
return rc; return rc;
} }
int settings_commit_subtree(const char *subtree)
{
struct settings_handler *ch;
int rc;
int rc2;
rc = 0;
SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) {
if (subtree && !settings_name_steq(ch->name, subtree, NULL)) {
continue;
}
if (ch->h_commit) {
rc2 = ch->h_commit();
if (!rc) {
rc = rc2;
}
}
}
return rc;
}

View file

@ -23,11 +23,11 @@ struct settings_fcb_load_cb_arg {
void *cb_arg; void *cb_arg;
}; };
static int settings_fcb_load(struct settings_store *cs); static int settings_fcb_load(struct settings_store *cs, const char *subtree);
static int settings_fcb_save(struct settings_store *cs, const char *name, static int settings_fcb_save(struct settings_store *cs, const char *name,
const char *value, size_t val_len); const char *value, size_t val_len);
static struct settings_store_itf settings_fcb_itf = { static const struct settings_store_itf settings_fcb_itf = {
.csi_load = settings_fcb_load, .csi_load = settings_fcb_load,
.csi_save = settings_fcb_save, .csi_save = settings_fcb_save,
}; };
@ -117,9 +117,10 @@ static int settings_fcb_load_priv(struct settings_store *cs, line_load_cb cb,
return 0; return 0;
} }
static int settings_fcb_load(struct settings_store *cs) static int settings_fcb_load(struct settings_store *cs, const char *subtree)
{ {
return settings_fcb_load_priv(cs, settings_line_load_cb, NULL); return settings_fcb_load_priv(cs, settings_line_load_cb,
(void *)subtree);
} }

View file

@ -14,11 +14,11 @@
#include "settings/settings_file.h" #include "settings/settings_file.h"
#include "settings_priv.h" #include "settings_priv.h"
static int settings_file_load(struct settings_store *cs); static int settings_file_load(struct settings_store *cs, const char *subtree);
static int settings_file_save(struct settings_store *cs, const char *name, static int settings_file_save(struct settings_store *cs, const char *name,
const char *value, size_t val_len); const char *value, size_t val_len);
static struct settings_store_itf settings_file_itf = { static const struct settings_store_itf settings_file_itf = {
.csi_load = settings_file_load, .csi_load = settings_file_load,
.csi_save = settings_file_save, .csi_save = settings_file_save,
}; };
@ -109,9 +109,10 @@ static int settings_file_load_priv(struct settings_store *cs, line_load_cb cb,
/* /*
* Called to load configuration items. * Called to load configuration items.
*/ */
static int settings_file_load(struct settings_store *cs) static int settings_file_load(struct settings_store *cs, const char *subtree)
{ {
return settings_file_load_priv(cs, settings_line_load_cb, NULL); return settings_file_load_priv(cs, settings_line_load_cb,
(void *)subtree);
} }
static void settings_tmpfile(char *dst, const char *src, char *pfx) static void settings_tmpfile(char *dst, const char *src, char *pfx)

View file

@ -487,7 +487,7 @@ static int settings_line_cmp(char const *val, size_t val_len,
return rc; return rc;
} }
void settings_line_dup_check_cb(char *name, void *val_read_cb_ctx, void settings_line_dup_check_cb(const char *name, void *val_read_cb_ctx,
off_t off, void *cb_arg) off_t off, void *cb_arg)
{ {
struct settings_line_dup_check_arg *cdca; struct settings_line_dup_check_arg *cdca;
@ -530,17 +530,20 @@ static ssize_t settings_line_read_cb(void *cb_arg, void *data, size_t len)
return -1; return -1;
} }
void settings_line_load_cb(char *name, void *val_read_cb_ctx, off_t off, void settings_line_load_cb(const char *name, void *val_read_cb_ctx, off_t off,
void *cb_arg) void *cb_arg)
{ {
int name_argc; const char *name_key;
char *name_argv[SETTINGS_MAX_DIR_DEPTH];
struct settings_handler *ch; struct settings_handler *ch;
struct settings_line_read_value_cb_ctx value_ctx; struct settings_line_read_value_cb_ctx value_ctx;
int rc; int rc;
size_t len; size_t len;
ch = settings_parse_and_lookup(name, &name_argc, name_argv); if (cb_arg && !settings_name_steq(name, cb_arg, NULL)) {
return;
}
ch = settings_parse_and_lookup(name, &name_key);
if (!ch) { if (!ch) {
return; return;
} }
@ -550,7 +553,7 @@ void settings_line_load_cb(char *name, void *val_read_cb_ctx, off_t off,
len = settings_line_val_get_len(off, val_read_cb_ctx); len = settings_line_val_get_len(off, val_read_cb_ctx);
rc = ch->h_set(name_argc - 1, &name_argv[1], len, settings_line_read_cb, rc = ch->h_set(name_key, len, settings_line_read_cb,
(void *)&value_ctx); (void *)&value_ctx);
if (rc != 0) { if (rc != 0) {

View file

@ -35,14 +35,14 @@ int settings_line_write(const char *name, const char *value, size_t val_len,
/* Get len of record without alignment to write-block-size */ /* Get len of record without alignment to write-block-size */
int settings_line_len_calc(const char *name, size_t val_len); int settings_line_len_calc(const char *name, size_t val_len);
void settings_line_dup_check_cb(char *name, void *val_read_cb_ctx, off_t off, void settings_line_dup_check_cb(const char *name, void *val_read_cb_ctx,
void *cb_arg); off_t off, void *cb_arg);
void settings_line_load_cb(char *name, void *val_read_cb_ctx, off_t off, void settings_line_load_cb(const char *name, void *val_read_cb_ctx,
void *cb_arg); off_t off, void *cb_arg);
typedef void (*line_load_cb)(char *name, void *val_read_cb_ctx, off_t off, typedef void (*line_load_cb)(const char *name, void *val_read_cb_ctx,
void *cb_arg); off_t off, void *cb_arg);
struct settings_line_read_value_cb_ctx { struct settings_line_read_value_cb_ctx {
void *read_cb_ctx; void *read_cb_ctx;

View file

@ -18,54 +18,39 @@ static ssize_t settings_runtime_read_cb(void *cb_arg, void *data, size_t len)
int settings_runtime_set(const char *name, void *data, size_t len) int settings_runtime_set(const char *name, void *data, size_t len)
{ {
struct settings_handler *ch; struct settings_handler *ch;
char name1[SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN]; const char *name_key;
char *name_argv[SETTINGS_MAX_DIR_DEPTH];
int name_argc;
strncpy(name1, name, sizeof(name1) - 1); ch = settings_parse_and_lookup(name, &name_key);
name1[sizeof(name1) - 1] = '\0';
ch = settings_parse_and_lookup(name1, &name_argc, name_argv);
if (!ch) { if (!ch) {
return -EINVAL; return -EINVAL;
} }
return ch->h_set(name_argc - 1, &name_argv[1], len, return ch->h_set(name_key, len, settings_runtime_read_cb, data);
settings_runtime_read_cb, data);
} }
int settings_runtime_get(const char *name, void *data, size_t len) int settings_runtime_get(const char *name, void *data, size_t len)
{ {
struct settings_handler *ch; struct settings_handler *ch;
char name1[SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN]; const char *name_key;
char *name_argv[SETTINGS_MAX_DIR_DEPTH];
int name_argc;
strncpy(name1, name, sizeof(name1) - 1); ch = settings_parse_and_lookup(name, &name_key);
name1[sizeof(name1) - 1] = '\0';
ch = settings_parse_and_lookup(name1, &name_argc, name_argv);
if (!ch) { if (!ch) {
return -EINVAL; return -EINVAL;
} }
return ch->h_get(name_argc - 1, &name_argv[1], data, len); return ch->h_get(name_key, data, len);
} }
int settings_runtime_commit(const char *name) int settings_runtime_commit(const char *name)
{ {
struct settings_handler *ch; struct settings_handler *ch;
char name1[SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN]; const char *name_key;
char *name_argv[SETTINGS_MAX_DIR_DEPTH];
int name_argc;
strncpy(name1, name, sizeof(name1) - 1); ch = settings_parse_and_lookup(name, &name_key);
name1[sizeof(name1) - 1] = '\0';
ch = settings_parse_and_lookup(name1, &name_argc, name_argv);
if (!ch) { if (!ch) {
return -EINVAL; return -EINVAL;
} }
if (ch->h_commit) { if (ch->h_commit) {
return ch->h_commit(); return ch->h_commit();
} else { } else {

View file

@ -21,6 +21,7 @@ LOG_MODULE_DECLARE(settings, CONFIG_SETTINGS_LOG_LEVEL);
sys_slist_t settings_load_srcs; sys_slist_t settings_load_srcs;
struct settings_store *settings_save_dst; struct settings_store *settings_save_dst;
extern struct k_mutex settings_lock;
void settings_src_register(struct settings_store *cs) void settings_src_register(struct settings_store *cs)
{ {
@ -41,8 +42,14 @@ void settings_dst_register(struct settings_store *cs)
} }
int settings_load(void) int settings_load(void)
{
return settings_load_subtree(NULL);
}
int settings_load_subtree(const char *subtree)
{ {
struct settings_store *cs; struct settings_store *cs;
int rc;
/* /*
* for every config store * for every config store
@ -50,11 +57,13 @@ int settings_load(void)
* apply config * apply config
* commit all * commit all
*/ */
k_mutex_lock(&settings_lock, K_FOREVER);
SYS_SLIST_FOR_EACH_CONTAINER(&settings_load_srcs, cs, cs_next) { SYS_SLIST_FOR_EACH_CONTAINER(&settings_load_srcs, cs, cs_next) {
cs->cs_itf->csi_load(cs); cs->cs_itf->csi_load(cs, subtree);
} }
return settings_commit(); rc = settings_commit_subtree(subtree);
k_mutex_unlock(&settings_lock);
return rc;
} }
/* /*
@ -62,6 +71,7 @@ int settings_load(void)
*/ */
int settings_save_one(const char *name, const void *value, size_t val_len) int settings_save_one(const char *name, const void *value, size_t val_len)
{ {
int rc;
struct settings_store *cs; struct settings_store *cs;
cs = settings_save_dst; cs = settings_save_dst;
@ -69,7 +79,13 @@ int settings_save_one(const char *name, const void *value, size_t val_len)
return -ENOENT; return -ENOENT;
} }
return cs->cs_itf->csi_save(cs, name, (char *)value, val_len); k_mutex_lock(&settings_lock, K_FOREVER);
rc = cs->cs_itf->csi_save(cs, name, (char *)value, val_len);
k_mutex_unlock(&settings_lock);
return rc;
} }
int settings_delete(const char *name) int settings_delete(const char *name)

View file

@ -23,21 +23,21 @@ int test_export_block;
int c2_var_count = 1; int c2_var_count = 1;
int c1_handle_get(int argc, char **argv, char *val, int val_len_max); int c1_handle_get(const char *name, char *val, int val_len_max);
int c1_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb, int c1_handle_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg); void *cb_arg);
int c1_handle_commit(void); int c1_handle_commit(void);
int c1_handle_export(int (*cb)(const char *name, int c1_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len)); const void *value, size_t val_len));
int c2_handle_get(int argc, char **argv, char *val, int val_len_max); int c2_handle_get(const char *name, char *val, int val_len_max);
int c2_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb, int c2_handle_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg); void *cb_arg);
int c2_handle_export(int (*cb)(const char *name, int c2_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len)); const void *value, size_t val_len));
int c3_handle_get(int argc, char **argv, char *val, int val_len_max); int c3_handle_get(const char *name, char *val, int val_len_max);
int c3_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb, int c3_handle_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg); void *cb_arg);
int c3_handle_export(int (*cb)(const char *name, int c3_handle_export(int (*cb)(const char *name,
const void *value, size_t val_len)); const void *value, size_t val_len));
@ -69,17 +69,19 @@ struct settings_handler c_test_handlers[] = {
char val_string[SETTINGS_TEST_FCB_VAL_STR_CNT][SETTINGS_MAX_VAL_LEN]; char val_string[SETTINGS_TEST_FCB_VAL_STR_CNT][SETTINGS_MAX_VAL_LEN];
char test_ref_value[SETTINGS_TEST_FCB_VAL_STR_CNT][SETTINGS_MAX_VAL_LEN]; char test_ref_value[SETTINGS_TEST_FCB_VAL_STR_CNT][SETTINGS_MAX_VAL_LEN];
int c1_handle_get(int argc, char **argv, char *val, int val_len_max) int c1_handle_get(const char *name, char *val, int val_len_max)
{ {
const char *next;
test_get_called = 1; test_get_called = 1;
if (argc == 1 && !strcmp(argv[0], "mybar")) { if (settings_name_steq(name, "mybar", &next) && !next) {
val_len_max = MIN(val_len_max, sizeof(val8)); val_len_max = MIN(val_len_max, sizeof(val8));
memcpy(val, &val8, MIN(val_len_max, sizeof(val8))); memcpy(val, &val8, MIN(val_len_max, sizeof(val8)));
return val_len_max; return val_len_max;
} }
if (argc == 1 && !strcmp(argv[0], "mybar64")) { if (settings_name_steq(name, "mybar64", &next) && !next) {
val_len_max = MIN(val_len_max, sizeof(val64)); val_len_max = MIN(val_len_max, sizeof(val64));
memcpy(val, &val64, MIN(val_len_max, sizeof(val64))); memcpy(val, &val64, MIN(val_len_max, sizeof(val64)));
return val_len_max; return val_len_max;
@ -88,26 +90,27 @@ int c1_handle_get(int argc, char **argv, char *val, int val_len_max)
return -ENOENT; return -ENOENT;
} }
int c1_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb, int c1_handle_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg) void *cb_arg)
{ {
size_t val_len; size_t val_len;
int rc; int rc;
const char *next;
test_set_called = 1; test_set_called = 1;
if (argc == 1 && !strcmp(argv[0], "mybar")) { if (settings_name_steq(name, "mybar", &next) && !next) {
rc = read_cb(cb_arg, &val8, sizeof(val8)); rc = read_cb(cb_arg, &val8, sizeof(val8));
zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback"); zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback");
return 0; return 0;
} }
if (argc == 1 && !strcmp(argv[0], "mybar64")) { if (settings_name_steq(name, "mybar64", &next) && !next) {
rc = read_cb(cb_arg, &val64, sizeof(val64)); rc = read_cb(cb_arg, &val64, sizeof(val64));
zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback"); zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback");
return 0; return 0;
} }
if (argc == 1 && !strcmp(argv[0], "unaligned")) { if (settings_name_steq(name, "unaligned", &next) && !next) {
val_len = len; val_len = len;
zassert_equal(val_len, sizeof(val8_un), zassert_equal(val_len, sizeof(val8_un),
"value length: %d, ought equal 1", val_len); "value length: %d, ought equal 1", val_len);
@ -225,13 +228,18 @@ char *c2_var_find(char *name)
return val_string[idx]; return val_string[idx];
} }
int c2_handle_get(int argc, char **argv, char *val, int val_len_max) int c2_handle_get(const char *name, char *val, int val_len_max)
{ {
int len; int len;
char *valptr; char *valptr;
const char *next;
char argv[32];
if (argc == 1) { len = settings_name_next(name, &next);
valptr = c2_var_find(argv[0]); if (len && !next) {
strncpy(argv, name, len);
argv[len] = '\0';
valptr = c2_var_find(argv);
if (!valptr) { if (!valptr) {
return -ENOENT; return -ENOENT;
} }
@ -249,14 +257,20 @@ int c2_handle_get(int argc, char **argv, char *val, int val_len_max)
return -ENOENT; return -ENOENT;
} }
int c2_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb, int c2_handle_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg) void *cb_arg)
{ {
char *valptr; char *valptr;
const char *next;
char argv[32];
int rc; int rc;
if (argc == 1) { len = settings_name_next(name, &next);
valptr = c2_var_find(argv[0]); if (len && !next) {
strncpy(argv, name, len);
argv[len] = '\0';
valptr = c2_var_find(argv);
if (!valptr) { if (!valptr) {
return -ENOENT; return -ENOENT;
} }
@ -287,9 +301,11 @@ int c2_handle_export(int (*cb)(const char *name,
return 0; return 0;
} }
int c3_handle_get(int argc, char **argv, char *val, int val_len_max) int c3_handle_get(const char *name, char *val, int val_len_max)
{ {
if (argc == 1 && !strcmp(argv[0], "v")) { const char *next;
if (settings_name_steq(name, "v", &next) && !next) {
val_len_max = MIN(val_len_max, sizeof(val32)); val_len_max = MIN(val_len_max, sizeof(val32));
memcpy(val, &val32, MIN(val_len_max, sizeof(val32))); memcpy(val, &val32, MIN(val_len_max, sizeof(val32)));
return val_len_max; return val_len_max;
@ -297,13 +313,14 @@ int c3_handle_get(int argc, char **argv, char *val, int val_len_max)
return -EINVAL; return -EINVAL;
} }
int c3_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb, int c3_handle_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg) void *cb_arg)
{ {
int rc; int rc;
size_t val_len; size_t val_len;
const char *next;
if (argc == 1 && !strcmp(argv[0], "v")) { if (settings_name_steq(name, "v", &next) && !next) {
val_len = len; val_len = len;
zassert_true(val_len == 4, "bad set-value size"); zassert_true(val_len == 4, "bad set-value size");

View file

@ -15,12 +15,13 @@
static u32_t val32; static u32_t val32;
static int c1_set(int argc, char **argv, size_t len, settings_read_cb read_cb, static int c1_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg) void *cb_arg)
{ {
int rc; int rc;
const char *next;
if (argc == 1 && !strcmp(argv[0], "val32")) { if (settings_name_steq(name, "val32", &next) && !next) {
rc = read_cb(cb_arg, &val32, sizeof(val32)); rc = read_cb(cb_arg, &val32, sizeof(val32));
zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback"); zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback");
return 0; return 0;

View file

@ -0,0 +1,18 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
zephyr_include_directories(
$ENV{ZEPHYR_BASE}/subsys/settings/include
$ENV{ZEPHYR_BASE}/subsys/settings/src
)
if(TEST)
target_compile_definitions(app PRIVATE
-DTEST_${TEST}
)
endif()

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2019 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/
/delete-node/ &storage_partition;
/delete-node/ &scratch_partition;
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
storage_partition: partition@70000 {
label = "storage";
reg = <0x00070000 0x10000>;
};
};
};

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/delete-node/ &storage_partition;
/delete-node/ &scratch_partition;
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
storage_partition: partition@de000 {
label = "storage";
reg = <0x000de000 0x00010000>;
};
};
};

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/delete-node/ &storage_partition;
/delete-node/ &scratch_partition;
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
storage_partition: partition@70000 {
label = "storage";
reg = <0x00070000 0x10000>;
};
};
};

View file

@ -0,0 +1,12 @@
CONFIG_ZTEST=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_ARM_MPU=n
CONFIG_FCB=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_SETTINGS_FCB=y
CONFIG_SETTINGS_USE_BASE64=n

View file

@ -0,0 +1,11 @@
CONFIG_ZTEST=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_FCB=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_SETTINGS_FCB=y
CONFIG_SETTINGS_USE_BASE64=n

View file

@ -0,0 +1,11 @@
CONFIG_ZTEST=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_FCB=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_SETTINGS_FCB=y
CONFIG_SETTINGS_USE_BASE64=n

View file

@ -0,0 +1,312 @@
/*
* Copyright (c) 2018 Laczen
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief Settings functional test suite
*
*/
#include <zephyr.h>
#include <ztest.h>
#include <errno.h>
#include <settings/settings.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(settings_basic_test);
/*
* Test the two support routines that settings provides:
*
* settings_name_steq(name, key, next): compares the start of name with key
* settings_name_next(name, next): returns the location of the first
* separator
*/
static void test_support_rtn(void)
{
const char test1[] = "bt/a/b/c/d";
const char test2[] = "bt/a/b/c/d=";
const char *next1, *next2;
int rc;
/* complete match: return 1, next = NULL */
rc = settings_name_steq(test1, "bt/a/b/c/d", &next1);
zassert_true(rc == 1, "_steq comparison failure");
zassert_is_null(next1, "_steq comparison next error");
rc = settings_name_steq(test2, "bt/a/b/c/d", &next2);
zassert_true(rc == 1, "_steq comparison failure");
zassert_is_null(next2, "_steq comparison next error");
/* partial match: return 1, next <> NULL */
rc = settings_name_steq(test1, "bt/a/b/c", &next1);
zassert_true(rc == 1, "_steq comparison failure");
zassert_not_null(next1, "_steq comparison next error");
zassert_equal_ptr(next1, test1+9, "next points to wrong location");
rc = settings_name_steq(test2, "bt/a/b/c", &next2);
zassert_true(rc == 1, "_steq comparison failure");
zassert_not_null(next2, "_steq comparison next error");
zassert_equal_ptr(next2, test2+9, "next points to wrong location");
/* no match: return 0, next = NULL */
rc = settings_name_steq(test1, "bta", &next1);
zassert_true(rc == 0, "_steq comparison failure");
zassert_is_null(next1, "_steq comparison next error");
rc = settings_name_steq(test2, "bta", &next2);
zassert_true(rc == 0, "_steq comparison failure");
zassert_is_null(next2, "_steq comparison next error");
/* no match: return 0, next = NULL */
rc = settings_name_steq(test1, "b", &next1);
zassert_true(rc == 0, "_steq comparison failure");
zassert_is_null(next1, "_steq comparison next error");
rc = settings_name_steq(test2, "b", &next2);
zassert_true(rc == 0, "_steq comparison failure");
zassert_is_null(next2, "_steq comparison next error");
/* first separator: return 2, next <> NULL */
rc = settings_name_next(test1, &next1);
zassert_true(rc == 2, "_next wrong return value");
zassert_not_null(next1, "_next wrong next");
zassert_equal_ptr(next1, test1+3, "next points to wrong location");
rc = settings_name_next(test2, &next2);
zassert_true(rc == 2, "_next wrong return value");
zassert_not_null(next2, "_next wrong next");
zassert_equal_ptr(next2, test2+3, "next points to wrong location");
/* second separator: return 1, next <> NULL */
rc = settings_name_next(next1, &next1);
zassert_true(rc == 1, "_next wrong return value");
zassert_not_null(next1, "_next wrong next");
zassert_equal_ptr(next1, test1+5, "next points to wrong location");
rc = settings_name_next(next2, &next2);
zassert_true(rc == 1, "_next wrong return value");
zassert_not_null(next2, "_next wrong next");
zassert_equal_ptr(next2, test2+5, "next points to wrong location");
/* third separator: return 1, next <> NULL */
rc = settings_name_next(next1, &next1);
zassert_true(rc == 1, "_next wrong return value");
zassert_not_null(next1, "_next wrong next");
rc = settings_name_next(next2, &next2);
zassert_true(rc == 1, "_next wrong return value");
zassert_not_null(next2, "_next wrong next");
/* fourth separator: return 1, next <> NULL */
rc = settings_name_next(next1, &next1);
zassert_true(rc == 1, "_next wrong return value");
zassert_not_null(next1, "_next wrong next");
rc = settings_name_next(next2, &next2);
zassert_true(rc == 1, "_next wrong return value");
zassert_not_null(next2, "_next wrong next");
/* fifth separator: return 1, next == NULL */
rc = settings_name_next(next1, &next1);
zassert_true(rc == 1, "_next wrong return value");
zassert_is_null(next1, "_next wrong next");
rc = settings_name_next(next2, &next2);
zassert_true(rc == 1, "_next wrong return value");
zassert_is_null(next2, "_next wrong next");
}
struct stored_data {
u8_t val1;
u8_t val2;
u8_t val3;
bool en1;
bool en2;
bool en3;
};
struct stored_data data;
int val1_set(const char *key, size_t len, settings_read_cb read_cb,
void *cb_arg)
{
data.val1 = 1;
return 0;
}
int val1_commit(void)
{
data.en1 = true;
return 0;
}
static struct settings_handler val1_settings = {
.name = "ps",
.h_set = val1_set,
.h_commit = val1_commit,
};
int val2_set(const char *key, size_t len, settings_read_cb read_cb,
void *cb_arg)
{
data.val2 = 2;
return 0;
}
int val2_commit(void)
{
data.en2 = true;
return 0;
}
static struct settings_handler val2_settings = {
.name = "ps/ss/ss",
.h_set = val2_set,
.h_commit = val2_commit,
};
int val3_set(const char *key, size_t len, settings_read_cb read_cb,
void *cb_arg)
{
data.val3 = 3;
return 0;
}
int val3_commit(void)
{
data.en3 = true;
return 0;
}
static struct settings_handler val3_settings = {
.name = "ps/ss",
.h_set = val3_set,
.h_commit = val3_commit,
};
/* helper routine to remove a handler from settings */
int settings_deregister(struct settings_handler *handler)
{
extern sys_slist_t settings_handlers;
return sys_slist_find_and_remove(&settings_handlers, &handler->node);
}
static void test_register_and_loading(void)
{
int rc, err;
u8_t val = 0;
rc = settings_subsys_init();
zassert_true(rc == 0, "subsys init failed");
settings_save_one("ps/ss/ss/val2", &val, sizeof(u8_t));
memset(&data, 0, sizeof(struct stored_data));
rc = settings_register(&val1_settings);
zassert_true(rc == 0, "register of val1 settings failed");
/* when we load settings now data.val1 should receive the value*/
rc = settings_load();
zassert_true(rc == 0, "settings_load failed");
err = (data.val1 == 1) && (data.val2 == 0) && (data.val3 == 0);
zassert_true(err, "wrong data value found");
/* commit is only called for val1_settings */
err = (data.en1) && (!data.en2) && (!data.en3);
zassert_true(err, "wrong data enable found");
/* Next register should be ok */
rc = settings_register(&val2_settings);
zassert_true(rc == 0, "register of val2 settings failed");
/* Next register should fail (same name) */
rc = settings_register(&val2_settings);
zassert_true(rc == -EEXIST, "double register of val2 settings allowed");
memset(&data, 0, sizeof(struct stored_data));
/* when we load settings now data.val2 should receive the value*/
rc = settings_load();
zassert_true(rc == 0, "settings_load failed");
err = (data.val1 == 0) && (data.val2 == 2) && (data.val3 == 0);
zassert_true(err, "wrong data value found");
/* commit is called for val1_settings and val2_settings*/
err = (data.en1) && (data.en2) && (!data.en3);
zassert_true(err, "wrong data enable found");
settings_save_one("ps/ss/val3", &val, sizeof(u8_t));
memset(&data, 0, sizeof(struct stored_data));
/* when we load settings now data.val2 and data.val1 should receive a
* value
*/
rc = settings_load();
zassert_true(rc == 0, "settings_load failed");
err = (data.val1 == 1) && (data.val2 == 2) && (data.val3 == 0);
zassert_true(err, "wrong data value found");
/* commit is called for val1_settings and val2_settings*/
err = (data.en1) && (data.en2) && (!data.en3);
zassert_true(err, "wrong data enable found");
/* val3 settings should be inserted in between val1_settings and
* val2_settings
*/
rc = settings_register(&val3_settings);
zassert_true(rc == 0, "register of val3 settings failed");
memset(&data, 0, sizeof(struct stored_data));
/* when we load settings now data.val2 and data.val3 should receive a
* value
*/
rc = settings_load();
zassert_true(rc == 0, "settings_load failed");
err = (data.val1 == 0) && (data.val2 == 2) && (data.val3 == 3);
zassert_true(err, "wrong data value found");
/* commit is called for val1_settings, val2_settings and val3_settings
*/
err = (data.en1) && (data.en2) && (data.en3);
zassert_true(err, "wrong data enable found");
settings_save_one("ps/val1", &val, sizeof(u8_t));
memset(&data, 0, sizeof(struct stored_data));
/* when we load settings all data should receive a value loaded */
rc = settings_load();
zassert_true(rc == 0, "settings_load failed");
err = (data.val1 == 1) && (data.val2 == 2) && (data.val3 == 3);
zassert_true(err, "wrong data value found");
/* commit is called for all settings*/
err = (data.en1) && (data.en2) && (data.en3);
zassert_true(err, "wrong data enable found");
memset(&data, 0, sizeof(struct stored_data));
/* test subtree loading: subtree "ps/ss" data.val2 and data.val3 should
* receive a value
*/
rc = settings_load_subtree("ps/ss");
zassert_true(rc == 0, "settings_load failed");
err = (data.val1 == 0) && (data.val2 == 2) && (data.val3 == 3);
zassert_true(err, "wrong data value found");
/* commit is called for val2_settings and val3_settings */
err = (!data.en1) && (data.en2) && (data.en3);
zassert_true(err, "wrong data enable found");
memset(&data, 0, sizeof(struct stored_data));
/* test subtree loading: subtree "ps/ss/ss" only data.val2 should
* receive a value
*/
rc = settings_load_subtree("ps/ss/ss");
zassert_true(rc == 0, "settings_load failed");
err = (data.val1 == 0) && (data.val2 == 2) && (data.val3 == 0);
zassert_true(err, "wrong data value found");
/* commit is called only for val2_settings */
err = (!data.en1) && (data.en2) && (!data.en3);
zassert_true(err, "wrong data enable found");
/* clean up by deregisterring settings_handler */
rc = settings_deregister(&val1_settings);
zassert_true(rc, "deregistering val1_settings failed");
rc = settings_deregister(&val2_settings);
zassert_true(rc, "deregistering val1_settings failed");
rc = settings_deregister(&val3_settings);
zassert_true(rc, "deregistering val1_settings failed");
}
void test_main(void)
{
ztest_test_suite(settings_test_suite,
ztest_unit_test(test_support_rtn),
ztest_unit_test(test_register_and_loading)
);
ztest_run_test_suite(settings_test_suite);
}

View file

@ -0,0 +1,4 @@
tests:
system.settings.fcb:
platform_whitelist: nrf52840_pca10056 nrf52_pca10040 native_posix
tags: settings_fcb

View file

@ -22,8 +22,8 @@ int test_export_block;
int c2_var_count = 1; int c2_var_count = 1;
int c1_handle_get(int argc, char **argv, char *val, int val_len_max); int c1_handle_get(const char *name, char *val, int val_len_max);
int c1_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb, int c1_handle_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg); void *cb_arg);
int c1_handle_commit(void); int c1_handle_commit(void);
int c1_handle_export(int (*cb)(const char *name, int c1_handle_export(int (*cb)(const char *name,
@ -41,23 +41,24 @@ struct settings_handler c_test_handlers[] = {
int c1_handle_get(int argc, char **argv, char *val, int val_len_max) int c1_handle_get(const char *name, char *val, int val_len_max)
{ {
test_get_called = 1; test_get_called = 1;
const char *next;
if (argc == 1 && !strcmp(argv[0], "mybar")) { if (settings_name_steq(name, "mybar", &next) && !next) {
val_len_max = MIN(val_len_max, sizeof(val8)); val_len_max = MIN(val_len_max, sizeof(val8));
memcpy(val, &val8, MIN(val_len_max, sizeof(val8))); memcpy(val, &val8, MIN(val_len_max, sizeof(val8)));
return val_len_max; return val_len_max;
} }
if (argc == 1 && !strcmp(argv[0], "mybar16")) { if (settings_name_steq(name, "mybar16", &next) && !next) {
val_len_max = MIN(val_len_max, sizeof(val16)); val_len_max = MIN(val_len_max, sizeof(val16));
memcpy(val, &val16, MIN(val_len_max, sizeof(val16))); memcpy(val, &val16, MIN(val_len_max, sizeof(val16)));
return val_len_max; return val_len_max;
} }
if (argc == 1 && !strcmp(argv[0], "mybar64")) { if (settings_name_steq(name, "mybar64", &next) && !next) {
val_len_max = MIN(val_len_max, sizeof(val64)); val_len_max = MIN(val_len_max, sizeof(val64));
memcpy(val, &val64, MIN(val_len_max, sizeof(val64))); memcpy(val, &val64, MIN(val_len_max, sizeof(val64)));
return val_len_max; return val_len_max;
@ -66,14 +67,15 @@ int c1_handle_get(int argc, char **argv, char *val, int val_len_max)
return -ENOENT; return -ENOENT;
} }
int c1_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb, int c1_handle_set(const char *name, size_t len, settings_read_cb read_cb,
void *cb_arg) void *cb_arg)
{ {
int rc; int rc;
const char *next;
size_t val_len; size_t val_len;
test_set_called = 1; test_set_called = 1;
if (argc == 1 && !strcmp(argv[0], "mybar")) { if (settings_name_steq(name, "mybar", &next) && !next) {
val_len = len; val_len = len;
zassert_true(val_len == 1, "bad set-value size"); zassert_true(val_len == 1, "bad set-value size");
@ -82,7 +84,7 @@ int c1_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb,
return 0; return 0;
} }
if (argc == 1 && !strcmp(argv[0], "mybar16")) { if (settings_name_steq(name, "mybar16", &next) && !next) {
val_len = len; val_len = len;
zassert_true(val_len == 2, "bad set-value size"); zassert_true(val_len == 2, "bad set-value size");
@ -91,7 +93,7 @@ int c1_handle_set(int argc, char **argv, size_t len, settings_read_cb read_cb,
return 0; return 0;
} }
if (argc == 1 && !strcmp(argv[0], "mybar64")) { if (settings_name_steq(name, "mybar64", &next) && !next) {
val_len = len; val_len = len;
zassert_true(val_len == 8, "bad set-value size"); zassert_true(val_len == 8, "bad set-value size");