From 6aa217ae0ce743984343fb71953cc0ffabafb3d2 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 19:36:14 +0200 Subject: [PATCH 001/117] sys: add runtime configuration registry --- makefiles/pseudomodules.inc.mk | 2 + sys/Kconfig | 1 + sys/Makefile | 3 + sys/Makefile.dep | 4 + sys/include/registry.h | 532 ++++++++++++++++++++++++++++ sys/include/registry/error.h | 45 +++ sys/include/registry/util.h | 65 ++++ sys/registry/Kconfig | 33 ++ sys/registry/Makefile | 5 + sys/registry/Makefile.dep | 6 + sys/registry/init.c | 51 +++ sys/registry/registry.c | 622 +++++++++++++++++++++++++++++++++ sys/registry/util.c | 299 ++++++++++++++++ 13 files changed, 1668 insertions(+) create mode 100644 sys/include/registry.h create mode 100644 sys/include/registry/error.h create mode 100644 sys/include/registry/util.h create mode 100644 sys/registry/Kconfig create mode 100644 sys/registry/Makefile create mode 100644 sys/registry/Makefile.dep create mode 100644 sys/registry/init.c create mode 100644 sys/registry/registry.c create mode 100644 sys/registry/util.c diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 1c5ea3dab46a..e27a3c81209c 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -396,6 +396,8 @@ PSEUDOMODULES += fortuna_reseed ## will be removed after 2023.07 release. PSEUDOMODULES += random_cmd ## @} +PSEUDOMODULES += registry_% + PSEUDOMODULES += riotboot_% PSEUDOMODULES += rtt_cmd PSEUDOMODULES += saul_adc diff --git a/sys/Kconfig b/sys/Kconfig index fc1153603656..6400945cecd0 100644 --- a/sys/Kconfig +++ b/sys/Kconfig @@ -94,6 +94,7 @@ rsource "preprocessor/Kconfig" rsource "progress_bar/Kconfig" rsource "ps/Kconfig" rsource "random/Kconfig" +rsource "registry/Kconfig" rsource "rtc_utils/Kconfig" rsource "rust_riotmodules/Kconfig" rsource "saul_reg/Kconfig" diff --git a/sys/Makefile b/sys/Makefile index b7724719a709..abbcdea6c2ae 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -125,6 +125,9 @@ endif ifneq (,$(filter netutils,$(USEMODULE))) DIRS += net/netutils endif +ifneq (,$(filter registry,$(USEMODULE))) + DIRS += registry +endif ifneq (,$(filter sema,$(USEMODULE))) DIRS += sema endif diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 3edf021097c2..77c36dcdebd5 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -694,4 +694,8 @@ ifneq (,$(filter auto_init%,$(USEMODULE))) USEMODULE += preprocessor_successor endif +ifneq (,$(filter registry%,$(USEMODULE))) + include $(RIOTBASE)/sys/registry/Makefile.dep +endif + include $(RIOTBASE)/sys/test_utils/Makefile.dep diff --git a/sys/include/registry.h b/sys/include/registry.h new file mode 100644 index 000000000000..d8576ca87919 --- /dev/null +++ b/sys/include/registry.h @@ -0,0 +1,532 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry RIOT Registry + * @ingroup sys + * @brief RIOT Registry module for handling runtime configurations + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_H +#define REGISTRY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include "clist.h" +#include "xfa.h" +#include "modules.h" + +typedef uint8_t registry_namespace_id_t; +typedef uint32_t registry_schema_id_t; +typedef uint16_t registry_instance_id_t; +typedef uint16_t registry_group_or_parameter_id_t; +typedef registry_group_or_parameter_id_t registry_group_id_t; +typedef registry_group_or_parameter_id_t registry_parameter_id_t; + +typedef struct _registry_namespace_t registry_namespace_t; +typedef struct _registry_schema_t registry_schema_t; +typedef struct _registry_instance_t registry_instance_t; +typedef struct _registry_group_t registry_group_t; +typedef struct _registry_parameter_t registry_parameter_t; + +/** + * @brief Data types of the registry. + */ +typedef enum { + REGISTRY_TYPE_NONE = 0, /**< No type specified */ + + REGISTRY_TYPE_OPAQUE, /**< OPAQUE. */ + REGISTRY_TYPE_STRING, /**< String. */ + REGISTRY_TYPE_BOOL, /**< Boolean. */ + + REGISTRY_TYPE_UINT8, /**< 8-bits unsigned integer. */ + REGISTRY_TYPE_UINT16, /**< 16-bits unsigned integer. */ + REGISTRY_TYPE_UINT32, /**< 32-bits unsigned integer. */ + REGISTRY_TYPE_UINT64, /**< 64-bits unsigned integer. */ + + REGISTRY_TYPE_INT8, /**< 8-bits signed integer. */ + REGISTRY_TYPE_INT16, /**< 16-bits signed integer. */ + REGISTRY_TYPE_INT32, /**< 32-bits signed integer. */ + REGISTRY_TYPE_INT64, /**< 64-bits signed integer. */ + + REGISTRY_TYPE_FLOAT32, /**< 32-bits float. */ + REGISTRY_TYPE_FLOAT64, /**< 64-bits float. */ +} registry_type_t; + +/** + * @brief Basic representation of a configuration parameter value. + */ +typedef struct { + registry_type_t type; /**< The type of the configuration parameter value. */ + const void *buf; /**< Pointer to the buffer containing the value of the configuration parameter. */ + size_t buf_len; /**< Length of the buffer. */ +} registry_value_t; + +typedef const enum { + REGISTRY_COMMIT_INSTANCE, + REGISTRY_COMMIT_GROUP, + REGISTRY_COMMIT_PARAMETER, +} registry_commit_cb_scope_t; + +/** + * @brief Callback must be implemented by modules / drivers that integrate a configuration schema. + * This callback is called when the registry notifies the module / driver, that a configuration + * parameter has changed. + * + * @param[in] scope Scope of what will be committed (a parameter, a group or the whole instance). + * @param[in] id ID of the group or parameter to commit changes to, commits the whole instance on NULL. + * @param[in] context Context of the instance. + * + * @return 0 on success, non-zero on failure. + */ +typedef int (*registry_commit_cb_t)(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context); + +/** + * @brief Instance of a schema containing its data. + */ +struct _registry_instance_t { + clist_node_t node; /**< Linked list node. */ + const registry_instance_id_t id; /**< Integer representing the path id of the schema instance. */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + const char * const name; /**< String describing the instance. */ +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + const void * const data; /**< Struct containing all configuration parameters of the schema. */ + const registry_schema_t *schema; /**< Configuration Schema that the Schema Instance belongs to. */ + registry_commit_cb_t commit_cb; /**< Will be called after @ref registry_commit() was called on this instance. */ + + void *context; /**< Optional context used by the instance */ +}; + + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES(_type) \ + const _type *allowed_values; \ + size_t allowed_values_len; +#else + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES(_type) +#endif /* _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES */ + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES(_type) \ + const _type *forbidden_values; \ + size_t forbidden_values_len; +#else + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES(_type) +#endif /* _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES */ + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MIN_VALUE(_type) \ + const _type *min_value; +#else + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MIN_VALUE(_type) +#endif /* _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MIN_VALUE */ + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MAX_VALUE(_type) \ + const _type *max_value; +#else + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MAX_VALUE(_type) +#endif /* _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MAX_VALUE */ + +#define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_STRUCT(_name, _body) \ + typedef struct { \ + _body \ + } registry_parameter_constraints_ ## _name ## _t; + +#define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE(_name) \ + typedef void *registry_parameter_constraints_ ## _name ## _t; + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN(_name, _type) \ + _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_STRUCT( \ + _name, \ + _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES(_type) \ + _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES(_type) \ + ) +#else + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN(_name, _type) +#endif + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) +#define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(_name, _type) \ + _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_STRUCT( \ + _name, \ + _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES(_type) \ + _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES(_type) \ + _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MIN_VALUE(_type) \ + _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MAX_VALUE(_type) \ + ) +#else + #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(_name, _type) +#endif + +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN(opaque, void *) +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN(string, char *) + +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE(bool) + +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(uint8, uint8_t) +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(uint16, uint16_t) +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(uint32, uint32_t) +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(uint64, uint64_t) + +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(int8, int8_t) +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(int16, int16_t) +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(int32, int32_t) +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(int64, int64_t) + +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(float32, float) +_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(float64, double) + + +struct _registry_group_t { + const registry_group_id_t id; /**< Integer representing the ID of the configuration group. */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + const char * const name; /**< String describing the configuration group. */ +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + const char * const description; /**< String describing the configuration group with more details. */ +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + const registry_schema_t * const schema; /**< Configuration Schema that the configuration group belongs to. */ + const registry_group_t ** const groups; /**< Array of pointers to all the configuration groups that belong to this group. */ + const size_t groups_len; /**< Size of groups array. */ + const registry_parameter_t ** const parameters; /**< Array of pointers to all the configuration parameters that belong to this group. */ + const size_t parameters_len; /**< Size of parameters array. */ +}; + +struct _registry_parameter_t { + const registry_parameter_id_t id; /**< Integer representing the ID of the configuration parameter. */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + const char * const name; /**< String describing the configuration parameter. */ +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + const char * const description; /**< String describing the configuration parameter with more details. */ +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + const registry_schema_t * const schema; /**< Configuration Schema that the configuration parameter belongs to. */ + const registry_type_t type; /**< Type of the configuration parameter. */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || \ + IS_ACTIVE(DOXYGEN) + const union { + const registry_parameter_constraints_opaque_t opaque; + const registry_parameter_constraints_string_t string; +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || \ + IS_ACTIVE(DOXYGEN) + const registry_parameter_constraints_bool_t boolean; + const registry_parameter_constraints_uint8_t uint8; + const registry_parameter_constraints_uint16_t uint16; + const registry_parameter_constraints_uint32_t uint32; + const registry_parameter_constraints_uint64_t uint64; + const registry_parameter_constraints_int8_t int8; + const registry_parameter_constraints_int16_t int16; + const registry_parameter_constraints_int32_t int32; + const registry_parameter_constraints_int64_t int64; + const registry_parameter_constraints_float32_t float32; + const registry_parameter_constraints_float64_t float64; +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK || CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + } constraints; /**< Constraints of the parameter value. */ +#endif \ + /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK || CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK || CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK || CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ +}; + +/** + * @brief Schema containing available configuration parameters. + */ +struct _registry_schema_t { + const registry_schema_id_t id; /**< Integer representing the ID of the schema. */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + const char * const name; /**< String describing the schema. */ +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + const char * const description; /**< String describing the schema with more details. */ +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + const registry_namespace_t * const namespace; /**< Configuration Namespace that the Configuration Schema belongs to. */ + clist_node_t instances; /**< Linked list of schema instances @ref registry_instance_t. */ + const registry_group_t ** const groups; /**< Array of pointers to all the configuration groups that belong to this schema. */ + const size_t groups_len; /**< Size of groups array. */ + const registry_parameter_t ** const parameters; /**< Array of pointers to all the configuration parameters that belong to this schema. */ + const size_t parameters_len; /**< Size of parameters array. */ + + /** + * @brief Mapping to connect configuration parameter IDs with the address in the storage. + * + * @param[in] parameter_id ID of the parameter that contains the value. + * @param[in] instance Pointer to the instance of the schema, that contains the parameter. + * @param[in] val Pointer to buffer containing the new value. + * @param[in] val_len Pointer to length of the buffer to store the current value. + */ + void(*const mapping)(const registry_parameter_id_t parameter_id, + const registry_instance_t *instance, + void **val, + size_t *val_len); +}; + +struct _registry_namespace_t { + const registry_namespace_id_t id; /**< Integer representing the ID of the namespace. */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + const char * const name; /**< String describing the configuration namespace. */ +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + const char * const description; /**< String describing the configuration namespace with more details. */ +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + const registry_schema_t ** const schemas; /**< Array of pointers to all the configuration schemas that belong to this namespace. */ + const size_t schemas_len; /**< Size of schemas array. */ +}; + +#define REGISTRY_ADD_NAMESPACE(_name, _namespace) \ + XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); \ + XFA_ADD_PTR(_registry_namespaces_xfa, _name, _name, &_namespace) + +/** + * @brief Initializes the RIOT Registry. + */ +void registry_init(void); + +/** + * @brief Adds a new instance to a schema. + * + * @param[in] schema Pointer to the schema. + * @param[in] instance Pointer to the new instance. + * + * @return 0 on success, non-zero on failure. + */ +int registry_add_schema_instance(const registry_schema_t *schema, + const registry_instance_t *instance); + +/** + * @brief Gets the current value of a parameter that belongs to an instance + * of a configuration schema. + * + * @param[in] instance Pointer to the configuration schema instance. + * @param[in] parameter Pointer to the configuration parameter. + * @param[out] value Pointer to a uninitialized @ref registry_value_t struct. + * + * @return 0 on success, non-zero on failure. + */ +int registry_get(const registry_instance_t *instance, const registry_parameter_t *parameter, + registry_value_t *value); + +/** + * @brief Sets the value of a configuration parameter that belongs to an instance + * of a configuration schema. + * + * @param[in] instance Pointer to the configuration schema instance. + * @param[in] parameter Pointer to the configuration parameter. + * @param[in] buf Pointer to the new value for the configuration parameter. + * @param[in] buf_len Length of the buffer. + * + * @return 0 on success, non-zero on failure. + */ +int registry_set(const registry_instance_t *instance, const registry_parameter_t *parameter, + const void *buf, const size_t buf_len); + +/** + * @brief Commits every configuration parameter. + * + * @return 0 on success, non-zero on failure. + */ +int registry_commit(void); + +/** + * @brief Commits every configuration parameter within the given configuration namespace. + * + * @param[in] namespace Pointer to the configuration namespace. + * + * @return 0 on success, non-zero on failure. + */ +int registry_commit_namespace(const registry_namespace_t *namespace); + +/** + * @brief Commits every configuration parameter within the given configuration schema. + * + * @param[in] schema Pointer to the configuration schema. + * + * @return 0 on success, non-zero on failure. + */ +int registry_commit_schema(const registry_schema_t *schema); + +/** + * @brief Commits every configuration parameter within the given configuration schema instance. + * + * @param[in] instance Pointer to the configuration schema instance. + * + * @return 0 on success, non-zero on failure. + */ +int registry_commit_instance(const registry_instance_t *instance); + +/** + * @brief Commits every configuration parameter within the given configuration group. + * + * @param[in] instance Pointer to the configuration schema instance of the configuration group. + * @param[in] group Pointer to the configuration group. + * + * @return 0 on success, non-zero on failure. + */ +int registry_commit_group(const registry_instance_t *instance, const registry_group_t *group); + +/** + * @brief Commits the given configuration parameter. + * + * @param[in] instance Pointer to the configuration schema instance of the configuration parameter. + * @param[in] parameter Pointer to the configuration parameter. + * + * @return 0 on success, non-zero on failure. + */ +int registry_commit_parameter(const registry_instance_t *instance, + const registry_parameter_t *parameter); + +typedef const union { + const registry_namespace_t *namespace; + const registry_schema_t *schema; + const registry_instance_t *instance; + const registry_group_t *group; + const struct { + const registry_parameter_t *data; + const registry_instance_t *instance; + } parameter; +} registry_export_cb_data_t; + +typedef const enum { + REGISTRY_EXPORT_NAMESPACE, + REGISTRY_EXPORT_SCHEMA, + REGISTRY_EXPORT_INSTANCE, + REGISTRY_EXPORT_GROUP, + REGISTRY_EXPORT_PARAMETER, +} registry_export_cb_data_type_t; + +typedef int (*registry_export_cb_t)(const registry_export_cb_data_t *data, + const registry_export_cb_data_type_t data_type, + const void *context); + +#define REGISTRY_EXPORT_ALL = 0; +#define REGISTRY_EXPORT_SELF = 1; +#define REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(_n) (_n + 1); + +/** + * @brief Exports every configuration parameter. + * + * @param[in] export_cb Exporting callback function will be called for each namespace, + * schema, instance, group and parameter that are in scope. + * @param[in] recursion_depth Defines how deeply nested child groups / parameters + * will be shown. (0 to show all children, 1 to only show the exact match, n > 1 + * to show the exact match plus n - 1 levels of children). + * @param[in] context Context that will be passed to @p export_cb. + * + * @return 0 on success, non-zero on failure. + */ +int registry_export(const registry_export_cb_t export_cb, + const uint8_t recursion_depth, const void *context); + +/** + * @brief Exports every configuration parameter within the given configuration namespace. + * + * @param[in] namespace Pointer to the configuration namespace. + * @param[in] export_cb Exporting callback function will be called for the given namespace + * and each of its schemas, instances, groups and parameters that are in scope. + * @param[in] recursion_depth Defines how deeply nested child groups / parameters + * will be shown. (0 to show all children, 1 to only show the exact match, 2 - n + * to show the exact match plus its children ... plus n levels of children). + * @param[in] context Context that will be passed to @p export_cb. + * + * @return 0 on success, non-zero on failure. + */ +int registry_export_namespace(const registry_namespace_t *namespace, + const registry_export_cb_t export_cb, const uint8_t recursion_depth, + const void *context); + +/** + * @brief Exports every configuration parameter within the given configuration schema. + * + * @param[in] schema Pointer to the configuration schema. + * @param[in] export_cb Exporting callback function will be called for the given schema + * and each of its instances, groups and parameters that are in scope. + * @param[in] recursion_depth Defines how deeply nested child groups / parameters + * will be shown. (0 to show all children, 1 to only show the exact match, 2 - n + * to show the exact match plus its children ... plus n levels of children). + * @param[in] context Context that will be passed to @p export_cb. + * + * @return 0 on success, non-zero on failure. + */ +int registry_export_schema(const registry_schema_t *schema, const registry_export_cb_t export_cb, + const uint8_t recursion_depth, const void *context); + +/** + * @brief Exports every configuration parameter within the given configuration schema instance. + * + * @param[in] instance Pointer to the configuration schema instance. + * @param[in] export_cb Exporting callback function will be called for the given instance + * and each of its groups and parameters that are in scope. + * @param[in] recursion_depth Defines how deeply nested child groups / parameters + * will be shown. (0 to show all children, 1 to only show the exact match, 2 - n + * to show the exact match plus its children ... plus n levels of children). + * @param[in] context Context that will be passed to @p export_cb. + * + * @return 0 on success, non-zero on failure. + */ +int registry_export_instance(const registry_instance_t *instance, + const registry_export_cb_t export_cb, const uint8_t recursion_depth, + const void *context); + +/** + * @brief Exports every configuration parameter within the given configuration group. + * + * @param[in] instance Pointer to the configuration schema instance. + * @param[in] group Pointer to the configuration group. + * @param[in] export_cb Exporting callback function will be called for the given group + * and each of its subgroups and parameters that are in scope. + * @param[in] recursion_depth Defines how deeply nested child groups / parameters + * will be shown. (0 to show all children, 1 to only show the exact match, 2 - n + * to show the exact match plus its children ... plus n levels of children). + * @param[in] context Context that will be passed to @p export_cb. + * + * @return 0 on success, non-zero on failure. + */ +int registry_export_group(const registry_instance_t *instance, const registry_group_t *group, + const registry_export_cb_t export_cb, const uint8_t recursion_depth, + const void *context); + +/** + * @brief Exports the given configuration parameter. + * + * @param[in] instance Pointer to the configuration schema instance. + * @param[in] parameter Pointer to the configuration parameter. + * @param[in] export_cb Exporting callback function will be called for the given parameter. + * @param[in] context Context that will be passed to @p export_cb. + * + * @return 0 on success, non-zero on failure. + */ +int registry_export_parameter(const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_export_cb_t export_cb, const void *context); + + + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_H */ +/** @} */ diff --git a/sys/include/registry/error.h b/sys/include/registry/error.h new file mode 100644 index 000000000000..970550d431d4 --- /dev/null +++ b/sys/include/registry/error.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_error RIOT Registry Error + * @ingroup sys + * @brief RIOT Registry module providing all possible registry specific error codes + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_ERROR_H +#define REGISTRY_ERROR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Error codes start at 1_000 to prevent clashing with stdlib error codes. + */ +typedef const enum { + REGISTRY_ERROR_NONE = 1000, + REGISTRY_ERROR_NO_DST_STORAGE, + REGISTRY_ERROR_NAMESPACE_NOT_FOUND, + REGISTRY_ERROR_SCHEMA_NOT_FOUND, + REGISTRY_ERROR_INSTANCE_NOT_FOUND, + REGISTRY_ERROR_GROUP_NOT_FOUND, + REGISTRY_ERROR_PARAMETER_NOT_FOUND, +} registry_error_t; + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_ERROR_H */ +/** @} */ diff --git a/sys/include/registry/util.h b/sys/include/registry/util.h new file mode 100644 index 000000000000..035278aad4e0 --- /dev/null +++ b/sys/include/registry/util.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_util RIOT Registry utilities + * @ingroup sys + * @brief RIOT Registry Util module providing utility functions + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#ifndef REGISTRY_UTIL_H +#define REGISTRY_UTIL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +void _debug_print_value(const registry_value_t *value); + +/** + * @brief Convenience function to parse a configuration parameter value from + * a string. + * + * @param[in] src Pointer of the input value. + * @param[out] dest Pointer to the output buffer. + * @param[in] dest_len Length of @p dest. + * @param[in] dest_type Type of the output value. + * + * @return 0 on success, non-zero on failure. + */ +int registry_util_convert_str_to_value(const char *src, void *dest, const size_t dest_len, + const registry_type_t dest_type); + +/** + * @brief Convenience function to transform a configuration parameter value into + * its representation as a string. + * + * @param[in] src Pointer to the value to be converted. + * @param[out] dest Buffer to store the output string. + * @param[in] dest_len Length of @p buf. + * + * @return Length of string value on success, non-zero on failure. + */ +int registry_util_convert_value_to_str(const registry_value_t *src, char *dest, + const size_t dest_len); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* REGISTRY_UTIL_H */ diff --git a/sys/registry/Kconfig b/sys/registry/Kconfig new file mode 100644 index 000000000000..18c13b6d9ac0 --- /dev/null +++ b/sys/registry/Kconfig @@ -0,0 +1,33 @@ +# Copyright (c) 2023 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +menuconfig MODULE_REGISTRY + bool "REGISTRY" + help + RIOT Registry module for handling runtime configurations. + +if MODULE_REGISTRY + +config REGISTRY_ENABLE_META_NAME + bool "Include name string in schemas" + +config REGISTRY_ENABLE_META_DESCRIPTION + bool "Include description string in schemas" + +config REGISTRY_ENABLE_ALLOWED_VALUES_CHECK + bool "Check if new values are allowed" + +config REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK + bool "Check if new values are forbidden" + +config REGISTRY_ENABLE_MIN_VALUE_CHECK + bool "Check if new value does not exceed minimum" + +config REGISTRY_ENABLE_MAX_VALUE_CHECK + bool "Check if new value does not exceed maximum" + +endif # MODULE_REGISTRY \ No newline at end of file diff --git a/sys/registry/Makefile b/sys/registry/Makefile new file mode 100644 index 000000000000..6f17dec2f0f4 --- /dev/null +++ b/sys/registry/Makefile @@ -0,0 +1,5 @@ +SRC := registry.c util.c init.c + +SUBMODULES := 1 + +include $(RIOTBASE)/Makefile.base diff --git a/sys/registry/Makefile.dep b/sys/registry/Makefile.dep new file mode 100644 index 000000000000..5fd516719057 --- /dev/null +++ b/sys/registry/Makefile.dep @@ -0,0 +1,6 @@ +ifneq (,$(filter registry_%,$(USEMODULE))) + USEMODULE += registry +endif + +USEMODULE += fmt +USEMODULE += base64 \ No newline at end of file diff --git a/sys/registry/init.c b/sys/registry/init.c new file mode 100644 index 000000000000..bbcc0039eb47 --- /dev/null +++ b/sys/registry/init.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_init RIOT Registry initialization + * @ingroup sys + * @brief RIOT Registry Init module providing init functions + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" + +#include "registry.h" + +#include "auto_init_utils.h" +#if IS_USED(MODULE_AUTO_INIT) +#endif + +XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); + +void registry_init(void) +{ + /* set namespace_id to its index value */ + for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { + registry_namespace_t *namespace = _registry_namespaces_xfa[i]; + + *(registry_namespace_id_t *)&namespace->id = i; + } +} + +AUTO_INIT(registry_init, 2000); diff --git a/sys/registry/registry.c b/sys/registry/registry.c new file mode 100644 index 000000000000..523cc1f010ec --- /dev/null +++ b/sys/registry/registry.c @@ -0,0 +1,622 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry RIOT Registry + * @ingroup module_registry + * @brief RIOT Registry for runtime configuration of modules + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "clist.h" + +#include "registry.h" +#include "registry/util.h" + +/* Implementation of the module */ + +XFA_INIT_CONST(registry_namespace_t *, _registry_namespaces_xfa); + +int registry_add_schema_instance(const registry_schema_t *schema, + const registry_instance_t *instance) +{ + assert(schema != NULL); + assert(instance != NULL); + + /* add schema to instance */ + (*((registry_instance_t *)instance)).schema = schema; + + /* get instances length to determine the id of the new instance */ + size_t count = clist_count((clist_node_t *)&schema->instances); + + /* set id of new instance to the instance count */ + *(registry_instance_id_t *)&instance->id = count; + + /* add instance to schema */ + clist_rpush((clist_node_t *)&schema->instances, (clist_node_t *)&instance->node); + + return 0; +} + +int registry_get(const registry_instance_t *instance, const registry_parameter_t *parameter, + registry_value_t *value) +{ + assert(instance != NULL); + assert(parameter != NULL); + assert(value != NULL); + + /* call handler to get pointer to registry internal value buffer and length */ + void *intern_val = NULL; + size_t intern_val_len; + + parameter->schema->mapping(parameter->id, instance, &intern_val, &intern_val_len); + + /* update buf pointer in registry_value_t to point to the value inside the registry and set buf_len */ + value->type = parameter->type; + value->buf = intern_val; + value->buf_len = intern_val_len; + + return 0; +} + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) +#define _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_ARRAY_TYPE(_passed_checks, \ + _type_field_name, \ + _parameter, _buf, \ + _buf_len) \ + if (_parameter->constraints._type_field_name.allowed_values_len > 0) { \ + _passed_checks = false; \ + if (_parameter->constraints._type_field_name.allowed_values_len == 0) { \ + _passed_checks = true; \ + } \ + for (size_t i = 0; i < _parameter->constraints._type_field_name.allowed_values_len; \ + i++) { \ + if (memcmp(_parameter->constraints._type_field_name.allowed_values[i], _buf, \ + _buf_len) == 0) { \ + _passed_checks = true; \ + } \ + } \ + if (!_passed_checks) { \ + return -EINVAL; \ + } \ + } +#else + #define _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_ARRAY_TYPE(_passed_checks, \ + _type_field_name, \ + _parameter, _buf, \ + _buf_len) +#endif + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) +#define _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_ARRAY_TYPE(_passed_checks, \ + _type_field_name, \ + _parameter, _buf, \ + _buf_len) \ + if (_parameter->constraints._type_field_name.forbidden_values_len > 0) { \ + _passed_checks = true; \ + for (size_t i = 0; i < _parameter->constraints._type_field_name.forbidden_values_len; \ + i++) { \ + if (memcmp(_parameter->constraints._type_field_name.forbidden_values[i], _buf, \ + _buf_len) == 0) { \ + _passed_checks = false; \ + } \ + } \ + if (!_passed_checks) { \ + return -EINVAL; \ + } \ + } +#else + #define _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_ARRAY_TYPE(_passed_checks, \ + _type_field_name, \ + _parameter, _buf, \ + _buf_len) +#endif + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) +#define _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ + _type_field_name, _parameter, \ + _buf) \ + if (_parameter->constraints._type_field_name.allowed_values_len > 0) { \ + _passed_checks = false; \ + if (_parameter->constraints._type_field_name.allowed_values_len == 0) { \ + _passed_checks = true; \ + } \ + for (size_t i = 0; i < _parameter->constraints._type_field_name.allowed_values_len; \ + i++) { \ + if (_parameter->constraints._type_field_name.allowed_values[i] == *(_type *)_buf) { \ + _passed_checks = true; \ + } \ + } \ + if (!_passed_checks) { \ + return -EINVAL; \ + } \ + } +#else + #define _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ + _type_field_name, \ + _parameter, _buf) +#endif + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) +#define _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ + _type_field_name, _parameter, \ + _buf) \ + if (_parameter->constraints._type_field_name.forbidden_values_len > 0) { \ + _passed_checks = true; \ + for (size_t i = 0; i < _parameter->constraints._type_field_name.forbidden_values_len; \ + i++) { \ + if (_parameter->constraints._type_field_name.forbidden_values[i] == \ + *(_type *)_buf) { \ + _passed_checks = false; \ + } \ + } \ + if (!_passed_checks) { \ + return -EINVAL; \ + } \ + } +#else + #define _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ + _type_field_name, \ + _parameter, _buf) +#endif + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) +#define _REGISTRY_CHECK_SET_CONSTRAINTS_MIN_VALUE_OF_VALUE_TYPE(_type, _type_field_name, _parameter, \ + _buf) \ + if (_parameter->constraints._type_field_name.min_value != NULL) { \ + if (*(_type *)_buf < *_parameter->constraints._type_field_name.min_value) { \ + return -EINVAL; \ + } \ + } +#else + #define _REGISTRY_CHECK_SET_CONSTRAINTS_MIN_VALUE_OF_VALUE_TYPE(_type, _type_field_name, \ + _parameter, _buf) +#endif + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) +#define _REGISTRY_CHECK_SET_CONSTRAINTS_MAX_VALUE_OF_VALUE_TYPE(_type, _type_field_name, _parameter, \ + _buf) \ + if (_parameter->constraints._type_field_name.max_value != NULL) { \ + if (*(_type *)_buf > *_parameter->constraints._type_field_name.max_value) { \ + return -EINVAL; \ + } \ + } +#else + #define _REGISTRY_CHECK_SET_CONSTRAINTS_MAX_VALUE_OF_VALUE_TYPE(_type, _type_field_name, \ + _parameter, _buf) +#endif + +#define _REGISTRY_CHECK_SET_CONSTRAINTS_OF_ARRAY_TYPE(_passed_checks, _type_field_name, _parameter, \ + _buf, _buf_len) \ + (void)_passed_checks; \ + _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_ARRAY_TYPE(_passed_checks, \ + _type_field_name, \ + _parameter, _buf, \ + _buf_len) \ + _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_ARRAY_TYPE(_passed_checks, \ + _type_field_name, \ + _parameter, _buf, \ + _buf_len) + +#define _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(_passed_checks, _type, _type_field_name, \ + _parameter, _buf) \ + (void)_passed_checks; \ + _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ + _type_field_name, \ + _parameter, _buf) \ + _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ + _type_field_name, \ + _parameter, _buf) \ + _REGISTRY_CHECK_SET_CONSTRAINTS_MIN_VALUE_OF_VALUE_TYPE(_type, _type_field_name, _parameter, \ + _buf) \ + _REGISTRY_CHECK_SET_CONSTRAINTS_MAX_VALUE_OF_VALUE_TYPE(_type, _type_field_name, _parameter, \ + _buf) + +int registry_set(const registry_instance_t *instance, const registry_parameter_t *parameter, + const void *buf, const size_t buf_len) +{ + assert(instance != NULL); + assert(parameter != NULL); + assert(buf != NULL); + + /* get pointer to registry internal value buffer and length */ + void *intern_val = NULL; + size_t intern_val_len; + + parameter->schema->mapping(parameter->id, instance, &intern_val, &intern_val_len); + + if (buf_len > intern_val_len) { + return -EINVAL; + } + + if (IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK)) { + + bool passed_checks = true; + switch (parameter->type) { + case REGISTRY_TYPE_NONE: + break; + + case REGISTRY_TYPE_OPAQUE: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_ARRAY_TYPE(passed_checks, opaque, parameter, buf, + buf_len) + break; + + case REGISTRY_TYPE_STRING: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_ARRAY_TYPE(passed_checks, string, parameter, buf, + buf_len) + break; + + case REGISTRY_TYPE_BOOL: + /* the boolean data type has no constraints*/ + break; + + case REGISTRY_TYPE_UINT8: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, uint8_t, uint8, parameter, + buf) + break; + + case REGISTRY_TYPE_UINT16: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, uint16_t, uint16, + parameter, + buf) + break; + + case REGISTRY_TYPE_UINT32: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, uint32_t, uint32, + parameter, + buf) + break; + + case REGISTRY_TYPE_UINT64: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, uint64_t, uint64, + parameter, + buf) + break; + + case REGISTRY_TYPE_INT8: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, int8_t, int8, parameter, + buf) + break; + + case REGISTRY_TYPE_INT16: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, int16_t, int16, parameter, + buf) + break; + + case REGISTRY_TYPE_INT32: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, int32_t, int32, parameter, + buf) + break; + + case REGISTRY_TYPE_INT64: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, int64_t, int64, parameter, + buf) + break; + + case REGISTRY_TYPE_FLOAT32: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, float, float32, parameter, + buf) + break; + + case REGISTRY_TYPE_FLOAT64: + _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, double, float64, parameter, + buf) + break; + } + } + + /* call handler to apply the new value to the correct parameter in the instance of the schema */ + memcpy(intern_val, buf, buf_len); + + return 0; +} + +int registry_commit(void) +{ + int rc = 0; + + /* commit all namespaces */ + for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { + registry_namespace_t *namespace = _registry_namespaces_xfa[i]; + + int _rc = registry_commit_namespace(namespace); + + if (!_rc) { + rc = _rc; + } + } + + return rc; +} + +int registry_commit_namespace(const registry_namespace_t *namespace) +{ + assert(namespace != NULL); + + int rc = 0; + + /* commit all configuration schemas of the given namespace if available */ + for (size_t i = 0; i < namespace->schemas_len; i++) { + const registry_schema_t *child = namespace->schemas[i]; + + int _rc = registry_commit_schema(child); + + if (!_rc) { + rc = _rc; + } + } + + return rc; +} + +int registry_commit_schema(const registry_schema_t *schema) +{ + assert(schema != NULL); + + int rc = 0; + + /* commit all configuration schema instances of the given configuration schema if available */ + clist_node_t *node = schema->instances.next; + + if (!node) { + return -EINVAL; + } + + do { + node = node->next; + registry_instance_t *instance = container_of(node, registry_instance_t, node); + + if (!instance) { + return -EINVAL; + } + + int _rc = registry_commit_instance(instance); + + if (!_rc) { + rc = _rc; + } + } while (node != schema->instances.next); + + return rc; +} + +int registry_commit_instance(const registry_instance_t *instance) +{ + return instance->commit_cb(REGISTRY_COMMIT_INSTANCE, NULL, instance->context); +} + +int registry_commit_group(const registry_instance_t *instance, const registry_group_t *group) +{ + return instance->commit_cb(REGISTRY_COMMIT_GROUP, &group->id, instance->context); +} + +int registry_commit_parameter(const registry_instance_t *instance, + const registry_parameter_t *parameter) +{ + return instance->commit_cb(REGISTRY_COMMIT_PARAMETER, ¶meter->id, instance->context); +} + +int registry_export(const registry_export_cb_t export_cb, const uint8_t recursion_depth, + const void *context) +{ + int rc = 0; + + /* export all namespaces */ + for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { + registry_namespace_t *namespace = _registry_namespaces_xfa[i]; + + int _rc = registry_export_namespace(namespace, export_cb, recursion_depth, context); + + if (!_rc) { + rc = _rc; + } + } + + return rc; +} + +int registry_export_namespace(const registry_namespace_t *namespace, + const registry_export_cb_t export_cb, const uint8_t recursion_depth, + const void *context) +{ + assert(namespace != NULL); + + /* export the given namespace */ + registry_export_cb_data_t export_data = { .namespace = namespace }; + int rc = export_cb(&export_data, REGISTRY_EXPORT_NAMESPACE, context); + + /* export all configuration schemas of the given namespace if available and within recursion_depth bounds */ + if (recursion_depth == 1) { + return 0; + } + else { + int new_recursion_depth = recursion_depth; + if (recursion_depth > 1) { + new_recursion_depth--; + } + + for (size_t i = 0; i < namespace->schemas_len; i++) { + const registry_schema_t *child = namespace->schemas[i]; + + int _rc = registry_export_schema(child, export_cb, new_recursion_depth, context); + + if (!_rc) { + rc = _rc; + } + } + } + + return rc; +} + +int registry_export_schema(const registry_schema_t *schema, const registry_export_cb_t export_cb, + const uint8_t recursion_depth, const void *context) +{ + assert(schema != NULL); + + /* export the given configuration schema */ + registry_export_cb_data_t export_data = { .schema = schema }; + int rc = export_cb(&export_data, REGISTRY_EXPORT_SCHEMA, context); + + /* export all instances of the given configuration schema if available and within recursion_depth bounds */ + if (recursion_depth == 1) { + return 0; + } + else { + int new_recursion_depth = recursion_depth; + if (recursion_depth > 1) { + new_recursion_depth--; + } + + clist_node_t *node = schema->instances.next; + + if (!node) { + return -EINVAL; + } + + do { + node = node->next; + registry_instance_t *instance = container_of(node, registry_instance_t, node); + + if (!instance) { + return -EINVAL; + } + + int _rc = registry_export_instance(instance, export_cb, new_recursion_depth, context); + + if (!_rc) { + rc = _rc; + } + } while (node != schema->instances.next); + } + + return rc; +} + +int registry_export_instance(const registry_instance_t *instance, + const registry_export_cb_t export_cb, const uint8_t recursion_depth, + const void *context) +{ + assert(instance != NULL); + + /* export the given configuration schema instance */ + registry_export_cb_data_t export_data = { .instance = instance }; + int rc = export_cb(&export_data, REGISTRY_EXPORT_INSTANCE, context); + + /* export all groups or parameters of the given configuration schema instance if available and within recursion_depth bounds */ + if (recursion_depth == 1) { + return 0; + } + else { + int new_recursion_depth = recursion_depth; + if (recursion_depth > 1) { + new_recursion_depth--; + } + + int _rc = rc; + + /* groups */ + for (size_t i = 0; i < instance->schema->groups_len; i++) { + _rc = registry_export_group(instance, instance->schema->groups[i], export_cb, + new_recursion_depth, context); + + if (!_rc) { + rc = _rc; + } + } + + /* parameters */ + for (size_t i = 0; i < instance->schema->parameters_len; i++) { + _rc = registry_export_parameter(instance, instance->schema->parameters[i], export_cb, + context); + + if (!_rc) { + rc = _rc; + } + } + } + + return rc; +} + +int registry_export_group(const registry_instance_t *instance, const registry_group_t *group, + const registry_export_cb_t export_cb, + const uint8_t recursion_depth, const void *context) +{ + assert(group != NULL); + + /* export the given configuration group */ + registry_export_cb_data_t export_data = { .group = group }; + int rc = export_cb(&export_data, REGISTRY_EXPORT_GROUP, context); + + /* export all children of the given configuration group if available and within recursion_depth bounds */ + if (recursion_depth == 1) { + return 0; + } + else { + int new_recursion_depth = recursion_depth; + if (recursion_depth > 1) { + new_recursion_depth--; + } + + int _rc = rc; + + /* group */ + for (size_t i = 0; i < group->groups_len; i++) { + _rc = registry_export_group(instance, group->groups[i], export_cb, new_recursion_depth, + context); + + if (!_rc) { + rc = _rc; + } + } + + /* parameter */ + for (size_t i = 0; i < group->parameters_len; i++) { + _rc = registry_export_parameter(instance, group->parameters[i], export_cb, context); + + if (!_rc) { + rc = _rc; + } + } + } + + return rc; +} + +int registry_export_parameter(const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_export_cb_t export_cb, const void *context) +{ + assert(parameter != NULL); + + registry_export_cb_data_t export_data = { + .parameter = { + .data = parameter, + .instance = instance, + } + }; + return export_cb(&export_data, REGISTRY_EXPORT_PARAMETER, context); +} diff --git a/sys/registry/util.c b/sys/registry/util.c new file mode 100644 index 000000000000..10892d4d8d91 --- /dev/null +++ b/sys/registry/util.c @@ -0,0 +1,299 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_util RIOT Registry utilities + * @ingroup sys + * @brief RIOT Registry Util module providing utility functions + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "base64.h" +#include "kernel_defines.h" + +#include "registry.h" +#include "registry/util.h" +#include "fmt.h" + +void _debug_print_value(const registry_value_t *value) +{ + if (ENABLE_DEBUG) { + switch (value->type) { + case REGISTRY_TYPE_NONE: break; + case REGISTRY_TYPE_OPAQUE: { + DEBUG("opaque (hex): "); + for (size_t i = 0; i < value->buf_len; i++) { + DEBUG("%02x", ((uint8_t *)value->buf)[i]); + } + break; + } + case REGISTRY_TYPE_STRING: DEBUG("string: %s", (char *)value->buf); break; + case REGISTRY_TYPE_BOOL: DEBUG("bool: %d", *(bool *)value->buf); break; + + case REGISTRY_TYPE_UINT8: DEBUG("uint8: %d", *(uint8_t *)value->buf); break; + case REGISTRY_TYPE_UINT16: DEBUG("uint16: %d", *(uint16_t *)value->buf); break; + case REGISTRY_TYPE_UINT32: DEBUG("uint32: %d", *(uint32_t *)value->buf); break; + case REGISTRY_TYPE_UINT64: DEBUG("uint64: %lld", *(uint64_t *)value->buf); break; + + case REGISTRY_TYPE_INT8: DEBUG("int8: %d", *(int8_t *)value->buf); break; + case REGISTRY_TYPE_INT16: DEBUG("int16: %d", *(int16_t *)value->buf); break; + case REGISTRY_TYPE_INT32: DEBUG("int32: %d", *(int32_t *)value->buf); break; + case REGISTRY_TYPE_INT64: DEBUG("int64: %lld", *(int64_t *)value->buf); break; + + case REGISTRY_TYPE_FLOAT32: DEBUG("f32: %f", *(float *)value->buf); break; + case REGISTRY_TYPE_FLOAT64: DEBUG("f64: %f", *(double *)value->buf); break; + } + } +} + +int registry_util_convert_str_to_value(const char *src, void *dest, const size_t dest_len, + const registry_type_t dest_type) +{ + assert(src != NULL); + assert(dest != NULL); + + char *eptr = '\0'; + + if (!src) { + return -EINVAL; + } + + switch (dest_type) { + case REGISTRY_TYPE_NONE: { + return -EINVAL; + } + + case REGISTRY_TYPE_OPAQUE: { + size_t base64_decode_len; + if (base64_decode(src, strlen(src), dest, &base64_decode_len) != + BASE64_SUCCESS && base64_decode_len <= dest_len) { + return -EINVAL; + } + break; + } + + case REGISTRY_TYPE_STRING: { + if (strlen(src) + 1 > dest_len) { + return -EINVAL; + } + strcpy((char *)dest, src); + break; + } + + case REGISTRY_TYPE_BOOL: { + *(bool *)dest = strtol(src, &eptr, 0); + break; + } + + case REGISTRY_TYPE_UINT8: { + *(uint8_t *)dest = strtoul(src, &eptr, 0); + break; + } + + case REGISTRY_TYPE_UINT16: { + *(uint16_t *)dest = strtoul(src, &eptr, 0); + break; + } + + case REGISTRY_TYPE_UINT32: { + *(uint32_t *)dest = strtoul(src, &eptr, 0); + break; + } + + case REGISTRY_TYPE_UINT64: { + *(uint64_t *)dest = strtoull(src, &eptr, 0); + break; + } + + case REGISTRY_TYPE_INT8: { + *(int8_t *)dest = strtol(src, &eptr, 0); + break; + } + + case REGISTRY_TYPE_INT16: { + *(int16_t *)dest = strtol(src, &eptr, 0); + break; + } + + case REGISTRY_TYPE_INT32: { + *(int32_t *)dest = strtol(src, &eptr, 0); + break; + } + + case REGISTRY_TYPE_INT64: { + *(int64_t *)dest = strtoll(src, &eptr, 0); + break; + } + + case REGISTRY_TYPE_FLOAT32: { + *(float *)dest = strtof(src, &eptr); + break; + } + + case REGISTRY_TYPE_FLOAT64: { + *(double *)dest = strtod(src, &eptr); + break; + } + } + + if (*eptr != '\0') { + return -EINVAL; + } + + return 0; +} + +int registry_util_convert_value_to_str(const registry_value_t *src, char *dest, + const size_t dest_len) +{ + assert(src != NULL); + + size_t str_len; + + switch (src->type) { + case REGISTRY_TYPE_NONE: { + return -EINVAL; + } + + case REGISTRY_TYPE_OPAQUE: { + if (base64_encode(src->buf, src->buf_len, dest, &str_len) != BASE64_SUCCESS + || str_len > dest_len - 1) { + /* If dest is NULL, the length is returned */ + if (dest != NULL) { + return -EINVAL; + } + } + else { + dest[str_len] = '\0'; + } + break; + } + + case REGISTRY_TYPE_STRING: { + char *str_val = (char *)src->buf; + + str_len = strlen(str_val); + + if (str_len > dest_len - 1) { + /* If dest is NULL, the length is returned */ + if (dest != NULL) { + return -EINVAL; + } + } + else { + strcpy(dest, str_val); + } + break; + } + + case REGISTRY_TYPE_BOOL: { + str_len = snprintf(dest, dest_len, " %" PRId8, *(bool *)src->buf); + break; + } + + case REGISTRY_TYPE_UINT8: { + str_len = snprintf(dest, dest_len, " %" PRIu8, *(uint8_t *)src->buf); + break; + } + + case REGISTRY_TYPE_UINT16: { + str_len = snprintf(dest, dest_len, " %" PRIu16, *(uint16_t *)src->buf); + break; + } + + case REGISTRY_TYPE_UINT32: { + str_len = snprintf(dest, dest_len, " %" PRIu32, *(uint32_t *)src->buf); + break; + } + + case REGISTRY_TYPE_UINT64: { + str_len = fmt_u64_dec(NULL, *(uint64_t *)src->buf); + if (str_len > dest_len - 1) { + /* If dest is NULL, the length is returned */ + if (dest != NULL) { + return -EINVAL; + } + } + else { + fmt_u64_dec(dest, *(uint64_t *)src->buf); + dest[str_len] = '\0'; + } + break; + } + + case REGISTRY_TYPE_INT8: { + str_len = snprintf(dest, dest_len, " %" PRId8, *(int8_t *)src->buf); + break; + } + + case REGISTRY_TYPE_INT16: { + str_len = snprintf(dest, dest_len, " %" PRId16, *(int16_t *)src->buf); + break; + } + + case REGISTRY_TYPE_INT32: { + str_len = snprintf(dest, dest_len, " %" PRId32, *(int32_t *)src->buf); + break; + } + + case REGISTRY_TYPE_INT64: { + str_len = fmt_s64_dec(NULL, *(int64_t *)src->buf); + if (str_len > dest_len - 1) { + /* If dest is NULL, the length is returned */ + if (dest != NULL) { + return -EINVAL; + } + } + else { + fmt_s64_dec(dest, *(int64_t *)src->buf); + dest[str_len] = '\0'; + } + break; + } + + case REGISTRY_TYPE_FLOAT32: { + str_len = sprintf(dest, " %f", *(float *)src->buf); + if (str_len > dest_len - 1) { + /* If dest is NULL, the length is returned */ + if (dest != NULL) { + return -EINVAL; + } + } + break; + } + + case REGISTRY_TYPE_FLOAT64: { + str_len = sprintf(dest, " %f", *(double *)src->buf); + if (str_len > dest_len - 1) { + /* If dest is NULL, the length is returned */ + if (dest != NULL) { + return -EINVAL; + } + } + break; + } + } + + return str_len; +} From a12ae66bfd2a5ac4fe71405f18c93c0668c36915 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 19:42:35 +0200 Subject: [PATCH 002/117] sys/registry: add persistent storage module --- makefiles/pseudomodules.inc.mk | 1 + sys/include/registry/storage.h | 154 +++++++++++++++++++++ sys/registry/Kconfig | 2 + sys/registry/Makefile | 4 + sys/registry/Makefile.dep | 4 + sys/registry/storage/Kconfig | 12 ++ sys/registry/storage/Makefile | 9 ++ sys/registry/storage/Makefile.dep | 4 + sys/registry/storage/storage.c | 216 ++++++++++++++++++++++++++++++ 9 files changed, 406 insertions(+) create mode 100644 sys/include/registry/storage.h create mode 100644 sys/registry/storage/Kconfig create mode 100644 sys/registry/storage/Makefile create mode 100644 sys/registry/storage/Makefile.dep create mode 100644 sys/registry/storage/storage.c diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index e27a3c81209c..f1896f4b777d 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -397,6 +397,7 @@ PSEUDOMODULES += fortuna_reseed PSEUDOMODULES += random_cmd ## @} PSEUDOMODULES += registry_% +NO_PSEUDOMODULES += registry_storage PSEUDOMODULES += riotboot_% PSEUDOMODULES += rtt_cmd diff --git a/sys/include/registry/storage.h b/sys/include/registry/storage.h new file mode 100644 index 000000000000..61a76d41ee6d --- /dev/null +++ b/sys/include/registry/storage.h @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_storage RIOT Registry Storage + * @ingroup sys + * @brief RIOT Registry Storage module allowing to store configuration parameters to non-volatile storage + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_STORAGE_H +#define REGISTRY_STORAGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/** + * @brief Prototype of a callback function for the load action of a storage interface. + */ +typedef int (*load_cb_t)(const registry_instance_t *instance, const registry_parameter_t *parameter, + const void *buf, const size_t buf_len); + +typedef struct _registry_storage_t registry_storage_t; + +/** + * @brief Storage descriptor. + */ +typedef struct { + registry_storage_t *storage; /**< interface of the storage. */ + void *data; /**< Struct containing all config data for the storage. */ +} registry_storage_instance_t; + +/** + * @brief Storage interface. All storages should, at least, implement the load and save actions. + */ +struct _registry_storage_t { + /** + * @brief Loads all saved parameters and calls the @p load_cb callback function. + * + * @param[in] storage Storage descriptor. + * @param[in] load_cb Callback function to call for every saved parameter. + * + * @return 0 on success, non-zero on failure. + */ + int (*load)(const registry_storage_instance_t *storage, + const load_cb_t load_cb); + + /** + * @brief If implemented, it is used for any preparation the storage may + * need before starting a saving process. + * + * @param[in] storage Storage descriptor. + * + * @return 0 on success, non-zero on failure. + */ + int (*save_start)(const registry_storage_instance_t *storage); + + /** + * @brief Saves a parameter into storage. + * + * @param[in] storage Storage descriptor. + * @param[in] instance Pointer to the configuration schema instance. + * @param[in] parameter Pointer to the configuration parameter. + * @param[in] value Configuration parameter value. + * + * @return 0 on success, non-zero on failure. + */ + int (*save)(const registry_storage_instance_t *storage, + const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_value_t *value); + + /** + * @brief If implemented, it is used for any tear-down the storage may need + * after a saving process. + * + * @param[in] storage Storage descriptor. + * + * @return 0 on success, non-zero on failure. + */ + int (*save_end)(const registry_storage_instance_t *storage); +}; + +/** + * @brief Load all configuration parameters from the registered storage. + * + * @return 0 on success, non-zero on failure. + */ +int registry_load(void); + +/** + * @brief Save all configuration parameters to the + * registered storage. + * + * @return 0 on success, non-zero on failure. + */ +int registry_save(void); + +int registry_save_namespace(const registry_namespace_t *namespace); + +int registry_save_schema(const registry_schema_t *schema); + +int registry_save_instance(const registry_instance_t *instance); + +int registry_save_group(const registry_instance_t *instance, const registry_group_t *group); + +int registry_save_parameter(const registry_instance_t *instance, + const registry_parameter_t *parameter); + +/** + * @brief Registers a new storage as a source of configurations. Multiple + * storages can be configured as sources at the same time. Configurations + * will be loaded from all of them. If more than one storage contain values + * for the same key, then only the value of the storage is used, that was + * registered last. + * + * @param[in] src Pointer to the storage to register as source. + */ +#define REGISTRY_ADD_STORAGE_SOURCE(_storage_instance) \ + XFA_USE_CONST(registry_storage_instance_t *, _registry_storage_instances_src_xfa); \ + XFA_ADD_PTR(_registry_storage_instances_src_xfa, _storage_instance, _storage_instance, \ + &_storage_instance) + +extern const registry_storage_instance_t *_registry_storage_instance_dst; + +/** + * @brief Registers a new storage as a destination for saving configurations + * Only one storage can be registered as destination at a time. If a + * previous storage had been registered before it will be replaced by the + * new one. + * + * @param[in] dst Pointer to the storage to register. + */ +#define REGISTRY_SET_STORAGE_DESTINATION(_storage_instance) \ + const registry_storage_instance_t *_registry_storage_instance_dst = &_storage_instance \ + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_STORAGE_H */ +/** @} */ diff --git a/sys/registry/Kconfig b/sys/registry/Kconfig index 18c13b6d9ac0..438867053018 100644 --- a/sys/registry/Kconfig +++ b/sys/registry/Kconfig @@ -30,4 +30,6 @@ config REGISTRY_ENABLE_MIN_VALUE_CHECK config REGISTRY_ENABLE_MAX_VALUE_CHECK bool "Check if new value does not exceed maximum" +rsource "storage/Kconfig" + endif # MODULE_REGISTRY \ No newline at end of file diff --git a/sys/registry/Makefile b/sys/registry/Makefile index 6f17dec2f0f4..2cc24520ed7d 100644 --- a/sys/registry/Makefile +++ b/sys/registry/Makefile @@ -2,4 +2,8 @@ SRC := registry.c util.c init.c SUBMODULES := 1 +ifneq (,$(filter registry_storage%,$(USEMODULE))) + DIRS += storage +endif + include $(RIOTBASE)/Makefile.base diff --git a/sys/registry/Makefile.dep b/sys/registry/Makefile.dep index 5fd516719057..bd58b563899c 100644 --- a/sys/registry/Makefile.dep +++ b/sys/registry/Makefile.dep @@ -1,3 +1,7 @@ +ifneq (,$(filter registry_storage%,$(USEMODULE))) + include $(RIOTBASE)/sys/registry/storage/Makefile.dep +endif + ifneq (,$(filter registry_%,$(USEMODULE))) USEMODULE += registry endif diff --git a/sys/registry/storage/Kconfig b/sys/registry/storage/Kconfig new file mode 100644 index 000000000000..0f18f0e3bc23 --- /dev/null +++ b/sys/registry/storage/Kconfig @@ -0,0 +1,12 @@ +# Copyright (c) 2023 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +menuconfig MODULE_REGISTRY_STORAGE + bool "MODULE_REGISTRY_STORAGE" + depends on MODULE_REGISTRY + help + Storage module allowing to store configuration parameters to non-volatile storage. diff --git a/sys/registry/storage/Makefile b/sys/registry/storage/Makefile new file mode 100644 index 000000000000..6d464a7919c1 --- /dev/null +++ b/sys/registry/storage/Makefile @@ -0,0 +1,9 @@ +MODULE := registry_storage + +BASE_MODULE := registry + +SRC := storage.c + +SUBMODULES := 1 + +include $(RIOTBASE)/Makefile.base diff --git a/sys/registry/storage/Makefile.dep b/sys/registry/storage/Makefile.dep new file mode 100644 index 000000000000..74d5f7d59018 --- /dev/null +++ b/sys/registry/storage/Makefile.dep @@ -0,0 +1,4 @@ +# Enable "registry_storage" module for all storage modules +ifneq (,$(filter registry_storage_%,$(USEMODULE))) + USEMODULE += registry_storage +endif diff --git a/sys/registry/storage/storage.c b/sys/registry/storage/storage.c new file mode 100644 index 000000000000..106dba4f910b --- /dev/null +++ b/sys/registry/storage/storage.c @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_storage RIOT Registry Storage + * @ingroup sys + * @brief RIOT Registry Storage module allowing to store configuration parameters to non-volatile storage + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "clist.h" + +#include "registry/storage.h" +#include "registry/util.h" +#include "registry/error.h" + +XFA_INIT_CONST(registry_storage_instance_t *, _registry_storage_instances_src_xfa); + +/* registry_load */ +static int _registry_load_cb(const registry_instance_t *instance, + const registry_parameter_t *parameter, + const void *buf, const size_t buf_len) +{ + return registry_set(instance, parameter, buf, buf_len); +} + +int registry_load(void) +{ + for (size_t i = 0; + i < XFA_LEN(registry_storage_instance_t *, _registry_storage_instances_src_xfa); i++) { + registry_storage_instance_t *src = _registry_storage_instances_src_xfa[i]; + + int res = src->storage->load(src, _registry_load_cb); + + if (res != 0) { + return res; + } + } + + return 0; +} + +/* registry_save */ +static int _registry_save_export_cb(const registry_export_cb_data_t *data, + const registry_export_cb_data_type_t data_type, + const void *context) +{ + (void)context; + + /* the registry also exports just the namespace or just a schema, but the storage is only interested in configuration parameter values */ + if (data_type != REGISTRY_EXPORT_PARAMETER) { + return 0; + } + + /* check if a destination storage is registered */ + if (!_registry_storage_instance_dst) { + return -REGISTRY_ERROR_NO_DST_STORAGE; + } + + /* get value of configuration parameter */ + registry_value_t value; + registry_get(data->parameter.instance, data->parameter.data, &value); + + /* save parameter value via the save function of the registered destination storage */ + return _registry_storage_instance_dst->storage->save(_registry_storage_instance_dst, + data->parameter.instance, + data->parameter.data, + &value); +} + +int registry_save(void) +{ + int res; + + if (!_registry_storage_instance_dst) { + return -REGISTRY_ERROR_NO_DST_STORAGE; + } + + if (_registry_storage_instance_dst->storage->save_start) { + _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); + } + + res = registry_export(_registry_save_export_cb, 0, NULL); + + if (_registry_storage_instance_dst->storage->save_end) { + _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); + } + + return res; +} + +int registry_save_namespace(const registry_namespace_t *namespace) +{ + int res; + + if (!_registry_storage_instance_dst) { + return -REGISTRY_ERROR_NO_DST_STORAGE; + } + + if (_registry_storage_instance_dst->storage->save_start) { + _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); + } + + res = registry_export_namespace(namespace, _registry_save_export_cb, 0, NULL); + + if (_registry_storage_instance_dst->storage->save_end) { + _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); + } + + return res; +} + +int registry_save_schema(const registry_schema_t *schema) +{ + int res; + + if (!_registry_storage_instance_dst) { + return -REGISTRY_ERROR_NO_DST_STORAGE; + } + + if (_registry_storage_instance_dst->storage->save_start) { + _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); + } + + res = registry_export_schema(schema, _registry_save_export_cb, 0, NULL); + + if (_registry_storage_instance_dst->storage->save_end) { + _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); + } + + return res; +} + +int registry_save_instance(const registry_instance_t *instance) +{ + int res; + + if (!_registry_storage_instance_dst) { + return -REGISTRY_ERROR_NO_DST_STORAGE; + } + + if (_registry_storage_instance_dst->storage->save_start) { + _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); + } + + res = registry_export_instance(instance, _registry_save_export_cb, 0, NULL); + + if (_registry_storage_instance_dst->storage->save_end) { + _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); + } + + return res; +} + +int registry_save_group(const registry_instance_t *instance, const registry_group_t *group) +{ + int res; + + if (!_registry_storage_instance_dst) { + return -REGISTRY_ERROR_NO_DST_STORAGE; + } + + if (_registry_storage_instance_dst->storage->save_start) { + _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); + } + + res = registry_export_group(instance, group, _registry_save_export_cb, 0, NULL); + + if (_registry_storage_instance_dst->storage->save_end) { + _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); + } + + return res; +} + +int registry_save_parameter(const registry_instance_t *instance, + const registry_parameter_t *parameter) +{ + int res; + + if (!_registry_storage_instance_dst) { + return -REGISTRY_ERROR_NO_DST_STORAGE; + } + + if (_registry_storage_instance_dst->storage->save_start) { + _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); + } + + res = registry_export_parameter(instance, parameter, _registry_save_export_cb, NULL); + + if (_registry_storage_instance_dst->storage->save_end) { + _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); + } + + return res; +} From 55be4403983bc259b54a82098f91092ccbb85969 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 19:47:11 +0200 Subject: [PATCH 003/117] sys/registry: add int_path module --- sys/include/registry/int_path.h | 266 ++++++++++++++++++++ sys/registry/Kconfig | 3 + sys/registry/int_path.c | 426 ++++++++++++++++++++++++++++++++ 3 files changed, 695 insertions(+) create mode 100644 sys/include/registry/int_path.h create mode 100644 sys/registry/int_path.c diff --git a/sys/include/registry/int_path.h b/sys/include/registry/int_path.h new file mode 100644 index 000000000000..2ff887181373 --- /dev/null +++ b/sys/include/registry/int_path.h @@ -0,0 +1,266 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_int_path RIOT Registry integer path + * @ingroup sys + * @brief RIOT Registry integer path module providing functions to convert between registry objects and their integer paths + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_INT_PATH_H +#define REGISTRY_INT_PATH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/** + * @brief Maximum length of a configuration path. + * + * Path: namespace_id / schema_id / instance_id / (group_id | parameter_id). + */ +#define REGISTRY_INT_PATH_MAX_LEN 4 + +/** + * @brief Maximum length of a configuration path as a string. + * + * A int path ID is an uint32_t and uint32_t MAX has 10 digits. + * We also need to include the separator. One additional char between each number. + */ +#define REGISTRY_INT_PATH_STRING_MAX_LEN ((10 * REGISTRY_INT_PATH_MAX_LEN) + \ + (REGISTRY_INT_PATH_MAX_LEN - 1)) + +/** + * @brief Integer path representation for a namespace. + */ +typedef struct { + registry_namespace_id_t namespace_id; /**< The ID of the namespace. */ +} registry_namespace_int_path_t; + +/** + * @brief Integer path representation for a configuration schema. + */ +typedef struct { + registry_namespace_id_t namespace_id; /**< The ID of the namespace. */ + registry_schema_id_t schema_id; /**< The ID of the schema. */ +} registry_schema_int_path_t; + +/** + * @brief Integer path representation for a configuration schema instance. + */ +typedef struct { + registry_namespace_id_t namespace_id; /**< The ID of the namespace. */ + registry_schema_id_t schema_id; /**< The ID of the schema. */ + registry_instance_id_t instance_id; /**< The ID of the instance. */ +} registry_instance_int_path_t; + +/** + * @brief Integer path representation for a configuration group. + */ +typedef struct { + registry_namespace_id_t namespace_id; /**< The ID of the namespace. */ + registry_schema_id_t schema_id; /**< The ID of the schema. */ + registry_instance_id_t instance_id; /**< The ID of the instance. */ + registry_group_id_t group_id; /**< The ID of the group. */ +} registry_group_int_path_t; + +/** + * @brief Integer path representation for a configuration parameter. + */ +typedef struct { + registry_namespace_id_t namespace_id; /**< The ID of the namespace. */ + registry_schema_id_t schema_id; /**< The ID of the schema. */ + registry_instance_id_t instance_id; /**< The ID of the instance. */ + registry_parameter_id_t parameter_id; /**< The ID of the parameter. */ +} registry_parameter_int_path_t; + +/** + * @brief Integer path representation for a configuration group or parameter. + */ +typedef struct { + registry_namespace_id_t namespace_id; /**< The ID of the namespace. */ + registry_schema_id_t schema_id; /**< The ID of the schema. */ + registry_instance_id_t instance_id; /**< The ID of the instance. */ + registry_group_or_parameter_id_t group_or_parameter_id; /**< The ID of the group or parameter. */ +} registry_group_or_parameter_int_path_t; + +/** + * @brief Enumeration of the different types of integer paths. + */ +typedef enum { + REGISTRY_INT_PATH_TYPE_NAMESPACE, /**< The path represents a namespace. */ + REGISTRY_INT_PATH_TYPE_SCHEMA, /**< The path represents a schema. */ + REGISTRY_INT_PATH_TYPE_INSTANCE, /**< The path represents an instance. */ + REGISTRY_INT_PATH_TYPE_GROUP, /**< The path represents a group. */ + REGISTRY_INT_PATH_TYPE_PARAMETER, /**< The path represents a parameter. */ + REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER, /**< The path represents a group or parameter. */ +}registry_int_path_type_t; + +/** + * @brief Union of the different types of integer paths. + */ +typedef union { + registry_namespace_int_path_t namespace_path; /**< The path represents a namespace. */ + registry_schema_int_path_t schema_path; /**< The path represents a schema. */ + registry_instance_int_path_t instance_path; /**< The path represents an instance. */ + registry_group_int_path_t group_path; /**< The path represents a group. */ + registry_parameter_int_path_t parameter_path; /**< The path represents a parameter. */ + registry_group_or_parameter_int_path_t group_or_parameter_path; /**< The path represents a group or parameter. */ +} registry_int_path_t; + +/** + * @brief Converts a registry namespace to an integer path. + * + * @param[in] namespace The registry namespace to convert. + * + * @return The integer path representation of the namespace. + */ +registry_namespace_int_path_t registry_to_namespace_int_path(const registry_namespace_t *namespace); + +/** + * @brief Converts a registry schema to an integer path. + * + * @param[in] schema The registry schema to convert. + * + * @return The integer path representation of the schema. + */ +registry_schema_int_path_t registry_to_schema_int_path(const registry_schema_t *schema); + +/** + * @brief Converts a registry instance to an integer path. + * + * @param[in] instance The registry instance to convert. + * + * @return The integer path representation of the instance. + */ +registry_instance_int_path_t registry_to_instance_int_path(const registry_instance_t *instance); + +/** + * @brief Converts a registry group to an integer path. + * + * @param[in] instance The registry instance that the group belongs to. + * @param[in] group The registry group to convert. + * + * @return The integer path representation of the group. + */ +registry_group_int_path_t registry_to_group_int_path(const registry_instance_t *instance, + const registry_group_t *group); + +/** + * @brief Converts a registry parameter to an integer path. + * + * @param[in] instance The registry instance that the parameter belongs to. + * @param[in] parameter The registry parameter to convert. + * + * @return The integer path representation of the parameter. + */ +registry_parameter_int_path_t registry_to_parameter_int_path(const registry_instance_t *instance, + const registry_parameter_t *parameter); + +/** + * @brief Converts an integer path to a registry namespace. + * + * @param[in] path The integer path to convert. + * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_namespace_int_path(const registry_namespace_int_path_t *path, + registry_namespace_t **namespace); + +/** + * @brief Converts an integer path to a registry schema. + * + * @param[in] path The integer path to convert. + * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. + * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_schema_int_path(const registry_schema_int_path_t *path, + registry_namespace_t **namespace, registry_schema_t **schema); + +/** + * @brief Converts an integer path to a registry instance. + * + * @param[in] path The integer path to convert. + * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. + * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. + * @param[out] instance A pointer to the registry instance that will be set to the result of the conversion. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_instance_int_path(const registry_instance_int_path_t *path, + registry_namespace_t **namespace, registry_schema_t **schema, + registry_instance_t **instance); + +/** + * @brief Converts an integer path to a registry group. + * + * @param[in] path The integer path to convert. + * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. + * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. + * @param[out] instance A pointer to the registry instance that will be set to the result of the conversion. + * @param[out] group A pointer to the registry group that will be set to the result of the conversion. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_group_int_path(const registry_group_int_path_t *path, + registry_namespace_t **namespace, registry_schema_t **schema, + registry_instance_t **instance, registry_group_t **group); + +/** + * @brief Converts an integer path to a registry parameter. + * + * @param[in] path The integer path to convert. + * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. + * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. + * @param[out] instance A pointer to the registry instance that will be set to the result of the conversion. + * @param[out] parameter A pointer to the registry parameter that will be set to the result of the conversion. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_parameter_int_path(const registry_parameter_int_path_t *path, + registry_namespace_t **namespace, registry_schema_t **schema, + registry_instance_t **instance, + registry_parameter_t **parameter); + +/** + * @brief Converts an integer path to either a registry group or a registry parameter. + * + * @param[in] path The integer path to convert. + * @param[out] path_type A pointer to the type of the integer path that was converted. + * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. + * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. + * @param[out] instance A pointer to the registry instance that will be set to the result of the conversion. + * @param[out] group A pointer to the registry group that will be set to the result of the conversion if the integer path represents a group. + * @param[out] parameter A pointer to the registry parameter that will be set to the result of the conversion if the integer path represents a parameter. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_group_or_parameter_int_path(const registry_group_or_parameter_int_path_t *path, + registry_int_path_type_t *path_type, + registry_namespace_t **namespace, + registry_schema_t **schema, + registry_instance_t **instance, + registry_group_t **group, + registry_parameter_t **parameter); + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_INT_PATH_H */ +/** @} */ diff --git a/sys/registry/Kconfig b/sys/registry/Kconfig index 438867053018..0a3ee90e9788 100644 --- a/sys/registry/Kconfig +++ b/sys/registry/Kconfig @@ -30,6 +30,9 @@ config REGISTRY_ENABLE_MIN_VALUE_CHECK config REGISTRY_ENABLE_MAX_VALUE_CHECK bool "Check if new value does not exceed maximum" +config MODULE_REGISTRY_INT_PATH + bool "Access configuration parameters via an integer path" + rsource "storage/Kconfig" endif # MODULE_REGISTRY \ No newline at end of file diff --git a/sys/registry/int_path.c b/sys/registry/int_path.c new file mode 100644 index 000000000000..0d132300b256 --- /dev/null +++ b/sys/registry/int_path.c @@ -0,0 +1,426 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_int_path RIOT Registry Int Path + * @ingroup sys + * @brief RIOT Registry Int Path module providing a API to access configuration parameter via an integer path + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "clist.h" +#include "registry.h" +#include "registry/util.h" +#include "registry/error.h" + +#include "registry/int_path.h" + +XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); + +static int _namespace_lookup(const registry_namespace_id_t namespace_id, + registry_namespace_t **namespace) +{ + assert(namespace != NULL); + + for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { + if (_registry_namespaces_xfa[i]->id == namespace_id) { + *namespace = _registry_namespaces_xfa[i]; + return 0; + } + } + + return -REGISTRY_ERROR_NAMESPACE_NOT_FOUND; +} + +static int _schema_lookup(const registry_namespace_t *namespace, + const registry_schema_id_t schema_id, + registry_schema_t **schema) +{ + assert(schema != NULL); + + for (size_t i = 0; i < namespace->schemas_len; i++) { + if (namespace->schemas[i]->id == schema_id) { + *schema = (registry_schema_t *)namespace->schemas[i]; + return 0; + } + } + + return -REGISTRY_ERROR_SCHEMA_NOT_FOUND; +} + +static int _instance_lookup(const registry_schema_t *schema, + const registry_instance_id_t instance_id, + registry_instance_t **instance) +{ + assert(schema != NULL); + assert(instance != NULL); + + /* find instance with correct instance_id */ + clist_node_t *node = schema->instances.next; + + if (!node) { + return -REGISTRY_ERROR_INSTANCE_NOT_FOUND; + } + + do { + node = node->next; + + /* check if index equals instance_id */ + if (container_of(node, registry_instance_t, node)->id == instance_id) { + *instance = container_of(node, registry_instance_t, node); + return 0; + } + } while (node != schema->instances.next); + + return -REGISTRY_ERROR_INSTANCE_NOT_FOUND; +} + +static const registry_group_t *_internal_group_lookup(const registry_group_t *group, + const registry_group_id_t group_id) +{ + assert(group != NULL); + + for (size_t i = 0; i < group->groups_len; i++) { + if (group->groups[i]->id == group_id) { + return group->groups[i]; + } + else if (group->groups[i]->groups_len > 0) { + return _internal_group_lookup(group->groups[i], group_id); + } + } + + return NULL; +} + +static int _group_lookup(const registry_schema_t *schema, const registry_group_id_t group_id, + registry_group_t **group) +{ + assert(schema != NULL); + assert(group != NULL); + + for (size_t i = 0; i < schema->groups_len; i++) { + if (schema->groups[i]->id == group_id) { + *group = (registry_group_t *)schema->groups[i]; + return 0; + } + else if (schema->groups[i]->groups_len > 0) { + registry_group_t *found_group = (registry_group_t *)_internal_group_lookup( + schema->groups[i], group_id); + if (found_group != NULL) { + *group = found_group; + return 0; + } + } + } + + return -REGISTRY_ERROR_GROUP_NOT_FOUND; +} + +static const registry_parameter_t *_internal_parameter_lookup(const registry_group_t *group, + const registry_parameter_id_t parameter_id) +{ + assert(group != NULL); + + for (size_t i = 0; i < group->parameters_len; i++) { + if (group->parameters[i]->id == parameter_id) { + return group->parameters[i]; + } + } + + for (size_t i = 0; i < group->groups_len; i++) { + return _internal_parameter_lookup(group->groups[i], parameter_id); + } + + return NULL; +} + +static int _parameter_lookup(const registry_schema_t *schema, + const registry_parameter_id_t parameter_id, + registry_parameter_t **parameter) +{ + assert(schema != NULL); + assert(parameter != NULL); + + for (size_t i = 0; i < schema->parameters_len; i++) { + if (schema->parameters[i]->id == parameter_id) { + *parameter = (registry_parameter_t *)schema->parameters[i]; + return 0; + } + } + + for (size_t i = 0; i < schema->groups_len; i++) { + registry_parameter_t *found_parameter = (registry_parameter_t *)_internal_parameter_lookup( + schema->groups[i], + parameter_id); + if (found_parameter != NULL) { + *parameter = found_parameter; + return 0; + } + } + + return -REGISTRY_ERROR_PARAMETER_NOT_FOUND; +} + +/* to int path */ +registry_namespace_int_path_t registry_to_namespace_int_path(const registry_namespace_t *namespace) +{ + assert(namespace != NULL); + + return (registry_namespace_int_path_t) { + .namespace_id = namespace->id, + }; +} + +registry_schema_int_path_t registry_to_schema_int_path(const registry_schema_t *schema) +{ + assert(schema != NULL); + + return (registry_schema_int_path_t) { + .namespace_id = schema->namespace->id, + .schema_id = schema->id, + }; +} + +registry_instance_int_path_t registry_to_instance_int_path(const registry_instance_t *instance) +{ + assert(instance != NULL); + + return (registry_instance_int_path_t) { + .namespace_id = instance->schema->namespace->id, + .schema_id = instance->schema->id, + .instance_id = instance->id, + }; +} + +registry_group_int_path_t registry_to_group_int_path(const registry_instance_t *instance, + const registry_group_t *group) +{ + assert(instance != NULL); + assert(group != NULL); + + return (registry_group_int_path_t) { + .namespace_id = instance->schema->namespace->id, + .schema_id = instance->schema->id, + .instance_id = instance->id, + .group_id = group->id, + }; +} + +registry_parameter_int_path_t registry_to_parameter_int_path(const registry_instance_t *instance, + const registry_parameter_t *parameter) +{ + assert(instance != NULL); + assert(parameter != NULL); + + return (registry_parameter_int_path_t) { + .namespace_id = instance->schema->namespace->id, + .schema_id = instance->schema->id, + .instance_id = instance->id, + .parameter_id = parameter->id, + }; +} + +/* from int path */ +int registry_from_namespace_int_path(const registry_namespace_int_path_t *path, + registry_namespace_t **namespace) +{ + assert(path != NULL); + assert(namespace != NULL); + + int res = _namespace_lookup(path->namespace_id, namespace); + + return res; +} + +int registry_from_schema_int_path(const registry_schema_int_path_t *path, + registry_namespace_t **namespace, registry_schema_t **schema) +{ + assert(path != NULL); + /* leaving namespace NULL is fine */ + assert(schema != NULL); + + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path->namespace_id, &found_namespace); + if (namespace != NULL) { + *namespace = found_namespace; + } + + if (res == 0) { + res = _schema_lookup(found_namespace, path->schema_id, schema); + } + + return res; +} + +int registry_from_instance_int_path(const registry_instance_int_path_t *path, + registry_namespace_t **namespace, registry_schema_t **schema, + registry_instance_t **instance) +{ + assert(path != NULL); + /* leaving namespace or schema NULL is fine */ + assert(instance != NULL); + + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path->namespace_id, &found_namespace); + if (namespace != NULL) { + *namespace = found_namespace; + } + + if (res == 0) { + registry_schema_t *found_schema; + res = _schema_lookup(found_namespace, path->schema_id, &found_schema); + if (schema != NULL) { + *schema = found_schema; + } + + if (res == 0) { + res = _instance_lookup(found_schema, path->instance_id, instance); + } + } + + return res; +} + +int registry_from_group_int_path(const registry_group_int_path_t *path, + registry_namespace_t **namespace, registry_schema_t **schema, + registry_instance_t **instance, registry_group_t **group) +{ + assert(path != NULL); + /* leaving namespace, schema or instance NULL is fine */ + assert(group != NULL); + + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path->namespace_id, &found_namespace); + if (namespace != NULL) { + *namespace = found_namespace; + } + + if (res == 0) { + registry_schema_t *found_schema; + res = _schema_lookup(found_namespace, path->schema_id, &found_schema); + if (schema != NULL) { + *schema = found_schema; + } + + if (res == 0) { + registry_instance_t *found_instance; + res = _instance_lookup(found_schema, path->instance_id, &found_instance); + if (instance != NULL) { + *instance = found_instance; + } + + if (res == 0) { + res = _group_lookup(found_schema, path->group_id, group); + } + } + } + + return res; +} + +int registry_from_parameter_int_path(const registry_parameter_int_path_t *path, + registry_namespace_t **namespace, registry_schema_t **schema, + registry_instance_t **instance, + registry_parameter_t **parameter) +{ + assert(path != NULL); + /* leaving namespace, schema or instance NULL is fine */ + assert(parameter != NULL); + + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path->namespace_id, &found_namespace); + if (namespace != NULL) { + *namespace = found_namespace; + } + + if (res == 0) { + registry_schema_t *found_schema; + res = _schema_lookup(found_namespace, path->schema_id, &found_schema); + if (schema != NULL) { + *schema = found_schema; + } + + if (res == 0) { + registry_instance_t *found_instance; + res = _instance_lookup(found_schema, path->instance_id, &found_instance); + if (instance != NULL) { + *instance = found_instance; + } + + if (res == 0) { + res = _parameter_lookup(found_schema, path->parameter_id, parameter); + } + } + } + + return res; +} + +int registry_from_group_or_parameter_int_path(const registry_group_or_parameter_int_path_t *path, + registry_int_path_type_t *path_type, + registry_namespace_t **namespace, + registry_schema_t **schema, + registry_instance_t **instance, + registry_group_t **group, + registry_parameter_t **parameter) +{ + assert(path != NULL); + /* leaving namespace, schema or instance NULL is fine */ + assert(group != NULL); + assert(parameter != NULL); + + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path->namespace_id, &found_namespace); + if (namespace != NULL) { + *namespace = found_namespace; + } + + if (res == 0) { + registry_schema_t *found_schema; + res = _schema_lookup(found_namespace, path->schema_id, &found_schema); + if (schema != NULL) { + *schema = found_schema; + } + + if (res == 0) { + registry_instance_t *found_instance; + res = _instance_lookup(found_schema, path->instance_id, &found_instance); + if (instance != NULL) { + *instance = found_instance; + } + + if (res == 0) { + res = _parameter_lookup(found_schema, path->group_or_parameter_id, parameter); + if (res == 0) { + *path_type = REGISTRY_INT_PATH_TYPE_PARAMETER; + } + else { + res = _group_lookup(found_schema, path->group_or_parameter_id, group); + if (res == 0) { + *path_type = REGISTRY_INT_PATH_TYPE_GROUP; + } + } + } + } + } + + return res; +} From cc16efbeec3e1e1111a882297faf439fb5eddeb4 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 19:48:30 +0200 Subject: [PATCH 004/117] sys/registry: add string_path module --- sys/Makefile.include | 4 + sys/include/registry/string_path.h | 183 +++++++ sys/registry/Kconfig | 3 + sys/registry/Makefile.include | 3 + sys/registry/string_path.c | 750 +++++++++++++++++++++++++++++ 5 files changed, 943 insertions(+) create mode 100644 sys/include/registry/string_path.h create mode 100644 sys/registry/Makefile.include create mode 100644 sys/registry/string_path.c diff --git a/sys/Makefile.include b/sys/Makefile.include index b1ba246995bd..652a19a47ad3 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -188,3 +188,7 @@ endif ifneq (,$(filter gcoap,$(USEMODULE))) include $(RIOTBASE)/sys/net/application_layer/gcoap/Makefile.include endif + +ifneq (,$(filter registry%,$(USEMODULE))) + include $(RIOTBASE)/sys/registry/Makefile.include +endif \ No newline at end of file diff --git a/sys/include/registry/string_path.h b/sys/include/registry/string_path.h new file mode 100644 index 000000000000..907a2e48142d --- /dev/null +++ b/sys/include/registry/string_path.h @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_string_path RIOT Registry String Path + * @ingroup sys + * @brief RIOT Registry String Path module providing functions to convert between registry objects and their string paths + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_STRING_PATH_H +#define REGISTRY_STRING_PATH_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + REGISTRY_STRING_PATH_TYPE_NAMESPACE, + REGISTRY_STRING_PATH_TYPE_SCHEMA, + REGISTRY_STRING_PATH_TYPE_INSTANCE, + REGISTRY_STRING_PATH_TYPE_GROUP, + REGISTRY_STRING_PATH_TYPE_PARAMETER, + REGISTRY_STRING_PATH_TYPE_GROUP_OR_PARAMETER, +}registry_string_path_type_t; + +#include "registry.h" + +/** + * @brief Converts a registry namespace object to its string path representation. + * + * @param[in] namespace The registry namespace object to convert. + * @param[out] path The buffer to store the resulting string path. + * + * @return Length of string path on success, non-zero on failure. + */ +int registry_to_namespace_string_path(const registry_namespace_t *namespace, char *path); + +/** + * @brief Converts a registry schema object to its string path representation. + * + * @param[in] schema The registry schema object to convert. + * @param[out] path The buffer to store the resulting string path. + * + * @return Length of string path on success, non-zero on failure. + */ +int registry_to_schema_string_path(const registry_schema_t *schema, char *path); + +/** + * @brief Converts a registry instance object to its string path representation. + * + * @param[in] instance The registry instance object to convert. + * @param[out] path The buffer to store the resulting string path. + * + * @return Length of string path on success, non-zero on failure. + */ +int registry_to_instance_string_path(const registry_instance_t *instance, char *path); + +/** + * @brief Converts a registry group object to its string path representation. + * + * @param[in] instance The registry instance object to which the group belongs. + * @param[in] group The registry group object to convert. + * @param[out] path The buffer to store the resulting string path. + * + * @return Length of string path on success, non-zero on failure. + */ +int registry_to_group_string_path(const registry_instance_t *instance, + const registry_group_t *group, char *path); + +/** + * @brief Converts a registry parameter object to its string path representation. + * + * @param[in] instance The registry instance object to which the parameter belongs. + * @param[in] parameter The registry parameter object to convert. + * @param[out] path The buffer to store the resulting string path. + * + * @return Length of string path on success, non-zero on failure. + */ +int registry_to_parameter_string_path(const registry_instance_t *instance, + const registry_parameter_t *parameter, char *path); + +/** + * @brief Converts a string path to a registry namespace object. + * + * @param[in] path The string path to convert. + * @param[out] namespace A pointer to the registry namespace object to be created. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_namespace_string_path(const char *path, registry_namespace_t **namespace); + +/** + * @brief Converts a string path to a registry schema object. + * + * @param[in] path The string path to convert. + * @param[out] namespace A pointer to the registry namespace object to be created. + * @param[out] schema A pointer to the registry schema object to be created. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_schema_string_path(const char *path, registry_namespace_t **namespace, + registry_schema_t **schema); + +/** + * @brief Converts a string path to a registry instance object. + * + * @param[in] path The string path to convert. + * @param[out] namespace A pointer to the registry namespace object to be created. + * @param[out] schema A pointer to the registry schema object to be created. + * @param[out] instance A pointer to the registry instance object to be created. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_instance_string_path(const char *path, registry_namespace_t **namespace, + registry_schema_t **schema, registry_instance_t **instance); + +/** + * @brief Converts a string path to a registry group object. + * + * @param[in] path The string path to convert. + * @param[out] namespace A pointer to the registry namespace object to be created. + * @param[out] schema A pointer to the registry schema object to be created. + * @param[out] instance A pointer to the registry instance object to which the group belongs. + * @param[out] group A pointer to the registry group object to be created. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_group_string_path(const char *path, registry_namespace_t **namespace, + registry_schema_t **schema, registry_instance_t **instance, + registry_group_t **group); + +/** + * @brief Converts a string path to a registry parameter object. + * + * @param[in] path The string path to convert. + * @param[out] namespace A pointer to the registry namespace object to be created. + * @param[out] schema A pointer to the registry schema object to be created. + * @param[out] instance A pointer to the registry instance object to which the parameter belongs. + * @param[out] parameter A pointer to the registry parameter object to be created. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_parameter_string_path(const char *path, registry_namespace_t **namespace, + registry_schema_t **schema, registry_instance_t **instance, + registry_parameter_t **parameter); + +/** + * @brief Converts a string path to either a registry group or a registry parameter object. + * + * @param[in] path The string path to convert. + * @param[out] path_type A pointer to the type of the resulting object. + * @param[out] namespace A pointer to the registry namespace object to be created. + * @param[out] schema A pointer to the registry schema object to be created. + * @param[out] instance A pointer to the registry instance object to which the group or parameter belongs. + * @param[out] group A pointer to the registry group object to be created. + * @param[out] parameter A pointer to the registry parameter object to be created. + * + * @return 0 on success, non-zero on failure. + */ +int registry_from_group_or_parameter_string_path(const char *path, + registry_string_path_type_t *path_type, + registry_namespace_t **namespace, + registry_schema_t **schema, + registry_instance_t **instance, + registry_group_t **group, + registry_parameter_t **parameter); + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_STRING_PATH_H */ +/** @} */ diff --git a/sys/registry/Kconfig b/sys/registry/Kconfig index 0a3ee90e9788..74835491887f 100644 --- a/sys/registry/Kconfig +++ b/sys/registry/Kconfig @@ -33,6 +33,9 @@ config REGISTRY_ENABLE_MAX_VALUE_CHECK config MODULE_REGISTRY_INT_PATH bool "Access configuration parameters via an integer path" +config MODULE_REGISTRY_STRING_PATH + bool "Access configuration parameters via a string path" + rsource "storage/Kconfig" endif # MODULE_REGISTRY \ No newline at end of file diff --git a/sys/registry/Makefile.include b/sys/registry/Makefile.include new file mode 100644 index 000000000000..2f8b6ebb115f --- /dev/null +++ b/sys/registry/Makefile.include @@ -0,0 +1,3 @@ +ifneq (,$(filter registry_string_path%,$(USEMODULE))) + CFLAGS += -DCONFIG_REGISTRY_ENABLE_META_NAME +endif \ No newline at end of file diff --git a/sys/registry/string_path.c b/sys/registry/string_path.c new file mode 100644 index 000000000000..4cff53f63a3b --- /dev/null +++ b/sys/registry/string_path.c @@ -0,0 +1,750 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_string_path RIOT Registry String Path + * @ingroup sys + * @brief RIOT Registry String Path module providing a API to access configuration parameter via a string path + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "clist.h" +#include "registry.h" +#include "registry/util.h" +#include "registry/error.h" + +#include "registry/string_path.h" + +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + +XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); + +static int _namespace_lookup(const char *path, registry_namespace_t **namespace) +{ + assert(path != NULL); + assert(namespace != NULL); + + char *ptr = (char *)path; + + /* remove '/' character */ + ptr++; + + for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { + const size_t name_length = strlen(_registry_namespaces_xfa[i]->name); + + /* check if length of path and name match */ + if (strlen(ptr) >= name_length) { + if (*(ptr + name_length) == '\0' || + *(ptr + name_length) == '/') { + /* check if strings are equal */ + if (strncmp(ptr, _registry_namespaces_xfa[i]->name, name_length) == 0) { + *namespace = _registry_namespaces_xfa[i]; + return name_length + 1; /* name_length + `/` character */ + } + } + } + } + + return -EINVAL; +} + +static int _schema_lookup(const char *path, const registry_namespace_t *namespace, + registry_schema_t **schema) +{ + assert(path != NULL); + assert(namespace != NULL); + assert(schema != NULL); + + char *ptr = (char *)path; + + /* remove '/' character */ + ptr++; + + for (size_t i = 0; i < namespace->schemas_len; i++) { + const size_t name_length = strlen(namespace->schemas[i]->name); + + /* check if length of path and name match */ + if (strlen(ptr) >= name_length) { + if (*(ptr + name_length) == '\0' || + *(ptr + name_length) == '/') { + /* check if strings are equal */ + if (strncmp(ptr, namespace->schemas[i]->name, name_length) == 0) { + *schema = (registry_schema_t *)namespace->schemas[i]; + return name_length + 1; /* name_length + `/` character */ + } + } + } + } + + return -EINVAL; +} + +static int _instance_lookup(const char *path, registry_schema_t *schema, + registry_instance_t **instance) +{ + assert(path != NULL); + assert(schema != NULL); + assert(instance != NULL); + + char *ptr = (char *)path; + + /* remove '/' character */ + ptr++; + + clist_node_t *node = schema->instances.next; + + if (!node) { + return -REGISTRY_ERROR_INSTANCE_NOT_FOUND; + } + + do { + node = node->next; + + const size_t name_length = strlen(container_of(node, registry_instance_t, node)->name); + + /* check if length of path and name match */ + if (strlen(ptr) >= name_length) { + if (*(ptr + name_length) == '\0' || + *(ptr + name_length) == '/') { + /* check if strings are equal */ + if (strncmp(ptr, container_of(node, registry_instance_t, node)->name, + name_length) == 0) { + *instance = container_of(node, registry_instance_t, node); + return name_length + 1; /* name_length + `/` character */ + } + } + } + } while (node != schema->instances.next); + + return -EINVAL; +} + +static int _group_lookup(const char *path, registry_schema_t *schema, registry_group_t **group) +{ + assert(path != NULL); + assert(schema != NULL); + assert(group != NULL); + + char *ptr = (char *)path; + + /* remove '/' character */ + ptr++; + + /* store the current path position */ + size_t path_position = 0; + + /* search for matching groups */ + bool found_subgroup = true; + registry_group_t **groups = (registry_group_t **)schema->groups; + size_t groups_len = schema->groups_len; + + while (found_subgroup) { + found_subgroup = false; + + for (size_t i = 0; i < groups_len; i++) { + const size_t name_length = strlen(groups[i]->name); + + /* path segment => save subgroups and keep searching them */ + if (strlen(ptr + path_position) >= name_length) { + if (*(ptr + path_position + name_length) == '/' && + strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { + if (groups[i]->groups_len > 0) { + found_subgroup = true; + groups = (registry_group_t **)groups[i]->groups; + groups_len = groups[i]->groups_len; + } + + path_position += name_length + 1; /* name_length + `/` character */ + break; + } + /* end of path => return group if it matches */ + else if (*(ptr + path_position + name_length) == '\0' && + strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { + *group = (registry_group_t *)groups[i]; + return path_position + name_length + 1; /* name_length + `/` character */ + } + } + } + } + + return -EINVAL; +} + +static int _parameter_lookup(const char *path, registry_schema_t *schema, + registry_parameter_t **parameter) +{ + assert(path != NULL); + assert(schema != NULL); + assert(parameter != NULL); + + char *ptr = (char *)path; + + /* remove '/' character */ + ptr++; + + /* store the current path position */ + size_t path_position = 0; + + /* search for matching parameters or groups */ + bool found_subgroup = true; + registry_parameter_t **parameters = (registry_parameter_t **)schema->parameters; + size_t parameters_len = schema->parameters_len; + + registry_group_t **groups = (registry_group_t **)schema->groups; + size_t groups_len = schema->groups_len; + + while (found_subgroup) { + found_subgroup = false; + + /* check for matching parameter */ + for (size_t i = 0; i < parameters_len; i++) { + const size_t name_length = strlen(parameters[i]->name); + + /* parameter matches => return parameters */ + if (strlen(ptr + path_position) == name_length && + strncmp(ptr + path_position, parameters[i]->name, name_length) == 0) { + *parameter = (registry_parameter_t *)parameters[i]; + return path_position + name_length + 1; /* name_length + `/` character */ + } + } + + /* check for matching subgroup */ + for (size_t i = 0; i < groups_len; i++) { + const size_t name_length = strlen(groups[i]->name); + + /* group matches => save subgroups and parameters and keep searching them */ + if (strlen(ptr + path_position) > name_length && + *(ptr + path_position + name_length) == '/' && + strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { + if (groups[i]->parameters_len > 0) { + found_subgroup = true; + parameters = (registry_parameter_t **)groups[i]->parameters; + parameters_len = groups[i]->parameters_len; + } + else { + parameters = NULL; + parameters_len = 0; + } + + if (groups[i]->groups_len > 0) { + found_subgroup = true; + groups = (registry_group_t **)groups[i]->groups; + groups_len = groups[i]->groups_len; + } + else { + groups = NULL; + groups_len = 0; + } + + path_position += name_length + 1; /* name_length + `/` character */ + break; + } + } + } + + return -EINVAL; +} + +static int _group_or_parameter_lookup(const char *path, registry_schema_t *schema, + registry_string_path_type_t *path_type, + registry_group_t **group, registry_parameter_t **parameter) +{ + assert(path != NULL); + assert(schema != NULL); + assert(parameter != NULL); + + char *ptr = (char *)path; + + /* remove '/' character */ + ptr++; + + /* store the current path position */ + size_t path_position = 0; + + /* search for matching parameters or groups */ + bool found_subgroup = true; + registry_parameter_t **parameters = (registry_parameter_t **)schema->parameters; + size_t parameters_len = schema->parameters_len; + + registry_group_t **groups = (registry_group_t **)schema->groups; + size_t groups_len = schema->groups_len; + + while (found_subgroup) { + /* check for matching parameter */ + for (size_t i = 0; i < parameters_len; i++) { + const size_t name_length = strlen(parameters[i]->name); + + /* parameter matches => return parameters */ + if (strlen(ptr + path_position) == name_length && + strncmp(ptr + path_position, parameters[i]->name, name_length) == 0) { + *parameter = (registry_parameter_t *)parameters[i]; + *path_type = REGISTRY_STRING_PATH_TYPE_PARAMETER; + return path_position + name_length + 1; /* name_length + `/` character */ + } + } + + /* check for matching subgroup */ + for (size_t i = 0; i < groups_len; i++) { + const size_t name_length = strlen(groups[i]->name); + + /* check if remaining path is at least longer than the group name */ + if (strlen(ptr + path_position) >= name_length) { + /* group matches but end of path is not reached => save subgroups and parameters and keep searching them */ + if (*(ptr + path_position + name_length) == '/' && + strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { + if (groups[i]->parameters_len > 0) { + found_subgroup = true; + parameters = (registry_parameter_t **)groups[i]->parameters; + parameters_len = groups[i]->parameters_len; + } + else { + parameters = NULL; + parameters_len = 0; + } + + if (groups[i]->groups_len > 0) { + found_subgroup = true; + groups = (registry_group_t **)groups[i]->groups; + groups_len = groups[i]->groups_len; + } + else { + groups = NULL; + groups_len = 0; + } + + path_position += name_length + 1; /* name_length + `/` character */ + break; + } + /* end of path => return group if it matches */ + else if (*(ptr + path_position + name_length) == '\0' && + strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { + *group = (registry_group_t *)groups[i]; + *path_type = REGISTRY_STRING_PATH_TYPE_GROUP; + return path_position + name_length + 1; /* name_length + `/` character */ + } + } + } + } + + return -EINVAL; +} + +/* to string_path */ +int registry_to_namespace_string_path(const registry_namespace_t *namespace, char *path) +{ + int size = snprintf(NULL, 0, "/%s", namespace->name); + + if (path != NULL) { + return snprintf(path, size + 1, "/%s", namespace->name); + } + + return size; +} + +int registry_to_schema_string_path(const registry_schema_t *schema, char *path) +{ + int size = snprintf(NULL, 0, "/%s/%s", schema->namespace->name, schema->name); + + if (path != NULL) { + return snprintf(path, size + 1, "/%s/%s", schema->namespace->name, schema->name); + } + + return size; +} + +int registry_to_instance_string_path(const registry_instance_t *instance, char *path) +{ + int size = snprintf(NULL, 0, "/%s/%s/%s", instance->schema->namespace->name, + instance->schema->name, instance->name); + + if (path != NULL) { + return snprintf(path, size + 1, "/%s/%s/%s", instance->schema->namespace->name, + instance->schema->name, instance->name); + } + + return size; +} + +static int _internal_registry_to_group_string_path(const registry_group_t *current_group, + const registry_group_t *group, char *path) +{ + int size = snprintf(NULL, 0, "/%s", current_group->name); + + if (path != NULL) { + snprintf(path, size + 1, "/%s", current_group->name); + } + + if (group == current_group) { + return size; + } + + for (size_t i = 0; i < current_group->groups_len; i++) { + int res = _internal_registry_to_group_string_path(current_group->groups[i], group, + path != NULL ? path + size : NULL); + if (res >= 0) { + return size + res; + } + } + + return -EINVAL; +} + +int registry_to_group_string_path(const registry_instance_t *instance, + const registry_group_t *group, char *path) +{ + int size = snprintf(NULL, 0, "/%s/%s/%s", instance->schema->namespace->name, + instance->schema->name, instance->name); + + if (path != NULL) { + snprintf(path, size + 1, "/%s/%s/%s", instance->schema->namespace->name, + instance->schema->name, instance->name); + } + + for (size_t i = 0; i < instance->schema->groups_len; i++) { + int res = _internal_registry_to_group_string_path(instance->schema->groups[i], group, + path != NULL ? path + size : NULL); + if (res >= 0) { + return size += res; + } + } + + return -EINVAL; +} + +static int _internal_registry_to_parameter_string_path(const registry_group_t *current_group, + const registry_parameter_t *parameter, + char *path) +{ + int size = snprintf(NULL, 0, "/%s", current_group->name); + + if (path != NULL) { + snprintf(path, size + 1, "/%s", current_group->name); + } + + /* check if the parameter is a child of this group */ + for (size_t i = 0; i < current_group->parameters_len; i++) { + if (current_group->parameters[i] == parameter) { + int sub_size = snprintf(NULL, 0, "/%s", current_group->parameters[i]->name); + + if (path != NULL) { + snprintf(path + size, sub_size + 1, "/%s", current_group->parameters[i]->name); + } + + return size + sub_size; + } + } + + /* check if the parameter is the child of a subgroup */ + for (size_t i = 0; i < current_group->groups_len; i++) { + int res = _internal_registry_to_parameter_string_path(current_group->groups[i], parameter, + path != NULL ? path + size : NULL); + if (res >= 0) { + return size + res; + } + } + + return -EINVAL; +} + +int registry_to_parameter_string_path(const registry_instance_t *instance, + const registry_parameter_t *parameter, char *path) +{ + int size = snprintf(NULL, 0, "/%s/%s/%s", instance->schema->namespace->name, + instance->schema->name, instance->name); + + if (path != NULL) { + snprintf(path, size + 1, "/%s/%s/%s", instance->schema->namespace->name, + instance->schema->name, instance->name); + } + + /* check if the parameter is a child of this schema */ + for (size_t i = 0; i < instance->schema->parameters_len; i++) { + if (instance->schema->parameters[i] == parameter) { + int sub_size = snprintf(NULL, 0, "/%s", instance->schema->parameters[i]->name); + + if (path != NULL) { + snprintf(path + size, sub_size + 1, "/%s", instance->schema->parameters[i]->name); + } + + return size + sub_size; + } + } + + /* check if the parameter is the child of a group */ + for (size_t i = 0; i < instance->schema->groups_len; i++) { + int res = _internal_registry_to_parameter_string_path(instance->schema->groups[i], + parameter, + path != NULL ? path + size : NULL); + if (res >= 0) { + return size += res; + } + } + + return -EINVAL; +} + +/* from string_path */ +int registry_from_namespace_string_path(const char *path, registry_namespace_t **namespace) +{ + /* namespace */ + int res = _namespace_lookup(path, namespace); + + if (res < 0) { + return res; + } + + return 0; +} + +int registry_from_schema_string_path(const char *path, registry_namespace_t **namespace, + registry_schema_t **schema) +{ + /* store the current path position */ + size_t path_position = 0; + + /* namespace */ + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path, &found_namespace); + + if (res >= 0) { + path_position += res; + + if (namespace != NULL) { + *namespace = found_namespace; + } + + /* schema */ + res = _schema_lookup(path + path_position, found_namespace, schema); + } + + if (res < 0) { + return res; + } + + return 0; +} + +int registry_from_instance_string_path(const char *path, registry_namespace_t **namespace, + registry_schema_t **schema, registry_instance_t **instance) +{ + /* store the current path position */ + size_t path_position = 0; + + /* namespace */ + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path, &found_namespace); + + if (res >= 0) { + path_position += res; + + if (namespace != NULL) { + *namespace = found_namespace; + } + + /* schema */ + registry_schema_t *found_schema; + res = _schema_lookup(path + path_position, found_namespace, &found_schema); + + if (res >= 0) { + path_position += res; + + if (schema != NULL) { + *schema = found_schema; + } + + /* instance */ + res = _instance_lookup(path + path_position, found_schema, instance); + } + } + + if (res < 0) { + return res; + } + + return 0; +} + +int registry_from_group_string_path(const char *path, registry_namespace_t **namespace, + registry_schema_t **schema, registry_instance_t **instance, + registry_group_t **group) +{ + /* store the current path position */ + size_t path_position = 0; + + /* namespace */ + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path, &found_namespace); + + if (res >= 0) { + path_position += res; + + if (namespace != NULL) { + *namespace = found_namespace; + } + + /* schema */ + registry_schema_t *found_schema; + res = _schema_lookup(path + path_position, found_namespace, &found_schema); + + if (res >= 0) { + path_position += res; + + if (schema != NULL) { + *schema = found_schema; + } + + /* instance */ + registry_instance_t *found_instance; + res = _instance_lookup(path + path_position, found_schema, &found_instance); + + if (res >= 0) { + path_position += res; + + if (instance != NULL) { + *instance = found_instance; + } + + /* group */ + res = _group_lookup(path + path_position, found_schema, group); + } + } + } + + if (res < 0) { + return res; + } + + return 0; +} + +int registry_from_parameter_string_path(const char *path, registry_namespace_t **namespace, + registry_schema_t **schema, registry_instance_t **instance, + registry_parameter_t **parameter) +{ + /* store the current path position */ + size_t path_position = 0; + + /* namespace */ + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path, &found_namespace); + + if (res >= 0) { + path_position += res; + + if (namespace != NULL) { + *namespace = found_namespace; + } + + /* schema */ + registry_schema_t *found_schema; + res = _schema_lookup(path + path_position, found_namespace, &found_schema); + + if (res >= 0) { + path_position += res; + + if (schema != NULL) { + *schema = found_schema; + } + + /* instance */ + registry_instance_t *found_instance; + res = _instance_lookup(path + path_position, found_schema, &found_instance); + + if (res >= 0) { + path_position += res; + + if (instance != NULL) { + *instance = found_instance; + } + + /* parameter */ + res = _parameter_lookup(path + path_position, found_schema, parameter); + } + } + } + + if (res < 0) { + return res; + } + + return 0; +} + +int registry_from_group_or_parameter_string_path(const char *path, + registry_string_path_type_t *path_type, + registry_namespace_t **namespace, + registry_schema_t **schema, + registry_instance_t **instance, + registry_group_t **group, + registry_parameter_t **parameter) +{ + /* store the current path position */ + size_t path_position = 0; + + /* namespace */ + registry_namespace_t *found_namespace; + int res = _namespace_lookup(path, &found_namespace); + + if (res >= 0) { + path_position += res; + + if (namespace != NULL) { + *namespace = found_namespace; + } + + /* schema */ + registry_schema_t *found_schema; + res = _schema_lookup(path + path_position, found_namespace, &found_schema); + + if (res >= 0) { + path_position += res; + + if (schema != NULL) { + *schema = found_schema; + } + + /* instance */ + registry_instance_t *found_instance; + res = _instance_lookup(path + path_position, found_schema, &found_instance); + + if (res >= 0) { + path_position += res; + + if (instance != NULL) { + *instance = found_instance; + } + + /* group or parameter */ + res = _group_or_parameter_lookup(path + path_position, found_schema, path_type, + group, parameter); + } + } + } + + if (res < 0) { + return res; + } + + return 0; +} + +#endif From f38a7363636ef46a6a60d26e6677ced0115439a3 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 19:55:37 +0200 Subject: [PATCH 005/117] sys/registry: add sys namespace --- makefiles/pseudomodules.inc.mk | 1 + sys/include/registry/namespace/sys.h | 40 +++ sys/include/registry/namespace/sys/rgb_led.h | 65 ++++ sys/registry/Makefile | 4 + sys/registry/Makefile.dep | 4 + sys/registry/namespace/Kconfig | 18 ++ sys/registry/namespace/Makefile | 5 + sys/registry/namespace/Makefile.dep | 3 + sys/registry/namespace/sys/Kconfig | 19 ++ sys/registry/namespace/sys/Makefile | 9 + sys/registry/namespace/sys/Makefile.dep | 4 + .../sys/definitions/0001_rgb_led.yaml | 40 +++ sys/registry/namespace/sys/namespace_sys.c | 49 +++ .../namespace/sys/namespace_sys_rgb_led.c | 278 ++++++++++++++++++ 14 files changed, 539 insertions(+) create mode 100644 sys/include/registry/namespace/sys.h create mode 100644 sys/include/registry/namespace/sys/rgb_led.h create mode 100644 sys/registry/namespace/Kconfig create mode 100644 sys/registry/namespace/Makefile create mode 100644 sys/registry/namespace/Makefile.dep create mode 100644 sys/registry/namespace/sys/Kconfig create mode 100644 sys/registry/namespace/sys/Makefile create mode 100644 sys/registry/namespace/sys/Makefile.dep create mode 100644 sys/registry/namespace/sys/definitions/0001_rgb_led.yaml create mode 100644 sys/registry/namespace/sys/namespace_sys.c create mode 100644 sys/registry/namespace/sys/namespace_sys_rgb_led.c diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index f1896f4b777d..2d860d196f84 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -397,6 +397,7 @@ PSEUDOMODULES += fortuna_reseed PSEUDOMODULES += random_cmd ## @} PSEUDOMODULES += registry_% +NO_PSEUDOMODULES += registry_namespace_sys NO_PSEUDOMODULES += registry_storage PSEUDOMODULES += riotboot_% diff --git a/sys/include/registry/namespace/sys.h b/sys/include/registry/namespace/sys.h new file mode 100644 index 000000000000..e88b68548d2a --- /dev/null +++ b/sys/include/registry/namespace/sys.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_sys RIOT Registry Sys Namespace + * @ingroup sys + * @brief RIOT Registry Namespace Sys module providing common sys configuration schemas for the RIOT Registry sys module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_SYS_H +#define REGISTRY_NAMESPACE_SYS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +extern registry_namespace_t registry_sys; + +typedef enum { + REGISTRY_SYS_RGB_LED, +} registry_sys_indices_t; + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_NAMESPACE_SYS_H */ +/** @} */ diff --git a/sys/include/registry/namespace/sys/rgb_led.h b/sys/include/registry/namespace/sys/rgb_led.h new file mode 100644 index 000000000000..2b485b0c0c72 --- /dev/null +++ b/sys/include/registry/namespace/sys/rgb_led.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_sys_rgb_led RIOT Registry Schema: RGB_LED + * @ingroup sys + * @brief RIOT Registry RGB_LED Schema representing the basic structure of an RGB LED + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_SYS_RGB_LED_H +#define REGISTRY_NAMESPACE_SYS_RGB_LED_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/* RGB-LED */ +#if IS_USED(MODULE_REGISTRY_NAMESPACE_SYS_RGB_LED) || IS_ACTIVE(DOXYGEN) + +extern const registry_parameter_t registry_sys_rgb_led_red; +extern const registry_parameter_t registry_sys_rgb_led_green; +extern const registry_parameter_t registry_sys_rgb_led_blue; +extern const registry_parameter_t registry_sys_rgb_led_brightnesses_white; +extern const registry_parameter_t registry_sys_rgb_led_brightnesses_yellow; +extern const registry_group_t registry_sys_rgb_led_brightnesses; +extern registry_schema_t registry_sys_rgb_led; + +typedef struct { + clist_node_t node; + uint8_t red; + uint8_t green; + uint8_t blue; + uint8_t white; + uint8_t yellow; +} registry_sys_rgb_led_instance_t; + +typedef const enum { + REGISTRY_SYS_RGB_LED_RED, + REGISTRY_SYS_RGB_LED_GREEN, + REGISTRY_SYS_RGB_LED_BLUE, + REGISTRY_SYS_RGB_LED_BRIGHTNESSES, + REGISTRY_SYS_RGB_LED_BRIGHTNESSES_WHITE, + REGISTRY_SYS_RGB_LED_BRIGHTNESSES_YELLOW, +} registry_sys_rgb_led_indices_t; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_NAMESPACE_SYS_RGB_LED_H */ +/** @} */ diff --git a/sys/registry/Makefile b/sys/registry/Makefile index 2cc24520ed7d..8baff91961c2 100644 --- a/sys/registry/Makefile +++ b/sys/registry/Makefile @@ -2,6 +2,10 @@ SRC := registry.c util.c init.c SUBMODULES := 1 +ifneq (,$(filter registry_namespace_%,$(USEMODULE))) + DIRS += namespace +endif + ifneq (,$(filter registry_storage%,$(USEMODULE))) DIRS += storage endif diff --git a/sys/registry/Makefile.dep b/sys/registry/Makefile.dep index bd58b563899c..65bb23a61bb7 100644 --- a/sys/registry/Makefile.dep +++ b/sys/registry/Makefile.dep @@ -1,3 +1,7 @@ +ifneq (,$(filter registry_namespace%,$(USEMODULE))) + include $(RIOTBASE)/sys/registry/namespace/Makefile.dep +endif + ifneq (,$(filter registry_storage%,$(USEMODULE))) include $(RIOTBASE)/sys/registry/storage/Makefile.dep endif diff --git a/sys/registry/namespace/Kconfig b/sys/registry/namespace/Kconfig new file mode 100644 index 000000000000..82a1406d7253 --- /dev/null +++ b/sys/registry/namespace/Kconfig @@ -0,0 +1,18 @@ +# Copyright (c) 2023 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +menuconfig MODULE_REGISTRY_NAMESPACE + bool "REGISTRY_NAMESPACE" + depends on MODULE_REGISTRY + help + Namespace module containing default namespaces for the RIOT Registry sys module. + +if MODULE_REGISTRY_NAMESPACE + +rsource "sys/Kconfig" + +endif # MODULE_REGISTRY_NAMESPACE diff --git a/sys/registry/namespace/Makefile b/sys/registry/namespace/Makefile new file mode 100644 index 000000000000..45c14481c0a3 --- /dev/null +++ b/sys/registry/namespace/Makefile @@ -0,0 +1,5 @@ +ifneq (,$(filter registry_namespace_sys%,$(USEMODULE))) + DIRS += sys +endif + +include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/sys/registry/namespace/Makefile.dep b/sys/registry/namespace/Makefile.dep new file mode 100644 index 000000000000..e8a0f1b07c53 --- /dev/null +++ b/sys/registry/namespace/Makefile.dep @@ -0,0 +1,3 @@ +ifneq (,$(filter registry_namespace_sys%,$(USEMODULE))) + include $(RIOTBASE)/sys/registry/namespace/sys/Makefile.dep +endif diff --git a/sys/registry/namespace/sys/Kconfig b/sys/registry/namespace/sys/Kconfig new file mode 100644 index 000000000000..beae57dfe2f7 --- /dev/null +++ b/sys/registry/namespace/sys/Kconfig @@ -0,0 +1,19 @@ +# Copyright (c) 2023 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +menuconfig MODULE_REGISTRY_NAMESPACE_SYS + bool "REGISTRY_NAMESPACE_SYS" + depends on MODULE_REGISTRY_NAMESPACE + help + Namespace Sys module providing common sys configuration schemas for the RIOT Registry sys module. + +if MODULE_REGISTRY_NAMESPACE_SYS + +config MODULE_REGISTRY_NAMESPACE_SYS_RGB_LED + bool "RGB LED schema" + +endif # MODULE_REGISTRY_NAMESPACE_SYS \ No newline at end of file diff --git a/sys/registry/namespace/sys/Makefile b/sys/registry/namespace/sys/Makefile new file mode 100644 index 000000000000..1389ac65a12d --- /dev/null +++ b/sys/registry/namespace/sys/Makefile @@ -0,0 +1,9 @@ +MODULE := registry_namespace_sys + +BASE_MODULE := registry + +SRC := namespace_sys.c + +SUBMODULES := 1 + +include $(RIOTBASE)/Makefile.base diff --git a/sys/registry/namespace/sys/Makefile.dep b/sys/registry/namespace/sys/Makefile.dep new file mode 100644 index 000000000000..b475297bcfe9 --- /dev/null +++ b/sys/registry/namespace/sys/Makefile.dep @@ -0,0 +1,4 @@ +# Enable "registry_namespace_sys" module for all schemas +ifneq (,$(filter registry_namespace_sys_%,$(USEMODULE))) + USEMODULE += registry_namespace_sys +endif diff --git a/sys/registry/namespace/sys/definitions/0001_rgb_led.yaml b/sys/registry/namespace/sys/definitions/0001_rgb_led.yaml new file mode 100644 index 000000000000..04c24cbf1c50 --- /dev/null +++ b/sys/registry/namespace/sys/definitions/0001_rgb_led.yaml @@ -0,0 +1,40 @@ +# yaml-language-server: $schema=../../../../../dist/tools/registry_gen/schema.json +id: 1 +name: rgb +description: Representation of an rgb color. +items: + - id: 0 + name: red + description: Intensity of the red color of the rgb lamp. + type: uint8 + + - id: 1 + name: green + description: Intensity of the green color of the rgb lamp. + type: uint8 + + - id: 2 + name: blue + description: Intensity of the blue color of the rgb lamp. + type: uint8 + + - id: 3 + name: brightnesses + description: Brightness of the rgb lamp. + type: group + items: + - id: 4 + name: yellow + description: Brightness of the yellow color of the rgb lamp. + type: uint8 + + - id: 5 + name: white + description: Brightness of the white color of the rgb lamp. + type: uint8 + + - id: 6 + name: string + description: Intensity of the blue color of the rgb lamp. + type: string + size: 20 diff --git a/sys/registry/namespace/sys/namespace_sys.c b/sys/registry/namespace/sys/namespace_sys.c new file mode 100644 index 000000000000..d390d5046de4 --- /dev/null +++ b/sys/registry/namespace/sys/namespace_sys.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_schema RIOT Registry Schema + * @ingroup sys + * @brief RIOT Registry Schema module providing common sys configuration schemas for the RIOT Registry sys module + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" + +#include "registry/namespace/sys.h" +#include "registry/namespace/sys/rgb_led.h" + +static const registry_schema_t *_schemas[] = { +#if IS_USED(MODULE_REGISTRY_NAMESPACE_SYS_RGB_LED) + ®istry_sys_rgb_led, +#endif +}; + +registry_namespace_t registry_sys = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "sys", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "Sys namespace", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schemas = _schemas, + .schemas_len = ARRAY_SIZE(_schemas), +}; + +REGISTRY_ADD_NAMESPACE(sys, registry_sys); diff --git a/sys/registry/namespace/sys/namespace_sys_rgb_led.c b/sys/registry/namespace/sys/namespace_sys_rgb_led.c new file mode 100644 index 000000000000..b040ff13247d --- /dev/null +++ b/sys/registry/namespace/sys/namespace_sys_rgb_led.c @@ -0,0 +1,278 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_sys_rgb_led RIOT Registry Schema: RGB_LED + * @ingroup sys + * @brief RIOT Registry RGB_LED Schema representing the basic structure of an RGB LED + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" +#include "registry/namespace/sys.h" + +#include "registry/namespace/sys/rgb_led.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_SYS_RGB_LED) || IS_ACTIVE(DOXYGEN) + +/* Mapping */ +static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, + void **val, size_t *val_len) +{ + registry_sys_rgb_led_instance_t *_instance = + (registry_sys_rgb_led_instance_t *)instance->data; + + switch (parameter_id) { + case REGISTRY_SYS_RGB_LED_RED: + *val = &_instance->red; + *val_len = sizeof(_instance->red); + break; + + case REGISTRY_SYS_RGB_LED_GREEN: + *val = &_instance->green; + *val_len = sizeof(_instance->green); + break; + + case REGISTRY_SYS_RGB_LED_BLUE: + *val = &_instance->blue; + *val_len = sizeof(_instance->blue); + break; + + case REGISTRY_SYS_RGB_LED_BRIGHTNESSES_WHITE: + *val = &_instance->white; + *val_len = sizeof(_instance->white); + break; + + case REGISTRY_SYS_RGB_LED_BRIGHTNESSES_YELLOW: + *val = &_instance->yellow; + *val_len = sizeof(_instance->yellow); + break; + } +} + +/* Schema */ +const registry_parameter_t registry_sys_rgb_led_red = { + .id = REGISTRY_SYS_RGB_LED_RED, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "red", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_sys_rgb_led, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_sys_rgb_led_green = { + .id = REGISTRY_SYS_RGB_LED_GREEN, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "green", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_sys_rgb_led, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_sys_rgb_led_blue = { + .id = REGISTRY_SYS_RGB_LED_BLUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "blue", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_sys_rgb_led, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_sys_rgb_led_brightnesses_white = { + .id = REGISTRY_SYS_RGB_LED_BRIGHTNESSES_WHITE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "white", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_sys_rgb_led, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_sys_rgb_led_brightnesses_yellow = { + .id = REGISTRY_SYS_RGB_LED_BRIGHTNESSES_YELLOW, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "yellow", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_sys_rgb_led, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_group_t registry_sys_rgb_led_brightnesses = { + .id = REGISTRY_SYS_RGB_LED_BRIGHTNESSES, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "brightnesses", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_sys_rgb_led, + .groups = NULL, + .groups_len = 0, + .parameters = (const registry_parameter_t *[]) { + ®istry_sys_rgb_led_brightnesses_white, + ®istry_sys_rgb_led_brightnesses_yellow, + }, + .parameters_len = 2, +}; + +registry_schema_t registry_sys_rgb_led = { + .id = REGISTRY_SYS_RGB_LED, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "rgb_led", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .namespace = ®istry_sys, + .mapping = mapping, + .groups = (const registry_group_t *[]) { + ®istry_sys_rgb_led_brightnesses, + }, + .groups_len = 1, + .parameters = (const registry_parameter_t *[]) { + ®istry_sys_rgb_led_red, + ®istry_sys_rgb_led_green, + ®istry_sys_rgb_led_blue, + }, + .parameters_len = 3, +}; + +#endif From cd6cd1b8d87a8568281d7998741ada8ad5dca910 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:11:19 +0200 Subject: [PATCH 006/117] sys/registry: add tests namespace --- sys/include/registry/namespace/tests.h | 44 ++ .../tests/constrained_allowed_values.h | 98 +++ .../tests/constrained_forbidden_values.h | 98 +++ .../namespace/tests/constrained_min_max.h | 98 +++ sys/include/registry/namespace/tests/full.h | 98 +++ sys/include/registry/namespace/tests/nested.h | 61 ++ sys/registry/Kconfig | 3 +- sys/registry/namespace/Kconfig | 3 +- sys/registry/namespace/Makefile | 4 + sys/registry/namespace/Makefile.dep | 4 + sys/registry/namespace/tests/Kconfig | 19 + sys/registry/namespace/tests/Makefile | 9 + sys/registry/namespace/tests/Makefile.dep | 4 + .../tests/definitions/0001_full.yaml | 71 +++ .../tests/definitions/0002_constrained.yaml | 132 +++++ .../namespace/tests/namespace_tests.c | 63 ++ ...mespace_tests_constrained_allowed_values.c | 557 ++++++++++++++++++ ...space_tests_constrained_forbidden_values.c | 544 +++++++++++++++++ .../namespace_tests_constrained_min_max.c | 544 +++++++++++++++++ .../namespace/tests/namespace_tests_full.c | 544 +++++++++++++++++ .../namespace/tests/namespace_tests_nested.c | 148 +++++ 21 files changed, 3144 insertions(+), 2 deletions(-) create mode 100644 sys/include/registry/namespace/tests.h create mode 100644 sys/include/registry/namespace/tests/constrained_allowed_values.h create mode 100644 sys/include/registry/namespace/tests/constrained_forbidden_values.h create mode 100644 sys/include/registry/namespace/tests/constrained_min_max.h create mode 100644 sys/include/registry/namespace/tests/full.h create mode 100644 sys/include/registry/namespace/tests/nested.h create mode 100644 sys/registry/namespace/tests/Kconfig create mode 100644 sys/registry/namespace/tests/Makefile create mode 100644 sys/registry/namespace/tests/Makefile.dep create mode 100644 sys/registry/namespace/tests/definitions/0001_full.yaml create mode 100644 sys/registry/namespace/tests/definitions/0002_constrained.yaml create mode 100644 sys/registry/namespace/tests/namespace_tests.c create mode 100644 sys/registry/namespace/tests/namespace_tests_constrained_allowed_values.c create mode 100644 sys/registry/namespace/tests/namespace_tests_constrained_forbidden_values.c create mode 100644 sys/registry/namespace/tests/namespace_tests_constrained_min_max.c create mode 100644 sys/registry/namespace/tests/namespace_tests_full.c create mode 100644 sys/registry/namespace/tests/namespace_tests_nested.c diff --git a/sys/include/registry/namespace/tests.h b/sys/include/registry/namespace/tests.h new file mode 100644 index 000000000000..1cb60a453e1c --- /dev/null +++ b/sys/include/registry/namespace/tests.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests RIOT Registry Tests Namespace + * @ingroup tests + * @brief RIOT Registry Namespace Tests module providing common tests configuration schemas for the RIOT Registry sys module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_TESTS_H +#define REGISTRY_NAMESPACE_TESTS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +extern registry_namespace_t registry_tests; + +typedef enum { + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_VALUES, + REGISTRY_TESTS_FULL, + REGISTRY_TESTS_NESTED, +} registry_tests_indices_t; + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_NAMESPACE_TESTS_H */ +/** @} */ diff --git a/sys/include/registry/namespace/tests/constrained_allowed_values.h b/sys/include/registry/namespace/tests/constrained_allowed_values.h new file mode 100644 index 000000000000..ba9abd168fe1 --- /dev/null +++ b/sys/include/registry/namespace/tests/constrained_allowed_values.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_constrained_allowed_values RIOT Registry Schema: Constrained Allowed Values + * @ingroup sys + * @brief RIOT Registry Constrained Allowed Values Schema representing all possible data types of the riot registry with allowed values constraints + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES_H +#define REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/* CONSTRAINED_ALLOWED_VALUES */ +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES) || IS_ACTIVE(DOXYGEN) + +extern const registry_parameter_t registry_tests_constrained_allowed_values_opaque; +extern const registry_parameter_t registry_tests_constrained_allowed_values_string; +extern const registry_parameter_t registry_tests_constrained_allowed_values_boolean; +extern const registry_parameter_t registry_tests_constrained_allowed_values_u8; +extern const registry_parameter_t registry_tests_constrained_allowed_values_u16; +extern const registry_parameter_t registry_tests_constrained_allowed_values_u32; +extern const registry_parameter_t registry_tests_constrained_allowed_values_u64; +extern const registry_parameter_t registry_tests_constrained_allowed_values_i8; +extern const registry_parameter_t registry_tests_constrained_allowed_values_i16; +extern const registry_parameter_t registry_tests_constrained_allowed_values_i32; +extern const registry_parameter_t registry_tests_constrained_allowed_values_i64; +extern const registry_parameter_t registry_tests_constrained_allowed_values_f32; +extern const registry_parameter_t registry_tests_constrained_allowed_values_f64; +extern registry_schema_t registry_tests_constrained_allowed_values; + +typedef struct { + uint8_t value; +} registry_tests_constrained_allowed_values_instance_opaque_t; + +typedef struct { + clist_node_t node; + + registry_tests_constrained_allowed_values_instance_opaque_t opaque; + char string[50]; + bool boolean; + + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + + int8_t i8; + int16_t i16; + int32_t i32; + int64_t i64; + + float f32; + double f64; +} registry_tests_constrained_allowed_values_instance_t; + +typedef enum { + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_OPAQUE, + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_STRING, + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_BOOLEAN, + + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U8, + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U16, + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U32, + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U64, + + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I8, + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I16, + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I32, + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I64, + + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F32, + REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F64, +} registry_tests_constrained_allowed_values_indices_t; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* CONSTRAINED_ALLOWED_VALUES */ +/** @} */ diff --git a/sys/include/registry/namespace/tests/constrained_forbidden_values.h b/sys/include/registry/namespace/tests/constrained_forbidden_values.h new file mode 100644 index 000000000000..3d6eb4c6a57d --- /dev/null +++ b/sys/include/registry/namespace/tests/constrained_forbidden_values.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_constrained_forbidden_values RIOT Registry Schema: Constrained Forbidden Values + * @ingroup sys + * @brief RIOT Registry Constrained Forbidden Values Schema representing all possible data types of the riot registry with forbidden values constraints + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES_H +#define REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/* CONSTRAINED_FORBIDDEN_VALUES */ +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES) || IS_ACTIVE(DOXYGEN) + +extern const registry_parameter_t registry_tests_constrained_forbidden_values_opaque; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_string; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_boolean; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_u8; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_u16; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_u32; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_u64; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_i8; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_i16; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_i32; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_i64; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_f32; +extern const registry_parameter_t registry_tests_constrained_forbidden_values_f64; +extern registry_schema_t registry_tests_constrained_forbidden_values; + +typedef struct { + uint8_t value; +} registry_tests_constrained_forbidden_values_instance_opaque_t; + +typedef struct { + clist_node_t node; + + registry_tests_constrained_forbidden_values_instance_opaque_t opaque; + char string[50]; + bool boolean; + + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + + int8_t i8; + int16_t i16; + int32_t i32; + int64_t i64; + + float f32; + double f64; +} registry_tests_constrained_forbidden_values_instance_t; + +typedef enum { + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_OPAQUE, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_STRING, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_BOOLEAN, + + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U8, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U16, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U32, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U64, + + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I8, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I16, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I32, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I64, + + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F32, + REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F64, +} registry_tests_constrained_forbidden_values_indices_t; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* CONSTRAINED_FORBIDDEN_VALUES */ +/** @} */ diff --git a/sys/include/registry/namespace/tests/constrained_min_max.h b/sys/include/registry/namespace/tests/constrained_min_max.h new file mode 100644 index 000000000000..0dd44d5fce5c --- /dev/null +++ b/sys/include/registry/namespace/tests/constrained_min_max.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_constrained_min_max RIOT Registry Schema: Constrained Min Max + * @ingroup sys + * @brief RIOT Registry Constrained Min Max Schema representing all possible data types of the riot registry with minimum and maximum value constraints + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX_H +#define REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/* CONSTRAINED_MIN_MAX */ +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX) || IS_ACTIVE(DOXYGEN) + +extern const registry_parameter_t registry_tests_constrained_min_max_opaque; +extern const registry_parameter_t registry_tests_constrained_min_max_string; +extern const registry_parameter_t registry_tests_constrained_min_max_boolean; +extern const registry_parameter_t registry_tests_constrained_min_max_u8; +extern const registry_parameter_t registry_tests_constrained_min_max_u16; +extern const registry_parameter_t registry_tests_constrained_min_max_u32; +extern const registry_parameter_t registry_tests_constrained_min_max_u64; +extern const registry_parameter_t registry_tests_constrained_min_max_i8; +extern const registry_parameter_t registry_tests_constrained_min_max_i16; +extern const registry_parameter_t registry_tests_constrained_min_max_i32; +extern const registry_parameter_t registry_tests_constrained_min_max_i64; +extern const registry_parameter_t registry_tests_constrained_min_max_f32; +extern const registry_parameter_t registry_tests_constrained_min_max_f64; +extern registry_schema_t registry_tests_constrained_min_max; + +typedef struct { + uint8_t value; +} registry_tests_constrained_min_max_instance_opaque_t; + +typedef struct { + clist_node_t node; + + registry_tests_constrained_min_max_instance_opaque_t opaque; + char string[50]; + bool boolean; + + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + + int8_t i8; + int16_t i16; + int32_t i32; + int64_t i64; + + float f32; + double f64; +} registry_tests_constrained_min_max_instance_t; + +typedef enum { + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_OPAQUE, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_STRING, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_BOOLEAN, + + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U8, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U16, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U32, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U64, + + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I8, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I16, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I32, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I64, + + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F32, + REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F64, +} registry_tests_constrained_min_max_indices_t; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* CONSTRAINED_MIN_MAX */ +/** @} */ diff --git a/sys/include/registry/namespace/tests/full.h b/sys/include/registry/namespace/tests/full.h new file mode 100644 index 000000000000..1201b02006b0 --- /dev/null +++ b/sys/include/registry/namespace/tests/full.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_full RIOT Registry Schema: Full + * @ingroup sys + * @brief RIOT Registry Full Schema representing all possible data types of the riot registry + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_TESTS_FULL_H +#define REGISTRY_NAMESPACE_TESTS_FULL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/* FULL */ +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) || IS_ACTIVE(DOXYGEN) + +extern const registry_parameter_t registry_tests_full_opaque; +extern const registry_parameter_t registry_tests_full_string; +extern const registry_parameter_t registry_tests_full_boolean; +extern const registry_parameter_t registry_tests_full_u8; +extern const registry_parameter_t registry_tests_full_u16; +extern const registry_parameter_t registry_tests_full_u32; +extern const registry_parameter_t registry_tests_full_u64; +extern const registry_parameter_t registry_tests_full_i8; +extern const registry_parameter_t registry_tests_full_i16; +extern const registry_parameter_t registry_tests_full_i32; +extern const registry_parameter_t registry_tests_full_i64; +extern const registry_parameter_t registry_tests_full_f32; +extern const registry_parameter_t registry_tests_full_f64; +extern registry_schema_t registry_tests_full; + +typedef struct { + uint8_t value; +} registry_tests_full_instance_opaque_t; + +typedef struct { + clist_node_t node; + + registry_tests_full_instance_opaque_t opaque; + char string[50]; + bool boolean; + + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + + int8_t i8; + int16_t i16; + int32_t i32; + int64_t i64; + + float f32; + double f64; +} registry_tests_full_instance_t; + +typedef enum { + REGISTRY_TESTS_FULL_OPAQUE, + REGISTRY_TESTS_FULL_STRING, + REGISTRY_TESTS_FULL_BOOLEAN, + + REGISTRY_TESTS_FULL_U8, + REGISTRY_TESTS_FULL_U16, + REGISTRY_TESTS_FULL_U32, + REGISTRY_TESTS_FULL_U64, + + REGISTRY_TESTS_FULL_I8, + REGISTRY_TESTS_FULL_I16, + REGISTRY_TESTS_FULL_I32, + REGISTRY_TESTS_FULL_I64, + + REGISTRY_TESTS_FULL_F32, + REGISTRY_TESTS_FULL_F64, +} registry_tests_full_indices_t; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* MODULE_REGISTRY_NAMESPACE_TESTS_FULL */ +/** @} */ diff --git a/sys/include/registry/namespace/tests/nested.h b/sys/include/registry/namespace/tests/nested.h new file mode 100644 index 000000000000..af6c26348d93 --- /dev/null +++ b/sys/include/registry/namespace/tests/nested.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_nested RIOT Registry Schema: Nested + * @ingroup sys + * @brief RIOT Registry Nested Schema representing different nesting level of a configuration schema + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_TESTS_NESTED_H +#define REGISTRY_NAMESPACE_TESTS_NESTED_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/* NESTED */ +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) + +extern const registry_parameter_t registry_tests_nested_parameter; +extern const registry_group_t registry_tests_nested_group; +extern const registry_parameter_t registry_tests_nested_group_parameter; +extern registry_schema_t registry_tests_nested; + +typedef struct { + uint8_t value; +} registry_tests_nested_instance_opaque_t; + +typedef struct { + clist_node_t node; + + uint8_t parameter; + uint8_t group_parameter; +} registry_tests_nested_instance_t; + +typedef enum { + REGISTRY_TESTS_NESTED_PARAMETER, + REGISTRY_TESTS_NESTED_GROUP, + REGISTRY_TESTS_NESTED_GROUP_PARAMETER, +} registry_tests_nested_indices_t; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* MODULE_REGISTRY_NAMESPACE_TESTS_NESTED */ +/** @} */ diff --git a/sys/registry/Kconfig b/sys/registry/Kconfig index 74835491887f..da218e9a2838 100644 --- a/sys/registry/Kconfig +++ b/sys/registry/Kconfig @@ -36,6 +36,7 @@ config MODULE_REGISTRY_INT_PATH config MODULE_REGISTRY_STRING_PATH bool "Access configuration parameters via a string path" +rsource "namespace/Kconfig" rsource "storage/Kconfig" -endif # MODULE_REGISTRY \ No newline at end of file +endif # MODULE_REGISTRY diff --git a/sys/registry/namespace/Kconfig b/sys/registry/namespace/Kconfig index 82a1406d7253..4d7a2a12f47f 100644 --- a/sys/registry/namespace/Kconfig +++ b/sys/registry/namespace/Kconfig @@ -14,5 +14,6 @@ menuconfig MODULE_REGISTRY_NAMESPACE if MODULE_REGISTRY_NAMESPACE rsource "sys/Kconfig" +rsource "tests/Kconfig" -endif # MODULE_REGISTRY_NAMESPACE +endif # MODULE_REGISTRY_NAMESPACE \ No newline at end of file diff --git a/sys/registry/namespace/Makefile b/sys/registry/namespace/Makefile index 45c14481c0a3..9cd1d452108d 100644 --- a/sys/registry/namespace/Makefile +++ b/sys/registry/namespace/Makefile @@ -2,4 +2,8 @@ ifneq (,$(filter registry_namespace_sys%,$(USEMODULE))) DIRS += sys endif +ifneq (,$(filter registry_namespace_tests%,$(USEMODULE))) + DIRS += tests +endif + include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/sys/registry/namespace/Makefile.dep b/sys/registry/namespace/Makefile.dep index e8a0f1b07c53..ff87a2711e5f 100644 --- a/sys/registry/namespace/Makefile.dep +++ b/sys/registry/namespace/Makefile.dep @@ -1,3 +1,7 @@ ifneq (,$(filter registry_namespace_sys%,$(USEMODULE))) include $(RIOTBASE)/sys/registry/namespace/sys/Makefile.dep endif + +ifneq (,$(filter registry_namespace_tests%,$(USEMODULE))) + include $(RIOTBASE)/sys/registry/namespace/tests/Makefile.dep +endif \ No newline at end of file diff --git a/sys/registry/namespace/tests/Kconfig b/sys/registry/namespace/tests/Kconfig new file mode 100644 index 000000000000..86e1bf1dd574 --- /dev/null +++ b/sys/registry/namespace/tests/Kconfig @@ -0,0 +1,19 @@ +# Copyright (c) 2023 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +menuconfig MODULE_REGISTRY_NAMESPACE_TESTS + bool "REGISTRY_NAMESPACE_TESTS" + depends on MODULE_REGISTRY_NAMESPACE + help + Namespace Tests module providing common testing configuration schemas for the RIOT Registry sys module. + +if MODULE_REGISTRY_NAMESPACE_TESTS + +config MODULE_REGISTRY_NAMESPACE_TESTS_FULL + bool "Full schema" + +endif # MODULE_REGISTRY_NAMESPACE_TESTS \ No newline at end of file diff --git a/sys/registry/namespace/tests/Makefile b/sys/registry/namespace/tests/Makefile new file mode 100644 index 000000000000..6819aae6b801 --- /dev/null +++ b/sys/registry/namespace/tests/Makefile @@ -0,0 +1,9 @@ +MODULE := registry_namespace_tests + +BASE_MODULE := registry + +SRC := namespace_tests.c + +SUBMODULES := 1 + +include $(RIOTBASE)/Makefile.base diff --git a/sys/registry/namespace/tests/Makefile.dep b/sys/registry/namespace/tests/Makefile.dep new file mode 100644 index 000000000000..ad4e1881883f --- /dev/null +++ b/sys/registry/namespace/tests/Makefile.dep @@ -0,0 +1,4 @@ +# Enable "registry_namespace_tests" module for all schemas +ifneq (,$(filter registry_namespace_tests_%,$(USEMODULE))) + USEMODULE += registry_namespace_tests +endif diff --git a/sys/registry/namespace/tests/definitions/0001_full.yaml b/sys/registry/namespace/tests/definitions/0001_full.yaml new file mode 100644 index 000000000000..63132f58bff7 --- /dev/null +++ b/sys/registry/namespace/tests/definitions/0001_full.yaml @@ -0,0 +1,71 @@ +# yaml-language-server: $schema=../../../../../dist/tools/registry_gen/schema.json +id: 1 +name: rgb +description: Representation of an rgb color. +items: + - id: 0 + name: opaque + description: Opaque data type property. + type: opaque + size: 50 + + - id: 1 + name: string + description: String data type property. + type: string + size: 50 + + - id: 2 + name: boolean + description: Boolean data type property. + type: bool + + - id: 3 + name: u8 + description: 8 bit unsigned integer data type property. + type: uint8 + + - id: 4 + name: u16 + description: 16 bit unsigned integer data type property. + type: uint16 + + - id: 5 + name: u32 + description: 32 bit unsigned integer data type property. + type: uint32 + + - id: 6 + name: u64 + description: 64 bit unsigned integer data type property. + type: uint64 + + - id: 7 + name: i8 + description: 8 bit integer data type property. + type: int8 + + - id: 8 + name: i16 + description: 16 bit integer data type property. + type: int16 + + - id: 9 + name: i32 + description: 32 bit integer data type property. + type: int32 + + - id: 10 + name: i64 + description: 64 bit integer data type property. + type: int64 + + - id: 11 + name: f32 + description: 64 bit integer data type property. + type: float32 + + - id: 12 + name: f64 + description: 64 bit integer data type property. + type: float64 diff --git a/sys/registry/namespace/tests/definitions/0002_constrained.yaml b/sys/registry/namespace/tests/definitions/0002_constrained.yaml new file mode 100644 index 000000000000..68087a3f55f8 --- /dev/null +++ b/sys/registry/namespace/tests/definitions/0002_constrained.yaml @@ -0,0 +1,132 @@ +# yaml-language-server: $schema=../../../../../dist/tools/registry_gen/schema.json +id: 1 +name: rgb +description: Representation of an rgb color. +items: + - id: 0 + name: opaque + description: Opaque data type property. + type: opaque + size: 50 + constraints: + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 1 + name: string + description: String data type property. + type: string + size: 50 + constraints: + allowedValues: ["hello", "world"] + forbiddenValues: ["goodbye", "moon"] + + - id: 2 + name: boolean + description: Boolean data type property. + type: bool + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 3 + name: u8 + description: 8 bit unsigned integer data type property. + type: uint8 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 4 + name: u16 + description: 16 bit unsigned integer data type property. + type: uint16 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 5 + name: u32 + description: 32 bit unsigned integer data type property. + type: uint32 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 6 + name: u64 + description: 64 bit unsigned integer data type property. + type: uint64 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 7 + name: i8 + description: 8 bit integer data type property. + type: int8 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 8 + name: i16 + description: 16 bit integer data type property. + type: int16 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 9 + name: i32 + description: 32 bit integer data type property. + type: int32 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 10 + name: i64 + description: 64 bit integer data type property. + type: int64 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 11 + name: f32 + description: 64 bit integer data type property. + type: float32 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] + + - id: 12 + name: f64 + description: 64 bit integer data type property. + type: float64 + constraints: + minValue: 7 + maxValue: 18 + allowedValues: ["7", "9"] + forbiddenValues: ["11", "19"] diff --git a/sys/registry/namespace/tests/namespace_tests.c b/sys/registry/namespace/tests/namespace_tests.c new file mode 100644 index 000000000000..bdff804129a0 --- /dev/null +++ b/sys/registry/namespace/tests/namespace_tests.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests RIOT Registry Tests Namespace + * @ingroup tests + * @brief RIOT Registry Namespace Tests module providing common tests configuration schemas for the RIOT Registry sys module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" + +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/full.h" +#include "registry/namespace/tests/constrained_min_max.h" +#include "registry/namespace/tests/constrained_allowed_values.h" +#include "registry/namespace/tests/constrained_forbidden_values.h" +#include "registry/namespace/tests/nested.h" + +static const registry_schema_t *_schemas[] = { +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) + ®istry_tests_full, +#endif +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX) + ®istry_tests_constrained_min_max, +#endif +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES) + ®istry_tests_constrained_allowed_values, +#endif +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES) + ®istry_tests_constrained_forbidden_values, +#endif +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) + ®istry_tests_nested, +#endif +}; + +registry_namespace_t registry_tests = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "tests", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "Tests namespace", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schemas = _schemas, + .schemas_len = ARRAY_SIZE(_schemas), +}; + +REGISTRY_ADD_NAMESPACE(tests, registry_tests); diff --git a/sys/registry/namespace/tests/namespace_tests_constrained_allowed_values.c b/sys/registry/namespace/tests/namespace_tests_constrained_allowed_values.c new file mode 100644 index 000000000000..fa5f4f32efec --- /dev/null +++ b/sys/registry/namespace/tests/namespace_tests_constrained_allowed_values.c @@ -0,0 +1,557 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_constrained_allowed_values RIOT Registry Schema: Constrained Allowed Values + * @ingroup sys + * @brief RIOT Registry Constrained Allowed Values Schema representing all possible data types of the riot registry with allowed values constraints + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/constrained_allowed_values.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES) || IS_ACTIVE(DOXYGEN) + +/* Mapping */ +static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, + void **val, size_t *val_len) +{ + registry_tests_constrained_allowed_values_instance_t *_instance = + (registry_tests_constrained_allowed_values_instance_t *)instance->data; + + switch (parameter_id) { + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_OPAQUE: + *val = &_instance->opaque; + *val_len = sizeof(_instance->opaque); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_STRING: + *val = &_instance->string; + *val_len = sizeof(_instance->string); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_BOOLEAN: + *val = &_instance->boolean; + *val_len = sizeof(_instance->boolean); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U8: + *val = &_instance->u8; + *val_len = sizeof(_instance->u8); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U16: + *val = &_instance->u16; + *val_len = sizeof(_instance->u16); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U32: + *val = &_instance->u32; + *val_len = sizeof(_instance->u32); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U64: + *val = &_instance->u64; + *val_len = sizeof(_instance->u64); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I8: + *val = &_instance->i8; + *val_len = sizeof(_instance->i8); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I16: + *val = &_instance->i16; + *val_len = sizeof(_instance->i16); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I32: + *val = &_instance->i32; + *val_len = sizeof(_instance->i32); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I64: + *val = &_instance->i64; + *val_len = sizeof(_instance->i64); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F32: + *val = &_instance->f32; + *val_len = sizeof(_instance->f32); + break; + + case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F64: + *val = &_instance->f64; + *val_len = sizeof(_instance->f64); + break; + } +} + +const registry_tests_constrained_allowed_values_instance_opaque_t + registry_tests_constrained_allowed_values_opaque_allowed_1 = { + .value = 7, +}; + +const registry_tests_constrained_allowed_values_instance_opaque_t + registry_tests_constrained_allowed_values_opaque_allowed_2 = { + .value = 9, +}; + +/* Schema */ +const registry_parameter_t registry_tests_constrained_allowed_values_opaque = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_OPAQUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "opaque", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_OPAQUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.opaque = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (const void *[]) { + ®istry_tests_constrained_allowed_values_opaque_allowed_1, + ®istry_tests_constrained_allowed_values_opaque_allowed_2, + }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_string = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_STRING, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "string", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_STRING, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.string = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (const char *[]){ "hello", "world" }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_boolean = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_BOOLEAN, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "boolean", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_BOOL, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.boolean = NULL, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_u8 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (uint8_t[]){ 7, 9 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint8_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint8_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_u16 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_UINT16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint16 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (uint16_t[]){ 7, 9 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint16_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint16_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_u32 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_UINT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (uint32_t[]){ 7, 9 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint32_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint32_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_u64 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_UINT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (uint64_t[]){ 7, 9 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint64_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint64_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_i8 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_INT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (int8_t[]){ 7, 9 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int8_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int8_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_i16 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_INT16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int16 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (int16_t[]){ 7, 9 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int16_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int16_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_i32 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_INT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (int32_t[]){ 7, 9 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int32_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int32_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_i64 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_INT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (int64_t[]){ 7, 9 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int64_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int64_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_f32 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_FLOAT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.float32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (float[]){ 7.0, 9.0 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (float[]){ 7.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (float[]){ 18.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_allowed_values_f64 = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_allowed_values, + .type = REGISTRY_TYPE_FLOAT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.float64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = (double[]){ 7.0, 9.0 }, + .allowed_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (double[]){ 7.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (double[]){ 18.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +registry_schema_t registry_tests_constrained_allowed_values = { + .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "constrained_allowed_values", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .namespace = ®istry_tests, + .mapping = mapping, + .groups = NULL, + .groups_len = 0, + .parameters = (const registry_parameter_t *[]) { + ®istry_tests_constrained_allowed_values_opaque, + ®istry_tests_constrained_allowed_values_string, + ®istry_tests_constrained_allowed_values_boolean, + ®istry_tests_constrained_allowed_values_u8, + ®istry_tests_constrained_allowed_values_u16, + ®istry_tests_constrained_allowed_values_u32, + ®istry_tests_constrained_allowed_values_u64, + ®istry_tests_constrained_allowed_values_i8, + ®istry_tests_constrained_allowed_values_i16, + ®istry_tests_constrained_allowed_values_i32, + ®istry_tests_constrained_allowed_values_i64, + ®istry_tests_constrained_allowed_values_f32, + ®istry_tests_constrained_allowed_values_f64, + }, + .parameters_len = 13, +}; + +#endif diff --git a/sys/registry/namespace/tests/namespace_tests_constrained_forbidden_values.c b/sys/registry/namespace/tests/namespace_tests_constrained_forbidden_values.c new file mode 100644 index 000000000000..41f1d6830781 --- /dev/null +++ b/sys/registry/namespace/tests/namespace_tests_constrained_forbidden_values.c @@ -0,0 +1,544 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_constrained_forbidden_values RIOT Registry Schema: Constrained Forbidden Values + * @ingroup sys + * @brief RIOT Registry Constrained Forbidden Values Schema representing all possible data types of the riot registry with forbidden values constraints + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/constrained_forbidden_values.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES) || IS_ACTIVE(DOXYGEN) + +/* Mapping */ +static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, + void **val, size_t *val_len) +{ + registry_tests_constrained_forbidden_values_instance_t *_instance = + (registry_tests_constrained_forbidden_values_instance_t *)instance->data; + + switch (parameter_id) { + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_OPAQUE: + *val = &_instance->opaque; + *val_len = sizeof(_instance->opaque); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_STRING: + *val = &_instance->string; + *val_len = sizeof(_instance->string); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_BOOLEAN: + *val = &_instance->boolean; + *val_len = sizeof(_instance->boolean); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U8: + *val = &_instance->u8; + *val_len = sizeof(_instance->u8); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U16: + *val = &_instance->u16; + *val_len = sizeof(_instance->u16); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U32: + *val = &_instance->u32; + *val_len = sizeof(_instance->u32); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U64: + *val = &_instance->u64; + *val_len = sizeof(_instance->u64); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I8: + *val = &_instance->i8; + *val_len = sizeof(_instance->i8); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I16: + *val = &_instance->i16; + *val_len = sizeof(_instance->i16); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I32: + *val = &_instance->i32; + *val_len = sizeof(_instance->i32); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I64: + *val = &_instance->i64; + *val_len = sizeof(_instance->i64); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F32: + *val = &_instance->f32; + *val_len = sizeof(_instance->f32); + break; + + case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F64: + *val = &_instance->f64; + *val_len = sizeof(_instance->f64); + break; + } +} + +/* Schema */ +const registry_parameter_t registry_tests_constrained_forbidden_values_opaque = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_OPAQUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "opaque", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_OPAQUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.opaque = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (const void *[]){ "goodbye", "moon" }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_string = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_STRING, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "string", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_STRING, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.string = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (const char *[]){ "goodbye", "moon" }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_boolean = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_BOOLEAN, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "boolean", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_BOOL, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.boolean = NULL, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_u8 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (uint8_t[]){ 11, 19 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint8_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint8_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_u16 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_UINT16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint16 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (uint16_t[]){ 11, 19 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint16_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint16_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_u32 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_UINT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (uint32_t[]){ 11, 19 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint32_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint32_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_u64 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_UINT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (uint64_t[]){ 11, 19 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint64_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint64_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_i8 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_INT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (int8_t[]){ 11, 19 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int8_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int8_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_i16 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_INT16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int16 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (int16_t[]){ 11, 19 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int16_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int16_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_i32 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_INT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (int32_t[]){ 11, 19 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int32_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int32_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_i64 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_INT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (int64_t[]){ 11, 19 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int64_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int64_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_f32 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_FLOAT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.float32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (float[]){ 11.0, 19.0 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (float[]){ 7.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (float[]){ 18.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_forbidden_values_f64 = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_forbidden_values, + .type = REGISTRY_TYPE_FLOAT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.float64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = (double[]){ 11.0, 19.0 }, + .forbidden_values_len = 2, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (double[]){ 7.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (double[]){ 18.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +registry_schema_t registry_tests_constrained_forbidden_values = { + .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "constrained_forbidden_values", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .namespace = ®istry_tests, + .mapping = mapping, + .groups = NULL, + .groups_len = 0, + .parameters = (const registry_parameter_t *[]) { + ®istry_tests_constrained_forbidden_values_opaque, + ®istry_tests_constrained_forbidden_values_string, + ®istry_tests_constrained_forbidden_values_boolean, + ®istry_tests_constrained_forbidden_values_u8, + ®istry_tests_constrained_forbidden_values_u16, + ®istry_tests_constrained_forbidden_values_u32, + ®istry_tests_constrained_forbidden_values_u64, + ®istry_tests_constrained_forbidden_values_i8, + ®istry_tests_constrained_forbidden_values_i16, + ®istry_tests_constrained_forbidden_values_i32, + ®istry_tests_constrained_forbidden_values_i64, + ®istry_tests_constrained_forbidden_values_f32, + ®istry_tests_constrained_forbidden_values_f64, + }, + .parameters_len = 13, +}; + +#endif diff --git a/sys/registry/namespace/tests/namespace_tests_constrained_min_max.c b/sys/registry/namespace/tests/namespace_tests_constrained_min_max.c new file mode 100644 index 000000000000..aa8fffdfa9f3 --- /dev/null +++ b/sys/registry/namespace/tests/namespace_tests_constrained_min_max.c @@ -0,0 +1,544 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_constrained_min_max RIOT Registry Schema: Constrained Min Max + * @ingroup sys + * @brief RIOT Registry Constrained Min Max Schema representing all possible data types of the riot registry with minimum and maximum value constraints + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/constrained_min_max.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX) || IS_ACTIVE(DOXYGEN) + +/* Mapping */ +static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, + void **val, size_t *val_len) +{ + registry_tests_constrained_min_max_instance_t *_instance = + (registry_tests_constrained_min_max_instance_t *)instance->data; + + switch (parameter_id) { + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_OPAQUE: + *val = &_instance->opaque; + *val_len = sizeof(_instance->opaque); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_STRING: + *val = &_instance->string; + *val_len = sizeof(_instance->string); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_BOOLEAN: + *val = &_instance->boolean; + *val_len = sizeof(_instance->boolean); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U8: + *val = &_instance->u8; + *val_len = sizeof(_instance->u8); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U16: + *val = &_instance->u16; + *val_len = sizeof(_instance->u16); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U32: + *val = &_instance->u32; + *val_len = sizeof(_instance->u32); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U64: + *val = &_instance->u64; + *val_len = sizeof(_instance->u64); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I8: + *val = &_instance->i8; + *val_len = sizeof(_instance->i8); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I16: + *val = &_instance->i16; + *val_len = sizeof(_instance->i16); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I32: + *val = &_instance->i32; + *val_len = sizeof(_instance->i32); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I64: + *val = &_instance->i64; + *val_len = sizeof(_instance->i64); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F32: + *val = &_instance->f32; + *val_len = sizeof(_instance->f32); + break; + + case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F64: + *val = &_instance->f64; + *val_len = sizeof(_instance->f64); + break; + } +} + +/* Schema */ +const registry_parameter_t registry_tests_constrained_min_max_opaque = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_OPAQUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "opaque", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_OPAQUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.opaque = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_string = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_STRING, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "string", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_STRING, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.string = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_boolean = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_BOOLEAN, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "boolean", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_BOOL, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.boolean = NULL, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_u8 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint8_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint8_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_u16 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_UINT16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint16 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint16_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint16_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_u32 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_UINT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint32_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint32_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_u64 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_UINT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (uint64_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (uint64_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_i8 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_INT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int8_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int8_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_i16 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_INT16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int16 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int16_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int16_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_i32 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_INT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int32_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int32_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_i64 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_INT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (int64_t[]){ 7 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (int64_t[]){ 18 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_f32 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_FLOAT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.float32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (float[]){ 7.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (float[]){ 18.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_constrained_min_max_f64 = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_constrained_min_max, + .type = REGISTRY_TYPE_FLOAT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.float64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = (double[]){ 7.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = (double[]){ 18.0 }, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +registry_schema_t registry_tests_constrained_min_max = { + .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_VALUES, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "constrained_min_max", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .namespace = ®istry_tests, + .mapping = mapping, + .groups = NULL, + .groups_len = 0, + .parameters = (const registry_parameter_t *[]) { + ®istry_tests_constrained_min_max_opaque, + ®istry_tests_constrained_min_max_string, + ®istry_tests_constrained_min_max_boolean, + ®istry_tests_constrained_min_max_u8, + ®istry_tests_constrained_min_max_u16, + ®istry_tests_constrained_min_max_u32, + ®istry_tests_constrained_min_max_u64, + ®istry_tests_constrained_min_max_i8, + ®istry_tests_constrained_min_max_i16, + ®istry_tests_constrained_min_max_i32, + ®istry_tests_constrained_min_max_i64, + ®istry_tests_constrained_min_max_f32, + ®istry_tests_constrained_min_max_f64, + }, + .parameters_len = 13, +}; + +#endif diff --git a/sys/registry/namespace/tests/namespace_tests_full.c b/sys/registry/namespace/tests/namespace_tests_full.c new file mode 100644 index 000000000000..1c1f2a38c76e --- /dev/null +++ b/sys/registry/namespace/tests/namespace_tests_full.c @@ -0,0 +1,544 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_full RIOT Registry Schema: Full + * @ingroup sys + * @brief RIOT Registry Full Schema representing all possible data types of the riot registry + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/full.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) || IS_ACTIVE(DOXYGEN) + +/* Mapping */ +static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, + void **val, size_t *val_len) +{ + registry_tests_full_instance_t *_instance = + (registry_tests_full_instance_t *)instance->data; + + switch (parameter_id) { + case REGISTRY_TESTS_FULL_OPAQUE: + *val = &_instance->opaque; + *val_len = sizeof(_instance->opaque); + break; + + case REGISTRY_TESTS_FULL_STRING: + *val = &_instance->string; + *val_len = sizeof(_instance->string); + break; + + case REGISTRY_TESTS_FULL_BOOLEAN: + *val = &_instance->boolean; + *val_len = sizeof(_instance->boolean); + break; + + case REGISTRY_TESTS_FULL_U8: + *val = &_instance->u8; + *val_len = sizeof(_instance->u8); + break; + + case REGISTRY_TESTS_FULL_U16: + *val = &_instance->u16; + *val_len = sizeof(_instance->u16); + break; + + case REGISTRY_TESTS_FULL_U32: + *val = &_instance->u32; + *val_len = sizeof(_instance->u32); + break; + + case REGISTRY_TESTS_FULL_U64: + *val = &_instance->u64; + *val_len = sizeof(_instance->u64); + break; + + case REGISTRY_TESTS_FULL_I8: + *val = &_instance->i8; + *val_len = sizeof(_instance->i8); + break; + + case REGISTRY_TESTS_FULL_I16: + *val = &_instance->i16; + *val_len = sizeof(_instance->i16); + break; + + case REGISTRY_TESTS_FULL_I32: + *val = &_instance->i32; + *val_len = sizeof(_instance->i32); + break; + + case REGISTRY_TESTS_FULL_I64: + *val = &_instance->i64; + *val_len = sizeof(_instance->i64); + break; + + case REGISTRY_TESTS_FULL_F32: + *val = &_instance->f32; + *val_len = sizeof(_instance->f32); + break; + + case REGISTRY_TESTS_FULL_F64: + *val = &_instance->f64; + *val_len = sizeof(_instance->f64); + break; + } +} + +/* Schema */ +const registry_parameter_t registry_tests_full_opaque = { + .id = REGISTRY_TESTS_FULL_OPAQUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "opaque", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_OPAQUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.opaque = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_string = { + .id = REGISTRY_TESTS_FULL_STRING, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "string", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_STRING, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.string = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_boolean = { + .id = REGISTRY_TESTS_FULL_BOOLEAN, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "boolean", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_BOOL, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.boolean = NULL, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_u8 = { + .id = REGISTRY_TESTS_FULL_U8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_u16 = { + .id = REGISTRY_TESTS_FULL_U16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_UINT16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint16 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_u32 = { + .id = REGISTRY_TESTS_FULL_U32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_UINT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_u64 = { + .id = REGISTRY_TESTS_FULL_U64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_UINT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_i8 = { + .id = REGISTRY_TESTS_FULL_I8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_INT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_i16 = { + .id = REGISTRY_TESTS_FULL_I16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_INT16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int16 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_i32 = { + .id = REGISTRY_TESTS_FULL_I32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_INT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_i64 = { + .id = REGISTRY_TESTS_FULL_I64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_INT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_f32 = { + .id = REGISTRY_TESTS_FULL_F32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_FLOAT32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.float32 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_parameter_t registry_tests_full_f64 = { + .id = REGISTRY_TESTS_FULL_F64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_FLOAT64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.int64 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .min_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) + .max_value = NULL, +#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +registry_schema_t registry_tests_full = { + .id = REGISTRY_TESTS_FULL, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "full", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .namespace = ®istry_tests, + .mapping = mapping, + .groups = NULL, + .groups_len = 0, + .parameters = (const registry_parameter_t *[]) { + ®istry_tests_full_opaque, + ®istry_tests_full_string, + ®istry_tests_full_boolean, + ®istry_tests_full_u8, + ®istry_tests_full_u16, + ®istry_tests_full_u32, + ®istry_tests_full_u64, + ®istry_tests_full_i8, + ®istry_tests_full_i16, + ®istry_tests_full_i32, + ®istry_tests_full_i64, + ®istry_tests_full_f32, + ®istry_tests_full_f64, + }, + .parameters_len = 13, +}; + +#endif diff --git a/sys/registry/namespace/tests/namespace_tests_nested.c b/sys/registry/namespace/tests/namespace_tests_nested.c new file mode 100644 index 000000000000..d199ff1d4c10 --- /dev/null +++ b/sys/registry/namespace/tests/namespace_tests_nested.c @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_nested RIOT Registry Schema: Nested + * @ingroup sys + * @brief RIOT Registry Nested Schema representing different nesting level of a configuration schema + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/nested.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) + +/* Mapping */ +static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, + void **val, size_t *val_len) +{ + registry_tests_nested_instance_t *_instance = + (registry_tests_nested_instance_t *)instance->data; + + switch (parameter_id) { + case REGISTRY_TESTS_NESTED_PARAMETER: + *val = &_instance->parameter; + *val_len = sizeof(_instance->parameter); + break; + + case REGISTRY_TESTS_NESTED_GROUP_PARAMETER: + *val = &_instance->group_parameter; + *val_len = sizeof(_instance->group_parameter); + break; + } +} + +/* Schema */ +const registry_parameter_t registry_tests_nested_parameter = { + .id = REGISTRY_TESTS_NESTED_PARAMETER, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "parameter", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_nested, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +const registry_group_t registry_tests_nested_group = { + .id = REGISTRY_TESTS_NESTED_GROUP, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "group", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_nested, + .groups = NULL, + .groups_len = 0, + .parameters = (const registry_parameter_t *[]) { + ®istry_tests_nested_group_parameter, + }, + .parameters_len = 1, +}; + +const registry_parameter_t registry_tests_nested_group_parameter = { + .id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "parameter", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_nested, + .type = REGISTRY_TYPE_UINT8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ + IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) + .constraints.uint8 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .allowed_values = NULL, + .allowed_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) + .forbidden_values = NULL, + .forbidden_values_len = 0, +#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ + }, +#endif /* CONSTRAINTS */ +}; + +registry_schema_t registry_tests_nested = { + .id = REGISTRY_TESTS_NESTED, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "nested", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .namespace = ®istry_tests, + .mapping = mapping, + .groups = (const registry_group_t *[]) { + ®istry_tests_nested_group, + }, + .groups_len = 1, + .parameters = (const registry_parameter_t *[]) { + ®istry_tests_nested_parameter, + }, + .parameters_len = 1, +}; + +#endif From e04a3c5f59cca6318dc2e70bcfe38227e8c29f75 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:15:46 +0200 Subject: [PATCH 007/117] sys/registry/storage: add heap based storage --- sys/include/registry/storage.h | 5 ++ sys/registry/storage/Kconfig | 7 ++ sys/registry/storage/storage_heap.c | 107 ++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 sys/registry/storage/storage_heap.c diff --git a/sys/include/registry/storage.h b/sys/include/registry/storage.h index 61a76d41ee6d..76ca9c69b8e4 100644 --- a/sys/include/registry/storage.h +++ b/sys/include/registry/storage.h @@ -146,6 +146,11 @@ extern const registry_storage_instance_t *_registry_storage_instance_dst; #define REGISTRY_SET_STORAGE_DESTINATION(_storage_instance) \ const registry_storage_instance_t *_registry_storage_instance_dst = &_storage_instance \ +/* heap */ +#if IS_USED(MODULE_REGISTRY_STORAGE_HEAP) || IS_ACTIVE(DOXYGEN) +extern registry_storage_t registry_storage_heap; +#endif + #ifdef __cplusplus } #endif diff --git a/sys/registry/storage/Kconfig b/sys/registry/storage/Kconfig index 0f18f0e3bc23..e45b3b09ca9b 100644 --- a/sys/registry/storage/Kconfig +++ b/sys/registry/storage/Kconfig @@ -10,3 +10,10 @@ menuconfig MODULE_REGISTRY_STORAGE depends on MODULE_REGISTRY help Storage module allowing to store configuration parameters to non-volatile storage. + +if MODULE_REGISTRY_STORAGE + +config MODULE_REGISTRY_STORAGE_HEAP + bool "Heap storage" + +endif # MODULE_REGISTRY_STORAGE \ No newline at end of file diff --git a/sys/registry/storage/storage_heap.c b/sys/registry/storage/storage_heap.c new file mode 100644 index 000000000000..d46700d4839e --- /dev/null +++ b/sys/registry/storage/storage_heap.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_storage_heap RIOT Registry Storage: Heap + * @ingroup sys + * @brief RIOT Registry Storage Heap, only uses the heap for testing. + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" + +#include "registry/storage.h" + +#ifndef REGISTRY_STORAGE_HEAP_CAPACITY + #define REGISTRY_STORAGE_HEAP_CAPACITY 100 +#endif + +static int load(const registry_storage_instance_t *storage, + const load_cb_t load_cb); +static int save(const registry_storage_instance_t *storage, + const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_value_t *value); + +typedef struct { + const registry_namespace_t *namespace; + const registry_schema_t *schema; + const registry_instance_t *instance; + const registry_parameter_t *parameter; + void *buf; + size_t buf_len; +} heap_storage_t; + +/* This is the "storage device" containing all the data */ +static heap_storage_t heap_storage[REGISTRY_STORAGE_HEAP_CAPACITY]; +static size_t heap_storage_len = 0; + +/* Storage interface descriptor to be registered in the RIOT Registry */ +registry_storage_t registry_storage_heap = { + .load = load, + .save = save, +}; + +static int load(const registry_storage_instance_t *storage, + const load_cb_t load_cb) +{ + (void)storage; + + for (size_t i = 0; i < heap_storage_len; i++) { + load_cb(heap_storage[i].instance, heap_storage[i].parameter, heap_storage[i].buf, + heap_storage[i].buf_len); + } + return 0; +} + +static int save(const registry_storage_instance_t *storage, + const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_value_t *value) +{ + (void)storage; + + /* Search value in storage */ + for (size_t i = 0; i < heap_storage_len; i++) { + if (heap_storage[i].namespace == parameter->schema->namespace && + heap_storage[i].schema == parameter->schema && + heap_storage[i].instance == instance && + heap_storage[i].parameter == parameter) { + memcpy(heap_storage[i].buf, value->buf, value->buf_len); + return 0; + } + } + + /* Value not found in storage => Append it at the end */ + heap_storage[heap_storage_len] = (heap_storage_t) { + .namespace = parameter->schema->namespace, + .schema = parameter->schema, + .instance = instance, + .parameter = parameter, + .buf = malloc(value->buf_len), + .buf_len = value->buf_len, + }; + memcpy(heap_storage[heap_storage_len].buf, value->buf, value->buf_len); + + heap_storage_len++; + return 0; +} From 23ad414a854e56150014804649f8ecd039e25805 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:17:27 +0200 Subject: [PATCH 008/117] sys/registry/storage: add vfs based storage --- sys/include/registry/storage.h | 5 + sys/registry/storage/Kconfig | 3 + sys/registry/storage/Makefile.dep | 5 + sys/registry/storage/storage_vfs.c | 336 +++++++++++++++++++++++++++++ 4 files changed, 349 insertions(+) create mode 100644 sys/registry/storage/storage_vfs.c diff --git a/sys/include/registry/storage.h b/sys/include/registry/storage.h index 76ca9c69b8e4..0304b1a70224 100644 --- a/sys/include/registry/storage.h +++ b/sys/include/registry/storage.h @@ -151,6 +151,11 @@ extern const registry_storage_instance_t *_registry_storage_instance_dst; extern registry_storage_t registry_storage_heap; #endif +/* vfs */ +#if IS_USED(MODULE_REGISTRY_STORAGE_VFS) || IS_ACTIVE(DOXYGEN) +extern registry_storage_t registry_storage_vfs; +#endif + #ifdef __cplusplus } #endif diff --git a/sys/registry/storage/Kconfig b/sys/registry/storage/Kconfig index e45b3b09ca9b..7ef846a45b2b 100644 --- a/sys/registry/storage/Kconfig +++ b/sys/registry/storage/Kconfig @@ -16,4 +16,7 @@ if MODULE_REGISTRY_STORAGE config MODULE_REGISTRY_STORAGE_HEAP bool "Heap storage" +config MODULE_REGISTRY_STORAGE_VFS + bool "VFS storage" + endif # MODULE_REGISTRY_STORAGE \ No newline at end of file diff --git a/sys/registry/storage/Makefile.dep b/sys/registry/storage/Makefile.dep index 74d5f7d59018..93e079bfbf1c 100644 --- a/sys/registry/storage/Makefile.dep +++ b/sys/registry/storage/Makefile.dep @@ -2,3 +2,8 @@ ifneq (,$(filter registry_storage_%,$(USEMODULE))) USEMODULE += registry_storage endif + +# Enable "registry_int_path" module for some storage modules +ifneq (,$(filter registry_storage_vfs,$(USEMODULE))) + USEMODULE += registry_int_path +endif \ No newline at end of file diff --git a/sys/registry/storage/storage_vfs.c b/sys/registry/storage/storage_vfs.c new file mode 100644 index 000000000000..ea9a12d320fa --- /dev/null +++ b/sys/registry/storage/storage_vfs.c @@ -0,0 +1,336 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_int_path_storage_vfs RIOT Registry Path Storage: VFS + * @ingroup sys + * @brief RIOT Registry Path Storage VFS, allows using the RIOT VFS module as a RIOT Registry data storage. + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "vfs.h" +#include "ps.h" +#include "registry/int_path.h" + +#include "registry/storage.h" + +static int load(const registry_storage_instance_t *storage, + const load_cb_t load_cb); +static int save(const registry_storage_instance_t *storage, + const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_value_t *value); + +registry_storage_t registry_storage_vfs = { + .load = load, + .save = save, +}; + +static void _string_path_append_item(char *dest, uint32_t number) +{ + int size = snprintf(NULL, 0, "/%d", number); + + /* Allocate size + string termination */ + char buf[size + 1]; + + sprintf(buf, "/%d", number); + + strcat(dest, buf); +} + +static int _format(vfs_mount_t *mount) +{ + DEBUG("formatting %s....\t", mount->mount_point); + if (vfs_format(mount) < 0) { + DEBUG("[Failed]\n"); + return 1; + } + else { + DEBUG("[OK]\n"); + } + + return 0; +} + +static int _mount(vfs_mount_t *mount) +{ + int res = vfs_mount(mount); + + if (res < 0) { + DEBUG("Error while mounting %s ... (%d) ... try format\n", mount->mount_point, res); + + /* format to fix mount */ + _format(mount); + + /* try to mount again */ + res = vfs_mount(mount); + if (res != 0) { + return -1; + } + } + + return 0; +} + +static int _umount(vfs_mount_t *mount) +{ + int res = vfs_umount(mount, false); + + if (res < 0) { + DEBUG("Error while unmounting %s...\n", mount->mount_point); + return 1; + } + + return 0; +} + +static int load(const registry_storage_instance_t *storage, + const load_cb_t load_cb) +{ + vfs_mount_t *mount = storage->data; + + /* mount */ + _mount(mount); + + /* create dir path */ + char string_path[REGISTRY_INT_PATH_STRING_MAX_LEN]; + + sprintf(string_path, "%s", mount->mount_point); + + /* read dirs */ + vfs_DIR dirp; + + if (vfs_opendir(&dirp, string_path) != 0) { + DEBUG("[registry storage_vfs] load: Can not open dir\n"); + } + else { + struct stat _stat; + vfs_dirent_t dir_entry; + + size_t i = 0; + int last_dir_entry_positions[REGISTRY_INT_PATH_MAX_LEN] = { -1 }; + size_t last_dir_string_path_lens[REGISTRY_INT_PATH_MAX_LEN] = { 0 }; + int res = 0; + bool exit_folder_iteration = false; + + while (exit_folder_iteration == false) { + int dir_entry_position = -1; + do { + res = vfs_readdir(&dirp, &dir_entry); + dir_entry_position++; + + if (dir_entry_position > last_dir_entry_positions[i]) { + last_dir_entry_positions[i] = dir_entry_position; + for (size_t j = i + 1; j < REGISTRY_INT_PATH_MAX_LEN; j++) { + last_dir_entry_positions[j] = -1; + } + + if (res == 1) { + if (strcmp(dir_entry.d_name, + ".") != 0 && strcmp(dir_entry.d_name, "..") != 0) { + /* save string_path length to restore it later */ + last_dir_string_path_lens[i] = strlen(string_path); + + /* add new directory to string_path */ + strcat(string_path, "/"); + strcat(string_path, dir_entry.d_name); + + vfs_stat(string_path, &_stat); + + if (S_ISDIR(_stat.st_mode)) { + /* close old directory */ + if (vfs_closedir(&dirp) != 0) { + DEBUG( + "[registry storage_vfs] load: Can not close dir\n"); + } + + /* open new directory */ + if (vfs_opendir(&dirp, string_path) != 0) { + DEBUG("[registry storage_vfs] load: Can not open dir\n"); + } + + /* move on to next sub path */ + i++; + + /* reset position within current dir, because the dir changed */ + dir_entry_position = -1; + } + else { + /* open file */ + int fd = vfs_open(string_path, O_RDONLY, 0); + + if (fd <= 0) { + DEBUG( + "[registry storage_vfs] load: Can not open file: %d\n", + fd); + } + + /* convert string path to registry int path (remove mount point and first '/' character) */ + char *ptr = (char *)string_path + mount->mount_point_len + 1; + registry_namespace_id_t namespace_id = strtol(ptr, &ptr, 10); + ptr++; + registry_schema_id_t schema_id = strtol(ptr, &ptr, 10); + ptr++; + registry_instance_id_t instance_id = strtol(ptr, &ptr, 10); + ptr++; + registry_parameter_id_t parameter_id = strtol(ptr, &ptr, 10); + + const registry_parameter_int_path_t parameter_path = { + .namespace_id = namespace_id, + .schema_id = schema_id, + .instance_id = instance_id, + .parameter_id = parameter_id, + }; + + /* get pointer to registry internal configuration parameter */ + registry_instance_t *instance; + registry_parameter_t *parameter; + registry_from_parameter_int_path(¶meter_path, NULL, NULL, + &instance, ¶meter); + + registry_value_t value; + registry_get(instance, parameter, &value); + + /* read value from file */ + uint8_t new_value_buf[value.buf_len]; + if (vfs_read(fd, new_value_buf, value.buf_len) < 0) { + DEBUG( + "[registry storage_vfs] load: Can not read from file\n"); + } + else { + /* call callback with value and path */ + load_cb(instance, parameter, new_value_buf, value.buf_len); + } + + /* close file */ + if (vfs_close(fd) != 0) { + DEBUG( + "[registry storage_vfs] load: Can not close file: %d\n", + fd); + } + + /* restore old string_path */ + string_path[last_dir_string_path_lens[i]] = '\0'; + } + } + } + else { + /* if i == 0 it can't be further decreased => exit */ + if (i == 0) { + exit_folder_iteration = true; + } + else { + /* move up one path back to the parent */ + i--; + + /* restore old string_path */ + string_path[last_dir_string_path_lens[i]] = '\0'; + + /* close old directory */ + if (vfs_closedir(&dirp) != 0) { + DEBUG("[registry storage_vfs] load: Can not close dir\n"); + } + + /* open new directory */ + if (vfs_opendir(&dirp, string_path) != 0) { + DEBUG("[registry storage_vfs] load: Can not open dir\n"); + } + } + } + } + } while (res == 1); + } + + if (vfs_closedir(&dirp) != 0) { + DEBUG("[registry storage_vfs] load: Can not close dir\n"); + } + } + + /* umount */ + _umount(mount); + + return 0; +} + +static int save(const registry_storage_instance_t *storage, + const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_value_t *value) +{ + vfs_mount_t *mount = storage->data; + + /* mount */ + _mount(mount); + + /* create dir path */ + registry_parameter_int_path_t path = registry_to_parameter_int_path(instance, parameter); + + char string_path[REGISTRY_INT_PATH_STRING_MAX_LEN]; + + sprintf(string_path, "%s", mount->mount_point); + + _string_path_append_item(string_path, path.namespace_id); + int res = vfs_mkdir(string_path, 0); + + if (res < 0 && res != -EEXIST) { + DEBUG("[registry storage_vfs] save: Can not make dir: %s\n", string_path); + } + + _string_path_append_item(string_path, path.schema_id); + res = vfs_mkdir(string_path, 0); + + if (res < 0 && res != -EEXIST) { + DEBUG("[registry storage_vfs] save: Can not make dir: %s\n", string_path); + } + + _string_path_append_item(string_path, path.instance_id); + res = vfs_mkdir(string_path, 0); + + if (res < 0 && res != -EEXIST) { + DEBUG("[registry storage_vfs] save: Can not make dir: %s\n", string_path); + } + + /* open file */ + _string_path_append_item(string_path, path.parameter_id); + + int fd = vfs_open(string_path, O_CREAT | O_RDWR, 0); + + if (fd <= 0) { + DEBUG("[registry storage_vfs] save: Can not open file: %d\n", fd); + } + + /* write to file */ + if (vfs_write(fd, value->buf, value->buf_len) < 0) { + DEBUG("[registry storage_vfs] save: Can not write to file: %d\n", fd); + } + + if (vfs_close(fd) != 0) { + DEBUG("[registry storage_vfs] save: Can not close file: %d\n", fd); + } + + /* umount */ + _umount(mount); + + return 0; +} From 8df46ed3f298ab6bf2b500958e8a5f850553a2d8 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:19:00 +0200 Subject: [PATCH 009/117] examples: add registry example --- examples/registry/Makefile | 31 +++++++++ examples/registry/main.c | 127 +++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 examples/registry/Makefile create mode 100644 examples/registry/main.c diff --git a/examples/registry/Makefile b/examples/registry/Makefile new file mode 100644 index 000000000000..d229a35246fd --- /dev/null +++ b/examples/registry/Makefile @@ -0,0 +1,31 @@ +# name of the application +APPLICATION = registry_example + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# required modules +USEMODULE += shell +USEMODULE += shell_cmds_default + +USEMODULE += littlefs2 +USEMODULE += mtd + +USEMODULE += registry_string_path +USEMODULE += registry_storage_vfs +USEMODULE += registry_namespace_sys_rgb_led +USEMODULE += registry_namespace_tests_full +USEMODULE += registry_namespace_tests_nested + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +include $(RIOTBASE)/Makefile.include diff --git a/examples/registry/main.c b/examples/registry/main.c new file mode 100644 index 000000000000..f46294872359 --- /dev/null +++ b/examples/registry/main.c @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief RIOT Registry example application + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include + +#include "msg.h" +#include "shell.h" +#include "board.h" +#include "mtd.h" +#include "vfs.h" +#include "fs/littlefs2_fs.h" +#include "registry.h" +#include "registry/namespace/sys.h" +#include "registry/namespace/sys/rgb_led.h" +#include "registry/storage.h" +#include "registry/string_path.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/nested.h" + +int rgb_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) +{ + (void)scope; + (void)context; + printf("RGB instance commit_cb was executed on "); + + if (group_or_parameter_id != NULL) { + printf("param: %d", *group_or_parameter_id); + } + else { + printf("whole instance"); + } + + printf("\n"); + + return 0; +} + +registry_sys_rgb_led_instance_t rgb_led_instance_0_data = { + .red = 0, + .green = 255, + .blue = 70, +}; +registry_instance_t rgb_led_instance_0 = { + .name = "rgb-0", + .data = &rgb_led_instance_0_data, + .commit_cb = &rgb_led_instance_0_commit_cb, +}; + +registry_sys_rgb_led_instance_t rgb_led_instance_1_data = { + .red = 90, + .green = 4, + .blue = 0, +}; +registry_instance_t rgb_led_instance_1 = { + .name = "rgb-1", + .data = &rgb_led_instance_1_data, + .commit_cb = &rgb_led_instance_0_commit_cb, +}; + +static littlefs2_desc_t fs_desc = { + .lock = MUTEX_INIT, +}; + +static vfs_mount_t _vfs_mount = { + .fs = &littlefs2_file_system, + .mount_point = "/sda", + .private_data = &fs_desc, +}; + +static registry_storage_instance_t vfs_instance = { + .storage = ®istry_storage_vfs, + .data = &_vfs_mount, +}; + +REGISTRY_ADD_STORAGE_SOURCE(vfs_instance); +REGISTRY_SET_STORAGE_DESTINATION(vfs_instance); + +static registry_tests_nested_instance_t test_nested_instance_data = { + .parameter = 9, + .group_parameter = 5, +}; + +static registry_instance_t test_nested_instance = { + .name = "instance-1", + .data = &test_nested_instance_data, + .commit_cb = NULL, +}; + +int main(void) +{ + registry_init(); + + /* init schemas */ + registry_add_schema_instance(®istry_sys_rgb_led, &rgb_led_instance_0); + registry_add_schema_instance(®istry_sys_rgb_led, &rgb_led_instance_1); + registry_add_schema_instance(®istry_tests_nested, &test_nested_instance); + + /* init storage */ + #if IS_USED(MODULE_LITTLEFS2) + fs_desc.dev = MTD_0; + #endif + + /* init and run CLI */ + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, sizeof(line_buf)); + return 0; +} From b5ebf73274cd2c96a5cd0f9a6688ec6a01f247d8 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:19:18 +0200 Subject: [PATCH 010/117] sys/shell: add registry cli --- sys/shell/Makefile.dep | 7 + sys/shell/cmds/Kconfig | 7 + sys/shell/cmds/registry.c | 487 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 501 insertions(+) create mode 100644 sys/shell/cmds/registry.c diff --git a/sys/shell/Makefile.dep b/sys/shell/Makefile.dep index 0254da82b22a..439cf52bd9cc 100644 --- a/sys/shell/Makefile.dep +++ b/sys/shell/Makefile.dep @@ -105,6 +105,9 @@ ifneq (,$(filter shell_cmds_default,$(USEMODULE))) ifneq (,$(filter openwsn,$(USEPKG))) USEMODULE += shell_cmd_openwsn endif + ifneq (,$(filter registry,$(USEMODULE))) + USEMODULE += shell_cmd_registry + endif ifneq (,$(filter rtt_rtc periph_rtc,$(USEMODULE))) USEMODULE += shell_cmd_rtc endif @@ -249,6 +252,10 @@ endif ifneq (,$(filter shell_cmd_random_cmd,$(USEMODULE))) USEMODULE += random endif +ifneq (,$(filter shell_cmd_registry,$(USEMODULE))) + USEMODULE += registry + USEMODULE += registry_int_path +endif ifneq (,$(filter shell_cmd_rtc,$(USEMODULE))) FEATURES_REQUIRED_ANY += periph_rtc|periph_rtt # beware: this is a bit more tricky than it looks. Before the diff --git a/sys/shell/cmds/Kconfig b/sys/shell/cmds/Kconfig index 794bca53d0e0..e5ea4c8badfc 100644 --- a/sys/shell/cmds/Kconfig +++ b/sys/shell/cmds/Kconfig @@ -251,6 +251,13 @@ config MODULE_SHELL_CMD_RANDOM depends on MODULE_SHELL_CMDS depends on MODULE_RANDOM +config MODULE_SHELL_CMD_REGISTRY + bool "Command to get, set, commit, export, save and load registry values" + default y if MODULE_SHELL_CMDS_DEFAULT + depends on MODULE_SHELL_CMDS + depends on MODULE_REGISTRY + depends on MODULE_REGISTRY_INT_PATH + config MODULE_SHELL_CMD_RTC bool "Command to control the peripheral real time clock" default y if MODULE_SHELL_CMDS_DEFAULT && MODULE_PERIPH_RTC diff --git a/sys/shell/cmds/registry.c b/sys/shell/cmds/registry.c new file mode 100644 index 000000000000..8070da1394f8 --- /dev/null +++ b/sys/shell/cmds/registry.c @@ -0,0 +1,487 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + * + */ + +/** + * @ingroup sys_shell_commands + * @{ + * + * @file + * @brief Registry shell commands + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "registry.h" +#include "registry/util.h" +#include "registry/int_path.h" +#include "registry/storage.h" +#include "shell.h" + +/** + * @brief Separator character to define hierarchy in configurations names. + */ +#define REGISTRY_CLI_PATH_SEPARATOR '/' + +static int _parse_string_path(const char *string_path, + registry_int_path_t *registry_path, + registry_int_path_type_t *registry_path_type) +{ + char *ptr = (char *)string_path; + + if (*ptr == '\0') { + return -EINVAL; + } + + /* get namespace_id */ + registry_namespace_id_t namespace_id = strtol(ptr, &ptr, 10); + + if (*ptr == '\0') { + registry_path->namespace_path = (registry_namespace_int_path_t) { + .namespace_id = namespace_id, + }; + *registry_path_type = REGISTRY_INT_PATH_TYPE_NAMESPACE; + return 0; + } + + /* get schema_id */ + ptr++; /* skip the '/' character */ + registry_schema_id_t schema_id = strtol(ptr, &ptr, 10); + + if (*ptr == '\0') { + registry_path->schema_path = (registry_schema_int_path_t) { + .namespace_id = namespace_id, + .schema_id = schema_id, + }; + *registry_path_type = REGISTRY_INT_PATH_TYPE_SCHEMA; + return 0; + } + + /* get instance_id */ + ptr++; /* skip the '/' character */ + registry_instance_id_t instance_id = strtol(ptr, &ptr, 10); + + if (*ptr == '\0') { + registry_path->instance_path = (registry_instance_int_path_t) { + .namespace_id = namespace_id, + .schema_id = schema_id, + .instance_id = instance_id, + }; + *registry_path_type = REGISTRY_INT_PATH_TYPE_INSTANCE; + return 0; + } + + /* get group_or_parameter_id */ + ptr++; /* skip the '/' character */ + registry_group_or_parameter_id_t group_or_parameter_id = strtol(ptr, &ptr, 10); + + if (*ptr == '\0') { + registry_path->group_or_parameter_path = (registry_group_or_parameter_int_path_t) { + .namespace_id = namespace_id, + .schema_id = schema_id, + .instance_id = instance_id, + .group_or_parameter_id = group_or_parameter_id, + }; + *registry_path_type = REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER; + return 0; + } + + return 0; +} + +static int _export_cb(const registry_export_cb_data_t *data, + const registry_export_cb_data_type_t data_type, + const void *context) +{ + (void)context; + + /* calculate the indentation based on the the exported data type */ + /* fallthrough switch is intentional */ + /* the more nesting we have, the more indentation we need. => highest nesting level first */ + size_t indentation = 0; + + switch (data_type) { + case REGISTRY_EXPORT_PARAMETER: + case REGISTRY_EXPORT_GROUP: + indentation++; + __attribute__ ((fallthrough)); + + case REGISTRY_EXPORT_INSTANCE: + indentation++; + __attribute__ ((fallthrough)); + + case REGISTRY_EXPORT_SCHEMA: + indentation++; + __attribute__ ((fallthrough)); + + case REGISTRY_EXPORT_NAMESPACE: + indentation++; + } + + printf("%*c\b", ((indentation - 1) * 2) + 1, ' '); + + /* print the path element, that is currently being exported */ + switch (data_type) { + case REGISTRY_EXPORT_NAMESPACE: + printf("%d %s\n", data->namespace->id, data->namespace->name); + break; + + case REGISTRY_EXPORT_SCHEMA: + printf("%d %s\n", data->schema->id, data->schema->name); + break; + + case REGISTRY_EXPORT_INSTANCE: + printf("%d %s\n", data->instance->id, data->instance->name); + break; + + case REGISTRY_EXPORT_GROUP: + printf("%d %s (group)\n", data->group->id, data->group->name); + break; + + case REGISTRY_EXPORT_PARAMETER: + printf("%d %s\n", data->parameter.data->id, data->parameter.data->name); + break; + } + + return 0; +} + +static int _registry(int argc, char **argv) +{ + registry_int_path_t path; + registry_int_path_type_t path_type; + registry_namespace_t *namespace; + registry_schema_t *schema; + registry_instance_t *instance; + registry_group_t *group; + registry_parameter_t *parameter; + registry_value_t value; + + if (argc == 1) { + /* show help for main commands */ + goto help_error; + } + + if (strcmp(argv[1], "get") == 0) { + if (_parse_string_path(argv[2], &path, &path_type) < 0) { + printf("usage: %s %s \n", argv[0], argv[1]); + return 1; + } + + if (path_type != REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { + return -EINVAL; + } + + /* get instance and parameter of the path */ + int res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, + &path_type, NULL, NULL, &instance, + &group, ¶meter); + + if (path_type != REGISTRY_INT_PATH_TYPE_PARAMETER) { + return -EINVAL; + } + + if (res == 0) { + res = registry_get(instance, parameter, &value); + + if (res == 0) { + /* get the length of the value as a string */ + size_t str_len = registry_util_convert_value_to_str(&value, NULL, 0); + + /* convert the value to a string */ + char str[str_len + 1]; + registry_util_convert_value_to_str(&value, str, str_len + 1); + + /* print the string */ + printf("%s\n", str); + return 0; + } + } + + printf("error: %d\n", res); + return 1; + } + else if (strcmp(argv[1], "set") == 0) { + if (_parse_string_path(argv[2], &path, &path_type) < 0) { + printf("usage: %s %s \n", argv[0], argv[1]); + return 1; + } + + if (path_type != REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { + return -EINVAL; + } + + /* get instance and parameter of the path */ + int res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, + &path_type, NULL, NULL, &instance, + &group, ¶meter); + + if (path_type != REGISTRY_INT_PATH_TYPE_PARAMETER) { + return -EINVAL; + } + + if (res == 0) { + /* get value from the registry, to know its correct type and size */ + res = registry_get(instance, parameter, &value); + + if (res == 0) { + /* convert the string into the correct value type */ + uint8_t new_value_buf[value.buf_len]; + registry_util_convert_str_to_value(argv[3], new_value_buf, value.buf_len, + value.type); + + /* let the registry_value_t object point to the buffer of the new value */ + value.buf = new_value_buf; + + /* set the new value in the registry */ + registry_set(instance, parameter, value.buf, value.buf_len); + return 0; + } + } + + printf("error: %d\n", res); + return 1; + } + else if (strcmp(argv[1], "commit") == 0) { + if (_parse_string_path(argv[2], &path, &path_type) < 0) { + printf("usage: %s %s \n", argv[0], argv[1]); + return 1; + } + + int res = 0; + + /* commit depending on the path type */ + switch (path_type) { + case REGISTRY_INT_PATH_TYPE_NAMESPACE: + res = registry_from_namespace_int_path(&path.namespace_path, &namespace); + if (res == 0) { + res = registry_commit_namespace(namespace); + } + break; + + case REGISTRY_INT_PATH_TYPE_SCHEMA: + res = registry_from_schema_int_path(&path.schema_path, &namespace, &schema); + if (res == 0) { + res = registry_commit_schema(schema); + } + break; + + case REGISTRY_INT_PATH_TYPE_INSTANCE: + res = registry_from_instance_int_path(&path.instance_path, &namespace, &schema, + &instance); + if (res == 0) { + res = registry_commit_instance(instance); + } + break; + + case REGISTRY_INT_PATH_TYPE_GROUP: + /* should not happen as we don't yet know if it is a group or a parameter */ + break; + + case REGISTRY_INT_PATH_TYPE_PARAMETER: + /* should not happen as we don't yet know if it is a group or a parameter */ + break; + + case REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER: + res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, + &path_type, + &namespace, &schema, &instance, + &group, ¶meter); + if (res == 0) { + if (path_type == REGISTRY_INT_PATH_TYPE_GROUP) { + res = registry_commit_group(instance, group); + } + else if (path_type == REGISTRY_INT_PATH_TYPE_PARAMETER) { + res = registry_commit_parameter(instance, parameter); + } + } + break; + } + + if (res != 0) { + printf("error: %d\n", res); + return 1; + } + + return 0; + } + else if (strcmp(argv[1], "export") == 0) { + /* if the path is invalid, it can also just be non existent, so other arguments like -r need to be checked */ + bool invalid_path = false; + if (_parse_string_path(argv[2], &path, &path_type) < 0) { + invalid_path = true; + } + if (invalid_path && strcmp(argv[2], "-r") != 0) { + printf("usage: %s %s [-r ]\n", argv[0], argv[1]); + return 1; + } + + /* the argv index of -r varies depending on if a path was specified or not */ + int recursion_level = 0; + if (invalid_path && argc > 3 && strcmp(argv[2], "-r") == 0) { + recursion_level = atoi(argv[3]); + } + else if (argc > 4 && strcmp(argv[3], "-r") == 0) { + recursion_level = atoi(argv[4]); + } + + int res = 0; + + switch (path_type) { + case REGISTRY_INT_PATH_TYPE_NAMESPACE: + res = registry_from_namespace_int_path(&path.namespace_path, &namespace); + if (res == 0) { + res = registry_export_namespace(namespace, _export_cb, recursion_level, NULL); + } + break; + + case REGISTRY_INT_PATH_TYPE_SCHEMA: + res = registry_from_schema_int_path(&path.schema_path, &namespace, &schema); + if (res == 0) { + res = registry_export_schema(schema, _export_cb, recursion_level, NULL); + } + break; + + case REGISTRY_INT_PATH_TYPE_INSTANCE: + res = registry_from_instance_int_path(&path.instance_path, &namespace, &schema, + &instance); + if (res == 0) { + res = registry_export_instance(instance, _export_cb, recursion_level, NULL); + } + break; + + case REGISTRY_INT_PATH_TYPE_GROUP: + /* should not happen as we don't yet know if it is a group or a parameter */ + break; + + case REGISTRY_INT_PATH_TYPE_PARAMETER: + /* should not happen as we don't yet know if it is a group or a parameter */ + break; + + case REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER: + res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, + &path_type, + &namespace, &schema, &instance, + &group, ¶meter); + if (res == 0) { + if (path_type == REGISTRY_INT_PATH_TYPE_GROUP) { + res = registry_export_group(instance, group, _export_cb, recursion_level, NULL); + } + else if (path_type == REGISTRY_INT_PATH_TYPE_PARAMETER) { + res = registry_export_parameter(instance, parameter, _export_cb, NULL); + } + } + break; + } + + if (res != 0) { + printf("error: %d\n", res); + return 1; + } + + return 0; + } +#if IS_USED(MODULE_REGISTRY_STORAGE) || IS_ACTIVE(DOXYGEN) + else if (strcmp(argv[1], "load") == 0) { + if (argc > 2) { + printf("usage: %s %s\n", argv[0], argv[1]); + return 1; + } + + registry_load(); + + return 0; + } + else if (strcmp(argv[1], "save") == 0) { + int res = 0; + + if (argc > 2) { + if (_parse_string_path(argv[2], &path, &path_type) < 0) { + printf("usage: %s %s [path]\n", argv[0], argv[1]); + return 1; + } + + /* commit depending on the path type */ + switch (path_type) { + case REGISTRY_INT_PATH_TYPE_NAMESPACE: + res = registry_from_namespace_int_path(&path.namespace_path, &namespace); + if (res == 0) { + res = registry_save_namespace(namespace); + } + break; + + case REGISTRY_INT_PATH_TYPE_SCHEMA: + res = registry_from_schema_int_path(&path.schema_path, &namespace, &schema); + if (res == 0) { + res = registry_save_schema(schema); + } + break; + + case REGISTRY_INT_PATH_TYPE_INSTANCE: + res = registry_from_instance_int_path(&path.instance_path, &namespace, &schema, + &instance); + if (res == 0) { + res = registry_save_instance(instance); + } + break; + + case REGISTRY_INT_PATH_TYPE_GROUP: + /* should not happen as we don't yet know if it is a group or a parameter */ + break; + + case REGISTRY_INT_PATH_TYPE_PARAMETER: + /* should not happen as we don't yet know if it is a group or a parameter */ + break; + + case REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER: + res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, + &path_type, + &namespace, &schema, &instance, + &group, ¶meter); + if (res == 0) { + if (path_type == REGISTRY_INT_PATH_TYPE_GROUP) { + res = registry_save_group(instance, group); + } + else if (path_type == REGISTRY_INT_PATH_TYPE_PARAMETER) { + res = registry_save_parameter(instance, parameter); + } + } + break; + } + } + else { + res = registry_save(); + } + + if (res != 0) { + printf("error: %d\n", res); + return 1; + } + + return 0; + } +#endif + +help_error: + printf("usage: %s {get|set|commit|export|load|save}\n", argv[0]); + + return 1; +} + +SHELL_COMMAND(registry, "Registry cli", _registry); From c559924a420410bf4618d9975028e89a80a67ec6 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:19:59 +0200 Subject: [PATCH 011/117] tests/unittests: add registry tests --- tests/unittests/tests-registry/Makefile | 1 + .../unittests/tests-registry/Makefile.include | 12 + tests/unittests/tests-registry/tests-commit.c | 190 +++ tests/unittests/tests-registry/tests-export.c | 371 +++++ .../unittests/tests-registry/tests-get-set.c | 1344 +++++++++++++++++ .../unittests/tests-registry/tests-registry.c | 32 + .../unittests/tests-registry/tests-registry.h | 37 + 7 files changed, 1987 insertions(+) create mode 100644 tests/unittests/tests-registry/Makefile create mode 100644 tests/unittests/tests-registry/Makefile.include create mode 100644 tests/unittests/tests-registry/tests-commit.c create mode 100644 tests/unittests/tests-registry/tests-export.c create mode 100644 tests/unittests/tests-registry/tests-get-set.c create mode 100644 tests/unittests/tests-registry/tests-registry.c create mode 100644 tests/unittests/tests-registry/tests-registry.h diff --git a/tests/unittests/tests-registry/Makefile b/tests/unittests/tests-registry/Makefile new file mode 100644 index 000000000000..9c9ae9884ad6 --- /dev/null +++ b/tests/unittests/tests-registry/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/tests/unittests/tests-registry/Makefile.include b/tests/unittests/tests-registry/Makefile.include new file mode 100644 index 000000000000..6e100b9e6eb2 --- /dev/null +++ b/tests/unittests/tests-registry/Makefile.include @@ -0,0 +1,12 @@ +CFLAGS += -DCONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK +CFLAGS += -DCONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK +CFLAGS += -DCONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK +CFLAGS += -DCONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK + +CFLAGS += -DCONFIG_REGISTRY_ENABLE_META_NAME + +USEMODULE += registry_namespace_tests_full +USEMODULE += registry_namespace_tests_constrained_min_max +USEMODULE += registry_namespace_tests_constrained_allowed_values +USEMODULE += registry_namespace_tests_constrained_forbidden_values +USEMODULE += registry_namespace_tests_nested diff --git a/tests/unittests/tests-registry/tests-commit.c b/tests/unittests/tests-registry/tests-commit.c new file mode 100644 index 000000000000..e6c13ace0bd3 --- /dev/null +++ b/tests/unittests/tests-registry/tests-commit.c @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @brief Unittests for registry_commit + * + * @author Lasse Rosenow + */ + +#include +#include +#include +#include +#include +#include +#include "embUnit.h" +#include "fmt.h" +#include "assert.h" +#include "vfs.h" +#include "board.h" +#include "mtd.h" +#include "registry.h" + +#include "tests-registry.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/nested.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) + +static bool successful = false; +static registry_group_or_parameter_id_t parameter_id; +static registry_group_or_parameter_id_t group_id; + +static int commit_parameter_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) +{ + (void)context; + + if (scope == REGISTRY_COMMIT_PARAMETER && group_or_parameter_id != NULL && + *group_or_parameter_id == parameter_id) { + successful = true; + } + + return 0; +} + +static int commit_group_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) +{ + (void)context; + + if (scope == REGISTRY_COMMIT_GROUP && group_or_parameter_id != NULL && + *group_or_parameter_id == group_id) { + successful = true; + } + + return 0; +} + +static int commit_instance_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) +{ + (void)context; + + if (scope == REGISTRY_COMMIT_INSTANCE && group_or_parameter_id == NULL) { + successful = true; + } + + return 0; +} + +static registry_tests_nested_instance_t test_nested_instance_data = { + .parameter = 9, + .group_parameter = 5, +}; + +static registry_instance_t test_nested_instance_parameter_test = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-nested-parameter-test", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_nested_instance_data, + .commit_cb = &commit_parameter_cb, +}; + +static registry_instance_t test_nested_instance_group_test = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-nested-group-test", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_nested_instance_data, + .commit_cb = &commit_group_cb, +}; + +static registry_instance_t test_nested_instance_instance_test = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-nested-instance-test", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_nested_instance_data, + .commit_cb = &commit_instance_cb, +}; + +static void test_registry_setup(void) +{ + /* init registry */ + registry_init(); + + /* add schema instances */ + registry_add_schema_instance(®istry_tests_nested, &test_nested_instance_parameter_test); + registry_add_schema_instance(®istry_tests_nested, &test_nested_instance_group_test); + registry_add_schema_instance(®istry_tests_nested, &test_nested_instance_instance_test); +} + +static void test_registry_teardown(void) +{ +} + +static void tests_registry_commit_parameter(void) +{ + successful = false; + parameter_id = REGISTRY_TESTS_NESTED_PARAMETER; + registry_commit_parameter(&test_nested_instance_parameter_test, + ®istry_tests_nested_parameter); + TEST_ASSERT(successful); +} + +static void tests_registry_commit_group(void) +{ + successful = false; + group_id = REGISTRY_TESTS_NESTED_GROUP; + registry_commit_group(&test_nested_instance_group_test, ®istry_tests_nested_group); + TEST_ASSERT(successful); +} + +static void tests_registry_commit_instance(void) +{ + successful = false; + registry_commit_instance(&test_nested_instance_instance_test); + TEST_ASSERT(successful); +} + +static void tests_registry_commit_schema(void) +{ + successful = false; + registry_commit_schema(®istry_tests_nested); + TEST_ASSERT(successful); +} + +static void tests_registry_commit_namespace(void) +{ + successful = false; + registry_commit_namespace(®istry_tests); + TEST_ASSERT(successful); +} + +static void tests_registry_commit_all(void) +{ + successful = false; + registry_commit(); + TEST_ASSERT(successful); +} + +Test *tests_registry_commit_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(tests_registry_commit_parameter), + new_TestFixture(tests_registry_commit_group), + new_TestFixture(tests_registry_commit_instance), + new_TestFixture(tests_registry_commit_schema), + new_TestFixture(tests_registry_commit_namespace), + new_TestFixture(tests_registry_commit_all), + }; + + EMB_UNIT_TESTCALLER(registry_tests, test_registry_setup, test_registry_teardown, fixtures); + + return (Test *)®istry_tests; +} + +#endif + +/** @} */ diff --git a/tests/unittests/tests-registry/tests-export.c b/tests/unittests/tests-registry/tests-export.c new file mode 100644 index 000000000000..757ae504abb7 --- /dev/null +++ b/tests/unittests/tests-registry/tests-export.c @@ -0,0 +1,371 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @brief Unittests for registry_export + * + * @author Lasse Rosenow + */ + +#include +#include +#include +#include +#include +#include +#include "embUnit.h" +#include "fmt.h" +#include "assert.h" +#include "vfs.h" +#include "board.h" +#include "mtd.h" +#include "registry.h" + +#include "tests-registry.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/nested.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) + +static bool successful = false; + +static registry_tests_nested_instance_t test_nested_instance_data = { + .parameter = 9, + .group_parameter = 5, +}; + +static registry_instance_t test_nested_instance_1 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-nested-parameter-test", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_nested_instance_data, + .commit_cb = NULL, +}; + +static int export_parameter_cb(const registry_export_cb_data_t *data, + const registry_export_cb_data_type_t data_type, + const void *context) +{ + (void)context; + + if (data_type == REGISTRY_EXPORT_PARAMETER && data != NULL && + data->parameter.data->id == *(registry_parameter_id_t *)context && + data->parameter.instance == &test_nested_instance_1) { + successful = true; + } + + return 0; +} + +static int export_group_cb(const registry_export_cb_data_t *data, + const registry_export_cb_data_type_t data_type, + const void *context) +{ + (void)context; + + if (data_type == REGISTRY_EXPORT_GROUP && data != NULL && + data->group->id == *(registry_group_id_t *)context) { + successful = true; + } + + return 0; +} + +static int export_instance_cb(const registry_export_cb_data_t *data, + const registry_export_cb_data_type_t data_type, + const void *context) +{ + (void)context; + + if (data_type == REGISTRY_EXPORT_INSTANCE && data != NULL && + data->instance == &test_nested_instance_1) { + successful = true; + } + + return 0; +} + +static int export_schema_cb(const registry_export_cb_data_t *data, + const registry_export_cb_data_type_t data_type, + const void *context) +{ + (void)context; + + if (data_type == REGISTRY_EXPORT_SCHEMA && data != NULL && + data->schema == ®istry_tests_nested) { + successful = true; + } + + return 0; +} + +static int export_namespace_cb(const registry_export_cb_data_t *data, + const registry_export_cb_data_type_t data_type, + const void *context) +{ + (void)context; + + if (data_type == REGISTRY_EXPORT_NAMESPACE && data != NULL && + data->namespace == ®istry_tests) { + successful = true; + } + + return 0; +} + +static void test_registry_setup(void) +{ + /* init registry */ + registry_init(); + + /* add schema instances */ + registry_add_schema_instance(®istry_tests_nested, &test_nested_instance_1); +} + +static void test_registry_teardown(void) +{ +} + +static void tests_registry_export_parameter(void) +{ + const registry_parameter_id_t parameter_id = REGISTRY_TESTS_NESTED_PARAMETER; + + successful = false; + registry_export_parameter(&test_nested_instance_1, ®istry_tests_nested_parameter, + &export_parameter_cb, ¶meter_id); + TEST_ASSERT(successful); +} + +static void tests_registry_export_group(void) +{ + /* check if group gets exported */ + const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; + + successful = false; + registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, &export_group_cb, + 0, &group_id); + TEST_ASSERT(successful); + + + /* check that siblings get NOT exported */ + const registry_parameter_id_t sibling_parameter_id = REGISTRY_TESTS_NESTED_PARAMETER; + successful = false; + registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, + &export_parameter_cb, 0, &sibling_parameter_id); + TEST_ASSERT_EQUAL_INT(false, successful); + + + /* check if children get exported */ + const registry_parameter_id_t child_parameter_id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER; + + /* recursion_depth 0 => infinite => parameter gets exported */ + successful = false; + registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, + &export_parameter_cb, 0, &child_parameter_id); + TEST_ASSERT(successful); + + /* recursion_depth 1 => only group => parameter gets NOT exported */ + successful = false; + registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, + &export_parameter_cb, 1, &child_parameter_id); + TEST_ASSERT_EQUAL_INT(false, successful); + + /* recursion_depth 2 => group + 1 level more => parameter gets exported */ + successful = false; + registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, + &export_parameter_cb, 2, &child_parameter_id); + TEST_ASSERT(successful); +} + +static void tests_registry_export_instance(void) +{ + /* check if instance gets exported */ + successful = false; + registry_export_instance(&test_nested_instance_1, &export_instance_cb, 0, NULL); + TEST_ASSERT(successful); + + + /* check if group gets exported */ + const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; + + successful = false; + registry_export_instance(&test_nested_instance_1, &export_group_cb, 0, &group_id); + TEST_ASSERT(successful); + + + /* check if parameter get exported */ + const registry_parameter_id_t child_parameter_id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER; + + /* recursion_depth 0 => infinite => parameter gets exported */ + successful = false; + registry_export_instance(&test_nested_instance_1, &export_parameter_cb, 0, &child_parameter_id); + TEST_ASSERT(successful); + + /* recursion_depth 2 => only instance and group => parameter gets NOT exported */ + successful = false; + registry_export_instance(&test_nested_instance_1, &export_parameter_cb, 2, &child_parameter_id); + TEST_ASSERT_EQUAL_INT(false, successful); + + /* recursion_depth 3 => instance, group and parameter => parameter gets exported */ + successful = false; + registry_export_instance(&test_nested_instance_1, &export_parameter_cb, 3, &child_parameter_id); + TEST_ASSERT(successful); +} + +static void tests_registry_export_schema(void) +{ + /* check if schema gets exported */ + successful = false; + registry_export_schema(®istry_tests_nested, &export_schema_cb, 0, NULL); + TEST_ASSERT(successful); + + /* check if instance gets exported */ + successful = false; + registry_export_schema(®istry_tests_nested, &export_instance_cb, 0, NULL); + TEST_ASSERT(successful); + + + /* check if group gets exported */ + const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; + + successful = false; + registry_export_schema(®istry_tests_nested, &export_group_cb, 0, &group_id); + TEST_ASSERT(successful); + + + /* check if parameter get exported */ + const registry_parameter_id_t child_parameter_id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER; + + /* recursion_depth 0 => infinite => parameter gets exported */ + successful = false; + registry_export_schema(®istry_tests_nested, &export_parameter_cb, 0, &child_parameter_id); + TEST_ASSERT(successful); + + /* recursion_depth 3 => only schema, instance and group => parameter gets NOT exported */ + successful = false; + registry_export_schema(®istry_tests_nested, &export_parameter_cb, 3, &child_parameter_id); + TEST_ASSERT_EQUAL_INT(false, successful); + + /* recursion_depth 4 => schema, instance, group and parameter => parameter gets exported */ + successful = false; + registry_export_schema(®istry_tests_nested, &export_parameter_cb, 4, &child_parameter_id); + TEST_ASSERT(successful); +} + +static void tests_registry_export_namespace(void) +{ + /* check if namespace gets exported */ + successful = false; + registry_export_namespace(®istry_tests, &export_namespace_cb, 0, NULL); + TEST_ASSERT(successful); + + /* check if schema gets exported */ + successful = false; + registry_export_namespace(®istry_tests, &export_schema_cb, 0, NULL); + TEST_ASSERT(successful); + + /* check if instance gets exported */ + successful = false; + registry_export_namespace(®istry_tests, &export_instance_cb, 0, NULL); + TEST_ASSERT(successful); + + + /* check if group gets exported */ + const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; + + successful = false; + registry_export_namespace(®istry_tests, &export_group_cb, 0, &group_id); + TEST_ASSERT(successful); + + + /* check if parameter get exported */ + const registry_parameter_id_t child_parameter_id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER; + + /* recursion_depth 0 => infinite => parameter gets exported */ + successful = false; + registry_export_namespace(®istry_tests, &export_parameter_cb, 0, &child_parameter_id); + TEST_ASSERT(successful); + + /* recursion_depth 4 => only namespace, schema, instance and group => parameter gets NOT exported */ + successful = false; + registry_export_namespace(®istry_tests, &export_parameter_cb, 4, &child_parameter_id); + TEST_ASSERT_EQUAL_INT(false, successful); + + /* recursion_depth 5 => namespace, schema, instance, group and parameter => parameter gets exported */ + successful = false; + registry_export_namespace(®istry_tests, &export_parameter_cb, 5, &child_parameter_id); + TEST_ASSERT(successful); +} + +static void tests_registry_export_all(void) +{ + /* check if namespace gets exported */ + successful = false; + registry_export(&export_namespace_cb, 0, NULL); + TEST_ASSERT(successful); + + /* check if schema gets exported */ + successful = false; + registry_export( &export_schema_cb, 0, NULL); + TEST_ASSERT(successful); + + /* check if instance gets exported */ + successful = false; + registry_export( &export_instance_cb, 0, NULL); + TEST_ASSERT(successful); + + + /* check if group gets exported */ + const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; + + successful = false; + registry_export( &export_group_cb, 0, &group_id); + TEST_ASSERT(successful); + + + /* check if parameter get exported */ + const registry_parameter_id_t child_parameter_id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER; + + /* recursion_depth 0 => infinite => parameter gets exported */ + successful = false; + registry_export( &export_parameter_cb, 0, &child_parameter_id); + TEST_ASSERT(successful); + + /* recursion_depth 4 => only namespace, schema, instance and group => parameter gets NOT exported */ + successful = false; + registry_export(&export_parameter_cb, 4, &child_parameter_id); + TEST_ASSERT_EQUAL_INT(false, successful); + + /* recursion_depth 5 => namespace, schema, instance, group and parameter => parameter gets exported */ + successful = false; + registry_export(&export_parameter_cb, 5, &child_parameter_id); + TEST_ASSERT(successful); +} + +Test *tests_registry_export_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(tests_registry_export_parameter), + new_TestFixture(tests_registry_export_group), + new_TestFixture(tests_registry_export_instance), + new_TestFixture(tests_registry_export_schema), + new_TestFixture(tests_registry_export_namespace), + new_TestFixture(tests_registry_export_all), + }; + + EMB_UNIT_TESTCALLER(registry_tests, test_registry_setup, test_registry_teardown, fixtures); + + return (Test *)®istry_tests; +} + +#endif + +/** @} */ diff --git a/tests/unittests/tests-registry/tests-get-set.c b/tests/unittests/tests-registry/tests-get-set.c new file mode 100644 index 000000000000..37ccd656bd87 --- /dev/null +++ b/tests/unittests/tests-registry/tests-get-set.c @@ -0,0 +1,1344 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @brief Unittests for registry_get, registry_set + * + * @author Lasse Rosenow + */ + +#include +#include +#include +#include +#include +#include +#include "embUnit.h" +#include "fmt.h" +#include "assert.h" +#include "vfs.h" +#include "board.h" +#include "mtd.h" +#include "registry.h" + +#include "tests-registry.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/full.h" +#include "registry/namespace/tests/constrained_min_max.h" +#include "registry/namespace/tests/constrained_allowed_values.h" +#include "registry/namespace/tests/constrained_forbidden_values.h" + +#define FLOAT_MAX_CHAR_COUNT ((FLT_MAX_10_EXP + 1) + 1 + 1 + 6) // (FLT_MAX_10_EXP + 1) + sign + dot + 6 decimal places +#define DOUBLE_MAX_CHAR_COUNT ((DBL_MAX_10_EXP + 1) + 1 + 1 + 6) // (DBL_MAX_10_EXP + 1) + sign + dot + 6 decimal places + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) || IS_ACTIVE(DOXYGEN) + +static int commit_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) +{ + (void)scope; + (void)group_or_parameter_id; + (void)context; + + return 0; +} + +static registry_tests_full_instance_t test_full_instance_1_data = { + .opaque = { + .value = 7, + }, + .string = "hello world", + .boolean = true, + .u8 = 9, + .u16 = 17, + .u32 = 33, + .u64 = 65, + .i8 = 8, + .i16 = 16, + .i32 = 32, + .i64 = 64, + .f32 = 3.2, + .f64 = 6.4, +}; + +static registry_instance_t test_full_instance_1 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-full-1", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_full_instance_1_data, + .commit_cb = &commit_cb, +}; + +static registry_tests_constrained_min_max_instance_t test_constrained_min_max_instance_1_data = { + .opaque = { + .value = 7, + }, + .string = "hello world", + .boolean = true, + .u8 = 9, + .u16 = 17, + .u32 = 33, + .u64 = 65, + .i8 = 8, + .i16 = 16, + .i32 = 32, + .i64 = 64, + .f32 = 3.2, + .f64 = 6.4, +}; + +static registry_instance_t test_constrained_min_max_instance_1 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-constrained_min_max-1", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_constrained_min_max_instance_1_data, + .commit_cb = &commit_cb, +}; + +static registry_tests_constrained_allowed_values_instance_t + test_constrained_allowed_values_instance_1_data = { + .opaque = { + .value = 7, + }, + .string = "hello world", + .boolean = true, + .u8 = 9, + .u16 = 17, + .u32 = 33, + .u64 = 65, + .i8 = 8, + .i16 = 16, + .i32 = 32, + .i64 = 64, + .f32 = 3.2, + .f64 = 6.4, +}; + +static registry_instance_t test_constrained_allowed_values_instance_1 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-constrained_allowed_values-1", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_constrained_allowed_values_instance_1_data, + .commit_cb = &commit_cb, +}; + +static registry_tests_constrained_forbidden_values_instance_t + test_constrained_forbidden_values_instance_1_data = { + .opaque = { + .value = 7, + }, + .string = "hello world", + .boolean = true, + .u8 = 9, + .u16 = 17, + .u32 = 33, + .u64 = 65, + .i8 = 8, + .i16 = 16, + .i32 = 32, + .i64 = 64, + .f32 = 3.2, + .f64 = 6.4, +}; + +static registry_instance_t test_constrained_forbidden_values_instance_1 = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-constrained_forbidden_values-1", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_constrained_forbidden_values_instance_1_data, + .commit_cb = &commit_cb, +}; + +static void test_registry_setup(void) +{ + /* init registry */ + registry_init(); + + /* add schema instances */ + registry_add_schema_instance(®istry_tests_full, &test_full_instance_1); + registry_add_schema_instance(®istry_tests_constrained_min_max, + &test_constrained_min_max_instance_1); +} + +static void test_registry_teardown(void) +{ +} + +static void tests_registry_min_values(void) +{ + registry_value_t output; + + /* opaque */ + const registry_tests_full_instance_opaque_t input_opaque = { + .value = 0, + }; + + registry_set(&test_full_instance_1, ®istry_tests_full_opaque, &input_opaque, + sizeof(input_opaque)); + registry_get(&test_full_instance_1, ®istry_tests_full_opaque, &output); + + TEST_ASSERT_EQUAL_INT(input_opaque.value, + ((registry_tests_full_instance_opaque_t *)output.buf)->value); + + /* string */ + const char input_string[] = ""; + + registry_set(&test_full_instance_1, ®istry_tests_full_string, input_string, + sizeof(input_string)); + registry_get(&test_full_instance_1, ®istry_tests_full_string, &output); + + TEST_ASSERT_EQUAL_STRING("", (char *)output.buf); + + + /* bool */ + const bool input_bool = false; + + registry_set(&test_full_instance_1, ®istry_tests_full_boolean, &input_bool, + sizeof(input_bool)); + registry_get(&test_full_instance_1, ®istry_tests_full_boolean, &output); + + TEST_ASSERT_EQUAL_INT(input_bool, *(bool *)output.buf); + + + /* u8 */ + const uint8_t input_u8 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_u8, &input_u8, sizeof(input_u8)); + registry_get(&test_full_instance_1, ®istry_tests_full_u8, &output); + + TEST_ASSERT_EQUAL_INT(input_u8, *(uint8_t *)output.buf); + + + /* u16 */ + const uint16_t input_u16 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_u16, &input_u16, sizeof(input_u16)); + registry_get(&test_full_instance_1, ®istry_tests_full_u16, &output); + + TEST_ASSERT_EQUAL_INT(input_u16, *(uint16_t *)output.buf); + + + /* u32 */ + const uint32_t input_u32 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_u32, &input_u32, sizeof(input_u32)); + registry_get(&test_full_instance_1, ®istry_tests_full_u32, &output); + + TEST_ASSERT_EQUAL_INT(input_u32, *(uint32_t *)output.buf); + + + /* u64 */ + const uint64_t input_u64 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_u64, &input_u64, sizeof(input_u64)); + registry_get(&test_full_instance_1, ®istry_tests_full_u64, &output); + + TEST_ASSERT_EQUAL_INT(input_u64, *(uint64_t *)output.buf); + + + /* i8 */ + const int8_t input_i8 = INT8_MIN; + + registry_set(&test_full_instance_1, ®istry_tests_full_i8, &input_i8, sizeof(input_i8)); + registry_get(&test_full_instance_1, ®istry_tests_full_i8, &output); + + TEST_ASSERT_EQUAL_INT(input_i8, *(int8_t *)output.buf); + + + /* i16 */ + const int16_t input_i16 = INT16_MIN; + + registry_set(&test_full_instance_1, ®istry_tests_full_i16, &input_i16, sizeof(input_i16)); + registry_get(&test_full_instance_1, ®istry_tests_full_i16, &output); + + TEST_ASSERT_EQUAL_INT(input_i16, *(int16_t *)output.buf); + + + /* i32 */ + const int32_t input_i32 = INT32_MIN; + + registry_set(&test_full_instance_1, ®istry_tests_full_i32, &input_i32, sizeof(input_i32)); + registry_get(&test_full_instance_1, ®istry_tests_full_i32, &output); + + TEST_ASSERT_EQUAL_INT(input_i32, *(int32_t *)output.buf); + + + /* i64 */ + const int64_t input_i64 = INT64_MIN; + + registry_set(&test_full_instance_1, ®istry_tests_full_i64, &input_i64, sizeof(input_i64)); + registry_get(&test_full_instance_1, ®istry_tests_full_i64, &output); + + TEST_ASSERT_EQUAL_INT(input_i64, *(int64_t *)output.buf); + + + /* f32 */ + const float input_f32 = FLT_MIN; + + registry_set(&test_full_instance_1, ®istry_tests_full_f32, &input_f32, sizeof(input_f32)); + registry_get(&test_full_instance_1, ®istry_tests_full_f32, &output); + + char input_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; + char output_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; + sprintf(input_f32_string, "%f", input_f32); + sprintf(output_f32_string, "%f", *(float *)output.buf); + + TEST_ASSERT_EQUAL_STRING(input_f32_string, output_f32_string); + + + /* f64 */ + const double input_f64 = DBL_MIN; + + registry_set(&test_full_instance_1, ®istry_tests_full_f64, &input_f64, sizeof(input_f64)); + registry_get(&test_full_instance_1, ®istry_tests_full_f64, &output); + + char input_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; + char output_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; + sprintf(input_f64_string, "%f", input_f64); + sprintf(output_f64_string, "%f", *(double *)output.buf); + + TEST_ASSERT_EQUAL_STRING(input_f64_string, output_f64_string); +} + +static void tests_registry_zero_values(void) +{ + registry_value_t output; + + /* opaque */ + const registry_tests_full_instance_opaque_t input_opaque = { + .value = 0, + }; + + registry_set(&test_full_instance_1, ®istry_tests_full_opaque, &input_opaque, + sizeof(input_opaque)); + registry_get(&test_full_instance_1, ®istry_tests_full_opaque, &output); + + TEST_ASSERT_EQUAL_INT(input_opaque.value, + ((registry_tests_full_instance_opaque_t *)output.buf)->value); + + + /* string */ + const char input_string[] = ""; + + registry_set(&test_full_instance_1, ®istry_tests_full_string, input_string, + sizeof(input_string)); + registry_get(&test_full_instance_1, ®istry_tests_full_string, &output); + + TEST_ASSERT_EQUAL_STRING("", (char *)output.buf); + + + /* bool */ + const bool input_bool = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_boolean, &input_bool, + sizeof(input_bool)); + registry_get(&test_full_instance_1, ®istry_tests_full_boolean, &output); + + TEST_ASSERT_EQUAL_INT(input_bool, *(bool *)output.buf); + + + /* u8 */ + const uint8_t input_u8 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_u8, &input_u8, sizeof(input_u8)); + registry_get(&test_full_instance_1, ®istry_tests_full_u8, &output); + + TEST_ASSERT_EQUAL_INT(input_u8, *(uint8_t *)output.buf); + + + /* u16 */ + const uint16_t input_u16 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_u16, &input_u16, sizeof(input_u16)); + registry_get(&test_full_instance_1, ®istry_tests_full_u16, &output); + + TEST_ASSERT_EQUAL_INT(input_u16, *(uint16_t *)output.buf); + + + /* u32 */ + const uint32_t input_u32 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_u32, &input_u32, sizeof(input_u32)); + registry_get(&test_full_instance_1, ®istry_tests_full_u32, &output); + + TEST_ASSERT_EQUAL_INT(input_u32, *(uint32_t *)output.buf); + + + /* u64 */ + const uint64_t input_u64 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_u64, &input_u64, sizeof(input_u64)); + registry_get(&test_full_instance_1, ®istry_tests_full_u64, &output); + + TEST_ASSERT_EQUAL_INT(input_u64, *(uint64_t *)output.buf); + + + /* i8 */ + const int8_t input_i8 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_i8, &input_i8, sizeof(input_i8)); + registry_get(&test_full_instance_1, ®istry_tests_full_i8, &output); + + TEST_ASSERT_EQUAL_INT(input_i8, *(int8_t *)output.buf); + + + /* i16 */ + const int16_t input_i16 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_i16, &input_i16, sizeof(input_i16)); + registry_get(&test_full_instance_1, ®istry_tests_full_i16, &output); + + TEST_ASSERT_EQUAL_INT(input_i16, *(int16_t *)output.buf); + + + /* i32 */ + const int32_t input_i32 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_i32, &input_i32, sizeof(input_i32)); + registry_get(&test_full_instance_1, ®istry_tests_full_i32, &output); + + TEST_ASSERT_EQUAL_INT(input_i32, *(int32_t *)output.buf); + + + /* i64 */ + const int64_t input_i64 = 0; + + registry_set(&test_full_instance_1, ®istry_tests_full_i64, &input_i64, sizeof(input_i64)); + registry_get(&test_full_instance_1, ®istry_tests_full_i64, &output); + + TEST_ASSERT_EQUAL_INT(input_i64, *(int64_t *)output.buf); + + + /* f32 */ + const float input_f32 = 0.0; + + registry_set(&test_full_instance_1, ®istry_tests_full_f32, &input_f32, sizeof(input_f32)); + registry_get(&test_full_instance_1, ®istry_tests_full_f32, &output); + + char input_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; + char output_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; + sprintf(input_f32_string, "%f", input_f32); + sprintf(output_f32_string, "%f", *(float *)output.buf); + + TEST_ASSERT_EQUAL_STRING(input_f32_string, output_f32_string); + + + /* f64 */ + const double input_f64 = 0.0; + + registry_set(&test_full_instance_1, ®istry_tests_full_f64, &input_f64, sizeof(input_f64)); + registry_get(&test_full_instance_1, ®istry_tests_full_f64, &output); + + char input_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; + char output_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; + sprintf(input_f64_string, "%f", input_f64); + sprintf(output_f64_string, "%f", *(double *)output.buf); + + TEST_ASSERT_EQUAL_STRING(input_f64_string, output_f64_string); +} + +static void tests_registry_max_values(void) +{ + registry_value_t output; + + /* opaque */ + const registry_tests_full_instance_opaque_t input_opaque = { + .value = UINT8_MAX, + }; + + registry_set(&test_full_instance_1, ®istry_tests_full_opaque, &input_opaque, + sizeof(input_opaque)); + registry_get(&test_full_instance_1, ®istry_tests_full_opaque, &output); + + TEST_ASSERT_EQUAL_INT(input_opaque.value, + ((registry_tests_full_instance_opaque_t *)output.buf)->value); + + + /* string */ + char input_string[sizeof(test_full_instance_1_data.string)] = { 0 }; + + for (size_t i = 0; i < sizeof(input_string) - 1; i++) { + input_string[i] = 'a'; + } + + registry_set(&test_full_instance_1, ®istry_tests_full_string, input_string, + sizeof(input_string)); + registry_get(&test_full_instance_1, ®istry_tests_full_string, &output); + + TEST_ASSERT_EQUAL_STRING(input_string, (char *)output.buf); + + + /* bool */ + const bool input_bool = true; + + registry_set(&test_full_instance_1, ®istry_tests_full_boolean, &input_bool, + sizeof(input_bool)); + registry_get(&test_full_instance_1, ®istry_tests_full_boolean, &output); + + TEST_ASSERT_EQUAL_INT(input_bool, *(bool *)output.buf); + + + /* u8 */ + const uint8_t input_u8 = UINT8_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_u8, &input_u8, sizeof(input_u8)); + registry_get(&test_full_instance_1, ®istry_tests_full_u8, &output); + + TEST_ASSERT_EQUAL_INT(input_u8, *(uint8_t *)output.buf); + + + /* u16 */ + const uint16_t input_u16 = UINT16_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_u16, &input_u16, sizeof(input_u16)); + registry_get(&test_full_instance_1, ®istry_tests_full_u16, &output); + + TEST_ASSERT_EQUAL_INT(input_u16, *(uint16_t *)output.buf); + + + /* u32 */ + const uint32_t input_u32 = UINT32_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_u32, &input_u32, sizeof(input_u32)); + registry_get(&test_full_instance_1, ®istry_tests_full_u32, &output); + + TEST_ASSERT_EQUAL_INT(input_u32, *(uint32_t *)output.buf); + + + /* u64 */ + const uint64_t input_u64 = UINT64_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_u64, &input_u64, sizeof(input_u64)); + registry_get(&test_full_instance_1, ®istry_tests_full_u64, &output); + + TEST_ASSERT_EQUAL_INT(input_u64, *(uint64_t *)output.buf); + + + /* i8 */ + const int8_t input_i8 = INT8_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_i8, &input_i8, sizeof(input_i8)); + registry_get(&test_full_instance_1, ®istry_tests_full_i8, &output); + + TEST_ASSERT_EQUAL_INT(input_i8, *(int8_t *)output.buf); + + + /* i16 */ + const int16_t input_i16 = INT16_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_i16, &input_i16, sizeof(input_i16)); + registry_get(&test_full_instance_1, ®istry_tests_full_i16, &output); + + TEST_ASSERT_EQUAL_INT(input_i16, *(int16_t *)output.buf); + + + /* i32 */ + const int32_t input_i32 = INT32_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_i32, &input_i32, sizeof(input_i32)); + registry_get(&test_full_instance_1, ®istry_tests_full_i32, &output); + + TEST_ASSERT_EQUAL_INT(input_i32, *(int32_t *)output.buf); + + + /* i64 */ + const int64_t input_i64 = INT64_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_i64, &input_i64, sizeof(input_i64)); + registry_get(&test_full_instance_1, ®istry_tests_full_i64, &output); + + TEST_ASSERT_EQUAL_INT(input_i64, *(int64_t *)output.buf); + + + /* f32 */ + const float input_f32 = FLT_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_f32, &input_f32, sizeof(input_f32)); + registry_get(&test_full_instance_1, ®istry_tests_full_f32, &output); + + char input_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; + char output_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; + sprintf(input_f32_string, "%f", input_f32); + sprintf(output_f32_string, "%f", *(float *)output.buf); + + TEST_ASSERT_EQUAL_STRING(input_f32_string, output_f32_string); + + + /* f64 */ + const double input_f64 = DBL_MAX; + + registry_set(&test_full_instance_1, ®istry_tests_full_f64, &input_f64, sizeof(input_f64)); + registry_get(&test_full_instance_1, ®istry_tests_full_f64, &output); + + char input_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; + char output_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; + sprintf(input_f64_string, "%f", input_f64); + sprintf(output_f64_string, "%f", *(double *)output.buf); + + TEST_ASSERT_EQUAL_STRING(input_f64_string, output_f64_string); +} + +static void tests_registry_constraints_min_max(void) +{ + int res_too_small; + int res_too_large; + int res_within_range; + + /* opaque */ + /* opaque does not have min_max constraints */ + + /* string */ + /* string does not have min_max constraints */ + + /* bool */ + /* bool does not have min_max constraints */ + + /* u8 */ + const uint8_t input_u8_too_small = + *registry_tests_constrained_min_max_u8.constraints.uint8.min_value - 1; + + const uint8_t input_u8_too_large = + *registry_tests_constrained_min_max_u8.constraints.uint8.max_value + 1; + const uint8_t input_u8_within_range = + *registry_tests_constrained_min_max_u8.constraints.uint8.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u8, + &input_u8_too_small, sizeof(input_u8_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u8, + &input_u8_too_large, sizeof(input_u8_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u8, + &input_u8_within_range, sizeof(input_u8_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); + + + /* u16 */ + const uint16_t input_u16_too_small = + *registry_tests_constrained_min_max_u16.constraints.uint16.min_value - + 1; + const uint16_t input_u16_too_large = + *registry_tests_constrained_min_max_u16.constraints.uint16.max_value + + 1; + const uint16_t input_u16_within_range = + *registry_tests_constrained_min_max_u16.constraints.uint16.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u16, + &input_u16_too_small, sizeof(input_u16_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u16, + &input_u16_too_large, sizeof(input_u16_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u16, + &input_u16_within_range, sizeof(input_u16_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); + + + /* u32 */ + const uint32_t input_u32_too_small = + *registry_tests_constrained_min_max_u32.constraints.uint32.min_value - + 1; + const uint32_t input_u32_too_large = + *registry_tests_constrained_min_max_u32.constraints.uint32.max_value + + 1; + const uint32_t input_u32_within_range = + *registry_tests_constrained_min_max_u32.constraints.uint32.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u32, + &input_u32_too_small, sizeof(input_u32_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u32, + &input_u32_too_large, sizeof(input_u32_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u32, + &input_u32_within_range, sizeof(input_u32_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); + + + /* u64 */ + const uint64_t input_u64_too_small = + *registry_tests_constrained_min_max_u64.constraints.uint64.min_value - + 1; + const uint64_t input_u64_too_large = + *registry_tests_constrained_min_max_u64.constraints.uint64.max_value + + 1; + const uint64_t input_u64_within_range = + *registry_tests_constrained_min_max_u64.constraints.uint64.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u64, + &input_u64_too_small, sizeof(input_u64_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u64, + &input_u64_too_large, sizeof(input_u64_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_u64, + &input_u64_within_range, sizeof(input_u64_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); + + + /* i8 */ + const uint8_t input_i8_too_small = + *registry_tests_constrained_min_max_i8.constraints.int8.min_value - + 1; + const int8_t input_i8_too_large = + *registry_tests_constrained_min_max_i8.constraints.int8.max_value + + 1; + const int8_t input_i8_within_range = + *registry_tests_constrained_min_max_i8.constraints.int8.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i8, + &input_i8_too_small, sizeof(input_i8_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i8, + &input_i8_too_large, sizeof(input_i8_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i8, + &input_i8_within_range, sizeof(input_i8_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); + + + /* i16 */ + const int16_t input_i16_too_small = + *registry_tests_constrained_min_max_i16.constraints.int16.min_value - + 1; + const int16_t input_i16_too_large = + *registry_tests_constrained_min_max_i16.constraints.int16.max_value + + 1; + const int16_t input_i16_within_range = + *registry_tests_constrained_min_max_i16.constraints.int16.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i16, + &input_i16_too_small, sizeof(input_i16_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i16, + &input_i16_too_large, sizeof(input_i16_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i16, + &input_i16_within_range, sizeof(input_i16_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); + + + /* i32 */ + const int32_t input_i32_too_small = + *registry_tests_constrained_min_max_i32.constraints.int32.min_value - + 1; + const int32_t input_i32_too_large = + *registry_tests_constrained_min_max_i32.constraints.int32.max_value + + 1; + const int32_t input_i32_within_range = + *registry_tests_constrained_min_max_i32.constraints.int32.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i32, + &input_i32_too_small, sizeof(input_i32_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i32, + &input_i32_too_large, sizeof(input_i32_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i32, + &input_i32_within_range, sizeof(input_i32_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); + + + /* i64 */ + const int64_t input_i64_too_small = + *registry_tests_constrained_min_max_i64.constraints.int64.min_value - + 1; + const int64_t input_i64_too_large = + *registry_tests_constrained_min_max_i64.constraints.int64.max_value + + 1; + const int64_t input_i64_within_range = + *registry_tests_constrained_min_max_i64.constraints.int64.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i64, + &input_i64_too_small, sizeof(input_i64_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i64, + &input_i64_too_large, sizeof(input_i64_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_i64, + &input_i64_within_range, sizeof(input_i64_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); + + + /* f32 */ + const float input_f32_too_small = + *registry_tests_constrained_min_max_f32.constraints.float32.min_value - + 1.0; + const float input_f32_too_large = + *registry_tests_constrained_min_max_f32.constraints.float32.max_value + + 1.0; + const float input_f32_within_range = + *registry_tests_constrained_min_max_f32.constraints.float32.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_f32, + &input_f32_too_small, sizeof(input_f32_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_f32, + &input_f32_too_large, sizeof(input_f32_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_f32, + &input_f32_within_range, sizeof(input_f32_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); + + + /* f64 */ + const double input_f64_too_small = + *registry_tests_constrained_min_max_f64.constraints.float64.min_value - + 1.0; + const double input_f64_too_large = + *registry_tests_constrained_min_max_f64.constraints.float64.max_value + + 1.0; + const double input_f64_within_range = + *registry_tests_constrained_min_max_f64.constraints.float64.min_value; + + res_too_small = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_f64, + &input_f64_too_small, sizeof(input_f64_too_small)); + + res_too_large = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_f64, + &input_f64_too_large, sizeof(input_f64_too_large)); + + res_within_range = registry_set(&test_constrained_min_max_instance_1, + ®istry_tests_constrained_min_max_f64, + &input_f64_within_range, sizeof(input_f64_within_range)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); + TEST_ASSERT_EQUAL_INT(0, res_within_range); +} + +static void tests_registry_constraints_allowed_values(void) +{ + int res_allowed; + int res_other; + + /* opaque */ + const registry_tests_constrained_allowed_values_instance_opaque_t *input_opaque_allowed = + registry_tests_constrained_allowed_values_opaque.constraints.opaque.allowed_values[0]; + const registry_tests_constrained_allowed_values_instance_opaque_t input_opaque_other = { + .value = 19, + }; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_opaque, + input_opaque_allowed, sizeof(*input_opaque_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_opaque, + &input_opaque_other, sizeof(input_opaque_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + + /* string */ + const char *input_string_allowed = + registry_tests_constrained_allowed_values_string.constraints.string.allowed_values[0]; + const char *input_string_other = "test test"; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_string, + input_string_allowed, sizeof(input_string_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_string, + input_string_other, sizeof(input_string_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + + /* bool */ + /* bool does not have allowed values constraints */ + + /* u8 */ + const uint8_t input_u8_allowed = + registry_tests_constrained_allowed_values_u8.constraints.uint8.allowed_values[0]; + const uint8_t input_u8_other = + registry_tests_constrained_allowed_values_u8.constraints.uint8.allowed_values[0] + 1; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_u8, + &input_u8_allowed, sizeof(input_u8_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_u8, + &input_u8_other, sizeof(input_u8_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + + /* u16 */ + const uint16_t input_u16_allowed = + registry_tests_constrained_allowed_values_u16.constraints.uint16.allowed_values[0]; + const uint16_t input_u16_other = + registry_tests_constrained_allowed_values_u16.constraints.uint16.allowed_values[0] + 1; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_u16, + &input_u16_allowed, sizeof(input_u16_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_u16, + &input_u16_other, sizeof(input_u16_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + + /* u32 */ + const uint32_t input_u32_allowed = + registry_tests_constrained_allowed_values_u32.constraints.uint32.allowed_values[0]; + const uint32_t input_u32_other = + registry_tests_constrained_allowed_values_u32.constraints.uint32.allowed_values[0] + 1; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_u32, + &input_u32_allowed, sizeof(input_u32_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_u32, + &input_u32_other, sizeof(input_u16_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + + /* u64 */ + const uint64_t input_u64_allowed = + registry_tests_constrained_allowed_values_u64.constraints.uint64.allowed_values[0]; + const uint64_t input_u64_other = + registry_tests_constrained_allowed_values_u64.constraints.uint64.allowed_values[0] + 1; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_u64, + &input_u64_allowed, sizeof(input_u64_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_u64, + &input_u64_other, sizeof(input_u16_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + + /* i8 */ + const int8_t input_i8_allowed = + registry_tests_constrained_allowed_values_i8.constraints.int8.allowed_values[0]; + const int8_t input_i8_other = + registry_tests_constrained_allowed_values_i8.constraints.int8.allowed_values[0] + 1; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_i8, + &input_i8_allowed, sizeof(input_i8_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_i8, + &input_i8_other, sizeof(input_i8_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + + /* i16 */ + const int16_t input_i16_allowed = + registry_tests_constrained_allowed_values_i16.constraints.int16.allowed_values[0]; + const int16_t input_i16_other = + registry_tests_constrained_allowed_values_i16.constraints.int16.allowed_values[0] + 1; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_i16, + &input_i16_allowed, sizeof(input_i16_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_i16, + &input_i16_other, sizeof(input_i16_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + + /* i32 */ + const int32_t input_i32_allowed = + registry_tests_constrained_allowed_values_i32.constraints.int32.allowed_values[0]; + const int32_t input_i32_other = + registry_tests_constrained_allowed_values_i32.constraints.int32.allowed_values[0] + 1; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_i32, + &input_i32_allowed, sizeof(input_i32_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_i32, + &input_i32_other, sizeof(input_i32_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + + /* i64 */ + const int64_t input_i64_allowed = + registry_tests_constrained_allowed_values_i64.constraints.int64.allowed_values[0]; + const int64_t input_i64_other = + registry_tests_constrained_allowed_values_i64.constraints.int64.allowed_values[0] + 1; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_i64, + &input_i64_allowed, sizeof(input_i64_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_i64, + &input_i64_other, sizeof(input_i64_other)); + + + /* f32 */ + const float input_f32_allowed = + registry_tests_constrained_allowed_values_f32.constraints.float32.allowed_values[0]; + const float input_f32_other = + registry_tests_constrained_allowed_values_f32.constraints.float32.allowed_values[0] + 1.0; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_f32, + &input_f32_allowed, sizeof(input_f32_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_f32, + &input_f32_other, sizeof(input_f32_other)); + + + /* f64 */ + const double input_f64_allowed = + registry_tests_constrained_allowed_values_f64.constraints.float64.allowed_values[0]; + const double input_f64_other = + registry_tests_constrained_allowed_values_f64.constraints.float64.allowed_values[0] + 1.0; + + res_allowed = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_f64, + &input_f64_allowed, sizeof(input_f64_allowed)); + + res_other = registry_set(&test_constrained_allowed_values_instance_1, + ®istry_tests_constrained_allowed_values_f64, + &input_f64_other, sizeof(input_f64_other)); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); + + TEST_ASSERT_EQUAL_INT(0, res_allowed); + TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); +} + +static void tests_registry_constraints_forbidden_values(void) +{ + int res_forbidden; + int res_other; + + /* opaque */ + const registry_tests_constrained_forbidden_values_instance_opaque_t *input_opaque_forbidden = + registry_tests_constrained_forbidden_values_opaque.constraints.opaque.forbidden_values[0]; + const registry_tests_constrained_forbidden_values_instance_opaque_t input_opaque_other = { + .value = 19, + }; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_opaque, + input_opaque_forbidden, sizeof(*input_opaque_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_opaque, + &input_opaque_other, sizeof(input_opaque_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* string */ + const char *input_string_forbidden = + registry_tests_constrained_forbidden_values_string.constraints.string.forbidden_values[0]; + const char *input_string_other = "test test"; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_string, + input_string_forbidden, sizeof(input_string_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_string, + input_string_other, sizeof(input_string_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* bool */ + /* bool does not have forbidden values constraints */ + + /* u8 */ + const uint8_t input_u8_forbidden = + registry_tests_constrained_forbidden_values_u8.constraints.uint8.forbidden_values[0]; + const uint8_t input_u8_other = + registry_tests_constrained_forbidden_values_u8.constraints.uint8.forbidden_values[0] + 1; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_u8, + &input_u8_forbidden, sizeof(input_u8_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_u8, + &input_u8_other, sizeof(input_u8_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* u16 */ + const uint16_t input_u16_forbidden = + registry_tests_constrained_forbidden_values_u16.constraints.uint16.forbidden_values[0]; + const uint16_t input_u16_other = + registry_tests_constrained_forbidden_values_u16.constraints.uint16.forbidden_values[0] + 1; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_u16, + &input_u16_forbidden, sizeof(input_u16_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_u16, + &input_u16_other, sizeof(input_u16_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* u32 */ + const uint32_t input_u32_forbidden = + registry_tests_constrained_forbidden_values_u32.constraints.uint32.forbidden_values[0]; + const uint32_t input_u32_other = + registry_tests_constrained_forbidden_values_u32.constraints.uint32.forbidden_values[0] + 1; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_u32, + &input_u32_forbidden, sizeof(input_u32_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_u32, + &input_u32_other, sizeof(input_u16_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* u64 */ + const uint64_t input_u64_forbidden = + registry_tests_constrained_forbidden_values_u64.constraints.uint64.forbidden_values[0]; + const uint64_t input_u64_other = + registry_tests_constrained_forbidden_values_u64.constraints.uint64.forbidden_values[0] + 1; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_u64, + &input_u64_forbidden, sizeof(input_u64_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_u64, + &input_u64_other, sizeof(input_u16_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* i8 */ + const int8_t input_i8_forbidden = + registry_tests_constrained_forbidden_values_i8.constraints.int8.forbidden_values[0]; + const int8_t input_i8_other = + registry_tests_constrained_forbidden_values_i8.constraints.int8.forbidden_values[0] + 1; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_i8, + &input_i8_forbidden, sizeof(input_i8_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_i8, + &input_i8_other, sizeof(input_i8_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* i16 */ + const int16_t input_i16_forbidden = + registry_tests_constrained_forbidden_values_i16.constraints.int16.forbidden_values[0]; + const int16_t input_i16_other = + registry_tests_constrained_forbidden_values_i16.constraints.int16.forbidden_values[0] + 1; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_i16, + &input_i16_forbidden, sizeof(input_i16_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_i16, + &input_i16_other, sizeof(input_i16_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* i32 */ + const int32_t input_i32_forbidden = + registry_tests_constrained_forbidden_values_i32.constraints.int32.forbidden_values[0]; + const int32_t input_i32_other = + registry_tests_constrained_forbidden_values_i32.constraints.int32.forbidden_values[0] + 1; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_i32, + &input_i32_forbidden, sizeof(input_i32_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_i32, + &input_i32_other, sizeof(input_i32_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* i64 */ + const int64_t input_i64_forbidden = + registry_tests_constrained_forbidden_values_i64.constraints.int64.forbidden_values[0]; + const int64_t input_i64_other = + registry_tests_constrained_forbidden_values_i64.constraints.int64.forbidden_values[0] + 1; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_i64, + &input_i64_forbidden, sizeof(input_i64_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_i64, + &input_i64_other, sizeof(input_i64_other)); + + + /* f32 */ + const float input_f32_forbidden = + registry_tests_constrained_forbidden_values_f32.constraints.float32.forbidden_values[0]; + const float input_f32_other = + registry_tests_constrained_forbidden_values_f32.constraints.float32.forbidden_values[0] + + 1.0; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_f32, + &input_f32_forbidden, sizeof(input_f32_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_f32, + &input_f32_other, sizeof(input_f32_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); + + + /* f64 */ + const double input_f64_forbidden = + registry_tests_constrained_forbidden_values_f64.constraints.float64.forbidden_values[0]; + const double input_f64_other = + registry_tests_constrained_forbidden_values_f64.constraints.float64.forbidden_values[0] + + 1.0; + + res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_f64, + &input_f64_forbidden, sizeof(input_f64_forbidden)); + + res_other = registry_set(&test_constrained_forbidden_values_instance_1, + ®istry_tests_constrained_forbidden_values_f64, + &input_f64_other, sizeof(input_f64_other)); + + TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); + TEST_ASSERT_EQUAL_INT(0, res_other); +} + +Test *tests_registry_get_set_tests(void) +{ + + (void)tests_registry_min_values; + (void)tests_registry_zero_values; + (void)tests_registry_max_values; + (void)tests_registry_constraints_min_max; + (void)tests_registry_constraints_allowed_values; + (void)tests_registry_constraints_forbidden_values; + + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(tests_registry_min_values), + new_TestFixture(tests_registry_zero_values), + new_TestFixture(tests_registry_max_values), + new_TestFixture(tests_registry_constraints_min_max), + new_TestFixture(tests_registry_constraints_allowed_values), + new_TestFixture(tests_registry_constraints_forbidden_values), + }; + + EMB_UNIT_TESTCALLER(registry_tests, test_registry_setup, test_registry_teardown, fixtures); + + return (Test *)®istry_tests; +} + +#endif + +/** @} */ diff --git a/tests/unittests/tests-registry/tests-registry.c b/tests/unittests/tests-registry/tests-registry.c new file mode 100644 index 000000000000..b763a3a4aa65 --- /dev/null +++ b/tests/unittests/tests-registry/tests-registry.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @brief Unittest entry point for the Registry test group + * + * @author Lasse Rosenow + */ + +#include "embUnit/embUnit.h" + +#include "tests-registry.h" + +Test *tests_registry_get_set_tests(void); +Test *tests_registry_commit_tests(void); +Test *tests_registry_export_tests(void); + +void tests_registry(void) +{ + TESTS_RUN(tests_registry_get_set_tests()); + TESTS_RUN(tests_registry_commit_tests()); + TESTS_RUN(tests_registry_export_tests()); +} +/** @} */ diff --git a/tests/unittests/tests-registry/tests-registry.h b/tests/unittests/tests-registry/tests-registry.h new file mode 100644 index 000000000000..1b22419139a7 --- /dev/null +++ b/tests/unittests/tests-registry/tests-registry.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ +#ifndef TESTS_REGISTRY_H +#define TESTS_REGISTRY_H + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The entry point of this test suite. + */ +void tests_registry(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_REGISTRY_H */ +/** @} */ From 99aa25f486e8728b65915acaf8afdec8fc8f983f Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:20:12 +0200 Subject: [PATCH 012/117] tests/unittests: add registry_storage tests --- .../unittests/tests-registry_storage/Makefile | 1 + .../tests-registry_storage/Makefile.include | 2 + .../tests-registry_storage.c | 185 ++++++++++++++++++ .../tests-registry_storage.h | 38 ++++ 4 files changed, 226 insertions(+) create mode 100644 tests/unittests/tests-registry_storage/Makefile create mode 100644 tests/unittests/tests-registry_storage/Makefile.include create mode 100644 tests/unittests/tests-registry_storage/tests-registry_storage.c create mode 100644 tests/unittests/tests-registry_storage/tests-registry_storage.h diff --git a/tests/unittests/tests-registry_storage/Makefile b/tests/unittests/tests-registry_storage/Makefile new file mode 100644 index 000000000000..9c9ae9884ad6 --- /dev/null +++ b/tests/unittests/tests-registry_storage/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/tests/unittests/tests-registry_storage/Makefile.include b/tests/unittests/tests-registry_storage/Makefile.include new file mode 100644 index 000000000000..bfd89dd4f3bd --- /dev/null +++ b/tests/unittests/tests-registry_storage/Makefile.include @@ -0,0 +1,2 @@ +USEMODULE += registry_storage +USEMODULE += registry_namespace_tests_nested diff --git a/tests/unittests/tests-registry_storage/tests-registry_storage.c b/tests/unittests/tests-registry_storage/tests-registry_storage.c new file mode 100644 index 000000000000..020588d72a20 --- /dev/null +++ b/tests/unittests/tests-registry_storage/tests-registry_storage.c @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_storage`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#include +#include +#include +#include +#include +#include +#include "embUnit.h" +#include "fmt.h" +#include "assert.h" +#include "vfs.h" +#include "board.h" +#include "mtd.h" +#include "registry.h" +#include "registry/storage.h" + +#include "tests-registry_storage.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/nested.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) + +#define _TESTS_REGISTRY_LOAD_STORED_VALUE 60 + +static registry_tests_nested_instance_t test_nested_instance_data = { + .parameter = 9, + .group_parameter = 5, +}; + +static registry_instance_t test_nested_instance = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-nested-parameter-test", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_nested_instance_data, + .commit_cb = NULL, +}; + +static int load(const registry_storage_instance_t *storage, + const load_cb_t load_cb); +static int save(const registry_storage_instance_t *storage, + const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_value_t *value); + +static registry_storage_t storage_test = { + .load = load, + .save = save, +}; + +static uint8_t storage_test_instance_data = 7; + +static registry_storage_instance_t storage_test_instance = { + .storage = &storage_test, + .data = &storage_test_instance_data, +}; + +static int load(const registry_storage_instance_t *storage, + const load_cb_t load_cb) +{ + if (storage == &storage_test_instance) { + uint8_t buf = _TESTS_REGISTRY_LOAD_STORED_VALUE; + return load_cb(&test_nested_instance, ®istry_tests_nested_parameter, &buf, sizeof(buf)); + } + + return -EINVAL; +} + +static int save(const registry_storage_instance_t *storage, + const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_value_t *value) +{ + if (storage == &storage_test_instance && + instance == &test_nested_instance && + parameter == ®istry_tests_nested_group_parameter && + value->buf == &test_nested_instance_data.group_parameter && + value->buf_len == sizeof(uint8_t) && + value->type == REGISTRY_TYPE_UINT8) { + + return 0; + } + + return -EINVAL; +} + +REGISTRY_ADD_STORAGE_SOURCE(storage_test_instance); +REGISTRY_SET_STORAGE_DESTINATION(storage_test_instance); + +static void test_setup(void) +{ + /* init registry */ + registry_init(); + + /* add schema instances */ + registry_add_schema_instance(®istry_tests_nested, &test_nested_instance); +} + +static void tests_registry_load(void) +{ + /* check if the registry_load function gets the correct input values internally */ + TEST_ASSERT(registry_load() == 0); + + /* check if the load_cb sets the value to the registry */ + registry_value_t output; + + registry_get(&test_nested_instance, ®istry_tests_nested_parameter, &output); + TEST_ASSERT_EQUAL_INT(_TESTS_REGISTRY_LOAD_STORED_VALUE, *(uint8_t *)output.buf); +} + +static void tests_registry_save_parameter(void) +{ + TEST_ASSERT_EQUAL_INT(0, registry_save_parameter(&test_nested_instance, + ®istry_tests_nested_group_parameter)); +} + +static void tests_registry_save_group(void) +{ + TEST_ASSERT_EQUAL_INT(0, registry_save_group(&test_nested_instance, + ®istry_tests_nested_group)); +} + +static void tests_registry_save_instance(void) +{ + TEST_ASSERT_EQUAL_INT(0, registry_save_instance(&test_nested_instance)); +} + +static void tests_registry_save_schema(void) +{ + TEST_ASSERT_EQUAL_INT(0, registry_save_schema(®istry_tests_nested)); +} + +static void tests_registry_save_namespace(void) +{ + TEST_ASSERT_EQUAL_INT(0, registry_save_namespace(®istry_tests)); +} + +static void tests_registry_save_all(void) +{ + TEST_ASSERT_EQUAL_INT(0, registry_save()); +} + +Test *tests_registry_storage_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + /* load */ + new_TestFixture(tests_registry_load), + /* save */ + new_TestFixture(tests_registry_save_parameter), + new_TestFixture(tests_registry_save_group), + new_TestFixture(tests_registry_save_instance), + new_TestFixture(tests_registry_save_schema), + new_TestFixture(tests_registry_save_namespace), + new_TestFixture(tests_registry_save_all), + }; + + EMB_UNIT_TESTCALLER(registry_storage_tests, test_setup, NULL, fixtures); + + return (Test *)®istry_storage_tests; +} + +void tests_registry_storage(void) +{ + TESTS_RUN(tests_registry_storage_tests()); +} + +#endif + +/** @} */ diff --git a/tests/unittests/tests-registry_storage/tests-registry_storage.h b/tests/unittests/tests-registry_storage/tests-registry_storage.h new file mode 100644 index 000000000000..9c0ee335ab8c --- /dev/null +++ b/tests/unittests/tests-registry_storage/tests-registry_storage.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_storage`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef TESTS_REGISTRY_STORAGE_H +#define TESTS_REGISTRY_STORAGE_H + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The entry point of this test suite. + */ +void tests_registry_storage(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_REGISTRY_STORAGE_H */ +/** @} */ From 786f8231973d9ef1271632723119490a3aed0aca Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:20:50 +0200 Subject: [PATCH 013/117] tests/unittests: add registry_int_path tests --- .../tests-registry_int_path/Makefile | 1 + .../tests-registry_int_path/Makefile.include | 2 + .../tests-registry_int_path.c | 274 ++++++++++++++++++ .../tests-registry_int_path.h | 38 +++ 4 files changed, 315 insertions(+) create mode 100644 tests/unittests/tests-registry_int_path/Makefile create mode 100644 tests/unittests/tests-registry_int_path/Makefile.include create mode 100644 tests/unittests/tests-registry_int_path/tests-registry_int_path.c create mode 100644 tests/unittests/tests-registry_int_path/tests-registry_int_path.h diff --git a/tests/unittests/tests-registry_int_path/Makefile b/tests/unittests/tests-registry_int_path/Makefile new file mode 100644 index 000000000000..9c9ae9884ad6 --- /dev/null +++ b/tests/unittests/tests-registry_int_path/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/tests/unittests/tests-registry_int_path/Makefile.include b/tests/unittests/tests-registry_int_path/Makefile.include new file mode 100644 index 000000000000..fd79cc7645b0 --- /dev/null +++ b/tests/unittests/tests-registry_int_path/Makefile.include @@ -0,0 +1,2 @@ +USEMODULE += registry_int_path +USEMODULE += registry_namespace_tests_nested diff --git a/tests/unittests/tests-registry_int_path/tests-registry_int_path.c b/tests/unittests/tests-registry_int_path/tests-registry_int_path.c new file mode 100644 index 000000000000..923c90c91c14 --- /dev/null +++ b/tests/unittests/tests-registry_int_path/tests-registry_int_path.c @@ -0,0 +1,274 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_int_path`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#include "embUnit/embUnit.h" +#include "tests-registry_int_path.h" + +#include +#include +#include +#include +#include +#include +#include "embUnit.h" +#include "fmt.h" +#include "assert.h" +#include "vfs.h" +#include "board.h" +#include "mtd.h" +#include "registry.h" +#include "registry/int_path.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/nested.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) + +static registry_tests_nested_instance_t test_instance_data = { + .parameter = 9, + .group_parameter = 5, +}; + +static registry_instance_t test_instance = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-nested-parameter-test", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_instance_data, + .commit_cb = NULL, +}; + +static void test_setup(void) +{ + /* init registry */ + registry_init(); + + /* add schema instances */ + registry_add_schema_instance(®istry_tests_nested, &test_instance); +} + +/* to int_path */ +static void tests_registry_to_parameter_int_path(void) +{ + registry_parameter_int_path_t path = registry_to_parameter_int_path(&test_instance, + ®istry_tests_nested_parameter); + + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.schema_id); + TEST_ASSERT_EQUAL_INT(test_instance.id, path.instance_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested_parameter.id, path.parameter_id); +} + +static void tests_registry_to_group_int_path(void) +{ + registry_group_int_path_t path = registry_to_group_int_path(&test_instance, + ®istry_tests_nested_group); + + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.schema_id); + TEST_ASSERT_EQUAL_INT(test_instance.id, path.instance_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested_group.id, path.group_id); +} + +static void tests_registry_to_instance_int_path(void) +{ + registry_instance_int_path_t path = registry_to_instance_int_path(&test_instance); + + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.schema_id); + TEST_ASSERT_EQUAL_INT(test_instance.id, path.instance_id); +} + +static void tests_registry_to_schema_int_path(void) +{ + registry_schema_int_path_t path = registry_to_schema_int_path(®istry_tests_nested); + + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.schema_id); +} + +static void tests_registry_to_namespace_int_path(void) +{ + registry_namespace_int_path_t path = registry_to_namespace_int_path(®istry_tests); + + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); +} + +/* from int_path */ +static void tests_registry_from_group_or_parameter_int_path(void) +{ + registry_int_path_type_t path_type; + registry_namespace_t *namespace; + registry_schema_t *schema; + registry_instance_t *instance; + registry_group_t *group; + registry_parameter_t *parameter; + + + /* parameter */ + const registry_group_or_parameter_int_path_t parameter_path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + .group_or_parameter_id = registry_tests_nested_group_parameter.id, + }; + + registry_from_group_or_parameter_int_path(¶meter_path, &path_type, &namespace, &schema, + &instance, &group, ¶meter); + + TEST_ASSERT_EQUAL_INT(path_type, REGISTRY_INT_PATH_TYPE_PARAMETER); + TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)parameter); + + + /* group */ + const registry_group_or_parameter_int_path_t group_path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + .group_or_parameter_id = registry_tests_nested_group.id, + }; + + registry_from_group_or_parameter_int_path(&group_path, &path_type, &namespace, &schema, + &instance, &group, ¶meter); + + TEST_ASSERT_EQUAL_INT(path_type, REGISTRY_INT_PATH_TYPE_GROUP); + TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)group); +} + +static void tests_registry_from_parameter_int_path(void) +{ + const registry_parameter_int_path_t path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + .parameter_id = registry_tests_nested_group_parameter.id, + }; + registry_namespace_t *namespace; + registry_schema_t *schema; + registry_instance_t *instance; + registry_parameter_t *parameter; + + registry_from_parameter_int_path(&path, &namespace, &schema, &instance, ¶meter); + + TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)parameter); +} + +static void tests_registry_from_group_int_path(void) +{ + const registry_group_int_path_t path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + .group_id = registry_tests_nested_group.id, + }; + registry_namespace_t *namespace; + registry_schema_t *schema; + registry_instance_t *instance; + registry_group_t *group; + + registry_from_group_int_path(&path, &namespace, &schema, &instance, &group); + + TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)group); +} + +static void tests_registry_from_instance_int_path(void) +{ + const registry_instance_int_path_t path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + }; + registry_namespace_t *namespace; + registry_schema_t *schema; + registry_instance_t *instance; + + registry_from_instance_int_path(&path, &namespace, &schema, &instance); + + TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); +} + +static void tests_registry_from_schema_int_path(void) +{ + const registry_schema_int_path_t path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + }; + registry_namespace_t *namespace; + registry_schema_t *schema; + + registry_from_schema_int_path(&path, &namespace, &schema); + + TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); +} + +static void tests_registry_from_namespace_int_path(void) +{ + const registry_namespace_int_path_t path = { + .namespace_id = registry_tests.id, + }; + registry_namespace_t *namespace; + + registry_from_namespace_int_path(&path, &namespace); + + TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); +} + +Test *tests_registry_int_path_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + /* to int_path */ + new_TestFixture(tests_registry_to_parameter_int_path), + new_TestFixture(tests_registry_to_group_int_path), + new_TestFixture(tests_registry_to_instance_int_path), + new_TestFixture(tests_registry_to_schema_int_path), + new_TestFixture(tests_registry_to_namespace_int_path), + /* from int_path */ + new_TestFixture(tests_registry_from_group_or_parameter_int_path), + new_TestFixture(tests_registry_from_parameter_int_path), + new_TestFixture(tests_registry_from_group_int_path), + new_TestFixture(tests_registry_from_instance_int_path), + new_TestFixture(tests_registry_from_schema_int_path), + new_TestFixture(tests_registry_from_namespace_int_path), + }; + + EMB_UNIT_TESTCALLER(registry_int_path_tests, test_setup, NULL, fixtures); + + return (Test *)®istry_int_path_tests; +} + +void tests_registry_int_path(void) +{ + TESTS_RUN(tests_registry_int_path_tests()); +} + +#endif + +/** @} */ diff --git a/tests/unittests/tests-registry_int_path/tests-registry_int_path.h b/tests/unittests/tests-registry_int_path/tests-registry_int_path.h new file mode 100644 index 000000000000..bfaf4157c808 --- /dev/null +++ b/tests/unittests/tests-registry_int_path/tests-registry_int_path.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_int_path`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef TESTS_REGISTRY_INT_PATH_H +#define TESTS_REGISTRY_INT_PATH_H + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The entry point of this test suite. + */ +void tests_registry_int_path(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_REGISTRY_INT_PATH_H */ +/** @} */ From 63562cdc499af441262890c22aaabac917d4fdd3 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:21:01 +0200 Subject: [PATCH 014/117] tests/unittests: add registry_string_path tests --- .../tests-registry_string_path/Makefile | 1 + .../Makefile.include | 2 + .../tests-registry_string_path.c | 244 ++++++++++++++++++ .../tests-registry_string_path.h | 38 +++ 4 files changed, 285 insertions(+) create mode 100644 tests/unittests/tests-registry_string_path/Makefile create mode 100644 tests/unittests/tests-registry_string_path/Makefile.include create mode 100644 tests/unittests/tests-registry_string_path/tests-registry_string_path.c create mode 100644 tests/unittests/tests-registry_string_path/tests-registry_string_path.h diff --git a/tests/unittests/tests-registry_string_path/Makefile b/tests/unittests/tests-registry_string_path/Makefile new file mode 100644 index 000000000000..9c9ae9884ad6 --- /dev/null +++ b/tests/unittests/tests-registry_string_path/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/tests/unittests/tests-registry_string_path/Makefile.include b/tests/unittests/tests-registry_string_path/Makefile.include new file mode 100644 index 000000000000..d81d6741258c --- /dev/null +++ b/tests/unittests/tests-registry_string_path/Makefile.include @@ -0,0 +1,2 @@ +USEMODULE += registry_string_path +USEMODULE += registry_namespace_tests_nested diff --git a/tests/unittests/tests-registry_string_path/tests-registry_string_path.c b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c new file mode 100644 index 000000000000..9c456952240e --- /dev/null +++ b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_string_path`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#include "embUnit/embUnit.h" +#include "tests-registry_string_path.h" + +#include +#include +#include +#include +#include +#include +#include "embUnit.h" +#include "fmt.h" +#include "assert.h" +#include "vfs.h" +#include "board.h" +#include "mtd.h" +#include "registry.h" +#include "registry/string_path.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/nested.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) + +static registry_tests_nested_instance_t test_instance_data = { + .parameter = 9, + .group_parameter = 5, +}; + +static registry_instance_t test_instance = { + .name = "instance-1", + .data = &test_instance_data, + .commit_cb = NULL, +}; + +static void test_setup(void) +{ + /* init registry */ + registry_init(); + + /* add schema instances */ + registry_add_schema_instance(®istry_tests_nested, &test_instance); +} + +/* to string_path */ +static void tests_registry_to_parameter_string_path(void) +{ + int size = registry_to_parameter_string_path(&test_instance, + ®istry_tests_nested_group_parameter, NULL); + char path[size + 1]; + + registry_to_parameter_string_path(&test_instance, ®istry_tests_nested_group_parameter, path); + + TEST_ASSERT_EQUAL_STRING("/tests/nested/instance-1/group/parameter", path); +} + +static void tests_registry_to_group_string_path(void) +{ + int size = registry_to_group_string_path(&test_instance, ®istry_tests_nested_group, NULL); + char path[size + 1]; + + registry_to_group_string_path(&test_instance, ®istry_tests_nested_group, path); + + TEST_ASSERT_EQUAL_STRING("/tests/nested/instance-1/group", path); +} + +static void tests_registry_to_instance_string_path(void) +{ + int size = registry_to_instance_string_path(&test_instance, NULL); + char path[size + 1]; + + registry_to_instance_string_path(&test_instance, path); + + TEST_ASSERT_EQUAL_STRING("/tests/nested/instance-1", path); +} + +static void tests_registry_to_schema_string_path(void) +{ + int size = registry_to_schema_string_path(®istry_tests_nested, NULL); + char path[size + 1]; + + registry_to_schema_string_path(®istry_tests_nested, path); + + TEST_ASSERT_EQUAL_STRING("/tests/nested", path); +} + +static void tests_registry_to_namespace_string_path(void) +{ + int size = registry_to_namespace_string_path(®istry_tests, NULL); + char path[size + 1]; + + registry_to_namespace_string_path(®istry_tests, path); + + TEST_ASSERT_EQUAL_STRING("/tests", path); +} + +/* from string_path */ +static void tests_registry_from_group_or_parameter_string_path(void) +{ + registry_string_path_type_t path_type; + registry_namespace_t *namespace; + registry_schema_t *schema; + registry_instance_t *instance; + registry_group_t *group; + registry_parameter_t *parameter; + + /* group */ + registry_from_group_or_parameter_string_path("/tests/nested/instance-1/group", + &path_type, &namespace, &schema, &instance, &group, + ¶meter); + + TEST_ASSERT_EQUAL_INT(REGISTRY_STRING_PATH_TYPE_GROUP, path_type); + TEST_ASSERT_EQUAL_STRING("tests", namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); + TEST_ASSERT_EQUAL_STRING("group", group->name); + + /* parameter */ + registry_from_group_or_parameter_string_path("/tests/nested/instance-1/group/parameter", + &path_type, &namespace, &schema, &instance, &group, + ¶meter); + + TEST_ASSERT_EQUAL_INT(REGISTRY_STRING_PATH_TYPE_PARAMETER, path_type); + TEST_ASSERT_EQUAL_STRING("tests", namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); + TEST_ASSERT_EQUAL_STRING("parameter", parameter->name); +} + +static void tests_registry_from_parameter_string_path(void) +{ + registry_namespace_t *namespace; + registry_schema_t *schema; + registry_instance_t *instance; + registry_parameter_t *parameter; + + registry_from_parameter_string_path("/tests/nested/instance-1/group/parameter", &namespace, + &schema, &instance, ¶meter); + + TEST_ASSERT_EQUAL_STRING("tests", namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); + TEST_ASSERT_EQUAL_STRING("parameter", parameter->name); +} + +static void tests_registry_from_group_string_path(void) +{ + registry_namespace_t *namespace; + registry_schema_t *schema; + registry_instance_t *instance; + registry_group_t *group; + + registry_from_group_string_path("/tests/nested/instance-1/group", &namespace, &schema, + &instance, &group); + + TEST_ASSERT_EQUAL_STRING("tests", namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); + TEST_ASSERT_EQUAL_STRING("group", group->name); +} + +static void tests_registry_from_instance_string_path(void) +{ + registry_namespace_t *namespace; + registry_schema_t *schema; + registry_instance_t *instance; + + registry_from_instance_string_path("/tests/nested/instance-1", &namespace, &schema, &instance); + + TEST_ASSERT_EQUAL_STRING("tests", namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); +} + +static void tests_registry_from_schema_string_path(void) +{ + registry_namespace_t *namespace; + registry_schema_t *schema; + + registry_from_schema_string_path("/tests/nested", &namespace, &schema); + + TEST_ASSERT_EQUAL_STRING("tests", namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", schema->name); +} + +static void tests_registry_from_namespace_string_path(void) +{ + registry_namespace_t *namespace; + + registry_from_namespace_string_path("/tests", &namespace); + + TEST_ASSERT_EQUAL_STRING("tests", namespace->name); +} + +Test *tests_registry_string_path_tests(void) +{ + (void)tests_registry_from_group_or_parameter_string_path; + (void)tests_registry_from_parameter_string_path; + (void)tests_registry_from_group_string_path; + EMB_UNIT_TESTFIXTURES(fixtures) { + /* to string_path */ + new_TestFixture(tests_registry_to_parameter_string_path), + new_TestFixture(tests_registry_to_group_string_path), + new_TestFixture(tests_registry_to_instance_string_path), + new_TestFixture(tests_registry_to_schema_string_path), + new_TestFixture(tests_registry_to_namespace_string_path), + /* from string_path */ + new_TestFixture(tests_registry_from_group_or_parameter_string_path), + new_TestFixture(tests_registry_from_parameter_string_path), + new_TestFixture(tests_registry_from_group_string_path), + new_TestFixture(tests_registry_from_instance_string_path), + new_TestFixture(tests_registry_from_schema_string_path), + new_TestFixture(tests_registry_from_namespace_string_path), + }; + + EMB_UNIT_TESTCALLER(registry_string_path_tests, test_setup, NULL, fixtures); + + return (Test *)®istry_string_path_tests; +} + +void tests_registry_string_path(void) +{ + TESTS_RUN(tests_registry_string_path_tests()); +} + +#endif + +/** @} */ diff --git a/tests/unittests/tests-registry_string_path/tests-registry_string_path.h b/tests/unittests/tests-registry_string_path/tests-registry_string_path.h new file mode 100644 index 000000000000..a419d2e33a29 --- /dev/null +++ b/tests/unittests/tests-registry_string_path/tests-registry_string_path.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_string_path`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef TESTS_REGISTRY_STRING_PATH_H +#define TESTS_REGISTRY_STRING_PATH_H + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The entry point of this test suite. + */ +void tests_registry_string_path(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_REGISTRY_STRING_PATH_H */ +/** @} */ From 47dd545f528b1540c6ca1391715ac155c7715ce5 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:21:15 +0200 Subject: [PATCH 015/117] tests/unittests: add registry_storage_heap tests --- .../tests-registry_storage_heap/Makefile | 1 + .../Makefile.include | 3 + .../tests-registry_storage_heap.c | 114 ++++++++++++++++++ .../tests-registry_storage_heap.h | 38 ++++++ 4 files changed, 156 insertions(+) create mode 100644 tests/unittests/tests-registry_storage_heap/Makefile create mode 100644 tests/unittests/tests-registry_storage_heap/Makefile.include create mode 100644 tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c create mode 100644 tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.h diff --git a/tests/unittests/tests-registry_storage_heap/Makefile b/tests/unittests/tests-registry_storage_heap/Makefile new file mode 100644 index 000000000000..9c9ae9884ad6 --- /dev/null +++ b/tests/unittests/tests-registry_storage_heap/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/tests/unittests/tests-registry_storage_heap/Makefile.include b/tests/unittests/tests-registry_storage_heap/Makefile.include new file mode 100644 index 000000000000..cafcaad6421b --- /dev/null +++ b/tests/unittests/tests-registry_storage_heap/Makefile.include @@ -0,0 +1,3 @@ +USEMODULE += registry_storage_heap +USEMODULE += registry_int_path +USEMODULE += registry_namespace_tests_nested diff --git a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c new file mode 100644 index 000000000000..e3dfa262c371 --- /dev/null +++ b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_storage_heap`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#include +#include +#include +#include +#include +#include +#include "embUnit.h" +#include "fmt.h" +#include "assert.h" +#include "registry.h" +#include "registry/storage.h" + +#include "tests-registry_storage_heap.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/nested.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) + +static registry_tests_nested_instance_t test_nested_instance_data = { + .parameter = 9, + .group_parameter = 5, +}; + +static registry_instance_t test_nested_instance = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-nested-parameter-test", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_nested_instance_data, + .commit_cb = NULL, +}; + +static registry_storage_instance_t heap_instance = { + .storage = ®istry_storage_heap, + .data = NULL, +}; + +REGISTRY_ADD_STORAGE_SOURCE(heap_instance); +REGISTRY_SET_STORAGE_DESTINATION(heap_instance); + +static void test_setup(void) +{ + /* init registry */ + registry_init(); + + /* add schema instances */ + registry_add_schema_instance(®istry_tests_nested, &test_nested_instance); +} + +static void tests_load_and_save(void) +{ + + /* set input to 8 */ + const uint8_t saved_input = 8; + + registry_set(&test_nested_instance, ®istry_tests_nested_group_parameter, &saved_input, + sizeof(saved_input)); + + /* save input to storage */ + registry_save(); + + /* override input with the value 20 */ + const uint8_t override_input = 20; + + registry_set(&test_nested_instance, ®istry_tests_nested_group_parameter, &override_input, + sizeof(override_input)); + + /* load old value from storage */ + registry_load(); + + /* check if the value is set back to 8 and not 20 anymore */ + registry_value_t output_value; + + registry_get(&test_nested_instance, ®istry_tests_nested_group_parameter, &output_value); + + TEST_ASSERT_EQUAL_INT(saved_input, *(uint8_t *)output_value.buf); +} + +Test *tests_registry_storage_heap_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(tests_load_and_save), + }; + + EMB_UNIT_TESTCALLER(registry_tests, test_setup, NULL, fixtures); + + return (Test *)®istry_tests; +} + +void tests_registry_storage_heap(void) +{ + TESTS_RUN(tests_registry_storage_heap_tests()); +} + +#endif + +/** @} */ diff --git a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.h b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.h new file mode 100644 index 000000000000..a3e5285384d3 --- /dev/null +++ b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_storage_heap`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef TESTS_REGISTRY_STORAGE_heap_H +#define TESTS_REGISTRY_STORAGE_heap_H + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The entry point of this test suite. + */ +void tests_registry_storage_heap(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_REGISTRY_STORAGE_heap_H */ +/** @} */ From 54e5f9af64433a695b3e198b4b73e96477fecc5a Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:21:30 +0200 Subject: [PATCH 016/117] tests/unittests: add registry_storage_vfs tests --- .../tests-registry_storage_vfs/Makefile | 1 + .../Makefile.include | 9 ++ .../tests-registry_storage_vfs.c | 135 ++++++++++++++++++ .../tests-registry_storage_vfs.h | 38 +++++ 4 files changed, 183 insertions(+) create mode 100644 tests/unittests/tests-registry_storage_vfs/Makefile create mode 100644 tests/unittests/tests-registry_storage_vfs/Makefile.include create mode 100644 tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c create mode 100644 tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.h diff --git a/tests/unittests/tests-registry_storage_vfs/Makefile b/tests/unittests/tests-registry_storage_vfs/Makefile new file mode 100644 index 000000000000..9c9ae9884ad6 --- /dev/null +++ b/tests/unittests/tests-registry_storage_vfs/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base \ No newline at end of file diff --git a/tests/unittests/tests-registry_storage_vfs/Makefile.include b/tests/unittests/tests-registry_storage_vfs/Makefile.include new file mode 100644 index 000000000000..247d9a98c5ff --- /dev/null +++ b/tests/unittests/tests-registry_storage_vfs/Makefile.include @@ -0,0 +1,9 @@ +CFLAGS += -DCONFIG_REGISTRY_ENABLE_META_NAME=1 + +USEMODULE += littlefs2 +USEMODULE += mtd +USEMODULE += vfs + +USEMODULE += registry_storage_vfs +USEMODULE += registry_int_path +USEMODULE += registry_namespace_tests_nested diff --git a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c new file mode 100644 index 000000000000..9e346f5c71ac --- /dev/null +++ b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_storage_vfs`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#include +#include +#include +#include +#include +#include +#include "embUnit.h" +#include "fmt.h" +#include "assert.h" +#include "vfs.h" +#include "board.h" +#include "mtd.h" +#include "fs/littlefs2_fs.h" +#include "registry.h" +#include "registry/storage.h" + +#include "tests-registry_storage_vfs.h" +#include "registry/namespace/tests.h" +#include "registry/namespace/tests/nested.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) + +static registry_tests_nested_instance_t test_nested_instance_data = { + .parameter = 9, + .group_parameter = 5, +}; + +static registry_instance_t test_nested_instance = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) + .name = "test-nested-parameter-test", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ + .data = &test_nested_instance_data, + .commit_cb = NULL, +}; + + +#define FS_DRIVER littlefs2_file_system +static littlefs2_desc_t fs_desc = { + .lock = MUTEX_INIT, +}; + +static vfs_mount_t _vfs_mount = { + .fs = &FS_DRIVER, + .mount_point = "/sda", + .private_data = &fs_desc, +}; + +static registry_storage_instance_t vfs_instance = { + .storage = ®istry_storage_vfs, + .data = &_vfs_mount, +}; + +REGISTRY_ADD_STORAGE_SOURCE(vfs_instance); +REGISTRY_SET_STORAGE_DESTINATION(vfs_instance); + +static void test_setup(void) +{ + /* init registry */ + registry_init(); + + /* add schema instances */ + registry_add_schema_instance(®istry_tests_nested, &test_nested_instance); + + /* init storage */ + #ifdef MTD_0 + fs_desc.dev = MTD_0; + #endif +} + +static void tests_load_and_save(void) +{ + + /* set input to 8 */ + const uint8_t saved_input = 8; + + registry_set(&test_nested_instance, ®istry_tests_nested_group_parameter, &saved_input, + sizeof(saved_input)); + + /* save input to storage */ + registry_save(); + + /* override input with the value 20 */ + const uint8_t override_input = 20; + + registry_set(&test_nested_instance, ®istry_tests_nested_group_parameter, &override_input, + sizeof(override_input)); + + /* load old value from storage */ + registry_load(); + + /* check if the value is set back to 8 and not 20 anymore */ + registry_value_t output_value; + + registry_get(&test_nested_instance, ®istry_tests_nested_group_parameter, &output_value); + + TEST_ASSERT_EQUAL_INT(saved_input, *(uint8_t *)output_value.buf); +} + +Test *tests_registry_storage_vfs_tests(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(tests_load_and_save), + }; + + EMB_UNIT_TESTCALLER(registry_tests, test_setup, NULL, fixtures); + + return (Test *)®istry_tests; +} + +void tests_registry_storage_vfs(void) +{ + TESTS_RUN(tests_registry_storage_vfs_tests()); +} + +#endif + +/** @} */ diff --git a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.h b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.h new file mode 100644 index 000000000000..0867df39c6c4 --- /dev/null +++ b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup unittests + * @brief Unittests for the ``registry_storage_vfs`` module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef TESTS_REGISTRY_STORAGE_VFS_H +#define TESTS_REGISTRY_STORAGE_VFS_H + +#include "embUnit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The entry point of this test suite. + */ +void tests_registry_storage_vfs(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_REGISTRY_STORAGE_VFS_H */ +/** @} */ From 502e658ccdfb77def2c6a58c1bec3f5094abfc09 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 21 Aug 2023 20:25:39 +0200 Subject: [PATCH 017/117] sys/registry/namespace: add to pseudomodules --- makefiles/pseudomodules.inc.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 2d860d196f84..84c136871d15 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -398,6 +398,7 @@ PSEUDOMODULES += random_cmd ## @} PSEUDOMODULES += registry_% NO_PSEUDOMODULES += registry_namespace_sys +NO_PSEUDOMODULES += registry_namespace_tests NO_PSEUDOMODULES += registry_storage PSEUDOMODULES += riotboot_% @@ -489,6 +490,7 @@ PSEUDOMODULES += shell_cmd_openwsn PSEUDOMODULES += shell_cmd_pm PSEUDOMODULES += shell_cmd_ps PSEUDOMODULES += shell_cmd_random +PSEUDOMODULES += shell_cmd_registry PSEUDOMODULES += shell_cmd_rtc PSEUDOMODULES += shell_cmd_rtt PSEUDOMODULES += shell_cmd_saul_reg From d8582124b79e45741bf82b2c3d6ed25e34163f0b Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 30 Jan 2024 15:34:07 +0100 Subject: [PATCH 018/117] sys/registry: add board_led schema to sys namespace --- sys/include/registry/namespace/sys.h | 1 + .../registry/namespace/sys/board_led.h | 51 ++++++++++++ .../sys/definitions/0002_board_led.yaml | 9 ++ sys/registry/namespace/sys/namespace_sys.c | 4 + .../namespace/sys/namespace_sys_board_led.c | 83 +++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 sys/include/registry/namespace/sys/board_led.h create mode 100644 sys/registry/namespace/sys/definitions/0002_board_led.yaml create mode 100644 sys/registry/namespace/sys/namespace_sys_board_led.c diff --git a/sys/include/registry/namespace/sys.h b/sys/include/registry/namespace/sys.h index e88b68548d2a..2bdd4238102a 100644 --- a/sys/include/registry/namespace/sys.h +++ b/sys/include/registry/namespace/sys.h @@ -30,6 +30,7 @@ extern registry_namespace_t registry_sys; typedef enum { REGISTRY_SYS_RGB_LED, + REGISTRY_SYS_BOARD_LED, } registry_sys_indices_t; #ifdef __cplusplus diff --git a/sys/include/registry/namespace/sys/board_led.h b/sys/include/registry/namespace/sys/board_led.h new file mode 100644 index 000000000000..ff24fa5c6d4a --- /dev/null +++ b/sys/include/registry/namespace/sys/board_led.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_sys_board_led RIOT Registry Schema: BOARD_LED + * @ingroup sys + * @brief RIOT Registry BOARD_LED Schema representing the basic structure of a BOARD LED + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_SYS_BOARD_LED_H +#define REGISTRY_NAMESPACE_SYS_BOARD_LED_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/* BOARD-LED */ +#if IS_USED(MODULE_REGISTRY_NAMESPACE_SYS_BOARD_LED) || IS_ACTIVE(DOXYGEN) + +extern const registry_parameter_t registry_sys_board_led_enabled; +extern registry_schema_t registry_sys_board_led; + +typedef struct { + clist_node_t node; + bool enabled; +} registry_sys_board_led_instance_t; + +typedef const enum { + REGISTRY_SYS_BOARD_LED_ENABLED, +} registry_sys_board_led_indices_t; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_NAMESPACE_SYS_BOARD_LED_H */ +/** @} */ diff --git a/sys/registry/namespace/sys/definitions/0002_board_led.yaml b/sys/registry/namespace/sys/definitions/0002_board_led.yaml new file mode 100644 index 000000000000..b423e4c928c9 --- /dev/null +++ b/sys/registry/namespace/sys/definitions/0002_board_led.yaml @@ -0,0 +1,9 @@ +# yaml-language-server: $schema=../../../../../dist/tools/registry_gen/schema.json +id: 2 +name: board_led +description: Representation of a board LED. +items: + - id: 0 + name: enabled + description: State of the board LED. + type: bool diff --git a/sys/registry/namespace/sys/namespace_sys.c b/sys/registry/namespace/sys/namespace_sys.c index d390d5046de4..302775e6a982 100644 --- a/sys/registry/namespace/sys/namespace_sys.c +++ b/sys/registry/namespace/sys/namespace_sys.c @@ -28,11 +28,15 @@ #include "registry/namespace/sys.h" #include "registry/namespace/sys/rgb_led.h" +#include "registry/namespace/sys/board_led.h" static const registry_schema_t *_schemas[] = { #if IS_USED(MODULE_REGISTRY_NAMESPACE_SYS_RGB_LED) ®istry_sys_rgb_led, #endif +#if IS_USED(MODULE_REGISTRY_NAMESPACE_SYS_BOARD_LED) + ®istry_sys_board_led, +#endif }; registry_namespace_t registry_sys = { diff --git a/sys/registry/namespace/sys/namespace_sys_board_led.c b/sys/registry/namespace/sys/namespace_sys_board_led.c new file mode 100644 index 000000000000..070a3977fe02 --- /dev/null +++ b/sys/registry/namespace/sys/namespace_sys_board_led.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_sys_board_led RIOT Registry Schema: BOARD_LED + * @ingroup sys + * @brief RIOT Registry BOARD_LED Schema representing the basic structure of a BOARD LED + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" +#include "registry/namespace/sys.h" + +#include "registry/namespace/sys/board_led.h" + +#if IS_USED(MODULE_REGISTRY_NAMESPACE_SYS_BOARD_LED) || IS_ACTIVE(DOXYGEN) + +/* Mapping */ +static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, + void **val, size_t *val_len) +{ + registry_sys_board_led_instance_t *_instance = + (registry_sys_board_led_instance_t *)instance->data; + + switch (parameter_id) { + case REGISTRY_SYS_BOARD_LED_ENABLED: + *val = &_instance->enabled; + *val_len = sizeof(_instance->enabled); + break; + } +} + +/* Schema */ +const registry_parameter_t registry_sys_board_led_enabled = { + .id = REGISTRY_SYS_BOARD_LED_ENABLED, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "enabled", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "State of the board LED.", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_sys_board_led, + .type = REGISTRY_TYPE_BOOL, +}; + +registry_schema_t registry_sys_board_led = { + .id = REGISTRY_SYS_BOARD_LED, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "board_led", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "Representation of a board LED.", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .namespace = ®istry_sys, + .mapping = mapping, + .groups = NULL, + .groups_len = 0, + .parameters = (const registry_parameter_t *[]) { + ®istry_sys_board_led_enabled, + }, + .parameters_len = 1, +}; + +#endif From 52f0169966ba204f69763e516b48acf4aa13c534 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 30 Jan 2024 15:35:28 +0100 Subject: [PATCH 019/117] examples: rename registry example to registry_cli --- examples/{registry => registry_cli}/Makefile | 2 +- examples/{registry => registry_cli}/main.c | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename examples/{registry => registry_cli}/Makefile (95%) rename examples/{registry => registry_cli}/main.c (100%) diff --git a/examples/registry/Makefile b/examples/registry_cli/Makefile similarity index 95% rename from examples/registry/Makefile rename to examples/registry_cli/Makefile index d229a35246fd..cf28607b1a0d 100644 --- a/examples/registry/Makefile +++ b/examples/registry_cli/Makefile @@ -1,5 +1,5 @@ # name of the application -APPLICATION = registry_example +APPLICATION = registry_example_cli # If no BOARD is found in the environment, use this default: BOARD ?= native diff --git a/examples/registry/main.c b/examples/registry_cli/main.c similarity index 100% rename from examples/registry/main.c rename to examples/registry_cli/main.c From 35abb4a2d95adfd8e49ab844bf54fc01024dc1ce Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 30 Jan 2024 15:35:44 +0100 Subject: [PATCH 020/117] examples: add registry_core example --- examples/registry_core/Makefile | 21 +++++++ examples/registry_core/main.c | 105 ++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 examples/registry_core/Makefile create mode 100644 examples/registry_core/main.c diff --git a/examples/registry_core/Makefile b/examples/registry_core/Makefile new file mode 100644 index 000000000000..ff0b934a5f10 --- /dev/null +++ b/examples/registry_core/Makefile @@ -0,0 +1,21 @@ +# name of the application +APPLICATION = registry_example_core + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# required modules +USEMODULE += registry_namespace_sys_board_led + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +include $(RIOTBASE)/Makefile.include diff --git a/examples/registry_core/main.c b/examples/registry_core/main.c new file mode 100644 index 000000000000..823413caa68c --- /dev/null +++ b/examples/registry_core/main.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief RIOT Registry example application + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include + +#include "board.h" +#include "led.h" +#include "registry.h" +#include "registry/namespace/sys.h" +#include "registry/namespace/sys/board_led.h" + +int board_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context); + +/* This belongs into the BOARD or Driver for example */ +registry_sys_board_led_instance_t board_led_instance_0_data = { + .enabled = 0, +}; + +registry_instance_t board_led_instance = { + .data = &board_led_instance_0_data, + .commit_cb = &board_led_instance_0_commit_cb, +}; + +int board_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) +{ + (void)scope; + (void)context; + + if (group_or_parameter_id != NULL) { + if (*group_or_parameter_id == REGISTRY_SYS_BOARD_LED_ENABLED) { + /* The Driver owns the board_led data instance, so we can just get our value from there */ + bool led_state = board_led_instance_0_data.enabled; + + /* Turn the LED on or off depending on the led_state */ + if (led_state == true) { + /* This is the commit_cb function of instance 0, so we toggle LED 0 as well */ + LED_ON(0); + } else { + LED_OFF(0); + } + } + } + else { + /* The whole instance got committed in one go, so apply all parameters (BOARD_LED has only one anyways)*/ + + bool led_state = board_led_instance_0_data.enabled; + if (led_state == true) { + LED_ON(0); + } else { + LED_OFF(0); + } + } + + return 0; +} + +/* This belongs into our main application */ +int main(void) +{ + registry_init(); + + /* init schemas */ + registry_add_schema_instance(®istry_sys_board_led, &board_led_instance); + + bool board_led_enabled = false; + + while (true) { + /* Invert the BOARD LED, to make it turn on and off on each subsequent cycle */ + board_led_enabled = !board_led_enabled; + + /* Set new registry value */ + registry_set(&board_led_instance, ®istry_sys_board_led_enabled, &board_led_enabled, sizeof(board_led_enabled)); + + /* Apply the registry value to change the LED state (calls the commit_cb function implemented by the BOARD for example)*/ + registry_commit_parameter(&board_led_instance, ®istry_sys_board_led_enabled); + + /* Sleep for 1 second and then do it again*/ + sleep(1); + } + + return 0; +} From 52d208d92ba4e0a57f7a8570dedd429e1e7a66d5 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 30 Jan 2024 19:06:43 +0100 Subject: [PATCH 021/117] fixup! sys: add runtime configuration registry --- sys/registry/util.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sys/registry/util.c b/sys/registry/util.c index 10892d4d8d91..451e28f65d7e 100644 --- a/sys/registry/util.c +++ b/sys/registry/util.c @@ -51,15 +51,15 @@ void _debug_print_value(const registry_value_t *value) case REGISTRY_TYPE_STRING: DEBUG("string: %s", (char *)value->buf); break; case REGISTRY_TYPE_BOOL: DEBUG("bool: %d", *(bool *)value->buf); break; - case REGISTRY_TYPE_UINT8: DEBUG("uint8: %d", *(uint8_t *)value->buf); break; - case REGISTRY_TYPE_UINT16: DEBUG("uint16: %d", *(uint16_t *)value->buf); break; - case REGISTRY_TYPE_UINT32: DEBUG("uint32: %d", *(uint32_t *)value->buf); break; - case REGISTRY_TYPE_UINT64: DEBUG("uint64: %lld", *(uint64_t *)value->buf); break; - - case REGISTRY_TYPE_INT8: DEBUG("int8: %d", *(int8_t *)value->buf); break; - case REGISTRY_TYPE_INT16: DEBUG("int16: %d", *(int16_t *)value->buf); break; - case REGISTRY_TYPE_INT32: DEBUG("int32: %d", *(int32_t *)value->buf); break; - case REGISTRY_TYPE_INT64: DEBUG("int64: %lld", *(int64_t *)value->buf); break; + case REGISTRY_TYPE_UINT8: DEBUG("uint8: %"PRIu8, *(uint8_t *)value->buf); break; + case REGISTRY_TYPE_UINT16: DEBUG("uint16: %"PRIu16, *(uint16_t *)value->buf); break; + case REGISTRY_TYPE_UINT32: DEBUG("uint32: %"PRIu32, *(uint32_t *)value->buf); break; + case REGISTRY_TYPE_UINT64: DEBUG("uint64: %"PRIu64, *(uint64_t *)value->buf); break; + + case REGISTRY_TYPE_INT8: DEBUG("int8: %"PRIu8, *(int8_t *)value->buf); break; + case REGISTRY_TYPE_INT16: DEBUG("int16: %"PRIu16, *(int16_t *)value->buf); break; + case REGISTRY_TYPE_INT32: DEBUG("int32: %"PRIu32, *(int32_t *)value->buf); break; + case REGISTRY_TYPE_INT64: DEBUG("int64: %"PRIu64, *(int64_t *)value->buf); break; case REGISTRY_TYPE_FLOAT32: DEBUG("f32: %f", *(float *)value->buf); break; case REGISTRY_TYPE_FLOAT64: DEBUG("f64: %f", *(double *)value->buf); break; From 40a98a7a160b74158a3e215cc89e220794382f71 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 30 Jan 2024 19:07:34 +0100 Subject: [PATCH 022/117] fixup! examples: add registry_core example --- examples/registry_core/Makefile | 3 ++- examples/registry_core/main.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/registry_core/Makefile b/examples/registry_core/Makefile index ff0b934a5f10..f8b0afe4e247 100644 --- a/examples/registry_core/Makefile +++ b/examples/registry_core/Makefile @@ -8,7 +8,8 @@ BOARD ?= native RIOTBASE ?= $(CURDIR)/../.. # required modules -USEMODULE += registry_namespace_sys_board_led +USEMODULE += registry_namespace_sys_board_led +USEMODULE += ztimer_msec # Comment this out to disable code in RIOT that does safety checking # which is not needed in a production environment but helps in the diff --git a/examples/registry_core/main.c b/examples/registry_core/main.c index 823413caa68c..4ceb1e114f21 100644 --- a/examples/registry_core/main.c +++ b/examples/registry_core/main.c @@ -22,11 +22,13 @@ #include #include -#include "board.h" +#include "periph_cpu.h" #include "led.h" +#include "board.h" #include "registry.h" #include "registry/namespace/sys.h" #include "registry/namespace/sys/board_led.h" +#include "ztimer.h" int board_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, @@ -98,7 +100,7 @@ int main(void) registry_commit_parameter(&board_led_instance, ®istry_sys_board_led_enabled); /* Sleep for 1 second and then do it again*/ - sleep(1); + ztimer_sleep(ZTIMER_MSEC, 1000); } return 0; From 3fa904b434d61d4192761a8cc53dde951e8e5e16 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 21 Feb 2024 15:53:40 +0100 Subject: [PATCH 023/117] fixup! sys: add runtime configuration registry Remove min-max and allowed and forbidden value constraints --- sys/include/registry.h | 112 ------------------- sys/registry/Kconfig | 12 --- sys/registry/registry.c | 232 ---------------------------------------- 3 files changed, 356 deletions(-) diff --git a/sys/include/registry.h b/sys/include/registry.h index d8576ca87919..1cb61bb5d9ba 100644 --- a/sys/include/registry.h +++ b/sys/include/registry.h @@ -113,92 +113,6 @@ struct _registry_instance_t { void *context; /**< Optional context used by the instance */ }; - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES(_type) \ - const _type *allowed_values; \ - size_t allowed_values_len; -#else - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES(_type) -#endif /* _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES */ - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES(_type) \ - const _type *forbidden_values; \ - size_t forbidden_values_len; -#else - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES(_type) -#endif /* _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES */ - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MIN_VALUE(_type) \ - const _type *min_value; -#else - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MIN_VALUE(_type) -#endif /* _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MIN_VALUE */ - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MAX_VALUE(_type) \ - const _type *max_value; -#else - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MAX_VALUE(_type) -#endif /* _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MAX_VALUE */ - -#define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_STRUCT(_name, _body) \ - typedef struct { \ - _body \ - } registry_parameter_constraints_ ## _name ## _t; - -#define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE(_name) \ - typedef void *registry_parameter_constraints_ ## _name ## _t; - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN(_name, _type) \ - _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_STRUCT( \ - _name, \ - _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES(_type) \ - _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES(_type) \ - ) -#else - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN(_name, _type) -#endif - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) -#define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(_name, _type) \ - _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_STRUCT( \ - _name, \ - _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_ALLOWED_VALUES(_type) \ - _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_FORBIDDEN_VALUES(_type) \ - _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MIN_VALUE(_type) \ - _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_PART_MAX_VALUE(_type) \ - ) -#else - #define _REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(_name, _type) -#endif - -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN(opaque, void *) -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN(string, char *) - -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE(bool) - -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(uint8, uint8_t) -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(uint16, uint16_t) -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(uint32, uint32_t) -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(uint64, uint64_t) - -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(int8, int8_t) -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(int16, int16_t) -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(int32, int32_t) -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(int64, int64_t) - -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(float32, float) -_REGISTRY_CREATE_PARAMETER_CONSTRAINT_TYPE_ALLOWED_FORBIDDEN_MIN_MAX(float64, double) - - struct _registry_group_t { const registry_group_id_t id; /**< Integer representing the ID of the configuration group. */ #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -224,32 +138,6 @@ struct _registry_parameter_t { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ const registry_schema_t * const schema; /**< Configuration Schema that the configuration parameter belongs to. */ const registry_type_t type; /**< Type of the configuration parameter. */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || \ - IS_ACTIVE(DOXYGEN) - const union { - const registry_parameter_constraints_opaque_t opaque; - const registry_parameter_constraints_string_t string; -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || \ - IS_ACTIVE(DOXYGEN) - const registry_parameter_constraints_bool_t boolean; - const registry_parameter_constraints_uint8_t uint8; - const registry_parameter_constraints_uint16_t uint16; - const registry_parameter_constraints_uint32_t uint32; - const registry_parameter_constraints_uint64_t uint64; - const registry_parameter_constraints_int8_t int8; - const registry_parameter_constraints_int16_t int16; - const registry_parameter_constraints_int32_t int32; - const registry_parameter_constraints_int64_t int64; - const registry_parameter_constraints_float32_t float32; - const registry_parameter_constraints_float64_t float64; -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK || CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - } constraints; /**< Constraints of the parameter value. */ -#endif \ - /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK || CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK || CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK || CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ }; /** diff --git a/sys/registry/Kconfig b/sys/registry/Kconfig index da218e9a2838..c0061e8ad5f7 100644 --- a/sys/registry/Kconfig +++ b/sys/registry/Kconfig @@ -18,18 +18,6 @@ config REGISTRY_ENABLE_META_NAME config REGISTRY_ENABLE_META_DESCRIPTION bool "Include description string in schemas" -config REGISTRY_ENABLE_ALLOWED_VALUES_CHECK - bool "Check if new values are allowed" - -config REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK - bool "Check if new values are forbidden" - -config REGISTRY_ENABLE_MIN_VALUE_CHECK - bool "Check if new value does not exceed minimum" - -config REGISTRY_ENABLE_MAX_VALUE_CHECK - bool "Check if new value does not exceed maximum" - config MODULE_REGISTRY_INT_PATH bool "Access configuration parameters via an integer path" diff --git a/sys/registry/registry.c b/sys/registry/registry.c index 523cc1f010ec..5318fb2f47da 100644 --- a/sys/registry/registry.c +++ b/sys/registry/registry.c @@ -78,159 +78,6 @@ int registry_get(const registry_instance_t *instance, const registry_parameter_t return 0; } -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) -#define _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_ARRAY_TYPE(_passed_checks, \ - _type_field_name, \ - _parameter, _buf, \ - _buf_len) \ - if (_parameter->constraints._type_field_name.allowed_values_len > 0) { \ - _passed_checks = false; \ - if (_parameter->constraints._type_field_name.allowed_values_len == 0) { \ - _passed_checks = true; \ - } \ - for (size_t i = 0; i < _parameter->constraints._type_field_name.allowed_values_len; \ - i++) { \ - if (memcmp(_parameter->constraints._type_field_name.allowed_values[i], _buf, \ - _buf_len) == 0) { \ - _passed_checks = true; \ - } \ - } \ - if (!_passed_checks) { \ - return -EINVAL; \ - } \ - } -#else - #define _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_ARRAY_TYPE(_passed_checks, \ - _type_field_name, \ - _parameter, _buf, \ - _buf_len) -#endif - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) -#define _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_ARRAY_TYPE(_passed_checks, \ - _type_field_name, \ - _parameter, _buf, \ - _buf_len) \ - if (_parameter->constraints._type_field_name.forbidden_values_len > 0) { \ - _passed_checks = true; \ - for (size_t i = 0; i < _parameter->constraints._type_field_name.forbidden_values_len; \ - i++) { \ - if (memcmp(_parameter->constraints._type_field_name.forbidden_values[i], _buf, \ - _buf_len) == 0) { \ - _passed_checks = false; \ - } \ - } \ - if (!_passed_checks) { \ - return -EINVAL; \ - } \ - } -#else - #define _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_ARRAY_TYPE(_passed_checks, \ - _type_field_name, \ - _parameter, _buf, \ - _buf_len) -#endif - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) -#define _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ - _type_field_name, _parameter, \ - _buf) \ - if (_parameter->constraints._type_field_name.allowed_values_len > 0) { \ - _passed_checks = false; \ - if (_parameter->constraints._type_field_name.allowed_values_len == 0) { \ - _passed_checks = true; \ - } \ - for (size_t i = 0; i < _parameter->constraints._type_field_name.allowed_values_len; \ - i++) { \ - if (_parameter->constraints._type_field_name.allowed_values[i] == *(_type *)_buf) { \ - _passed_checks = true; \ - } \ - } \ - if (!_passed_checks) { \ - return -EINVAL; \ - } \ - } -#else - #define _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ - _type_field_name, \ - _parameter, _buf) -#endif - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) -#define _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ - _type_field_name, _parameter, \ - _buf) \ - if (_parameter->constraints._type_field_name.forbidden_values_len > 0) { \ - _passed_checks = true; \ - for (size_t i = 0; i < _parameter->constraints._type_field_name.forbidden_values_len; \ - i++) { \ - if (_parameter->constraints._type_field_name.forbidden_values[i] == \ - *(_type *)_buf) { \ - _passed_checks = false; \ - } \ - } \ - if (!_passed_checks) { \ - return -EINVAL; \ - } \ - } -#else - #define _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ - _type_field_name, \ - _parameter, _buf) -#endif - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) -#define _REGISTRY_CHECK_SET_CONSTRAINTS_MIN_VALUE_OF_VALUE_TYPE(_type, _type_field_name, _parameter, \ - _buf) \ - if (_parameter->constraints._type_field_name.min_value != NULL) { \ - if (*(_type *)_buf < *_parameter->constraints._type_field_name.min_value) { \ - return -EINVAL; \ - } \ - } -#else - #define _REGISTRY_CHECK_SET_CONSTRAINTS_MIN_VALUE_OF_VALUE_TYPE(_type, _type_field_name, \ - _parameter, _buf) -#endif - -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) -#define _REGISTRY_CHECK_SET_CONSTRAINTS_MAX_VALUE_OF_VALUE_TYPE(_type, _type_field_name, _parameter, \ - _buf) \ - if (_parameter->constraints._type_field_name.max_value != NULL) { \ - if (*(_type *)_buf > *_parameter->constraints._type_field_name.max_value) { \ - return -EINVAL; \ - } \ - } -#else - #define _REGISTRY_CHECK_SET_CONSTRAINTS_MAX_VALUE_OF_VALUE_TYPE(_type, _type_field_name, \ - _parameter, _buf) -#endif - -#define _REGISTRY_CHECK_SET_CONSTRAINTS_OF_ARRAY_TYPE(_passed_checks, _type_field_name, _parameter, \ - _buf, _buf_len) \ - (void)_passed_checks; \ - _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_ARRAY_TYPE(_passed_checks, \ - _type_field_name, \ - _parameter, _buf, \ - _buf_len) \ - _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_ARRAY_TYPE(_passed_checks, \ - _type_field_name, \ - _parameter, _buf, \ - _buf_len) - -#define _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(_passed_checks, _type, _type_field_name, \ - _parameter, _buf) \ - (void)_passed_checks; \ - _REGISTRY_CHECK_SET_CONSTRAINTS_ALLOWED_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ - _type_field_name, \ - _parameter, _buf) \ - _REGISTRY_CHECK_SET_CONSTRAINTS_FORBIDDEN_VALUES_OF_VALUE_TYPE(_passed_checks, _type, \ - _type_field_name, \ - _parameter, _buf) \ - _REGISTRY_CHECK_SET_CONSTRAINTS_MIN_VALUE_OF_VALUE_TYPE(_type, _type_field_name, _parameter, \ - _buf) \ - _REGISTRY_CHECK_SET_CONSTRAINTS_MAX_VALUE_OF_VALUE_TYPE(_type, _type_field_name, _parameter, \ - _buf) - int registry_set(const registry_instance_t *instance, const registry_parameter_t *parameter, const void *buf, const size_t buf_len) { @@ -248,85 +95,6 @@ int registry_set(const registry_instance_t *instance, const registry_parameter_t return -EINVAL; } - if (IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK)) { - - bool passed_checks = true; - switch (parameter->type) { - case REGISTRY_TYPE_NONE: - break; - - case REGISTRY_TYPE_OPAQUE: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_ARRAY_TYPE(passed_checks, opaque, parameter, buf, - buf_len) - break; - - case REGISTRY_TYPE_STRING: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_ARRAY_TYPE(passed_checks, string, parameter, buf, - buf_len) - break; - - case REGISTRY_TYPE_BOOL: - /* the boolean data type has no constraints*/ - break; - - case REGISTRY_TYPE_UINT8: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, uint8_t, uint8, parameter, - buf) - break; - - case REGISTRY_TYPE_UINT16: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, uint16_t, uint16, - parameter, - buf) - break; - - case REGISTRY_TYPE_UINT32: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, uint32_t, uint32, - parameter, - buf) - break; - - case REGISTRY_TYPE_UINT64: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, uint64_t, uint64, - parameter, - buf) - break; - - case REGISTRY_TYPE_INT8: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, int8_t, int8, parameter, - buf) - break; - - case REGISTRY_TYPE_INT16: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, int16_t, int16, parameter, - buf) - break; - - case REGISTRY_TYPE_INT32: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, int32_t, int32, parameter, - buf) - break; - - case REGISTRY_TYPE_INT64: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, int64_t, int64, parameter, - buf) - break; - - case REGISTRY_TYPE_FLOAT32: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, float, float32, parameter, - buf) - break; - - case REGISTRY_TYPE_FLOAT64: - _REGISTRY_CHECK_SET_CONSTRAINTS_OF_VALUE_TYPE(passed_checks, double, float64, parameter, - buf) - break; - } - } - /* call handler to apply the new value to the correct parameter in the instance of the schema */ memcpy(intern_val, buf, buf_len); From efc7a945f45856948b6ab4d26c04b1535e665af4 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 21 Feb 2024 15:55:51 +0100 Subject: [PATCH 024/117] fixup! sys/registry: add sys namespace Remove min-max and allowed and forbidden value constraints --- .../namespace/sys/namespace_sys_rgb_led.c | 105 ------------------ 1 file changed, 105 deletions(-) diff --git a/sys/registry/namespace/sys/namespace_sys_rgb_led.c b/sys/registry/namespace/sys/namespace_sys_rgb_led.c index b040ff13247d..0666ec1c61b0 100644 --- a/sys/registry/namespace/sys/namespace_sys_rgb_led.c +++ b/sys/registry/namespace/sys/namespace_sys_rgb_led.c @@ -80,27 +80,6 @@ const registry_parameter_t registry_sys_rgb_led_red = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_sys_rgb_led, .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_sys_rgb_led_green = { @@ -113,27 +92,6 @@ const registry_parameter_t registry_sys_rgb_led_green = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_sys_rgb_led, .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_sys_rgb_led_blue = { @@ -146,27 +104,6 @@ const registry_parameter_t registry_sys_rgb_led_blue = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_sys_rgb_led, .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_sys_rgb_led_brightnesses_white = { @@ -179,27 +116,6 @@ const registry_parameter_t registry_sys_rgb_led_brightnesses_white = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_sys_rgb_led, .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_sys_rgb_led_brightnesses_yellow = { @@ -212,27 +128,6 @@ const registry_parameter_t registry_sys_rgb_led_brightnesses_yellow = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_sys_rgb_led, .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_group_t registry_sys_rgb_led_brightnesses = { From 111d73c1bf1b64f3ec03e407233d0614f3e14808 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 21 Feb 2024 15:56:50 +0100 Subject: [PATCH 025/117] fixup! sys/registry: add tests namespace Remove min-max and allowed and forbidden value constraints --- sys/include/registry/namespace/tests.h | 3 - .../tests/constrained_allowed_values.h | 98 --- .../tests/constrained_forbidden_values.h | 98 --- .../namespace/tests/constrained_min_max.h | 98 --- .../tests/definitions/0002_constrained.yaml | 132 ----- .../namespace/tests/namespace_tests.c | 12 - ...mespace_tests_constrained_allowed_values.c | 557 ------------------ ...space_tests_constrained_forbidden_values.c | 544 ----------------- .../namespace_tests_constrained_min_max.c | 544 ----------------- .../namespace/tests/namespace_tests_full.c | 246 -------- .../namespace/tests/namespace_tests_nested.c | 30 - 11 files changed, 2362 deletions(-) delete mode 100644 sys/include/registry/namespace/tests/constrained_allowed_values.h delete mode 100644 sys/include/registry/namespace/tests/constrained_forbidden_values.h delete mode 100644 sys/include/registry/namespace/tests/constrained_min_max.h delete mode 100644 sys/registry/namespace/tests/definitions/0002_constrained.yaml delete mode 100644 sys/registry/namespace/tests/namespace_tests_constrained_allowed_values.c delete mode 100644 sys/registry/namespace/tests/namespace_tests_constrained_forbidden_values.c delete mode 100644 sys/registry/namespace/tests/namespace_tests_constrained_min_max.c diff --git a/sys/include/registry/namespace/tests.h b/sys/include/registry/namespace/tests.h index 1cb60a453e1c..cbbe9463d418 100644 --- a/sys/include/registry/namespace/tests.h +++ b/sys/include/registry/namespace/tests.h @@ -29,9 +29,6 @@ extern "C" { extern registry_namespace_t registry_tests; typedef enum { - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_VALUES, REGISTRY_TESTS_FULL, REGISTRY_TESTS_NESTED, } registry_tests_indices_t; diff --git a/sys/include/registry/namespace/tests/constrained_allowed_values.h b/sys/include/registry/namespace/tests/constrained_allowed_values.h deleted file mode 100644 index ba9abd168fe1..000000000000 --- a/sys/include/registry/namespace/tests/constrained_allowed_values.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_constrained_allowed_values RIOT Registry Schema: Constrained Allowed Values - * @ingroup sys - * @brief RIOT Registry Constrained Allowed Values Schema representing all possible data types of the riot registry with allowed values constraints - * @{ - * - * @file - * - * @author Lasse Rosenow - */ - -#ifndef REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES_H -#define REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "registry.h" - -/* CONSTRAINED_ALLOWED_VALUES */ -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES) || IS_ACTIVE(DOXYGEN) - -extern const registry_parameter_t registry_tests_constrained_allowed_values_opaque; -extern const registry_parameter_t registry_tests_constrained_allowed_values_string; -extern const registry_parameter_t registry_tests_constrained_allowed_values_boolean; -extern const registry_parameter_t registry_tests_constrained_allowed_values_u8; -extern const registry_parameter_t registry_tests_constrained_allowed_values_u16; -extern const registry_parameter_t registry_tests_constrained_allowed_values_u32; -extern const registry_parameter_t registry_tests_constrained_allowed_values_u64; -extern const registry_parameter_t registry_tests_constrained_allowed_values_i8; -extern const registry_parameter_t registry_tests_constrained_allowed_values_i16; -extern const registry_parameter_t registry_tests_constrained_allowed_values_i32; -extern const registry_parameter_t registry_tests_constrained_allowed_values_i64; -extern const registry_parameter_t registry_tests_constrained_allowed_values_f32; -extern const registry_parameter_t registry_tests_constrained_allowed_values_f64; -extern registry_schema_t registry_tests_constrained_allowed_values; - -typedef struct { - uint8_t value; -} registry_tests_constrained_allowed_values_instance_opaque_t; - -typedef struct { - clist_node_t node; - - registry_tests_constrained_allowed_values_instance_opaque_t opaque; - char string[50]; - bool boolean; - - uint8_t u8; - uint16_t u16; - uint32_t u32; - uint64_t u64; - - int8_t i8; - int16_t i16; - int32_t i32; - int64_t i64; - - float f32; - double f64; -} registry_tests_constrained_allowed_values_instance_t; - -typedef enum { - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_OPAQUE, - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_STRING, - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_BOOLEAN, - - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U8, - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U16, - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U32, - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U64, - - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I8, - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I16, - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I32, - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I64, - - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F32, - REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F64, -} registry_tests_constrained_allowed_values_indices_t; - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* CONSTRAINED_ALLOWED_VALUES */ -/** @} */ diff --git a/sys/include/registry/namespace/tests/constrained_forbidden_values.h b/sys/include/registry/namespace/tests/constrained_forbidden_values.h deleted file mode 100644 index 3d6eb4c6a57d..000000000000 --- a/sys/include/registry/namespace/tests/constrained_forbidden_values.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_constrained_forbidden_values RIOT Registry Schema: Constrained Forbidden Values - * @ingroup sys - * @brief RIOT Registry Constrained Forbidden Values Schema representing all possible data types of the riot registry with forbidden values constraints - * @{ - * - * @file - * - * @author Lasse Rosenow - */ - -#ifndef REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES_H -#define REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "registry.h" - -/* CONSTRAINED_FORBIDDEN_VALUES */ -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES) || IS_ACTIVE(DOXYGEN) - -extern const registry_parameter_t registry_tests_constrained_forbidden_values_opaque; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_string; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_boolean; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_u8; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_u16; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_u32; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_u64; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_i8; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_i16; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_i32; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_i64; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_f32; -extern const registry_parameter_t registry_tests_constrained_forbidden_values_f64; -extern registry_schema_t registry_tests_constrained_forbidden_values; - -typedef struct { - uint8_t value; -} registry_tests_constrained_forbidden_values_instance_opaque_t; - -typedef struct { - clist_node_t node; - - registry_tests_constrained_forbidden_values_instance_opaque_t opaque; - char string[50]; - bool boolean; - - uint8_t u8; - uint16_t u16; - uint32_t u32; - uint64_t u64; - - int8_t i8; - int16_t i16; - int32_t i32; - int64_t i64; - - float f32; - double f64; -} registry_tests_constrained_forbidden_values_instance_t; - -typedef enum { - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_OPAQUE, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_STRING, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_BOOLEAN, - - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U8, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U16, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U32, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U64, - - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I8, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I16, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I32, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I64, - - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F32, - REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F64, -} registry_tests_constrained_forbidden_values_indices_t; - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* CONSTRAINED_FORBIDDEN_VALUES */ -/** @} */ diff --git a/sys/include/registry/namespace/tests/constrained_min_max.h b/sys/include/registry/namespace/tests/constrained_min_max.h deleted file mode 100644 index 0dd44d5fce5c..000000000000 --- a/sys/include/registry/namespace/tests/constrained_min_max.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_constrained_min_max RIOT Registry Schema: Constrained Min Max - * @ingroup sys - * @brief RIOT Registry Constrained Min Max Schema representing all possible data types of the riot registry with minimum and maximum value constraints - * @{ - * - * @file - * - * @author Lasse Rosenow - */ - -#ifndef REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX_H -#define REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "registry.h" - -/* CONSTRAINED_MIN_MAX */ -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX) || IS_ACTIVE(DOXYGEN) - -extern const registry_parameter_t registry_tests_constrained_min_max_opaque; -extern const registry_parameter_t registry_tests_constrained_min_max_string; -extern const registry_parameter_t registry_tests_constrained_min_max_boolean; -extern const registry_parameter_t registry_tests_constrained_min_max_u8; -extern const registry_parameter_t registry_tests_constrained_min_max_u16; -extern const registry_parameter_t registry_tests_constrained_min_max_u32; -extern const registry_parameter_t registry_tests_constrained_min_max_u64; -extern const registry_parameter_t registry_tests_constrained_min_max_i8; -extern const registry_parameter_t registry_tests_constrained_min_max_i16; -extern const registry_parameter_t registry_tests_constrained_min_max_i32; -extern const registry_parameter_t registry_tests_constrained_min_max_i64; -extern const registry_parameter_t registry_tests_constrained_min_max_f32; -extern const registry_parameter_t registry_tests_constrained_min_max_f64; -extern registry_schema_t registry_tests_constrained_min_max; - -typedef struct { - uint8_t value; -} registry_tests_constrained_min_max_instance_opaque_t; - -typedef struct { - clist_node_t node; - - registry_tests_constrained_min_max_instance_opaque_t opaque; - char string[50]; - bool boolean; - - uint8_t u8; - uint16_t u16; - uint32_t u32; - uint64_t u64; - - int8_t i8; - int16_t i16; - int32_t i32; - int64_t i64; - - float f32; - double f64; -} registry_tests_constrained_min_max_instance_t; - -typedef enum { - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_OPAQUE, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_STRING, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_BOOLEAN, - - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U8, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U16, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U32, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U64, - - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I8, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I16, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I32, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I64, - - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F32, - REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F64, -} registry_tests_constrained_min_max_indices_t; - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* CONSTRAINED_MIN_MAX */ -/** @} */ diff --git a/sys/registry/namespace/tests/definitions/0002_constrained.yaml b/sys/registry/namespace/tests/definitions/0002_constrained.yaml deleted file mode 100644 index 68087a3f55f8..000000000000 --- a/sys/registry/namespace/tests/definitions/0002_constrained.yaml +++ /dev/null @@ -1,132 +0,0 @@ -# yaml-language-server: $schema=../../../../../dist/tools/registry_gen/schema.json -id: 1 -name: rgb -description: Representation of an rgb color. -items: - - id: 0 - name: opaque - description: Opaque data type property. - type: opaque - size: 50 - constraints: - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 1 - name: string - description: String data type property. - type: string - size: 50 - constraints: - allowedValues: ["hello", "world"] - forbiddenValues: ["goodbye", "moon"] - - - id: 2 - name: boolean - description: Boolean data type property. - type: bool - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 3 - name: u8 - description: 8 bit unsigned integer data type property. - type: uint8 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 4 - name: u16 - description: 16 bit unsigned integer data type property. - type: uint16 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 5 - name: u32 - description: 32 bit unsigned integer data type property. - type: uint32 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 6 - name: u64 - description: 64 bit unsigned integer data type property. - type: uint64 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 7 - name: i8 - description: 8 bit integer data type property. - type: int8 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 8 - name: i16 - description: 16 bit integer data type property. - type: int16 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 9 - name: i32 - description: 32 bit integer data type property. - type: int32 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 10 - name: i64 - description: 64 bit integer data type property. - type: int64 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 11 - name: f32 - description: 64 bit integer data type property. - type: float32 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] - - - id: 12 - name: f64 - description: 64 bit integer data type property. - type: float64 - constraints: - minValue: 7 - maxValue: 18 - allowedValues: ["7", "9"] - forbiddenValues: ["11", "19"] diff --git a/sys/registry/namespace/tests/namespace_tests.c b/sys/registry/namespace/tests/namespace_tests.c index bdff804129a0..86ddba168922 100644 --- a/sys/registry/namespace/tests/namespace_tests.c +++ b/sys/registry/namespace/tests/namespace_tests.c @@ -26,24 +26,12 @@ #include "registry/namespace/tests.h" #include "registry/namespace/tests/full.h" -#include "registry/namespace/tests/constrained_min_max.h" -#include "registry/namespace/tests/constrained_allowed_values.h" -#include "registry/namespace/tests/constrained_forbidden_values.h" #include "registry/namespace/tests/nested.h" static const registry_schema_t *_schemas[] = { #if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) ®istry_tests_full, #endif -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX) - ®istry_tests_constrained_min_max, -#endif -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES) - ®istry_tests_constrained_allowed_values, -#endif -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES) - ®istry_tests_constrained_forbidden_values, -#endif #if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) ®istry_tests_nested, #endif diff --git a/sys/registry/namespace/tests/namespace_tests_constrained_allowed_values.c b/sys/registry/namespace/tests/namespace_tests_constrained_allowed_values.c deleted file mode 100644 index fa5f4f32efec..000000000000 --- a/sys/registry/namespace/tests/namespace_tests_constrained_allowed_values.c +++ /dev/null @@ -1,557 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_constrained_allowed_values RIOT Registry Schema: Constrained Allowed Values - * @ingroup sys - * @brief RIOT Registry Constrained Allowed Values Schema representing all possible data types of the riot registry with allowed values constraints - * @{ - * - * @file - * - * @author Lasse Rosenow - * - * @} - */ - -#include -#include -#include -#include - -#define ENABLE_DEBUG (0) -#include "debug.h" -#include "kernel_defines.h" -#include "registry.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/constrained_allowed_values.h" - -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_ALLOWED_VALUES) || IS_ACTIVE(DOXYGEN) - -/* Mapping */ -static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, - void **val, size_t *val_len) -{ - registry_tests_constrained_allowed_values_instance_t *_instance = - (registry_tests_constrained_allowed_values_instance_t *)instance->data; - - switch (parameter_id) { - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_OPAQUE: - *val = &_instance->opaque; - *val_len = sizeof(_instance->opaque); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_STRING: - *val = &_instance->string; - *val_len = sizeof(_instance->string); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_BOOLEAN: - *val = &_instance->boolean; - *val_len = sizeof(_instance->boolean); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U8: - *val = &_instance->u8; - *val_len = sizeof(_instance->u8); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U16: - *val = &_instance->u16; - *val_len = sizeof(_instance->u16); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U32: - *val = &_instance->u32; - *val_len = sizeof(_instance->u32); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U64: - *val = &_instance->u64; - *val_len = sizeof(_instance->u64); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I8: - *val = &_instance->i8; - *val_len = sizeof(_instance->i8); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I16: - *val = &_instance->i16; - *val_len = sizeof(_instance->i16); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I32: - *val = &_instance->i32; - *val_len = sizeof(_instance->i32); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I64: - *val = &_instance->i64; - *val_len = sizeof(_instance->i64); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F32: - *val = &_instance->f32; - *val_len = sizeof(_instance->f32); - break; - - case REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F64: - *val = &_instance->f64; - *val_len = sizeof(_instance->f64); - break; - } -} - -const registry_tests_constrained_allowed_values_instance_opaque_t - registry_tests_constrained_allowed_values_opaque_allowed_1 = { - .value = 7, -}; - -const registry_tests_constrained_allowed_values_instance_opaque_t - registry_tests_constrained_allowed_values_opaque_allowed_2 = { - .value = 9, -}; - -/* Schema */ -const registry_parameter_t registry_tests_constrained_allowed_values_opaque = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_OPAQUE, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "opaque", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_OPAQUE, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.opaque = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (const void *[]) { - ®istry_tests_constrained_allowed_values_opaque_allowed_1, - ®istry_tests_constrained_allowed_values_opaque_allowed_2, - }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_string = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_STRING, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "string", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_STRING, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.string = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (const char *[]){ "hello", "world" }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_boolean = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_BOOLEAN, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "boolean", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_BOOL, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.boolean = NULL, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_u8 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u8", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (uint8_t[]){ 7, 9 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint8_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint8_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_u16 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u16", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_UINT16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint16 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (uint16_t[]){ 7, 9 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint16_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint16_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_u32 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_UINT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (uint32_t[]){ 7, 9 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint32_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint32_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_u64 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_U64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_UINT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (uint64_t[]){ 7, 9 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint64_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint64_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_i8 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i8", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_INT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (int8_t[]){ 7, 9 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int8_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int8_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_i16 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i16", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_INT16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int16 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (int16_t[]){ 7, 9 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int16_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int16_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_i32 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_INT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (int32_t[]){ 7, 9 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int32_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int32_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_i64 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_I64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_INT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (int64_t[]){ 7, 9 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int64_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int64_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_f32 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "f32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_FLOAT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.float32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (float[]){ 7.0, 9.0 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (float[]){ 7.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (float[]){ 18.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_allowed_values_f64 = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES_F64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "f64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_allowed_values, - .type = REGISTRY_TYPE_FLOAT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.float64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = (double[]){ 7.0, 9.0 }, - .allowed_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (double[]){ 7.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (double[]){ 18.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -registry_schema_t registry_tests_constrained_allowed_values = { - .id = REGISTRY_TESTS_CONSTRAINED_ALLOWED_VALUES, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "constrained_allowed_values", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .namespace = ®istry_tests, - .mapping = mapping, - .groups = NULL, - .groups_len = 0, - .parameters = (const registry_parameter_t *[]) { - ®istry_tests_constrained_allowed_values_opaque, - ®istry_tests_constrained_allowed_values_string, - ®istry_tests_constrained_allowed_values_boolean, - ®istry_tests_constrained_allowed_values_u8, - ®istry_tests_constrained_allowed_values_u16, - ®istry_tests_constrained_allowed_values_u32, - ®istry_tests_constrained_allowed_values_u64, - ®istry_tests_constrained_allowed_values_i8, - ®istry_tests_constrained_allowed_values_i16, - ®istry_tests_constrained_allowed_values_i32, - ®istry_tests_constrained_allowed_values_i64, - ®istry_tests_constrained_allowed_values_f32, - ®istry_tests_constrained_allowed_values_f64, - }, - .parameters_len = 13, -}; - -#endif diff --git a/sys/registry/namespace/tests/namespace_tests_constrained_forbidden_values.c b/sys/registry/namespace/tests/namespace_tests_constrained_forbidden_values.c deleted file mode 100644 index 41f1d6830781..000000000000 --- a/sys/registry/namespace/tests/namespace_tests_constrained_forbidden_values.c +++ /dev/null @@ -1,544 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_constrained_forbidden_values RIOT Registry Schema: Constrained Forbidden Values - * @ingroup sys - * @brief RIOT Registry Constrained Forbidden Values Schema representing all possible data types of the riot registry with forbidden values constraints - * @{ - * - * @file - * - * @author Lasse Rosenow - * - * @} - */ - -#include -#include -#include -#include - -#define ENABLE_DEBUG (0) -#include "debug.h" -#include "kernel_defines.h" -#include "registry.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/constrained_forbidden_values.h" - -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_FORBIDDEN_VALUES) || IS_ACTIVE(DOXYGEN) - -/* Mapping */ -static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, - void **val, size_t *val_len) -{ - registry_tests_constrained_forbidden_values_instance_t *_instance = - (registry_tests_constrained_forbidden_values_instance_t *)instance->data; - - switch (parameter_id) { - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_OPAQUE: - *val = &_instance->opaque; - *val_len = sizeof(_instance->opaque); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_STRING: - *val = &_instance->string; - *val_len = sizeof(_instance->string); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_BOOLEAN: - *val = &_instance->boolean; - *val_len = sizeof(_instance->boolean); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U8: - *val = &_instance->u8; - *val_len = sizeof(_instance->u8); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U16: - *val = &_instance->u16; - *val_len = sizeof(_instance->u16); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U32: - *val = &_instance->u32; - *val_len = sizeof(_instance->u32); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U64: - *val = &_instance->u64; - *val_len = sizeof(_instance->u64); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I8: - *val = &_instance->i8; - *val_len = sizeof(_instance->i8); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I16: - *val = &_instance->i16; - *val_len = sizeof(_instance->i16); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I32: - *val = &_instance->i32; - *val_len = sizeof(_instance->i32); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I64: - *val = &_instance->i64; - *val_len = sizeof(_instance->i64); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F32: - *val = &_instance->f32; - *val_len = sizeof(_instance->f32); - break; - - case REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F64: - *val = &_instance->f64; - *val_len = sizeof(_instance->f64); - break; - } -} - -/* Schema */ -const registry_parameter_t registry_tests_constrained_forbidden_values_opaque = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_OPAQUE, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "opaque", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_OPAQUE, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.opaque = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (const void *[]){ "goodbye", "moon" }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_string = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_STRING, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "string", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_STRING, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.string = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (const char *[]){ "goodbye", "moon" }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_boolean = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_BOOLEAN, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "boolean", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_BOOL, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.boolean = NULL, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_u8 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u8", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (uint8_t[]){ 11, 19 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint8_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint8_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_u16 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u16", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_UINT16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint16 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (uint16_t[]){ 11, 19 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint16_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint16_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_u32 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_UINT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (uint32_t[]){ 11, 19 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint32_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint32_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_u64 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_U64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_UINT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (uint64_t[]){ 11, 19 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint64_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint64_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_i8 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i8", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_INT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (int8_t[]){ 11, 19 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int8_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int8_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_i16 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i16", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_INT16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int16 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (int16_t[]){ 11, 19 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int16_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int16_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_i32 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_INT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (int32_t[]){ 11, 19 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int32_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int32_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_i64 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_I64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_INT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (int64_t[]){ 11, 19 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int64_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int64_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_f32 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "f32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_FLOAT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.float32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (float[]){ 11.0, 19.0 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (float[]){ 7.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (float[]){ 18.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_forbidden_values_f64 = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES_F64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "f64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_forbidden_values, - .type = REGISTRY_TYPE_FLOAT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.float64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = (double[]){ 11.0, 19.0 }, - .forbidden_values_len = 2, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (double[]){ 7.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (double[]){ 18.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -registry_schema_t registry_tests_constrained_forbidden_values = { - .id = REGISTRY_TESTS_CONSTRAINED_FORBIDDEN_VALUES, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "constrained_forbidden_values", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .namespace = ®istry_tests, - .mapping = mapping, - .groups = NULL, - .groups_len = 0, - .parameters = (const registry_parameter_t *[]) { - ®istry_tests_constrained_forbidden_values_opaque, - ®istry_tests_constrained_forbidden_values_string, - ®istry_tests_constrained_forbidden_values_boolean, - ®istry_tests_constrained_forbidden_values_u8, - ®istry_tests_constrained_forbidden_values_u16, - ®istry_tests_constrained_forbidden_values_u32, - ®istry_tests_constrained_forbidden_values_u64, - ®istry_tests_constrained_forbidden_values_i8, - ®istry_tests_constrained_forbidden_values_i16, - ®istry_tests_constrained_forbidden_values_i32, - ®istry_tests_constrained_forbidden_values_i64, - ®istry_tests_constrained_forbidden_values_f32, - ®istry_tests_constrained_forbidden_values_f64, - }, - .parameters_len = 13, -}; - -#endif diff --git a/sys/registry/namespace/tests/namespace_tests_constrained_min_max.c b/sys/registry/namespace/tests/namespace_tests_constrained_min_max.c deleted file mode 100644 index aa8fffdfa9f3..000000000000 --- a/sys/registry/namespace/tests/namespace_tests_constrained_min_max.c +++ /dev/null @@ -1,544 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_constrained_min_max RIOT Registry Schema: Constrained Min Max - * @ingroup sys - * @brief RIOT Registry Constrained Min Max Schema representing all possible data types of the riot registry with minimum and maximum value constraints - * @{ - * - * @file - * - * @author Lasse Rosenow - * - * @} - */ - -#include -#include -#include -#include - -#define ENABLE_DEBUG (0) -#include "debug.h" -#include "kernel_defines.h" -#include "registry.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/constrained_min_max.h" - -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_CONSTRAINED_MIN_MAX) || IS_ACTIVE(DOXYGEN) - -/* Mapping */ -static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, - void **val, size_t *val_len) -{ - registry_tests_constrained_min_max_instance_t *_instance = - (registry_tests_constrained_min_max_instance_t *)instance->data; - - switch (parameter_id) { - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_OPAQUE: - *val = &_instance->opaque; - *val_len = sizeof(_instance->opaque); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_STRING: - *val = &_instance->string; - *val_len = sizeof(_instance->string); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_BOOLEAN: - *val = &_instance->boolean; - *val_len = sizeof(_instance->boolean); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U8: - *val = &_instance->u8; - *val_len = sizeof(_instance->u8); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U16: - *val = &_instance->u16; - *val_len = sizeof(_instance->u16); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U32: - *val = &_instance->u32; - *val_len = sizeof(_instance->u32); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U64: - *val = &_instance->u64; - *val_len = sizeof(_instance->u64); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I8: - *val = &_instance->i8; - *val_len = sizeof(_instance->i8); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I16: - *val = &_instance->i16; - *val_len = sizeof(_instance->i16); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I32: - *val = &_instance->i32; - *val_len = sizeof(_instance->i32); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I64: - *val = &_instance->i64; - *val_len = sizeof(_instance->i64); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F32: - *val = &_instance->f32; - *val_len = sizeof(_instance->f32); - break; - - case REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F64: - *val = &_instance->f64; - *val_len = sizeof(_instance->f64); - break; - } -} - -/* Schema */ -const registry_parameter_t registry_tests_constrained_min_max_opaque = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_OPAQUE, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "opaque", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_OPAQUE, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.opaque = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_string = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_STRING, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "string", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_STRING, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.string = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_boolean = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_BOOLEAN, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "boolean", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_BOOL, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.boolean = NULL, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_u8 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u8", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint8_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint8_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_u16 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u16", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_UINT16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint16 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint16_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint16_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_u32 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_UINT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint32_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint32_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_u64 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_U64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_UINT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (uint64_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (uint64_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_i8 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i8", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_INT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int8_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int8_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_i16 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i16", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_INT16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int16 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int16_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int16_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_i32 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_INT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int32_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int32_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_i64 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_I64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_INT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (int64_t[]){ 7 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (int64_t[]){ 18 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_f32 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "f32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_FLOAT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.float32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (float[]){ 7.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (float[]){ 18.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -const registry_parameter_t registry_tests_constrained_min_max_f64 = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_F64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "f64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_constrained_min_max, - .type = REGISTRY_TYPE_FLOAT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.float64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = (double[]){ 7.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = (double[]){ 18.0 }, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ -}; - -registry_schema_t registry_tests_constrained_min_max = { - .id = REGISTRY_TESTS_CONSTRAINED_MIN_MAX_VALUES, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "constrained_min_max", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .namespace = ®istry_tests, - .mapping = mapping, - .groups = NULL, - .groups_len = 0, - .parameters = (const registry_parameter_t *[]) { - ®istry_tests_constrained_min_max_opaque, - ®istry_tests_constrained_min_max_string, - ®istry_tests_constrained_min_max_boolean, - ®istry_tests_constrained_min_max_u8, - ®istry_tests_constrained_min_max_u16, - ®istry_tests_constrained_min_max_u32, - ®istry_tests_constrained_min_max_u64, - ®istry_tests_constrained_min_max_i8, - ®istry_tests_constrained_min_max_i16, - ®istry_tests_constrained_min_max_i32, - ®istry_tests_constrained_min_max_i64, - ®istry_tests_constrained_min_max_f32, - ®istry_tests_constrained_min_max_f64, - }, - .parameters_len = 13, -}; - -#endif diff --git a/sys/registry/namespace/tests/namespace_tests_full.c b/sys/registry/namespace/tests/namespace_tests_full.c index 1c1f2a38c76e..ecf2d7d38cb6 100644 --- a/sys/registry/namespace/tests/namespace_tests_full.c +++ b/sys/registry/namespace/tests/namespace_tests_full.c @@ -119,21 +119,6 @@ const registry_parameter_t registry_tests_full_opaque = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_OPAQUE, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.opaque = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_string = { @@ -146,21 +131,6 @@ const registry_parameter_t registry_tests_full_string = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_STRING, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.string = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_boolean = { @@ -173,12 +143,6 @@ const registry_parameter_t registry_tests_full_boolean = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_BOOL, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.boolean = NULL, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_u8 = { @@ -191,27 +155,6 @@ const registry_parameter_t registry_tests_full_u8 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_u16 = { @@ -224,27 +167,6 @@ const registry_parameter_t registry_tests_full_u16 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_UINT16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint16 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_u32 = { @@ -257,27 +179,6 @@ const registry_parameter_t registry_tests_full_u32 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_UINT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_u64 = { @@ -290,27 +191,6 @@ const registry_parameter_t registry_tests_full_u64 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_UINT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_i8 = { @@ -323,27 +203,6 @@ const registry_parameter_t registry_tests_full_i8 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_INT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_i16 = { @@ -356,27 +215,6 @@ const registry_parameter_t registry_tests_full_i16 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_INT16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int16 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_i32 = { @@ -389,27 +227,6 @@ const registry_parameter_t registry_tests_full_i32 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_INT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_i64 = { @@ -422,27 +239,6 @@ const registry_parameter_t registry_tests_full_i64 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_INT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_f32 = { @@ -455,27 +251,6 @@ const registry_parameter_t registry_tests_full_f32 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_FLOAT32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.float32 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_parameter_t registry_tests_full_f64 = { @@ -488,27 +263,6 @@ const registry_parameter_t registry_tests_full_f64 = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_full, .type = REGISTRY_TYPE_FLOAT64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.int64 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .min_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) || IS_ACTIVE(DOXYGEN) - .max_value = NULL, -#endif /* CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK */ - }, -#endif /* CONSTRAINTS */ }; registry_schema_t registry_tests_full = { diff --git a/sys/registry/namespace/tests/namespace_tests_nested.c b/sys/registry/namespace/tests/namespace_tests_nested.c index d199ff1d4c10..2b9aadd05edb 100644 --- a/sys/registry/namespace/tests/namespace_tests_nested.c +++ b/sys/registry/namespace/tests/namespace_tests_nested.c @@ -64,21 +64,6 @@ const registry_parameter_t registry_tests_nested_parameter = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_nested, .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ }; const registry_group_t registry_tests_nested_group = { @@ -108,21 +93,6 @@ const registry_parameter_t registry_tests_nested_group_parameter = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .schema = ®istry_tests_nested, .type = REGISTRY_TYPE_UINT8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK) || \ - IS_ACTIVE(CONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK) - .constraints.uint8 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .allowed_values = NULL, - .allowed_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK) || IS_ACTIVE(DOXYGEN) - .forbidden_values = NULL, - .forbidden_values_len = 0, -#endif /* CONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK */ - }, -#endif /* CONSTRAINTS */ }; registry_schema_t registry_tests_nested = { From 7b046d003fea5c5a75c3f1e6773043f25501e50d Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 21 Feb 2024 15:58:11 +0100 Subject: [PATCH 026/117] fixup! tests/unittests: add registry tests Remove min-max and allowed and forbidden value constraints --- .../unittests/tests-registry/Makefile.include | 8 - .../unittests/tests-registry/tests-get-set.c | 819 ------------------ 2 files changed, 827 deletions(-) diff --git a/tests/unittests/tests-registry/Makefile.include b/tests/unittests/tests-registry/Makefile.include index 6e100b9e6eb2..a308a6bcdeb6 100644 --- a/tests/unittests/tests-registry/Makefile.include +++ b/tests/unittests/tests-registry/Makefile.include @@ -1,12 +1,4 @@ -CFLAGS += -DCONFIG_REGISTRY_ENABLE_ALLOWED_VALUES_CHECK -CFLAGS += -DCONFIG_REGISTRY_ENABLE_FORBIDDEN_VALUES_CHECK -CFLAGS += -DCONFIG_REGISTRY_ENABLE_MIN_VALUE_CHECK -CFLAGS += -DCONFIG_REGISTRY_ENABLE_MAX_VALUE_CHECK - CFLAGS += -DCONFIG_REGISTRY_ENABLE_META_NAME USEMODULE += registry_namespace_tests_full -USEMODULE += registry_namespace_tests_constrained_min_max -USEMODULE += registry_namespace_tests_constrained_allowed_values -USEMODULE += registry_namespace_tests_constrained_forbidden_values USEMODULE += registry_namespace_tests_nested diff --git a/tests/unittests/tests-registry/tests-get-set.c b/tests/unittests/tests-registry/tests-get-set.c index 37ccd656bd87..b82cc8a35186 100644 --- a/tests/unittests/tests-registry/tests-get-set.c +++ b/tests/unittests/tests-registry/tests-get-set.c @@ -32,9 +32,6 @@ #include "tests-registry.h" #include "registry/namespace/tests.h" #include "registry/namespace/tests/full.h" -#include "registry/namespace/tests/constrained_min_max.h" -#include "registry/namespace/tests/constrained_allowed_values.h" -#include "registry/namespace/tests/constrained_forbidden_values.h" #define FLOAT_MAX_CHAR_COUNT ((FLT_MAX_10_EXP + 1) + 1 + 1 + 6) // (FLT_MAX_10_EXP + 1) + sign + dot + 6 decimal places #define DOUBLE_MAX_CHAR_COUNT ((DBL_MAX_10_EXP + 1) + 1 + 1 + 6) // (DBL_MAX_10_EXP + 1) + sign + dot + 6 decimal places @@ -78,86 +75,6 @@ static registry_instance_t test_full_instance_1 = { .commit_cb = &commit_cb, }; -static registry_tests_constrained_min_max_instance_t test_constrained_min_max_instance_1_data = { - .opaque = { - .value = 7, - }, - .string = "hello world", - .boolean = true, - .u8 = 9, - .u16 = 17, - .u32 = 33, - .u64 = 65, - .i8 = 8, - .i16 = 16, - .i32 = 32, - .i64 = 64, - .f32 = 3.2, - .f64 = 6.4, -}; - -static registry_instance_t test_constrained_min_max_instance_1 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) - .name = "test-constrained_min_max-1", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ - .data = &test_constrained_min_max_instance_1_data, - .commit_cb = &commit_cb, -}; - -static registry_tests_constrained_allowed_values_instance_t - test_constrained_allowed_values_instance_1_data = { - .opaque = { - .value = 7, - }, - .string = "hello world", - .boolean = true, - .u8 = 9, - .u16 = 17, - .u32 = 33, - .u64 = 65, - .i8 = 8, - .i16 = 16, - .i32 = 32, - .i64 = 64, - .f32 = 3.2, - .f64 = 6.4, -}; - -static registry_instance_t test_constrained_allowed_values_instance_1 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) - .name = "test-constrained_allowed_values-1", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ - .data = &test_constrained_allowed_values_instance_1_data, - .commit_cb = &commit_cb, -}; - -static registry_tests_constrained_forbidden_values_instance_t - test_constrained_forbidden_values_instance_1_data = { - .opaque = { - .value = 7, - }, - .string = "hello world", - .boolean = true, - .u8 = 9, - .u16 = 17, - .u32 = 33, - .u64 = 65, - .i8 = 8, - .i16 = 16, - .i32 = 32, - .i64 = 64, - .f32 = 3.2, - .f64 = 6.4, -}; - -static registry_instance_t test_constrained_forbidden_values_instance_1 = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) - .name = "test-constrained_forbidden_values-1", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ - .data = &test_constrained_forbidden_values_instance_1_data, - .commit_cb = &commit_cb, -}; - static void test_registry_setup(void) { /* init registry */ @@ -165,8 +82,6 @@ static void test_registry_setup(void) /* add schema instances */ registry_add_schema_instance(®istry_tests_full, &test_full_instance_1); - registry_add_schema_instance(®istry_tests_constrained_min_max, - &test_constrained_min_max_instance_1); } static void test_registry_teardown(void) @@ -587,751 +502,17 @@ static void tests_registry_max_values(void) TEST_ASSERT_EQUAL_STRING(input_f64_string, output_f64_string); } -static void tests_registry_constraints_min_max(void) -{ - int res_too_small; - int res_too_large; - int res_within_range; - - /* opaque */ - /* opaque does not have min_max constraints */ - - /* string */ - /* string does not have min_max constraints */ - - /* bool */ - /* bool does not have min_max constraints */ - - /* u8 */ - const uint8_t input_u8_too_small = - *registry_tests_constrained_min_max_u8.constraints.uint8.min_value - 1; - - const uint8_t input_u8_too_large = - *registry_tests_constrained_min_max_u8.constraints.uint8.max_value + 1; - const uint8_t input_u8_within_range = - *registry_tests_constrained_min_max_u8.constraints.uint8.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u8, - &input_u8_too_small, sizeof(input_u8_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u8, - &input_u8_too_large, sizeof(input_u8_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u8, - &input_u8_within_range, sizeof(input_u8_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); - - - /* u16 */ - const uint16_t input_u16_too_small = - *registry_tests_constrained_min_max_u16.constraints.uint16.min_value - - 1; - const uint16_t input_u16_too_large = - *registry_tests_constrained_min_max_u16.constraints.uint16.max_value + - 1; - const uint16_t input_u16_within_range = - *registry_tests_constrained_min_max_u16.constraints.uint16.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u16, - &input_u16_too_small, sizeof(input_u16_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u16, - &input_u16_too_large, sizeof(input_u16_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u16, - &input_u16_within_range, sizeof(input_u16_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); - - - /* u32 */ - const uint32_t input_u32_too_small = - *registry_tests_constrained_min_max_u32.constraints.uint32.min_value - - 1; - const uint32_t input_u32_too_large = - *registry_tests_constrained_min_max_u32.constraints.uint32.max_value + - 1; - const uint32_t input_u32_within_range = - *registry_tests_constrained_min_max_u32.constraints.uint32.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u32, - &input_u32_too_small, sizeof(input_u32_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u32, - &input_u32_too_large, sizeof(input_u32_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u32, - &input_u32_within_range, sizeof(input_u32_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); - - - /* u64 */ - const uint64_t input_u64_too_small = - *registry_tests_constrained_min_max_u64.constraints.uint64.min_value - - 1; - const uint64_t input_u64_too_large = - *registry_tests_constrained_min_max_u64.constraints.uint64.max_value + - 1; - const uint64_t input_u64_within_range = - *registry_tests_constrained_min_max_u64.constraints.uint64.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u64, - &input_u64_too_small, sizeof(input_u64_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u64, - &input_u64_too_large, sizeof(input_u64_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_u64, - &input_u64_within_range, sizeof(input_u64_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); - - - /* i8 */ - const uint8_t input_i8_too_small = - *registry_tests_constrained_min_max_i8.constraints.int8.min_value - - 1; - const int8_t input_i8_too_large = - *registry_tests_constrained_min_max_i8.constraints.int8.max_value + - 1; - const int8_t input_i8_within_range = - *registry_tests_constrained_min_max_i8.constraints.int8.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i8, - &input_i8_too_small, sizeof(input_i8_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i8, - &input_i8_too_large, sizeof(input_i8_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i8, - &input_i8_within_range, sizeof(input_i8_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); - - - /* i16 */ - const int16_t input_i16_too_small = - *registry_tests_constrained_min_max_i16.constraints.int16.min_value - - 1; - const int16_t input_i16_too_large = - *registry_tests_constrained_min_max_i16.constraints.int16.max_value + - 1; - const int16_t input_i16_within_range = - *registry_tests_constrained_min_max_i16.constraints.int16.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i16, - &input_i16_too_small, sizeof(input_i16_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i16, - &input_i16_too_large, sizeof(input_i16_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i16, - &input_i16_within_range, sizeof(input_i16_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); - - - /* i32 */ - const int32_t input_i32_too_small = - *registry_tests_constrained_min_max_i32.constraints.int32.min_value - - 1; - const int32_t input_i32_too_large = - *registry_tests_constrained_min_max_i32.constraints.int32.max_value + - 1; - const int32_t input_i32_within_range = - *registry_tests_constrained_min_max_i32.constraints.int32.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i32, - &input_i32_too_small, sizeof(input_i32_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i32, - &input_i32_too_large, sizeof(input_i32_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i32, - &input_i32_within_range, sizeof(input_i32_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); - - - /* i64 */ - const int64_t input_i64_too_small = - *registry_tests_constrained_min_max_i64.constraints.int64.min_value - - 1; - const int64_t input_i64_too_large = - *registry_tests_constrained_min_max_i64.constraints.int64.max_value + - 1; - const int64_t input_i64_within_range = - *registry_tests_constrained_min_max_i64.constraints.int64.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i64, - &input_i64_too_small, sizeof(input_i64_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i64, - &input_i64_too_large, sizeof(input_i64_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_i64, - &input_i64_within_range, sizeof(input_i64_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); - - - /* f32 */ - const float input_f32_too_small = - *registry_tests_constrained_min_max_f32.constraints.float32.min_value - - 1.0; - const float input_f32_too_large = - *registry_tests_constrained_min_max_f32.constraints.float32.max_value + - 1.0; - const float input_f32_within_range = - *registry_tests_constrained_min_max_f32.constraints.float32.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_f32, - &input_f32_too_small, sizeof(input_f32_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_f32, - &input_f32_too_large, sizeof(input_f32_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_f32, - &input_f32_within_range, sizeof(input_f32_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); - - - /* f64 */ - const double input_f64_too_small = - *registry_tests_constrained_min_max_f64.constraints.float64.min_value - - 1.0; - const double input_f64_too_large = - *registry_tests_constrained_min_max_f64.constraints.float64.max_value + - 1.0; - const double input_f64_within_range = - *registry_tests_constrained_min_max_f64.constraints.float64.min_value; - - res_too_small = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_f64, - &input_f64_too_small, sizeof(input_f64_too_small)); - - res_too_large = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_f64, - &input_f64_too_large, sizeof(input_f64_too_large)); - - res_within_range = registry_set(&test_constrained_min_max_instance_1, - ®istry_tests_constrained_min_max_f64, - &input_f64_within_range, sizeof(input_f64_within_range)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_small); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_too_large); - TEST_ASSERT_EQUAL_INT(0, res_within_range); -} - -static void tests_registry_constraints_allowed_values(void) -{ - int res_allowed; - int res_other; - - /* opaque */ - const registry_tests_constrained_allowed_values_instance_opaque_t *input_opaque_allowed = - registry_tests_constrained_allowed_values_opaque.constraints.opaque.allowed_values[0]; - const registry_tests_constrained_allowed_values_instance_opaque_t input_opaque_other = { - .value = 19, - }; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_opaque, - input_opaque_allowed, sizeof(*input_opaque_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_opaque, - &input_opaque_other, sizeof(input_opaque_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - - /* string */ - const char *input_string_allowed = - registry_tests_constrained_allowed_values_string.constraints.string.allowed_values[0]; - const char *input_string_other = "test test"; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_string, - input_string_allowed, sizeof(input_string_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_string, - input_string_other, sizeof(input_string_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - - /* bool */ - /* bool does not have allowed values constraints */ - - /* u8 */ - const uint8_t input_u8_allowed = - registry_tests_constrained_allowed_values_u8.constraints.uint8.allowed_values[0]; - const uint8_t input_u8_other = - registry_tests_constrained_allowed_values_u8.constraints.uint8.allowed_values[0] + 1; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_u8, - &input_u8_allowed, sizeof(input_u8_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_u8, - &input_u8_other, sizeof(input_u8_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - - /* u16 */ - const uint16_t input_u16_allowed = - registry_tests_constrained_allowed_values_u16.constraints.uint16.allowed_values[0]; - const uint16_t input_u16_other = - registry_tests_constrained_allowed_values_u16.constraints.uint16.allowed_values[0] + 1; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_u16, - &input_u16_allowed, sizeof(input_u16_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_u16, - &input_u16_other, sizeof(input_u16_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - - /* u32 */ - const uint32_t input_u32_allowed = - registry_tests_constrained_allowed_values_u32.constraints.uint32.allowed_values[0]; - const uint32_t input_u32_other = - registry_tests_constrained_allowed_values_u32.constraints.uint32.allowed_values[0] + 1; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_u32, - &input_u32_allowed, sizeof(input_u32_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_u32, - &input_u32_other, sizeof(input_u16_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - - /* u64 */ - const uint64_t input_u64_allowed = - registry_tests_constrained_allowed_values_u64.constraints.uint64.allowed_values[0]; - const uint64_t input_u64_other = - registry_tests_constrained_allowed_values_u64.constraints.uint64.allowed_values[0] + 1; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_u64, - &input_u64_allowed, sizeof(input_u64_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_u64, - &input_u64_other, sizeof(input_u16_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - - /* i8 */ - const int8_t input_i8_allowed = - registry_tests_constrained_allowed_values_i8.constraints.int8.allowed_values[0]; - const int8_t input_i8_other = - registry_tests_constrained_allowed_values_i8.constraints.int8.allowed_values[0] + 1; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_i8, - &input_i8_allowed, sizeof(input_i8_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_i8, - &input_i8_other, sizeof(input_i8_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - - /* i16 */ - const int16_t input_i16_allowed = - registry_tests_constrained_allowed_values_i16.constraints.int16.allowed_values[0]; - const int16_t input_i16_other = - registry_tests_constrained_allowed_values_i16.constraints.int16.allowed_values[0] + 1; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_i16, - &input_i16_allowed, sizeof(input_i16_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_i16, - &input_i16_other, sizeof(input_i16_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - - /* i32 */ - const int32_t input_i32_allowed = - registry_tests_constrained_allowed_values_i32.constraints.int32.allowed_values[0]; - const int32_t input_i32_other = - registry_tests_constrained_allowed_values_i32.constraints.int32.allowed_values[0] + 1; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_i32, - &input_i32_allowed, sizeof(input_i32_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_i32, - &input_i32_other, sizeof(input_i32_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - - /* i64 */ - const int64_t input_i64_allowed = - registry_tests_constrained_allowed_values_i64.constraints.int64.allowed_values[0]; - const int64_t input_i64_other = - registry_tests_constrained_allowed_values_i64.constraints.int64.allowed_values[0] + 1; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_i64, - &input_i64_allowed, sizeof(input_i64_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_i64, - &input_i64_other, sizeof(input_i64_other)); - - - /* f32 */ - const float input_f32_allowed = - registry_tests_constrained_allowed_values_f32.constraints.float32.allowed_values[0]; - const float input_f32_other = - registry_tests_constrained_allowed_values_f32.constraints.float32.allowed_values[0] + 1.0; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_f32, - &input_f32_allowed, sizeof(input_f32_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_f32, - &input_f32_other, sizeof(input_f32_other)); - - - /* f64 */ - const double input_f64_allowed = - registry_tests_constrained_allowed_values_f64.constraints.float64.allowed_values[0]; - const double input_f64_other = - registry_tests_constrained_allowed_values_f64.constraints.float64.allowed_values[0] + 1.0; - - res_allowed = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_f64, - &input_f64_allowed, sizeof(input_f64_allowed)); - - res_other = registry_set(&test_constrained_allowed_values_instance_1, - ®istry_tests_constrained_allowed_values_f64, - &input_f64_other, sizeof(input_f64_other)); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); - - TEST_ASSERT_EQUAL_INT(0, res_allowed); - TEST_ASSERT_EQUAL_INT(-EINVAL, res_other); -} - -static void tests_registry_constraints_forbidden_values(void) -{ - int res_forbidden; - int res_other; - - /* opaque */ - const registry_tests_constrained_forbidden_values_instance_opaque_t *input_opaque_forbidden = - registry_tests_constrained_forbidden_values_opaque.constraints.opaque.forbidden_values[0]; - const registry_tests_constrained_forbidden_values_instance_opaque_t input_opaque_other = { - .value = 19, - }; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_opaque, - input_opaque_forbidden, sizeof(*input_opaque_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_opaque, - &input_opaque_other, sizeof(input_opaque_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* string */ - const char *input_string_forbidden = - registry_tests_constrained_forbidden_values_string.constraints.string.forbidden_values[0]; - const char *input_string_other = "test test"; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_string, - input_string_forbidden, sizeof(input_string_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_string, - input_string_other, sizeof(input_string_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* bool */ - /* bool does not have forbidden values constraints */ - - /* u8 */ - const uint8_t input_u8_forbidden = - registry_tests_constrained_forbidden_values_u8.constraints.uint8.forbidden_values[0]; - const uint8_t input_u8_other = - registry_tests_constrained_forbidden_values_u8.constraints.uint8.forbidden_values[0] + 1; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_u8, - &input_u8_forbidden, sizeof(input_u8_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_u8, - &input_u8_other, sizeof(input_u8_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* u16 */ - const uint16_t input_u16_forbidden = - registry_tests_constrained_forbidden_values_u16.constraints.uint16.forbidden_values[0]; - const uint16_t input_u16_other = - registry_tests_constrained_forbidden_values_u16.constraints.uint16.forbidden_values[0] + 1; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_u16, - &input_u16_forbidden, sizeof(input_u16_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_u16, - &input_u16_other, sizeof(input_u16_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* u32 */ - const uint32_t input_u32_forbidden = - registry_tests_constrained_forbidden_values_u32.constraints.uint32.forbidden_values[0]; - const uint32_t input_u32_other = - registry_tests_constrained_forbidden_values_u32.constraints.uint32.forbidden_values[0] + 1; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_u32, - &input_u32_forbidden, sizeof(input_u32_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_u32, - &input_u32_other, sizeof(input_u16_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* u64 */ - const uint64_t input_u64_forbidden = - registry_tests_constrained_forbidden_values_u64.constraints.uint64.forbidden_values[0]; - const uint64_t input_u64_other = - registry_tests_constrained_forbidden_values_u64.constraints.uint64.forbidden_values[0] + 1; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_u64, - &input_u64_forbidden, sizeof(input_u64_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_u64, - &input_u64_other, sizeof(input_u16_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* i8 */ - const int8_t input_i8_forbidden = - registry_tests_constrained_forbidden_values_i8.constraints.int8.forbidden_values[0]; - const int8_t input_i8_other = - registry_tests_constrained_forbidden_values_i8.constraints.int8.forbidden_values[0] + 1; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_i8, - &input_i8_forbidden, sizeof(input_i8_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_i8, - &input_i8_other, sizeof(input_i8_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* i16 */ - const int16_t input_i16_forbidden = - registry_tests_constrained_forbidden_values_i16.constraints.int16.forbidden_values[0]; - const int16_t input_i16_other = - registry_tests_constrained_forbidden_values_i16.constraints.int16.forbidden_values[0] + 1; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_i16, - &input_i16_forbidden, sizeof(input_i16_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_i16, - &input_i16_other, sizeof(input_i16_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* i32 */ - const int32_t input_i32_forbidden = - registry_tests_constrained_forbidden_values_i32.constraints.int32.forbidden_values[0]; - const int32_t input_i32_other = - registry_tests_constrained_forbidden_values_i32.constraints.int32.forbidden_values[0] + 1; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_i32, - &input_i32_forbidden, sizeof(input_i32_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_i32, - &input_i32_other, sizeof(input_i32_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* i64 */ - const int64_t input_i64_forbidden = - registry_tests_constrained_forbidden_values_i64.constraints.int64.forbidden_values[0]; - const int64_t input_i64_other = - registry_tests_constrained_forbidden_values_i64.constraints.int64.forbidden_values[0] + 1; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_i64, - &input_i64_forbidden, sizeof(input_i64_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_i64, - &input_i64_other, sizeof(input_i64_other)); - - - /* f32 */ - const float input_f32_forbidden = - registry_tests_constrained_forbidden_values_f32.constraints.float32.forbidden_values[0]; - const float input_f32_other = - registry_tests_constrained_forbidden_values_f32.constraints.float32.forbidden_values[0] + - 1.0; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_f32, - &input_f32_forbidden, sizeof(input_f32_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_f32, - &input_f32_other, sizeof(input_f32_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); - - - /* f64 */ - const double input_f64_forbidden = - registry_tests_constrained_forbidden_values_f64.constraints.float64.forbidden_values[0]; - const double input_f64_other = - registry_tests_constrained_forbidden_values_f64.constraints.float64.forbidden_values[0] + - 1.0; - - res_forbidden = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_f64, - &input_f64_forbidden, sizeof(input_f64_forbidden)); - - res_other = registry_set(&test_constrained_forbidden_values_instance_1, - ®istry_tests_constrained_forbidden_values_f64, - &input_f64_other, sizeof(input_f64_other)); - - TEST_ASSERT_EQUAL_INT(-EINVAL, res_forbidden); - TEST_ASSERT_EQUAL_INT(0, res_other); -} - Test *tests_registry_get_set_tests(void) { (void)tests_registry_min_values; (void)tests_registry_zero_values; (void)tests_registry_max_values; - (void)tests_registry_constraints_min_max; - (void)tests_registry_constraints_allowed_values; - (void)tests_registry_constraints_forbidden_values; EMB_UNIT_TESTFIXTURES(fixtures) { new_TestFixture(tests_registry_min_values), new_TestFixture(tests_registry_zero_values), new_TestFixture(tests_registry_max_values), - new_TestFixture(tests_registry_constraints_min_max), - new_TestFixture(tests_registry_constraints_allowed_values), - new_TestFixture(tests_registry_constraints_forbidden_values), }; EMB_UNIT_TESTCALLER(registry_tests, test_registry_setup, test_registry_teardown, fixtures); From 0674a1a6d86618771f3608725878fca1931d3211 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:07:31 +0200 Subject: [PATCH 027/117] fixup! sys: add runtime configuration registry Simplify registry core API --- sys/include/registry.h | 204 ++++--------------- sys/include/registry/error.h | 5 +- sys/registry/registry.c | 366 ++++++++++++++++++++--------------- 3 files changed, 253 insertions(+), 322 deletions(-) diff --git a/sys/include/registry.h b/sys/include/registry.h index 1cb61bb5d9ba..39e08d67ebbc 100644 --- a/sys/include/registry.h +++ b/sys/include/registry.h @@ -67,6 +67,27 @@ typedef enum { REGISTRY_TYPE_FLOAT64, /**< 64-bits float. */ } registry_type_t; +// TODO Documentation +typedef enum { + REGISTRY_NODE_NAMESPACE = 0, + REGISTRY_NODE_SCHEMA, + REGISTRY_NODE_INSTANCE, + REGISTRY_NODE_GROUP, + REGISTRY_NODE_PARAMETER, +} registry_node_type_t; + +// TODO Documentation +typedef struct { + registry_node_type_t type; + union { + const registry_namespace_t *namespace; + const registry_schema_t *schema; + const registry_group_t *group; + const registry_parameter_t *parameter; + } location; + const registry_instance_t *instance; +} registry_node_t; + /** * @brief Basic representation of a configuration parameter value. */ @@ -163,8 +184,8 @@ struct _registry_schema_t { * * @param[in] parameter_id ID of the parameter that contains the value. * @param[in] instance Pointer to the instance of the schema, that contains the parameter. - * @param[in] val Pointer to buffer containing the new value. - * @param[in] val_len Pointer to length of the buffer to store the current value. + * @param[out] val Pointer to buffer containing the new value. + * @param[out] val_len Pointer to length of the buffer to store the current value. */ void(*const mapping)(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, @@ -208,209 +229,54 @@ int registry_add_schema_instance(const registry_schema_t *schema, * @brief Gets the current value of a parameter that belongs to an instance * of a configuration schema. * - * @param[in] instance Pointer to the configuration schema instance. - * @param[in] parameter Pointer to the configuration parameter. + * @param[in] node A location within the registry configuration tree. * @param[out] value Pointer to a uninitialized @ref registry_value_t struct. * * @return 0 on success, non-zero on failure. */ -int registry_get(const registry_instance_t *instance, const registry_parameter_t *parameter, - registry_value_t *value); +int registry_get(const registry_node_t *node, registry_value_t *value); /** * @brief Sets the value of a configuration parameter that belongs to an instance * of a configuration schema. * - * @param[in] instance Pointer to the configuration schema instance. - * @param[in] parameter Pointer to the configuration parameter. + * @param[in] node A location within the registry configuration tree. * @param[in] buf Pointer to the new value for the configuration parameter. * @param[in] buf_len Length of the buffer. * * @return 0 on success, non-zero on failure. */ -int registry_set(const registry_instance_t *instance, const registry_parameter_t *parameter, - const void *buf, const size_t buf_len); - -/** - * @brief Commits every configuration parameter. - * - * @return 0 on success, non-zero on failure. - */ -int registry_commit(void); +int registry_set(const registry_node_t *node, const void *buf, const size_t buf_len); /** - * @brief Commits every configuration parameter within the given configuration namespace. + * @brief Commits every configuration parameter within the given configuration location (@p node) of the registry configuration tree. * - * @param[in] namespace Pointer to the configuration namespace. + * @param[in] node A location within the registry configuration tree. * * @return 0 on success, non-zero on failure. */ -int registry_commit_namespace(const registry_namespace_t *namespace); +int registry_commit(const registry_node_t *node); -/** - * @brief Commits every configuration parameter within the given configuration schema. - * - * @param[in] schema Pointer to the configuration schema. - * - * @return 0 on success, non-zero on failure. - */ -int registry_commit_schema(const registry_schema_t *schema); - -/** - * @brief Commits every configuration parameter within the given configuration schema instance. - * - * @param[in] instance Pointer to the configuration schema instance. - * - * @return 0 on success, non-zero on failure. - */ -int registry_commit_instance(const registry_instance_t *instance); - -/** - * @brief Commits every configuration parameter within the given configuration group. - * - * @param[in] instance Pointer to the configuration schema instance of the configuration group. - * @param[in] group Pointer to the configuration group. - * - * @return 0 on success, non-zero on failure. - */ -int registry_commit_group(const registry_instance_t *instance, const registry_group_t *group); - -/** - * @brief Commits the given configuration parameter. - * - * @param[in] instance Pointer to the configuration schema instance of the configuration parameter. - * @param[in] parameter Pointer to the configuration parameter. - * - * @return 0 on success, non-zero on failure. - */ -int registry_commit_parameter(const registry_instance_t *instance, - const registry_parameter_t *parameter); - -typedef const union { - const registry_namespace_t *namespace; - const registry_schema_t *schema; - const registry_instance_t *instance; - const registry_group_t *group; - const struct { - const registry_parameter_t *data; - const registry_instance_t *instance; - } parameter; -} registry_export_cb_data_t; - -typedef const enum { - REGISTRY_EXPORT_NAMESPACE, - REGISTRY_EXPORT_SCHEMA, - REGISTRY_EXPORT_INSTANCE, - REGISTRY_EXPORT_GROUP, - REGISTRY_EXPORT_PARAMETER, -} registry_export_cb_data_type_t; - -typedef int (*registry_export_cb_t)(const registry_export_cb_data_t *data, - const registry_export_cb_data_type_t data_type, - const void *context); +typedef int (*registry_export_cb_t)(const registry_node_t *node, const void *context); #define REGISTRY_EXPORT_ALL = 0; #define REGISTRY_EXPORT_SELF = 1; #define REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(_n) (_n + 1); /** - * @brief Exports every configuration parameter. + * @brief Exports every configuration parameter within the given configuration location (@p node) of the registry configuration tree. * + * @param[in] node A location within the registry configuration tree. * @param[in] export_cb Exporting callback function will be called for each namespace, * schema, instance, group and parameter that are in scope. - * @param[in] recursion_depth Defines how deeply nested child groups / parameters + * @param[in] tree_traversal_depth Defines how deeply nested child groups / parameters * will be shown. (0 to show all children, 1 to only show the exact match, n > 1 * to show the exact match plus n - 1 levels of children). * @param[in] context Context that will be passed to @p export_cb. * * @return 0 on success, non-zero on failure. */ -int registry_export(const registry_export_cb_t export_cb, - const uint8_t recursion_depth, const void *context); - -/** - * @brief Exports every configuration parameter within the given configuration namespace. - * - * @param[in] namespace Pointer to the configuration namespace. - * @param[in] export_cb Exporting callback function will be called for the given namespace - * and each of its schemas, instances, groups and parameters that are in scope. - * @param[in] recursion_depth Defines how deeply nested child groups / parameters - * will be shown. (0 to show all children, 1 to only show the exact match, 2 - n - * to show the exact match plus its children ... plus n levels of children). - * @param[in] context Context that will be passed to @p export_cb. - * - * @return 0 on success, non-zero on failure. - */ -int registry_export_namespace(const registry_namespace_t *namespace, - const registry_export_cb_t export_cb, const uint8_t recursion_depth, - const void *context); - -/** - * @brief Exports every configuration parameter within the given configuration schema. - * - * @param[in] schema Pointer to the configuration schema. - * @param[in] export_cb Exporting callback function will be called for the given schema - * and each of its instances, groups and parameters that are in scope. - * @param[in] recursion_depth Defines how deeply nested child groups / parameters - * will be shown. (0 to show all children, 1 to only show the exact match, 2 - n - * to show the exact match plus its children ... plus n levels of children). - * @param[in] context Context that will be passed to @p export_cb. - * - * @return 0 on success, non-zero on failure. - */ -int registry_export_schema(const registry_schema_t *schema, const registry_export_cb_t export_cb, - const uint8_t recursion_depth, const void *context); - -/** - * @brief Exports every configuration parameter within the given configuration schema instance. - * - * @param[in] instance Pointer to the configuration schema instance. - * @param[in] export_cb Exporting callback function will be called for the given instance - * and each of its groups and parameters that are in scope. - * @param[in] recursion_depth Defines how deeply nested child groups / parameters - * will be shown. (0 to show all children, 1 to only show the exact match, 2 - n - * to show the exact match plus its children ... plus n levels of children). - * @param[in] context Context that will be passed to @p export_cb. - * - * @return 0 on success, non-zero on failure. - */ -int registry_export_instance(const registry_instance_t *instance, - const registry_export_cb_t export_cb, const uint8_t recursion_depth, - const void *context); - -/** - * @brief Exports every configuration parameter within the given configuration group. - * - * @param[in] instance Pointer to the configuration schema instance. - * @param[in] group Pointer to the configuration group. - * @param[in] export_cb Exporting callback function will be called for the given group - * and each of its subgroups and parameters that are in scope. - * @param[in] recursion_depth Defines how deeply nested child groups / parameters - * will be shown. (0 to show all children, 1 to only show the exact match, 2 - n - * to show the exact match plus its children ... plus n levels of children). - * @param[in] context Context that will be passed to @p export_cb. - * - * @return 0 on success, non-zero on failure. - */ -int registry_export_group(const registry_instance_t *instance, const registry_group_t *group, - const registry_export_cb_t export_cb, const uint8_t recursion_depth, - const void *context); - -/** - * @brief Exports the given configuration parameter. - * - * @param[in] instance Pointer to the configuration schema instance. - * @param[in] parameter Pointer to the configuration parameter. - * @param[in] export_cb Exporting callback function will be called for the given parameter. - * @param[in] context Context that will be passed to @p export_cb. - * - * @return 0 on success, non-zero on failure. - */ -int registry_export_parameter(const registry_instance_t *instance, - const registry_parameter_t *parameter, - const registry_export_cb_t export_cb, const void *context); - - +int registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context); #ifdef __cplusplus } diff --git a/sys/include/registry/error.h b/sys/include/registry/error.h index 970550d431d4..7dc8b6a36d5b 100644 --- a/sys/include/registry/error.h +++ b/sys/include/registry/error.h @@ -25,16 +25,17 @@ extern "C" { #endif /** - * @brief Error codes start at 1_000 to prevent clashing with stdlib error codes. + * @brief Registry specific error codes. */ typedef const enum { - REGISTRY_ERROR_NONE = 1000, + REGISTRY_ERROR_NONE = 1, REGISTRY_ERROR_NO_DST_STORAGE, REGISTRY_ERROR_NAMESPACE_NOT_FOUND, REGISTRY_ERROR_SCHEMA_NOT_FOUND, REGISTRY_ERROR_INSTANCE_NOT_FOUND, REGISTRY_ERROR_GROUP_NOT_FOUND, REGISTRY_ERROR_PARAMETER_NOT_FOUND, + REGISTRY_ERROR_NODE_INVALID, } registry_error_t; #ifdef __cplusplus diff --git a/sys/registry/registry.c b/sys/registry/registry.c index 5318fb2f47da..4dc16f39250e 100644 --- a/sys/registry/registry.c +++ b/sys/registry/registry.c @@ -31,6 +31,7 @@ #include "registry.h" #include "registry/util.h" +#include "registry/error.h" /* Implementation of the module */ @@ -57,18 +58,22 @@ int registry_add_schema_instance(const registry_schema_t *schema, return 0; } -int registry_get(const registry_instance_t *instance, const registry_parameter_t *parameter, - registry_value_t *value) +int registry_get(const registry_node_t *node, registry_value_t *value) { - assert(instance != NULL); - assert(parameter != NULL); + assert(node != NULL); assert(value != NULL); + if (node->type != REGISTRY_NODE_PARAMETER || node->instance == NULL) { + return -REGISTRY_ERROR_NODE_INVALID; + } + /* call handler to get pointer to registry internal value buffer and length */ void *intern_val = NULL; size_t intern_val_len; - parameter->schema->mapping(parameter->id, instance, &intern_val, &intern_val_len); + const registry_parameter_t *parameter = node->location.parameter; + + parameter->schema->mapping(parameter->id, node->instance, &intern_val, &intern_val_len); /* update buf pointer in registry_value_t to point to the value inside the registry and set buf_len */ value->type = parameter->type; @@ -78,18 +83,22 @@ int registry_get(const registry_instance_t *instance, const registry_parameter_t return 0; } -int registry_set(const registry_instance_t *instance, const registry_parameter_t *parameter, - const void *buf, const size_t buf_len) +int registry_set(const registry_node_t *node, const void *buf, const size_t buf_len) { - assert(instance != NULL); - assert(parameter != NULL); + assert(node != NULL); assert(buf != NULL); + if (node->type != REGISTRY_NODE_PARAMETER || node->instance == NULL) { + return -REGISTRY_ERROR_NODE_INVALID; + } + /* get pointer to registry internal value buffer and length */ void *intern_val = NULL; size_t intern_val_len; - parameter->schema->mapping(parameter->id, instance, &intern_val, &intern_val_len); + const registry_parameter_t *parameter = node->location.parameter; + + parameter->schema->mapping(parameter->id, node->instance, &intern_val, &intern_val_len); if (buf_len > intern_val_len) { return -EINVAL; @@ -101,45 +110,23 @@ int registry_set(const registry_instance_t *instance, const registry_parameter_t return 0; } -int registry_commit(void) +static int _registry_commit_parameter(const registry_instance_t *instance, + const registry_parameter_t *parameter) { - int rc = 0; - - /* commit all namespaces */ - for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { - registry_namespace_t *namespace = _registry_namespaces_xfa[i]; - - int _rc = registry_commit_namespace(namespace); - - if (!_rc) { - rc = _rc; - } - } - - return rc; + return instance->commit_cb(REGISTRY_COMMIT_PARAMETER, ¶meter->id, instance->context); } -int registry_commit_namespace(const registry_namespace_t *namespace) +static int _registry_commit_group(const registry_instance_t *instance, const registry_group_t *group) { - assert(namespace != NULL); - - int rc = 0; - - /* commit all configuration schemas of the given namespace if available */ - for (size_t i = 0; i < namespace->schemas_len; i++) { - const registry_schema_t *child = namespace->schemas[i]; - - int _rc = registry_commit_schema(child); - - if (!_rc) { - rc = _rc; - } - } + return instance->commit_cb(REGISTRY_COMMIT_GROUP, &group->id, instance->context); +} - return rc; +static int _registry_commit_instance(const registry_instance_t *instance) +{ + return instance->commit_cb(REGISTRY_COMMIT_INSTANCE, NULL, instance->context); } -int registry_commit_schema(const registry_schema_t *schema) +static int _registry_commit_schema(const registry_schema_t *schema) { assert(schema != NULL); @@ -160,7 +147,7 @@ int registry_commit_schema(const registry_schema_t *schema) return -EINVAL; } - int _rc = registry_commit_instance(instance); + int _rc = _registry_commit_instance(instance); if (!_rc) { rc = _rc; @@ -170,32 +157,17 @@ int registry_commit_schema(const registry_schema_t *schema) return rc; } -int registry_commit_instance(const registry_instance_t *instance) +static int _registry_commit_namespace(const registry_namespace_t *namespace) { - return instance->commit_cb(REGISTRY_COMMIT_INSTANCE, NULL, instance->context); -} - -int registry_commit_group(const registry_instance_t *instance, const registry_group_t *group) -{ - return instance->commit_cb(REGISTRY_COMMIT_GROUP, &group->id, instance->context); -} - -int registry_commit_parameter(const registry_instance_t *instance, - const registry_parameter_t *parameter) -{ - return instance->commit_cb(REGISTRY_COMMIT_PARAMETER, ¶meter->id, instance->context); -} + assert(namespace != NULL); -int registry_export(const registry_export_cb_t export_cb, const uint8_t recursion_depth, - const void *context) -{ int rc = 0; - /* export all namespaces */ - for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { - registry_namespace_t *namespace = _registry_namespaces_xfa[i]; + /* commit all configuration schemas of the given namespace if available */ + for (size_t i = 0; i < namespace->schemas_len; i++) { + const registry_schema_t *child = namespace->schemas[i]; - int _rc = registry_export_namespace(namespace, export_cb, recursion_depth, context); + int _rc = _registry_commit_schema(child); if (!_rc) { rc = _rc; @@ -205,110 +177,137 @@ int registry_export(const registry_export_cb_t export_cb, const uint8_t recursio return rc; } -int registry_export_namespace(const registry_namespace_t *namespace, - const registry_export_cb_t export_cb, const uint8_t recursion_depth, - const void *context) -{ - assert(namespace != NULL); - - /* export the given namespace */ - registry_export_cb_data_t export_data = { .namespace = namespace }; - int rc = export_cb(&export_data, REGISTRY_EXPORT_NAMESPACE, context); - - /* export all configuration schemas of the given namespace if available and within recursion_depth bounds */ - if (recursion_depth == 1) { - return 0; - } - else { - int new_recursion_depth = recursion_depth; - if (recursion_depth > 1) { - new_recursion_depth--; - } +int registry_commit(const registry_node_t *node) { + int rc = 0; - for (size_t i = 0; i < namespace->schemas_len; i++) { - const registry_schema_t *child = namespace->schemas[i]; + if (node == NULL) { + /* commit all namespaces */ + for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { + registry_namespace_t *namespace = _registry_namespaces_xfa[i]; - int _rc = registry_export_schema(child, export_cb, new_recursion_depth, context); + int _rc = _registry_commit_namespace(namespace); if (!_rc) { rc = _rc; } } + } else { + switch (node->type) + { + case REGISTRY_NODE_NAMESPACE: + rc = _registry_commit_namespace(node->location.namespace); + break; + case REGISTRY_NODE_SCHEMA: + rc = _registry_commit_schema(node->location.schema); + break; + case REGISTRY_NODE_INSTANCE: + rc = _registry_commit_instance(node->instance); + break; + case REGISTRY_NODE_GROUP: + rc = _registry_commit_group(node->instance, node->location.group); + break; + case REGISTRY_NODE_PARAMETER: + rc = _registry_commit_parameter(node->instance, node->location.parameter); + break; + } } return rc; } -int registry_export_schema(const registry_schema_t *schema, const registry_export_cb_t export_cb, - const uint8_t recursion_depth, const void *context) +static int _registry_export_parameter(const registry_instance_t *instance, + const registry_parameter_t *parameter, + const registry_export_cb_t export_cb, const void *context) { - assert(schema != NULL); + assert(parameter != NULL); - /* export the given configuration schema */ - registry_export_cb_data_t export_data = { .schema = schema }; - int rc = export_cb(&export_data, REGISTRY_EXPORT_SCHEMA, context); + const registry_node_t export_node = { + .type = REGISTRY_NODE_PARAMETER, + .instance = instance, + .location.parameter = parameter, + }; + + return export_cb(&export_node, context); +} - /* export all instances of the given configuration schema if available and within recursion_depth bounds */ - if (recursion_depth == 1) { +static int _registry_export_group(const registry_instance_t *instance, const registry_group_t *group, + const registry_export_cb_t export_cb, + const uint8_t tree_traversal_depth, const void *context) +{ + assert(group != NULL); + + /* export the given configuration group */ + const registry_node_t export_node = { + .type = REGISTRY_NODE_GROUP, + .instance = NULL, + .location.group = group, + }; + int rc = export_cb(&export_node, context); + + /* export all children of the given configuration group if available and within tree_traversal_depth bounds */ + if (tree_traversal_depth == 1) { return 0; } else { - int new_recursion_depth = recursion_depth; - if (recursion_depth > 1) { - new_recursion_depth--; + int new_tree_traversal_depth = tree_traversal_depth; + if (tree_traversal_depth > 1) { + new_tree_traversal_depth--; } - clist_node_t *node = schema->instances.next; - - if (!node) { - return -EINVAL; - } + int _rc = rc; - do { - node = node->next; - registry_instance_t *instance = container_of(node, registry_instance_t, node); + /* group */ + for (size_t i = 0; i < group->groups_len; i++) { + _rc = _registry_export_group(instance, group->groups[i], export_cb, new_tree_traversal_depth, + context); - if (!instance) { - return -EINVAL; + if (!_rc) { + rc = _rc; } + } - int _rc = registry_export_instance(instance, export_cb, new_recursion_depth, context); + /* parameter */ + for (size_t i = 0; i < group->parameters_len; i++) { + _rc = _registry_export_parameter(instance, group->parameters[i], export_cb, context); if (!_rc) { rc = _rc; } - } while (node != schema->instances.next); + } } return rc; } -int registry_export_instance(const registry_instance_t *instance, - const registry_export_cb_t export_cb, const uint8_t recursion_depth, +static int _registry_export_instance(const registry_instance_t *instance, + const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context) { assert(instance != NULL); /* export the given configuration schema instance */ - registry_export_cb_data_t export_data = { .instance = instance }; - int rc = export_cb(&export_data, REGISTRY_EXPORT_INSTANCE, context); + const registry_node_t export_node = { + .type = REGISTRY_NODE_INSTANCE, + .instance = instance, + }; + int rc = export_cb(&export_node, context); - /* export all groups or parameters of the given configuration schema instance if available and within recursion_depth bounds */ - if (recursion_depth == 1) { + /* export all groups or parameters of the given configuration schema instance if available and within tree_traversal_depth bounds */ + if (tree_traversal_depth == 1) { return 0; } else { - int new_recursion_depth = recursion_depth; - if (recursion_depth > 1) { - new_recursion_depth--; + int new_tree_traversal_depth = tree_traversal_depth; + if (tree_traversal_depth > 1) { + new_tree_traversal_depth--; } int _rc = rc; /* groups */ for (size_t i = 0; i < instance->schema->groups_len; i++) { - _rc = registry_export_group(instance, instance->schema->groups[i], export_cb, - new_recursion_depth, context); + _rc = _registry_export_group(instance, instance->schema->groups[i], export_cb, + new_tree_traversal_depth, context); if (!_rc) { rc = _rc; @@ -317,7 +316,7 @@ int registry_export_instance(const registry_instance_t *instance, /* parameters */ for (size_t i = 0; i < instance->schema->parameters_len; i++) { - _rc = registry_export_parameter(instance, instance->schema->parameters[i], export_cb, + _rc = _registry_export_parameter(instance, instance->schema->parameters[i], export_cb, context); if (!_rc) { @@ -329,41 +328,82 @@ int registry_export_instance(const registry_instance_t *instance, return rc; } -int registry_export_group(const registry_instance_t *instance, const registry_group_t *group, - const registry_export_cb_t export_cb, - const uint8_t recursion_depth, const void *context) +static int _registry_export_schema(const registry_schema_t *schema, const registry_export_cb_t export_cb, + const uint8_t tree_traversal_depth, const void *context) { - assert(group != NULL); + assert(schema != NULL); - /* export the given configuration group */ - registry_export_cb_data_t export_data = { .group = group }; - int rc = export_cb(&export_data, REGISTRY_EXPORT_GROUP, context); + /* export the given configuration schema */ + const registry_node_t export_node = { + .type = REGISTRY_NODE_SCHEMA, + .instance = NULL, + .location.schema = schema, + }; + int rc = export_cb(&export_node, context); - /* export all children of the given configuration group if available and within recursion_depth bounds */ - if (recursion_depth == 1) { + /* export all instances of the given configuration schema if available and within tree_traversal_depth bounds */ + if (tree_traversal_depth == 1) { return 0; } else { - int new_recursion_depth = recursion_depth; - if (recursion_depth > 1) { - new_recursion_depth--; + int new_tree_traversal_depth = tree_traversal_depth; + if (tree_traversal_depth > 1) { + new_tree_traversal_depth--; } - int _rc = rc; + clist_node_t *node = schema->instances.next; - /* group */ - for (size_t i = 0; i < group->groups_len; i++) { - _rc = registry_export_group(instance, group->groups[i], export_cb, new_recursion_depth, - context); + if (!node) { + return -EINVAL; + } + + do { + node = node->next; + registry_instance_t *instance = container_of(node, registry_instance_t, node); + + if (!instance) { + return -EINVAL; + } + + int _rc = _registry_export_instance(instance, export_cb, new_tree_traversal_depth, context); if (!_rc) { rc = _rc; } + } while (node != schema->instances.next); + } + + return rc; +} + +static int _registry_export_namespace(const registry_namespace_t *namespace, + const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, + const void *context) +{ + assert(namespace != NULL); + + /* export the given namespace */ + const registry_node_t export_node = { + .type = REGISTRY_NODE_NAMESPACE, + .instance = NULL, + .location.namespace = namespace, + }; + int rc = export_cb(&export_node, context); + + /* export all configuration schemas of the given namespace if available and within tree_traversal_depth bounds */ + if (tree_traversal_depth == 1) { + return 0; + } + else { + int new_tree_traversal_depth = tree_traversal_depth; + if (tree_traversal_depth > 1) { + new_tree_traversal_depth--; } - /* parameter */ - for (size_t i = 0; i < group->parameters_len; i++) { - _rc = registry_export_parameter(instance, group->parameters[i], export_cb, context); + for (size_t i = 0; i < namespace->schemas_len; i++) { + const registry_schema_t *child = namespace->schemas[i]; + + int _rc = _registry_export_schema(child, export_cb, new_tree_traversal_depth, context); if (!_rc) { rc = _rc; @@ -374,17 +414,41 @@ int registry_export_group(const registry_instance_t *instance, const registry_gr return rc; } -int registry_export_parameter(const registry_instance_t *instance, - const registry_parameter_t *parameter, - const registry_export_cb_t export_cb, const void *context) +int registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context) { - assert(parameter != NULL); + int rc = 0; - registry_export_cb_data_t export_data = { - .parameter = { - .data = parameter, - .instance = instance, + if (node == NULL) { + /* export all namespaces */ + for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { + registry_namespace_t *namespace = _registry_namespaces_xfa[i]; + + int _rc = _registry_export_namespace(namespace, export_cb, tree_traversal_depth, context); + + if (!_rc) { + rc = _rc; + } } - }; - return export_cb(&export_data, REGISTRY_EXPORT_PARAMETER, context); + } else { + switch (node->type) + { + case REGISTRY_NODE_NAMESPACE: + rc = _registry_export_namespace(node->location.namespace, export_cb, tree_traversal_depth, context); + break; + case REGISTRY_NODE_SCHEMA: + rc = _registry_export_schema(node->location.schema, export_cb, tree_traversal_depth, context); + break; + case REGISTRY_NODE_INSTANCE: + rc = _registry_export_instance(node->instance, export_cb, tree_traversal_depth, context); + break; + case REGISTRY_NODE_GROUP: + rc = _registry_export_group(node->instance, node->location.group, export_cb, tree_traversal_depth, context); + break; + case REGISTRY_NODE_PARAMETER: + rc = _registry_export_parameter(node->instance, node->location.parameter, export_cb, context); + break; + } + } + + return rc; } From bf1438db1cd6a409a823f208bc97c83da9faa14b Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:09:08 +0200 Subject: [PATCH 028/117] fixup! sys/registry: add persistent storage module Adjust storage module API --- sys/include/registry/storage.h | 28 ++----- sys/registry/storage/storage.c | 132 +++------------------------------ 2 files changed, 20 insertions(+), 140 deletions(-) diff --git a/sys/include/registry/storage.h b/sys/include/registry/storage.h index 0304b1a70224..629c0e3ee888 100644 --- a/sys/include/registry/storage.h +++ b/sys/include/registry/storage.h @@ -29,8 +29,7 @@ extern "C" { /** * @brief Prototype of a callback function for the load action of a storage interface. */ -typedef int (*load_cb_t)(const registry_instance_t *instance, const registry_parameter_t *parameter, - const void *buf, const size_t buf_len); +typedef int (*load_cb_t)(const registry_node_t *node, const void *buf, const size_t buf_len); typedef struct _registry_storage_t registry_storage_t; @@ -71,15 +70,13 @@ struct _registry_storage_t { * @brief Saves a parameter into storage. * * @param[in] storage Storage descriptor. - * @param[in] instance Pointer to the configuration schema instance. - * @param[in] parameter Pointer to the configuration parameter. + * @param[in] node A location within the registry configuration tree. * @param[in] value Configuration parameter value. * * @return 0 on success, non-zero on failure. */ int (*save)(const registry_storage_instance_t *storage, - const registry_instance_t *instance, - const registry_parameter_t *parameter, + const registry_node_t *node, const registry_value_t *value); /** @@ -101,23 +98,14 @@ struct _registry_storage_t { int registry_load(void); /** - * @brief Save all configuration parameters to the - * registered storage. + * @brief Save all configuration parameters that are within + * the scope of the to the @p node. to the registered storage. + * + * @param[in] node A location within the registry configuration tree. * * @return 0 on success, non-zero on failure. */ -int registry_save(void); - -int registry_save_namespace(const registry_namespace_t *namespace); - -int registry_save_schema(const registry_schema_t *schema); - -int registry_save_instance(const registry_instance_t *instance); - -int registry_save_group(const registry_instance_t *instance, const registry_group_t *group); - -int registry_save_parameter(const registry_instance_t *instance, - const registry_parameter_t *parameter); +int registry_save(const registry_node_t *node); /** * @brief Registers a new storage as a source of configurations. Multiple diff --git a/sys/registry/storage/storage.c b/sys/registry/storage/storage.c index 106dba4f910b..342ba81b150d 100644 --- a/sys/registry/storage/storage.c +++ b/sys/registry/storage/storage.c @@ -37,11 +37,13 @@ XFA_INIT_CONST(registry_storage_instance_t *, _registry_storage_instances_src_xfa); /* registry_load */ -static int _registry_load_cb(const registry_instance_t *instance, - const registry_parameter_t *parameter, - const void *buf, const size_t buf_len) +static int _registry_load_cb(const registry_node_t *node, const void *buf, const size_t buf_len) { - return registry_set(instance, parameter, buf, buf_len); + assert(node->type == REGISTRY_NODE_PARAMETER); + assert(node->location.parameter != NULL); + assert(node->instance != NULL); + + return registry_set(node, buf, buf_len); } int registry_load(void) @@ -61,14 +63,12 @@ int registry_load(void) } /* registry_save */ -static int _registry_save_export_cb(const registry_export_cb_data_t *data, - const registry_export_cb_data_type_t data_type, - const void *context) +static int _registry_save_export_cb(const registry_node_t *node, const void *context) { (void)context; /* the registry also exports just the namespace or just a schema, but the storage is only interested in configuration parameter values */ - if (data_type != REGISTRY_EXPORT_PARAMETER) { + if (node->type != REGISTRY_NODE_PARAMETER) { return 0; } @@ -79,122 +79,14 @@ static int _registry_save_export_cb(const registry_export_cb_data_t *data, /* get value of configuration parameter */ registry_value_t value; - registry_get(data->parameter.instance, data->parameter.data, &value); + registry_get(node, &value); /* save parameter value via the save function of the registered destination storage */ return _registry_storage_instance_dst->storage->save(_registry_storage_instance_dst, - data->parameter.instance, - data->parameter.data, - &value); -} - -int registry_save(void) -{ - int res; - - if (!_registry_storage_instance_dst) { - return -REGISTRY_ERROR_NO_DST_STORAGE; - } - - if (_registry_storage_instance_dst->storage->save_start) { - _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); - } - - res = registry_export(_registry_save_export_cb, 0, NULL); - - if (_registry_storage_instance_dst->storage->save_end) { - _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); - } - - return res; -} - -int registry_save_namespace(const registry_namespace_t *namespace) -{ - int res; - - if (!_registry_storage_instance_dst) { - return -REGISTRY_ERROR_NO_DST_STORAGE; - } - - if (_registry_storage_instance_dst->storage->save_start) { - _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); - } - - res = registry_export_namespace(namespace, _registry_save_export_cb, 0, NULL); - - if (_registry_storage_instance_dst->storage->save_end) { - _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); - } - - return res; -} - -int registry_save_schema(const registry_schema_t *schema) -{ - int res; - - if (!_registry_storage_instance_dst) { - return -REGISTRY_ERROR_NO_DST_STORAGE; - } - - if (_registry_storage_instance_dst->storage->save_start) { - _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); - } - - res = registry_export_schema(schema, _registry_save_export_cb, 0, NULL); - - if (_registry_storage_instance_dst->storage->save_end) { - _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); - } - - return res; -} - -int registry_save_instance(const registry_instance_t *instance) -{ - int res; - - if (!_registry_storage_instance_dst) { - return -REGISTRY_ERROR_NO_DST_STORAGE; - } - - if (_registry_storage_instance_dst->storage->save_start) { - _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); - } - - res = registry_export_instance(instance, _registry_save_export_cb, 0, NULL); - - if (_registry_storage_instance_dst->storage->save_end) { - _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); - } - - return res; -} - -int registry_save_group(const registry_instance_t *instance, const registry_group_t *group) -{ - int res; - - if (!_registry_storage_instance_dst) { - return -REGISTRY_ERROR_NO_DST_STORAGE; - } - - if (_registry_storage_instance_dst->storage->save_start) { - _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); - } - - res = registry_export_group(instance, group, _registry_save_export_cb, 0, NULL); - - if (_registry_storage_instance_dst->storage->save_end) { - _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); - } - - return res; + node, &value); } -int registry_save_parameter(const registry_instance_t *instance, - const registry_parameter_t *parameter) +int registry_save(const registry_node_t *node) { int res; @@ -206,7 +98,7 @@ int registry_save_parameter(const registry_instance_t *instance, _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); } - res = registry_export_parameter(instance, parameter, _registry_save_export_cb, NULL); + res = registry_export(node, _registry_save_export_cb, 0, NULL); if (_registry_storage_instance_dst->storage->save_end) { _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); From 2f84e3860d321b550956ed8a63505123ac62e297 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:09:49 +0200 Subject: [PATCH 029/117] fixup! sys/registry/storage: add heap based storage Adjust heap storage module --- sys/registry/storage/storage_heap.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/sys/registry/storage/storage_heap.c b/sys/registry/storage/storage_heap.c index d46700d4839e..201c916f9e1d 100644 --- a/sys/registry/storage/storage_heap.c +++ b/sys/registry/storage/storage_heap.c @@ -38,15 +38,11 @@ static int load(const registry_storage_instance_t *storage, const load_cb_t load_cb); static int save(const registry_storage_instance_t *storage, - const registry_instance_t *instance, - const registry_parameter_t *parameter, + const registry_node_t *node, const registry_value_t *value); typedef struct { - const registry_namespace_t *namespace; - const registry_schema_t *schema; - const registry_instance_t *instance; - const registry_parameter_t *parameter; + registry_node_t node; void *buf; size_t buf_len; } heap_storage_t; @@ -67,25 +63,25 @@ static int load(const registry_storage_instance_t *storage, (void)storage; for (size_t i = 0; i < heap_storage_len; i++) { - load_cb(heap_storage[i].instance, heap_storage[i].parameter, heap_storage[i].buf, - heap_storage[i].buf_len); + load_cb(&heap_storage[i].node, heap_storage[i].buf, heap_storage[i].buf_len); } return 0; } static int save(const registry_storage_instance_t *storage, - const registry_instance_t *instance, - const registry_parameter_t *parameter, + const registry_node_t *node, const registry_value_t *value) { + assert(node->type == REGISTRY_NODE_PARAMETER); + assert(node->location.parameter != NULL); + assert(node->instance != NULL); + (void)storage; /* Search value in storage */ for (size_t i = 0; i < heap_storage_len; i++) { - if (heap_storage[i].namespace == parameter->schema->namespace && - heap_storage[i].schema == parameter->schema && - heap_storage[i].instance == instance && - heap_storage[i].parameter == parameter) { + if (heap_storage[i].node.instance == node->instance && + heap_storage[i].node.location.parameter == node->location.parameter) { memcpy(heap_storage[i].buf, value->buf, value->buf_len); return 0; } @@ -93,10 +89,7 @@ static int save(const registry_storage_instance_t *storage, /* Value not found in storage => Append it at the end */ heap_storage[heap_storage_len] = (heap_storage_t) { - .namespace = parameter->schema->namespace, - .schema = parameter->schema, - .instance = instance, - .parameter = parameter, + .node = *node, .buf = malloc(value->buf_len), .buf_len = value->buf_len, }; From 587d504c493fd99c55b9114879ad31783eef8b48 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:10:39 +0200 Subject: [PATCH 030/117] fixup! sys/registry/storage: add vfs based storage Adjust vfs storage module --- sys/registry/storage/storage_vfs.c | 49 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/sys/registry/storage/storage_vfs.c b/sys/registry/storage/storage_vfs.c index ea9a12d320fa..beac285bb5b0 100644 --- a/sys/registry/storage/storage_vfs.c +++ b/sys/registry/storage/storage_vfs.c @@ -38,8 +38,7 @@ static int load(const registry_storage_instance_t *storage, const load_cb_t load_cb); static int save(const registry_storage_instance_t *storage, - const registry_instance_t *instance, - const registry_parameter_t *parameter, + const registry_node_t *node, const registry_value_t *value); registry_storage_t registry_storage_vfs = { @@ -186,7 +185,7 @@ static int load(const registry_storage_instance_t *storage, fd); } - /* convert string path to registry int path (remove mount point and first '/' character) */ + /* convert string path of integers to native registry int path format (remove mount point and first '/' character) */ char *ptr = (char *)string_path + mount->mount_point_len + 1; registry_namespace_id_t namespace_id = strtol(ptr, &ptr, 10); ptr++; @@ -196,21 +195,23 @@ static int load(const registry_storage_instance_t *storage, ptr++; registry_parameter_id_t parameter_id = strtol(ptr, &ptr, 10); - const registry_parameter_int_path_t parameter_path = { - .namespace_id = namespace_id, - .schema_id = schema_id, - .instance_id = instance_id, - .parameter_id = parameter_id, + const registry_int_path_t int_path = { + .type = REGISTRY_INT_PATH_TYPE_PARAMETER, + .value.parameter_path = { + .namespace_id = namespace_id, + .schema_id = schema_id, + .instance_id = instance_id, + .parameter_id = parameter_id, + } }; /* get pointer to registry internal configuration parameter */ - registry_instance_t *instance; - registry_parameter_t *parameter; - registry_from_parameter_int_path(¶meter_path, NULL, NULL, - &instance, ¶meter); + registry_node_t node; + registry_node_from_int_path(&int_path, &node); + /* get value from registry to know its size (buf_len) */ registry_value_t value; - registry_get(instance, parameter, &value); + registry_get(&node, &value); /* read value from file */ uint8_t new_value_buf[value.buf_len]; @@ -220,7 +221,7 @@ static int load(const registry_storage_instance_t *storage, } else { /* call callback with value and path */ - load_cb(instance, parameter, new_value_buf, value.buf_len); + load_cb(&node, new_value_buf, value.buf_len); } /* close file */ @@ -274,37 +275,41 @@ static int load(const registry_storage_instance_t *storage, } static int save(const registry_storage_instance_t *storage, - const registry_instance_t *instance, - const registry_parameter_t *parameter, + const registry_node_t *node, const registry_value_t *value) { + assert(node->type == REGISTRY_NODE_PARAMETER); + assert(node->location.parameter != NULL); + assert(node->instance != NULL); + vfs_mount_t *mount = storage->data; /* mount */ _mount(mount); /* create dir path */ - registry_parameter_int_path_t path = registry_to_parameter_int_path(instance, parameter); + registry_int_path_t path; + int res = registry_node_to_int_path(node, &path); char string_path[REGISTRY_INT_PATH_STRING_MAX_LEN]; sprintf(string_path, "%s", mount->mount_point); - _string_path_append_item(string_path, path.namespace_id); - int res = vfs_mkdir(string_path, 0); + _string_path_append_item(string_path, path.value.parameter_path.namespace_id); + res = vfs_mkdir(string_path, 0); if (res < 0 && res != -EEXIST) { DEBUG("[registry storage_vfs] save: Can not make dir: %s\n", string_path); } - _string_path_append_item(string_path, path.schema_id); + _string_path_append_item(string_path, path.value.parameter_path.schema_id); res = vfs_mkdir(string_path, 0); if (res < 0 && res != -EEXIST) { DEBUG("[registry storage_vfs] save: Can not make dir: %s\n", string_path); } - _string_path_append_item(string_path, path.instance_id); + _string_path_append_item(string_path, path.value.parameter_path.instance_id); res = vfs_mkdir(string_path, 0); if (res < 0 && res != -EEXIST) { @@ -312,7 +317,7 @@ static int save(const registry_storage_instance_t *storage, } /* open file */ - _string_path_append_item(string_path, path.parameter_id); + _string_path_append_item(string_path, path.value.parameter_path.parameter_id); int fd = vfs_open(string_path, O_CREAT | O_RDWR, 0); From ba1d4c4746f41e4c00ad6d02371c580d949cb12d Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:11:21 +0200 Subject: [PATCH 031/117] fixup! sys/registry: add int_path module Simplify int_path API --- sys/include/registry/int_path.h | 149 ++----------- sys/registry/int_path.c | 369 +++++++++++++------------------- 2 files changed, 160 insertions(+), 358 deletions(-) diff --git a/sys/include/registry/int_path.h b/sys/include/registry/int_path.h index 2ff887181373..6507d7f63665 100644 --- a/sys/include/registry/int_path.h +++ b/sys/include/registry/int_path.h @@ -106,157 +106,42 @@ typedef enum { REGISTRY_INT_PATH_TYPE_GROUP, /**< The path represents a group. */ REGISTRY_INT_PATH_TYPE_PARAMETER, /**< The path represents a parameter. */ REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER, /**< The path represents a group or parameter. */ -}registry_int_path_type_t; +} registry_int_path_type_t; /** * @brief Union of the different types of integer paths. */ -typedef union { - registry_namespace_int_path_t namespace_path; /**< The path represents a namespace. */ - registry_schema_int_path_t schema_path; /**< The path represents a schema. */ - registry_instance_int_path_t instance_path; /**< The path represents an instance. */ - registry_group_int_path_t group_path; /**< The path represents a group. */ - registry_parameter_int_path_t parameter_path; /**< The path represents a parameter. */ - registry_group_or_parameter_int_path_t group_or_parameter_path; /**< The path represents a group or parameter. */ +typedef struct { + registry_int_path_type_t type; + union { + registry_namespace_int_path_t namespace_path; /**< The path represents a namespace. */ + registry_schema_int_path_t schema_path; /**< The path represents a schema. */ + registry_instance_int_path_t instance_path; /**< The path represents an instance. */ + registry_group_int_path_t group_path; /**< The path represents a group. */ + registry_parameter_int_path_t parameter_path; /**< The path represents a parameter. */ + registry_group_or_parameter_int_path_t group_or_parameter_path; /**< The path represents a group or parameter. */ + } value; } registry_int_path_t; /** * @brief Converts a registry namespace to an integer path. * - * @param[in] namespace The registry namespace to convert. - * - * @return The integer path representation of the namespace. - */ -registry_namespace_int_path_t registry_to_namespace_int_path(const registry_namespace_t *namespace); - -/** - * @brief Converts a registry schema to an integer path. - * - * @param[in] schema The registry schema to convert. - * - * @return The integer path representation of the schema. - */ -registry_schema_int_path_t registry_to_schema_int_path(const registry_schema_t *schema); - -/** - * @brief Converts a registry instance to an integer path. - * - * @param[in] instance The registry instance to convert. - * - * @return The integer path representation of the instance. - */ -registry_instance_int_path_t registry_to_instance_int_path(const registry_instance_t *instance); - -/** - * @brief Converts a registry group to an integer path. - * - * @param[in] instance The registry instance that the group belongs to. - * @param[in] group The registry group to convert. - * - * @return The integer path representation of the group. - */ -registry_group_int_path_t registry_to_group_int_path(const registry_instance_t *instance, - const registry_group_t *group); - -/** - * @brief Converts a registry parameter to an integer path. - * - * @param[in] instance The registry instance that the parameter belongs to. - * @param[in] parameter The registry parameter to convert. - * - * @return The integer path representation of the parameter. - */ -registry_parameter_int_path_t registry_to_parameter_int_path(const registry_instance_t *instance, - const registry_parameter_t *parameter); - -/** - * @brief Converts an integer path to a registry namespace. - * - * @param[in] path The integer path to convert. - * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. + * @param[in] node A location within the registry configuration tree. + * @param[out] path The integer path. * * @return 0 on success, non-zero on failure. */ -int registry_from_namespace_int_path(const registry_namespace_int_path_t *path, - registry_namespace_t **namespace); +int registry_node_to_int_path(const registry_node_t *node, registry_int_path_t *path); /** - * @brief Converts an integer path to a registry schema. - * - * @param[in] path The integer path to convert. - * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. - * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. - * - * @return 0 on success, non-zero on failure. - */ -int registry_from_schema_int_path(const registry_schema_int_path_t *path, - registry_namespace_t **namespace, registry_schema_t **schema); - -/** - * @brief Converts an integer path to a registry instance. - * - * @param[in] path The integer path to convert. - * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. - * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. - * @param[out] instance A pointer to the registry instance that will be set to the result of the conversion. - * - * @return 0 on success, non-zero on failure. - */ -int registry_from_instance_int_path(const registry_instance_int_path_t *path, - registry_namespace_t **namespace, registry_schema_t **schema, - registry_instance_t **instance); - -/** - * @brief Converts an integer path to a registry group. - * - * @param[in] path The integer path to convert. - * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. - * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. - * @param[out] instance A pointer to the registry instance that will be set to the result of the conversion. - * @param[out] group A pointer to the registry group that will be set to the result of the conversion. - * - * @return 0 on success, non-zero on failure. - */ -int registry_from_group_int_path(const registry_group_int_path_t *path, - registry_namespace_t **namespace, registry_schema_t **schema, - registry_instance_t **instance, registry_group_t **group); - -/** - * @brief Converts an integer path to a registry parameter. - * - * @param[in] path The integer path to convert. - * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. - * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. - * @param[out] instance A pointer to the registry instance that will be set to the result of the conversion. - * @param[out] parameter A pointer to the registry parameter that will be set to the result of the conversion. - * - * @return 0 on success, non-zero on failure. - */ -int registry_from_parameter_int_path(const registry_parameter_int_path_t *path, - registry_namespace_t **namespace, registry_schema_t **schema, - registry_instance_t **instance, - registry_parameter_t **parameter); - -/** - * @brief Converts an integer path to either a registry group or a registry parameter. + * @brief Converts an integer path to a registry namespace. * * @param[in] path The integer path to convert. - * @param[out] path_type A pointer to the type of the integer path that was converted. - * @param[out] namespace A pointer to the registry namespace that will be set to the result of the conversion. - * @param[out] schema A pointer to the registry schema that will be set to the result of the conversion. - * @param[out] instance A pointer to the registry instance that will be set to the result of the conversion. - * @param[out] group A pointer to the registry group that will be set to the result of the conversion if the integer path represents a group. - * @param[out] parameter A pointer to the registry parameter that will be set to the result of the conversion if the integer path represents a parameter. + * @param[out] node A location within the registry configuration tree. * * @return 0 on success, non-zero on failure. */ -int registry_from_group_or_parameter_int_path(const registry_group_or_parameter_int_path_t *path, - registry_int_path_type_t *path_type, - registry_namespace_t **namespace, - registry_schema_t **schema, - registry_instance_t **instance, - registry_group_t **group, - registry_parameter_t **parameter); +int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t *node); #ifdef __cplusplus } diff --git a/sys/registry/int_path.c b/sys/registry/int_path.c index 0d132300b256..8cf61548583e 100644 --- a/sys/registry/int_path.c +++ b/sys/registry/int_path.c @@ -52,13 +52,13 @@ static int _namespace_lookup(const registry_namespace_id_t namespace_id, static int _schema_lookup(const registry_namespace_t *namespace, const registry_schema_id_t schema_id, - registry_schema_t **schema) + const registry_schema_t **schema) { assert(schema != NULL); for (size_t i = 0; i < namespace->schemas_len; i++) { if (namespace->schemas[i]->id == schema_id) { - *schema = (registry_schema_t *)namespace->schemas[i]; + *schema = namespace->schemas[i]; return 0; } } @@ -111,19 +111,18 @@ static const registry_group_t *_internal_group_lookup(const registry_group_t *gr } static int _group_lookup(const registry_schema_t *schema, const registry_group_id_t group_id, - registry_group_t **group) + const registry_group_t **group) { assert(schema != NULL); assert(group != NULL); for (size_t i = 0; i < schema->groups_len; i++) { if (schema->groups[i]->id == group_id) { - *group = (registry_group_t *)schema->groups[i]; + *group = schema->groups[i]; return 0; } else if (schema->groups[i]->groups_len > 0) { - registry_group_t *found_group = (registry_group_t *)_internal_group_lookup( - schema->groups[i], group_id); + const registry_group_t *found_group = _internal_group_lookup(schema->groups[i], group_id); if (found_group != NULL) { *group = found_group; return 0; @@ -154,22 +153,20 @@ static const registry_parameter_t *_internal_parameter_lookup(const registry_gro static int _parameter_lookup(const registry_schema_t *schema, const registry_parameter_id_t parameter_id, - registry_parameter_t **parameter) + const registry_parameter_t **parameter) { assert(schema != NULL); assert(parameter != NULL); for (size_t i = 0; i < schema->parameters_len; i++) { if (schema->parameters[i]->id == parameter_id) { - *parameter = (registry_parameter_t *)schema->parameters[i]; + *parameter = schema->parameters[i]; return 0; } } for (size_t i = 0; i < schema->groups_len; i++) { - registry_parameter_t *found_parameter = (registry_parameter_t *)_internal_parameter_lookup( - schema->groups[i], - parameter_id); + const registry_parameter_t *found_parameter = _internal_parameter_lookup(schema->groups[i], parameter_id); if (found_parameter != NULL) { *parameter = found_parameter; return 0; @@ -179,245 +176,165 @@ static int _parameter_lookup(const registry_schema_t *schema, return -REGISTRY_ERROR_PARAMETER_NOT_FOUND; } -/* to int path */ -registry_namespace_int_path_t registry_to_namespace_int_path(const registry_namespace_t *namespace) -{ - assert(namespace != NULL); - - return (registry_namespace_int_path_t) { - .namespace_id = namespace->id, - }; -} - -registry_schema_int_path_t registry_to_schema_int_path(const registry_schema_t *schema) -{ - assert(schema != NULL); - - return (registry_schema_int_path_t) { - .namespace_id = schema->namespace->id, - .schema_id = schema->id, - }; -} - -registry_instance_int_path_t registry_to_instance_int_path(const registry_instance_t *instance) -{ - assert(instance != NULL); - - return (registry_instance_int_path_t) { - .namespace_id = instance->schema->namespace->id, - .schema_id = instance->schema->id, - .instance_id = instance->id, - }; -} - -registry_group_int_path_t registry_to_group_int_path(const registry_instance_t *instance, - const registry_group_t *group) -{ - assert(instance != NULL); - assert(group != NULL); - - return (registry_group_int_path_t) { - .namespace_id = instance->schema->namespace->id, - .schema_id = instance->schema->id, - .instance_id = instance->id, - .group_id = group->id, - }; -} - -registry_parameter_int_path_t registry_to_parameter_int_path(const registry_instance_t *instance, - const registry_parameter_t *parameter) -{ - assert(instance != NULL); - assert(parameter != NULL); - - return (registry_parameter_int_path_t) { - .namespace_id = instance->schema->namespace->id, - .schema_id = instance->schema->id, - .instance_id = instance->id, - .parameter_id = parameter->id, - }; -} - -/* from int path */ -int registry_from_namespace_int_path(const registry_namespace_int_path_t *path, - registry_namespace_t **namespace) +int registry_node_to_int_path(const registry_node_t *node, registry_int_path_t *path) { + assert(node != NULL); assert(path != NULL); - assert(namespace != NULL); - int res = _namespace_lookup(path->namespace_id, namespace); - - return res; -} - -int registry_from_schema_int_path(const registry_schema_int_path_t *path, - registry_namespace_t **namespace, registry_schema_t **schema) -{ - assert(path != NULL); - /* leaving namespace NULL is fine */ - assert(schema != NULL); - - registry_namespace_t *found_namespace; - int res = _namespace_lookup(path->namespace_id, &found_namespace); - if (namespace != NULL) { - *namespace = found_namespace; - } - - if (res == 0) { - res = _schema_lookup(found_namespace, path->schema_id, schema); + switch (node->type) + { + case REGISTRY_NODE_NAMESPACE: + path->type = REGISTRY_INT_PATH_TYPE_NAMESPACE; + path->value.namespace_path.namespace_id = node->location.namespace->id; + break; + + case REGISTRY_NODE_SCHEMA: + path->type = REGISTRY_INT_PATH_TYPE_SCHEMA; + path->value.schema_path.namespace_id = node->location.schema->namespace->id; + path->value.schema_path.schema_id = node->location.schema->id; + break; + + case REGISTRY_NODE_INSTANCE: + path->type = REGISTRY_INT_PATH_TYPE_INSTANCE; + path->value.instance_path.namespace_id = node->instance->schema->namespace->id; + path->value.instance_path.schema_id = node->instance->schema->id; + path->value.instance_path.instance_id = node->instance->id; + break; + + case REGISTRY_NODE_GROUP: + path->type = REGISTRY_INT_PATH_TYPE_GROUP; + path->value.group_path.namespace_id = node->location.group->schema->namespace->id; + path->value.group_path.schema_id = node->location.group->schema->id; + path->value.group_path.instance_id = node->instance->id; + path->value.group_path.group_id = node->location.group->id; + break; + + case REGISTRY_NODE_PARAMETER: + path->type = REGISTRY_INT_PATH_TYPE_PARAMETER; + path->value.parameter_path.namespace_id = node->location.parameter->schema->namespace->id; + path->value.parameter_path.schema_id = node->location.parameter->schema->id; + path->value.parameter_path.instance_id = node->instance->id; + path->value.parameter_path.parameter_id = node->location.parameter->id; + break; } - return res; + return 0; } -int registry_from_instance_int_path(const registry_instance_int_path_t *path, - registry_namespace_t **namespace, registry_schema_t **schema, - registry_instance_t **instance) +int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t *node) { assert(path != NULL); - /* leaving namespace or schema NULL is fine */ - assert(instance != NULL); - - registry_namespace_t *found_namespace; - int res = _namespace_lookup(path->namespace_id, &found_namespace); - if (namespace != NULL) { - *namespace = found_namespace; + assert(node != NULL); + + registry_namespace_id_t namespace_id = 0; + registry_schema_id_t schema_id = 0; + registry_instance_id_t instance_id = 0; + registry_group_or_parameter_id_t group_or_parameter_id = 0; + registry_parameter_id_t parameter_id = 0; + registry_group_id_t group_id = 0; + + switch (path->type) + { + case REGISTRY_INT_PATH_TYPE_NAMESPACE: + namespace_id = path->value.namespace_path.namespace_id; + break; + + case REGISTRY_INT_PATH_TYPE_SCHEMA: + namespace_id = path->value.schema_path.namespace_id; + schema_id = path->value.schema_path.schema_id; + break; + + case REGISTRY_INT_PATH_TYPE_INSTANCE: + namespace_id = path->value.instance_path.namespace_id; + schema_id = path->value.instance_path.schema_id; + instance_id = path->value.instance_path.instance_id; + break; + + case REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER: + namespace_id = path->value.group_or_parameter_path.namespace_id; + schema_id = path->value.group_or_parameter_path.schema_id; + instance_id = path->value.group_or_parameter_path.instance_id; + group_or_parameter_id = path->value.group_or_parameter_path.group_or_parameter_id; + break; + + case REGISTRY_INT_PATH_TYPE_GROUP: + namespace_id = path->value.group_path.namespace_id; + schema_id = path->value.group_path.schema_id; + instance_id = path->value.group_path.instance_id; + group_id = path->value.group_path.group_id; + break; + + case REGISTRY_INT_PATH_TYPE_PARAMETER: + namespace_id = path->value.parameter_path.namespace_id; + schema_id = path->value.parameter_path.schema_id; + instance_id = path->value.parameter_path.instance_id; + parameter_id = path->value.parameter_path.parameter_id; + break; } - if (res == 0) { - registry_schema_t *found_schema; - res = _schema_lookup(found_namespace, path->schema_id, &found_schema); - if (schema != NULL) { - *schema = found_schema; - } - - if (res == 0) { - res = _instance_lookup(found_schema, path->instance_id, instance); - } - } - - return res; -} - -int registry_from_group_int_path(const registry_group_int_path_t *path, - registry_namespace_t **namespace, registry_schema_t **schema, - registry_instance_t **instance, registry_group_t **group) -{ - assert(path != NULL); - /* leaving namespace, schema or instance NULL is fine */ - assert(group != NULL); - - registry_namespace_t *found_namespace; - int res = _namespace_lookup(path->namespace_id, &found_namespace); - if (namespace != NULL) { - *namespace = found_namespace; - } - - if (res == 0) { - registry_schema_t *found_schema; - res = _schema_lookup(found_namespace, path->schema_id, &found_schema); - if (schema != NULL) { - *schema = found_schema; - } - - if (res == 0) { - registry_instance_t *found_instance; - res = _instance_lookup(found_schema, path->instance_id, &found_instance); - if (instance != NULL) { - *instance = found_instance; - } - - if (res == 0) { - res = _group_lookup(found_schema, path->group_id, group); - } - } - } - - return res; -} - -int registry_from_parameter_int_path(const registry_parameter_int_path_t *path, - registry_namespace_t **namespace, registry_schema_t **schema, - registry_instance_t **instance, - registry_parameter_t **parameter) -{ - assert(path != NULL); - /* leaving namespace, schema or instance NULL is fine */ - assert(parameter != NULL); - - registry_namespace_t *found_namespace; - int res = _namespace_lookup(path->namespace_id, &found_namespace); - if (namespace != NULL) { - *namespace = found_namespace; - } + /* Namespace */ + registry_namespace_t *namespace; + int res = _namespace_lookup(namespace_id, &namespace); if (res == 0) { - registry_schema_t *found_schema; - res = _schema_lookup(found_namespace, path->schema_id, &found_schema); - if (schema != NULL) { - *schema = found_schema; + if (path->type == REGISTRY_INT_PATH_TYPE_NAMESPACE) { + node->type = REGISTRY_NODE_NAMESPACE; + node->location.namespace = namespace; + return res; } + + /* Schema */ + const registry_schema_t *schema; + res = _schema_lookup(namespace, schema_id, &schema); if (res == 0) { - registry_instance_t *found_instance; - res = _instance_lookup(found_schema, path->instance_id, &found_instance); - if (instance != NULL) { - *instance = found_instance; + if (path->type == REGISTRY_INT_PATH_TYPE_SCHEMA) { + node->type = REGISTRY_NODE_SCHEMA; + node->location.schema = schema; + return res; } + + /* Instance */ + registry_instance_t *instance; + res = _instance_lookup(schema, instance_id, &instance); if (res == 0) { - res = _parameter_lookup(found_schema, path->parameter_id, parameter); - } - } - } - - return res; -} - -int registry_from_group_or_parameter_int_path(const registry_group_or_parameter_int_path_t *path, - registry_int_path_type_t *path_type, - registry_namespace_t **namespace, - registry_schema_t **schema, - registry_instance_t **instance, - registry_group_t **group, - registry_parameter_t **parameter) -{ - assert(path != NULL); - /* leaving namespace, schema or instance NULL is fine */ - assert(group != NULL); - assert(parameter != NULL); - - registry_namespace_t *found_namespace; - int res = _namespace_lookup(path->namespace_id, &found_namespace); - if (namespace != NULL) { - *namespace = found_namespace; - } - - if (res == 0) { - registry_schema_t *found_schema; - res = _schema_lookup(found_namespace, path->schema_id, &found_schema); - if (schema != NULL) { - *schema = found_schema; - } + if (path->type == REGISTRY_INT_PATH_TYPE_INSTANCE) { + node->type = REGISTRY_NODE_INSTANCE; + node->instance = instance; + return res; + } - if (res == 0) { - registry_instance_t *found_instance; - res = _instance_lookup(found_schema, path->instance_id, &found_instance); - if (instance != NULL) { - *instance = found_instance; - } + /* Group or Parameter */ + if (path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { + node->instance = instance; - if (res == 0) { - res = _parameter_lookup(found_schema, path->group_or_parameter_id, parameter); - if (res == 0) { - *path_type = REGISTRY_INT_PATH_TYPE_PARAMETER; - } - else { - res = _group_lookup(found_schema, path->group_or_parameter_id, group); + res = _group_lookup(schema, group_or_parameter_id, &node->location.group); + if (res == 0) { + node->type = REGISTRY_NODE_GROUP; + return res; + } + + res = _parameter_lookup(schema, group_or_parameter_id, &node->location.parameter); if (res == 0) { - *path_type = REGISTRY_INT_PATH_TYPE_GROUP; + node->type = REGISTRY_NODE_PARAMETER; + return res; } } + + /* Group */ + if (path->type == REGISTRY_INT_PATH_TYPE_GROUP) { + node->type = REGISTRY_NODE_GROUP; + node->instance = instance; + return _group_lookup(schema, group_id, &node->location.group); + } + + /* Parameter */ + if (path->type == REGISTRY_INT_PATH_TYPE_PARAMETER) { + node->type = REGISTRY_NODE_PARAMETER; + node->instance = instance; + return _parameter_lookup(schema, parameter_id, &node->location.parameter); + } } } } From a70d7259565cef1c86e0453812d06885f6054e7f Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:11:53 +0200 Subject: [PATCH 032/117] fixup! sys/registry: add string_path module Simplify string_path API --- sys/include/registry/string_path.h | 141 +------- sys/registry/string_path.c | 533 ++++++----------------------- 2 files changed, 114 insertions(+), 560 deletions(-) diff --git a/sys/include/registry/string_path.h b/sys/include/registry/string_path.h index 907a2e48142d..34f4061a9313 100644 --- a/sys/include/registry/string_path.h +++ b/sys/include/registry/string_path.h @@ -24,156 +24,29 @@ extern "C" { #endif -typedef enum { - REGISTRY_STRING_PATH_TYPE_NAMESPACE, - REGISTRY_STRING_PATH_TYPE_SCHEMA, - REGISTRY_STRING_PATH_TYPE_INSTANCE, - REGISTRY_STRING_PATH_TYPE_GROUP, - REGISTRY_STRING_PATH_TYPE_PARAMETER, - REGISTRY_STRING_PATH_TYPE_GROUP_OR_PARAMETER, -}registry_string_path_type_t; - #include "registry.h" /** * @brief Converts a registry namespace object to its string path representation. * - * @param[in] namespace The registry namespace object to convert. - * @param[out] path The buffer to store the resulting string path. - * - * @return Length of string path on success, non-zero on failure. - */ -int registry_to_namespace_string_path(const registry_namespace_t *namespace, char *path); - -/** - * @brief Converts a registry schema object to its string path representation. - * - * @param[in] schema The registry schema object to convert. - * @param[out] path The buffer to store the resulting string path. - * - * @return Length of string path on success, non-zero on failure. - */ -int registry_to_schema_string_path(const registry_schema_t *schema, char *path); - -/** - * @brief Converts a registry instance object to its string path representation. - * - * @param[in] instance The registry instance object to convert. + * @param[in] node A location within the registry configuration tree. * @param[out] path The buffer to store the resulting string path. + * @param[out] path_len Length of the path. * * @return Length of string path on success, non-zero on failure. */ -int registry_to_instance_string_path(const registry_instance_t *instance, char *path); - -/** - * @brief Converts a registry group object to its string path representation. - * - * @param[in] instance The registry instance object to which the group belongs. - * @param[in] group The registry group object to convert. - * @param[out] path The buffer to store the resulting string path. - * - * @return Length of string path on success, non-zero on failure. - */ -int registry_to_group_string_path(const registry_instance_t *instance, - const registry_group_t *group, char *path); - -/** - * @brief Converts a registry parameter object to its string path representation. - * - * @param[in] instance The registry instance object to which the parameter belongs. - * @param[in] parameter The registry parameter object to convert. - * @param[out] path The buffer to store the resulting string path. - * - * @return Length of string path on success, non-zero on failure. - */ -int registry_to_parameter_string_path(const registry_instance_t *instance, - const registry_parameter_t *parameter, char *path); +int registry_node_to_string_path(const registry_node_t *node, char *path); /** * @brief Converts a string path to a registry namespace object. * - * @param[in] path The string path to convert. - * @param[out] namespace A pointer to the registry namespace object to be created. - * - * @return 0 on success, non-zero on failure. - */ -int registry_from_namespace_string_path(const char *path, registry_namespace_t **namespace); - -/** - * @brief Converts a string path to a registry schema object. - * - * @param[in] path The string path to convert. - * @param[out] namespace A pointer to the registry namespace object to be created. - * @param[out] schema A pointer to the registry schema object to be created. - * - * @return 0 on success, non-zero on failure. - */ -int registry_from_schema_string_path(const char *path, registry_namespace_t **namespace, - registry_schema_t **schema); - -/** - * @brief Converts a string path to a registry instance object. - * - * @param[in] path The string path to convert. - * @param[out] namespace A pointer to the registry namespace object to be created. - * @param[out] schema A pointer to the registry schema object to be created. - * @param[out] instance A pointer to the registry instance object to be created. - * - * @return 0 on success, non-zero on failure. - */ -int registry_from_instance_string_path(const char *path, registry_namespace_t **namespace, - registry_schema_t **schema, registry_instance_t **instance); - -/** - * @brief Converts a string path to a registry group object. - * - * @param[in] path The string path to convert. - * @param[out] namespace A pointer to the registry namespace object to be created. - * @param[out] schema A pointer to the registry schema object to be created. - * @param[out] instance A pointer to the registry instance object to which the group belongs. - * @param[out] group A pointer to the registry group object to be created. - * - * @return 0 on success, non-zero on failure. - */ -int registry_from_group_string_path(const char *path, registry_namespace_t **namespace, - registry_schema_t **schema, registry_instance_t **instance, - registry_group_t **group); - -/** - * @brief Converts a string path to a registry parameter object. - * - * @param[in] path The string path to convert. - * @param[out] namespace A pointer to the registry namespace object to be created. - * @param[out] schema A pointer to the registry schema object to be created. - * @param[out] instance A pointer to the registry instance object to which the parameter belongs. - * @param[out] parameter A pointer to the registry parameter object to be created. - * - * @return 0 on success, non-zero on failure. - */ -int registry_from_parameter_string_path(const char *path, registry_namespace_t **namespace, - registry_schema_t **schema, registry_instance_t **instance, - registry_parameter_t **parameter); - -/** - * @brief Converts a string path to either a registry group or a registry parameter object. - * - * @param[in] path The string path to convert. - * @param[out] path_type A pointer to the type of the resulting object. - * @param[out] namespace A pointer to the registry namespace object to be created. - * @param[out] schema A pointer to the registry schema object to be created. - * @param[out] instance A pointer to the registry instance object to which the group or parameter belongs. - * @param[out] group A pointer to the registry group object to be created. - * @param[out] parameter A pointer to the registry parameter object to be created. + * @param[in] path The string path to convert. + * @param[in] path_len Length of the path. + * @param[out] node A location within the registry configuration tree. * * @return 0 on success, non-zero on failure. */ -int registry_from_group_or_parameter_string_path(const char *path, - registry_string_path_type_t *path_type, - registry_namespace_t **namespace, - registry_schema_t **schema, - registry_instance_t **instance, - registry_group_t **group, - registry_parameter_t **parameter); +int registry_node_from_string_path(const char *path, const size_t path_len, registry_node_t *node); #ifdef __cplusplus } diff --git a/sys/registry/string_path.c b/sys/registry/string_path.c index 4cff53f63a3b..fc21f7f8b463 100644 --- a/sys/registry/string_path.c +++ b/sys/registry/string_path.c @@ -38,7 +38,7 @@ XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); -static int _namespace_lookup(const char *path, registry_namespace_t **namespace) +static int _namespace_lookup(const char *path, const registry_namespace_t **namespace) { assert(path != NULL); assert(namespace != NULL); @@ -68,7 +68,7 @@ static int _namespace_lookup(const char *path, registry_namespace_t **namespace) } static int _schema_lookup(const char *path, const registry_namespace_t *namespace, - registry_schema_t **schema) + const registry_schema_t **schema) { assert(path != NULL); assert(namespace != NULL); @@ -98,8 +98,8 @@ static int _schema_lookup(const char *path, const registry_namespace_t *namespac return -EINVAL; } -static int _instance_lookup(const char *path, registry_schema_t *schema, - registry_instance_t **instance) +static int _instance_lookup(const char *path, const registry_schema_t *schema, + const registry_instance_t **instance) { assert(path != NULL); assert(schema != NULL); @@ -138,63 +138,12 @@ static int _instance_lookup(const char *path, registry_schema_t *schema, return -EINVAL; } -static int _group_lookup(const char *path, registry_schema_t *schema, registry_group_t **group) +static int _group_or_parameter_lookup(const char *path, const registry_schema_t *schema, + registry_node_t *node) { assert(path != NULL); assert(schema != NULL); - assert(group != NULL); - - char *ptr = (char *)path; - - /* remove '/' character */ - ptr++; - - /* store the current path position */ - size_t path_position = 0; - - /* search for matching groups */ - bool found_subgroup = true; - registry_group_t **groups = (registry_group_t **)schema->groups; - size_t groups_len = schema->groups_len; - - while (found_subgroup) { - found_subgroup = false; - - for (size_t i = 0; i < groups_len; i++) { - const size_t name_length = strlen(groups[i]->name); - - /* path segment => save subgroups and keep searching them */ - if (strlen(ptr + path_position) >= name_length) { - if (*(ptr + path_position + name_length) == '/' && - strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { - if (groups[i]->groups_len > 0) { - found_subgroup = true; - groups = (registry_group_t **)groups[i]->groups; - groups_len = groups[i]->groups_len; - } - - path_position += name_length + 1; /* name_length + `/` character */ - break; - } - /* end of path => return group if it matches */ - else if (*(ptr + path_position + name_length) == '\0' && - strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { - *group = (registry_group_t *)groups[i]; - return path_position + name_length + 1; /* name_length + `/` character */ - } - } - } - } - - return -EINVAL; -} - -static int _parameter_lookup(const char *path, registry_schema_t *schema, - registry_parameter_t **parameter) -{ - assert(path != NULL); - assert(schema != NULL); - assert(parameter != NULL); + assert(node != NULL); char *ptr = (char *)path; @@ -206,15 +155,13 @@ static int _parameter_lookup(const char *path, registry_schema_t *schema, /* search for matching parameters or groups */ bool found_subgroup = true; - registry_parameter_t **parameters = (registry_parameter_t **)schema->parameters; + const registry_parameter_t **parameters = schema->parameters; size_t parameters_len = schema->parameters_len; - registry_group_t **groups = (registry_group_t **)schema->groups; + const registry_group_t **groups = schema->groups; size_t groups_len = schema->groups_len; while (found_subgroup) { - found_subgroup = false; - /* check for matching parameter */ for (size_t i = 0; i < parameters_len; i++) { const size_t name_length = strlen(parameters[i]->name); @@ -222,82 +169,8 @@ static int _parameter_lookup(const char *path, registry_schema_t *schema, /* parameter matches => return parameters */ if (strlen(ptr + path_position) == name_length && strncmp(ptr + path_position, parameters[i]->name, name_length) == 0) { - *parameter = (registry_parameter_t *)parameters[i]; - return path_position + name_length + 1; /* name_length + `/` character */ - } - } - - /* check for matching subgroup */ - for (size_t i = 0; i < groups_len; i++) { - const size_t name_length = strlen(groups[i]->name); - - /* group matches => save subgroups and parameters and keep searching them */ - if (strlen(ptr + path_position) > name_length && - *(ptr + path_position + name_length) == '/' && - strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { - if (groups[i]->parameters_len > 0) { - found_subgroup = true; - parameters = (registry_parameter_t **)groups[i]->parameters; - parameters_len = groups[i]->parameters_len; - } - else { - parameters = NULL; - parameters_len = 0; - } - - if (groups[i]->groups_len > 0) { - found_subgroup = true; - groups = (registry_group_t **)groups[i]->groups; - groups_len = groups[i]->groups_len; - } - else { - groups = NULL; - groups_len = 0; - } - - path_position += name_length + 1; /* name_length + `/` character */ - break; - } - } - } - - return -EINVAL; -} - -static int _group_or_parameter_lookup(const char *path, registry_schema_t *schema, - registry_string_path_type_t *path_type, - registry_group_t **group, registry_parameter_t **parameter) -{ - assert(path != NULL); - assert(schema != NULL); - assert(parameter != NULL); - - char *ptr = (char *)path; - - /* remove '/' character */ - ptr++; - - /* store the current path position */ - size_t path_position = 0; - - /* search for matching parameters or groups */ - bool found_subgroup = true; - registry_parameter_t **parameters = (registry_parameter_t **)schema->parameters; - size_t parameters_len = schema->parameters_len; - - registry_group_t **groups = (registry_group_t **)schema->groups; - size_t groups_len = schema->groups_len; - - while (found_subgroup) { - /* check for matching parameter */ - for (size_t i = 0; i < parameters_len; i++) { - const size_t name_length = strlen(parameters[i]->name); - - /* parameter matches => return parameters */ - if (strlen(ptr + path_position) == name_length && - strncmp(ptr + path_position, parameters[i]->name, name_length) == 0) { - *parameter = (registry_parameter_t *)parameters[i]; - *path_type = REGISTRY_STRING_PATH_TYPE_PARAMETER; + node->location.parameter = parameters[i]; + node->type = REGISTRY_NODE_PARAMETER; return path_position + name_length + 1; /* name_length + `/` character */ } } @@ -313,7 +186,7 @@ static int _group_or_parameter_lookup(const char *path, registry_schema_t *schem strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { if (groups[i]->parameters_len > 0) { found_subgroup = true; - parameters = (registry_parameter_t **)groups[i]->parameters; + parameters = groups[i]->parameters; parameters_len = groups[i]->parameters_len; } else { @@ -323,7 +196,7 @@ static int _group_or_parameter_lookup(const char *path, registry_schema_t *schem if (groups[i]->groups_len > 0) { found_subgroup = true; - groups = (registry_group_t **)groups[i]->groups; + groups = groups[i]->groups; groups_len = groups[i]->groups_len; } else { @@ -337,8 +210,8 @@ static int _group_or_parameter_lookup(const char *path, registry_schema_t *schem /* end of path => return group if it matches */ else if (*(ptr + path_position + name_length) == '\0' && strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { - *group = (registry_group_t *)groups[i]; - *path_type = REGISTRY_STRING_PATH_TYPE_GROUP; + node->location.group = groups[i]; + node->type = REGISTRY_NODE_GROUP; return path_position + name_length + 1; /* name_length + `/` character */ } } @@ -348,42 +221,6 @@ static int _group_or_parameter_lookup(const char *path, registry_schema_t *schem return -EINVAL; } -/* to string_path */ -int registry_to_namespace_string_path(const registry_namespace_t *namespace, char *path) -{ - int size = snprintf(NULL, 0, "/%s", namespace->name); - - if (path != NULL) { - return snprintf(path, size + 1, "/%s", namespace->name); - } - - return size; -} - -int registry_to_schema_string_path(const registry_schema_t *schema, char *path) -{ - int size = snprintf(NULL, 0, "/%s/%s", schema->namespace->name, schema->name); - - if (path != NULL) { - return snprintf(path, size + 1, "/%s/%s", schema->namespace->name, schema->name); - } - - return size; -} - -int registry_to_instance_string_path(const registry_instance_t *instance, char *path) -{ - int size = snprintf(NULL, 0, "/%s/%s/%s", instance->schema->namespace->name, - instance->schema->name, instance->name); - - if (path != NULL) { - return snprintf(path, size + 1, "/%s/%s/%s", instance->schema->namespace->name, - instance->schema->name, instance->name); - } - - return size; -} - static int _internal_registry_to_group_string_path(const registry_group_t *current_group, const registry_group_t *group, char *path) { @@ -408,28 +245,6 @@ static int _internal_registry_to_group_string_path(const registry_group_t *curre return -EINVAL; } -int registry_to_group_string_path(const registry_instance_t *instance, - const registry_group_t *group, char *path) -{ - int size = snprintf(NULL, 0, "/%s/%s/%s", instance->schema->namespace->name, - instance->schema->name, instance->name); - - if (path != NULL) { - snprintf(path, size + 1, "/%s/%s/%s", instance->schema->namespace->name, - instance->schema->name, instance->name); - } - - for (size_t i = 0; i < instance->schema->groups_len; i++) { - int res = _internal_registry_to_group_string_path(instance->schema->groups[i], group, - path != NULL ? path + size : NULL); - if (res >= 0) { - return size += res; - } - } - - return -EINVAL; -} - static int _internal_registry_to_parameter_string_path(const registry_group_t *current_group, const registry_parameter_t *parameter, char *path) @@ -465,277 +280,143 @@ static int _internal_registry_to_parameter_string_path(const registry_group_t *c return -EINVAL; } -int registry_to_parameter_string_path(const registry_instance_t *instance, - const registry_parameter_t *parameter, char *path) +int registry_node_to_string_path(const registry_node_t *node, char *path) { - int size = snprintf(NULL, 0, "/%s/%s/%s", instance->schema->namespace->name, - instance->schema->name, instance->name); - - if (path != NULL) { - snprintf(path, size + 1, "/%s/%s/%s", instance->schema->namespace->name, - instance->schema->name, instance->name); - } + assert(node != NULL); - /* check if the parameter is a child of this schema */ - for (size_t i = 0; i < instance->schema->parameters_len; i++) { - if (instance->schema->parameters[i] == parameter) { - int sub_size = snprintf(NULL, 0, "/%s", instance->schema->parameters[i]->name); + int size = 0; - if (path != NULL) { - snprintf(path + size, sub_size + 1, "/%s", instance->schema->parameters[i]->name); - } + switch (node->type) + { + case REGISTRY_NODE_NAMESPACE: + size = snprintf(NULL, 0, "/%s", node->location.namespace->name); - return size + sub_size; + if (path != NULL) { + return snprintf(path, size + 1, "/%s", node->location.namespace->name); } - } + break; + + case REGISTRY_NODE_SCHEMA: + size = snprintf(NULL, 0, "/%s/%s", node->location.schema->namespace->name, node->location.schema->name); - /* check if the parameter is the child of a group */ - for (size_t i = 0; i < instance->schema->groups_len; i++) { - int res = _internal_registry_to_parameter_string_path(instance->schema->groups[i], - parameter, - path != NULL ? path + size : NULL); - if (res >= 0) { - return size += res; + if (path != NULL) { + return snprintf(path, size + 1, "/%s/%s", node->location.schema->namespace->name, node->location.schema->name); } - } - - return -EINVAL; -} - -/* from string_path */ -int registry_from_namespace_string_path(const char *path, registry_namespace_t **namespace) -{ - /* namespace */ - int res = _namespace_lookup(path, namespace); - - if (res < 0) { - return res; - } - - return 0; -} - -int registry_from_schema_string_path(const char *path, registry_namespace_t **namespace, - registry_schema_t **schema) -{ - /* store the current path position */ - size_t path_position = 0; - - /* namespace */ - registry_namespace_t *found_namespace; - int res = _namespace_lookup(path, &found_namespace); - - if (res >= 0) { - path_position += res; - - if (namespace != NULL) { - *namespace = found_namespace; + break; + + case REGISTRY_NODE_INSTANCE: + size = snprintf(NULL, 0, "/%s/%s/%s", node->instance->schema->namespace->name, + node->instance->schema->name, node->instance->name); + + if (path != NULL) { + return snprintf(path, size + 1, "/%s/%s/%s", node->instance->schema->namespace->name, + node->instance->schema->name, node->instance->name); } - - /* schema */ - res = _schema_lookup(path + path_position, found_namespace, schema); - } - - if (res < 0) { - return res; - } - - return 0; -} - -int registry_from_instance_string_path(const char *path, registry_namespace_t **namespace, - registry_schema_t **schema, registry_instance_t **instance) -{ - /* store the current path position */ - size_t path_position = 0; - - /* namespace */ - registry_namespace_t *found_namespace; - int res = _namespace_lookup(path, &found_namespace); - - if (res >= 0) { - path_position += res; - - if (namespace != NULL) { - *namespace = found_namespace; + break; + + case REGISTRY_NODE_GROUP: + size = snprintf(NULL, 0, "/%s/%s/%s", node->instance->schema->namespace->name, + node->instance->schema->name, node->instance->name); + + if (path != NULL) { + snprintf(path, size + 1, "/%s/%s/%s", node->instance->schema->namespace->name, + node->instance->schema->name, node->instance->name); } - /* schema */ - registry_schema_t *found_schema; - res = _schema_lookup(path + path_position, found_namespace, &found_schema); - - if (res >= 0) { - path_position += res; - - if (schema != NULL) { - *schema = found_schema; + for (size_t i = 0; i < node->instance->schema->groups_len; i++) { + int res = _internal_registry_to_group_string_path(node->instance->schema->groups[i], node->location.group, + path != NULL ? path + size : NULL); + if (res >= 0) { + return size += res; } - - /* instance */ - res = _instance_lookup(path + path_position, found_schema, instance); } - } - - if (res < 0) { - return res; - } - return 0; -} + return -EINVAL; + break; + + case REGISTRY_NODE_PARAMETER: + size = snprintf(NULL, 0, "/%s/%s/%s", node->instance->schema->namespace->name, + node->instance->schema->name, node->instance->name); -int registry_from_group_string_path(const char *path, registry_namespace_t **namespace, - registry_schema_t **schema, registry_instance_t **instance, - registry_group_t **group) -{ - /* store the current path position */ - size_t path_position = 0; - - /* namespace */ - registry_namespace_t *found_namespace; - int res = _namespace_lookup(path, &found_namespace); - - if (res >= 0) { - path_position += res; - - if (namespace != NULL) { - *namespace = found_namespace; + if (path != NULL) { + snprintf(path, size + 1, "/%s/%s/%s", node->instance->schema->namespace->name, + node->instance->schema->name, node->instance->name); } - /* schema */ - registry_schema_t *found_schema; - res = _schema_lookup(path + path_position, found_namespace, &found_schema); - - if (res >= 0) { - path_position += res; - - if (schema != NULL) { - *schema = found_schema; - } - - /* instance */ - registry_instance_t *found_instance; - res = _instance_lookup(path + path_position, found_schema, &found_instance); - - if (res >= 0) { - path_position += res; + /* check if the parameter is a child of this schema */ + for (size_t i = 0; i < node->instance->schema->parameters_len; i++) { + if (node->instance->schema->parameters[i] == node->location.parameter) { + int sub_size = snprintf(NULL, 0, "/%s", node->instance->schema->parameters[i]->name); - if (instance != NULL) { - *instance = found_instance; + if (path != NULL) { + snprintf(path + size, sub_size + 1, "/%s", node->instance->schema->parameters[i]->name); } - /* group */ - res = _group_lookup(path + path_position, found_schema, group); + return size + sub_size; } } - } - - if (res < 0) { - return res; - } - - return 0; -} - -int registry_from_parameter_string_path(const char *path, registry_namespace_t **namespace, - registry_schema_t **schema, registry_instance_t **instance, - registry_parameter_t **parameter) -{ - /* store the current path position */ - size_t path_position = 0; - - /* namespace */ - registry_namespace_t *found_namespace; - int res = _namespace_lookup(path, &found_namespace); - - if (res >= 0) { - path_position += res; - - if (namespace != NULL) { - *namespace = found_namespace; - } - - /* schema */ - registry_schema_t *found_schema; - res = _schema_lookup(path + path_position, found_namespace, &found_schema); - - if (res >= 0) { - path_position += res; - - if (schema != NULL) { - *schema = found_schema; - } - - /* instance */ - registry_instance_t *found_instance; - res = _instance_lookup(path + path_position, found_schema, &found_instance); + /* check if the parameter is the child of a group */ + for (size_t i = 0; i < node->instance->schema->groups_len; i++) { + int res = _internal_registry_to_parameter_string_path(node->instance->schema->groups[i], + node->location.parameter, + path != NULL ? path + size : NULL); if (res >= 0) { - path_position += res; - - if (instance != NULL) { - *instance = found_instance; - } - - /* parameter */ - res = _parameter_lookup(path + path_position, found_schema, parameter); + return size += res; } } - } - if (res < 0) { - return res; + return -EINVAL; + break; } - return 0; + return size; } -int registry_from_group_or_parameter_string_path(const char *path, - registry_string_path_type_t *path_type, - registry_namespace_t **namespace, - registry_schema_t **schema, - registry_instance_t **instance, - registry_group_t **group, - registry_parameter_t **parameter) +int registry_node_from_string_path(const char *path, const size_t path_len, registry_node_t *node) { /* store the current path position */ size_t path_position = 0; /* namespace */ - registry_namespace_t *found_namespace; + const registry_namespace_t *found_namespace; int res = _namespace_lookup(path, &found_namespace); if (res >= 0) { - path_position += res; - - if (namespace != NULL) { - *namespace = found_namespace; - } + node->type = REGISTRY_NODE_NAMESPACE; + node->location.namespace = found_namespace; - /* schema */ - registry_schema_t *found_schema; - res = _schema_lookup(path + path_position, found_namespace, &found_schema); - - if (res >= 0) { - path_position += res; - - if (schema != NULL) { - *schema = found_schema; - } + path_position += res; - /* instance */ - registry_instance_t *found_instance; - res = _instance_lookup(path + path_position, found_schema, &found_instance); + if (path_position < path_len - 1) { + /* schema */ + const registry_schema_t *found_schema; + res = _schema_lookup(path + path_position, found_namespace, &found_schema); if (res >= 0) { + node->type = REGISTRY_NODE_SCHEMA; + node->location.schema = found_schema; + path_position += res; - if (instance != NULL) { - *instance = found_instance; + if (path_position < path_len - 1) { + /* instance */ + const registry_instance_t *found_instance; + res = _instance_lookup(path + path_position, found_schema, &found_instance); + + if (res >= 0) { + node->type = REGISTRY_NODE_INSTANCE; + node->location.schema = NULL; + node->instance = found_instance; + + path_position += res; + + if (path_position < path_len - 1) { + /* group or parameter */ + res = _group_or_parameter_lookup(path + path_position, found_schema, node); + } + } } - - /* group or parameter */ - res = _group_or_parameter_lookup(path + path_position, found_schema, path_type, - group, parameter); } } } From 49be2f90d58a45794585e879896733bb0e2f333d Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:12:45 +0200 Subject: [PATCH 033/117] fixup! examples: add registry_core example --- examples/registry_core/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/registry_core/main.c b/examples/registry_core/main.c index 4ceb1e114f21..7fc2bcfeb9cb 100644 --- a/examples/registry_core/main.c +++ b/examples/registry_core/main.c @@ -93,11 +93,18 @@ int main(void) /* Invert the BOARD LED, to make it turn on and off on each subsequent cycle */ board_led_enabled = !board_led_enabled; + /* Create registry_node_t for the board_led_parameter */ + const registry_node_t parameter_node = { + .type = REGISTRY_NODE_PARAMETER, + .instance = &board_led_instance, + .location.parameter = ®istry_sys_board_led_enabled, + }; + /* Set new registry value */ - registry_set(&board_led_instance, ®istry_sys_board_led_enabled, &board_led_enabled, sizeof(board_led_enabled)); + registry_set(¶meter_node, &board_led_enabled, sizeof(board_led_enabled)); /* Apply the registry value to change the LED state (calls the commit_cb function implemented by the BOARD for example)*/ - registry_commit_parameter(&board_led_instance, ®istry_sys_board_led_enabled); + registry_commit(¶meter_node); /* Sleep for 1 second and then do it again*/ ztimer_sleep(ZTIMER_MSEC, 1000); From 8b00112774704b1c2e01e6e372c87eae1285106a Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:13:20 +0200 Subject: [PATCH 034/117] fixup! sys/shell: add registry cli --- sys/shell/cmds/registry.c | 257 +++++++++----------------------------- 1 file changed, 58 insertions(+), 199 deletions(-) diff --git a/sys/shell/cmds/registry.c b/sys/shell/cmds/registry.c index 8070da1394f8..034adb3fdccc 100644 --- a/sys/shell/cmds/registry.c +++ b/sys/shell/cmds/registry.c @@ -40,8 +40,7 @@ #define REGISTRY_CLI_PATH_SEPARATOR '/' static int _parse_string_path(const char *string_path, - registry_int_path_t *registry_path, - registry_int_path_type_t *registry_path_type) + registry_int_path_t *registry_path) { char *ptr = (char *)string_path; @@ -53,10 +52,10 @@ static int _parse_string_path(const char *string_path, registry_namespace_id_t namespace_id = strtol(ptr, &ptr, 10); if (*ptr == '\0') { - registry_path->namespace_path = (registry_namespace_int_path_t) { + registry_path->type = REGISTRY_INT_PATH_TYPE_NAMESPACE; + registry_path->value.namespace_path = (registry_namespace_int_path_t) { .namespace_id = namespace_id, }; - *registry_path_type = REGISTRY_INT_PATH_TYPE_NAMESPACE; return 0; } @@ -65,11 +64,11 @@ static int _parse_string_path(const char *string_path, registry_schema_id_t schema_id = strtol(ptr, &ptr, 10); if (*ptr == '\0') { - registry_path->schema_path = (registry_schema_int_path_t) { + registry_path->type = REGISTRY_INT_PATH_TYPE_SCHEMA; + registry_path->value.schema_path = (registry_schema_int_path_t) { .namespace_id = namespace_id, .schema_id = schema_id, }; - *registry_path_type = REGISTRY_INT_PATH_TYPE_SCHEMA; return 0; } @@ -78,12 +77,12 @@ static int _parse_string_path(const char *string_path, registry_instance_id_t instance_id = strtol(ptr, &ptr, 10); if (*ptr == '\0') { - registry_path->instance_path = (registry_instance_int_path_t) { + registry_path->type = REGISTRY_INT_PATH_TYPE_INSTANCE; + registry_path->value.instance_path = (registry_instance_int_path_t) { .namespace_id = namespace_id, .schema_id = schema_id, .instance_id = instance_id, }; - *registry_path_type = REGISTRY_INT_PATH_TYPE_INSTANCE; return 0; } @@ -92,22 +91,20 @@ static int _parse_string_path(const char *string_path, registry_group_or_parameter_id_t group_or_parameter_id = strtol(ptr, &ptr, 10); if (*ptr == '\0') { - registry_path->group_or_parameter_path = (registry_group_or_parameter_int_path_t) { + registry_path->type = REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER; + registry_path->value.group_or_parameter_path = (registry_group_or_parameter_int_path_t) { .namespace_id = namespace_id, .schema_id = schema_id, .instance_id = instance_id, .group_or_parameter_id = group_or_parameter_id, }; - *registry_path_type = REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER; return 0; } return 0; } -static int _export_cb(const registry_export_cb_data_t *data, - const registry_export_cb_data_type_t data_type, - const void *context) +static int _export_cb(const registry_node_t *node, const void *context) { (void)context; @@ -116,46 +113,46 @@ static int _export_cb(const registry_export_cb_data_t *data, /* the more nesting we have, the more indentation we need. => highest nesting level first */ size_t indentation = 0; - switch (data_type) { - case REGISTRY_EXPORT_PARAMETER: - case REGISTRY_EXPORT_GROUP: + switch (node->type) { + case REGISTRY_NODE_PARAMETER: + case REGISTRY_NODE_GROUP: indentation++; __attribute__ ((fallthrough)); - case REGISTRY_EXPORT_INSTANCE: + case REGISTRY_NODE_INSTANCE: indentation++; __attribute__ ((fallthrough)); - case REGISTRY_EXPORT_SCHEMA: + case REGISTRY_NODE_SCHEMA: indentation++; __attribute__ ((fallthrough)); - case REGISTRY_EXPORT_NAMESPACE: + case REGISTRY_NODE_NAMESPACE: indentation++; } printf("%*c\b", ((indentation - 1) * 2) + 1, ' '); /* print the path element, that is currently being exported */ - switch (data_type) { - case REGISTRY_EXPORT_NAMESPACE: - printf("%d %s\n", data->namespace->id, data->namespace->name); + switch (node->type) { + case REGISTRY_NODE_NAMESPACE: + printf("%d %s\n", node->location.namespace->id, node->location.namespace->name); break; - case REGISTRY_EXPORT_SCHEMA: - printf("%d %s\n", data->schema->id, data->schema->name); + case REGISTRY_NODE_SCHEMA: + printf("%d %s\n", node->location.schema->id, node->location.schema->name); break; - case REGISTRY_EXPORT_INSTANCE: - printf("%d %s\n", data->instance->id, data->instance->name); + case REGISTRY_NODE_INSTANCE: + printf("%d %s\n", node->instance->id, node->instance->name); break; - case REGISTRY_EXPORT_GROUP: - printf("%d %s (group)\n", data->group->id, data->group->name); + case REGISTRY_NODE_GROUP: + printf("%d %s (group)\n", node->location.group->id, node->location.group->name); break; - case REGISTRY_EXPORT_PARAMETER: - printf("%d %s\n", data->parameter.data->id, data->parameter.data->name); + case REGISTRY_NODE_PARAMETER: + printf("%d %s\n", node->location.parameter->id, node->location.parameter->name); break; } @@ -165,12 +162,7 @@ static int _export_cb(const registry_export_cb_data_t *data, static int _registry(int argc, char **argv) { registry_int_path_t path; - registry_int_path_type_t path_type; - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_instance_t *instance; - registry_group_t *group; - registry_parameter_t *parameter; + registry_node_t node; registry_value_t value; if (argc == 1) { @@ -179,26 +171,24 @@ static int _registry(int argc, char **argv) } if (strcmp(argv[1], "get") == 0) { - if (_parse_string_path(argv[2], &path, &path_type) < 0) { + if (_parse_string_path(argv[2], &path) < 0) { printf("usage: %s %s \n", argv[0], argv[1]); return 1; } - if (path_type != REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { + if (path.type != REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { return -EINVAL; } /* get instance and parameter of the path */ - int res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, - &path_type, NULL, NULL, &instance, - &group, ¶meter); + int res = registry_node_from_int_path(&path, &node); - if (path_type != REGISTRY_INT_PATH_TYPE_PARAMETER) { + if (node.type != REGISTRY_NODE_PARAMETER) { return -EINVAL; } if (res == 0) { - res = registry_get(instance, parameter, &value); + res = registry_get(&node, &value); if (res == 0) { /* get the length of the value as a string */ @@ -218,27 +208,25 @@ static int _registry(int argc, char **argv) return 1; } else if (strcmp(argv[1], "set") == 0) { - if (_parse_string_path(argv[2], &path, &path_type) < 0) { + if (_parse_string_path(argv[2], &path) < 0) { printf("usage: %s %s \n", argv[0], argv[1]); return 1; } - if (path_type != REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { + if (path.type != REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { return -EINVAL; } /* get instance and parameter of the path */ - int res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, - &path_type, NULL, NULL, &instance, - &group, ¶meter); + int res = registry_node_from_int_path(&path, &node); - if (path_type != REGISTRY_INT_PATH_TYPE_PARAMETER) { + if (node.type != REGISTRY_NODE_PARAMETER) { return -EINVAL; } if (res == 0) { /* get value from the registry, to know its correct type and size */ - res = registry_get(instance, parameter, &value); + res = registry_get(&node, &value); if (res == 0) { /* convert the string into the correct value type */ @@ -250,7 +238,7 @@ static int _registry(int argc, char **argv) value.buf = new_value_buf; /* set the new value in the registry */ - registry_set(instance, parameter, value.buf, value.buf_len); + registry_set(&node, value.buf, value.buf_len); return 0; } } @@ -259,61 +247,17 @@ static int _registry(int argc, char **argv) return 1; } else if (strcmp(argv[1], "commit") == 0) { - if (_parse_string_path(argv[2], &path, &path_type) < 0) { + if (_parse_string_path(argv[2], &path) < 0) { printf("usage: %s %s \n", argv[0], argv[1]); return 1; } - int res = 0; - - /* commit depending on the path type */ - switch (path_type) { - case REGISTRY_INT_PATH_TYPE_NAMESPACE: - res = registry_from_namespace_int_path(&path.namespace_path, &namespace); - if (res == 0) { - res = registry_commit_namespace(namespace); - } - break; - - case REGISTRY_INT_PATH_TYPE_SCHEMA: - res = registry_from_schema_int_path(&path.schema_path, &namespace, &schema); - if (res == 0) { - res = registry_commit_schema(schema); - } - break; - - case REGISTRY_INT_PATH_TYPE_INSTANCE: - res = registry_from_instance_int_path(&path.instance_path, &namespace, &schema, - &instance); - if (res == 0) { - res = registry_commit_instance(instance); - } - break; - - case REGISTRY_INT_PATH_TYPE_GROUP: - /* should not happen as we don't yet know if it is a group or a parameter */ - break; - - case REGISTRY_INT_PATH_TYPE_PARAMETER: - /* should not happen as we don't yet know if it is a group or a parameter */ - break; + int res = registry_node_from_int_path(&path, &node); - case REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER: - res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, - &path_type, - &namespace, &schema, &instance, - &group, ¶meter); - if (res == 0) { - if (path_type == REGISTRY_INT_PATH_TYPE_GROUP) { - res = registry_commit_group(instance, group); - } - else if (path_type == REGISTRY_INT_PATH_TYPE_PARAMETER) { - res = registry_commit_parameter(instance, parameter); - } - } - break; + if (res == 0) { + res = registry_commit(&node); } - + if (res != 0) { printf("error: %d\n", res); return 1; @@ -324,70 +268,27 @@ static int _registry(int argc, char **argv) else if (strcmp(argv[1], "export") == 0) { /* if the path is invalid, it can also just be non existent, so other arguments like -r need to be checked */ bool invalid_path = false; - if (_parse_string_path(argv[2], &path, &path_type) < 0) { + if (_parse_string_path(argv[2], &path) < 0) { invalid_path = true; } if (invalid_path && strcmp(argv[2], "-r") != 0) { - printf("usage: %s %s [-r ]\n", argv[0], argv[1]); + printf("usage: %s %s [-r ]\n", argv[0], argv[1]); return 1; } /* the argv index of -r varies depending on if a path was specified or not */ - int recursion_level = 0; + int tree_traversal_level = 0; if (invalid_path && argc > 3 && strcmp(argv[2], "-r") == 0) { - recursion_level = atoi(argv[3]); + tree_traversal_level = atoi(argv[3]); } else if (argc > 4 && strcmp(argv[3], "-r") == 0) { - recursion_level = atoi(argv[4]); + tree_traversal_level = atoi(argv[4]); } - int res = 0; - - switch (path_type) { - case REGISTRY_INT_PATH_TYPE_NAMESPACE: - res = registry_from_namespace_int_path(&path.namespace_path, &namespace); - if (res == 0) { - res = registry_export_namespace(namespace, _export_cb, recursion_level, NULL); - } - break; - - case REGISTRY_INT_PATH_TYPE_SCHEMA: - res = registry_from_schema_int_path(&path.schema_path, &namespace, &schema); - if (res == 0) { - res = registry_export_schema(schema, _export_cb, recursion_level, NULL); - } - break; - - case REGISTRY_INT_PATH_TYPE_INSTANCE: - res = registry_from_instance_int_path(&path.instance_path, &namespace, &schema, - &instance); - if (res == 0) { - res = registry_export_instance(instance, _export_cb, recursion_level, NULL); - } - break; - - case REGISTRY_INT_PATH_TYPE_GROUP: - /* should not happen as we don't yet know if it is a group or a parameter */ - break; - - case REGISTRY_INT_PATH_TYPE_PARAMETER: - /* should not happen as we don't yet know if it is a group or a parameter */ - break; + int res = registry_node_from_int_path(&path, &node); - case REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER: - res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, - &path_type, - &namespace, &schema, &instance, - &group, ¶meter); - if (res == 0) { - if (path_type == REGISTRY_INT_PATH_TYPE_GROUP) { - res = registry_export_group(instance, group, _export_cb, recursion_level, NULL); - } - else if (path_type == REGISTRY_INT_PATH_TYPE_PARAMETER) { - res = registry_export_parameter(instance, parameter, _export_cb, NULL); - } - } - break; + if (res == 0) { + res = registry_export(&node, _export_cb, tree_traversal_level, NULL); } if (res != 0) { @@ -412,61 +313,19 @@ static int _registry(int argc, char **argv) int res = 0; if (argc > 2) { - if (_parse_string_path(argv[2], &path, &path_type) < 0) { + if (_parse_string_path(argv[2], &path) < 0) { printf("usage: %s %s [path]\n", argv[0], argv[1]); return 1; } - /* commit depending on the path type */ - switch (path_type) { - case REGISTRY_INT_PATH_TYPE_NAMESPACE: - res = registry_from_namespace_int_path(&path.namespace_path, &namespace); - if (res == 0) { - res = registry_save_namespace(namespace); - } - break; - - case REGISTRY_INT_PATH_TYPE_SCHEMA: - res = registry_from_schema_int_path(&path.schema_path, &namespace, &schema); - if (res == 0) { - res = registry_save_schema(schema); - } - break; - - case REGISTRY_INT_PATH_TYPE_INSTANCE: - res = registry_from_instance_int_path(&path.instance_path, &namespace, &schema, - &instance); - if (res == 0) { - res = registry_save_instance(instance); - } - break; - - case REGISTRY_INT_PATH_TYPE_GROUP: - /* should not happen as we don't yet know if it is a group or a parameter */ - break; - - case REGISTRY_INT_PATH_TYPE_PARAMETER: - /* should not happen as we don't yet know if it is a group or a parameter */ - break; - - case REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER: - res = registry_from_group_or_parameter_int_path(&path.group_or_parameter_path, - &path_type, - &namespace, &schema, &instance, - &group, ¶meter); - if (res == 0) { - if (path_type == REGISTRY_INT_PATH_TYPE_GROUP) { - res = registry_save_group(instance, group); - } - else if (path_type == REGISTRY_INT_PATH_TYPE_PARAMETER) { - res = registry_save_parameter(instance, parameter); - } - } - break; + res = registry_node_from_int_path(&path, &node); + if (res == 0) { + res = registry_save(&node); } } else { - res = registry_save(); + // save everything + res = registry_save(NULL); } if (res != 0) { From 938b2b848b11977db41c5f43a497cc8eed79c63f Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:14:56 +0200 Subject: [PATCH 035/117] fixup! tests/unittests: add registry tests --- tests/unittests/tests-registry/tests-commit.c | 50 +++- tests/unittests/tests-registry/tests-export.c | 141 ++++++----- .../unittests/tests-registry/tests-get-set.c | 222 +++++++++++------- 3 files changed, 257 insertions(+), 156 deletions(-) diff --git a/tests/unittests/tests-registry/tests-commit.c b/tests/unittests/tests-registry/tests-commit.c index e6c13ace0bd3..3405f0fb1aeb 100644 --- a/tests/unittests/tests-registry/tests-commit.c +++ b/tests/unittests/tests-registry/tests-commit.c @@ -128,8 +128,15 @@ static void tests_registry_commit_parameter(void) { successful = false; parameter_id = REGISTRY_TESTS_NESTED_PARAMETER; - registry_commit_parameter(&test_nested_instance_parameter_test, - ®istry_tests_nested_parameter); + + const registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .location.parameter = ®istry_tests_nested_parameter, + .instance = &test_nested_instance_parameter_test, + }; + + registry_commit(&node); + TEST_ASSERT(successful); } @@ -137,35 +144,64 @@ static void tests_registry_commit_group(void) { successful = false; group_id = REGISTRY_TESTS_NESTED_GROUP; - registry_commit_group(&test_nested_instance_group_test, ®istry_tests_nested_group); + + const registry_node_t node = { + .type = REGISTRY_NODE_GROUP, + .location.group = ®istry_tests_nested_group, + .instance = &test_nested_instance_group_test, + }; + + registry_commit(&node); + TEST_ASSERT(successful); } static void tests_registry_commit_instance(void) { successful = false; - registry_commit_instance(&test_nested_instance_instance_test); + + const registry_node_t node = { + .type = REGISTRY_NODE_INSTANCE, + .instance = &test_nested_instance_instance_test, + }; + + registry_commit(&node); + TEST_ASSERT(successful); } static void tests_registry_commit_schema(void) { successful = false; - registry_commit_schema(®istry_tests_nested); + + const registry_node_t node = { + .type = REGISTRY_NODE_SCHEMA, + .location.schema = ®istry_tests_nested, + }; + + registry_commit(&node); + TEST_ASSERT(successful); } static void tests_registry_commit_namespace(void) { successful = false; - registry_commit_namespace(®istry_tests); + + const registry_node_t node = { + .type = REGISTRY_NODE_NAMESPACE, + .location.namespace = ®istry_tests, + }; + + registry_commit(&node); + TEST_ASSERT(successful); } static void tests_registry_commit_all(void) { successful = false; - registry_commit(); + registry_commit(NULL); TEST_ASSERT(successful); } diff --git a/tests/unittests/tests-registry/tests-export.c b/tests/unittests/tests-registry/tests-export.c index 757ae504abb7..4eefdd1dabc3 100644 --- a/tests/unittests/tests-registry/tests-export.c +++ b/tests/unittests/tests-registry/tests-export.c @@ -50,71 +50,66 @@ static registry_instance_t test_nested_instance_1 = { .commit_cb = NULL, }; -static int export_parameter_cb(const registry_export_cb_data_t *data, - const registry_export_cb_data_type_t data_type, +static int export_parameter_cb(const registry_node_t *node, const void *context) { (void)context; - if (data_type == REGISTRY_EXPORT_PARAMETER && data != NULL && - data->parameter.data->id == *(registry_parameter_id_t *)context && - data->parameter.instance == &test_nested_instance_1) { + if (node->type == REGISTRY_NODE_PARAMETER && node->location.parameter != NULL && + node->location.parameter->id == *(registry_parameter_id_t *)context && + node->instance == &test_nested_instance_1) { successful = true; } return 0; } -static int export_group_cb(const registry_export_cb_data_t *data, - const registry_export_cb_data_type_t data_type, - const void *context) +static int export_group_cb(const registry_node_t *node, + const void *context) { (void)context; - if (data_type == REGISTRY_EXPORT_GROUP && data != NULL && - data->group->id == *(registry_group_id_t *)context) { + if (node->type == REGISTRY_NODE_GROUP && node->location.group != NULL && + node->location.group->id == *(registry_group_id_t *)context) { successful = true; } return 0; } -static int export_instance_cb(const registry_export_cb_data_t *data, - const registry_export_cb_data_type_t data_type, - const void *context) +static int export_instance_cb(const registry_node_t *node, + const void *context) { (void)context; - if (data_type == REGISTRY_EXPORT_INSTANCE && data != NULL && - data->instance == &test_nested_instance_1) { + if (node->type == REGISTRY_NODE_INSTANCE && node->instance != NULL && + node->instance == &test_nested_instance_1) { successful = true; } return 0; } -static int export_schema_cb(const registry_export_cb_data_t *data, - const registry_export_cb_data_type_t data_type, - const void *context) +static int export_schema_cb(const registry_node_t *node, + const void *context) { (void)context; - if (data_type == REGISTRY_EXPORT_SCHEMA && data != NULL && - data->schema == ®istry_tests_nested) { + if (node->type == REGISTRY_NODE_SCHEMA && node->location.schema != NULL && + node->location.schema == ®istry_tests_nested) { successful = true; } return 0; } -static int export_namespace_cb(const registry_export_cb_data_t *data, - const registry_export_cb_data_type_t data_type, +static int export_namespace_cb(const registry_node_t *node, const void *context) { (void)context; - if (data_type == REGISTRY_EXPORT_NAMESPACE && data != NULL && - data->namespace == ®istry_tests) { + if (node->type == REGISTRY_NODE_NAMESPACE && node->location.namespace != NULL && + node->location.namespace == ®istry_tests) { successful = true; } @@ -139,27 +134,37 @@ static void tests_registry_export_parameter(void) const registry_parameter_id_t parameter_id = REGISTRY_TESTS_NESTED_PARAMETER; successful = false; - registry_export_parameter(&test_nested_instance_1, ®istry_tests_nested_parameter, - &export_parameter_cb, ¶meter_id); + + const registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .location.parameter = ®istry_tests_nested_parameter, + .instance = &test_nested_instance_1, + }; + + registry_export(&node, &export_parameter_cb, 0, ¶meter_id); + TEST_ASSERT(successful); } static void tests_registry_export_group(void) { + const registry_node_t node = { + .type = REGISTRY_NODE_GROUP, + .location.group = ®istry_tests_nested_group, + .instance = &test_nested_instance_1, + }; + /* check if group gets exported */ const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; - successful = false; - registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, &export_group_cb, - 0, &group_id); + registry_export(&node, &export_group_cb, 0, &group_id); TEST_ASSERT(successful); /* check that siblings get NOT exported */ const registry_parameter_id_t sibling_parameter_id = REGISTRY_TESTS_NESTED_PARAMETER; successful = false; - registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, - &export_parameter_cb, 0, &sibling_parameter_id); + registry_export(&node, &export_parameter_cb, 0, &sibling_parameter_id); TEST_ASSERT_EQUAL_INT(false, successful); @@ -168,28 +173,30 @@ static void tests_registry_export_group(void) /* recursion_depth 0 => infinite => parameter gets exported */ successful = false; - registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, - &export_parameter_cb, 0, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 0, &child_parameter_id); TEST_ASSERT(successful); /* recursion_depth 1 => only group => parameter gets NOT exported */ successful = false; - registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, - &export_parameter_cb, 1, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 1, &child_parameter_id); TEST_ASSERT_EQUAL_INT(false, successful); /* recursion_depth 2 => group + 1 level more => parameter gets exported */ successful = false; - registry_export_group(&test_nested_instance_1, ®istry_tests_nested_group, - &export_parameter_cb, 2, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 2, &child_parameter_id); TEST_ASSERT(successful); } static void tests_registry_export_instance(void) { + const registry_node_t node = { + .type = REGISTRY_NODE_INSTANCE, + .instance = &test_nested_instance_1, + }; + /* check if instance gets exported */ successful = false; - registry_export_instance(&test_nested_instance_1, &export_instance_cb, 0, NULL); + registry_export(&node, &export_instance_cb, 0, NULL); TEST_ASSERT(successful); @@ -197,7 +204,7 @@ static void tests_registry_export_instance(void) const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; successful = false; - registry_export_instance(&test_nested_instance_1, &export_group_cb, 0, &group_id); + registry_export(&node, &export_group_cb, 0, &group_id); TEST_ASSERT(successful); @@ -206,30 +213,35 @@ static void tests_registry_export_instance(void) /* recursion_depth 0 => infinite => parameter gets exported */ successful = false; - registry_export_instance(&test_nested_instance_1, &export_parameter_cb, 0, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 0, &child_parameter_id); TEST_ASSERT(successful); /* recursion_depth 2 => only instance and group => parameter gets NOT exported */ successful = false; - registry_export_instance(&test_nested_instance_1, &export_parameter_cb, 2, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 2, &child_parameter_id); TEST_ASSERT_EQUAL_INT(false, successful); /* recursion_depth 3 => instance, group and parameter => parameter gets exported */ successful = false; - registry_export_instance(&test_nested_instance_1, &export_parameter_cb, 3, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 3, &child_parameter_id); TEST_ASSERT(successful); } static void tests_registry_export_schema(void) { + const registry_node_t node = { + .type = REGISTRY_NODE_SCHEMA, + .location.schema = ®istry_tests_nested, + }; + /* check if schema gets exported */ successful = false; - registry_export_schema(®istry_tests_nested, &export_schema_cb, 0, NULL); + registry_export(&node, &export_schema_cb, 0, NULL); TEST_ASSERT(successful); /* check if instance gets exported */ successful = false; - registry_export_schema(®istry_tests_nested, &export_instance_cb, 0, NULL); + registry_export(&node, &export_instance_cb, 0, NULL); TEST_ASSERT(successful); @@ -237,7 +249,7 @@ static void tests_registry_export_schema(void) const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; successful = false; - registry_export_schema(®istry_tests_nested, &export_group_cb, 0, &group_id); + registry_export(&node, &export_group_cb, 0, &group_id); TEST_ASSERT(successful); @@ -246,35 +258,40 @@ static void tests_registry_export_schema(void) /* recursion_depth 0 => infinite => parameter gets exported */ successful = false; - registry_export_schema(®istry_tests_nested, &export_parameter_cb, 0, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 0, &child_parameter_id); TEST_ASSERT(successful); /* recursion_depth 3 => only schema, instance and group => parameter gets NOT exported */ successful = false; - registry_export_schema(®istry_tests_nested, &export_parameter_cb, 3, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 3, &child_parameter_id); TEST_ASSERT_EQUAL_INT(false, successful); /* recursion_depth 4 => schema, instance, group and parameter => parameter gets exported */ successful = false; - registry_export_schema(®istry_tests_nested, &export_parameter_cb, 4, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 4, &child_parameter_id); TEST_ASSERT(successful); } static void tests_registry_export_namespace(void) { + const registry_node_t node = { + .type = REGISTRY_NODE_NAMESPACE, + .location.namespace = ®istry_tests, + }; + /* check if namespace gets exported */ successful = false; - registry_export_namespace(®istry_tests, &export_namespace_cb, 0, NULL); + registry_export(&node, &export_namespace_cb, 0, NULL); TEST_ASSERT(successful); /* check if schema gets exported */ successful = false; - registry_export_namespace(®istry_tests, &export_schema_cb, 0, NULL); + registry_export(&node, &export_schema_cb, 0, NULL); TEST_ASSERT(successful); /* check if instance gets exported */ successful = false; - registry_export_namespace(®istry_tests, &export_instance_cb, 0, NULL); + registry_export(&node, &export_instance_cb, 0, NULL); TEST_ASSERT(successful); @@ -282,7 +299,7 @@ static void tests_registry_export_namespace(void) const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; successful = false; - registry_export_namespace(®istry_tests, &export_group_cb, 0, &group_id); + registry_export(&node, &export_group_cb, 0, &group_id); TEST_ASSERT(successful); @@ -291,17 +308,17 @@ static void tests_registry_export_namespace(void) /* recursion_depth 0 => infinite => parameter gets exported */ successful = false; - registry_export_namespace(®istry_tests, &export_parameter_cb, 0, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 0, &child_parameter_id); TEST_ASSERT(successful); /* recursion_depth 4 => only namespace, schema, instance and group => parameter gets NOT exported */ successful = false; - registry_export_namespace(®istry_tests, &export_parameter_cb, 4, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 4, &child_parameter_id); TEST_ASSERT_EQUAL_INT(false, successful); /* recursion_depth 5 => namespace, schema, instance, group and parameter => parameter gets exported */ successful = false; - registry_export_namespace(®istry_tests, &export_parameter_cb, 5, &child_parameter_id); + registry_export(&node, &export_parameter_cb, 5, &child_parameter_id); TEST_ASSERT(successful); } @@ -309,17 +326,17 @@ static void tests_registry_export_all(void) { /* check if namespace gets exported */ successful = false; - registry_export(&export_namespace_cb, 0, NULL); + registry_export(NULL, &export_namespace_cb, 0, NULL); TEST_ASSERT(successful); /* check if schema gets exported */ successful = false; - registry_export( &export_schema_cb, 0, NULL); + registry_export(NULL, &export_schema_cb, 0, NULL); TEST_ASSERT(successful); /* check if instance gets exported */ successful = false; - registry_export( &export_instance_cb, 0, NULL); + registry_export(NULL, &export_instance_cb, 0, NULL); TEST_ASSERT(successful); @@ -327,7 +344,7 @@ static void tests_registry_export_all(void) const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; successful = false; - registry_export( &export_group_cb, 0, &group_id); + registry_export(NULL, &export_group_cb, 0, &group_id); TEST_ASSERT(successful); @@ -336,17 +353,17 @@ static void tests_registry_export_all(void) /* recursion_depth 0 => infinite => parameter gets exported */ successful = false; - registry_export( &export_parameter_cb, 0, &child_parameter_id); + registry_export(NULL, &export_parameter_cb, 0, &child_parameter_id); TEST_ASSERT(successful); /* recursion_depth 4 => only namespace, schema, instance and group => parameter gets NOT exported */ successful = false; - registry_export(&export_parameter_cb, 4, &child_parameter_id); + registry_export(NULL, &export_parameter_cb, 4, &child_parameter_id); TEST_ASSERT_EQUAL_INT(false, successful); /* recursion_depth 5 => namespace, schema, instance, group and parameter => parameter gets exported */ successful = false; - registry_export(&export_parameter_cb, 5, &child_parameter_id); + registry_export(NULL, &export_parameter_cb, 5, &child_parameter_id); TEST_ASSERT(successful); } diff --git a/tests/unittests/tests-registry/tests-get-set.c b/tests/unittests/tests-registry/tests-get-set.c index b82cc8a35186..1ca95666430f 100644 --- a/tests/unittests/tests-registry/tests-get-set.c +++ b/tests/unittests/tests-registry/tests-get-set.c @@ -75,6 +75,8 @@ static registry_instance_t test_full_instance_1 = { .commit_cb = &commit_cb, }; + + static void test_registry_setup(void) { /* init registry */ @@ -92,115 +94,129 @@ static void tests_registry_min_values(void) { registry_value_t output; + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .instance = &test_full_instance_1, + }; + /* opaque */ const registry_tests_full_instance_opaque_t input_opaque = { .value = 0, }; + node.location.parameter = ®istry_tests_full_opaque; - registry_set(&test_full_instance_1, ®istry_tests_full_opaque, &input_opaque, - sizeof(input_opaque)); - registry_get(&test_full_instance_1, ®istry_tests_full_opaque, &output); + registry_set(&node, &input_opaque, sizeof(input_opaque)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_opaque.value, ((registry_tests_full_instance_opaque_t *)output.buf)->value); /* string */ const char input_string[] = ""; + node.location.parameter = ®istry_tests_full_string; - registry_set(&test_full_instance_1, ®istry_tests_full_string, input_string, - sizeof(input_string)); - registry_get(&test_full_instance_1, ®istry_tests_full_string, &output); + registry_set(&node, input_string, sizeof(input_string)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_STRING("", (char *)output.buf); /* bool */ const bool input_bool = false; + node.location.parameter = ®istry_tests_full_boolean; - registry_set(&test_full_instance_1, ®istry_tests_full_boolean, &input_bool, - sizeof(input_bool)); - registry_get(&test_full_instance_1, ®istry_tests_full_boolean, &output); + registry_set(&node, &input_bool, sizeof(input_bool)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_bool, *(bool *)output.buf); /* u8 */ const uint8_t input_u8 = 0; + node.location.parameter = ®istry_tests_full_u8; - registry_set(&test_full_instance_1, ®istry_tests_full_u8, &input_u8, sizeof(input_u8)); - registry_get(&test_full_instance_1, ®istry_tests_full_u8, &output); + registry_set(&node, &input_u8, sizeof(input_u8)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u8, *(uint8_t *)output.buf); /* u16 */ const uint16_t input_u16 = 0; + node.location.parameter = ®istry_tests_full_u16; - registry_set(&test_full_instance_1, ®istry_tests_full_u16, &input_u16, sizeof(input_u16)); - registry_get(&test_full_instance_1, ®istry_tests_full_u16, &output); + registry_set(&node, &input_u16, sizeof(input_u16)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u16, *(uint16_t *)output.buf); /* u32 */ const uint32_t input_u32 = 0; + node.location.parameter = ®istry_tests_full_u32; - registry_set(&test_full_instance_1, ®istry_tests_full_u32, &input_u32, sizeof(input_u32)); - registry_get(&test_full_instance_1, ®istry_tests_full_u32, &output); + registry_set(&node, &input_u32, sizeof(input_u32)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u32, *(uint32_t *)output.buf); /* u64 */ const uint64_t input_u64 = 0; + node.location.parameter = ®istry_tests_full_u64; - registry_set(&test_full_instance_1, ®istry_tests_full_u64, &input_u64, sizeof(input_u64)); - registry_get(&test_full_instance_1, ®istry_tests_full_u64, &output); + registry_set(&node, &input_u64, sizeof(input_u64)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u64, *(uint64_t *)output.buf); /* i8 */ const int8_t input_i8 = INT8_MIN; + node.location.parameter = ®istry_tests_full_i8; - registry_set(&test_full_instance_1, ®istry_tests_full_i8, &input_i8, sizeof(input_i8)); - registry_get(&test_full_instance_1, ®istry_tests_full_i8, &output); + registry_set(&node, &input_i8, sizeof(input_i8)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i8, *(int8_t *)output.buf); /* i16 */ const int16_t input_i16 = INT16_MIN; + node.location.parameter = ®istry_tests_full_i16; - registry_set(&test_full_instance_1, ®istry_tests_full_i16, &input_i16, sizeof(input_i16)); - registry_get(&test_full_instance_1, ®istry_tests_full_i16, &output); + registry_set(&node, &input_i16, sizeof(input_i16)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i16, *(int16_t *)output.buf); /* i32 */ const int32_t input_i32 = INT32_MIN; + node.location.parameter = ®istry_tests_full_i32; - registry_set(&test_full_instance_1, ®istry_tests_full_i32, &input_i32, sizeof(input_i32)); - registry_get(&test_full_instance_1, ®istry_tests_full_i32, &output); + registry_set(&node, &input_i32, sizeof(input_i32)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i32, *(int32_t *)output.buf); /* i64 */ const int64_t input_i64 = INT64_MIN; + node.location.parameter = ®istry_tests_full_i64; - registry_set(&test_full_instance_1, ®istry_tests_full_i64, &input_i64, sizeof(input_i64)); - registry_get(&test_full_instance_1, ®istry_tests_full_i64, &output); + registry_set(&node, &input_i64, sizeof(input_i64)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i64, *(int64_t *)output.buf); /* f32 */ const float input_f32 = FLT_MIN; + node.location.parameter = ®istry_tests_full_f32; - registry_set(&test_full_instance_1, ®istry_tests_full_f32, &input_f32, sizeof(input_f32)); - registry_get(&test_full_instance_1, ®istry_tests_full_f32, &output); + registry_set(&node, &input_f32, sizeof(input_f32)); + registry_get(&node, &output); char input_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; char output_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; @@ -212,9 +228,10 @@ static void tests_registry_min_values(void) /* f64 */ const double input_f64 = DBL_MIN; + node.location.parameter = ®istry_tests_full_f64; - registry_set(&test_full_instance_1, ®istry_tests_full_f64, &input_f64, sizeof(input_f64)); - registry_get(&test_full_instance_1, ®istry_tests_full_f64, &output); + registry_set(&node, &input_f64, sizeof(input_f64)); + registry_get(&node, &output); char input_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; char output_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; @@ -228,14 +245,19 @@ static void tests_registry_zero_values(void) { registry_value_t output; + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .instance = &test_full_instance_1, + }; + /* opaque */ const registry_tests_full_instance_opaque_t input_opaque = { .value = 0, }; + node.location.parameter = ®istry_tests_full_opaque; - registry_set(&test_full_instance_1, ®istry_tests_full_opaque, &input_opaque, - sizeof(input_opaque)); - registry_get(&test_full_instance_1, ®istry_tests_full_opaque, &output); + registry_set(&node, &input_opaque, sizeof(input_opaque)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_opaque.value, ((registry_tests_full_instance_opaque_t *)output.buf)->value); @@ -243,101 +265,110 @@ static void tests_registry_zero_values(void) /* string */ const char input_string[] = ""; + node.location.parameter = ®istry_tests_full_string; - registry_set(&test_full_instance_1, ®istry_tests_full_string, input_string, - sizeof(input_string)); - registry_get(&test_full_instance_1, ®istry_tests_full_string, &output); + registry_set(&node, input_string, sizeof(input_string)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_STRING("", (char *)output.buf); /* bool */ const bool input_bool = 0; + node.location.parameter = ®istry_tests_full_boolean; - registry_set(&test_full_instance_1, ®istry_tests_full_boolean, &input_bool, - sizeof(input_bool)); - registry_get(&test_full_instance_1, ®istry_tests_full_boolean, &output); + registry_set(&node, &input_bool, sizeof(input_bool)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_bool, *(bool *)output.buf); /* u8 */ const uint8_t input_u8 = 0; + node.location.parameter = ®istry_tests_full_u8; - registry_set(&test_full_instance_1, ®istry_tests_full_u8, &input_u8, sizeof(input_u8)); - registry_get(&test_full_instance_1, ®istry_tests_full_u8, &output); + registry_set(&node, &input_u8, sizeof(input_u8)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u8, *(uint8_t *)output.buf); /* u16 */ const uint16_t input_u16 = 0; + node.location.parameter = ®istry_tests_full_u16; - registry_set(&test_full_instance_1, ®istry_tests_full_u16, &input_u16, sizeof(input_u16)); - registry_get(&test_full_instance_1, ®istry_tests_full_u16, &output); + registry_set(&node, &input_u16, sizeof(input_u16)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u16, *(uint16_t *)output.buf); /* u32 */ const uint32_t input_u32 = 0; + node.location.parameter = ®istry_tests_full_u32; - registry_set(&test_full_instance_1, ®istry_tests_full_u32, &input_u32, sizeof(input_u32)); - registry_get(&test_full_instance_1, ®istry_tests_full_u32, &output); + registry_set(&node, &input_u32, sizeof(input_u32)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u32, *(uint32_t *)output.buf); /* u64 */ const uint64_t input_u64 = 0; + node.location.parameter = ®istry_tests_full_u64; - registry_set(&test_full_instance_1, ®istry_tests_full_u64, &input_u64, sizeof(input_u64)); - registry_get(&test_full_instance_1, ®istry_tests_full_u64, &output); + registry_set(&node, &input_u64, sizeof(input_u64)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u64, *(uint64_t *)output.buf); /* i8 */ const int8_t input_i8 = 0; + node.location.parameter = ®istry_tests_full_i8; - registry_set(&test_full_instance_1, ®istry_tests_full_i8, &input_i8, sizeof(input_i8)); - registry_get(&test_full_instance_1, ®istry_tests_full_i8, &output); + registry_set(&node, &input_i8, sizeof(input_i8)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i8, *(int8_t *)output.buf); /* i16 */ const int16_t input_i16 = 0; + node.location.parameter = ®istry_tests_full_i16; - registry_set(&test_full_instance_1, ®istry_tests_full_i16, &input_i16, sizeof(input_i16)); - registry_get(&test_full_instance_1, ®istry_tests_full_i16, &output); + registry_set(&node, &input_i16, sizeof(input_i16)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i16, *(int16_t *)output.buf); /* i32 */ const int32_t input_i32 = 0; + node.location.parameter = ®istry_tests_full_i32; - registry_set(&test_full_instance_1, ®istry_tests_full_i32, &input_i32, sizeof(input_i32)); - registry_get(&test_full_instance_1, ®istry_tests_full_i32, &output); + registry_set(&node, &input_i32, sizeof(input_i32)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i32, *(int32_t *)output.buf); /* i64 */ const int64_t input_i64 = 0; + node.location.parameter = ®istry_tests_full_i64; - registry_set(&test_full_instance_1, ®istry_tests_full_i64, &input_i64, sizeof(input_i64)); - registry_get(&test_full_instance_1, ®istry_tests_full_i64, &output); + registry_set(&node, &input_i64, sizeof(input_i64)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i64, *(int64_t *)output.buf); /* f32 */ const float input_f32 = 0.0; + node.location.parameter = ®istry_tests_full_f32; - registry_set(&test_full_instance_1, ®istry_tests_full_f32, &input_f32, sizeof(input_f32)); - registry_get(&test_full_instance_1, ®istry_tests_full_f32, &output); + registry_set(&node, &input_f32, sizeof(input_f32)); + registry_get(&node, &output); char input_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; char output_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; @@ -349,9 +380,10 @@ static void tests_registry_zero_values(void) /* f64 */ const double input_f64 = 0.0; + node.location.parameter = ®istry_tests_full_f64; - registry_set(&test_full_instance_1, ®istry_tests_full_f64, &input_f64, sizeof(input_f64)); - registry_get(&test_full_instance_1, ®istry_tests_full_f64, &output); + registry_set(&node, &input_f64, sizeof(input_f64)); + registry_get(&node, &output); char input_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; char output_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; @@ -365,14 +397,19 @@ static void tests_registry_max_values(void) { registry_value_t output; + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .instance = &test_full_instance_1, + }; + /* opaque */ const registry_tests_full_instance_opaque_t input_opaque = { .value = UINT8_MAX, }; + node.location.parameter = ®istry_tests_full_opaque; - registry_set(&test_full_instance_1, ®istry_tests_full_opaque, &input_opaque, - sizeof(input_opaque)); - registry_get(&test_full_instance_1, ®istry_tests_full_opaque, &output); + registry_set(&node, &input_opaque, sizeof(input_opaque)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_opaque.value, ((registry_tests_full_instance_opaque_t *)output.buf)->value); @@ -385,100 +422,110 @@ static void tests_registry_max_values(void) input_string[i] = 'a'; } - registry_set(&test_full_instance_1, ®istry_tests_full_string, input_string, - sizeof(input_string)); - registry_get(&test_full_instance_1, ®istry_tests_full_string, &output); + node.location.parameter = ®istry_tests_full_string; + + registry_set(&node, input_string, sizeof(input_string)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_STRING(input_string, (char *)output.buf); /* bool */ const bool input_bool = true; + node.location.parameter = ®istry_tests_full_boolean; - registry_set(&test_full_instance_1, ®istry_tests_full_boolean, &input_bool, - sizeof(input_bool)); - registry_get(&test_full_instance_1, ®istry_tests_full_boolean, &output); + registry_set(&node, &input_bool, sizeof(input_bool)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_bool, *(bool *)output.buf); /* u8 */ const uint8_t input_u8 = UINT8_MAX; + node.location.parameter = ®istry_tests_full_u8; - registry_set(&test_full_instance_1, ®istry_tests_full_u8, &input_u8, sizeof(input_u8)); - registry_get(&test_full_instance_1, ®istry_tests_full_u8, &output); + registry_set(&node, &input_u8, sizeof(input_u8)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u8, *(uint8_t *)output.buf); /* u16 */ const uint16_t input_u16 = UINT16_MAX; + node.location.parameter = ®istry_tests_full_u16; - registry_set(&test_full_instance_1, ®istry_tests_full_u16, &input_u16, sizeof(input_u16)); - registry_get(&test_full_instance_1, ®istry_tests_full_u16, &output); + registry_set(&node, &input_u16, sizeof(input_u16)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u16, *(uint16_t *)output.buf); /* u32 */ const uint32_t input_u32 = UINT32_MAX; + node.location.parameter = ®istry_tests_full_u32; - registry_set(&test_full_instance_1, ®istry_tests_full_u32, &input_u32, sizeof(input_u32)); - registry_get(&test_full_instance_1, ®istry_tests_full_u32, &output); + registry_set(&node, &input_u32, sizeof(input_u32)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u32, *(uint32_t *)output.buf); /* u64 */ const uint64_t input_u64 = UINT64_MAX; + node.location.parameter = ®istry_tests_full_u64; - registry_set(&test_full_instance_1, ®istry_tests_full_u64, &input_u64, sizeof(input_u64)); - registry_get(&test_full_instance_1, ®istry_tests_full_u64, &output); + registry_set(&node, &input_u64, sizeof(input_u64)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_u64, *(uint64_t *)output.buf); /* i8 */ const int8_t input_i8 = INT8_MAX; + node.location.parameter = ®istry_tests_full_i8; - registry_set(&test_full_instance_1, ®istry_tests_full_i8, &input_i8, sizeof(input_i8)); - registry_get(&test_full_instance_1, ®istry_tests_full_i8, &output); + registry_set(&node, &input_i8, sizeof(input_i8)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i8, *(int8_t *)output.buf); /* i16 */ const int16_t input_i16 = INT16_MAX; + node.location.parameter = ®istry_tests_full_i16; - registry_set(&test_full_instance_1, ®istry_tests_full_i16, &input_i16, sizeof(input_i16)); - registry_get(&test_full_instance_1, ®istry_tests_full_i16, &output); + registry_set(&node, &input_i16, sizeof(input_i16)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i16, *(int16_t *)output.buf); /* i32 */ const int32_t input_i32 = INT32_MAX; + node.location.parameter = ®istry_tests_full_i32; - registry_set(&test_full_instance_1, ®istry_tests_full_i32, &input_i32, sizeof(input_i32)); - registry_get(&test_full_instance_1, ®istry_tests_full_i32, &output); + registry_set(&node, &input_i32, sizeof(input_i32)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i32, *(int32_t *)output.buf); /* i64 */ const int64_t input_i64 = INT64_MAX; + node.location.parameter = ®istry_tests_full_i64; - registry_set(&test_full_instance_1, ®istry_tests_full_i64, &input_i64, sizeof(input_i64)); - registry_get(&test_full_instance_1, ®istry_tests_full_i64, &output); + registry_set(&node, &input_i64, sizeof(input_i64)); + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(input_i64, *(int64_t *)output.buf); /* f32 */ const float input_f32 = FLT_MAX; + node.location.parameter = ®istry_tests_full_f32; - registry_set(&test_full_instance_1, ®istry_tests_full_f32, &input_f32, sizeof(input_f32)); - registry_get(&test_full_instance_1, ®istry_tests_full_f32, &output); + registry_set(&node, &input_f32, sizeof(input_f32)); + registry_get(&node, &output); char input_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; char output_f32_string[FLOAT_MAX_CHAR_COUNT + 1] = { 0 }; @@ -490,9 +537,10 @@ static void tests_registry_max_values(void) /* f64 */ const double input_f64 = DBL_MAX; + node.location.parameter = ®istry_tests_full_f64; - registry_set(&test_full_instance_1, ®istry_tests_full_f64, &input_f64, sizeof(input_f64)); - registry_get(&test_full_instance_1, ®istry_tests_full_f64, &output); + registry_set(&node, &input_f64, sizeof(input_f64)); + registry_get(&node, &output); char input_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; char output_f64_string[DOUBLE_MAX_CHAR_COUNT + 1] = { 0 }; From 7129ca1ac19e0f08b19de5c4a89b750cf2b00cdf Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:15:27 +0200 Subject: [PATCH 036/117] fixup! tests/unittests: add registry_int_path tests --- .../tests-registry_int_path.c | 252 ++++++++++-------- 1 file changed, 146 insertions(+), 106 deletions(-) diff --git a/tests/unittests/tests-registry_int_path/tests-registry_int_path.c b/tests/unittests/tests-registry_int_path/tests-registry_int_path.c index 923c90c91c14..9d23ca4ff325 100644 --- a/tests/unittests/tests-registry_int_path/tests-registry_int_path.c +++ b/tests/unittests/tests-registry_int_path/tests-registry_int_path.c @@ -63,182 +63,222 @@ static void test_setup(void) /* to int_path */ static void tests_registry_to_parameter_int_path(void) { - registry_parameter_int_path_t path = registry_to_parameter_int_path(&test_instance, - ®istry_tests_nested_parameter); - - TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); - TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.schema_id); - TEST_ASSERT_EQUAL_INT(test_instance.id, path.instance_id); - TEST_ASSERT_EQUAL_INT(registry_tests_nested_parameter.id, path.parameter_id); + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .instance = &test_instance, + .location.parameter = ®istry_tests_nested_parameter, + }; + registry_int_path_t path; + int res = registry_node_to_int_path(&node, &path); + + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.value.parameter_path.namespace_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.value.parameter_path.schema_id); + TEST_ASSERT_EQUAL_INT(test_instance.id, path.value.parameter_path.instance_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested_parameter.id, path.value.parameter_path.parameter_id); } static void tests_registry_to_group_int_path(void) { - registry_group_int_path_t path = registry_to_group_int_path(&test_instance, - ®istry_tests_nested_group); - - TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); - TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.schema_id); - TEST_ASSERT_EQUAL_INT(test_instance.id, path.instance_id); - TEST_ASSERT_EQUAL_INT(registry_tests_nested_group.id, path.group_id); + registry_node_t node = { + .type = REGISTRY_NODE_GROUP, + .instance = &test_instance, + .location.group = ®istry_tests_nested_group, + }; + registry_int_path_t path; + int res = registry_node_to_int_path(&node, &path); + + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.value.group_path.namespace_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.value.group_path.schema_id); + TEST_ASSERT_EQUAL_INT(test_instance.id, path.value.group_path.instance_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested_group.id, path.value.group_path.group_id); } static void tests_registry_to_instance_int_path(void) { - registry_instance_int_path_t path = registry_to_instance_int_path(&test_instance); + registry_node_t node = { + .type = REGISTRY_NODE_INSTANCE, + .instance = &test_instance, + }; + registry_int_path_t path; + int res = registry_node_to_int_path(&node, &path); - TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); - TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.schema_id); - TEST_ASSERT_EQUAL_INT(test_instance.id, path.instance_id); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.value.instance_path.namespace_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.value.instance_path.schema_id); + TEST_ASSERT_EQUAL_INT(test_instance.id, path.value.instance_path.instance_id); } static void tests_registry_to_schema_int_path(void) { - registry_schema_int_path_t path = registry_to_schema_int_path(®istry_tests_nested); + registry_node_t node = { + .type = REGISTRY_NODE_SCHEMA, + .location.schema = ®istry_tests_nested, + }; + registry_int_path_t path; + int res = registry_node_to_int_path(&node, &path); - TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); - TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.schema_id); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.value.schema_path.namespace_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.value.schema_path.schema_id); } static void tests_registry_to_namespace_int_path(void) { - registry_namespace_int_path_t path = registry_to_namespace_int_path(®istry_tests); + registry_node_t node = { + .type = REGISTRY_NODE_NAMESPACE, + .location.namespace = ®istry_tests, + }; + registry_int_path_t path; + int res = registry_node_to_int_path(&node, &path); - TEST_ASSERT_EQUAL_INT(registry_tests.id, path.namespace_id); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(registry_tests.id, path.value.namespace_path.namespace_id); } /* from int_path */ static void tests_registry_from_group_or_parameter_int_path(void) { - registry_int_path_type_t path_type; - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_instance_t *instance; - registry_group_t *group; - registry_parameter_t *parameter; - + registry_node_t node; /* parameter */ - const registry_group_or_parameter_int_path_t parameter_path = { - .namespace_id = registry_tests.id, - .schema_id = registry_tests_nested.id, - .instance_id = test_instance.id, - .group_or_parameter_id = registry_tests_nested_group_parameter.id, + const registry_int_path_t parameter_path = { + .type = REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER, + .value.group_or_parameter_path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + .group_or_parameter_id = registry_tests_nested_group_parameter.id, + }, }; - registry_from_group_or_parameter_int_path(¶meter_path, &path_type, &namespace, &schema, - &instance, &group, ¶meter); + int res = registry_node_from_int_path(¶meter_path, &node); - TEST_ASSERT_EQUAL_INT(path_type, REGISTRY_INT_PATH_TYPE_PARAMETER); - TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)parameter); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)node.location.parameter); /* group */ - const registry_group_or_parameter_int_path_t group_path = { - .namespace_id = registry_tests.id, - .schema_id = registry_tests_nested.id, - .instance_id = test_instance.id, - .group_or_parameter_id = registry_tests_nested_group.id, + const registry_int_path_t group_path = { + .type = REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER, + .value.group_or_parameter_path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + .group_or_parameter_id = registry_tests_nested_group.id, + }, }; - registry_from_group_or_parameter_int_path(&group_path, &path_type, &namespace, &schema, - &instance, &group, ¶meter); + res = registry_node_from_int_path(&group_path, &node); - TEST_ASSERT_EQUAL_INT(path_type, REGISTRY_INT_PATH_TYPE_GROUP); - TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)group); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_GROUP, node.type); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)node.location.group); } static void tests_registry_from_parameter_int_path(void) { - const registry_parameter_int_path_t path = { - .namespace_id = registry_tests.id, - .schema_id = registry_tests_nested.id, - .instance_id = test_instance.id, - .parameter_id = registry_tests_nested_group_parameter.id, + registry_node_t node; + + const registry_int_path_t path = { + .type = REGISTRY_INT_PATH_TYPE_PARAMETER, + .value.parameter_path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + .parameter_id = registry_tests_nested_group_parameter.id, + }, }; - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_instance_t *instance; - registry_parameter_t *parameter; - registry_from_parameter_int_path(&path, &namespace, &schema, &instance, ¶meter); + int res = registry_node_from_int_path(&path, &node); - TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)parameter); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)node.location.parameter); } static void tests_registry_from_group_int_path(void) { - const registry_group_int_path_t path = { - .namespace_id = registry_tests.id, - .schema_id = registry_tests_nested.id, - .instance_id = test_instance.id, - .group_id = registry_tests_nested_group.id, + registry_node_t node; + + const registry_int_path_t path = { + .type = REGISTRY_INT_PATH_TYPE_GROUP, + .value.group_path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + .group_id = registry_tests_nested_group.id, + }, }; - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_instance_t *instance; - registry_group_t *group; - registry_from_group_int_path(&path, &namespace, &schema, &instance, &group); + int res = registry_node_from_int_path(&path, &node); - TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)group); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_GROUP, node.type); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)node.location.group); } static void tests_registry_from_instance_int_path(void) { - const registry_instance_int_path_t path = { - .namespace_id = registry_tests.id, - .schema_id = registry_tests_nested.id, - .instance_id = test_instance.id, + registry_node_t node; + + const registry_int_path_t path = { + .type = REGISTRY_INT_PATH_TYPE_INSTANCE, + .value.instance_path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + .instance_id = test_instance.id, + }, }; - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_instance_t *instance; - registry_from_instance_int_path(&path, &namespace, &schema, &instance); + int res = registry_node_from_int_path(&path, &node); - TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)instance); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_INSTANCE, node.type); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); } static void tests_registry_from_schema_int_path(void) { - const registry_schema_int_path_t path = { - .namespace_id = registry_tests.id, - .schema_id = registry_tests_nested.id, + registry_node_t node; + + const registry_int_path_t path = { + .type = REGISTRY_INT_PATH_TYPE_SCHEMA, + .value.schema_path = { + .namespace_id = registry_tests.id, + .schema_id = registry_tests_nested.id, + }, }; - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_from_schema_int_path(&path, &namespace, &schema); + int res = registry_node_from_int_path(&path, &node); - TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)schema); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_SCHEMA, node.type); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)node.location.schema); } static void tests_registry_from_namespace_int_path(void) { - const registry_namespace_int_path_t path = { - .namespace_id = registry_tests.id, + registry_node_t node; + + const registry_int_path_t path = { + .type = REGISTRY_INT_PATH_TYPE_NAMESPACE, + .value.namespace_path = { + .namespace_id = registry_tests.id, + }, }; - registry_namespace_t *namespace; - registry_from_namespace_int_path(&path, &namespace); + int res = registry_node_from_int_path(&path, &node); - TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)namespace); + TEST_ASSERT_EQUAL_INT(0, res); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_NAMESPACE, node.type); + TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)node.location.namespace); } Test *tests_registry_int_path_tests(void) From 34a70b47cf4ab8ced6e5eeef46c66967538e672f Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:16:01 +0200 Subject: [PATCH 037/117] fixup! tests/unittests: add registry_string_path tests --- .../tests-registry_string_path.c | 161 ++++++++---------- 1 file changed, 75 insertions(+), 86 deletions(-) diff --git a/tests/unittests/tests-registry_string_path/tests-registry_string_path.c b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c index 9c456952240e..3c47c330af16 100644 --- a/tests/unittests/tests-registry_string_path/tests-registry_string_path.c +++ b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c @@ -61,158 +61,148 @@ static void test_setup(void) /* to string_path */ static void tests_registry_to_parameter_string_path(void) { - int size = registry_to_parameter_string_path(&test_instance, - ®istry_tests_nested_group_parameter, NULL); + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .location.parameter = ®istry_tests_nested_group_parameter, + .instance = &test_instance, + }; + + int size = registry_node_to_string_path(&node, NULL); char path[size + 1]; - registry_to_parameter_string_path(&test_instance, ®istry_tests_nested_group_parameter, path); + registry_node_to_string_path(&node, path); TEST_ASSERT_EQUAL_STRING("/tests/nested/instance-1/group/parameter", path); } static void tests_registry_to_group_string_path(void) { - int size = registry_to_group_string_path(&test_instance, ®istry_tests_nested_group, NULL); + registry_node_t node = { + .type = REGISTRY_NODE_GROUP, + .location.group = ®istry_tests_nested_group, + .instance = &test_instance, + }; + + int size = registry_node_to_string_path(&node, NULL); char path[size + 1]; - registry_to_group_string_path(&test_instance, ®istry_tests_nested_group, path); + registry_node_to_string_path(&node, path); TEST_ASSERT_EQUAL_STRING("/tests/nested/instance-1/group", path); } static void tests_registry_to_instance_string_path(void) { - int size = registry_to_instance_string_path(&test_instance, NULL); + registry_node_t node = { + .type = REGISTRY_NODE_INSTANCE, + .instance = &test_instance, + }; + + int size = registry_node_to_string_path(&node, NULL); char path[size + 1]; - registry_to_instance_string_path(&test_instance, path); + registry_node_to_string_path(&node, path); TEST_ASSERT_EQUAL_STRING("/tests/nested/instance-1", path); } static void tests_registry_to_schema_string_path(void) { - int size = registry_to_schema_string_path(®istry_tests_nested, NULL); + registry_node_t node = { + .type = REGISTRY_NODE_SCHEMA, + .location.schema = ®istry_tests_nested, + }; + + int size = registry_node_to_string_path(&node, NULL); char path[size + 1]; - registry_to_schema_string_path(®istry_tests_nested, path); + registry_node_to_string_path(&node, path); TEST_ASSERT_EQUAL_STRING("/tests/nested", path); } static void tests_registry_to_namespace_string_path(void) { - int size = registry_to_namespace_string_path(®istry_tests, NULL); + registry_node_t node = { + .type = REGISTRY_NODE_NAMESPACE, + .location.namespace = ®istry_tests, + }; + + int size = registry_node_to_string_path(&node, NULL); char path[size + 1]; - registry_to_namespace_string_path(®istry_tests, path); + registry_node_to_string_path(&node, path); TEST_ASSERT_EQUAL_STRING("/tests", path); } /* from string_path */ -static void tests_registry_from_group_or_parameter_string_path(void) -{ - registry_string_path_type_t path_type; - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_instance_t *instance; - registry_group_t *group; - registry_parameter_t *parameter; - - /* group */ - registry_from_group_or_parameter_string_path("/tests/nested/instance-1/group", - &path_type, &namespace, &schema, &instance, &group, - ¶meter); - - TEST_ASSERT_EQUAL_INT(REGISTRY_STRING_PATH_TYPE_GROUP, path_type); - TEST_ASSERT_EQUAL_STRING("tests", namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", schema->name); - TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); - TEST_ASSERT_EQUAL_STRING("group", group->name); - - /* parameter */ - registry_from_group_or_parameter_string_path("/tests/nested/instance-1/group/parameter", - &path_type, &namespace, &schema, &instance, &group, - ¶meter); - - TEST_ASSERT_EQUAL_INT(REGISTRY_STRING_PATH_TYPE_PARAMETER, path_type); - TEST_ASSERT_EQUAL_STRING("tests", namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", schema->name); - TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); - TEST_ASSERT_EQUAL_STRING("parameter", parameter->name); -} - static void tests_registry_from_parameter_string_path(void) { - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_instance_t *instance; - registry_parameter_t *parameter; - - registry_from_parameter_string_path("/tests/nested/instance-1/group/parameter", &namespace, - &schema, &instance, ¶meter); - - TEST_ASSERT_EQUAL_STRING("tests", namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", schema->name); - TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); - TEST_ASSERT_EQUAL_STRING("parameter", parameter->name); + registry_node_t node; + + char str[] = "/tests/nested/instance-1/group/parameter"; + registry_node_from_string_path(str, sizeof(str), &node); + + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); + TEST_ASSERT_EQUAL_STRING("tests", node.location.parameter->schema->namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", node.location.parameter->schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", node.instance->name); + TEST_ASSERT_EQUAL_STRING("parameter", node.location.parameter->name); } static void tests_registry_from_group_string_path(void) { - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_instance_t *instance; - registry_group_t *group; - - registry_from_group_string_path("/tests/nested/instance-1/group", &namespace, &schema, - &instance, &group); - - TEST_ASSERT_EQUAL_STRING("tests", namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", schema->name); - TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); - TEST_ASSERT_EQUAL_STRING("group", group->name); + registry_node_t node; + + char str[] = "/tests/nested/instance-1/group"; + registry_node_from_string_path(str, sizeof(str), &node); + + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_GROUP, node.type); + TEST_ASSERT_EQUAL_STRING("tests", node.location.group->schema->namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", node.location.group->schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", node.instance->name); + TEST_ASSERT_EQUAL_STRING("group", node.location.group->name); } static void tests_registry_from_instance_string_path(void) { - registry_namespace_t *namespace; - registry_schema_t *schema; - registry_instance_t *instance; + registry_node_t node; - registry_from_instance_string_path("/tests/nested/instance-1", &namespace, &schema, &instance); + char str[] = "/tests/nested/instance-1"; + registry_node_from_string_path(str, sizeof(str), &node); - TEST_ASSERT_EQUAL_STRING("tests", namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", schema->name); - TEST_ASSERT_EQUAL_STRING("instance-1", instance->name); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_INSTANCE, node.type); + TEST_ASSERT_EQUAL_STRING("tests", node.instance->schema->namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", node.instance->schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", node.instance->name); } static void tests_registry_from_schema_string_path(void) { - registry_namespace_t *namespace; - registry_schema_t *schema; + registry_node_t node; - registry_from_schema_string_path("/tests/nested", &namespace, &schema); + char str[] = "/tests/nested"; + registry_node_from_string_path(str, sizeof(str), &node); - TEST_ASSERT_EQUAL_STRING("tests", namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", schema->name); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_SCHEMA, node.type); + TEST_ASSERT_EQUAL_STRING("tests", node.location.schema->namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", node.location.schema->name); } static void tests_registry_from_namespace_string_path(void) { - registry_namespace_t *namespace; + registry_node_t node; - registry_from_namespace_string_path("/tests", &namespace); + char str[] = "/tests"; + registry_node_from_string_path(str, sizeof(str), &node); - TEST_ASSERT_EQUAL_STRING("tests", namespace->name); + TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_NAMESPACE, node.type); + TEST_ASSERT_EQUAL_STRING("tests", node.location.namespace->name); } Test *tests_registry_string_path_tests(void) { - (void)tests_registry_from_group_or_parameter_string_path; - (void)tests_registry_from_parameter_string_path; - (void)tests_registry_from_group_string_path; EMB_UNIT_TESTFIXTURES(fixtures) { /* to string_path */ new_TestFixture(tests_registry_to_parameter_string_path), @@ -221,7 +211,6 @@ Test *tests_registry_string_path_tests(void) new_TestFixture(tests_registry_to_schema_string_path), new_TestFixture(tests_registry_to_namespace_string_path), /* from string_path */ - new_TestFixture(tests_registry_from_group_or_parameter_string_path), new_TestFixture(tests_registry_from_parameter_string_path), new_TestFixture(tests_registry_from_group_string_path), new_TestFixture(tests_registry_from_instance_string_path), From 749d51a6f064e46a718336e915c953b92372dd1b Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:17:52 +0200 Subject: [PATCH 038/117] fixup! tests/unittests: add registry_storage_heap tests --- .../tests-registry_storage_heap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c index e3dfa262c371..eb6ed5b98919 100644 --- a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c +++ b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c @@ -66,21 +66,24 @@ static void test_setup(void) static void tests_load_and_save(void) { + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .location.parameter = ®istry_tests_nested_group_parameter, + .instance = &test_nested_instance, + }; /* set input to 8 */ const uint8_t saved_input = 8; - registry_set(&test_nested_instance, ®istry_tests_nested_group_parameter, &saved_input, - sizeof(saved_input)); + registry_set(&node, &saved_input, sizeof(saved_input)); /* save input to storage */ - registry_save(); + registry_save(NULL); /* override input with the value 20 */ const uint8_t override_input = 20; - registry_set(&test_nested_instance, ®istry_tests_nested_group_parameter, &override_input, - sizeof(override_input)); + registry_set(&node, &override_input, sizeof(override_input)); /* load old value from storage */ registry_load(); @@ -88,7 +91,7 @@ static void tests_load_and_save(void) /* check if the value is set back to 8 and not 20 anymore */ registry_value_t output_value; - registry_get(&test_nested_instance, ®istry_tests_nested_group_parameter, &output_value); + registry_get(&node, &output_value); TEST_ASSERT_EQUAL_INT(saved_input, *(uint8_t *)output_value.buf); } From 4d40b09e73648bce2e6740b49515db22cc907add Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:18:14 +0200 Subject: [PATCH 039/117] fixup! tests/unittests: add registry_storage_vfs tests --- .../tests-registry_storage_vfs.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c index 9e346f5c71ac..29e741b2da53 100644 --- a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c +++ b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c @@ -87,21 +87,24 @@ static void test_setup(void) static void tests_load_and_save(void) { + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .location.parameter = ®istry_tests_nested_group_parameter, + .instance = &test_nested_instance, + }; /* set input to 8 */ const uint8_t saved_input = 8; - registry_set(&test_nested_instance, ®istry_tests_nested_group_parameter, &saved_input, - sizeof(saved_input)); + registry_set(&node, &saved_input, sizeof(saved_input)); /* save input to storage */ - registry_save(); + registry_save(NULL); /* override input with the value 20 */ const uint8_t override_input = 20; - registry_set(&test_nested_instance, ®istry_tests_nested_group_parameter, &override_input, - sizeof(override_input)); + registry_set(&node, &override_input, sizeof(override_input)); /* load old value from storage */ registry_load(); @@ -109,7 +112,7 @@ static void tests_load_and_save(void) /* check if the value is set back to 8 and not 20 anymore */ registry_value_t output_value; - registry_get(&test_nested_instance, ®istry_tests_nested_group_parameter, &output_value); + registry_get(&node, &output_value); TEST_ASSERT_EQUAL_INT(saved_input, *(uint8_t *)output_value.buf); } From 75842a4b3681e2df6f5b7b5028adf9caa390a54f Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Sat, 6 Apr 2024 15:18:37 +0200 Subject: [PATCH 040/117] fixup! tests/unittests: add registry_storage tests --- .../tests-registry_storage.c | 61 ++++++++++++++----- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/tests/unittests/tests-registry_storage/tests-registry_storage.c b/tests/unittests/tests-registry_storage/tests-registry_storage.c index 020588d72a20..713bf5f7a6a0 100644 --- a/tests/unittests/tests-registry_storage/tests-registry_storage.c +++ b/tests/unittests/tests-registry_storage/tests-registry_storage.c @@ -55,8 +55,7 @@ static registry_instance_t test_nested_instance = { static int load(const registry_storage_instance_t *storage, const load_cb_t load_cb); static int save(const registry_storage_instance_t *storage, - const registry_instance_t *instance, - const registry_parameter_t *parameter, + const registry_node_t *node, const registry_value_t *value); static registry_storage_t storage_test = { @@ -75,21 +74,25 @@ static int load(const registry_storage_instance_t *storage, const load_cb_t load_cb) { if (storage == &storage_test_instance) { + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .location.parameter = ®istry_tests_nested_parameter, + .instance = &test_nested_instance, + }; uint8_t buf = _TESTS_REGISTRY_LOAD_STORED_VALUE; - return load_cb(&test_nested_instance, ®istry_tests_nested_parameter, &buf, sizeof(buf)); + return load_cb(&node, &buf, sizeof(buf)); } return -EINVAL; } static int save(const registry_storage_instance_t *storage, - const registry_instance_t *instance, - const registry_parameter_t *parameter, + const registry_node_t *node, const registry_value_t *value) { if (storage == &storage_test_instance && - instance == &test_nested_instance && - parameter == ®istry_tests_nested_group_parameter && + node->instance == &test_nested_instance && + node->location.parameter == ®istry_tests_nested_group_parameter && value->buf == &test_nested_instance_data.group_parameter && value->buf_len == sizeof(uint8_t) && value->type == REGISTRY_TYPE_UINT8) { @@ -120,40 +123,66 @@ static void tests_registry_load(void) /* check if the load_cb sets the value to the registry */ registry_value_t output; - registry_get(&test_nested_instance, ®istry_tests_nested_parameter, &output); + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .location.parameter = ®istry_tests_nested_parameter, + .instance = &test_nested_instance, + }; + + registry_get(&node, &output); TEST_ASSERT_EQUAL_INT(_TESTS_REGISTRY_LOAD_STORED_VALUE, *(uint8_t *)output.buf); } static void tests_registry_save_parameter(void) { - TEST_ASSERT_EQUAL_INT(0, registry_save_parameter(&test_nested_instance, - ®istry_tests_nested_group_parameter)); + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + .location.parameter = ®istry_tests_nested_group_parameter, + .instance = &test_nested_instance, + }; + TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } static void tests_registry_save_group(void) { - TEST_ASSERT_EQUAL_INT(0, registry_save_group(&test_nested_instance, - ®istry_tests_nested_group)); + registry_node_t node = { + .type = REGISTRY_NODE_GROUP, + .location.group = ®istry_tests_nested_group, + .instance = &test_nested_instance, + }; + TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } static void tests_registry_save_instance(void) { - TEST_ASSERT_EQUAL_INT(0, registry_save_instance(&test_nested_instance)); + registry_node_t node = { + .type = REGISTRY_NODE_INSTANCE, + .instance = &test_nested_instance, + }; + TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } static void tests_registry_save_schema(void) { - TEST_ASSERT_EQUAL_INT(0, registry_save_schema(®istry_tests_nested)); + registry_node_t node = { + .type = REGISTRY_NODE_SCHEMA, + .location.schema = ®istry_tests_nested, + }; + TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } static void tests_registry_save_namespace(void) { - TEST_ASSERT_EQUAL_INT(0, registry_save_namespace(®istry_tests)); + registry_node_t node = { + .type = REGISTRY_NODE_NAMESPACE, + .location.namespace = ®istry_tests, + }; + TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } static void tests_registry_save_all(void) { - TEST_ASSERT_EQUAL_INT(0, registry_save()); + TEST_ASSERT_EQUAL_INT(0, registry_save(NULL)); } Test *tests_registry_storage_tests(void) From 7f429457e35951ac633ef31ade5f995a57e493a2 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 10 Apr 2024 18:20:05 +0200 Subject: [PATCH 041/117] fixup! examples: add registry example Improve registry_cli example and add some documentation to it --- examples/registry_cli/Makefile | 2 - examples/registry_cli/main.c | 76 ++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/examples/registry_cli/Makefile b/examples/registry_cli/Makefile index cf28607b1a0d..3469f6d2a238 100644 --- a/examples/registry_cli/Makefile +++ b/examples/registry_cli/Makefile @@ -17,8 +17,6 @@ USEMODULE += mtd USEMODULE += registry_string_path USEMODULE += registry_storage_vfs USEMODULE += registry_namespace_sys_rgb_led -USEMODULE += registry_namespace_tests_full -USEMODULE += registry_namespace_tests_nested # Comment this out to disable code in RIOT that does safety checking # which is not needed in a production environment but helps in the diff --git a/examples/registry_cli/main.c b/examples/registry_cli/main.c index f46294872359..4117f224176f 100644 --- a/examples/registry_cli/main.c +++ b/examples/registry_cli/main.c @@ -32,95 +32,99 @@ #include "registry/namespace/sys/rgb_led.h" #include "registry/storage.h" #include "registry/string_path.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/nested.h" -int rgb_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, +/* this callback is usually implemented drivers such as an RGB LED driver */ +int rgb_led_instance_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { - (void)scope; (void)context; printf("RGB instance commit_cb was executed on "); - if (group_or_parameter_id != NULL) { - printf("param: %d", *group_or_parameter_id); + /* check how much of the registry instance was committed */ + switch (scope) + { + case REGISTRY_COMMIT_INSTANCE: + /* in this case the whole instance and all parameters inside of it was committed */ + printf("the whole instance"); + break; + case REGISTRY_COMMIT_GROUP: + /* in this case a group and all parameters inside of it was committed */ + printf("a group: %d\n", *group_or_parameter_id); + break; + case REGISTRY_COMMIT_PARAMETER: + /* in this case only a single parameter was committed */ + printf("a single parameter: %d\n", *group_or_parameter_id); + break; } - else { - printf("whole instance"); - } - - printf("\n"); return 0; } -registry_sys_rgb_led_instance_t rgb_led_instance_0_data = { +/* create instances of a configuration schema, to expose configuration parameters to the registry */ +static registry_sys_rgb_led_instance_t rgb_led_instance_0_data = { .red = 0, .green = 255, .blue = 70, }; -registry_instance_t rgb_led_instance_0 = { +static registry_instance_t rgb_led_instance_0 = { .name = "rgb-0", .data = &rgb_led_instance_0_data, - .commit_cb = &rgb_led_instance_0_commit_cb, + .commit_cb = &rgb_led_instance_commit_cb, }; -registry_sys_rgb_led_instance_t rgb_led_instance_1_data = { +/* this instance uses the same commit_cb function as instance 0 just for simplicity */ +/* normally each instance should have its own */ +static registry_sys_rgb_led_instance_t rgb_led_instance_1_data = { .red = 90, .green = 4, .blue = 0, }; -registry_instance_t rgb_led_instance_1 = { +static registry_instance_t rgb_led_instance_1 = { .name = "rgb-1", .data = &rgb_led_instance_1_data, - .commit_cb = &rgb_led_instance_0_commit_cb, + .commit_cb = &rgb_led_instance_commit_cb, }; +/* configure the registry storage to use littlefs2 */ static littlefs2_desc_t fs_desc = { .lock = MUTEX_INIT, }; +/* set the mount point for the registry storage to /sda for this example */ static vfs_mount_t _vfs_mount = { .fs = &littlefs2_file_system, .mount_point = "/sda", .private_data = &fs_desc, }; +/* create a storage instance to register the storage at the RIOT registry */ static registry_storage_instance_t vfs_instance = { .storage = ®istry_storage_vfs, .data = &_vfs_mount, }; +/* the storage source is where the registry reads parameter values from */ REGISTRY_ADD_STORAGE_SOURCE(vfs_instance); -REGISTRY_SET_STORAGE_DESTINATION(vfs_instance); - -static registry_tests_nested_instance_t test_nested_instance_data = { - .parameter = 9, - .group_parameter = 5, -}; -static registry_instance_t test_nested_instance = { - .name = "instance-1", - .data = &test_nested_instance_data, - .commit_cb = NULL, -}; +/* the storage destination is where the registry writes parameter values to */ +REGISTRY_SET_STORAGE_DESTINATION(vfs_instance); int main(void) { + /* initialize the riot registry storage for persistent configuration parameters */ + #if IS_USED(MODULE_LITTLEFS2) + fs_desc.dev = MTD_0; + #endif + + /* initialize the riot registry */ registry_init(); - /* init schemas */ + /* add configuration schemas to the registry */ registry_add_schema_instance(®istry_sys_rgb_led, &rgb_led_instance_0); registry_add_schema_instance(®istry_sys_rgb_led, &rgb_led_instance_1); - registry_add_schema_instance(®istry_tests_nested, &test_nested_instance); - - /* init storage */ - #if IS_USED(MODULE_LITTLEFS2) - fs_desc.dev = MTD_0; - #endif - /* init and run CLI */ + /* initialize and run the RIOT shell */ char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(NULL, line_buf, sizeof(line_buf)); return 0; From f1cbcf51e5887a61028a7cd3862abaf3f759fd3b Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 15:05:44 +0200 Subject: [PATCH 042/117] fixup! examples: add registry example Add more comments and address review --- examples/registry_cli/Makefile | 9 +++++ examples/registry_cli/README.md | 25 ++++++++++++++ examples/registry_cli/main.c | 58 +++++++++++++++++++++++++-------- 3 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 examples/registry_cli/README.md diff --git a/examples/registry_cli/Makefile b/examples/registry_cli/Makefile index 3469f6d2a238..54e60d403134 100644 --- a/examples/registry_cli/Makefile +++ b/examples/registry_cli/Makefile @@ -8,14 +8,23 @@ BOARD ?= native RIOTBASE ?= $(CURDIR)/../.. # required modules +# enable the shell to execute the registry CLI USEMODULE += shell USEMODULE += shell_cmds_default +# enable littlefs2 for the persistent storage of the registry USEMODULE += littlefs2 +# enable mtd to use it as the storage location USEMODULE += mtd +# enable the string_path extension of the registry to +# identify configuration parameters using strings instead of pointers USEMODULE += registry_string_path +# enable the vfs storage implementation to persistently store configuration +# parameters to a storage device such as the mtd USEMODULE += registry_storage_vfs +# enable the rgb_led schema (sys/rgb_led) to demonstrate how to configure +# RGB LEDs as an example for the registry CLI USEMODULE += registry_namespace_sys_rgb_led # Comment this out to disable code in RIOT that does safety checking diff --git a/examples/registry_cli/README.md b/examples/registry_cli/README.md new file mode 100644 index 000000000000..cb6f2f1430b2 --- /dev/null +++ b/examples/registry_cli/README.md @@ -0,0 +1,25 @@ +examples/registry_cli +================ + +This application demonstrates the most basic usage of the RIOT Registry. + +Usage +===== + +Simply build and flash the application for your target board: + +``` +BOARD=YOUR_BOARD_NAME_HERE make flash term +``` + +Now you should have access to the RIOT shell on your board. For interacting +with the RIOT Registry, use the `registry` shell command, e.g.: + +``` +registry export <- prints the IDs of the whole configuration tree +registry get 0/0/0/0 <- get the value of the red parameter of the instance 0 of the RGB LED Schema inside of the SYS namespace +registry set 0/0/0/0 56 <- set the value of the red parameter to 56 +registry commit 0/0/0/0 <- apply new value for the 0/0/0/0 path +registry save <- save configurations to persistent storage +registry load <- load configurations from persistent storage +``` diff --git a/examples/registry_cli/main.c b/examples/registry_cli/main.c index 4117f224176f..6e8417a75c1d 100644 --- a/examples/registry_cli/main.c +++ b/examples/registry_cli/main.c @@ -11,7 +11,8 @@ * @{ * * @file - * @brief RIOT Registry example application + * @brief RIOT registry CLI example application to demonstrate how + * to use the RIOT registry using the CLI. * * @author Lasse Rosenow * @@ -34,34 +35,49 @@ #include "registry/string_path.h" /* this callback is usually implemented drivers such as an RGB LED driver */ -int rgb_led_instance_commit_cb(const registry_commit_cb_scope_t scope, - const registry_group_or_parameter_id_t *group_or_parameter_id, - const void *context) +static int shared_commit_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) { - (void)context; + /* since this function is shared by multiple commit_cb functions, we path the instance in the context */ + const registry_instance_t *instance = context; + const registry_sys_rgb_led_instance_t *data = instance->data; + printf("RGB instance commit_cb was executed on "); - /* check how much of the registry instance was committed */ + /* check how much of the registry instance was committed and print the new values */ switch (scope) { case REGISTRY_COMMIT_INSTANCE: /* in this case the whole instance and all parameters inside of it was committed */ - printf("the whole instance"); + printf("the whole instance: ID: %d\n", instance->id); + printf("\tParameter ID: 0, VALUE: %d\n", data->red); + printf("\tParameter ID: 1, VALUE: %d\n", data->green); + printf("\tParameter ID: 2, VALUE: %d\n", data->blue); break; case REGISTRY_COMMIT_GROUP: /* in this case a group and all parameters inside of it was committed */ printf("a group: %d\n", *group_or_parameter_id); + /* this instance does not have groups, so no need to print anything here */ break; case REGISTRY_COMMIT_PARAMETER: /* in this case only a single parameter was committed */ - printf("a single parameter: %d\n", *group_or_parameter_id); - break; + printf("a single parameter: ID: %d,", *group_or_parameter_id); + switch (*group_or_parameter_id) + { + case 0: printf(" VALUE: %d\n", data->red); break; + case 1: printf(" VALUE: %d\n", data->green); break; + case 2: printf(" VALUE: %d\n", data->blue); break; + } } return 0; } /* create instances of a configuration schema, to expose configuration parameters to the registry */ +static int rgb_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context); static registry_sys_rgb_led_instance_t rgb_led_instance_0_data = { .red = 0, .green = 255, @@ -70,11 +86,20 @@ static registry_sys_rgb_led_instance_t rgb_led_instance_0_data = { static registry_instance_t rgb_led_instance_0 = { .name = "rgb-0", .data = &rgb_led_instance_0_data, - .commit_cb = &rgb_led_instance_commit_cb, + .commit_cb = &rgb_led_instance_0_commit_cb, }; +static int rgb_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) +{ + (void)context; + return shared_commit_cb(scope, group_or_parameter_id, &rgb_led_instance_0); +} -/* this instance uses the same commit_cb function as instance 0 just for simplicity */ -/* normally each instance should have its own */ +/* create an instance for a second RGB LED */ +static int rgb_led_instance_1_commit_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context); static registry_sys_rgb_led_instance_t rgb_led_instance_1_data = { .red = 90, .green = 4, @@ -83,8 +108,15 @@ static registry_sys_rgb_led_instance_t rgb_led_instance_1_data = { static registry_instance_t rgb_led_instance_1 = { .name = "rgb-1", .data = &rgb_led_instance_1_data, - .commit_cb = &rgb_led_instance_commit_cb, + .commit_cb = &rgb_led_instance_1_commit_cb, }; +static int rgb_led_instance_1_commit_cb(const registry_commit_cb_scope_t scope, + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) +{ + (void)context; + return shared_commit_cb(scope, group_or_parameter_id, &rgb_led_instance_1); +} /* configure the registry storage to use littlefs2 */ static littlefs2_desc_t fs_desc = { From 5675174fc97a273393fcb328f1adad841b0e89eb Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 15:06:38 +0200 Subject: [PATCH 043/117] fixup! examples: add registry_core example Add more comments and address review --- examples/registry_core/Makefile | 2 ++ examples/registry_core/README.md | 16 ++++++++++++++ examples/registry_core/main.c | 36 +++++++++++++------------------- 3 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 examples/registry_core/README.md diff --git a/examples/registry_core/Makefile b/examples/registry_core/Makefile index f8b0afe4e247..d3c76e6394c3 100644 --- a/examples/registry_core/Makefile +++ b/examples/registry_core/Makefile @@ -8,7 +8,9 @@ BOARD ?= native RIOTBASE ?= $(CURDIR)/../.. # required modules +# enable board_led schema (sys/board_led) of the riot registry USEMODULE += registry_namespace_sys_board_led +# enable the ztimer to turn the led on and off every second USEMODULE += ztimer_msec # Comment this out to disable code in RIOT that does safety checking diff --git a/examples/registry_core/README.md b/examples/registry_core/README.md new file mode 100644 index 000000000000..0317fb298292 --- /dev/null +++ b/examples/registry_core/README.md @@ -0,0 +1,16 @@ +examples/registry_core +================ + +This application demonstrates the most basic usage of the RIOT Registry. +It implements a RGB LED schema and continuously changes its value every second. + +Usage +===== + +Simply build and flash the application for your target board: + +``` +BOARD=YOUR_BOARD_NAME_HERE make flash term +``` + +Now you should see the terminal continuously print out different LED states. diff --git a/examples/registry_core/main.c b/examples/registry_core/main.c index 7fc2bcfeb9cb..bc6cb88ada8a 100644 --- a/examples/registry_core/main.c +++ b/examples/registry_core/main.c @@ -11,7 +11,8 @@ * @{ * * @file - * @brief RIOT Registry example application + * @brief RIOT registry core minimal example application to demonstrate + * how to use the riot registry without any of its extensions. * * @author Lasse Rosenow * @@ -30,7 +31,7 @@ #include "registry/namespace/sys/board_led.h" #include "ztimer.h" -int board_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, +int board_led_instance_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context); @@ -41,35 +42,26 @@ registry_sys_board_led_instance_t board_led_instance_0_data = { registry_instance_t board_led_instance = { .data = &board_led_instance_0_data, - .commit_cb = &board_led_instance_0_commit_cb, + .commit_cb = &board_led_instance_commit_cb, }; -int board_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, +/* this callback is usually implemented drivers such as an RGB LED driver */ +int board_led_instance_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { (void)scope; (void)context; - if (group_or_parameter_id != NULL) { - if (*group_or_parameter_id == REGISTRY_SYS_BOARD_LED_ENABLED) { - /* The Driver owns the board_led data instance, so we can just get our value from there */ - bool led_state = board_led_instance_0_data.enabled; - - /* Turn the LED on or off depending on the led_state */ - if (led_state == true) { - /* This is the commit_cb function of instance 0, so we toggle LED 0 as well */ - LED_ON(0); - } else { - LED_OFF(0); - } - } - } - else { - /* The whole instance got committed in one go, so apply all parameters (BOARD_LED has only one anyways)*/ - + /* Either commit all parameters of the instance or only the given parameter. + * For a single LED there is no difference as it only has one parameter. */ + if ((group_or_parameter_id == NULL) || + (*group_or_parameter_id == REGISTRY_SYS_BOARD_LED_ENABLED)) { + /* The Driver owns the board_led data instance, so we can just get our value from there */ bool led_state = board_led_instance_0_data.enabled; + /* Turn the LED on or off depending on the led_state */ if (led_state == true) { + /* This is the commit_cb function of instance 0, so we toggle LED 0 as well */ LED_ON(0); } else { LED_OFF(0); @@ -103,7 +95,7 @@ int main(void) /* Set new registry value */ registry_set(¶meter_node, &board_led_enabled, sizeof(board_led_enabled)); - /* Apply the registry value to change the LED state (calls the commit_cb function implemented by the BOARD for example)*/ + /* Apply the registry value to change the LED state (in this case calls the commit_cb function: "board_led_instance_commit_cb")*/ registry_commit(¶meter_node); /* Sleep for 1 second and then do it again*/ From 845bf27a1a686e1b59d19e7810a8ea6ee6dab173 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 15:24:46 +0200 Subject: [PATCH 044/117] fixup! sys: add runtime configuration registry Fix typos --- sys/include/registry.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/include/registry.h b/sys/include/registry.h index 39e08d67ebbc..c88ddc2bc88a 100644 --- a/sys/include/registry.h +++ b/sys/include/registry.h @@ -104,8 +104,8 @@ typedef const enum { } registry_commit_cb_scope_t; /** - * @brief Callback must be implemented by modules / drivers that integrate a configuration schema. - * This callback is called when the registry notifies the module / driver, that a configuration + * @brief The callback must be implemented by modules that integrate a configuration schema. + * This callback is called when the registry notifies the module, that a configuration * parameter has changed. * * @param[in] scope Scope of what will be committed (a parameter, a group or the whole instance). From 423d209bc550ff0244c15fa9fe109929971988c9 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 17:29:30 +0200 Subject: [PATCH 045/117] fixup! sys: add runtime configuration registry Improve documentation --- sys/include/registry.h | 78 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 15 deletions(-) diff --git a/sys/include/registry.h b/sys/include/registry.h index c88ddc2bc88a..bc8cf527126f 100644 --- a/sys/include/registry.h +++ b/sys/include/registry.h @@ -67,7 +67,10 @@ typedef enum { REGISTRY_TYPE_FLOAT64, /**< 64-bits float. */ } registry_type_t; -// TODO Documentation +/** + * @brief The type of a registry node. + * A registry node points to a namespace, schema, instance, group or parameter. + */ typedef enum { REGISTRY_NODE_NAMESPACE = 0, REGISTRY_NODE_SCHEMA, @@ -76,16 +79,27 @@ typedef enum { REGISTRY_NODE_PARAMETER, } registry_node_type_t; -// TODO Documentation +/** + * @brief A registry node represents a specific location within the registry configuration tree. + * It can point to a namespace, schema, instance, group or parameter. + * The configuration group and the configuration parameter contain a pointer to a + * schema instance, because they are children of a specific schema instance in the configuration tree. + */ typedef struct { - registry_node_type_t type; - union { - const registry_namespace_t *namespace; - const registry_schema_t *schema; - const registry_group_t *group; - const registry_parameter_t *parameter; - } location; - const registry_instance_t *instance; + registry_node_type_t type; /**< The type of the node */ + union { + const registry_namespace_t *namespace; /**< Pointer to the configuration namespace */ + const registry_schema_t *schema; /**< Pointer to a configuration schema */ + const registry_instance_t *instance; /**< Pointer to a schema instance */ + struct { + const registry_instance_t *instance; /**< Pointer to a schema instance */ + const registry_group_t *group; /**< Pointer to a configuration group */ + } group; /**< A configuration group depends on an instance */ + struct { + const registry_instance_t *instance; /**< Pointer to a schema instance */ + const registry_parameter_t *parameter; /**< Pointer to a configuration parameter */ + } parameter; /**< A configuration parameter depends on an instance */ + } value; /**< The location inside of the configuration tree */ } registry_node_t; /** @@ -97,8 +111,11 @@ typedef struct { size_t buf_len; /**< Length of the buffer. */ } registry_value_t; +/** + * @brief The different scopes of a registry @p commit_cb function. + */ typedef const enum { - REGISTRY_COMMIT_INSTANCE, + REGISTRY_COMMIT_INSTANCE = 0, REGISTRY_COMMIT_GROUP, REGISTRY_COMMIT_PARAMETER, } registry_commit_cb_scope_t; @@ -119,10 +136,12 @@ typedef int (*registry_commit_cb_t)(const registry_commit_cb_scope_t scope, const void *context); /** - * @brief Instance of a schema containing its data. + * @brief Instance of a schema containing its configuration parameters values. + * The instance of a configuration schema is created by the modules that need to expose runtime configurations. + * The modules also implement the @p commit_cb function to react to configuration changes. */ struct _registry_instance_t { - clist_node_t node; /**< Linked list node. */ + clist_node_t node; /**< Linked list node pointing to the next schema instance. */ const registry_instance_id_t id; /**< Integer representing the path id of the schema instance. */ #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) const char * const name; /**< String describing the instance. */ @@ -130,10 +149,14 @@ struct _registry_instance_t { const void * const data; /**< Struct containing all configuration parameters of the schema. */ const registry_schema_t *schema; /**< Configuration Schema that the Schema Instance belongs to. */ registry_commit_cb_t commit_cb; /**< Will be called after @ref registry_commit() was called on this instance. */ - void *context; /**< Optional context used by the instance */ }; +/** + * @brief Data structure of a configuration group. + * A configuration group contains further configuration groups and/or configuration parameters. + * It has an ID that is unique within the scope of its parent configuration schema. + */ struct _registry_group_t { const registry_group_id_t id; /**< Integer representing the ID of the configuration group. */ #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -149,6 +172,11 @@ struct _registry_group_t { const size_t parameters_len; /**< Size of parameters array. */ }; +/** + * @brief Data structure of a configuration parameter. + * A configuration parameter mostly holds the type information for a configuration value. + * It has an ID that is unique within the scope of its parent configuration schema. + */ struct _registry_parameter_t { const registry_parameter_id_t id; /**< Integer representing the ID of the configuration parameter. */ #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -162,7 +190,10 @@ struct _registry_parameter_t { }; /** - * @brief Schema containing available configuration parameters. + * @brief Data structure of a configuration schema. + * A configuration schema contains configuration configuration groups and/or configuration parameters. + * Besides that it also contains a list of instances that hold the actual configuration parameter values. + * It has an ID that is unique within the scope of its parent configuration namespace. */ struct _registry_schema_t { const registry_schema_id_t id; /**< Integer representing the ID of the schema. */ @@ -193,6 +224,13 @@ struct _registry_schema_t { size_t *val_len); }; +/** + * @brief Data structure of a configuration namespace. + * A configuration namespace contains configuration schemas. + * It exists to prevent ID collisions between RIOT internal configuration schemas + * and schemas defined by applications running on RIOT. + * It has an ID that is unique within the scope of the RIOT registry itself. + */ struct _registry_namespace_t { const registry_namespace_id_t id; /**< Integer representing the ID of the namespace. */ #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -257,6 +295,16 @@ int registry_set(const registry_node_t *node, const void *buf, const size_t buf_ */ int registry_commit(const registry_node_t *node); +/** + * @brief Callback definition of the @p registry_export function. + * This callback will be called for each location inside of the configuration tree that is + * within the scope of the registry node passed on to the @p registry_export function. + * + * @param[in] node A location within the registry configuration tree. + * @param[in] context Context that is passed by the @p registry_export function. + * + * @return 0 on success, non-zero on failure. + */ typedef int (*registry_export_cb_t)(const registry_node_t *node, const void *context); #define REGISTRY_EXPORT_ALL = 0; From bdfc315a6b3717ac33a3c09ca6e0a88001f29d1b Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:15:31 +0200 Subject: [PATCH 046/117] fixup! sys/shell: add registry cli Fix new registry_node_t format --- sys/shell/cmds/registry.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/shell/cmds/registry.c b/sys/shell/cmds/registry.c index 034adb3fdccc..1083981ecfd5 100644 --- a/sys/shell/cmds/registry.c +++ b/sys/shell/cmds/registry.c @@ -136,23 +136,23 @@ static int _export_cb(const registry_node_t *node, const void *context) /* print the path element, that is currently being exported */ switch (node->type) { case REGISTRY_NODE_NAMESPACE: - printf("%d %s\n", node->location.namespace->id, node->location.namespace->name); + printf("%d %s\n", node->value.namespace->id, node->value.namespace->name); break; case REGISTRY_NODE_SCHEMA: - printf("%d %s\n", node->location.schema->id, node->location.schema->name); + printf("%d %s\n", node->value.schema->id, node->value.schema->name); break; case REGISTRY_NODE_INSTANCE: - printf("%d %s\n", node->instance->id, node->instance->name); + printf("%d %s\n", node->value.instance->id, node->value.instance->name); break; case REGISTRY_NODE_GROUP: - printf("%d %s (group)\n", node->location.group->id, node->location.group->name); + printf("%d %s (group)\n", node->value.group.group->id, node->value.group.group->name); break; case REGISTRY_NODE_PARAMETER: - printf("%d %s\n", node->location.parameter->id, node->location.parameter->name); + printf("%d %s\n", node->value.parameter.parameter->id, node->value.parameter.parameter->name); break; } From 9d8da1326603d393c691927c76e581e9debd3ce7 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:16:37 +0200 Subject: [PATCH 047/117] fixup! examples: add registry_core example Fix new registry_node_t format --- examples/registry_core/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/registry_core/main.c b/examples/registry_core/main.c index bc6cb88ada8a..656d36c17ef6 100644 --- a/examples/registry_core/main.c +++ b/examples/registry_core/main.c @@ -88,8 +88,10 @@ int main(void) /* Create registry_node_t for the board_led_parameter */ const registry_node_t parameter_node = { .type = REGISTRY_NODE_PARAMETER, - .instance = &board_led_instance, - .location.parameter = ®istry_sys_board_led_enabled, + .value.parameter = { + .instance = &board_led_instance, + .parameter = ®istry_sys_board_led_enabled, + }, }; /* Set new registry value */ From 66a8e2b508555920c1e7209b88d7ff213f72e141 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:17:19 +0200 Subject: [PATCH 048/117] fixup! sys/registry: add string_path module Fix new registry_node_t format --- sys/registry/string_path.c | 67 ++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/sys/registry/string_path.c b/sys/registry/string_path.c index fc21f7f8b463..226eb311090b 100644 --- a/sys/registry/string_path.c +++ b/sys/registry/string_path.c @@ -169,7 +169,7 @@ static int _group_or_parameter_lookup(const char *path, const registry_schema_t /* parameter matches => return parameters */ if (strlen(ptr + path_position) == name_length && strncmp(ptr + path_position, parameters[i]->name, name_length) == 0) { - node->location.parameter = parameters[i]; + node->value.parameter.parameter = parameters[i]; node->type = REGISTRY_NODE_PARAMETER; return path_position + name_length + 1; /* name_length + `/` character */ } @@ -210,7 +210,7 @@ static int _group_or_parameter_lookup(const char *path, const registry_schema_t /* end of path => return group if it matches */ else if (*(ptr + path_position + name_length) == '\0' && strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { - node->location.group = groups[i]; + node->value.group.group = groups[i]; node->type = REGISTRY_NODE_GROUP; return path_position + name_length + 1; /* name_length + `/` character */ } @@ -289,42 +289,42 @@ int registry_node_to_string_path(const registry_node_t *node, char *path) switch (node->type) { case REGISTRY_NODE_NAMESPACE: - size = snprintf(NULL, 0, "/%s", node->location.namespace->name); + size = snprintf(NULL, 0, "/%s", node->value.namespace->name); if (path != NULL) { - return snprintf(path, size + 1, "/%s", node->location.namespace->name); + return snprintf(path, size + 1, "/%s", node->value.namespace->name); } break; case REGISTRY_NODE_SCHEMA: - size = snprintf(NULL, 0, "/%s/%s", node->location.schema->namespace->name, node->location.schema->name); + size = snprintf(NULL, 0, "/%s/%s", node->value.schema->namespace->name, node->value.schema->name); if (path != NULL) { - return snprintf(path, size + 1, "/%s/%s", node->location.schema->namespace->name, node->location.schema->name); + return snprintf(path, size + 1, "/%s/%s", node->value.schema->namespace->name, node->value.schema->name); } break; case REGISTRY_NODE_INSTANCE: - size = snprintf(NULL, 0, "/%s/%s/%s", node->instance->schema->namespace->name, - node->instance->schema->name, node->instance->name); + size = snprintf(NULL, 0, "/%s/%s/%s", node->value.instance->schema->namespace->name, + node->value.instance->schema->name, node->value.instance->name); if (path != NULL) { - return snprintf(path, size + 1, "/%s/%s/%s", node->instance->schema->namespace->name, - node->instance->schema->name, node->instance->name); + return snprintf(path, size + 1, "/%s/%s/%s", node->value.instance->schema->namespace->name, + node->value.instance->schema->name, node->value.instance->name); } break; case REGISTRY_NODE_GROUP: - size = snprintf(NULL, 0, "/%s/%s/%s", node->instance->schema->namespace->name, - node->instance->schema->name, node->instance->name); + size = snprintf(NULL, 0, "/%s/%s/%s", node->value.group.instance->schema->namespace->name, + node->value.group.instance->schema->name, node->value.group.instance->name); if (path != NULL) { - snprintf(path, size + 1, "/%s/%s/%s", node->instance->schema->namespace->name, - node->instance->schema->name, node->instance->name); + snprintf(path, size + 1, "/%s/%s/%s", node->value.group.instance->schema->namespace->name, + node->value.group.instance->schema->name, node->value.group.instance->name); } - for (size_t i = 0; i < node->instance->schema->groups_len; i++) { - int res = _internal_registry_to_group_string_path(node->instance->schema->groups[i], node->location.group, + for (size_t i = 0; i < node->value.group.instance->schema->groups_len; i++) { + int res = _internal_registry_to_group_string_path(node->value.group.instance->schema->groups[i], node->value.group.group, path != NULL ? path + size : NULL); if (res >= 0) { return size += res; @@ -335,21 +335,21 @@ int registry_node_to_string_path(const registry_node_t *node, char *path) break; case REGISTRY_NODE_PARAMETER: - size = snprintf(NULL, 0, "/%s/%s/%s", node->instance->schema->namespace->name, - node->instance->schema->name, node->instance->name); + size = snprintf(NULL, 0, "/%s/%s/%s", node->value.parameter.instance->schema->namespace->name, + node->value.parameter.instance->schema->name, node->value.parameter.instance->name); if (path != NULL) { - snprintf(path, size + 1, "/%s/%s/%s", node->instance->schema->namespace->name, - node->instance->schema->name, node->instance->name); + snprintf(path, size + 1, "/%s/%s/%s", node->value.parameter.instance->schema->namespace->name, + node->value.parameter.instance->schema->name, node->value.parameter.instance->name); } /* check if the parameter is a child of this schema */ - for (size_t i = 0; i < node->instance->schema->parameters_len; i++) { - if (node->instance->schema->parameters[i] == node->location.parameter) { - int sub_size = snprintf(NULL, 0, "/%s", node->instance->schema->parameters[i]->name); + for (size_t i = 0; i < node->value.parameter.instance->schema->parameters_len; i++) { + if (node->value.parameter.instance->schema->parameters[i] == node->value.parameter.parameter) { + int sub_size = snprintf(NULL, 0, "/%s", node->value.parameter.instance->schema->parameters[i]->name); if (path != NULL) { - snprintf(path + size, sub_size + 1, "/%s", node->instance->schema->parameters[i]->name); + snprintf(path + size, sub_size + 1, "/%s", node->value.parameter.instance->schema->parameters[i]->name); } return size + sub_size; @@ -357,9 +357,9 @@ int registry_node_to_string_path(const registry_node_t *node, char *path) } /* check if the parameter is the child of a group */ - for (size_t i = 0; i < node->instance->schema->groups_len; i++) { - int res = _internal_registry_to_parameter_string_path(node->instance->schema->groups[i], - node->location.parameter, + for (size_t i = 0; i < node->value.parameter.instance->schema->groups_len; i++) { + int res = _internal_registry_to_parameter_string_path(node->value.parameter.instance->schema->groups[i], + node->value.parameter.parameter, path != NULL ? path + size : NULL); if (res >= 0) { return size += res; @@ -384,7 +384,7 @@ int registry_node_from_string_path(const char *path, const size_t path_len, regi if (res >= 0) { node->type = REGISTRY_NODE_NAMESPACE; - node->location.namespace = found_namespace; + node->value.namespace = found_namespace; path_position += res; @@ -395,7 +395,7 @@ int registry_node_from_string_path(const char *path, const size_t path_len, regi if (res >= 0) { node->type = REGISTRY_NODE_SCHEMA; - node->location.schema = found_schema; + node->value.schema = found_schema; path_position += res; @@ -406,14 +406,19 @@ int registry_node_from_string_path(const char *path, const size_t path_len, regi if (res >= 0) { node->type = REGISTRY_NODE_INSTANCE; - node->location.schema = NULL; - node->instance = found_instance; + node->value.instance = found_instance; path_position += res; if (path_position < path_len - 1) { /* group or parameter */ res = _group_or_parameter_lookup(path + path_position, found_schema, node); + + if (node->type == REGISTRY_NODE_GROUP) { + node->value.group.instance = found_instance; + } else if (node->type == REGISTRY_NODE_PARAMETER) { + node->value.parameter.instance = found_instance; + } } } } From 1828302344e45c7607cbd7c96cb6fb87402d32c6 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:17:49 +0200 Subject: [PATCH 049/117] fixup! sys/registry: add int_path module Fix new registry_node_t format --- sys/registry/int_path.c | 50 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/sys/registry/int_path.c b/sys/registry/int_path.c index 8cf61548583e..aada6955d51a 100644 --- a/sys/registry/int_path.c +++ b/sys/registry/int_path.c @@ -185,36 +185,36 @@ int registry_node_to_int_path(const registry_node_t *node, registry_int_path_t * { case REGISTRY_NODE_NAMESPACE: path->type = REGISTRY_INT_PATH_TYPE_NAMESPACE; - path->value.namespace_path.namespace_id = node->location.namespace->id; + path->value.namespace_path.namespace_id = node->value.namespace->id; break; case REGISTRY_NODE_SCHEMA: path->type = REGISTRY_INT_PATH_TYPE_SCHEMA; - path->value.schema_path.namespace_id = node->location.schema->namespace->id; - path->value.schema_path.schema_id = node->location.schema->id; + path->value.schema_path.namespace_id = node->value.schema->namespace->id; + path->value.schema_path.schema_id = node->value.schema->id; break; case REGISTRY_NODE_INSTANCE: path->type = REGISTRY_INT_PATH_TYPE_INSTANCE; - path->value.instance_path.namespace_id = node->instance->schema->namespace->id; - path->value.instance_path.schema_id = node->instance->schema->id; - path->value.instance_path.instance_id = node->instance->id; + path->value.instance_path.namespace_id = node->value.instance->schema->namespace->id; + path->value.instance_path.schema_id = node->value.instance->schema->id; + path->value.instance_path.instance_id = node->value.instance->id; break; case REGISTRY_NODE_GROUP: path->type = REGISTRY_INT_PATH_TYPE_GROUP; - path->value.group_path.namespace_id = node->location.group->schema->namespace->id; - path->value.group_path.schema_id = node->location.group->schema->id; - path->value.group_path.instance_id = node->instance->id; - path->value.group_path.group_id = node->location.group->id; + path->value.group_path.namespace_id = node->value.group.group->schema->namespace->id; + path->value.group_path.schema_id = node->value.group.group->schema->id; + path->value.group_path.instance_id = node->value.group.instance->id; + path->value.group_path.group_id = node->value.group.group->id; break; case REGISTRY_NODE_PARAMETER: path->type = REGISTRY_INT_PATH_TYPE_PARAMETER; - path->value.parameter_path.namespace_id = node->location.parameter->schema->namespace->id; - path->value.parameter_path.schema_id = node->location.parameter->schema->id; - path->value.parameter_path.instance_id = node->instance->id; - path->value.parameter_path.parameter_id = node->location.parameter->id; + path->value.parameter_path.namespace_id = node->value.parameter.parameter->schema->namespace->id; + path->value.parameter_path.schema_id = node->value.parameter.parameter->schema->id; + path->value.parameter_path.instance_id = node->value.parameter.instance->id; + path->value.parameter_path.parameter_id = node->value.parameter.parameter->id; break; } @@ -279,7 +279,7 @@ int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t if (res == 0) { if (path->type == REGISTRY_INT_PATH_TYPE_NAMESPACE) { node->type = REGISTRY_NODE_NAMESPACE; - node->location.namespace = namespace; + node->value.namespace = namespace; return res; } @@ -290,7 +290,7 @@ int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t if (res == 0) { if (path->type == REGISTRY_INT_PATH_TYPE_SCHEMA) { node->type = REGISTRY_NODE_SCHEMA; - node->location.schema = schema; + node->value.schema = schema; return res; } @@ -301,23 +301,23 @@ int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t if (res == 0) { if (path->type == REGISTRY_INT_PATH_TYPE_INSTANCE) { node->type = REGISTRY_NODE_INSTANCE; - node->instance = instance; + node->value.instance = instance; return res; } /* Group or Parameter */ if (path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { - node->instance = instance; - - res = _group_lookup(schema, group_or_parameter_id, &node->location.group); + res = _group_lookup(schema, group_or_parameter_id, &node->value.group.group); if (res == 0) { node->type = REGISTRY_NODE_GROUP; + node->value.group.instance = instance; return res; } - res = _parameter_lookup(schema, group_or_parameter_id, &node->location.parameter); + res = _parameter_lookup(schema, group_or_parameter_id, &node->value.parameter.parameter); if (res == 0) { node->type = REGISTRY_NODE_PARAMETER; + node->value.parameter.instance = instance; return res; } } @@ -325,15 +325,15 @@ int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t /* Group */ if (path->type == REGISTRY_INT_PATH_TYPE_GROUP) { node->type = REGISTRY_NODE_GROUP; - node->instance = instance; - return _group_lookup(schema, group_id, &node->location.group); + node->value.group.instance = instance; + return _group_lookup(schema, group_id, &node->value.group.group); } /* Parameter */ if (path->type == REGISTRY_INT_PATH_TYPE_PARAMETER) { node->type = REGISTRY_NODE_PARAMETER; - node->instance = instance; - return _parameter_lookup(schema, parameter_id, &node->location.parameter); + node->value.parameter.instance = instance; + return _parameter_lookup(schema, parameter_id, &node->value.parameter.parameter); } } } From 2d8867033938a531d5c959a2ec065048bb84a099 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:18:19 +0200 Subject: [PATCH 050/117] fixup! sys/registry: add persistent storage module Fix new registry_node_t format --- sys/registry/storage/storage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/registry/storage/storage.c b/sys/registry/storage/storage.c index 342ba81b150d..aa69f762eab2 100644 --- a/sys/registry/storage/storage.c +++ b/sys/registry/storage/storage.c @@ -40,8 +40,8 @@ XFA_INIT_CONST(registry_storage_instance_t *, _registry_storage_instances_src_xf static int _registry_load_cb(const registry_node_t *node, const void *buf, const size_t buf_len) { assert(node->type == REGISTRY_NODE_PARAMETER); - assert(node->location.parameter != NULL); - assert(node->instance != NULL); + assert(node->value.parameter.parameter != NULL); + assert(node->value.parameter.instance != NULL); return registry_set(node, buf, buf_len); } From fb8e41e6c12a3f4d8b7086496d71b060ce495010 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:18:50 +0200 Subject: [PATCH 051/117] fixup! sys/registry/storage: add vfs based storage Fix new registry_node_t format --- sys/registry/storage/storage_vfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/registry/storage/storage_vfs.c b/sys/registry/storage/storage_vfs.c index beac285bb5b0..e65d52c48d8e 100644 --- a/sys/registry/storage/storage_vfs.c +++ b/sys/registry/storage/storage_vfs.c @@ -279,8 +279,8 @@ static int save(const registry_storage_instance_t *storage, const registry_value_t *value) { assert(node->type == REGISTRY_NODE_PARAMETER); - assert(node->location.parameter != NULL); - assert(node->instance != NULL); + assert(node->value.parameter.parameter != NULL); + assert(node->value.parameter.instance != NULL); vfs_mount_t *mount = storage->data; From 671acff2a7a529a509327186373a33d4f558afc6 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:19:11 +0200 Subject: [PATCH 052/117] fixup! sys/registry/storage: add heap based storage Fix new registry_node_t format --- sys/registry/storage/storage_heap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/registry/storage/storage_heap.c b/sys/registry/storage/storage_heap.c index 201c916f9e1d..5f39ddd62d04 100644 --- a/sys/registry/storage/storage_heap.c +++ b/sys/registry/storage/storage_heap.c @@ -73,15 +73,15 @@ static int save(const registry_storage_instance_t *storage, const registry_value_t *value) { assert(node->type == REGISTRY_NODE_PARAMETER); - assert(node->location.parameter != NULL); - assert(node->instance != NULL); + assert(node->value.parameter.parameter != NULL); + assert(node->value.parameter.instance != NULL); (void)storage; /* Search value in storage */ for (size_t i = 0; i < heap_storage_len; i++) { - if (heap_storage[i].node.instance == node->instance && - heap_storage[i].node.location.parameter == node->location.parameter) { + if (heap_storage[i].node.value.parameter.instance == node->value.parameter.instance && + heap_storage[i].node.value.parameter.parameter == node->value.parameter.parameter) { memcpy(heap_storage[i].buf, value->buf, value->buf_len); return 0; } From f2b82ee710f464a1e75b7e8e61228df94f0e47b7 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:19:30 +0200 Subject: [PATCH 053/117] fixup! sys: add runtime configuration registry Fix new registry_node_t format --- sys/registry/registry.c | 52 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/sys/registry/registry.c b/sys/registry/registry.c index 4dc16f39250e..a5cddc3bf057 100644 --- a/sys/registry/registry.c +++ b/sys/registry/registry.c @@ -63,7 +63,7 @@ int registry_get(const registry_node_t *node, registry_value_t *value) assert(node != NULL); assert(value != NULL); - if (node->type != REGISTRY_NODE_PARAMETER || node->instance == NULL) { + if (node->type != REGISTRY_NODE_PARAMETER) { return -REGISTRY_ERROR_NODE_INVALID; } @@ -71,9 +71,9 @@ int registry_get(const registry_node_t *node, registry_value_t *value) void *intern_val = NULL; size_t intern_val_len; - const registry_parameter_t *parameter = node->location.parameter; + const registry_parameter_t *parameter = node->value.parameter.parameter; - parameter->schema->mapping(parameter->id, node->instance, &intern_val, &intern_val_len); + parameter->schema->mapping(parameter->id, node->value.parameter.instance, &intern_val, &intern_val_len); /* update buf pointer in registry_value_t to point to the value inside the registry and set buf_len */ value->type = parameter->type; @@ -88,7 +88,7 @@ int registry_set(const registry_node_t *node, const void *buf, const size_t buf_ assert(node != NULL); assert(buf != NULL); - if (node->type != REGISTRY_NODE_PARAMETER || node->instance == NULL) { + if (node->type != REGISTRY_NODE_PARAMETER) { return -REGISTRY_ERROR_NODE_INVALID; } @@ -96,9 +96,9 @@ int registry_set(const registry_node_t *node, const void *buf, const size_t buf_ void *intern_val = NULL; size_t intern_val_len; - const registry_parameter_t *parameter = node->location.parameter; + const registry_parameter_t *parameter = node->value.parameter.parameter; - parameter->schema->mapping(parameter->id, node->instance, &intern_val, &intern_val_len); + parameter->schema->mapping(parameter->id, node->value.parameter.instance, &intern_val, &intern_val_len); if (buf_len > intern_val_len) { return -EINVAL; @@ -195,19 +195,19 @@ int registry_commit(const registry_node_t *node) { switch (node->type) { case REGISTRY_NODE_NAMESPACE: - rc = _registry_commit_namespace(node->location.namespace); + rc = _registry_commit_namespace(node->value.namespace); break; case REGISTRY_NODE_SCHEMA: - rc = _registry_commit_schema(node->location.schema); + rc = _registry_commit_schema(node->value.schema); break; case REGISTRY_NODE_INSTANCE: - rc = _registry_commit_instance(node->instance); + rc = _registry_commit_instance(node->value.instance); break; case REGISTRY_NODE_GROUP: - rc = _registry_commit_group(node->instance, node->location.group); + rc = _registry_commit_group(node->value.group.instance, node->value.group.group); break; case REGISTRY_NODE_PARAMETER: - rc = _registry_commit_parameter(node->instance, node->location.parameter); + rc = _registry_commit_parameter(node->value.parameter.instance, node->value.parameter.parameter); break; } } @@ -223,8 +223,10 @@ static int _registry_export_parameter(const registry_instance_t *instance, const registry_node_t export_node = { .type = REGISTRY_NODE_PARAMETER, - .instance = instance, - .location.parameter = parameter, + .value.parameter = { + .instance = instance, + .parameter = parameter, + }, }; return export_cb(&export_node, context); @@ -239,8 +241,10 @@ static int _registry_export_group(const registry_instance_t *instance, const reg /* export the given configuration group */ const registry_node_t export_node = { .type = REGISTRY_NODE_GROUP, - .instance = NULL, - .location.group = group, + .value.group = { + .instance = instance, + .group = group, + }, }; int rc = export_cb(&export_node, context); @@ -288,7 +292,7 @@ static int _registry_export_instance(const registry_instance_t *instance, /* export the given configuration schema instance */ const registry_node_t export_node = { .type = REGISTRY_NODE_INSTANCE, - .instance = instance, + .value.instance = instance, }; int rc = export_cb(&export_node, context); @@ -336,8 +340,7 @@ static int _registry_export_schema(const registry_schema_t *schema, const regist /* export the given configuration schema */ const registry_node_t export_node = { .type = REGISTRY_NODE_SCHEMA, - .instance = NULL, - .location.schema = schema, + .value.schema = schema, }; int rc = export_cb(&export_node, context); @@ -385,8 +388,7 @@ static int _registry_export_namespace(const registry_namespace_t *namespace, /* export the given namespace */ const registry_node_t export_node = { .type = REGISTRY_NODE_NAMESPACE, - .instance = NULL, - .location.namespace = namespace, + .value.namespace = namespace, }; int rc = export_cb(&export_node, context); @@ -433,19 +435,19 @@ int registry_export(const registry_node_t *node, const registry_export_cb_t expo switch (node->type) { case REGISTRY_NODE_NAMESPACE: - rc = _registry_export_namespace(node->location.namespace, export_cb, tree_traversal_depth, context); + rc = _registry_export_namespace(node->value.namespace, export_cb, tree_traversal_depth, context); break; case REGISTRY_NODE_SCHEMA: - rc = _registry_export_schema(node->location.schema, export_cb, tree_traversal_depth, context); + rc = _registry_export_schema(node->value.schema, export_cb, tree_traversal_depth, context); break; case REGISTRY_NODE_INSTANCE: - rc = _registry_export_instance(node->instance, export_cb, tree_traversal_depth, context); + rc = _registry_export_instance(node->value.instance, export_cb, tree_traversal_depth, context); break; case REGISTRY_NODE_GROUP: - rc = _registry_export_group(node->instance, node->location.group, export_cb, tree_traversal_depth, context); + rc = _registry_export_group(node->value.group.instance, node->value.group.group, export_cb, tree_traversal_depth, context); break; case REGISTRY_NODE_PARAMETER: - rc = _registry_export_parameter(node->instance, node->location.parameter, export_cb, context); + rc = _registry_export_parameter(node->value.parameter.instance, node->value.parameter.parameter, export_cb, context); break; } } From b668ccb3d9752ae9fe98391abf2dbeaafee7772c Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:20:23 +0200 Subject: [PATCH 054/117] fixup! tests/unittests: add registry tests Fix new registry_node_t format --- tests/unittests/tests-registry/tests-commit.c | 18 ++-- tests/unittests/tests-registry/tests-export.c | 39 +++++---- .../unittests/tests-registry/tests-get-set.c | 84 +++++++++---------- 3 files changed, 74 insertions(+), 67 deletions(-) diff --git a/tests/unittests/tests-registry/tests-commit.c b/tests/unittests/tests-registry/tests-commit.c index 3405f0fb1aeb..c35cefdb71b2 100644 --- a/tests/unittests/tests-registry/tests-commit.c +++ b/tests/unittests/tests-registry/tests-commit.c @@ -131,8 +131,10 @@ static void tests_registry_commit_parameter(void) const registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .location.parameter = ®istry_tests_nested_parameter, - .instance = &test_nested_instance_parameter_test, + .value.parameter = { + .instance = &test_nested_instance_parameter_test, + .parameter = ®istry_tests_nested_parameter, + }, }; registry_commit(&node); @@ -147,8 +149,10 @@ static void tests_registry_commit_group(void) const registry_node_t node = { .type = REGISTRY_NODE_GROUP, - .location.group = ®istry_tests_nested_group, - .instance = &test_nested_instance_group_test, + .value.group = { + .instance = &test_nested_instance_group_test, + .group = ®istry_tests_nested_group, + }, }; registry_commit(&node); @@ -162,7 +166,7 @@ static void tests_registry_commit_instance(void) const registry_node_t node = { .type = REGISTRY_NODE_INSTANCE, - .instance = &test_nested_instance_instance_test, + .value.instance = &test_nested_instance_instance_test, }; registry_commit(&node); @@ -176,7 +180,7 @@ static void tests_registry_commit_schema(void) const registry_node_t node = { .type = REGISTRY_NODE_SCHEMA, - .location.schema = ®istry_tests_nested, + .value.schema = ®istry_tests_nested, }; registry_commit(&node); @@ -190,7 +194,7 @@ static void tests_registry_commit_namespace(void) const registry_node_t node = { .type = REGISTRY_NODE_NAMESPACE, - .location.namespace = ®istry_tests, + .value.namespace = ®istry_tests, }; registry_commit(&node); diff --git a/tests/unittests/tests-registry/tests-export.c b/tests/unittests/tests-registry/tests-export.c index 4eefdd1dabc3..33d58259b6f6 100644 --- a/tests/unittests/tests-registry/tests-export.c +++ b/tests/unittests/tests-registry/tests-export.c @@ -55,9 +55,9 @@ static int export_parameter_cb(const registry_node_t *node, { (void)context; - if (node->type == REGISTRY_NODE_PARAMETER && node->location.parameter != NULL && - node->location.parameter->id == *(registry_parameter_id_t *)context && - node->instance == &test_nested_instance_1) { + if (node->type == REGISTRY_NODE_PARAMETER && node->value.parameter.parameter != NULL && + node->value.parameter.parameter->id == *(registry_parameter_id_t *)context && + node->value.parameter.instance == &test_nested_instance_1) { successful = true; } @@ -69,8 +69,8 @@ static int export_group_cb(const registry_node_t *node, { (void)context; - if (node->type == REGISTRY_NODE_GROUP && node->location.group != NULL && - node->location.group->id == *(registry_group_id_t *)context) { + if (node->type == REGISTRY_NODE_GROUP && node->value.group.group != NULL && + node->value.group.group->id == *(registry_group_id_t *)context) { successful = true; } @@ -82,8 +82,7 @@ static int export_instance_cb(const registry_node_t *node, { (void)context; - if (node->type == REGISTRY_NODE_INSTANCE && node->instance != NULL && - node->instance == &test_nested_instance_1) { + if (node->type == REGISTRY_NODE_INSTANCE && node->value.instance == &test_nested_instance_1) { successful = true; } @@ -95,8 +94,8 @@ static int export_schema_cb(const registry_node_t *node, { (void)context; - if (node->type == REGISTRY_NODE_SCHEMA && node->location.schema != NULL && - node->location.schema == ®istry_tests_nested) { + if (node->type == REGISTRY_NODE_SCHEMA && node->value.schema != NULL && + node->value.schema == ®istry_tests_nested) { successful = true; } @@ -108,8 +107,8 @@ static int export_namespace_cb(const registry_node_t *node, { (void)context; - if (node->type == REGISTRY_NODE_NAMESPACE && node->location.namespace != NULL && - node->location.namespace == ®istry_tests) { + if (node->type == REGISTRY_NODE_NAMESPACE && node->value.namespace != NULL && + node->value.namespace == ®istry_tests) { successful = true; } @@ -137,8 +136,10 @@ static void tests_registry_export_parameter(void) const registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .location.parameter = ®istry_tests_nested_parameter, - .instance = &test_nested_instance_1, + .value.parameter = { + .instance = &test_nested_instance_1, + .parameter = ®istry_tests_nested_parameter, + }, }; registry_export(&node, &export_parameter_cb, 0, ¶meter_id); @@ -150,8 +151,10 @@ static void tests_registry_export_group(void) { const registry_node_t node = { .type = REGISTRY_NODE_GROUP, - .location.group = ®istry_tests_nested_group, - .instance = &test_nested_instance_1, + .value.group = { + .instance = &test_nested_instance_1, + .group = ®istry_tests_nested_group, + }, }; /* check if group gets exported */ @@ -191,7 +194,7 @@ static void tests_registry_export_instance(void) { const registry_node_t node = { .type = REGISTRY_NODE_INSTANCE, - .instance = &test_nested_instance_1, + .value.instance = &test_nested_instance_1, }; /* check if instance gets exported */ @@ -231,7 +234,7 @@ static void tests_registry_export_schema(void) { const registry_node_t node = { .type = REGISTRY_NODE_SCHEMA, - .location.schema = ®istry_tests_nested, + .value.schema = ®istry_tests_nested, }; /* check if schema gets exported */ @@ -276,7 +279,7 @@ static void tests_registry_export_namespace(void) { const registry_node_t node = { .type = REGISTRY_NODE_NAMESPACE, - .location.namespace = ®istry_tests, + .value.namespace = ®istry_tests, }; /* check if namespace gets exported */ diff --git a/tests/unittests/tests-registry/tests-get-set.c b/tests/unittests/tests-registry/tests-get-set.c index 1ca95666430f..12c7e48e8e4d 100644 --- a/tests/unittests/tests-registry/tests-get-set.c +++ b/tests/unittests/tests-registry/tests-get-set.c @@ -96,14 +96,14 @@ static void tests_registry_min_values(void) registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .instance = &test_full_instance_1, + .value.parameter.instance = &test_full_instance_1, }; /* opaque */ const registry_tests_full_instance_opaque_t input_opaque = { .value = 0, }; - node.location.parameter = ®istry_tests_full_opaque; + node.value.parameter.parameter = ®istry_tests_full_opaque; registry_set(&node, &input_opaque, sizeof(input_opaque)); registry_get(&node, &output); @@ -113,7 +113,7 @@ static void tests_registry_min_values(void) /* string */ const char input_string[] = ""; - node.location.parameter = ®istry_tests_full_string; + node.value.parameter.parameter = ®istry_tests_full_string; registry_set(&node, input_string, sizeof(input_string)); registry_get(&node, &output); @@ -123,7 +123,7 @@ static void tests_registry_min_values(void) /* bool */ const bool input_bool = false; - node.location.parameter = ®istry_tests_full_boolean; + node.value.parameter.parameter = ®istry_tests_full_boolean; registry_set(&node, &input_bool, sizeof(input_bool)); registry_get(&node, &output); @@ -133,7 +133,7 @@ static void tests_registry_min_values(void) /* u8 */ const uint8_t input_u8 = 0; - node.location.parameter = ®istry_tests_full_u8; + node.value.parameter.parameter = ®istry_tests_full_u8; registry_set(&node, &input_u8, sizeof(input_u8)); registry_get(&node, &output); @@ -143,7 +143,7 @@ static void tests_registry_min_values(void) /* u16 */ const uint16_t input_u16 = 0; - node.location.parameter = ®istry_tests_full_u16; + node.value.parameter.parameter = ®istry_tests_full_u16; registry_set(&node, &input_u16, sizeof(input_u16)); registry_get(&node, &output); @@ -153,7 +153,7 @@ static void tests_registry_min_values(void) /* u32 */ const uint32_t input_u32 = 0; - node.location.parameter = ®istry_tests_full_u32; + node.value.parameter.parameter = ®istry_tests_full_u32; registry_set(&node, &input_u32, sizeof(input_u32)); registry_get(&node, &output); @@ -163,7 +163,7 @@ static void tests_registry_min_values(void) /* u64 */ const uint64_t input_u64 = 0; - node.location.parameter = ®istry_tests_full_u64; + node.value.parameter.parameter = ®istry_tests_full_u64; registry_set(&node, &input_u64, sizeof(input_u64)); registry_get(&node, &output); @@ -173,7 +173,7 @@ static void tests_registry_min_values(void) /* i8 */ const int8_t input_i8 = INT8_MIN; - node.location.parameter = ®istry_tests_full_i8; + node.value.parameter.parameter = ®istry_tests_full_i8; registry_set(&node, &input_i8, sizeof(input_i8)); registry_get(&node, &output); @@ -183,7 +183,7 @@ static void tests_registry_min_values(void) /* i16 */ const int16_t input_i16 = INT16_MIN; - node.location.parameter = ®istry_tests_full_i16; + node.value.parameter.parameter = ®istry_tests_full_i16; registry_set(&node, &input_i16, sizeof(input_i16)); registry_get(&node, &output); @@ -193,7 +193,7 @@ static void tests_registry_min_values(void) /* i32 */ const int32_t input_i32 = INT32_MIN; - node.location.parameter = ®istry_tests_full_i32; + node.value.parameter.parameter = ®istry_tests_full_i32; registry_set(&node, &input_i32, sizeof(input_i32)); registry_get(&node, &output); @@ -203,7 +203,7 @@ static void tests_registry_min_values(void) /* i64 */ const int64_t input_i64 = INT64_MIN; - node.location.parameter = ®istry_tests_full_i64; + node.value.parameter.parameter = ®istry_tests_full_i64; registry_set(&node, &input_i64, sizeof(input_i64)); registry_get(&node, &output); @@ -213,7 +213,7 @@ static void tests_registry_min_values(void) /* f32 */ const float input_f32 = FLT_MIN; - node.location.parameter = ®istry_tests_full_f32; + node.value.parameter.parameter = ®istry_tests_full_f32; registry_set(&node, &input_f32, sizeof(input_f32)); registry_get(&node, &output); @@ -228,7 +228,7 @@ static void tests_registry_min_values(void) /* f64 */ const double input_f64 = DBL_MIN; - node.location.parameter = ®istry_tests_full_f64; + node.value.parameter.parameter = ®istry_tests_full_f64; registry_set(&node, &input_f64, sizeof(input_f64)); registry_get(&node, &output); @@ -247,14 +247,14 @@ static void tests_registry_zero_values(void) registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .instance = &test_full_instance_1, + .value.parameter.instance = &test_full_instance_1, }; /* opaque */ const registry_tests_full_instance_opaque_t input_opaque = { .value = 0, }; - node.location.parameter = ®istry_tests_full_opaque; + node.value.parameter.parameter = ®istry_tests_full_opaque; registry_set(&node, &input_opaque, sizeof(input_opaque)); registry_get(&node, &output); @@ -265,7 +265,7 @@ static void tests_registry_zero_values(void) /* string */ const char input_string[] = ""; - node.location.parameter = ®istry_tests_full_string; + node.value.parameter.parameter = ®istry_tests_full_string; registry_set(&node, input_string, sizeof(input_string)); registry_get(&node, &output); @@ -275,7 +275,7 @@ static void tests_registry_zero_values(void) /* bool */ const bool input_bool = 0; - node.location.parameter = ®istry_tests_full_boolean; + node.value.parameter.parameter = ®istry_tests_full_boolean; registry_set(&node, &input_bool, sizeof(input_bool)); registry_get(&node, &output); @@ -285,7 +285,7 @@ static void tests_registry_zero_values(void) /* u8 */ const uint8_t input_u8 = 0; - node.location.parameter = ®istry_tests_full_u8; + node.value.parameter.parameter = ®istry_tests_full_u8; registry_set(&node, &input_u8, sizeof(input_u8)); registry_get(&node, &output); @@ -295,7 +295,7 @@ static void tests_registry_zero_values(void) /* u16 */ const uint16_t input_u16 = 0; - node.location.parameter = ®istry_tests_full_u16; + node.value.parameter.parameter = ®istry_tests_full_u16; registry_set(&node, &input_u16, sizeof(input_u16)); registry_get(&node, &output); @@ -305,7 +305,7 @@ static void tests_registry_zero_values(void) /* u32 */ const uint32_t input_u32 = 0; - node.location.parameter = ®istry_tests_full_u32; + node.value.parameter.parameter = ®istry_tests_full_u32; registry_set(&node, &input_u32, sizeof(input_u32)); registry_get(&node, &output); @@ -315,7 +315,7 @@ static void tests_registry_zero_values(void) /* u64 */ const uint64_t input_u64 = 0; - node.location.parameter = ®istry_tests_full_u64; + node.value.parameter.parameter = ®istry_tests_full_u64; registry_set(&node, &input_u64, sizeof(input_u64)); registry_get(&node, &output); @@ -325,7 +325,7 @@ static void tests_registry_zero_values(void) /* i8 */ const int8_t input_i8 = 0; - node.location.parameter = ®istry_tests_full_i8; + node.value.parameter.parameter = ®istry_tests_full_i8; registry_set(&node, &input_i8, sizeof(input_i8)); registry_get(&node, &output); @@ -335,7 +335,7 @@ static void tests_registry_zero_values(void) /* i16 */ const int16_t input_i16 = 0; - node.location.parameter = ®istry_tests_full_i16; + node.value.parameter.parameter = ®istry_tests_full_i16; registry_set(&node, &input_i16, sizeof(input_i16)); registry_get(&node, &output); @@ -345,7 +345,7 @@ static void tests_registry_zero_values(void) /* i32 */ const int32_t input_i32 = 0; - node.location.parameter = ®istry_tests_full_i32; + node.value.parameter.parameter = ®istry_tests_full_i32; registry_set(&node, &input_i32, sizeof(input_i32)); registry_get(&node, &output); @@ -355,7 +355,7 @@ static void tests_registry_zero_values(void) /* i64 */ const int64_t input_i64 = 0; - node.location.parameter = ®istry_tests_full_i64; + node.value.parameter.parameter = ®istry_tests_full_i64; registry_set(&node, &input_i64, sizeof(input_i64)); registry_get(&node, &output); @@ -365,7 +365,7 @@ static void tests_registry_zero_values(void) /* f32 */ const float input_f32 = 0.0; - node.location.parameter = ®istry_tests_full_f32; + node.value.parameter.parameter = ®istry_tests_full_f32; registry_set(&node, &input_f32, sizeof(input_f32)); registry_get(&node, &output); @@ -380,7 +380,7 @@ static void tests_registry_zero_values(void) /* f64 */ const double input_f64 = 0.0; - node.location.parameter = ®istry_tests_full_f64; + node.value.parameter.parameter = ®istry_tests_full_f64; registry_set(&node, &input_f64, sizeof(input_f64)); registry_get(&node, &output); @@ -399,14 +399,14 @@ static void tests_registry_max_values(void) registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .instance = &test_full_instance_1, + .value.parameter.instance = &test_full_instance_1, }; /* opaque */ const registry_tests_full_instance_opaque_t input_opaque = { .value = UINT8_MAX, }; - node.location.parameter = ®istry_tests_full_opaque; + node.value.parameter.parameter = ®istry_tests_full_opaque; registry_set(&node, &input_opaque, sizeof(input_opaque)); registry_get(&node, &output); @@ -422,7 +422,7 @@ static void tests_registry_max_values(void) input_string[i] = 'a'; } - node.location.parameter = ®istry_tests_full_string; + node.value.parameter.parameter = ®istry_tests_full_string; registry_set(&node, input_string, sizeof(input_string)); registry_get(&node, &output); @@ -432,7 +432,7 @@ static void tests_registry_max_values(void) /* bool */ const bool input_bool = true; - node.location.parameter = ®istry_tests_full_boolean; + node.value.parameter.parameter = ®istry_tests_full_boolean; registry_set(&node, &input_bool, sizeof(input_bool)); registry_get(&node, &output); @@ -442,7 +442,7 @@ static void tests_registry_max_values(void) /* u8 */ const uint8_t input_u8 = UINT8_MAX; - node.location.parameter = ®istry_tests_full_u8; + node.value.parameter.parameter = ®istry_tests_full_u8; registry_set(&node, &input_u8, sizeof(input_u8)); registry_get(&node, &output); @@ -452,7 +452,7 @@ static void tests_registry_max_values(void) /* u16 */ const uint16_t input_u16 = UINT16_MAX; - node.location.parameter = ®istry_tests_full_u16; + node.value.parameter.parameter = ®istry_tests_full_u16; registry_set(&node, &input_u16, sizeof(input_u16)); registry_get(&node, &output); @@ -462,7 +462,7 @@ static void tests_registry_max_values(void) /* u32 */ const uint32_t input_u32 = UINT32_MAX; - node.location.parameter = ®istry_tests_full_u32; + node.value.parameter.parameter = ®istry_tests_full_u32; registry_set(&node, &input_u32, sizeof(input_u32)); registry_get(&node, &output); @@ -472,7 +472,7 @@ static void tests_registry_max_values(void) /* u64 */ const uint64_t input_u64 = UINT64_MAX; - node.location.parameter = ®istry_tests_full_u64; + node.value.parameter.parameter = ®istry_tests_full_u64; registry_set(&node, &input_u64, sizeof(input_u64)); registry_get(&node, &output); @@ -482,7 +482,7 @@ static void tests_registry_max_values(void) /* i8 */ const int8_t input_i8 = INT8_MAX; - node.location.parameter = ®istry_tests_full_i8; + node.value.parameter.parameter = ®istry_tests_full_i8; registry_set(&node, &input_i8, sizeof(input_i8)); registry_get(&node, &output); @@ -492,7 +492,7 @@ static void tests_registry_max_values(void) /* i16 */ const int16_t input_i16 = INT16_MAX; - node.location.parameter = ®istry_tests_full_i16; + node.value.parameter.parameter = ®istry_tests_full_i16; registry_set(&node, &input_i16, sizeof(input_i16)); registry_get(&node, &output); @@ -502,7 +502,7 @@ static void tests_registry_max_values(void) /* i32 */ const int32_t input_i32 = INT32_MAX; - node.location.parameter = ®istry_tests_full_i32; + node.value.parameter.parameter = ®istry_tests_full_i32; registry_set(&node, &input_i32, sizeof(input_i32)); registry_get(&node, &output); @@ -512,7 +512,7 @@ static void tests_registry_max_values(void) /* i64 */ const int64_t input_i64 = INT64_MAX; - node.location.parameter = ®istry_tests_full_i64; + node.value.parameter.parameter = ®istry_tests_full_i64; registry_set(&node, &input_i64, sizeof(input_i64)); registry_get(&node, &output); @@ -522,7 +522,7 @@ static void tests_registry_max_values(void) /* f32 */ const float input_f32 = FLT_MAX; - node.location.parameter = ®istry_tests_full_f32; + node.value.parameter.parameter = ®istry_tests_full_f32; registry_set(&node, &input_f32, sizeof(input_f32)); registry_get(&node, &output); @@ -537,7 +537,7 @@ static void tests_registry_max_values(void) /* f64 */ const double input_f64 = DBL_MAX; - node.location.parameter = ®istry_tests_full_f64; + node.value.parameter.parameter = ®istry_tests_full_f64; registry_set(&node, &input_f64, sizeof(input_f64)); registry_get(&node, &output); From 06adb075224ef99636b9dd9acefb7d2b2be28faf Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:20:53 +0200 Subject: [PATCH 055/117] fixup! tests/unittests: add registry_int_path tests Fix new registry_node_t format --- .../tests-registry_int_path.c | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tests/unittests/tests-registry_int_path/tests-registry_int_path.c b/tests/unittests/tests-registry_int_path/tests-registry_int_path.c index 9d23ca4ff325..303e0c7baee6 100644 --- a/tests/unittests/tests-registry_int_path/tests-registry_int_path.c +++ b/tests/unittests/tests-registry_int_path/tests-registry_int_path.c @@ -65,8 +65,10 @@ static void tests_registry_to_parameter_int_path(void) { registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .instance = &test_instance, - .location.parameter = ®istry_tests_nested_parameter, + .value.parameter = { + .instance = &test_instance, + .parameter = ®istry_tests_nested_parameter, + }, }; registry_int_path_t path; int res = registry_node_to_int_path(&node, &path); @@ -82,8 +84,10 @@ static void tests_registry_to_group_int_path(void) { registry_node_t node = { .type = REGISTRY_NODE_GROUP, - .instance = &test_instance, - .location.group = ®istry_tests_nested_group, + .value.group = { + .instance = &test_instance, + .group = ®istry_tests_nested_group, + }, }; registry_int_path_t path; int res = registry_node_to_int_path(&node, &path); @@ -99,7 +103,7 @@ static void tests_registry_to_instance_int_path(void) { registry_node_t node = { .type = REGISTRY_NODE_INSTANCE, - .instance = &test_instance, + .value.instance = &test_instance, }; registry_int_path_t path; int res = registry_node_to_int_path(&node, &path); @@ -114,7 +118,7 @@ static void tests_registry_to_schema_int_path(void) { registry_node_t node = { .type = REGISTRY_NODE_SCHEMA, - .location.schema = ®istry_tests_nested, + .value.schema = ®istry_tests_nested, }; registry_int_path_t path; int res = registry_node_to_int_path(&node, &path); @@ -128,7 +132,7 @@ static void tests_registry_to_namespace_int_path(void) { registry_node_t node = { .type = REGISTRY_NODE_NAMESPACE, - .location.namespace = ®istry_tests, + .value.namespace = ®istry_tests, }; registry_int_path_t path; int res = registry_node_to_int_path(&node, &path); @@ -157,8 +161,8 @@ static void tests_registry_from_group_or_parameter_int_path(void) TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)node.location.parameter); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.value.parameter.instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)node.value.parameter.parameter); /* group */ @@ -176,8 +180,8 @@ static void tests_registry_from_group_or_parameter_int_path(void) TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_GROUP, node.type); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)node.location.group); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.value.group.instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)node.value.group.group); } static void tests_registry_from_parameter_int_path(void) @@ -198,8 +202,8 @@ static void tests_registry_from_parameter_int_path(void) TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)node.location.parameter); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.value.parameter.instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)node.value.parameter.parameter); } static void tests_registry_from_group_int_path(void) @@ -220,8 +224,8 @@ static void tests_registry_from_group_int_path(void) TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_GROUP, node.type); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)node.location.group); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.value.group.instance); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group, (int)node.value.group.group); } static void tests_registry_from_instance_int_path(void) @@ -241,7 +245,7 @@ static void tests_registry_from_instance_int_path(void) TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_INSTANCE, node.type); - TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.instance); + TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.value.instance); } static void tests_registry_from_schema_int_path(void) @@ -260,7 +264,7 @@ static void tests_registry_from_schema_int_path(void) TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_SCHEMA, node.type); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)node.location.schema); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested, (int)node.value.schema); } static void tests_registry_from_namespace_int_path(void) @@ -278,7 +282,7 @@ static void tests_registry_from_namespace_int_path(void) TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_NAMESPACE, node.type); - TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)node.location.namespace); + TEST_ASSERT_EQUAL_INT((int)®istry_tests, (int)node.value.namespace); } Test *tests_registry_int_path_tests(void) From 0d91422017721445198ac0a6e3c218ea292c438e Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:21:22 +0200 Subject: [PATCH 056/117] fixup! tests/unittests: add registry_storage tests Fix new registry_node_t format --- .../tests-registry_storage.c | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/unittests/tests-registry_storage/tests-registry_storage.c b/tests/unittests/tests-registry_storage/tests-registry_storage.c index 713bf5f7a6a0..73d7d3287222 100644 --- a/tests/unittests/tests-registry_storage/tests-registry_storage.c +++ b/tests/unittests/tests-registry_storage/tests-registry_storage.c @@ -76,8 +76,10 @@ static int load(const registry_storage_instance_t *storage, if (storage == &storage_test_instance) { registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .location.parameter = ®istry_tests_nested_parameter, - .instance = &test_nested_instance, + .value.parameter = { + .instance = &test_nested_instance, + .parameter = ®istry_tests_nested_parameter, + }, }; uint8_t buf = _TESTS_REGISTRY_LOAD_STORED_VALUE; return load_cb(&node, &buf, sizeof(buf)); @@ -91,8 +93,8 @@ static int save(const registry_storage_instance_t *storage, const registry_value_t *value) { if (storage == &storage_test_instance && - node->instance == &test_nested_instance && - node->location.parameter == ®istry_tests_nested_group_parameter && + node->value.parameter.instance == &test_nested_instance && + node->value.parameter.parameter == ®istry_tests_nested_group_parameter && value->buf == &test_nested_instance_data.group_parameter && value->buf_len == sizeof(uint8_t) && value->type == REGISTRY_TYPE_UINT8) { @@ -125,8 +127,10 @@ static void tests_registry_load(void) registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .location.parameter = ®istry_tests_nested_parameter, - .instance = &test_nested_instance, + .value.parameter = { + .instance = &test_nested_instance, + .parameter = ®istry_tests_nested_parameter, + }, }; registry_get(&node, &output); @@ -137,8 +141,10 @@ static void tests_registry_save_parameter(void) { registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .location.parameter = ®istry_tests_nested_group_parameter, - .instance = &test_nested_instance, + .value.parameter = { + .instance = &test_nested_instance, + .parameter = ®istry_tests_nested_group_parameter, + }, }; TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } @@ -147,8 +153,10 @@ static void tests_registry_save_group(void) { registry_node_t node = { .type = REGISTRY_NODE_GROUP, - .location.group = ®istry_tests_nested_group, - .instance = &test_nested_instance, + .value.group = { + .instance = &test_nested_instance, + .group = ®istry_tests_nested_group, + }, }; TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } @@ -157,7 +165,7 @@ static void tests_registry_save_instance(void) { registry_node_t node = { .type = REGISTRY_NODE_INSTANCE, - .instance = &test_nested_instance, + .value.instance = &test_nested_instance, }; TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } @@ -166,7 +174,7 @@ static void tests_registry_save_schema(void) { registry_node_t node = { .type = REGISTRY_NODE_SCHEMA, - .location.schema = ®istry_tests_nested, + .value.schema = ®istry_tests_nested, }; TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } @@ -175,7 +183,7 @@ static void tests_registry_save_namespace(void) { registry_node_t node = { .type = REGISTRY_NODE_NAMESPACE, - .location.namespace = ®istry_tests, + .value.namespace = ®istry_tests, }; TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); } From f7e4008722614e33920072499e2c83e67a1c5b77 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:21:51 +0200 Subject: [PATCH 057/117] fixup! tests/unittests: add registry_storage_heap tests Fix new registry_node_t format --- .../tests-registry_storage_heap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c index eb6ed5b98919..5948cfc7d0d6 100644 --- a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c +++ b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c @@ -68,8 +68,10 @@ static void tests_load_and_save(void) { registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .location.parameter = ®istry_tests_nested_group_parameter, - .instance = &test_nested_instance, + .value.parameter = { + .instance = &test_nested_instance, + .parameter = ®istry_tests_nested_group_parameter, + }, }; /* set input to 8 */ From 4a9c124b91fb9ae6f3bba62a052792ff698dda00 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:22:08 +0200 Subject: [PATCH 058/117] fixup! tests/unittests: add registry_storage_vfs tests Fix new registry_node_t format --- .../tests-registry_storage_vfs/tests-registry_storage_vfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c index 29e741b2da53..ed8e947fdec0 100644 --- a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c +++ b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c @@ -89,8 +89,10 @@ static void tests_load_and_save(void) { registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .location.parameter = ®istry_tests_nested_group_parameter, - .instance = &test_nested_instance, + .value.parameter = { + .instance = &test_nested_instance, + ®istry_tests_nested_group_parameter, + }, }; /* set input to 8 */ From f9d8c3eeb9ab730c3fd75233553573fc9bd621ed Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 12 Apr 2024 18:22:32 +0200 Subject: [PATCH 059/117] fixup! tests/unittests: add registry_string_path tests Fix new registry_node_t format --- .../tests-registry_string_path.c | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/tests/unittests/tests-registry_string_path/tests-registry_string_path.c b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c index 3c47c330af16..697e66fedb58 100644 --- a/tests/unittests/tests-registry_string_path/tests-registry_string_path.c +++ b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c @@ -63,8 +63,10 @@ static void tests_registry_to_parameter_string_path(void) { registry_node_t node = { .type = REGISTRY_NODE_PARAMETER, - .location.parameter = ®istry_tests_nested_group_parameter, - .instance = &test_instance, + .value.parameter = { + .instance = &test_instance, + .parameter = ®istry_tests_nested_group_parameter, + }, }; int size = registry_node_to_string_path(&node, NULL); @@ -79,8 +81,10 @@ static void tests_registry_to_group_string_path(void) { registry_node_t node = { .type = REGISTRY_NODE_GROUP, - .location.group = ®istry_tests_nested_group, - .instance = &test_instance, + .value.group = { + .instance = &test_instance, + .group = ®istry_tests_nested_group, + }, }; int size = registry_node_to_string_path(&node, NULL); @@ -95,7 +99,7 @@ static void tests_registry_to_instance_string_path(void) { registry_node_t node = { .type = REGISTRY_NODE_INSTANCE, - .instance = &test_instance, + .value.instance = &test_instance, }; int size = registry_node_to_string_path(&node, NULL); @@ -110,7 +114,7 @@ static void tests_registry_to_schema_string_path(void) { registry_node_t node = { .type = REGISTRY_NODE_SCHEMA, - .location.schema = ®istry_tests_nested, + .value.schema = ®istry_tests_nested, }; int size = registry_node_to_string_path(&node, NULL); @@ -125,7 +129,7 @@ static void tests_registry_to_namespace_string_path(void) { registry_node_t node = { .type = REGISTRY_NODE_NAMESPACE, - .location.namespace = ®istry_tests, + .value.namespace = ®istry_tests, }; int size = registry_node_to_string_path(&node, NULL); @@ -145,10 +149,10 @@ static void tests_registry_from_parameter_string_path(void) registry_node_from_string_path(str, sizeof(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); - TEST_ASSERT_EQUAL_STRING("tests", node.location.parameter->schema->namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", node.location.parameter->schema->name); - TEST_ASSERT_EQUAL_STRING("instance-1", node.instance->name); - TEST_ASSERT_EQUAL_STRING("parameter", node.location.parameter->name); + TEST_ASSERT_EQUAL_STRING("tests", node.value.parameter.parameter->schema->namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", node.value.parameter.parameter->schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", node.value.parameter.instance->name); + TEST_ASSERT_EQUAL_STRING("parameter", node.value.parameter.parameter->name); } static void tests_registry_from_group_string_path(void) @@ -159,10 +163,10 @@ static void tests_registry_from_group_string_path(void) registry_node_from_string_path(str, sizeof(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_GROUP, node.type); - TEST_ASSERT_EQUAL_STRING("tests", node.location.group->schema->namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", node.location.group->schema->name); - TEST_ASSERT_EQUAL_STRING("instance-1", node.instance->name); - TEST_ASSERT_EQUAL_STRING("group", node.location.group->name); + TEST_ASSERT_EQUAL_STRING("tests", node.value.group.group->schema->namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", node.value.group.group->schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", node.value.group.instance->name); + TEST_ASSERT_EQUAL_STRING("group", node.value.group.group->name); } static void tests_registry_from_instance_string_path(void) @@ -173,9 +177,9 @@ static void tests_registry_from_instance_string_path(void) registry_node_from_string_path(str, sizeof(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_INSTANCE, node.type); - TEST_ASSERT_EQUAL_STRING("tests", node.instance->schema->namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", node.instance->schema->name); - TEST_ASSERT_EQUAL_STRING("instance-1", node.instance->name); + TEST_ASSERT_EQUAL_STRING("tests", node.value.instance->schema->namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", node.value.instance->schema->name); + TEST_ASSERT_EQUAL_STRING("instance-1", node.value.instance->name); } static void tests_registry_from_schema_string_path(void) @@ -186,8 +190,8 @@ static void tests_registry_from_schema_string_path(void) registry_node_from_string_path(str, sizeof(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_SCHEMA, node.type); - TEST_ASSERT_EQUAL_STRING("tests", node.location.schema->namespace->name); - TEST_ASSERT_EQUAL_STRING("nested", node.location.schema->name); + TEST_ASSERT_EQUAL_STRING("tests", node.value.schema->namespace->name); + TEST_ASSERT_EQUAL_STRING("nested", node.value.schema->name); } static void tests_registry_from_namespace_string_path(void) @@ -198,7 +202,7 @@ static void tests_registry_from_namespace_string_path(void) registry_node_from_string_path(str, sizeof(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_NAMESPACE, node.type); - TEST_ASSERT_EQUAL_STRING("tests", node.location.namespace->name); + TEST_ASSERT_EQUAL_STRING("tests", node.value.namespace->name); } Test *tests_registry_string_path_tests(void) From 9444fe8b55533a9539472908bb10f91445f0255f Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 18:01:22 +0200 Subject: [PATCH 060/117] fixup! sys/registry: add int_path module Improve documentation --- sys/include/registry/int_path.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sys/include/registry/int_path.h b/sys/include/registry/int_path.h index 6507d7f63665..395d3bbc2944 100644 --- a/sys/include/registry/int_path.h +++ b/sys/include/registry/int_path.h @@ -9,8 +9,11 @@ /** * @defgroup sys_registry_int_path RIOT Registry integer path * @ingroup sys - * @brief RIOT Registry integer path module providing functions to convert between registry objects and their integer paths + * @brief RIOT Registry integer path module * @{ + * + * This module provides functions to convert between @ref registry_node_t and + * @ref registry_int_path_t. * * @file * @@ -34,13 +37,16 @@ extern "C" { #define REGISTRY_INT_PATH_MAX_LEN 4 /** - * @brief Maximum length of a configuration path as a string. - * - * A int path ID is an uint32_t and uint32_t MAX has 10 digits. + * @brief Maximum length of a configuration path as a string of numbers. + * + * An int path consists of the following elements: + * namespace_id: 8 bits corresponds to a max of 3 characters + * schema_id: 32 bits corresponds to a max of 10 characters + * instance_id: 16 bits corresponds to a max of 5 characters + * group__or_parameter_id: 8 bits corresponds to a max of 3 characters * We also need to include the separator. One additional char between each number. */ -#define REGISTRY_INT_PATH_STRING_MAX_LEN ((10 * REGISTRY_INT_PATH_MAX_LEN) + \ - (REGISTRY_INT_PATH_MAX_LEN - 1)) +#define REGISTRY_INT_PATH_STRING_MAX_LEN (3 + 10 + 5 + 3 + (REGISTRY_INT_PATH_MAX_LEN - 1)) /** * @brief Integer path representation for a namespace. From 4f9283c6c93e805d2c03674cafc933e7e0c1be80 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 18:01:54 +0200 Subject: [PATCH 061/117] fixup! sys: add runtime configuration registry Improve documentation --- sys/include/registry.h | 55 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/sys/include/registry.h b/sys/include/registry.h index bc8cf527126f..6b2344957a1e 100644 --- a/sys/include/registry.h +++ b/sys/include/registry.h @@ -30,19 +30,72 @@ extern "C" { #include "xfa.h" #include "modules.h" +/** + * @brief Identifier of a configuration namespace. + * It is unique within the scope of the RIOT registry itself. + */ typedef uint8_t registry_namespace_id_t; + +/** + * @brief Identifier of a configuration schema. + * It is unique within the scope of its parent configuration namespace. + */ typedef uint32_t registry_schema_id_t; + +/** + * @brief Identifier of a schema instance. + * It is unique within the scope of its parent configuration schema. + */ typedef uint16_t registry_instance_id_t; -typedef uint16_t registry_group_or_parameter_id_t; + +/** + * @brief Identifier of a configuration group or parameter. + * It is unique within the scope of its parent schema instance. + * Because a configuration group and a configuration parameter share the same + * namespace, this type exists for cases where it is not clear if an ID belongs + * to a group or a parameter. + */ +typedef uint8_t registry_group_or_parameter_id_t; + +/** + * @brief Identifier of a configuration group. + * It is unique within the scope of its parent schema instance. + */ typedef registry_group_or_parameter_id_t registry_group_id_t; + +/** + * @brief Identifier of a configuration parameter. + * It is unique within the scope of its parent schema instance. + */ typedef registry_group_or_parameter_id_t registry_parameter_id_t; + +/** + * @brief Data structure of a configuration namespace see @p _registry_namespace_t. + */ typedef struct _registry_namespace_t registry_namespace_t; + +/** + * @brief Data structure of a configuration schema see @p _registry_schema_t. + */ typedef struct _registry_schema_t registry_schema_t; + +/** + * @brief Instance of a schema containing its configuration parameters values see @p _registry_instance_t. + */ typedef struct _registry_instance_t registry_instance_t; + +/** + * @brief Data structure of a configuration group see @p _registry_group_t. + */ typedef struct _registry_group_t registry_group_t; + +/** + * @brief Data structure of a configuration parameter see @p _registry_parameter_t. + */ typedef struct _registry_parameter_t registry_parameter_t; + /** * @brief Data types of the registry. */ From 3614909e95f94682f8913921852e26107a23090f Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 18:09:32 +0200 Subject: [PATCH 062/117] fixup! sys: add runtime configuration registry Remove devel code --- sys/include/registry/util.h | 2 -- sys/registry/util.c | 31 ------------------------------- 2 files changed, 33 deletions(-) diff --git a/sys/include/registry/util.h b/sys/include/registry/util.h index 035278aad4e0..92b2b42b5b10 100644 --- a/sys/include/registry/util.h +++ b/sys/include/registry/util.h @@ -28,8 +28,6 @@ extern "C" { #include "registry.h" -void _debug_print_value(const registry_value_t *value); - /** * @brief Convenience function to parse a configuration parameter value from * a string. diff --git a/sys/registry/util.c b/sys/registry/util.c index 451e28f65d7e..0c2eff641317 100644 --- a/sys/registry/util.c +++ b/sys/registry/util.c @@ -36,37 +36,6 @@ #include "registry/util.h" #include "fmt.h" -void _debug_print_value(const registry_value_t *value) -{ - if (ENABLE_DEBUG) { - switch (value->type) { - case REGISTRY_TYPE_NONE: break; - case REGISTRY_TYPE_OPAQUE: { - DEBUG("opaque (hex): "); - for (size_t i = 0; i < value->buf_len; i++) { - DEBUG("%02x", ((uint8_t *)value->buf)[i]); - } - break; - } - case REGISTRY_TYPE_STRING: DEBUG("string: %s", (char *)value->buf); break; - case REGISTRY_TYPE_BOOL: DEBUG("bool: %d", *(bool *)value->buf); break; - - case REGISTRY_TYPE_UINT8: DEBUG("uint8: %"PRIu8, *(uint8_t *)value->buf); break; - case REGISTRY_TYPE_UINT16: DEBUG("uint16: %"PRIu16, *(uint16_t *)value->buf); break; - case REGISTRY_TYPE_UINT32: DEBUG("uint32: %"PRIu32, *(uint32_t *)value->buf); break; - case REGISTRY_TYPE_UINT64: DEBUG("uint64: %"PRIu64, *(uint64_t *)value->buf); break; - - case REGISTRY_TYPE_INT8: DEBUG("int8: %"PRIu8, *(int8_t *)value->buf); break; - case REGISTRY_TYPE_INT16: DEBUG("int16: %"PRIu16, *(int16_t *)value->buf); break; - case REGISTRY_TYPE_INT32: DEBUG("int32: %"PRIu32, *(int32_t *)value->buf); break; - case REGISTRY_TYPE_INT64: DEBUG("int64: %"PRIu64, *(int64_t *)value->buf); break; - - case REGISTRY_TYPE_FLOAT32: DEBUG("f32: %f", *(float *)value->buf); break; - case REGISTRY_TYPE_FLOAT64: DEBUG("f64: %f", *(double *)value->buf); break; - } - } -} - int registry_util_convert_str_to_value(const char *src, void *dest, const size_t dest_len, const registry_type_t dest_type) { From 265043fe09e28e78b4e4dd88b0fc0afcd20bfb59 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 18:34:44 +0200 Subject: [PATCH 063/117] fixup! sys/shell: add registry cli Fix dependency of util --- sys/shell/Makefile.dep | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/shell/Makefile.dep b/sys/shell/Makefile.dep index 439cf52bd9cc..59cdbe04eb33 100644 --- a/sys/shell/Makefile.dep +++ b/sys/shell/Makefile.dep @@ -107,6 +107,7 @@ ifneq (,$(filter shell_cmds_default,$(USEMODULE))) endif ifneq (,$(filter registry,$(USEMODULE))) USEMODULE += shell_cmd_registry + USEMODULE += registry_util endif ifneq (,$(filter rtt_rtc periph_rtc,$(USEMODULE))) USEMODULE += shell_cmd_rtc From 491733a994157dee9d652b44257edf6e4b95089a Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 18:35:33 +0200 Subject: [PATCH 064/117] fixup! sys: add runtime configuration registry Make util a seperate module --- sys/registry/Makefile | 2 +- sys/registry/Makefile.dep | 7 ++++--- sys/registry/util.c | 24 ++---------------------- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/sys/registry/Makefile b/sys/registry/Makefile index 8baff91961c2..ee04422a8c26 100644 --- a/sys/registry/Makefile +++ b/sys/registry/Makefile @@ -1,4 +1,4 @@ -SRC := registry.c util.c init.c +SRC := registry.c init.c SUBMODULES := 1 diff --git a/sys/registry/Makefile.dep b/sys/registry/Makefile.dep index 65bb23a61bb7..0120c9b94015 100644 --- a/sys/registry/Makefile.dep +++ b/sys/registry/Makefile.dep @@ -6,9 +6,10 @@ ifneq (,$(filter registry_storage%,$(USEMODULE))) include $(RIOTBASE)/sys/registry/storage/Makefile.dep endif +ifneq (,$(filter registry_util%,$(USEMODULE))) + USEMODULE += base64 +endif + ifneq (,$(filter registry_%,$(USEMODULE))) USEMODULE += registry endif - -USEMODULE += fmt -USEMODULE += base64 \ No newline at end of file diff --git a/sys/registry/util.c b/sys/registry/util.c index 0c2eff641317..d313878405b7 100644 --- a/sys/registry/util.c +++ b/sys/registry/util.c @@ -197,17 +197,7 @@ int registry_util_convert_value_to_str(const registry_value_t *src, char *dest, } case REGISTRY_TYPE_UINT64: { - str_len = fmt_u64_dec(NULL, *(uint64_t *)src->buf); - if (str_len > dest_len - 1) { - /* If dest is NULL, the length is returned */ - if (dest != NULL) { - return -EINVAL; - } - } - else { - fmt_u64_dec(dest, *(uint64_t *)src->buf); - dest[str_len] = '\0'; - } + str_len = snprintf(dest, dest_len, " %" PRIu64, *(uint64_t *)src->buf); break; } @@ -227,17 +217,7 @@ int registry_util_convert_value_to_str(const registry_value_t *src, char *dest, } case REGISTRY_TYPE_INT64: { - str_len = fmt_s64_dec(NULL, *(int64_t *)src->buf); - if (str_len > dest_len - 1) { - /* If dest is NULL, the length is returned */ - if (dest != NULL) { - return -EINVAL; - } - } - else { - fmt_s64_dec(dest, *(int64_t *)src->buf); - dest[str_len] = '\0'; - } + str_len = snprintf(dest, dest_len, " %" PRId64, *(int64_t *)src->buf); break; } From 3b3734fb46d16bb84e1f3c5ff85533178a53473b Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 18:46:43 +0200 Subject: [PATCH 065/117] fixup! sys/registry: add string_path module Improve documentation --- sys/include/registry/string_path.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/include/registry/string_path.h b/sys/include/registry/string_path.h index 34f4061a9313..47db10c264c4 100644 --- a/sys/include/registry/string_path.h +++ b/sys/include/registry/string_path.h @@ -9,8 +9,11 @@ /** * @defgroup sys_registry_string_path RIOT Registry String Path * @ingroup sys - * @brief RIOT Registry String Path module providing functions to convert between registry objects and their string paths + * @brief RIOT Registry String Path module * @{ + * + * This module provides functions to convert between @ref registry_node_t and + * a string path representation of it. * * @file * @@ -27,7 +30,7 @@ extern "C" { #include "registry.h" /** - * @brief Converts a registry namespace object to its string path representation. + * @brief Converts a registry namespace to its string path representation. * * @param[in] node A location within the registry configuration tree. * @param[out] path The buffer to store the resulting string path. @@ -38,7 +41,7 @@ extern "C" { int registry_node_to_string_path(const registry_node_t *node, char *path); /** - * @brief Converts a string path to a registry namespace object. + * @brief Converts a string path to a registry namespace. * * @param[in] path The string path to convert. * @param[in] path_len Length of the path. From 4e28f6a69a61f3978b64cd570ab3afe20987798b Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 19:05:56 +0200 Subject: [PATCH 066/117] fixup! sys/registry: add tests namespace Improve namespace comments --- .../namespace/tests/namespace_tests_full.c | 3 +- .../namespace/tests/namespace_tests_nested.c | 28 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/sys/registry/namespace/tests/namespace_tests_full.c b/sys/registry/namespace/tests/namespace_tests_full.c index ecf2d7d38cb6..f02d03569447 100644 --- a/sys/registry/namespace/tests/namespace_tests_full.c +++ b/sys/registry/namespace/tests/namespace_tests_full.c @@ -108,7 +108,7 @@ static void mapping(const registry_parameter_id_t parameter_id, const registry_i } } -/* Schema */ +/* Schema parameters */ const registry_parameter_t registry_tests_full_opaque = { .id = REGISTRY_TESTS_FULL_OPAQUE, #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -265,6 +265,7 @@ const registry_parameter_t registry_tests_full_f64 = { .type = REGISTRY_TYPE_FLOAT64, }; +/* Schema */ registry_schema_t registry_tests_full = { .id = REGISTRY_TESTS_FULL, #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) diff --git a/sys/registry/namespace/tests/namespace_tests_nested.c b/sys/registry/namespace/tests/namespace_tests_nested.c index 2b9aadd05edb..b7aca4632c3a 100644 --- a/sys/registry/namespace/tests/namespace_tests_nested.c +++ b/sys/registry/namespace/tests/namespace_tests_nested.c @@ -53,7 +53,7 @@ static void mapping(const registry_parameter_id_t parameter_id, const registry_i } } -/* Schema */ +/* Schema parameters */ const registry_parameter_t registry_tests_nested_parameter = { .id = REGISTRY_TESTS_NESTED_PARAMETER, #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -66,6 +66,19 @@ const registry_parameter_t registry_tests_nested_parameter = { .type = REGISTRY_TYPE_UINT8, }; +const registry_parameter_t registry_tests_nested_group_parameter = { + .id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "parameter", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_nested, + .type = REGISTRY_TYPE_UINT8, +}; + +/* Schema groups */ const registry_group_t registry_tests_nested_group = { .id = REGISTRY_TESTS_NESTED_GROUP, #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -83,18 +96,7 @@ const registry_group_t registry_tests_nested_group = { .parameters_len = 1, }; -const registry_parameter_t registry_tests_nested_group_parameter = { - .id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "parameter", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_nested, - .type = REGISTRY_TYPE_UINT8, -}; - +/* Schema */ registry_schema_t registry_tests_nested = { .id = REGISTRY_TESTS_NESTED, #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) From 6820c2b6d8aee959dcf3e73a011274f24c68e2fa Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 19:06:40 +0200 Subject: [PATCH 067/117] fixup! sys/registry: add sys namespace Improve namespace comments --- sys/include/registry/namespace/sys.h | 2 +- sys/include/registry/namespace/sys/rgb_led.h | 8 --- ...002_board_led.yaml => 0000_board_led.yaml} | 2 +- .../sys/definitions/0001_rgb_led.yaml | 21 ------- .../namespace/sys/namespace_sys_board_led.c | 3 +- .../namespace/sys/namespace_sys_rgb_led.c | 61 ++----------------- 6 files changed, 8 insertions(+), 89 deletions(-) rename sys/registry/namespace/sys/definitions/{0002_board_led.yaml => 0000_board_led.yaml} (97%) diff --git a/sys/include/registry/namespace/sys.h b/sys/include/registry/namespace/sys.h index 2bdd4238102a..83dbcc7d4513 100644 --- a/sys/include/registry/namespace/sys.h +++ b/sys/include/registry/namespace/sys.h @@ -29,8 +29,8 @@ extern "C" { extern registry_namespace_t registry_sys; typedef enum { - REGISTRY_SYS_RGB_LED, REGISTRY_SYS_BOARD_LED, + REGISTRY_SYS_RGB_LED, } registry_sys_indices_t; #ifdef __cplusplus diff --git a/sys/include/registry/namespace/sys/rgb_led.h b/sys/include/registry/namespace/sys/rgb_led.h index 2b485b0c0c72..413b20bd7fc0 100644 --- a/sys/include/registry/namespace/sys/rgb_led.h +++ b/sys/include/registry/namespace/sys/rgb_led.h @@ -32,9 +32,6 @@ extern "C" { extern const registry_parameter_t registry_sys_rgb_led_red; extern const registry_parameter_t registry_sys_rgb_led_green; extern const registry_parameter_t registry_sys_rgb_led_blue; -extern const registry_parameter_t registry_sys_rgb_led_brightnesses_white; -extern const registry_parameter_t registry_sys_rgb_led_brightnesses_yellow; -extern const registry_group_t registry_sys_rgb_led_brightnesses; extern registry_schema_t registry_sys_rgb_led; typedef struct { @@ -42,17 +39,12 @@ typedef struct { uint8_t red; uint8_t green; uint8_t blue; - uint8_t white; - uint8_t yellow; } registry_sys_rgb_led_instance_t; typedef const enum { REGISTRY_SYS_RGB_LED_RED, REGISTRY_SYS_RGB_LED_GREEN, REGISTRY_SYS_RGB_LED_BLUE, - REGISTRY_SYS_RGB_LED_BRIGHTNESSES, - REGISTRY_SYS_RGB_LED_BRIGHTNESSES_WHITE, - REGISTRY_SYS_RGB_LED_BRIGHTNESSES_YELLOW, } registry_sys_rgb_led_indices_t; #endif diff --git a/sys/registry/namespace/sys/definitions/0002_board_led.yaml b/sys/registry/namespace/sys/definitions/0000_board_led.yaml similarity index 97% rename from sys/registry/namespace/sys/definitions/0002_board_led.yaml rename to sys/registry/namespace/sys/definitions/0000_board_led.yaml index b423e4c928c9..ee651b62ad6b 100644 --- a/sys/registry/namespace/sys/definitions/0002_board_led.yaml +++ b/sys/registry/namespace/sys/definitions/0000_board_led.yaml @@ -1,5 +1,5 @@ # yaml-language-server: $schema=../../../../../dist/tools/registry_gen/schema.json -id: 2 +id: 0 name: board_led description: Representation of a board LED. items: diff --git a/sys/registry/namespace/sys/definitions/0001_rgb_led.yaml b/sys/registry/namespace/sys/definitions/0001_rgb_led.yaml index 04c24cbf1c50..8d42ddf04002 100644 --- a/sys/registry/namespace/sys/definitions/0001_rgb_led.yaml +++ b/sys/registry/namespace/sys/definitions/0001_rgb_led.yaml @@ -17,24 +17,3 @@ items: name: blue description: Intensity of the blue color of the rgb lamp. type: uint8 - - - id: 3 - name: brightnesses - description: Brightness of the rgb lamp. - type: group - items: - - id: 4 - name: yellow - description: Brightness of the yellow color of the rgb lamp. - type: uint8 - - - id: 5 - name: white - description: Brightness of the white color of the rgb lamp. - type: uint8 - - - id: 6 - name: string - description: Intensity of the blue color of the rgb lamp. - type: string - size: 20 diff --git a/sys/registry/namespace/sys/namespace_sys_board_led.c b/sys/registry/namespace/sys/namespace_sys_board_led.c index 070a3977fe02..3602b4338b85 100644 --- a/sys/registry/namespace/sys/namespace_sys_board_led.c +++ b/sys/registry/namespace/sys/namespace_sys_board_led.c @@ -49,7 +49,7 @@ static void mapping(const registry_parameter_id_t parameter_id, const registry_i } } -/* Schema */ +/* Schema parameters */ const registry_parameter_t registry_sys_board_led_enabled = { .id = REGISTRY_SYS_BOARD_LED_ENABLED, #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -62,6 +62,7 @@ const registry_parameter_t registry_sys_board_led_enabled = { .type = REGISTRY_TYPE_BOOL, }; +/* Schema */ registry_schema_t registry_sys_board_led = { .id = REGISTRY_SYS_BOARD_LED, #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) diff --git a/sys/registry/namespace/sys/namespace_sys_rgb_led.c b/sys/registry/namespace/sys/namespace_sys_rgb_led.c index 0666ec1c61b0..e33bbadb6fca 100644 --- a/sys/registry/namespace/sys/namespace_sys_rgb_led.c +++ b/sys/registry/namespace/sys/namespace_sys_rgb_led.c @@ -56,20 +56,10 @@ static void mapping(const registry_parameter_id_t parameter_id, const registry_i *val = &_instance->blue; *val_len = sizeof(_instance->blue); break; - - case REGISTRY_SYS_RGB_LED_BRIGHTNESSES_WHITE: - *val = &_instance->white; - *val_len = sizeof(_instance->white); - break; - - case REGISTRY_SYS_RGB_LED_BRIGHTNESSES_YELLOW: - *val = &_instance->yellow; - *val_len = sizeof(_instance->yellow); - break; } } -/* Schema */ +/* Schema parameters */ const registry_parameter_t registry_sys_rgb_led_red = { .id = REGISTRY_SYS_RGB_LED_RED, #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -106,48 +96,7 @@ const registry_parameter_t registry_sys_rgb_led_blue = { .type = REGISTRY_TYPE_UINT8, }; -const registry_parameter_t registry_sys_rgb_led_brightnesses_white = { - .id = REGISTRY_SYS_RGB_LED_BRIGHTNESSES_WHITE, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "white", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_sys_rgb_led, - .type = REGISTRY_TYPE_UINT8, -}; - -const registry_parameter_t registry_sys_rgb_led_brightnesses_yellow = { - .id = REGISTRY_SYS_RGB_LED_BRIGHTNESSES_YELLOW, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "yellow", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_sys_rgb_led, - .type = REGISTRY_TYPE_UINT8, -}; - -const registry_group_t registry_sys_rgb_led_brightnesses = { - .id = REGISTRY_SYS_RGB_LED_BRIGHTNESSES, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "brightnesses", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_sys_rgb_led, - .groups = NULL, - .groups_len = 0, - .parameters = (const registry_parameter_t *[]) { - ®istry_sys_rgb_led_brightnesses_white, - ®istry_sys_rgb_led_brightnesses_yellow, - }, - .parameters_len = 2, -}; - +/* Schema */ registry_schema_t registry_sys_rgb_led = { .id = REGISTRY_SYS_RGB_LED, #if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) @@ -158,10 +107,8 @@ registry_schema_t registry_sys_rgb_led = { #endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ .namespace = ®istry_sys, .mapping = mapping, - .groups = (const registry_group_t *[]) { - ®istry_sys_rgb_led_brightnesses, - }, - .groups_len = 1, + .groups = NULL, + .groups_len = 0, .parameters = (const registry_parameter_t *[]) { ®istry_sys_rgb_led_red, ®istry_sys_rgb_led_green, From 3dfcd91b6ed9f68004e430529e737a9f113ddb75 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 19:30:08 +0200 Subject: [PATCH 068/117] fixup! sys/registry: add int_path module Fix code duplication --- sys/registry/int_path.c | 43 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/sys/registry/int_path.c b/sys/registry/int_path.c index aada6955d51a..ca59fab37d38 100644 --- a/sys/registry/int_path.c +++ b/sys/registry/int_path.c @@ -93,40 +93,21 @@ static int _instance_lookup(const registry_schema_t *schema, return -REGISTRY_ERROR_INSTANCE_NOT_FOUND; } -static const registry_group_t *_internal_group_lookup(const registry_group_t *group, - const registry_group_id_t group_id) -{ - assert(group != NULL); - - for (size_t i = 0; i < group->groups_len; i++) { - if (group->groups[i]->id == group_id) { - return group->groups[i]; - } - else if (group->groups[i]->groups_len > 0) { - return _internal_group_lookup(group->groups[i], group_id); - } - } - - return NULL; -} - -static int _group_lookup(const registry_schema_t *schema, const registry_group_id_t group_id, +static int _group_lookup(const registry_group_t **groups, + const size_t groups_len, + const registry_group_id_t group_id, const registry_group_t **group) { - assert(schema != NULL); - assert(group != NULL); + assert(groups != NULL); + assert(groups_len > 0); - for (size_t i = 0; i < schema->groups_len; i++) { - if (schema->groups[i]->id == group_id) { - *group = schema->groups[i]; + for (size_t i = 0; i < groups_len; i++) { + if ((*groups)[i].id == group_id) { + *group = groups[i]; return 0; } - else if (schema->groups[i]->groups_len > 0) { - const registry_group_t *found_group = _internal_group_lookup(schema->groups[i], group_id); - if (found_group != NULL) { - *group = found_group; - return 0; - } + else if ((*groups)[i].groups_len > 0) { + return _group_lookup((*groups)[i].groups, (*groups)[i].groups_len, group_id, group); } } @@ -307,7 +288,7 @@ int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t /* Group or Parameter */ if (path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { - res = _group_lookup(schema, group_or_parameter_id, &node->value.group.group); + res = _group_lookup(schema->groups, schema->groups_len, group_or_parameter_id, &node->value.group.group); if (res == 0) { node->type = REGISTRY_NODE_GROUP; node->value.group.instance = instance; @@ -326,7 +307,7 @@ int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t if (path->type == REGISTRY_INT_PATH_TYPE_GROUP) { node->type = REGISTRY_NODE_GROUP; node->value.group.instance = instance; - return _group_lookup(schema, group_id, &node->value.group.group); + return _group_lookup(schema->groups, schema->groups_len, group_id, &node->value.group.group); } /* Parameter */ From e8424e92d4f00ddc91f2bdc904987196ca6e67ef Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 19:38:03 +0200 Subject: [PATCH 069/117] fixup! sys/registry: add int_path module Fix documentation --- sys/registry/int_path.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sys/registry/int_path.c b/sys/registry/int_path.c index ca59fab37d38..b4a0c669b652 100644 --- a/sys/registry/int_path.c +++ b/sys/registry/int_path.c @@ -9,8 +9,11 @@ /** * @defgroup sys_registry_int_path RIOT Registry Int Path * @ingroup sys - * @brief RIOT Registry Int Path module providing a API to access configuration parameter via an integer path + * @brief RIOT Registry integer path module * @{ + * + * This module provides functions to convert between @ref registry_node_t and + * @ref registry_int_path_t. * * @file * @@ -68,7 +71,7 @@ static int _schema_lookup(const registry_namespace_t *namespace, static int _instance_lookup(const registry_schema_t *schema, const registry_instance_id_t instance_id, - registry_instance_t **instance) + const registry_instance_t **instance) { assert(schema != NULL); assert(instance != NULL); @@ -83,9 +86,11 @@ static int _instance_lookup(const registry_schema_t *schema, do { node = node->next; + const registry_instance_t *current_instance = container_of(node, registry_instance_t, node); + /* check if index equals instance_id */ - if (container_of(node, registry_instance_t, node)->id == instance_id) { - *instance = container_of(node, registry_instance_t, node); + if (current_instance->id == instance_id) { + *instance = current_instance; return 0; } } while (node != schema->instances.next); @@ -276,7 +281,7 @@ int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t } /* Instance */ - registry_instance_t *instance; + const registry_instance_t *instance; res = _instance_lookup(schema, instance_id, &instance); if (res == 0) { From 74b0a340853ee803394a0fc538ecf0d9ecb72514 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 19:38:25 +0200 Subject: [PATCH 070/117] fixup! sys/registry: add string_path module Fix documentation --- sys/registry/string_path.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/registry/string_path.c b/sys/registry/string_path.c index 226eb311090b..23d4cdae253e 100644 --- a/sys/registry/string_path.c +++ b/sys/registry/string_path.c @@ -9,8 +9,11 @@ /** * @defgroup sys_registry_string_path RIOT Registry String Path * @ingroup sys - * @brief RIOT Registry String Path module providing a API to access configuration parameter via a string path + * @brief RIOT Registry String Path module * @{ + * + * This module provides functions to convert between @ref registry_node_t and + * a string path representation of it. * * @file * From c252ad2fc357a8e6ec1f3a9e50d7ca6de4429075 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 19:41:34 +0200 Subject: [PATCH 071/117] fixup! sys: add runtime configuration registry Remove unused includes --- sys/registry/init.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/sys/registry/init.c b/sys/registry/init.c index bbcc0039eb47..12548e8b8b15 100644 --- a/sys/registry/init.c +++ b/sys/registry/init.c @@ -19,14 +19,6 @@ * @} */ -#include -#include -#include -#include -#include -#include -#include - #define ENABLE_DEBUG (0) #include "debug.h" From 909b2f17609e541d79db51a8e1b7b3f37efc9c63 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 19:47:51 +0200 Subject: [PATCH 072/117] fixup! sys/registry: add persistent storage module Add more docs --- sys/include/registry/storage.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/include/registry/storage.h b/sys/include/registry/storage.h index 629c0e3ee888..f11b4016bb48 100644 --- a/sys/include/registry/storage.h +++ b/sys/include/registry/storage.h @@ -91,7 +91,8 @@ struct _registry_storage_t { }; /** - * @brief Load all configuration parameters from the registered storage. + * @brief Load all configuration parameters from the storages that are registered + * using @p REGISTRY_ADD_STORAGE_SOURCE. * * @return 0 on success, non-zero on failure. */ @@ -99,7 +100,8 @@ int registry_load(void); /** * @brief Save all configuration parameters that are within - * the scope of the to the @p node. to the registered storage. + * the scope of the to the @p node. to the storage device, that was registered + * using @p REGISTRY_SET_STORAGE_DESTINATION. * * @param[in] node A location within the registry configuration tree. * From 2f6eaad09a3d2173ad8010c7400b780ef447bf85 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 20:11:39 +0200 Subject: [PATCH 073/117] fixup! sys/registry: add tests namespace Improve documentation --- sys/include/registry/namespace/tests.h | 9 ++++++++- sys/include/registry/namespace/tests/full.h | 9 +-------- sys/include/registry/namespace/tests/nested.h | 7 +------ sys/registry/namespace/tests/namespace_tests_full.c | 2 +- sys/registry/namespace/tests/namespace_tests_nested.c | 2 +- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/sys/include/registry/namespace/tests.h b/sys/include/registry/namespace/tests.h index cbbe9463d418..0e717559f4d4 100644 --- a/sys/include/registry/namespace/tests.h +++ b/sys/include/registry/namespace/tests.h @@ -9,8 +9,10 @@ /** * @defgroup sys_registry_namespace_tests RIOT Registry Tests Namespace * @ingroup tests - * @brief RIOT Registry Namespace Tests module providing common tests configuration schemas for the RIOT Registry sys module + * @brief RIOT Registry Namespace Tests module * @{ + * + * This module provides common test schemas for the RIOT Registry sys module * * @file * @@ -28,6 +30,11 @@ extern "C" { extern registry_namespace_t registry_tests; +/** + * @brief This ENUM defines the IDs of configuration schemas in the "tests" namespace. + * The IDs are needed by the int_path module to identify schemas using IDs instead + * of pointers. + */ typedef enum { REGISTRY_TESTS_FULL, REGISTRY_TESTS_NESTED, diff --git a/sys/include/registry/namespace/tests/full.h b/sys/include/registry/namespace/tests/full.h index 1201b02006b0..ab7459cabc6f 100644 --- a/sys/include/registry/namespace/tests/full.h +++ b/sys/include/registry/namespace/tests/full.h @@ -9,7 +9,7 @@ /** * @defgroup sys_registry_namespace_tests_full RIOT Registry Schema: Full * @ingroup sys - * @brief RIOT Registry Full Schema representing all possible data types of the riot registry + * @brief RIOT Registry Full Schema using all possible data types of the riot registry * @{ * * @file @@ -50,21 +50,17 @@ typedef struct { typedef struct { clist_node_t node; - registry_tests_full_instance_opaque_t opaque; char string[50]; bool boolean; - uint8_t u8; uint16_t u16; uint32_t u32; uint64_t u64; - int8_t i8; int16_t i16; int32_t i32; int64_t i64; - float f32; double f64; } registry_tests_full_instance_t; @@ -73,17 +69,14 @@ typedef enum { REGISTRY_TESTS_FULL_OPAQUE, REGISTRY_TESTS_FULL_STRING, REGISTRY_TESTS_FULL_BOOLEAN, - REGISTRY_TESTS_FULL_U8, REGISTRY_TESTS_FULL_U16, REGISTRY_TESTS_FULL_U32, REGISTRY_TESTS_FULL_U64, - REGISTRY_TESTS_FULL_I8, REGISTRY_TESTS_FULL_I16, REGISTRY_TESTS_FULL_I32, REGISTRY_TESTS_FULL_I64, - REGISTRY_TESTS_FULL_F32, REGISTRY_TESTS_FULL_F64, } registry_tests_full_indices_t; diff --git a/sys/include/registry/namespace/tests/nested.h b/sys/include/registry/namespace/tests/nested.h index af6c26348d93..77e8cc78afcb 100644 --- a/sys/include/registry/namespace/tests/nested.h +++ b/sys/include/registry/namespace/tests/nested.h @@ -9,7 +9,7 @@ /** * @defgroup sys_registry_namespace_tests_nested RIOT Registry Schema: Nested * @ingroup sys - * @brief RIOT Registry Nested Schema representing different nesting level of a configuration schema + * @brief RIOT Registry Nested Schema representing different nesting levels of a configuration schema * @{ * * @file @@ -34,13 +34,8 @@ extern const registry_group_t registry_tests_nested_group; extern const registry_parameter_t registry_tests_nested_group_parameter; extern registry_schema_t registry_tests_nested; -typedef struct { - uint8_t value; -} registry_tests_nested_instance_opaque_t; - typedef struct { clist_node_t node; - uint8_t parameter; uint8_t group_parameter; } registry_tests_nested_instance_t; diff --git a/sys/registry/namespace/tests/namespace_tests_full.c b/sys/registry/namespace/tests/namespace_tests_full.c index f02d03569447..9608b3951e69 100644 --- a/sys/registry/namespace/tests/namespace_tests_full.c +++ b/sys/registry/namespace/tests/namespace_tests_full.c @@ -9,7 +9,7 @@ /** * @defgroup sys_registry_namespace_tests_full RIOT Registry Schema: Full * @ingroup sys - * @brief RIOT Registry Full Schema representing all possible data types of the riot registry + * @brief RIOT Registry Full Schema using all possible data types of the riot registry * @{ * * @file diff --git a/sys/registry/namespace/tests/namespace_tests_nested.c b/sys/registry/namespace/tests/namespace_tests_nested.c index b7aca4632c3a..9210785b55d2 100644 --- a/sys/registry/namespace/tests/namespace_tests_nested.c +++ b/sys/registry/namespace/tests/namespace_tests_nested.c @@ -9,7 +9,7 @@ /** * @defgroup sys_registry_namespace_tests_nested RIOT Registry Schema: Nested * @ingroup sys - * @brief RIOT Registry Nested Schema representing different nesting level of a configuration schema + * @brief RIOT Registry Nested Schema representing different nesting levels of a configuration schema * @{ * * @file From e58fb667b84c9bee0e2d97ba4a94d34c28f876cb Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 20:12:01 +0200 Subject: [PATCH 074/117] fixup! sys/registry: add sys namespace Improve documentation --- sys/include/registry/namespace/sys.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sys/include/registry/namespace/sys.h b/sys/include/registry/namespace/sys.h index 83dbcc7d4513..1391265624a9 100644 --- a/sys/include/registry/namespace/sys.h +++ b/sys/include/registry/namespace/sys.h @@ -9,8 +9,10 @@ /** * @defgroup sys_registry_namespace_sys RIOT Registry Sys Namespace * @ingroup sys - * @brief RIOT Registry Namespace Sys module providing common sys configuration schemas for the RIOT Registry sys module + * @brief RIOT Registry Namespace Sys module * @{ + * + * This module provides common sys configuration schemas for the RIOT Registry sys module * * @file * @@ -28,9 +30,14 @@ extern "C" { extern registry_namespace_t registry_sys; +/** + * @brief This ENUM defines the IDs of configuration schemas in the "sys" namespace. + * The IDs are needed by the int_path module to identify schemas using IDs instead + * of pointers. + */ typedef enum { - REGISTRY_SYS_BOARD_LED, - REGISTRY_SYS_RGB_LED, + REGISTRY_SYS_BOARD_LED = 0, + REGISTRY_SYS_RGB_LED = 1, } registry_sys_indices_t; #ifdef __cplusplus From 57682a1646fc7d9e59571c4223221cb8b87e4124 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Wed, 24 Apr 2024 20:12:38 +0200 Subject: [PATCH 075/117] fixup! sys/registry: add persistent storage module Improve documentation --- sys/include/registry/storage.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sys/include/registry/storage.h b/sys/include/registry/storage.h index f11b4016bb48..2ef3c915f111 100644 --- a/sys/include/registry/storage.h +++ b/sys/include/registry/storage.h @@ -28,17 +28,23 @@ extern "C" { /** * @brief Prototype of a callback function for the load action of a storage interface. + * + * @param[in] node A location within the registry configuration tree. (In this case it must be a configuration parameter) + * @param[in] buf The saved value of the configuration parameter. + * @param[in] buf_len The size of @p buf. + * + * @return 0 on success, non-zero on failure. */ typedef int (*load_cb_t)(const registry_node_t *node, const void *buf, const size_t buf_len); typedef struct _registry_storage_t registry_storage_t; /** - * @brief Storage descriptor. + * @brief The Storage instance references the @p registry_storage_t and holds configuration data such as mount points. */ typedef struct { registry_storage_t *storage; /**< interface of the storage. */ - void *data; /**< Struct containing all config data for the storage. */ + void *data; /**< Struct containing all config data for the storage (specific to storage implementation). */ } registry_storage_instance_t; /** @@ -48,7 +54,7 @@ struct _registry_storage_t { /** * @brief Loads all saved parameters and calls the @p load_cb callback function. * - * @param[in] storage Storage descriptor. + * @param[in] storage Storage instance. * @param[in] load_cb Callback function to call for every saved parameter. * * @return 0 on success, non-zero on failure. @@ -59,6 +65,7 @@ struct _registry_storage_t { /** * @brief If implemented, it is used for any preparation the storage may * need before starting a saving process. + * NULL if not implemented * * @param[in] storage Storage descriptor. * @@ -82,6 +89,7 @@ struct _registry_storage_t { /** * @brief If implemented, it is used for any tear-down the storage may need * after a saving process. + * NULL if not implemented * * @param[in] storage Storage descriptor. * From dc430dbeb7d3f90f9c17b67b4583aca9652474ee Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 3 May 2024 17:40:17 +0200 Subject: [PATCH 076/117] sys/registry: add tree traversal utility --- sys/include/registry/tree_traversal.h | 71 +++++++ sys/registry/tree_traversal.c | 282 ++++++++++++++++++++++++++ 2 files changed, 353 insertions(+) create mode 100644 sys/include/registry/tree_traversal.h create mode 100644 sys/registry/tree_traversal.c diff --git a/sys/include/registry/tree_traversal.h b/sys/include/registry/tree_traversal.h new file mode 100644 index 000000000000..f3f0e6196da2 --- /dev/null +++ b/sys/include/registry/tree_traversal.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_tree_traversal RIOT Registry tree traversal utilities + * @ingroup sys + * @brief RIOT Registry Tree traversal module providing utility functions to travers the configuration tree + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#ifndef REGISTRY_TREE_TRAVERSAL_H +#define REGISTRY_TREE_TRAVERSAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" +#include "registry/error.h" + +/** + * @brief The different return types of @p registry_find_comparator_t callback function. + */ +typedef enum { + REGISTRY_FIND_NO_MATCH = -1, + REGISTRY_FIND_EXACT_MATCH = 0, + REGISTRY_FIND_PARTIAL_MATCH = 1, +} registry_find_result_type; + +/** + * @brief This callback is called by the @p registry_find function passing in a @p context, + * to compare a @p node with it. + * + * @param[in] node A location within the registry configuration tree. + * @param[in] context Context of the callback (contains the data to compare each @p node to). + * + * @return 0 on exact match, 1 on partial match and -1 on no match. + */ +typedef registry_find_result_type (*registry_find_comparator_t)(const registry_node_t *node, const void *context); + +/** + * @brief Finds a specific node within the registry configuration tree. + * The comparison of nodes is handled by the @p compare callback function. + * The context to compare to is passed to it using the @p context parameter. + * + * @param[in] compare Callback function that is invoked on the nodes of the configuration tree. + * @param[in] context Optional context used by the @p compare callback function. + * @param[out] node A location within the registry configuration tree. + * + * @return 0 on success, non-zero on failure. + */ +registry_error_t registry_find(const registry_find_comparator_t compare, + const void *context, registry_node_t *node); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* REGISTRY_TREE_TRAVERSAL_H */ diff --git a/sys/registry/tree_traversal.c b/sys/registry/tree_traversal.c new file mode 100644 index 000000000000..cbd2e8c5d634 --- /dev/null +++ b/sys/registry/tree_traversal.c @@ -0,0 +1,282 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_tree_traversal RIOT Registry tree traversal utilities + * @ingroup sys + * @brief RIOT Registry Tree traversal module providing utility functions to travers the configuration tree + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" + +#include "registry.h" +#include "registry/error.h" +#include "registry/tree_traversal.h" + +XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); + +static registry_find_result_type _find_group(const registry_group_t **groups, const size_t groups_len, + const registry_find_comparator_t compare, + const void *context, const registry_group_t **group) { + assert(groups != NULL); + assert(groups_len > 0); + assert(compare != NULL); + + registry_find_result_type res; + registry_node_t node = { + .type = REGISTRY_NODE_GROUP, + }; + + for (size_t i = 0; i < groups_len; i++) { + node.value.group.group = groups[i]; + res = compare(&node, context); + + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + *group = groups[i]; + return res; + } + + /* if a partial match is found, we need to keep searching for its children, but can break the loop */ + if (res == REGISTRY_FIND_PARTIAL_MATCH) { + return _find_group(groups[i]->groups, groups[i]->groups_len, compare, context, group); + } + } + + return -REGISTRY_ERROR_GROUP_NOT_FOUND; +} + +static registry_find_result_type _find_parameter_by_group( + const registry_group_t *group, const registry_find_comparator_t compare, + const void *context, const registry_parameter_t **parameter) +{ + assert(group != NULL); + assert(compare != NULL); + + registry_find_result_type res; + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + }; + + /* search parameter at group root */ + for (size_t i = 0; i < group->parameters_len; i++) { + node.value.parameter.parameter = group->parameters[i]; + res = compare(&node, context); + + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + *parameter = group->parameters[i]; + return res; + } + } + + /* search parameter inside sub-groups */ + for (size_t i = 0; i < group->groups_len; i++) { + res = _find_parameter_by_group(group->groups[i], compare, context, parameter); + + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + return res; + } + } + + return -REGISTRY_ERROR_PARAMETER_NOT_FOUND; +} + +static registry_find_result_type _find_parameter_by_schema( + const registry_schema_t *schema, const registry_find_comparator_t compare, + const void *context, const registry_parameter_t **parameter) { + assert(schema != NULL); + assert(compare != NULL); + + registry_find_result_type res; + registry_node_t node = { + .type = REGISTRY_NODE_PARAMETER, + }; + + /* search parameter at schema root */ + for (size_t i = 0; i < schema->parameters_len; i++) { + node.value.parameter.parameter = schema->parameters[i]; + res = compare(&node, context); + + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + *parameter = schema->parameters[i]; + return res; + } + } + + /* search parameter inside groups */ + for (size_t i = 0; i < schema->groups_len; i++) { + res = _find_parameter_by_group(schema->groups[i], compare, context, parameter); + + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + return res; + } + } + + return -REGISTRY_ERROR_PARAMETER_NOT_FOUND; +} + +registry_error_t registry_find(const registry_find_comparator_t compare, + const void *context, registry_node_t *node) { + assert(compare != NULL); + assert(context != NULL); + + registry_find_result_type res = REGISTRY_FIND_NO_MATCH; + registry_node_t compare_node; + + /* Namespace */ + const registry_namespace_t *namespace; + for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { + namespace = _registry_namespaces_xfa[i]; + compare_node.type = REGISTRY_NODE_NAMESPACE; + compare_node.value.namespace = namespace; + res = compare(&compare_node, context); + + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + node->type = REGISTRY_NODE_NAMESPACE; + node->value.namespace = namespace; + return 0; + } + + /* if a partial match is found, we need to keep searching for its children, but can break the loop */ + if (res == REGISTRY_FIND_PARTIAL_MATCH) { + break; + } + } + + /* Check if a namespace was found */ + if (res == REGISTRY_FIND_NO_MATCH) { + return -REGISTRY_ERROR_NAMESPACE_NOT_FOUND; + } + + /* Schema */ + const registry_schema_t *schema = NULL; + for (size_t i = 0; i < namespace->schemas_len; i++) { + schema = namespace->schemas[i]; + compare_node.type = REGISTRY_NODE_SCHEMA; + compare_node.value.schema = schema; + res = compare(&compare_node, context); + + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + node->type = REGISTRY_NODE_SCHEMA; + node->value.schema = schema; + return 0; + } + + /* if a partial match is found, we need to keep searching for its children, but can break the loop */ + if (res == REGISTRY_FIND_PARTIAL_MATCH) { + break; + } + } + + /* Check if a schema was found */ + if (res == REGISTRY_FIND_NO_MATCH) { + return -REGISTRY_ERROR_SCHEMA_NOT_FOUND; + } + + + if (schema != NULL) { + /* Instance */ + const registry_instance_t *instance = NULL; + clist_node_t *instance_node = schema->instances.next; + if (instance_node) { + do { + instance_node = instance_node->next; + instance = container_of(instance_node, registry_instance_t, node); + compare_node.type = REGISTRY_NODE_INSTANCE; + compare_node.value.instance = instance; + + res = compare(&compare_node, context); + + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + node->type = REGISTRY_NODE_INSTANCE; + node->value.instance = instance; + return 0; + } + + /* if a partial match is found, we need to keep searching for its children, but can break the loop */ + if (res == REGISTRY_FIND_PARTIAL_MATCH) { + break; + } + } while (instance_node != schema->instances.next); + } + + /* Check if an instance was found */ + if (res == REGISTRY_FIND_NO_MATCH) { + return -REGISTRY_ERROR_INSTANCE_NOT_FOUND; + } + + if (instance != NULL) { + /* Group */ + const registry_group_t *group; + res = _find_group(schema->groups, schema->groups_len, compare, context, &group); + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + node->type = REGISTRY_NODE_GROUP; + node->value.group.group = group; + node->value.group.instance = instance; + return 0; + } + + /* if a partial match is found, we need to keep searching for its children */ + if (res == REGISTRY_FIND_PARTIAL_MATCH) { + const registry_parameter_t *parameter; + res = _find_parameter_by_group(node->value.group.group, compare, context, ¶meter); + + if (res == REGISTRY_FIND_EXACT_MATCH) { + node->type = REGISTRY_NODE_PARAMETER; + node->value.parameter.parameter = parameter; + node->value.parameter.instance = instance; + return 0; + } + + /* A partial match of a parameter cannot happen as it is a leaf of the configuration tree */ + + return -REGISTRY_ERROR_PARAMETER_NOT_FOUND; + } + + /* Parameter */ + const registry_parameter_t *parameter; + res = _find_parameter_by_schema(schema, compare, context, ¶meter); + /* if an exact match is found, we can set it and return the function */ + if (res == REGISTRY_FIND_EXACT_MATCH) { + node->type = REGISTRY_NODE_PARAMETER; + node->value.parameter.parameter = parameter; + node->value.parameter.instance = instance; + return 0; + } + + /* A partial match of a parameter cannot happen as it is a leaf of the configuration tree */ + } + } + + return -REGISTRY_ERROR_PARAMETER_NOT_FOUND; +} From 8c9bbaefb7df8cf456e4d9733b1b7debdcd79f05 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 3 May 2024 17:41:19 +0200 Subject: [PATCH 077/117] fixup! sys: add runtime configuration registry Adjust to new tree traversal module --- sys/include/registry/error.h | 2 +- sys/registry/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/include/registry/error.h b/sys/include/registry/error.h index 7dc8b6a36d5b..e887ab359df1 100644 --- a/sys/include/registry/error.h +++ b/sys/include/registry/error.h @@ -27,7 +27,7 @@ extern "C" { /** * @brief Registry specific error codes. */ -typedef const enum { +typedef enum { REGISTRY_ERROR_NONE = 1, REGISTRY_ERROR_NO_DST_STORAGE, REGISTRY_ERROR_NAMESPACE_NOT_FOUND, diff --git a/sys/registry/Makefile b/sys/registry/Makefile index ee04422a8c26..9702771336d2 100644 --- a/sys/registry/Makefile +++ b/sys/registry/Makefile @@ -1,4 +1,4 @@ -SRC := registry.c init.c +SRC := registry.c init.c tree_traversal.c SUBMODULES := 1 From d548e0232dd3f1317d730f9fe2f3da614dbe22fb Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 3 May 2024 17:41:50 +0200 Subject: [PATCH 078/117] fixup! sys/registry: add int_path module Adjust to new tree traversal module --- sys/include/registry/int_path.h | 3 +- sys/registry/int_path.c | 269 +++++--------------------------- 2 files changed, 40 insertions(+), 232 deletions(-) diff --git a/sys/include/registry/int_path.h b/sys/include/registry/int_path.h index 395d3bbc2944..82fc8e27134b 100644 --- a/sys/include/registry/int_path.h +++ b/sys/include/registry/int_path.h @@ -28,6 +28,7 @@ extern "C" { #endif #include "registry.h" +#include "registry/error.h" /** * @brief Maximum length of a configuration path. @@ -147,7 +148,7 @@ int registry_node_to_int_path(const registry_node_t *node, registry_int_path_t * * * @return 0 on success, non-zero on failure. */ -int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t *node); +registry_error_t registry_node_from_int_path(const registry_int_path_t *path, registry_node_t *node); #ifdef __cplusplus } diff --git a/sys/registry/int_path.c b/sys/registry/int_path.c index b4a0c669b652..6e5d690aff3a 100644 --- a/sys/registry/int_path.c +++ b/sys/registry/int_path.c @@ -33,135 +33,10 @@ #include "registry.h" #include "registry/util.h" #include "registry/error.h" +#include "registry/tree_traversal.h" #include "registry/int_path.h" -XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); - -static int _namespace_lookup(const registry_namespace_id_t namespace_id, - registry_namespace_t **namespace) -{ - assert(namespace != NULL); - - for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { - if (_registry_namespaces_xfa[i]->id == namespace_id) { - *namespace = _registry_namespaces_xfa[i]; - return 0; - } - } - - return -REGISTRY_ERROR_NAMESPACE_NOT_FOUND; -} - -static int _schema_lookup(const registry_namespace_t *namespace, - const registry_schema_id_t schema_id, - const registry_schema_t **schema) -{ - assert(schema != NULL); - - for (size_t i = 0; i < namespace->schemas_len; i++) { - if (namespace->schemas[i]->id == schema_id) { - *schema = namespace->schemas[i]; - return 0; - } - } - - return -REGISTRY_ERROR_SCHEMA_NOT_FOUND; -} - -static int _instance_lookup(const registry_schema_t *schema, - const registry_instance_id_t instance_id, - const registry_instance_t **instance) -{ - assert(schema != NULL); - assert(instance != NULL); - - /* find instance with correct instance_id */ - clist_node_t *node = schema->instances.next; - - if (!node) { - return -REGISTRY_ERROR_INSTANCE_NOT_FOUND; - } - - do { - node = node->next; - - const registry_instance_t *current_instance = container_of(node, registry_instance_t, node); - - /* check if index equals instance_id */ - if (current_instance->id == instance_id) { - *instance = current_instance; - return 0; - } - } while (node != schema->instances.next); - - return -REGISTRY_ERROR_INSTANCE_NOT_FOUND; -} - -static int _group_lookup(const registry_group_t **groups, - const size_t groups_len, - const registry_group_id_t group_id, - const registry_group_t **group) -{ - assert(groups != NULL); - assert(groups_len > 0); - - for (size_t i = 0; i < groups_len; i++) { - if ((*groups)[i].id == group_id) { - *group = groups[i]; - return 0; - } - else if ((*groups)[i].groups_len > 0) { - return _group_lookup((*groups)[i].groups, (*groups)[i].groups_len, group_id, group); - } - } - - return -REGISTRY_ERROR_GROUP_NOT_FOUND; -} - -static const registry_parameter_t *_internal_parameter_lookup(const registry_group_t *group, - const registry_parameter_id_t parameter_id) -{ - assert(group != NULL); - - for (size_t i = 0; i < group->parameters_len; i++) { - if (group->parameters[i]->id == parameter_id) { - return group->parameters[i]; - } - } - - for (size_t i = 0; i < group->groups_len; i++) { - return _internal_parameter_lookup(group->groups[i], parameter_id); - } - - return NULL; -} - -static int _parameter_lookup(const registry_schema_t *schema, - const registry_parameter_id_t parameter_id, - const registry_parameter_t **parameter) -{ - assert(schema != NULL); - assert(parameter != NULL); - - for (size_t i = 0; i < schema->parameters_len; i++) { - if (schema->parameters[i]->id == parameter_id) { - *parameter = schema->parameters[i]; - return 0; - } - } - - for (size_t i = 0; i < schema->groups_len; i++) { - const registry_parameter_t *found_parameter = _internal_parameter_lookup(schema->groups[i], parameter_id); - if (found_parameter != NULL) { - *parameter = found_parameter; - return 0; - } - } - - return -REGISTRY_ERROR_PARAMETER_NOT_FOUND; -} - int registry_node_to_int_path(const registry_node_t *node, registry_int_path_t *path) { assert(node != NULL); @@ -207,123 +82,55 @@ int registry_node_to_int_path(const registry_node_t *node, registry_int_path_t * return 0; } -int registry_node_from_int_path(const registry_int_path_t *path, registry_node_t *node) -{ - assert(path != NULL); - assert(node != NULL); +static registry_find_result_type _compare_node_by_id(const registry_node_t *node, const void *context) { + const registry_int_path_t *path = context; - registry_namespace_id_t namespace_id = 0; - registry_schema_id_t schema_id = 0; - registry_instance_id_t instance_id = 0; - registry_group_or_parameter_id_t group_or_parameter_id = 0; - registry_parameter_id_t parameter_id = 0; - registry_group_id_t group_id = 0; + bool id_matches = false; + bool path_type_matches = false; - switch (path->type) + switch (node->type) { - case REGISTRY_INT_PATH_TYPE_NAMESPACE: - namespace_id = path->value.namespace_path.namespace_id; - break; - - case REGISTRY_INT_PATH_TYPE_SCHEMA: - namespace_id = path->value.schema_path.namespace_id; - schema_id = path->value.schema_path.schema_id; + case REGISTRY_NODE_NAMESPACE: + id_matches = node->value.namespace->id == path->value.namespace_path.namespace_id; + path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_NAMESPACE; break; - - case REGISTRY_INT_PATH_TYPE_INSTANCE: - namespace_id = path->value.instance_path.namespace_id; - schema_id = path->value.instance_path.schema_id; - instance_id = path->value.instance_path.instance_id; + + case REGISTRY_NODE_SCHEMA: + id_matches = node->value.schema->id == path->value.schema_path.schema_id; + path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_SCHEMA; break; - - case REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER: - namespace_id = path->value.group_or_parameter_path.namespace_id; - schema_id = path->value.group_or_parameter_path.schema_id; - instance_id = path->value.group_or_parameter_path.instance_id; - group_or_parameter_id = path->value.group_or_parameter_path.group_or_parameter_id; + + case REGISTRY_NODE_INSTANCE: + id_matches = node->value.instance->id == path->value.instance_path.instance_id; + path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_INSTANCE; break; - - case REGISTRY_INT_PATH_TYPE_GROUP: - namespace_id = path->value.group_path.namespace_id; - schema_id = path->value.group_path.schema_id; - instance_id = path->value.group_path.instance_id; - group_id = path->value.group_path.group_id; + + case REGISTRY_NODE_GROUP: + id_matches = node->value.group.group->id == path->value.group_path.group_id; + path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_GROUP || path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER; break; - - case REGISTRY_INT_PATH_TYPE_PARAMETER: - namespace_id = path->value.parameter_path.namespace_id; - schema_id = path->value.parameter_path.schema_id; - instance_id = path->value.parameter_path.instance_id; - parameter_id = path->value.parameter_path.parameter_id; + + case REGISTRY_NODE_PARAMETER: + id_matches = node->value.parameter.parameter->id == path->value.parameter_path.parameter_id; + path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_PARAMETER || path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER; break; } - /* Namespace */ - registry_namespace_t *namespace; - int res = _namespace_lookup(namespace_id, &namespace); - - if (res == 0) { - if (path->type == REGISTRY_INT_PATH_TYPE_NAMESPACE) { - node->type = REGISTRY_NODE_NAMESPACE; - node->value.namespace = namespace; - return res; + if (id_matches) { + if (path_type_matches) { + return REGISTRY_FIND_EXACT_MATCH; } - - /* Schema */ - const registry_schema_t *schema; - res = _schema_lookup(namespace, schema_id, &schema); - if (res == 0) { - if (path->type == REGISTRY_INT_PATH_TYPE_SCHEMA) { - node->type = REGISTRY_NODE_SCHEMA; - node->value.schema = schema; - return res; - } - - /* Instance */ - const registry_instance_t *instance; - res = _instance_lookup(schema, instance_id, &instance); - - if (res == 0) { - if (path->type == REGISTRY_INT_PATH_TYPE_INSTANCE) { - node->type = REGISTRY_NODE_INSTANCE; - node->value.instance = instance; - return res; - } - - /* Group or Parameter */ - if (path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER) { - res = _group_lookup(schema->groups, schema->groups_len, group_or_parameter_id, &node->value.group.group); - if (res == 0) { - node->type = REGISTRY_NODE_GROUP; - node->value.group.instance = instance; - return res; - } - - res = _parameter_lookup(schema, group_or_parameter_id, &node->value.parameter.parameter); - if (res == 0) { - node->type = REGISTRY_NODE_PARAMETER; - node->value.parameter.instance = instance; - return res; - } - } - - /* Group */ - if (path->type == REGISTRY_INT_PATH_TYPE_GROUP) { - node->type = REGISTRY_NODE_GROUP; - node->value.group.instance = instance; - return _group_lookup(schema->groups, schema->groups_len, group_id, &node->value.group.group); - } - - /* Parameter */ - if (path->type == REGISTRY_INT_PATH_TYPE_PARAMETER) { - node->type = REGISTRY_NODE_PARAMETER; - node->value.parameter.instance = instance; - return _parameter_lookup(schema, parameter_id, &node->value.parameter.parameter); - } - } - } + return REGISTRY_FIND_PARTIAL_MATCH; } + + return REGISTRY_FIND_NO_MATCH; +} + +registry_error_t registry_node_from_int_path(const registry_int_path_t *path, registry_node_t *node) +{ + assert(path != NULL); + assert(node != NULL); - return res; + return registry_find(_compare_node_by_id, path, node); } From 130d1b51da9958e52b1dd406f46d79177c208d9e Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 3 May 2024 17:42:27 +0200 Subject: [PATCH 079/117] fixup! sys/registry: add string_path module Utilize new tree traversal module --- sys/include/registry/string_path.h | 5 +- sys/registry/string_path.c | 281 +++++------------------------ 2 files changed, 51 insertions(+), 235 deletions(-) diff --git a/sys/include/registry/string_path.h b/sys/include/registry/string_path.h index 47db10c264c4..59a15e79d1e9 100644 --- a/sys/include/registry/string_path.h +++ b/sys/include/registry/string_path.h @@ -28,6 +28,7 @@ extern "C" { #endif #include "registry.h" +#include "registry/error.h" /** * @brief Converts a registry namespace to its string path representation. @@ -43,13 +44,13 @@ int registry_node_to_string_path(const registry_node_t *node, char *path); /** * @brief Converts a string path to a registry namespace. * - * @param[in] path The string path to convert. + * @param[in] path The string path array to convert. * @param[in] path_len Length of the path. * @param[out] node A location within the registry configuration tree. * * @return 0 on success, non-zero on failure. */ -int registry_node_from_string_path(const char *path, const size_t path_len, registry_node_t *node); +registry_error_t registry_node_from_string_path(const char **path, const size_t path_len, registry_node_t *node); #ifdef __cplusplus } diff --git a/sys/registry/string_path.c b/sys/registry/string_path.c index 23d4cdae253e..2901d48198e1 100644 --- a/sys/registry/string_path.c +++ b/sys/registry/string_path.c @@ -34,195 +34,18 @@ #include "registry.h" #include "registry/util.h" #include "registry/error.h" +#include "registry/tree_traversal.h" #include "registry/string_path.h" -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - -XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); - -static int _namespace_lookup(const char *path, const registry_namespace_t **namespace) -{ - assert(path != NULL); - assert(namespace != NULL); - - char *ptr = (char *)path; - - /* remove '/' character */ - ptr++; - - for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { - const size_t name_length = strlen(_registry_namespaces_xfa[i]->name); - - /* check if length of path and name match */ - if (strlen(ptr) >= name_length) { - if (*(ptr + name_length) == '\0' || - *(ptr + name_length) == '/') { - /* check if strings are equal */ - if (strncmp(ptr, _registry_namespaces_xfa[i]->name, name_length) == 0) { - *namespace = _registry_namespaces_xfa[i]; - return name_length + 1; /* name_length + `/` character */ - } - } - } - } - - return -EINVAL; -} - -static int _schema_lookup(const char *path, const registry_namespace_t *namespace, - const registry_schema_t **schema) -{ - assert(path != NULL); - assert(namespace != NULL); - assert(schema != NULL); - - char *ptr = (char *)path; - - /* remove '/' character */ - ptr++; - - for (size_t i = 0; i < namespace->schemas_len; i++) { - const size_t name_length = strlen(namespace->schemas[i]->name); - - /* check if length of path and name match */ - if (strlen(ptr) >= name_length) { - if (*(ptr + name_length) == '\0' || - *(ptr + name_length) == '/') { - /* check if strings are equal */ - if (strncmp(ptr, namespace->schemas[i]->name, name_length) == 0) { - *schema = (registry_schema_t *)namespace->schemas[i]; - return name_length + 1; /* name_length + `/` character */ - } - } - } - } - - return -EINVAL; -} - -static int _instance_lookup(const char *path, const registry_schema_t *schema, - const registry_instance_t **instance) -{ - assert(path != NULL); - assert(schema != NULL); - assert(instance != NULL); - - char *ptr = (char *)path; - - /* remove '/' character */ - ptr++; - - clist_node_t *node = schema->instances.next; - - if (!node) { - return -REGISTRY_ERROR_INSTANCE_NOT_FOUND; - } - - do { - node = node->next; - - const size_t name_length = strlen(container_of(node, registry_instance_t, node)->name); - - /* check if length of path and name match */ - if (strlen(ptr) >= name_length) { - if (*(ptr + name_length) == '\0' || - *(ptr + name_length) == '/') { - /* check if strings are equal */ - if (strncmp(ptr, container_of(node, registry_instance_t, node)->name, - name_length) == 0) { - *instance = container_of(node, registry_instance_t, node); - return name_length + 1; /* name_length + `/` character */ - } - } - } - } while (node != schema->instances.next); - - return -EINVAL; -} - -static int _group_or_parameter_lookup(const char *path, const registry_schema_t *schema, - registry_node_t *node) -{ - assert(path != NULL); - assert(schema != NULL); - assert(node != NULL); - char *ptr = (char *)path; - - /* remove '/' character */ - ptr++; - - /* store the current path position */ - size_t path_position = 0; - - /* search for matching parameters or groups */ - bool found_subgroup = true; - const registry_parameter_t **parameters = schema->parameters; - size_t parameters_len = schema->parameters_len; - - const registry_group_t **groups = schema->groups; - size_t groups_len = schema->groups_len; - - while (found_subgroup) { - /* check for matching parameter */ - for (size_t i = 0; i < parameters_len; i++) { - const size_t name_length = strlen(parameters[i]->name); - - /* parameter matches => return parameters */ - if (strlen(ptr + path_position) == name_length && - strncmp(ptr + path_position, parameters[i]->name, name_length) == 0) { - node->value.parameter.parameter = parameters[i]; - node->type = REGISTRY_NODE_PARAMETER; - return path_position + name_length + 1; /* name_length + `/` character */ - } - } - - /* check for matching subgroup */ - for (size_t i = 0; i < groups_len; i++) { - const size_t name_length = strlen(groups[i]->name); - - /* check if remaining path is at least longer than the group name */ - if (strlen(ptr + path_position) >= name_length) { - /* group matches but end of path is not reached => save subgroups and parameters and keep searching them */ - if (*(ptr + path_position + name_length) == '/' && - strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { - if (groups[i]->parameters_len > 0) { - found_subgroup = true; - parameters = groups[i]->parameters; - parameters_len = groups[i]->parameters_len; - } - else { - parameters = NULL; - parameters_len = 0; - } - - if (groups[i]->groups_len > 0) { - found_subgroup = true; - groups = groups[i]->groups; - groups_len = groups[i]->groups_len; - } - else { - groups = NULL; - groups_len = 0; - } - - path_position += name_length + 1; /* name_length + `/` character */ - break; - } - /* end of path => return group if it matches */ - else if (*(ptr + path_position + name_length) == '\0' && - strncmp(ptr + path_position, groups[i]->name, name_length) == 0) { - node->value.group.group = groups[i]; - node->type = REGISTRY_NODE_GROUP; - return path_position + name_length + 1; /* name_length + `/` character */ - } - } - } - } +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - return -EINVAL; -} +typedef struct { + const char **path; + size_t path_len; + size_t position; +} _registry_string_comparator_context_t; static int _internal_registry_to_group_string_path(const registry_group_t *current_group, const registry_group_t *group, char *path) @@ -376,64 +199,56 @@ int registry_node_to_string_path(const registry_node_t *node, char *path) return size; } -int registry_node_from_string_path(const char *path, const size_t path_len, registry_node_t *node) -{ - /* store the current path position */ - size_t path_position = 0; +static registry_find_result_type _compare_node_by_string(const registry_node_t *node, const void *context) { + _registry_string_comparator_context_t *data = (void*)context; + + const char *name = NULL; + + switch (node->type) + { + case REGISTRY_NODE_NAMESPACE: + name = node->value.namespace->name; + break; - /* namespace */ - const registry_namespace_t *found_namespace; - int res = _namespace_lookup(path, &found_namespace); + case REGISTRY_NODE_SCHEMA: + name = node->value.schema->name; + break; - if (res >= 0) { - node->type = REGISTRY_NODE_NAMESPACE; - node->value.namespace = found_namespace; + case REGISTRY_NODE_INSTANCE: + name = node->value.instance->name; + break; - path_position += res; + case REGISTRY_NODE_GROUP: + name = node->value.group.group->name; + break; - if (path_position < path_len - 1) { - /* schema */ - const registry_schema_t *found_schema; - res = _schema_lookup(path + path_position, found_namespace, &found_schema); - if (res >= 0) { - node->type = REGISTRY_NODE_SCHEMA; - node->value.schema = found_schema; - - path_position += res; - - if (path_position < path_len - 1) { - /* instance */ - const registry_instance_t *found_instance; - res = _instance_lookup(path + path_position, found_schema, &found_instance); - - if (res >= 0) { - node->type = REGISTRY_NODE_INSTANCE; - node->value.instance = found_instance; - - path_position += res; - - if (path_position < path_len - 1) { - /* group or parameter */ - res = _group_or_parameter_lookup(path + path_position, found_schema, node); - - if (node->type == REGISTRY_NODE_GROUP) { - node->value.group.instance = found_instance; - } else if (node->type == REGISTRY_NODE_PARAMETER) { - node->value.parameter.instance = found_instance; - } - } - } - } - } - } + case REGISTRY_NODE_PARAMETER: + name = node->value.parameter.parameter->name; + break; } - if (res < 0) { - return res; + if (strncmp(data->path[data->position], name, strlen(name)) == 0) { + if (data->path_len == data->position + 1) { + return REGISTRY_FIND_EXACT_MATCH; + } + + data->position++; + return REGISTRY_FIND_PARTIAL_MATCH; } + + return REGISTRY_FIND_NO_MATCH; +} + +registry_error_t registry_node_from_string_path(const char **path, const size_t path_len, registry_node_t *node) +{ + _registry_string_comparator_context_t context = { + .path = path, + .path_len = path_len, + .position = 0, + }; - return 0; + return registry_find(_compare_node_by_string, &context, node); } #endif From 3204ad67d71acb91b99f14741719e745e387acae Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Fri, 3 May 2024 17:43:06 +0200 Subject: [PATCH 080/117] fixup! tests/unittests: add registry_string_path tests Adjust to changed string_path api --- .../tests-registry_string_path.c | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tests/unittests/tests-registry_string_path/tests-registry_string_path.c b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c index 697e66fedb58..06249274a44f 100644 --- a/tests/unittests/tests-registry_string_path/tests-registry_string_path.c +++ b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c @@ -26,6 +26,7 @@ #include #include #include "embUnit.h" +#include "kernel_defines.h" #include "fmt.h" #include "assert.h" #include "vfs.h" @@ -145,8 +146,8 @@ static void tests_registry_from_parameter_string_path(void) { registry_node_t node; - char str[] = "/tests/nested/instance-1/group/parameter"; - registry_node_from_string_path(str, sizeof(str), &node); + const char *str[] = { "tests", "nested", "instance-1", "group", "parameter" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); TEST_ASSERT_EQUAL_STRING("tests", node.value.parameter.parameter->schema->namespace->name); @@ -159,8 +160,8 @@ static void tests_registry_from_group_string_path(void) { registry_node_t node; - char str[] = "/tests/nested/instance-1/group"; - registry_node_from_string_path(str, sizeof(str), &node); + const char *str[] = { "tests", "nested", "instance-1", "group" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_GROUP, node.type); TEST_ASSERT_EQUAL_STRING("tests", node.value.group.group->schema->namespace->name); @@ -173,8 +174,8 @@ static void tests_registry_from_instance_string_path(void) { registry_node_t node; - char str[] = "/tests/nested/instance-1"; - registry_node_from_string_path(str, sizeof(str), &node); + const char *str[] = { "tests", "nested", "instance-1" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_INSTANCE, node.type); TEST_ASSERT_EQUAL_STRING("tests", node.value.instance->schema->namespace->name); @@ -186,8 +187,8 @@ static void tests_registry_from_schema_string_path(void) { registry_node_t node; - char str[] = "/tests/nested"; - registry_node_from_string_path(str, sizeof(str), &node); + const char *str[] = { "tests", "nested" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_SCHEMA, node.type); TEST_ASSERT_EQUAL_STRING("tests", node.value.schema->namespace->name); @@ -198,8 +199,8 @@ static void tests_registry_from_namespace_string_path(void) { registry_node_t node; - char str[] = "/tests"; - registry_node_from_string_path(str, sizeof(str), &node); + const char *str[] = { "tests" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_NAMESPACE, node.type); TEST_ASSERT_EQUAL_STRING("tests", node.value.namespace->name); @@ -207,6 +208,17 @@ static void tests_registry_from_namespace_string_path(void) Test *tests_registry_string_path_tests(void) { + (void)tests_registry_to_parameter_string_path; + (void)tests_registry_to_group_string_path; + (void)tests_registry_to_instance_string_path; + (void)tests_registry_to_schema_string_path; + (void)tests_registry_to_namespace_string_path; + (void)tests_registry_from_parameter_string_path; + (void)tests_registry_from_group_string_path; + (void)tests_registry_from_instance_string_path; + (void)tests_registry_from_schema_string_path; + (void)tests_registry_from_namespace_string_path; + EMB_UNIT_TESTFIXTURES(fixtures) { /* to string_path */ new_TestFixture(tests_registry_to_parameter_string_path), @@ -214,7 +226,7 @@ Test *tests_registry_string_path_tests(void) new_TestFixture(tests_registry_to_instance_string_path), new_TestFixture(tests_registry_to_schema_string_path), new_TestFixture(tests_registry_to_namespace_string_path), - /* from string_path */ + // /* from string_path */ new_TestFixture(tests_registry_from_parameter_string_path), new_TestFixture(tests_registry_from_group_string_path), new_TestFixture(tests_registry_from_instance_string_path), From 38c6dc143529e0aaa606525cbd3d0a4ae9178088 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 18:42:57 +0200 Subject: [PATCH 081/117] fixup! sys/registry: add tree traversal utility Rename tree-traversal to find --- sys/include/registry/{tree_traversal.h => find.h} | 4 ++-- sys/registry/{tree_traversal.c => find.c} | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename sys/include/registry/{tree_traversal.h => find.h} (90%) rename sys/registry/{tree_traversal.c => find.c} (97%) diff --git a/sys/include/registry/tree_traversal.h b/sys/include/registry/find.h similarity index 90% rename from sys/include/registry/tree_traversal.h rename to sys/include/registry/find.h index f3f0e6196da2..4c5d268a46ae 100644 --- a/sys/include/registry/tree_traversal.h +++ b/sys/include/registry/find.h @@ -7,9 +7,9 @@ */ /** - * @defgroup sys_registry_tree_traversal RIOT Registry tree traversal utilities + * @defgroup sys_registry_find RIOT Registry utility to find registry nodes * @ingroup sys - * @brief RIOT Registry Tree traversal module providing utility functions to travers the configuration tree + * @brief RIOT Registry Find module for finding specific nodes within the configuration tree * @{ * * @file diff --git a/sys/registry/tree_traversal.c b/sys/registry/find.c similarity index 97% rename from sys/registry/tree_traversal.c rename to sys/registry/find.c index cbd2e8c5d634..743e95044ba9 100644 --- a/sys/registry/tree_traversal.c +++ b/sys/registry/find.c @@ -7,9 +7,9 @@ */ /** - * @defgroup sys_registry_tree_traversal RIOT Registry tree traversal utilities + * @defgroup sys_registry_find RIOT Registry utility to find registry nodes * @ingroup sys - * @brief RIOT Registry Tree traversal module providing utility functions to travers the configuration tree + * @brief RIOT Registry Find module for finding specific nodes within the configuration tree * @{ * * @file @@ -33,7 +33,7 @@ #include "registry.h" #include "registry/error.h" -#include "registry/tree_traversal.h" +#include "registry/find.h" XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); From 95e3ea26d5e10ba94a3cff44d7174dee11a158de Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 18:43:58 +0200 Subject: [PATCH 082/117] fixup! sys: add runtime configuration registry Improve commit implementation --- sys/include/registry.h | 4 +- sys/registry/Makefile | 2 +- sys/registry/Makefile.dep | 8 +++ sys/registry/Makefile.include | 2 +- sys/registry/registry.c | 107 +++++++++------------------------- 5 files changed, 40 insertions(+), 83 deletions(-) diff --git a/sys/include/registry.h b/sys/include/registry.h index 6b2344957a1e..3164d9e8490d 100644 --- a/sys/include/registry.h +++ b/sys/include/registry.h @@ -360,8 +360,8 @@ int registry_commit(const registry_node_t *node); */ typedef int (*registry_export_cb_t)(const registry_node_t *node, const void *context); -#define REGISTRY_EXPORT_ALL = 0; -#define REGISTRY_EXPORT_SELF = 1; +#define REGISTRY_EXPORT_ALL 0; +#define REGISTRY_EXPORT_SELF 1; #define REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(_n) (_n + 1); /** diff --git a/sys/registry/Makefile b/sys/registry/Makefile index 9702771336d2..ee04422a8c26 100644 --- a/sys/registry/Makefile +++ b/sys/registry/Makefile @@ -1,4 +1,4 @@ -SRC := registry.c init.c tree_traversal.c +SRC := registry.c init.c SUBMODULES := 1 diff --git a/sys/registry/Makefile.dep b/sys/registry/Makefile.dep index 0120c9b94015..9a7fd7d7ecfd 100644 --- a/sys/registry/Makefile.dep +++ b/sys/registry/Makefile.dep @@ -6,6 +6,14 @@ ifneq (,$(filter registry_storage%,$(USEMODULE))) include $(RIOTBASE)/sys/registry/storage/Makefile.dep endif +ifneq (,$(filter registry_int_path%,$(USEMODULE))) + USEMODULE += registry_find +endif + +ifneq (,$(filter registry_string_path%,$(USEMODULE))) + USEMODULE += registry_find +endif + ifneq (,$(filter registry_util%,$(USEMODULE))) USEMODULE += base64 endif diff --git a/sys/registry/Makefile.include b/sys/registry/Makefile.include index 2f8b6ebb115f..d43c8233d207 100644 --- a/sys/registry/Makefile.include +++ b/sys/registry/Makefile.include @@ -1,3 +1,3 @@ ifneq (,$(filter registry_string_path%,$(USEMODULE))) CFLAGS += -DCONFIG_REGISTRY_ENABLE_META_NAME -endif \ No newline at end of file +endif diff --git a/sys/registry/registry.c b/sys/registry/registry.c index a5cddc3bf057..a35ca668ed08 100644 --- a/sys/registry/registry.c +++ b/sys/registry/registry.c @@ -110,109 +110,57 @@ int registry_set(const registry_node_t *node, const void *buf, const size_t buf_ return 0; } -static int _registry_commit_parameter(const registry_instance_t *instance, - const registry_parameter_t *parameter) -{ - return instance->commit_cb(REGISTRY_COMMIT_PARAMETER, ¶meter->id, instance->context); -} - -static int _registry_commit_group(const registry_instance_t *instance, const registry_group_t *group) -{ - return instance->commit_cb(REGISTRY_COMMIT_GROUP, &group->id, instance->context); -} - -static int _registry_commit_instance(const registry_instance_t *instance) -{ - return instance->commit_cb(REGISTRY_COMMIT_INSTANCE, NULL, instance->context); -} - -static int _registry_commit_schema(const registry_schema_t *schema) -{ - assert(schema != NULL); - - int rc = 0; +static int _commit_export_cb(const registry_node_t *node, const void *context) { + (void)context; - /* commit all configuration schema instances of the given configuration schema if available */ - clist_node_t *node = schema->instances.next; - - if (!node) { - return -EINVAL; - } - - do { - node = node->next; - registry_instance_t *instance = container_of(node, registry_instance_t, node); - - if (!instance) { - return -EINVAL; - } - - int _rc = _registry_commit_instance(instance); - - if (!_rc) { - rc = _rc; - } - } while (node != schema->instances.next); - - return rc; -} + const registry_instance_t *instance; -static int _registry_commit_namespace(const registry_namespace_t *namespace) -{ - assert(namespace != NULL); - - int rc = 0; + switch (node->type) + { + /* The commit function is only called for instance and below */ + case REGISTRY_NODE_NAMESPACE: + case REGISTRY_NODE_SCHEMA: + return 0; - /* commit all configuration schemas of the given namespace if available */ - for (size_t i = 0; i < namespace->schemas_len; i++) { - const registry_schema_t *child = namespace->schemas[i]; + case REGISTRY_NODE_INSTANCE: + instance = node->value.instance; + return instance->commit_cb(REGISTRY_COMMIT_INSTANCE, NULL, instance->context); - int _rc = _registry_commit_schema(child); + case REGISTRY_NODE_GROUP: + instance = node->value.group.instance; + return instance->commit_cb(REGISTRY_COMMIT_GROUP, &node->value.group.group->id, instance->context); - if (!_rc) { - rc = _rc; - } + case REGISTRY_NODE_PARAMETER: + instance = node->value.parameter.instance; + return instance->commit_cb(REGISTRY_COMMIT_PARAMETER, &node->value.parameter.parameter->id, instance->context); } - return rc; + return 0; } int registry_commit(const registry_node_t *node) { - int rc = 0; - - if (node == NULL) { - /* commit all namespaces */ - for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { - registry_namespace_t *namespace = _registry_namespaces_xfa[i]; + int tree_traversal_depth = REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(3); - int _rc = _registry_commit_namespace(namespace); - - if (!_rc) { - rc = _rc; - } - } - } else { + if (node != NULL) { switch (node->type) { case REGISTRY_NODE_NAMESPACE: - rc = _registry_commit_namespace(node->value.namespace); + tree_traversal_depth = REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(2); break; + case REGISTRY_NODE_SCHEMA: - rc = _registry_commit_schema(node->value.schema); + tree_traversal_depth = REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(1); break; + case REGISTRY_NODE_INSTANCE: - rc = _registry_commit_instance(node->value.instance); - break; case REGISTRY_NODE_GROUP: - rc = _registry_commit_group(node->value.group.instance, node->value.group.group); - break; case REGISTRY_NODE_PARAMETER: - rc = _registry_commit_parameter(node->value.parameter.instance, node->value.parameter.parameter); + tree_traversal_depth = REGISTRY_EXPORT_SELF; break; } } - return rc; + return registry_export(node, _commit_export_cb, tree_traversal_depth, NULL); } static int _registry_export_parameter(const registry_instance_t *instance, @@ -418,6 +366,7 @@ static int _registry_export_namespace(const registry_namespace_t *namespace, int registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context) { + int rc = 0; if (node == NULL) { From b61abb0a0732dd834b38d471b18c5a664532cef6 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 18:44:38 +0200 Subject: [PATCH 083/117] fixup! sys/registry: add int_path module Adjust to tree-traversal rename --- sys/registry/int_path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/registry/int_path.c b/sys/registry/int_path.c index 6e5d690aff3a..d6b76add42b3 100644 --- a/sys/registry/int_path.c +++ b/sys/registry/int_path.c @@ -33,7 +33,7 @@ #include "registry.h" #include "registry/util.h" #include "registry/error.h" -#include "registry/tree_traversal.h" +#include "registry/find.h" #include "registry/int_path.h" From 49e643afb1ed2eea01c45c3de805766bc1785cc0 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 18:45:02 +0200 Subject: [PATCH 084/117] fixup! sys/registry: add string_path module Adjust to tree-traversal rename --- sys/registry/string_path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/registry/string_path.c b/sys/registry/string_path.c index 2901d48198e1..76057329f97f 100644 --- a/sys/registry/string_path.c +++ b/sys/registry/string_path.c @@ -34,7 +34,7 @@ #include "registry.h" #include "registry/util.h" #include "registry/error.h" -#include "registry/tree_traversal.h" +#include "registry/find.h" #include "registry/string_path.h" From 3e638c1f9cdb2bfecd24449eee8d35e10cf96375 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 20:06:55 +0200 Subject: [PATCH 085/117] fixup! sys: add runtime configuration registry Implement registry_error_t --- sys/include/registry.h | 15 +++-- sys/include/registry/error.h | 6 +- sys/registry/registry.c | 127 +++++++++++++++++------------------ 3 files changed, 76 insertions(+), 72 deletions(-) diff --git a/sys/include/registry.h b/sys/include/registry.h index 3164d9e8490d..b55ce0d07cb1 100644 --- a/sys/include/registry.h +++ b/sys/include/registry.h @@ -29,6 +29,7 @@ extern "C" { #include "clist.h" #include "xfa.h" #include "modules.h" +#include "registry/error.h" /** * @brief Identifier of a configuration namespace. @@ -184,7 +185,7 @@ typedef const enum { * * @return 0 on success, non-zero on failure. */ -typedef int (*registry_commit_cb_t)(const registry_commit_cb_scope_t scope, +typedef registry_error_t (*registry_commit_cb_t)(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context); @@ -313,7 +314,7 @@ void registry_init(void); * * @return 0 on success, non-zero on failure. */ -int registry_add_schema_instance(const registry_schema_t *schema, +registry_error_t registry_add_schema_instance(const registry_schema_t *schema, const registry_instance_t *instance); /** @@ -325,7 +326,7 @@ int registry_add_schema_instance(const registry_schema_t *schema, * * @return 0 on success, non-zero on failure. */ -int registry_get(const registry_node_t *node, registry_value_t *value); +registry_error_t registry_get(const registry_node_t *node, registry_value_t *value); /** * @brief Sets the value of a configuration parameter that belongs to an instance @@ -337,7 +338,7 @@ int registry_get(const registry_node_t *node, registry_value_t *value); * * @return 0 on success, non-zero on failure. */ -int registry_set(const registry_node_t *node, const void *buf, const size_t buf_len); +registry_error_t registry_set(const registry_node_t *node, const void *buf, const size_t buf_len); /** * @brief Commits every configuration parameter within the given configuration location (@p node) of the registry configuration tree. @@ -346,7 +347,7 @@ int registry_set(const registry_node_t *node, const void *buf, const size_t buf_ * * @return 0 on success, non-zero on failure. */ -int registry_commit(const registry_node_t *node); +registry_error_t registry_commit(const registry_node_t *node); /** * @brief Callback definition of the @p registry_export function. @@ -358,7 +359,7 @@ int registry_commit(const registry_node_t *node); * * @return 0 on success, non-zero on failure. */ -typedef int (*registry_export_cb_t)(const registry_node_t *node, const void *context); +typedef registry_error_t (*registry_export_cb_t)(const registry_node_t *node, const void *context); #define REGISTRY_EXPORT_ALL 0; #define REGISTRY_EXPORT_SELF 1; @@ -377,7 +378,7 @@ typedef int (*registry_export_cb_t)(const registry_node_t *node, const void *con * * @return 0 on success, non-zero on failure. */ -int registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context); +registry_error_t registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context); #ifdef __cplusplus } diff --git a/sys/include/registry/error.h b/sys/include/registry/error.h index e887ab359df1..3427fab9584d 100644 --- a/sys/include/registry/error.h +++ b/sys/include/registry/error.h @@ -28,7 +28,8 @@ extern "C" { * @brief Registry specific error codes. */ typedef enum { - REGISTRY_ERROR_NONE = 1, + REGISTRY_ERROR_NONE = 0, + REGISTRY_ERROR_INVALID_ARGUMENT, REGISTRY_ERROR_NO_DST_STORAGE, REGISTRY_ERROR_NAMESPACE_NOT_FOUND, REGISTRY_ERROR_SCHEMA_NOT_FOUND, @@ -36,6 +37,9 @@ typedef enum { REGISTRY_ERROR_GROUP_NOT_FOUND, REGISTRY_ERROR_PARAMETER_NOT_FOUND, REGISTRY_ERROR_NODE_INVALID, + REGISTRY_ERROR_BUF_LEN_TOO_SMALL, + REGISTRY_ERROR_BUF_LEN_TOO_LARGE, + REGISTRY_ERROR_SCHEMA_HAS_NO_INSTANCE, } registry_error_t; #ifdef __cplusplus diff --git a/sys/registry/registry.c b/sys/registry/registry.c index a35ca668ed08..40a7c43b8d40 100644 --- a/sys/registry/registry.c +++ b/sys/registry/registry.c @@ -31,14 +31,13 @@ #include "registry.h" #include "registry/util.h" -#include "registry/error.h" /* Implementation of the module */ XFA_INIT_CONST(registry_namespace_t *, _registry_namespaces_xfa); -int registry_add_schema_instance(const registry_schema_t *schema, - const registry_instance_t *instance) +registry_error_t registry_add_schema_instance(const registry_schema_t *schema, + const registry_instance_t *instance) { assert(schema != NULL); assert(instance != NULL); @@ -55,10 +54,10 @@ int registry_add_schema_instance(const registry_schema_t *schema, /* add instance to schema */ clist_rpush((clist_node_t *)&schema->instances, (clist_node_t *)&instance->node); - return 0; + return REGISTRY_ERROR_NONE; } -int registry_get(const registry_node_t *node, registry_value_t *value) +registry_error_t registry_get(const registry_node_t *node, registry_value_t *value) { assert(node != NULL); assert(value != NULL); @@ -80,10 +79,10 @@ int registry_get(const registry_node_t *node, registry_value_t *value) value->buf = intern_val; value->buf_len = intern_val_len; - return 0; + return REGISTRY_ERROR_NONE; } -int registry_set(const registry_node_t *node, const void *buf, const size_t buf_len) +registry_error_t registry_set(const registry_node_t *node, const void *buf, const size_t buf_len) { assert(node != NULL); assert(buf != NULL); @@ -101,16 +100,16 @@ int registry_set(const registry_node_t *node, const void *buf, const size_t buf_ parameter->schema->mapping(parameter->id, node->value.parameter.instance, &intern_val, &intern_val_len); if (buf_len > intern_val_len) { - return -EINVAL; + return -REGISTRY_ERROR_BUF_LEN_TOO_LARGE; } /* call handler to apply the new value to the correct parameter in the instance of the schema */ memcpy(intern_val, buf, buf_len); - return 0; + return REGISTRY_ERROR_NONE; } -static int _commit_export_cb(const registry_node_t *node, const void *context) { +static registry_error_t _commit_export_cb(const registry_node_t *node, const void *context) { (void)context; const registry_instance_t *instance; @@ -120,7 +119,7 @@ static int _commit_export_cb(const registry_node_t *node, const void *context) { /* The commit function is only called for instance and below */ case REGISTRY_NODE_NAMESPACE: case REGISTRY_NODE_SCHEMA: - return 0; + return REGISTRY_ERROR_NONE; case REGISTRY_NODE_INSTANCE: instance = node->value.instance; @@ -135,11 +134,11 @@ static int _commit_export_cb(const registry_node_t *node, const void *context) { return instance->commit_cb(REGISTRY_COMMIT_PARAMETER, &node->value.parameter.parameter->id, instance->context); } - return 0; + return REGISTRY_ERROR_NONE; } -int registry_commit(const registry_node_t *node) { - int tree_traversal_depth = REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(3); +registry_error_t registry_commit(const registry_node_t *node) { + uint8_t tree_traversal_depth = REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(3); if (node != NULL) { switch (node->type) @@ -163,7 +162,7 @@ int registry_commit(const registry_node_t *node) { return registry_export(node, _commit_export_cb, tree_traversal_depth, NULL); } -static int _registry_export_parameter(const registry_instance_t *instance, +static registry_error_t _registry_export_parameter(const registry_instance_t *instance, const registry_parameter_t *parameter, const registry_export_cb_t export_cb, const void *context) { @@ -180,7 +179,8 @@ static int _registry_export_parameter(const registry_instance_t *instance, return export_cb(&export_node, context); } -static int _registry_export_group(const registry_instance_t *instance, const registry_group_t *group, +static registry_error_t _registry_export_group(const registry_instance_t *instance, + const registry_group_t *group, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context) { @@ -194,36 +194,34 @@ static int _registry_export_group(const registry_instance_t *instance, const reg .group = group, }, }; - int rc = export_cb(&export_node, context); + registry_error_t rc = export_cb(&export_node, context); /* export all children of the given configuration group if available and within tree_traversal_depth bounds */ if (tree_traversal_depth == 1) { - return 0; + return REGISTRY_ERROR_NONE; } else { - int new_tree_traversal_depth = tree_traversal_depth; + uint8_t new_tree_traversal_depth = tree_traversal_depth; if (tree_traversal_depth > 1) { new_tree_traversal_depth--; } - int _rc = rc; - /* group */ for (size_t i = 0; i < group->groups_len; i++) { - _rc = _registry_export_group(instance, group->groups[i], export_cb, new_tree_traversal_depth, + rc = _registry_export_group(instance, group->groups[i], export_cb, new_tree_traversal_depth, context); - if (!_rc) { - rc = _rc; + if (!rc == REGISTRY_ERROR_NONE) { + return rc; } } /* parameter */ for (size_t i = 0; i < group->parameters_len; i++) { - _rc = _registry_export_parameter(instance, group->parameters[i], export_cb, context); + rc = _registry_export_parameter(instance, group->parameters[i], export_cb, context); - if (!_rc) { - rc = _rc; + if (!rc == REGISTRY_ERROR_NONE) { + return rc; } } } @@ -231,9 +229,11 @@ static int _registry_export_group(const registry_instance_t *instance, const reg return rc; } -static int _registry_export_instance(const registry_instance_t *instance, - const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, - const void *context) +static registry_error_t _registry_export_instance( + const registry_instance_t *instance, + const registry_export_cb_t export_cb, + const uint8_t tree_traversal_depth, + const void *context) { assert(instance != NULL); @@ -242,37 +242,35 @@ static int _registry_export_instance(const registry_instance_t *instance, .type = REGISTRY_NODE_INSTANCE, .value.instance = instance, }; - int rc = export_cb(&export_node, context); + registry_error_t rc = export_cb(&export_node, context); /* export all groups or parameters of the given configuration schema instance if available and within tree_traversal_depth bounds */ if (tree_traversal_depth == 1) { - return 0; + return REGISTRY_ERROR_NONE; } else { - int new_tree_traversal_depth = tree_traversal_depth; + uint8_t new_tree_traversal_depth = tree_traversal_depth; if (tree_traversal_depth > 1) { new_tree_traversal_depth--; } - int _rc = rc; - /* groups */ for (size_t i = 0; i < instance->schema->groups_len; i++) { - _rc = _registry_export_group(instance, instance->schema->groups[i], export_cb, + rc = _registry_export_group(instance, instance->schema->groups[i], export_cb, new_tree_traversal_depth, context); - if (!_rc) { - rc = _rc; + if (!rc == REGISTRY_ERROR_NONE) { + return rc; } } /* parameters */ for (size_t i = 0; i < instance->schema->parameters_len; i++) { - _rc = _registry_export_parameter(instance, instance->schema->parameters[i], export_cb, + rc = _registry_export_parameter(instance, instance->schema->parameters[i], export_cb, context); - if (!_rc) { - rc = _rc; + if (!rc == REGISTRY_ERROR_NONE) { + return rc; } } } @@ -280,8 +278,10 @@ static int _registry_export_instance(const registry_instance_t *instance, return rc; } -static int _registry_export_schema(const registry_schema_t *schema, const registry_export_cb_t export_cb, - const uint8_t tree_traversal_depth, const void *context) +static registry_error_t _registry_export_schema( + const registry_schema_t *schema, + const registry_export_cb_t export_cb, + const uint8_t tree_traversal_depth, const void *context) { assert(schema != NULL); @@ -290,14 +290,14 @@ static int _registry_export_schema(const registry_schema_t *schema, const regist .type = REGISTRY_NODE_SCHEMA, .value.schema = schema, }; - int rc = export_cb(&export_node, context); + registry_error_t rc = export_cb(&export_node, context); /* export all instances of the given configuration schema if available and within tree_traversal_depth bounds */ if (tree_traversal_depth == 1) { - return 0; + return REGISTRY_ERROR_NONE; } else { - int new_tree_traversal_depth = tree_traversal_depth; + uint8_t new_tree_traversal_depth = tree_traversal_depth; if (tree_traversal_depth > 1) { new_tree_traversal_depth--; } @@ -305,7 +305,7 @@ static int _registry_export_schema(const registry_schema_t *schema, const regist clist_node_t *node = schema->instances.next; if (!node) { - return -EINVAL; + return -REGISTRY_ERROR_SCHEMA_HAS_NO_INSTANCE; } do { @@ -313,13 +313,13 @@ static int _registry_export_schema(const registry_schema_t *schema, const regist registry_instance_t *instance = container_of(node, registry_instance_t, node); if (!instance) { - return -EINVAL; + return -REGISTRY_ERROR_SCHEMA_HAS_NO_INSTANCE; } - int _rc = _registry_export_instance(instance, export_cb, new_tree_traversal_depth, context); + rc = _registry_export_instance(instance, export_cb, new_tree_traversal_depth, context); - if (!_rc) { - rc = _rc; + if (!rc == REGISTRY_ERROR_NONE) { + return rc; } } while (node != schema->instances.next); } @@ -327,7 +327,7 @@ static int _registry_export_schema(const registry_schema_t *schema, const regist return rc; } -static int _registry_export_namespace(const registry_namespace_t *namespace, +static registry_error_t _registry_export_namespace(const registry_namespace_t *namespace, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context) { @@ -338,14 +338,14 @@ static int _registry_export_namespace(const registry_namespace_t *namespace, .type = REGISTRY_NODE_NAMESPACE, .value.namespace = namespace, }; - int rc = export_cb(&export_node, context); + registry_error_t rc = export_cb(&export_node, context); /* export all configuration schemas of the given namespace if available and within tree_traversal_depth bounds */ if (tree_traversal_depth == 1) { - return 0; + return REGISTRY_ERROR_NONE; } else { - int new_tree_traversal_depth = tree_traversal_depth; + uint8_t new_tree_traversal_depth = tree_traversal_depth; if (tree_traversal_depth > 1) { new_tree_traversal_depth--; } @@ -353,10 +353,10 @@ static int _registry_export_namespace(const registry_namespace_t *namespace, for (size_t i = 0; i < namespace->schemas_len; i++) { const registry_schema_t *child = namespace->schemas[i]; - int _rc = _registry_export_schema(child, export_cb, new_tree_traversal_depth, context); + rc = _registry_export_schema(child, export_cb, new_tree_traversal_depth, context); - if (!_rc) { - rc = _rc; + if (!rc == REGISTRY_ERROR_NONE) { + return rc; } } } @@ -364,20 +364,19 @@ static int _registry_export_namespace(const registry_namespace_t *namespace, return rc; } -int registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context) +registry_error_t registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context) { - - int rc = 0; + registry_error_t rc = REGISTRY_ERROR_NONE; if (node == NULL) { /* export all namespaces */ for (size_t i = 0; i < XFA_LEN(registry_namespace_t *, _registry_namespaces_xfa); i++) { registry_namespace_t *namespace = _registry_namespaces_xfa[i]; - int _rc = _registry_export_namespace(namespace, export_cb, tree_traversal_depth, context); + rc = _registry_export_namespace(namespace, export_cb, tree_traversal_depth, context); - if (!_rc) { - rc = _rc; + if (!rc == REGISTRY_ERROR_NONE) { + return rc; } } } else { From f0d67928d93f0658509d9929a261267a4365fc9a Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 20:08:16 +0200 Subject: [PATCH 086/117] fixup! sys/registry: add persistent storage module Implement registry_error_t --- sys/include/registry/storage.h | 14 +++++++------- sys/registry/storage/storage.c | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sys/include/registry/storage.h b/sys/include/registry/storage.h index 2ef3c915f111..c1e58570a87d 100644 --- a/sys/include/registry/storage.h +++ b/sys/include/registry/storage.h @@ -35,7 +35,7 @@ extern "C" { * * @return 0 on success, non-zero on failure. */ -typedef int (*load_cb_t)(const registry_node_t *node, const void *buf, const size_t buf_len); +typedef registry_error_t (*load_cb_t)(const registry_node_t *node, const void *buf, const size_t buf_len); typedef struct _registry_storage_t registry_storage_t; @@ -59,7 +59,7 @@ struct _registry_storage_t { * * @return 0 on success, non-zero on failure. */ - int (*load)(const registry_storage_instance_t *storage, + registry_error_t (*load)(const registry_storage_instance_t *storage, const load_cb_t load_cb); /** @@ -71,7 +71,7 @@ struct _registry_storage_t { * * @return 0 on success, non-zero on failure. */ - int (*save_start)(const registry_storage_instance_t *storage); + registry_error_t (*save_start)(const registry_storage_instance_t *storage); /** * @brief Saves a parameter into storage. @@ -82,7 +82,7 @@ struct _registry_storage_t { * * @return 0 on success, non-zero on failure. */ - int (*save)(const registry_storage_instance_t *storage, + registry_error_t (*save)(const registry_storage_instance_t *storage, const registry_node_t *node, const registry_value_t *value); @@ -95,7 +95,7 @@ struct _registry_storage_t { * * @return 0 on success, non-zero on failure. */ - int (*save_end)(const registry_storage_instance_t *storage); + registry_error_t (*save_end)(const registry_storage_instance_t *storage); }; /** @@ -104,7 +104,7 @@ struct _registry_storage_t { * * @return 0 on success, non-zero on failure. */ -int registry_load(void); +registry_error_t registry_load(void); /** * @brief Save all configuration parameters that are within @@ -115,7 +115,7 @@ int registry_load(void); * * @return 0 on success, non-zero on failure. */ -int registry_save(const registry_node_t *node); +registry_error_t registry_save(const registry_node_t *node); /** * @brief Registers a new storage as a source of configurations. Multiple diff --git a/sys/registry/storage/storage.c b/sys/registry/storage/storage.c index aa69f762eab2..0bbb1341c5bd 100644 --- a/sys/registry/storage/storage.c +++ b/sys/registry/storage/storage.c @@ -37,7 +37,7 @@ XFA_INIT_CONST(registry_storage_instance_t *, _registry_storage_instances_src_xfa); /* registry_load */ -static int _registry_load_cb(const registry_node_t *node, const void *buf, const size_t buf_len) +static registry_error_t _registry_load_cb(const registry_node_t *node, const void *buf, const size_t buf_len) { assert(node->type == REGISTRY_NODE_PARAMETER); assert(node->value.parameter.parameter != NULL); @@ -46,30 +46,30 @@ static int _registry_load_cb(const registry_node_t *node, const void *buf, const return registry_set(node, buf, buf_len); } -int registry_load(void) +registry_error_t registry_load(void) { for (size_t i = 0; i < XFA_LEN(registry_storage_instance_t *, _registry_storage_instances_src_xfa); i++) { registry_storage_instance_t *src = _registry_storage_instances_src_xfa[i]; - int res = src->storage->load(src, _registry_load_cb); + registry_error_t res = src->storage->load(src, _registry_load_cb); if (res != 0) { return res; } } - return 0; + return REGISTRY_ERROR_NONE; } /* registry_save */ -static int _registry_save_export_cb(const registry_node_t *node, const void *context) +static registry_error_t _registry_save_export_cb(const registry_node_t *node, const void *context) { (void)context; /* the registry also exports just the namespace or just a schema, but the storage is only interested in configuration parameter values */ if (node->type != REGISTRY_NODE_PARAMETER) { - return 0; + return REGISTRY_ERROR_NONE; } /* check if a destination storage is registered */ @@ -86,9 +86,9 @@ static int _registry_save_export_cb(const registry_node_t *node, const void *con node, &value); } -int registry_save(const registry_node_t *node) +registry_error_t registry_save(const registry_node_t *node) { - int res; + registry_error_t res; if (!_registry_storage_instance_dst) { return -REGISTRY_ERROR_NO_DST_STORAGE; @@ -97,7 +97,7 @@ int registry_save(const registry_node_t *node) if (_registry_storage_instance_dst->storage->save_start) { _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); } - + res = registry_export(node, _registry_save_export_cb, 0, NULL); if (_registry_storage_instance_dst->storage->save_end) { From 50f08d4bc709e53e471da567bbe5904d30fb7e64 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 20:08:39 +0200 Subject: [PATCH 087/117] fixup! sys/registry: add int_path module Implement registry_error_t --- sys/include/registry/int_path.h | 2 +- sys/registry/int_path.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/include/registry/int_path.h b/sys/include/registry/int_path.h index 82fc8e27134b..dc9eb02c8bd2 100644 --- a/sys/include/registry/int_path.h +++ b/sys/include/registry/int_path.h @@ -138,7 +138,7 @@ typedef struct { * * @return 0 on success, non-zero on failure. */ -int registry_node_to_int_path(const registry_node_t *node, registry_int_path_t *path); +registry_error_t registry_node_to_int_path(const registry_node_t *node, registry_int_path_t *path); /** * @brief Converts an integer path to a registry namespace. diff --git a/sys/registry/int_path.c b/sys/registry/int_path.c index d6b76add42b3..23ebb85e52d6 100644 --- a/sys/registry/int_path.c +++ b/sys/registry/int_path.c @@ -37,7 +37,7 @@ #include "registry/int_path.h" -int registry_node_to_int_path(const registry_node_t *node, registry_int_path_t *path) +registry_error_t registry_node_to_int_path(const registry_node_t *node, registry_int_path_t *path) { assert(node != NULL); assert(path != NULL); @@ -79,7 +79,7 @@ int registry_node_to_int_path(const registry_node_t *node, registry_int_path_t * break; } - return 0; + return REGISTRY_ERROR_NONE; } static registry_find_result_type _compare_node_by_id(const registry_node_t *node, const void *context) { From 92890958557b5208b6be5cfac847f260679c6511 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 20:09:16 +0200 Subject: [PATCH 088/117] fixup! tests/unittests: add registry tests Implement registry_error_t --- tests/unittests/tests-registry/tests-commit.c | 12 +++++------ tests/unittests/tests-registry/tests-export.c | 20 +++++++++---------- .../unittests/tests-registry/tests-get-set.c | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/unittests/tests-registry/tests-commit.c b/tests/unittests/tests-registry/tests-commit.c index c35cefdb71b2..dd86d8da1e7d 100644 --- a/tests/unittests/tests-registry/tests-commit.c +++ b/tests/unittests/tests-registry/tests-commit.c @@ -39,7 +39,7 @@ static bool successful = false; static registry_group_or_parameter_id_t parameter_id; static registry_group_or_parameter_id_t group_id; -static int commit_parameter_cb(const registry_commit_cb_scope_t scope, +static registry_error_t commit_parameter_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { @@ -50,10 +50,10 @@ static int commit_parameter_cb(const registry_commit_cb_scope_t scope, successful = true; } - return 0; + return REGISTRY_ERROR_NONE; } -static int commit_group_cb(const registry_commit_cb_scope_t scope, +static registry_error_t commit_group_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { @@ -64,10 +64,10 @@ static int commit_group_cb(const registry_commit_cb_scope_t scope, successful = true; } - return 0; + return REGISTRY_ERROR_NONE; } -static int commit_instance_cb(const registry_commit_cb_scope_t scope, +static registry_error_t commit_instance_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { @@ -77,7 +77,7 @@ static int commit_instance_cb(const registry_commit_cb_scope_t scope, successful = true; } - return 0; + return REGISTRY_ERROR_NONE; } static registry_tests_nested_instance_t test_nested_instance_data = { diff --git a/tests/unittests/tests-registry/tests-export.c b/tests/unittests/tests-registry/tests-export.c index 33d58259b6f6..7506d4bc94a6 100644 --- a/tests/unittests/tests-registry/tests-export.c +++ b/tests/unittests/tests-registry/tests-export.c @@ -50,7 +50,7 @@ static registry_instance_t test_nested_instance_1 = { .commit_cb = NULL, }; -static int export_parameter_cb(const registry_node_t *node, +static registry_error_t export_parameter_cb(const registry_node_t *node, const void *context) { (void)context; @@ -61,10 +61,10 @@ static int export_parameter_cb(const registry_node_t *node, successful = true; } - return 0; + return REGISTRY_ERROR_NONE; } -static int export_group_cb(const registry_node_t *node, +static registry_error_t export_group_cb(const registry_node_t *node, const void *context) { (void)context; @@ -74,10 +74,10 @@ static int export_group_cb(const registry_node_t *node, successful = true; } - return 0; + return REGISTRY_ERROR_NONE; } -static int export_instance_cb(const registry_node_t *node, +static registry_error_t export_instance_cb(const registry_node_t *node, const void *context) { (void)context; @@ -86,10 +86,10 @@ static int export_instance_cb(const registry_node_t *node, successful = true; } - return 0; + return REGISTRY_ERROR_NONE; } -static int export_schema_cb(const registry_node_t *node, +static registry_error_t export_schema_cb(const registry_node_t *node, const void *context) { (void)context; @@ -99,10 +99,10 @@ static int export_schema_cb(const registry_node_t *node, successful = true; } - return 0; + return REGISTRY_ERROR_NONE; } -static int export_namespace_cb(const registry_node_t *node, +static registry_error_t export_namespace_cb(const registry_node_t *node, const void *context) { (void)context; @@ -112,7 +112,7 @@ static int export_namespace_cb(const registry_node_t *node, successful = true; } - return 0; + return REGISTRY_ERROR_NONE; } static void test_registry_setup(void) diff --git a/tests/unittests/tests-registry/tests-get-set.c b/tests/unittests/tests-registry/tests-get-set.c index 12c7e48e8e4d..169b2c8428c0 100644 --- a/tests/unittests/tests-registry/tests-get-set.c +++ b/tests/unittests/tests-registry/tests-get-set.c @@ -38,7 +38,7 @@ #if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) || IS_ACTIVE(DOXYGEN) -static int commit_cb(const registry_commit_cb_scope_t scope, +static registry_error_t commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { @@ -46,7 +46,7 @@ static int commit_cb(const registry_commit_cb_scope_t scope, (void)group_or_parameter_id; (void)context; - return 0; + return REGISTRY_ERROR_NONE; } static registry_tests_full_instance_t test_full_instance_1_data = { From 28bad946c4d56e75d66003de4ca5f43381f0e583 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 20:09:36 +0200 Subject: [PATCH 089/117] fixup! tests/unittests: add registry_storage tests Implement registry_error_t --- .../tests-registry_storage.c | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/tests/unittests/tests-registry_storage/tests-registry_storage.c b/tests/unittests/tests-registry_storage/tests-registry_storage.c index 73d7d3287222..522230baf90d 100644 --- a/tests/unittests/tests-registry_storage/tests-registry_storage.c +++ b/tests/unittests/tests-registry_storage/tests-registry_storage.c @@ -39,6 +39,8 @@ #define _TESTS_REGISTRY_LOAD_STORED_VALUE 60 +static bool successful = false; + static registry_tests_nested_instance_t test_nested_instance_data = { .parameter = 9, .group_parameter = 5, @@ -52,9 +54,9 @@ static registry_instance_t test_nested_instance = { .commit_cb = NULL, }; -static int load(const registry_storage_instance_t *storage, +static registry_error_t load(const registry_storage_instance_t *storage, const load_cb_t load_cb); -static int save(const registry_storage_instance_t *storage, +static registry_error_t save(const registry_storage_instance_t *storage, const registry_node_t *node, const registry_value_t *value); @@ -70,7 +72,7 @@ static registry_storage_instance_t storage_test_instance = { .data = &storage_test_instance_data, }; -static int load(const registry_storage_instance_t *storage, +static registry_error_t load(const registry_storage_instance_t *storage, const load_cb_t load_cb) { if (storage == &storage_test_instance) { @@ -85,13 +87,14 @@ static int load(const registry_storage_instance_t *storage, return load_cb(&node, &buf, sizeof(buf)); } - return -EINVAL; + return -REGISTRY_ERROR_INVALID_ARGUMENT; } -static int save(const registry_storage_instance_t *storage, +static registry_error_t save(const registry_storage_instance_t *storage, const registry_node_t *node, const registry_value_t *value) { + if (storage == &storage_test_instance && node->value.parameter.instance == &test_nested_instance && node->value.parameter.parameter == ®istry_tests_nested_group_parameter && @@ -99,10 +102,10 @@ static int save(const registry_storage_instance_t *storage, value->buf_len == sizeof(uint8_t) && value->type == REGISTRY_TYPE_UINT8) { - return 0; + successful = true; } - return -EINVAL; + return REGISTRY_ERROR_NONE; } REGISTRY_ADD_STORAGE_SOURCE(storage_test_instance); @@ -115,6 +118,9 @@ static void test_setup(void) /* add schema instances */ registry_add_schema_instance(®istry_tests_nested, &test_nested_instance); + + /* reset testing variable */ + successful = false; } static void tests_registry_load(void) @@ -146,7 +152,10 @@ static void tests_registry_save_parameter(void) .parameter = ®istry_tests_nested_group_parameter, }, }; - TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); + + registry_save(&node); + + TEST_ASSERT(successful); } static void tests_registry_save_group(void) @@ -158,7 +167,10 @@ static void tests_registry_save_group(void) .group = ®istry_tests_nested_group, }, }; - TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); + + registry_save(&node); + + TEST_ASSERT(successful); } static void tests_registry_save_instance(void) @@ -167,7 +179,10 @@ static void tests_registry_save_instance(void) .type = REGISTRY_NODE_INSTANCE, .value.instance = &test_nested_instance, }; - TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); + + registry_save(&node); + + TEST_ASSERT(successful); } static void tests_registry_save_schema(void) @@ -176,7 +191,10 @@ static void tests_registry_save_schema(void) .type = REGISTRY_NODE_SCHEMA, .value.schema = ®istry_tests_nested, }; - TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); + + registry_save(&node); + + TEST_ASSERT(successful); } static void tests_registry_save_namespace(void) @@ -185,12 +203,18 @@ static void tests_registry_save_namespace(void) .type = REGISTRY_NODE_NAMESPACE, .value.namespace = ®istry_tests, }; - TEST_ASSERT_EQUAL_INT(0, registry_save(&node)); + + registry_save(&node); + + TEST_ASSERT(successful); } static void tests_registry_save_all(void) { - TEST_ASSERT_EQUAL_INT(0, registry_save(NULL)); + + registry_save(NULL); + + TEST_ASSERT(successful); } Test *tests_registry_storage_tests(void) From b57f2974f59c942bb95874013ad5a23a1fa95fe2 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:17:07 +0200 Subject: [PATCH 090/117] fixup! examples: add registry example Fix example --- examples/registry_cli/main.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/registry_cli/main.c b/examples/registry_cli/main.c index 6e8417a75c1d..0a76f2af4706 100644 --- a/examples/registry_cli/main.c +++ b/examples/registry_cli/main.c @@ -35,7 +35,7 @@ #include "registry/string_path.h" /* this callback is usually implemented drivers such as an RGB LED driver */ -static int shared_commit_cb(const registry_commit_cb_scope_t scope, +static registry_error_t shared_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { @@ -71,11 +71,11 @@ static int shared_commit_cb(const registry_commit_cb_scope_t scope, } } - return 0; + return REGISTRY_ERROR_NONE; } /* create instances of a configuration schema, to expose configuration parameters to the registry */ -static int rgb_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, +static registry_error_t rgb_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context); static registry_sys_rgb_led_instance_t rgb_led_instance_0_data = { @@ -88,7 +88,7 @@ static registry_instance_t rgb_led_instance_0 = { .data = &rgb_led_instance_0_data, .commit_cb = &rgb_led_instance_0_commit_cb, }; -static int rgb_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, +static registry_error_t rgb_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { @@ -97,7 +97,7 @@ static int rgb_led_instance_0_commit_cb(const registry_commit_cb_scope_t scope, } /* create an instance for a second RGB LED */ -static int rgb_led_instance_1_commit_cb(const registry_commit_cb_scope_t scope, +static registry_error_t rgb_led_instance_1_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context); static registry_sys_rgb_led_instance_t rgb_led_instance_1_data = { @@ -110,7 +110,7 @@ static registry_instance_t rgb_led_instance_1 = { .data = &rgb_led_instance_1_data, .commit_cb = &rgb_led_instance_1_commit_cb, }; -static int rgb_led_instance_1_commit_cb(const registry_commit_cb_scope_t scope, +static registry_error_t rgb_led_instance_1_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { @@ -136,12 +136,6 @@ static registry_storage_instance_t vfs_instance = { .data = &_vfs_mount, }; -/* the storage source is where the registry reads parameter values from */ -REGISTRY_ADD_STORAGE_SOURCE(vfs_instance); - -/* the storage destination is where the registry writes parameter values to */ -REGISTRY_SET_STORAGE_DESTINATION(vfs_instance); - int main(void) { /* initialize the riot registry storage for persistent configuration parameters */ @@ -152,6 +146,10 @@ int main(void) /* initialize the riot registry */ registry_init(); + /* set storage instances so that the CLI can find them */ + const registry_storage_instance_t* storage_instances[] = {&vfs_instance}; + registry_storage_set_instances(storage_instances); + /* add configuration schemas to the registry */ registry_add_schema_instance(®istry_sys_rgb_led, &rgb_led_instance_0); registry_add_schema_instance(®istry_sys_rgb_led, &rgb_led_instance_1); From f74ed613bc39934d5678cb285e0df2ed2921c2b7 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:17:38 +0200 Subject: [PATCH 091/117] fixup! examples: add registry_core example Fix example --- examples/registry_core/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/registry_core/main.c b/examples/registry_core/main.c index 656d36c17ef6..3840e7dedc19 100644 --- a/examples/registry_core/main.c +++ b/examples/registry_core/main.c @@ -31,7 +31,7 @@ #include "registry/namespace/sys/board_led.h" #include "ztimer.h" -int board_led_instance_commit_cb(const registry_commit_cb_scope_t scope, +registry_error_t board_led_instance_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context); @@ -46,7 +46,7 @@ registry_instance_t board_led_instance = { }; /* this callback is usually implemented drivers such as an RGB LED driver */ -int board_led_instance_commit_cb(const registry_commit_cb_scope_t scope, +registry_error_t board_led_instance_commit_cb(const registry_commit_cb_scope_t scope, const registry_group_or_parameter_id_t *group_or_parameter_id, const void *context) { From 77937f85bb9cca0506cdb67b74021116436aa8a6 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:18:29 +0200 Subject: [PATCH 092/117] fixup! sys: add runtime configuration registry Fix typos --- sys/include/registry.h | 6 +++--- sys/include/registry/error.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sys/include/registry.h b/sys/include/registry.h index b55ce0d07cb1..d781048ff0fb 100644 --- a/sys/include/registry.h +++ b/sys/include/registry.h @@ -361,9 +361,9 @@ registry_error_t registry_commit(const registry_node_t *node); */ typedef registry_error_t (*registry_export_cb_t)(const registry_node_t *node, const void *context); -#define REGISTRY_EXPORT_ALL 0; -#define REGISTRY_EXPORT_SELF 1; -#define REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(_n) (_n + 1); +#define REGISTRY_EXPORT_ALL 0 +#define REGISTRY_EXPORT_SELF 1 +#define REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(_n) (_n + 1) /** * @brief Exports every configuration parameter within the given configuration location (@p node) of the registry configuration tree. diff --git a/sys/include/registry/error.h b/sys/include/registry/error.h index 3427fab9584d..d67e94eac1cc 100644 --- a/sys/include/registry/error.h +++ b/sys/include/registry/error.h @@ -30,7 +30,6 @@ extern "C" { typedef enum { REGISTRY_ERROR_NONE = 0, REGISTRY_ERROR_INVALID_ARGUMENT, - REGISTRY_ERROR_NO_DST_STORAGE, REGISTRY_ERROR_NAMESPACE_NOT_FOUND, REGISTRY_ERROR_SCHEMA_NOT_FOUND, REGISTRY_ERROR_INSTANCE_NOT_FOUND, From c7d840e735052a17c2a1c6e3fe65b2305f875ec2 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:19:11 +0200 Subject: [PATCH 093/117] fixup! sys/registry: add persistent storage module Add storage instance as a parameter --- sys/include/registry/storage.h | 46 +++++++++++------------- sys/registry/storage/storage.c | 64 +++++++++++++++------------------- 2 files changed, 50 insertions(+), 60 deletions(-) diff --git a/sys/include/registry/storage.h b/sys/include/registry/storage.h index c1e58570a87d..60213edfc15b 100644 --- a/sys/include/registry/storage.h +++ b/sys/include/registry/storage.h @@ -54,7 +54,7 @@ struct _registry_storage_t { /** * @brief Loads all saved parameters and calls the @p load_cb callback function. * - * @param[in] storage Storage instance. + * @param[in] storage_instance Storage instance to load the configurations from. * @param[in] load_cb Callback function to call for every saved parameter. * * @return 0 on success, non-zero on failure. @@ -67,7 +67,7 @@ struct _registry_storage_t { * need before starting a saving process. * NULL if not implemented * - * @param[in] storage Storage descriptor. + * @param[in] storage_instance Storage instance to save the configurations to. * * @return 0 on success, non-zero on failure. */ @@ -76,7 +76,7 @@ struct _registry_storage_t { /** * @brief Saves a parameter into storage. * - * @param[in] storage Storage descriptor. + * @param[in] storage_instance Storage instance to save the configurations to. * @param[in] node A location within the registry configuration tree. * @param[in] value Configuration parameter value. * @@ -91,7 +91,7 @@ struct _registry_storage_t { * after a saving process. * NULL if not implemented * - * @param[in] storage Storage descriptor. + * @param[in] storage_instance Storage instance to save the configurations to. * * @return 0 on success, non-zero on failure. */ @@ -101,48 +101,44 @@ struct _registry_storage_t { /** * @brief Load all configuration parameters from the storages that are registered * using @p REGISTRY_ADD_STORAGE_SOURCE. + * + * @param[in] storage_instance Storage instance to load the configurations from. * * @return 0 on success, non-zero on failure. */ -registry_error_t registry_load(void); +registry_error_t registry_storage_load(const registry_storage_instance_t *storage_instance); /** * @brief Save all configuration parameters that are within * the scope of the to the @p node. to the storage device, that was registered * using @p REGISTRY_SET_STORAGE_DESTINATION. * + * @param[in] storage_instance Storage instance to save the configurations to. * @param[in] node A location within the registry configuration tree. * * @return 0 on success, non-zero on failure. */ -registry_error_t registry_save(const registry_node_t *node); +registry_error_t registry_storage_save(const registry_storage_instance_t *storage_instance, const registry_node_t *node); /** - * @brief Registers a new storage as a source of configurations. Multiple - * storages can be configured as sources at the same time. Configurations - * will be loaded from all of them. If more than one storage contain values - * for the same key, then only the value of the storage is used, that was - * registered last. + * @brief Set storage instances to expose them to configuration managers such as + * the RIOT CLI. + * + * @param[in] storage_instances An array of pointers to storage instances. * - * @param[in] src Pointer to the storage to register as source. + * @return 0 on success, non-zero on failure. */ -#define REGISTRY_ADD_STORAGE_SOURCE(_storage_instance) \ - XFA_USE_CONST(registry_storage_instance_t *, _registry_storage_instances_src_xfa); \ - XFA_ADD_PTR(_registry_storage_instances_src_xfa, _storage_instance, _storage_instance, \ - &_storage_instance) - -extern const registry_storage_instance_t *_registry_storage_instance_dst; +registry_error_t registry_storage_set_instances(const registry_storage_instance_t **storage_instances); /** - * @brief Registers a new storage as a destination for saving configurations - * Only one storage can be registered as destination at a time. If a - * previous storage had been registered before it will be replaced by the - * new one. + * @brief Get exposed storage instances to use them in a configuration manager + * such as the RIOT CLI. + * + * @param[out] storage_instances An array of pointers to storage instances. * - * @param[in] dst Pointer to the storage to register. + * @return 0 on success, non-zero on failure. */ -#define REGISTRY_SET_STORAGE_DESTINATION(_storage_instance) \ - const registry_storage_instance_t *_registry_storage_instance_dst = &_storage_instance \ +registry_error_t registry_storage_get_instances(const registry_storage_instance_t ***storage_instances); /* heap */ #if IS_USED(MODULE_REGISTRY_STORAGE_HEAP) || IS_ACTIVE(DOXYGEN) diff --git a/sys/registry/storage/storage.c b/sys/registry/storage/storage.c index 0bbb1341c5bd..6529eed634ff 100644 --- a/sys/registry/storage/storage.c +++ b/sys/registry/storage/storage.c @@ -31,10 +31,9 @@ #include "clist.h" #include "registry/storage.h" -#include "registry/util.h" #include "registry/error.h" -XFA_INIT_CONST(registry_storage_instance_t *, _registry_storage_instances_src_xfa); +static const registry_storage_instance_t **_storage_instances; /* registry_load */ static registry_error_t _registry_load_cb(const registry_node_t *node, const void *buf, const size_t buf_len) @@ -46,63 +45,58 @@ static registry_error_t _registry_load_cb(const registry_node_t *node, const voi return registry_set(node, buf, buf_len); } -registry_error_t registry_load(void) +registry_error_t registry_storage_load(const registry_storage_instance_t *storage_instance) { - for (size_t i = 0; - i < XFA_LEN(registry_storage_instance_t *, _registry_storage_instances_src_xfa); i++) { - registry_storage_instance_t *src = _registry_storage_instances_src_xfa[i]; - - registry_error_t res = src->storage->load(src, _registry_load_cb); - - if (res != 0) { - return res; - } - } - - return REGISTRY_ERROR_NONE; + return storage_instance->storage->load(storage_instance, _registry_load_cb); } /* registry_save */ static registry_error_t _registry_save_export_cb(const registry_node_t *node, const void *context) { - (void)context; + const registry_storage_instance_t *storage_instance = context; /* the registry also exports just the namespace or just a schema, but the storage is only interested in configuration parameter values */ if (node->type != REGISTRY_NODE_PARAMETER) { return REGISTRY_ERROR_NONE; } - /* check if a destination storage is registered */ - if (!_registry_storage_instance_dst) { - return -REGISTRY_ERROR_NO_DST_STORAGE; - } - /* get value of configuration parameter */ registry_value_t value; registry_get(node, &value); - /* save parameter value via the save function of the registered destination storage */ - return _registry_storage_instance_dst->storage->save(_registry_storage_instance_dst, - node, &value); + /* save parameter value via the save function of the provided storage instance */ + return storage_instance->storage->save(storage_instance, node, &value); } -registry_error_t registry_save(const registry_node_t *node) +registry_error_t registry_storage_save(const registry_storage_instance_t *storage_instance, const registry_node_t *node) { - registry_error_t res; + assert(storage_instance != NULL); - if (!_registry_storage_instance_dst) { - return -REGISTRY_ERROR_NO_DST_STORAGE; + if (storage_instance->storage->save_start) { + storage_instance->storage->save_start(storage_instance); } - if (_registry_storage_instance_dst->storage->save_start) { - _registry_storage_instance_dst->storage->save_start(_registry_storage_instance_dst); - } - - res = registry_export(node, _registry_save_export_cb, 0, NULL); + registry_error_t res = registry_export(node, _registry_save_export_cb, REGISTRY_EXPORT_ALL, storage_instance); - if (_registry_storage_instance_dst->storage->save_end) { - _registry_storage_instance_dst->storage->save_end(_registry_storage_instance_dst); + if (storage_instance->storage->save_end) { + storage_instance->storage->save_end(storage_instance); } return res; } + +registry_error_t registry_storage_set_instances(const registry_storage_instance_t **storage_instances) { + assert(storage_instances != NULL); + + _storage_instances = storage_instances; + + return REGISTRY_ERROR_NONE; +} + +registry_error_t registry_storage_get_instances(const registry_storage_instance_t ***storage_instances) { + assert(storage_instances != NULL); + + storage_instances = &_storage_instances; + + return REGISTRY_ERROR_NONE; +} From 082d89d8c4f2b228771af1c9df1427318049c9f0 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:25:06 +0200 Subject: [PATCH 094/117] fixup! sys/registry/storage: add heap based storage Fix heap storage --- sys/registry/storage/storage_heap.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sys/registry/storage/storage_heap.c b/sys/registry/storage/storage_heap.c index 5f39ddd62d04..b5ede64a3263 100644 --- a/sys/registry/storage/storage_heap.c +++ b/sys/registry/storage/storage_heap.c @@ -35,11 +35,11 @@ #define REGISTRY_STORAGE_HEAP_CAPACITY 100 #endif -static int load(const registry_storage_instance_t *storage, - const load_cb_t load_cb); -static int save(const registry_storage_instance_t *storage, - const registry_node_t *node, - const registry_value_t *value); +static registry_error_t load(const registry_storage_instance_t *storage, + const load_cb_t load_cb); +static registry_error_t save(const registry_storage_instance_t *storage, + const registry_node_t *node, + const registry_value_t *value); typedef struct { registry_node_t node; @@ -57,7 +57,7 @@ registry_storage_t registry_storage_heap = { .save = save, }; -static int load(const registry_storage_instance_t *storage, +static registry_error_t load(const registry_storage_instance_t *storage, const load_cb_t load_cb) { (void)storage; @@ -65,10 +65,11 @@ static int load(const registry_storage_instance_t *storage, for (size_t i = 0; i < heap_storage_len; i++) { load_cb(&heap_storage[i].node, heap_storage[i].buf, heap_storage[i].buf_len); } - return 0; + + return REGISTRY_ERROR_NONE; } -static int save(const registry_storage_instance_t *storage, +static registry_error_t save(const registry_storage_instance_t *storage, const registry_node_t *node, const registry_value_t *value) { @@ -83,7 +84,7 @@ static int save(const registry_storage_instance_t *storage, if (heap_storage[i].node.value.parameter.instance == node->value.parameter.instance && heap_storage[i].node.value.parameter.parameter == node->value.parameter.parameter) { memcpy(heap_storage[i].buf, value->buf, value->buf_len); - return 0; + return REGISTRY_ERROR_NONE; } } @@ -96,5 +97,5 @@ static int save(const registry_storage_instance_t *storage, memcpy(heap_storage[heap_storage_len].buf, value->buf, value->buf_len); heap_storage_len++; - return 0; + return REGISTRY_ERROR_NONE; } From 82b088a35282a41c33b24e02c27e88915634d863 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:25:26 +0200 Subject: [PATCH 095/117] fixup! sys/registry/storage: add vfs based storage Fix vfs storage --- sys/registry/storage/storage_vfs.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sys/registry/storage/storage_vfs.c b/sys/registry/storage/storage_vfs.c index e65d52c48d8e..99b9f4419d74 100644 --- a/sys/registry/storage/storage_vfs.c +++ b/sys/registry/storage/storage_vfs.c @@ -35,9 +35,9 @@ #include "registry/storage.h" -static int load(const registry_storage_instance_t *storage, +static registry_error_t load(const registry_storage_instance_t *storage, const load_cb_t load_cb); -static int save(const registry_storage_instance_t *storage, +static registry_error_t save(const registry_storage_instance_t *storage, const registry_node_t *node, const registry_value_t *value); @@ -104,7 +104,7 @@ static int _umount(vfs_mount_t *mount) return 0; } -static int load(const registry_storage_instance_t *storage, +static registry_error_t load(const registry_storage_instance_t *storage, const load_cb_t load_cb) { vfs_mount_t *mount = storage->data; @@ -271,12 +271,12 @@ static int load(const registry_storage_instance_t *storage, /* umount */ _umount(mount); - return 0; + return REGISTRY_ERROR_NONE; } -static int save(const registry_storage_instance_t *storage, - const registry_node_t *node, - const registry_value_t *value) +static registry_error_t save(const registry_storage_instance_t *storage, + const registry_node_t *node, + const registry_value_t *value) { assert(node->type == REGISTRY_NODE_PARAMETER); assert(node->value.parameter.parameter != NULL); @@ -289,7 +289,7 @@ static int save(const registry_storage_instance_t *storage, /* create dir path */ registry_int_path_t path; - int res = registry_node_to_int_path(node, &path); + registry_error_t res = registry_node_to_int_path(node, &path); char string_path[REGISTRY_INT_PATH_STRING_MAX_LEN]; @@ -337,5 +337,5 @@ static int save(const registry_storage_instance_t *storage, /* umount */ _umount(mount); - return 0; + return REGISTRY_ERROR_NONE; } From b73f7127902b22c24ab0298dd61fd1a270d4e72d Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:25:49 +0200 Subject: [PATCH 096/117] fixup! sys/registry: add persistent storage module Fix storage --- sys/registry/storage/storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/registry/storage/storage.c b/sys/registry/storage/storage.c index 6529eed634ff..54ed8f6ea73d 100644 --- a/sys/registry/storage/storage.c +++ b/sys/registry/storage/storage.c @@ -96,7 +96,7 @@ registry_error_t registry_storage_set_instances(const registry_storage_instance_ registry_error_t registry_storage_get_instances(const registry_storage_instance_t ***storage_instances) { assert(storage_instances != NULL); - storage_instances = &_storage_instances; + *storage_instances = _storage_instances; return REGISTRY_ERROR_NONE; } From 64bfdd9e9b4cd3c50910a0b0bccec38d18c9d6c0 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:26:25 +0200 Subject: [PATCH 097/117] fixup! sys/shell: add registry cli Fix regsitry_cli --- sys/shell/cmds/registry.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sys/shell/cmds/registry.c b/sys/shell/cmds/registry.c index 1083981ecfd5..3ad0812f9acc 100644 --- a/sys/shell/cmds/registry.c +++ b/sys/shell/cmds/registry.c @@ -104,7 +104,7 @@ static int _parse_string_path(const char *string_path, return 0; } -static int _export_cb(const registry_node_t *node, const void *context) +static registry_error_t _export_cb(const registry_node_t *node, const void *context) { (void)context; @@ -300,17 +300,24 @@ static int _registry(int argc, char **argv) } #if IS_USED(MODULE_REGISTRY_STORAGE) || IS_ACTIVE(DOXYGEN) else if (strcmp(argv[1], "load") == 0) { + // TODO implement storage selector + const registry_storage_instance_t **storage_instances; + registry_storage_get_instances(&storage_instances); + if (argc > 2) { printf("usage: %s %s\n", argv[0], argv[1]); return 1; } - registry_load(); + registry_storage_load(storage_instances[0]); return 0; } else if (strcmp(argv[1], "save") == 0) { int res = 0; + // TODO implement storage selector + const registry_storage_instance_t **storage_instances; + registry_storage_get_instances(&storage_instances); if (argc > 2) { if (_parse_string_path(argv[2], &path) < 0) { @@ -320,12 +327,12 @@ static int _registry(int argc, char **argv) res = registry_node_from_int_path(&path, &node); if (res == 0) { - res = registry_save(&node); + res = registry_storage_save(storage_instances[0], &node); } } else { // save everything - res = registry_save(NULL); + res = registry_storage_save(storage_instances[0], NULL); } if (res != 0) { From 714e7a3b763f471596c84e656c8abdd2e28e739f Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:27:02 +0200 Subject: [PATCH 098/117] fixup! tests/unittests: add registry_storage tests Fix tests --- .../tests-registry_storage.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/unittests/tests-registry_storage/tests-registry_storage.c b/tests/unittests/tests-registry_storage/tests-registry_storage.c index 522230baf90d..73ed1591a4d9 100644 --- a/tests/unittests/tests-registry_storage/tests-registry_storage.c +++ b/tests/unittests/tests-registry_storage/tests-registry_storage.c @@ -108,9 +108,6 @@ static registry_error_t save(const registry_storage_instance_t *storage, return REGISTRY_ERROR_NONE; } -REGISTRY_ADD_STORAGE_SOURCE(storage_test_instance); -REGISTRY_SET_STORAGE_DESTINATION(storage_test_instance); - static void test_setup(void) { /* init registry */ @@ -126,7 +123,7 @@ static void test_setup(void) static void tests_registry_load(void) { /* check if the registry_load function gets the correct input values internally */ - TEST_ASSERT(registry_load() == 0); + TEST_ASSERT_EQUAL_INT(registry_storage_load(&storage_test_instance), REGISTRY_ERROR_NONE); /* check if the load_cb sets the value to the registry */ registry_value_t output; @@ -153,7 +150,7 @@ static void tests_registry_save_parameter(void) }, }; - registry_save(&node); + registry_storage_save(&storage_test_instance, &node); TEST_ASSERT(successful); } @@ -168,7 +165,7 @@ static void tests_registry_save_group(void) }, }; - registry_save(&node); + registry_storage_save(&storage_test_instance, &node); TEST_ASSERT(successful); } @@ -180,7 +177,7 @@ static void tests_registry_save_instance(void) .value.instance = &test_nested_instance, }; - registry_save(&node); + registry_storage_save(&storage_test_instance, &node); TEST_ASSERT(successful); } @@ -192,7 +189,7 @@ static void tests_registry_save_schema(void) .value.schema = ®istry_tests_nested, }; - registry_save(&node); + registry_storage_save(&storage_test_instance, &node); TEST_ASSERT(successful); } @@ -204,7 +201,7 @@ static void tests_registry_save_namespace(void) .value.namespace = ®istry_tests, }; - registry_save(&node); + registry_storage_save(&storage_test_instance, &node); TEST_ASSERT(successful); } @@ -212,7 +209,7 @@ static void tests_registry_save_namespace(void) static void tests_registry_save_all(void) { - registry_save(NULL); + registry_storage_save(&storage_test_instance, NULL); TEST_ASSERT(successful); } From 68a0716e4ee160c31799f14fd2134553e62fcd0e Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:27:21 +0200 Subject: [PATCH 099/117] fixup! tests/unittests: add registry_storage_heap tests Fix tests --- .../tests-registry_storage_heap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c index 5948cfc7d0d6..2251a06e4157 100644 --- a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c +++ b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c @@ -52,9 +52,6 @@ static registry_storage_instance_t heap_instance = { .data = NULL, }; -REGISTRY_ADD_STORAGE_SOURCE(heap_instance); -REGISTRY_SET_STORAGE_DESTINATION(heap_instance); - static void test_setup(void) { /* init registry */ @@ -80,7 +77,7 @@ static void tests_load_and_save(void) registry_set(&node, &saved_input, sizeof(saved_input)); /* save input to storage */ - registry_save(NULL); + registry_storage_save(&heap_instance, NULL); /* override input with the value 20 */ const uint8_t override_input = 20; @@ -88,7 +85,7 @@ static void tests_load_and_save(void) registry_set(&node, &override_input, sizeof(override_input)); /* load old value from storage */ - registry_load(); + registry_storage_load(&heap_instance); /* check if the value is set back to 8 and not 20 anymore */ registry_value_t output_value; From 3bd0c7b277b60877b221db72d9019c5d95a772a6 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Mon, 6 May 2024 21:27:38 +0200 Subject: [PATCH 100/117] fixup! tests/unittests: add registry_storage_vfs tests Fix tests --- .../tests-registry_storage_vfs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c index ed8e947fdec0..cb8e4acc97c0 100644 --- a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c +++ b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c @@ -68,9 +68,6 @@ static registry_storage_instance_t vfs_instance = { .data = &_vfs_mount, }; -REGISTRY_ADD_STORAGE_SOURCE(vfs_instance); -REGISTRY_SET_STORAGE_DESTINATION(vfs_instance); - static void test_setup(void) { /* init registry */ @@ -101,7 +98,7 @@ static void tests_load_and_save(void) registry_set(&node, &saved_input, sizeof(saved_input)); /* save input to storage */ - registry_save(NULL); + registry_storage_save(&vfs_instance, NULL); /* override input with the value 20 */ const uint8_t override_input = 20; @@ -109,7 +106,7 @@ static void tests_load_and_save(void) registry_set(&node, &override_input, sizeof(override_input)); /* load old value from storage */ - registry_load(); + registry_storage_load(&vfs_instance); /* check if the value is set back to 8 and not 20 anymore */ registry_value_t output_value; From 1438aa761ddc00edd7502def614c351f799f8c97 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 13:11:32 +0200 Subject: [PATCH 101/117] fixup! sys/registry: add string_path module Format --- sys/include/registry/string_path.h | 5 +- sys/registry/string_path.c | 77 ++++++++++++++++++------------ 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/sys/include/registry/string_path.h b/sys/include/registry/string_path.h index 59a15e79d1e9..40635ffa9fa5 100644 --- a/sys/include/registry/string_path.h +++ b/sys/include/registry/string_path.h @@ -11,7 +11,7 @@ * @ingroup sys * @brief RIOT Registry String Path module * @{ - * + * * This module provides functions to convert between @ref registry_node_t and * a string path representation of it. * @@ -50,7 +50,8 @@ int registry_node_to_string_path(const registry_node_t *node, char *path); * * @return 0 on success, non-zero on failure. */ -registry_error_t registry_node_from_string_path(const char **path, const size_t path_len, registry_node_t *node); +registry_error_t registry_node_from_string_path(const char **path, const size_t path_len, + registry_node_t *node); #ifdef __cplusplus } diff --git a/sys/registry/string_path.c b/sys/registry/string_path.c index 76057329f97f..3500d464a22f 100644 --- a/sys/registry/string_path.c +++ b/sys/registry/string_path.c @@ -11,7 +11,7 @@ * @ingroup sys * @brief RIOT Registry String Path module * @{ - * + * * This module provides functions to convert between @ref registry_node_t and * a string path representation of it. * @@ -112,8 +112,7 @@ int registry_node_to_string_path(const registry_node_t *node, char *path) int size = 0; - switch (node->type) - { + switch (node->type) { case REGISTRY_NODE_NAMESPACE: size = snprintf(NULL, 0, "/%s", node->value.namespace->name); @@ -121,37 +120,43 @@ int registry_node_to_string_path(const registry_node_t *node, char *path) return snprintf(path, size + 1, "/%s", node->value.namespace->name); } break; - + case REGISTRY_NODE_SCHEMA: - size = snprintf(NULL, 0, "/%s/%s", node->value.schema->namespace->name, node->value.schema->name); + size = snprintf(NULL, 0, "/%s/%s", node->value.schema->namespace->name, + node->value.schema->name); if (path != NULL) { - return snprintf(path, size + 1, "/%s/%s", node->value.schema->namespace->name, node->value.schema->name); + return snprintf(path, size + 1, "/%s/%s", node->value.schema->namespace->name, + node->value.schema->name); } break; - + case REGISTRY_NODE_INSTANCE: size = snprintf(NULL, 0, "/%s/%s/%s", node->value.instance->schema->namespace->name, node->value.instance->schema->name, node->value.instance->name); if (path != NULL) { - return snprintf(path, size + 1, "/%s/%s/%s", node->value.instance->schema->namespace->name, + return snprintf(path, size + 1, "/%s/%s/%s", + node->value.instance->schema->namespace->name, node->value.instance->schema->name, node->value.instance->name); } break; - + case REGISTRY_NODE_GROUP: size = snprintf(NULL, 0, "/%s/%s/%s", node->value.group.instance->schema->namespace->name, node->value.group.instance->schema->name, node->value.group.instance->name); if (path != NULL) { - snprintf(path, size + 1, "/%s/%s/%s", node->value.group.instance->schema->namespace->name, - node->value.group.instance->schema->name, node->value.group.instance->name); + snprintf(path, size + 1, "/%s/%s/%s", + node->value.group.instance->schema->namespace->name, + node->value.group.instance->schema->name, node->value.group.instance->name); } for (size_t i = 0; i < node->value.group.instance->schema->groups_len; i++) { - int res = _internal_registry_to_group_string_path(node->value.group.instance->schema->groups[i], node->value.group.group, - path != NULL ? path + size : NULL); + int res = + _internal_registry_to_group_string_path( + node->value.group.instance->schema->groups[i], node->value.group.group, + path != NULL ? path + size : NULL); if (res >= 0) { return size += res; } @@ -159,23 +164,30 @@ int registry_node_to_string_path(const registry_node_t *node, char *path) return -EINVAL; break; - + case REGISTRY_NODE_PARAMETER: - size = snprintf(NULL, 0, "/%s/%s/%s", node->value.parameter.instance->schema->namespace->name, - node->value.parameter.instance->schema->name, node->value.parameter.instance->name); + size = snprintf(NULL, 0, "/%s/%s/%s", + node->value.parameter.instance->schema->namespace->name, + node->value.parameter.instance->schema->name, + node->value.parameter.instance->name); if (path != NULL) { - snprintf(path, size + 1, "/%s/%s/%s", node->value.parameter.instance->schema->namespace->name, - node->value.parameter.instance->schema->name, node->value.parameter.instance->name); + snprintf(path, size + 1, "/%s/%s/%s", + node->value.parameter.instance->schema->namespace->name, + node->value.parameter.instance->schema->name, + node->value.parameter.instance->name); } /* check if the parameter is a child of this schema */ for (size_t i = 0; i < node->value.parameter.instance->schema->parameters_len; i++) { - if (node->value.parameter.instance->schema->parameters[i] == node->value.parameter.parameter) { - int sub_size = snprintf(NULL, 0, "/%s", node->value.parameter.instance->schema->parameters[i]->name); + if (node->value.parameter.instance->schema->parameters[i] == + node->value.parameter.parameter) { + int sub_size = snprintf(NULL, 0, "/%s", + node->value.parameter.instance->schema->parameters[i]->name); if (path != NULL) { - snprintf(path + size, sub_size + 1, "/%s", node->value.parameter.instance->schema->parameters[i]->name); + snprintf(path + size, sub_size + 1, "/%s", + node->value.parameter.instance->schema->parameters[i]->name); } return size + sub_size; @@ -184,9 +196,12 @@ int registry_node_to_string_path(const registry_node_t *node, char *path) /* check if the parameter is the child of a group */ for (size_t i = 0; i < node->value.parameter.instance->schema->groups_len; i++) { - int res = _internal_registry_to_parameter_string_path(node->value.parameter.instance->schema->groups[i], - node->value.parameter.parameter, - path != NULL ? path + size : NULL); + int res = + _internal_registry_to_parameter_string_path( + node->value.parameter.instance->schema->groups[i], + node->value.parameter.parameter, + path != + NULL ? path + size : NULL); if (res >= 0) { return size += res; } @@ -199,13 +214,14 @@ int registry_node_to_string_path(const registry_node_t *node, char *path) return size; } -static registry_find_result_type _compare_node_by_string(const registry_node_t *node, const void *context) { - _registry_string_comparator_context_t *data = (void*)context; +static registry_find_result_type _compare_node_by_string(const registry_node_t *node, + const void *context) +{ + _registry_string_comparator_context_t *data = (void *)context; const char *name = NULL; - switch (node->type) - { + switch (node->type) { case REGISTRY_NODE_NAMESPACE: name = node->value.namespace->name; break; @@ -236,11 +252,12 @@ static registry_find_result_type _compare_node_by_string(const registry_node_t * data->position++; return REGISTRY_FIND_PARTIAL_MATCH; } - + return REGISTRY_FIND_NO_MATCH; } -registry_error_t registry_node_from_string_path(const char **path, const size_t path_len, registry_node_t *node) +registry_error_t registry_node_from_string_path(const char **path, const size_t path_len, + registry_node_t *node) { _registry_string_comparator_context_t context = { .path = path, From b0d8b3b77ee17ff0b33a3025b8f63e64da868db3 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 13:11:54 +0200 Subject: [PATCH 102/117] fixup! sys/registry: add int_path module Format --- sys/include/registry/int_path.h | 7 +++--- sys/registry/int_path.c | 39 ++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/sys/include/registry/int_path.h b/sys/include/registry/int_path.h index dc9eb02c8bd2..28d5061f484c 100644 --- a/sys/include/registry/int_path.h +++ b/sys/include/registry/int_path.h @@ -11,7 +11,7 @@ * @ingroup sys * @brief RIOT Registry integer path module * @{ - * + * * This module provides functions to convert between @ref registry_node_t and * @ref registry_int_path_t. * @@ -39,7 +39,7 @@ extern "C" { /** * @brief Maximum length of a configuration path as a string of numbers. - * + * * An int path consists of the following elements: * namespace_id: 8 bits corresponds to a max of 3 characters * schema_id: 32 bits corresponds to a max of 10 characters @@ -148,7 +148,8 @@ registry_error_t registry_node_to_int_path(const registry_node_t *node, registry * * @return 0 on success, non-zero on failure. */ -registry_error_t registry_node_from_int_path(const registry_int_path_t *path, registry_node_t *node); +registry_error_t registry_node_from_int_path(const registry_int_path_t *path, + registry_node_t *node); #ifdef __cplusplus } diff --git a/sys/registry/int_path.c b/sys/registry/int_path.c index 23ebb85e52d6..4c78f37962ab 100644 --- a/sys/registry/int_path.c +++ b/sys/registry/int_path.c @@ -11,7 +11,7 @@ * @ingroup sys * @brief RIOT Registry integer path module * @{ - * + * * This module provides functions to convert between @ref registry_node_t and * @ref registry_int_path_t. * @@ -42,26 +42,25 @@ registry_error_t registry_node_to_int_path(const registry_node_t *node, registry assert(node != NULL); assert(path != NULL); - switch (node->type) - { + switch (node->type) { case REGISTRY_NODE_NAMESPACE: path->type = REGISTRY_INT_PATH_TYPE_NAMESPACE; path->value.namespace_path.namespace_id = node->value.namespace->id; break; - + case REGISTRY_NODE_SCHEMA: path->type = REGISTRY_INT_PATH_TYPE_SCHEMA; path->value.schema_path.namespace_id = node->value.schema->namespace->id; path->value.schema_path.schema_id = node->value.schema->id; break; - + case REGISTRY_NODE_INSTANCE: path->type = REGISTRY_INT_PATH_TYPE_INSTANCE; path->value.instance_path.namespace_id = node->value.instance->schema->namespace->id; path->value.instance_path.schema_id = node->value.instance->schema->id; path->value.instance_path.instance_id = node->value.instance->id; break; - + case REGISTRY_NODE_GROUP: path->type = REGISTRY_INT_PATH_TYPE_GROUP; path->value.group_path.namespace_id = node->value.group.group->schema->namespace->id; @@ -69,10 +68,11 @@ registry_error_t registry_node_to_int_path(const registry_node_t *node, registry path->value.group_path.instance_id = node->value.group.instance->id; path->value.group_path.group_id = node->value.group.group->id; break; - + case REGISTRY_NODE_PARAMETER: path->type = REGISTRY_INT_PATH_TYPE_PARAMETER; - path->value.parameter_path.namespace_id = node->value.parameter.parameter->schema->namespace->id; + path->value.parameter_path.namespace_id = + node->value.parameter.parameter->schema->namespace->id; path->value.parameter_path.schema_id = node->value.parameter.parameter->schema->id; path->value.parameter_path.instance_id = node->value.parameter.instance->id; path->value.parameter_path.parameter_id = node->value.parameter.parameter->id; @@ -82,37 +82,40 @@ registry_error_t registry_node_to_int_path(const registry_node_t *node, registry return REGISTRY_ERROR_NONE; } -static registry_find_result_type _compare_node_by_id(const registry_node_t *node, const void *context) { +static registry_find_result_type _compare_node_by_id(const registry_node_t *node, + const void *context) +{ const registry_int_path_t *path = context; bool id_matches = false; bool path_type_matches = false; - switch (node->type) - { + switch (node->type) { case REGISTRY_NODE_NAMESPACE: id_matches = node->value.namespace->id == path->value.namespace_path.namespace_id; path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_NAMESPACE; break; - + case REGISTRY_NODE_SCHEMA: id_matches = node->value.schema->id == path->value.schema_path.schema_id; path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_SCHEMA; break; - + case REGISTRY_NODE_INSTANCE: id_matches = node->value.instance->id == path->value.instance_path.instance_id; path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_INSTANCE; break; - + case REGISTRY_NODE_GROUP: id_matches = node->value.group.group->id == path->value.group_path.group_id; - path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_GROUP || path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER; + path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_GROUP || + path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER; break; - + case REGISTRY_NODE_PARAMETER: id_matches = node->value.parameter.parameter->id == path->value.parameter_path.parameter_id; - path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_PARAMETER || path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER; + path_type_matches = path->type == REGISTRY_INT_PATH_TYPE_PARAMETER || + path->type == REGISTRY_INT_PATH_TYPE_GROUP_OR_PARAMETER; break; } @@ -123,7 +126,7 @@ static registry_find_result_type _compare_node_by_id(const registry_node_t *node return REGISTRY_FIND_PARTIAL_MATCH; } - + return REGISTRY_FIND_NO_MATCH; } From fc599ed1bbdfdd0cad377d460c4151ed3af212a3 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 13:12:58 +0200 Subject: [PATCH 103/117] fixup! sys/registry: add int_path module Format --- sys/include/registry.h | 13 ++++---- sys/registry/registry.c | 70 ++++++++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/sys/include/registry.h b/sys/include/registry.h index d781048ff0fb..db09a9ae7861 100644 --- a/sys/include/registry.h +++ b/sys/include/registry.h @@ -141,7 +141,7 @@ typedef enum { */ typedef struct { registry_node_type_t type; /**< The type of the node */ - union { + union { const registry_namespace_t *namespace; /**< Pointer to the configuration namespace */ const registry_schema_t *schema; /**< Pointer to a configuration schema */ const registry_instance_t *instance; /**< Pointer to a schema instance */ @@ -186,8 +186,8 @@ typedef const enum { * @return 0 on success, non-zero on failure. */ typedef registry_error_t (*registry_commit_cb_t)(const registry_commit_cb_scope_t scope, - const registry_group_or_parameter_id_t *group_or_parameter_id, - const void *context); + const registry_group_or_parameter_id_t * + group_or_parameter_id, const void *context); /** * @brief Instance of a schema containing its configuration parameters values. @@ -315,7 +315,7 @@ void registry_init(void); * @return 0 on success, non-zero on failure. */ registry_error_t registry_add_schema_instance(const registry_schema_t *schema, - const registry_instance_t *instance); + const registry_instance_t *instance); /** * @brief Gets the current value of a parameter that belongs to an instance @@ -353,7 +353,7 @@ registry_error_t registry_commit(const registry_node_t *node); * @brief Callback definition of the @p registry_export function. * This callback will be called for each location inside of the configuration tree that is * within the scope of the registry node passed on to the @p registry_export function. - * + * * @param[in] node A location within the registry configuration tree. * @param[in] context Context that is passed by the @p registry_export function. * @@ -378,7 +378,8 @@ typedef registry_error_t (*registry_export_cb_t)(const registry_node_t *node, co * * @return 0 on success, non-zero on failure. */ -registry_error_t registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context); +registry_error_t registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, + const uint8_t tree_traversal_depth, const void *context); #ifdef __cplusplus } diff --git a/sys/registry/registry.c b/sys/registry/registry.c index 40a7c43b8d40..83d35adea909 100644 --- a/sys/registry/registry.c +++ b/sys/registry/registry.c @@ -72,7 +72,8 @@ registry_error_t registry_get(const registry_node_t *node, registry_value_t *val const registry_parameter_t *parameter = node->value.parameter.parameter; - parameter->schema->mapping(parameter->id, node->value.parameter.instance, &intern_val, &intern_val_len); + parameter->schema->mapping(parameter->id, node->value.parameter.instance, &intern_val, + &intern_val_len); /* update buf pointer in registry_value_t to point to the value inside the registry and set buf_len */ value->type = parameter->type; @@ -97,7 +98,8 @@ registry_error_t registry_set(const registry_node_t *node, const void *buf, cons const registry_parameter_t *parameter = node->value.parameter.parameter; - parameter->schema->mapping(parameter->id, node->value.parameter.instance, &intern_val, &intern_val_len); + parameter->schema->mapping(parameter->id, node->value.parameter.instance, &intern_val, + &intern_val_len); if (buf_len > intern_val_len) { return -REGISTRY_ERROR_BUF_LEN_TOO_LARGE; @@ -109,13 +111,13 @@ registry_error_t registry_set(const registry_node_t *node, const void *buf, cons return REGISTRY_ERROR_NONE; } -static registry_error_t _commit_export_cb(const registry_node_t *node, const void *context) { +static registry_error_t _commit_export_cb(const registry_node_t *node, const void *context) +{ (void)context; const registry_instance_t *instance; - switch (node->type) - { + switch (node->type) { /* The commit function is only called for instance and below */ case REGISTRY_NODE_NAMESPACE: case REGISTRY_NODE_SCHEMA: @@ -127,22 +129,24 @@ static registry_error_t _commit_export_cb(const registry_node_t *node, const voi case REGISTRY_NODE_GROUP: instance = node->value.group.instance; - return instance->commit_cb(REGISTRY_COMMIT_GROUP, &node->value.group.group->id, instance->context); + return instance->commit_cb(REGISTRY_COMMIT_GROUP, &node->value.group.group->id, + instance->context); case REGISTRY_NODE_PARAMETER: instance = node->value.parameter.instance; - return instance->commit_cb(REGISTRY_COMMIT_PARAMETER, &node->value.parameter.parameter->id, instance->context); + return instance->commit_cb(REGISTRY_COMMIT_PARAMETER, &node->value.parameter.parameter->id, + instance->context); } return REGISTRY_ERROR_NONE; } -registry_error_t registry_commit(const registry_node_t *node) { +registry_error_t registry_commit(const registry_node_t *node) +{ uint8_t tree_traversal_depth = REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(3); if (node != NULL) { - switch (node->type) - { + switch (node->type) { case REGISTRY_NODE_NAMESPACE: tree_traversal_depth = REGISTRY_EXPORT_WITH_N_LEVELS_OF_CHILDREN(2); break; @@ -163,8 +167,9 @@ registry_error_t registry_commit(const registry_node_t *node) { } static registry_error_t _registry_export_parameter(const registry_instance_t *instance, - const registry_parameter_t *parameter, - const registry_export_cb_t export_cb, const void *context) + const registry_parameter_t *parameter, + const registry_export_cb_t export_cb, + const void *context) { assert(parameter != NULL); @@ -180,9 +185,10 @@ static registry_error_t _registry_export_parameter(const registry_instance_t *in } static registry_error_t _registry_export_group(const registry_instance_t *instance, - const registry_group_t *group, - const registry_export_cb_t export_cb, - const uint8_t tree_traversal_depth, const void *context) + const registry_group_t *group, + const registry_export_cb_t export_cb, + const uint8_t tree_traversal_depth, + const void *context) { assert(group != NULL); @@ -208,7 +214,8 @@ static registry_error_t _registry_export_group(const registry_instance_t *instan /* group */ for (size_t i = 0; i < group->groups_len; i++) { - rc = _registry_export_group(instance, group->groups[i], export_cb, new_tree_traversal_depth, + rc = _registry_export_group(instance, group->groups[i], export_cb, + new_tree_traversal_depth, context); if (!rc == REGISTRY_ERROR_NONE) { @@ -279,7 +286,7 @@ static registry_error_t _registry_export_instance( } static registry_error_t _registry_export_schema( - const registry_schema_t *schema, + const registry_schema_t *schema, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context) { @@ -328,8 +335,9 @@ static registry_error_t _registry_export_schema( } static registry_error_t _registry_export_namespace(const registry_namespace_t *namespace, - const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, - const void *context) + const registry_export_cb_t export_cb, + const uint8_t tree_traversal_depth, + const void *context) { assert(namespace != NULL); @@ -364,7 +372,8 @@ static registry_error_t _registry_export_namespace(const registry_namespace_t *n return rc; } -registry_error_t registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, const uint8_t tree_traversal_depth, const void *context) +registry_error_t registry_export(const registry_node_t *node, const registry_export_cb_t export_cb, + const uint8_t tree_traversal_depth, const void *context) { registry_error_t rc = REGISTRY_ERROR_NONE; @@ -379,23 +388,28 @@ registry_error_t registry_export(const registry_node_t *node, const registry_exp return rc; } } - } else { - switch (node->type) - { + } + else { + switch (node->type) { case REGISTRY_NODE_NAMESPACE: - rc = _registry_export_namespace(node->value.namespace, export_cb, tree_traversal_depth, context); + rc = _registry_export_namespace(node->value.namespace, export_cb, tree_traversal_depth, + context); break; case REGISTRY_NODE_SCHEMA: - rc = _registry_export_schema(node->value.schema, export_cb, tree_traversal_depth, context); + rc = _registry_export_schema(node->value.schema, export_cb, tree_traversal_depth, + context); break; case REGISTRY_NODE_INSTANCE: - rc = _registry_export_instance(node->value.instance, export_cb, tree_traversal_depth, context); + rc = _registry_export_instance(node->value.instance, export_cb, tree_traversal_depth, + context); break; case REGISTRY_NODE_GROUP: - rc = _registry_export_group(node->value.group.instance, node->value.group.group, export_cb, tree_traversal_depth, context); + rc = _registry_export_group(node->value.group.instance, node->value.group.group, + export_cb, tree_traversal_depth, context); break; case REGISTRY_NODE_PARAMETER: - rc = _registry_export_parameter(node->value.parameter.instance, node->value.parameter.parameter, export_cb, context); + rc = _registry_export_parameter(node->value.parameter.instance, + node->value.parameter.parameter, export_cb, context); break; } } From 2de13de20030a43e2f1b587ed0e6a6dcbed762f2 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 13:13:23 +0200 Subject: [PATCH 104/117] fixup! sys/registry: add persistent storage module Format --- sys/include/registry/storage.h | 34 +++++++++++++++++++--------------- sys/registry/storage/storage.c | 17 ++++++++++++----- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/sys/include/registry/storage.h b/sys/include/registry/storage.h index 60213edfc15b..ff1531ab9c46 100644 --- a/sys/include/registry/storage.h +++ b/sys/include/registry/storage.h @@ -28,14 +28,15 @@ extern "C" { /** * @brief Prototype of a callback function for the load action of a storage interface. - * + * * @param[in] node A location within the registry configuration tree. (In this case it must be a configuration parameter) * @param[in] buf The saved value of the configuration parameter. * @param[in] buf_len The size of @p buf. - * + * * @return 0 on success, non-zero on failure. */ -typedef registry_error_t (*load_cb_t)(const registry_node_t *node, const void *buf, const size_t buf_len); +typedef registry_error_t (*load_cb_t)(const registry_node_t *node, const void *buf, + const size_t buf_len); typedef struct _registry_storage_t registry_storage_t; @@ -60,7 +61,7 @@ struct _registry_storage_t { * @return 0 on success, non-zero on failure. */ registry_error_t (*load)(const registry_storage_instance_t *storage, - const load_cb_t load_cb); + const load_cb_t load_cb); /** * @brief If implemented, it is used for any preparation the storage may @@ -83,8 +84,8 @@ struct _registry_storage_t { * @return 0 on success, non-zero on failure. */ registry_error_t (*save)(const registry_storage_instance_t *storage, - const registry_node_t *node, - const registry_value_t *value); + const registry_node_t *node, + const registry_value_t *value); /** * @brief If implemented, it is used for any tear-down the storage may need @@ -101,7 +102,7 @@ struct _registry_storage_t { /** * @brief Load all configuration parameters from the storages that are registered * using @p REGISTRY_ADD_STORAGE_SOURCE. - * + * * @param[in] storage_instance Storage instance to load the configurations from. * * @return 0 on success, non-zero on failure. @@ -109,36 +110,39 @@ struct _registry_storage_t { registry_error_t registry_storage_load(const registry_storage_instance_t *storage_instance); /** - * @brief Save all configuration parameters that are within - * the scope of the to the @p node. to the storage device, that was registered + * @brief Save all configuration parameters that are within + * the scope of the to the @p node. to the storage device, that was registered * using @p REGISTRY_SET_STORAGE_DESTINATION. - * + * * @param[in] storage_instance Storage instance to save the configurations to. * @param[in] node A location within the registry configuration tree. * * @return 0 on success, non-zero on failure. */ -registry_error_t registry_storage_save(const registry_storage_instance_t *storage_instance, const registry_node_t *node); +registry_error_t registry_storage_save(const registry_storage_instance_t *storage_instance, + const registry_node_t *node); /** * @brief Set storage instances to expose them to configuration managers such as * the RIOT CLI. - * + * * @param[in] storage_instances An array of pointers to storage instances. * * @return 0 on success, non-zero on failure. */ -registry_error_t registry_storage_set_instances(const registry_storage_instance_t **storage_instances); +registry_error_t registry_storage_set_instances( + const registry_storage_instance_t **storage_instances); /** * @brief Get exposed storage instances to use them in a configuration manager * such as the RIOT CLI. - * + * * @param[out] storage_instances An array of pointers to storage instances. * * @return 0 on success, non-zero on failure. */ -registry_error_t registry_storage_get_instances(const registry_storage_instance_t ***storage_instances); +registry_error_t registry_storage_get_instances( + const registry_storage_instance_t ***storage_instances); /* heap */ #if IS_USED(MODULE_REGISTRY_STORAGE_HEAP) || IS_ACTIVE(DOXYGEN) diff --git a/sys/registry/storage/storage.c b/sys/registry/storage/storage.c index 54ed8f6ea73d..c4a6ee3f5676 100644 --- a/sys/registry/storage/storage.c +++ b/sys/registry/storage/storage.c @@ -36,7 +36,8 @@ static const registry_storage_instance_t **_storage_instances; /* registry_load */ -static registry_error_t _registry_load_cb(const registry_node_t *node, const void *buf, const size_t buf_len) +static registry_error_t _registry_load_cb(const registry_node_t *node, const void *buf, + const size_t buf_len) { assert(node->type == REGISTRY_NODE_PARAMETER); assert(node->value.parameter.parameter != NULL); @@ -68,7 +69,8 @@ static registry_error_t _registry_save_export_cb(const registry_node_t *node, co return storage_instance->storage->save(storage_instance, node, &value); } -registry_error_t registry_storage_save(const registry_storage_instance_t *storage_instance, const registry_node_t *node) +registry_error_t registry_storage_save(const registry_storage_instance_t *storage_instance, + const registry_node_t *node) { assert(storage_instance != NULL); @@ -76,7 +78,8 @@ registry_error_t registry_storage_save(const registry_storage_instance_t *storag storage_instance->storage->save_start(storage_instance); } - registry_error_t res = registry_export(node, _registry_save_export_cb, REGISTRY_EXPORT_ALL, storage_instance); + registry_error_t res = registry_export(node, _registry_save_export_cb, REGISTRY_EXPORT_ALL, + storage_instance); if (storage_instance->storage->save_end) { storage_instance->storage->save_end(storage_instance); @@ -85,7 +88,9 @@ registry_error_t registry_storage_save(const registry_storage_instance_t *storag return res; } -registry_error_t registry_storage_set_instances(const registry_storage_instance_t **storage_instances) { +registry_error_t registry_storage_set_instances( + const registry_storage_instance_t **storage_instances) +{ assert(storage_instances != NULL); _storage_instances = storage_instances; @@ -93,7 +98,9 @@ registry_error_t registry_storage_set_instances(const registry_storage_instance_ return REGISTRY_ERROR_NONE; } -registry_error_t registry_storage_get_instances(const registry_storage_instance_t ***storage_instances) { +registry_error_t registry_storage_get_instances( + const registry_storage_instance_t ***storage_instances) +{ assert(storage_instances != NULL); *storage_instances = _storage_instances; From b7577c62275b0ff1caac4c101231173cce4b8615 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 13:14:08 +0200 Subject: [PATCH 105/117] fixup! sys/registry: add tree traversal utility Format --- sys/include/registry/find.h | 9 +++++---- sys/registry/find.c | 35 ++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/sys/include/registry/find.h b/sys/include/registry/find.h index 4c5d268a46ae..90e4ba8b0d6d 100644 --- a/sys/include/registry/find.h +++ b/sys/include/registry/find.h @@ -33,8 +33,8 @@ extern "C" { * @brief The different return types of @p registry_find_comparator_t callback function. */ typedef enum { - REGISTRY_FIND_NO_MATCH = -1, - REGISTRY_FIND_EXACT_MATCH = 0, + REGISTRY_FIND_NO_MATCH = -1, + REGISTRY_FIND_EXACT_MATCH = 0, REGISTRY_FIND_PARTIAL_MATCH = 1, } registry_find_result_type; @@ -47,7 +47,8 @@ typedef enum { * * @return 0 on exact match, 1 on partial match and -1 on no match. */ -typedef registry_find_result_type (*registry_find_comparator_t)(const registry_node_t *node, const void *context); +typedef registry_find_result_type (*registry_find_comparator_t)(const registry_node_t *node, + const void *context); /** * @brief Finds a specific node within the registry configuration tree. @@ -60,7 +61,7 @@ typedef registry_find_result_type (*registry_find_comparator_t)(const registry_n * * @return 0 on success, non-zero on failure. */ -registry_error_t registry_find(const registry_find_comparator_t compare, +registry_error_t registry_find(const registry_find_comparator_t compare, const void *context, registry_node_t *node); #ifdef __cplusplus diff --git a/sys/registry/find.c b/sys/registry/find.c index 743e95044ba9..3eed6f2421e9 100644 --- a/sys/registry/find.c +++ b/sys/registry/find.c @@ -37,9 +37,11 @@ XFA_USE_CONST(registry_namespace_t *, _registry_namespaces_xfa); -static registry_find_result_type _find_group(const registry_group_t **groups, const size_t groups_len, - const registry_find_comparator_t compare, - const void *context, const registry_group_t **group) { +static registry_find_result_type _find_group(const registry_group_t **groups, + const size_t groups_len, + const registry_find_comparator_t compare, + const void *context, const registry_group_t **group) +{ assert(groups != NULL); assert(groups_len > 0); assert(compare != NULL); @@ -57,8 +59,8 @@ static registry_find_result_type _find_group(const registry_group_t **groups, co if (res == REGISTRY_FIND_EXACT_MATCH) { *group = groups[i]; return res; - } - + } + /* if a partial match is found, we need to keep searching for its children, but can break the loop */ if (res == REGISTRY_FIND_PARTIAL_MATCH) { return _find_group(groups[i]->groups, groups[i]->groups_len, compare, context, group); @@ -106,8 +108,9 @@ static registry_find_result_type _find_parameter_by_group( } static registry_find_result_type _find_parameter_by_schema( - const registry_schema_t *schema, const registry_find_comparator_t compare, - const void *context, const registry_parameter_t **parameter) { + const registry_schema_t *schema, const registry_find_comparator_t compare, + const void *context, const registry_parameter_t **parameter) +{ assert(schema != NULL); assert(compare != NULL); @@ -141,8 +144,9 @@ static registry_find_result_type _find_parameter_by_schema( return -REGISTRY_ERROR_PARAMETER_NOT_FOUND; } -registry_error_t registry_find(const registry_find_comparator_t compare, - const void *context, registry_node_t *node) { +registry_error_t registry_find(const registry_find_comparator_t compare, + const void *context, registry_node_t *node) +{ assert(compare != NULL); assert(context != NULL); @@ -163,7 +167,7 @@ registry_error_t registry_find(const registry_find_comparator_t compare, node->value.namespace = namespace; return 0; } - + /* if a partial match is found, we need to keep searching for its children, but can break the loop */ if (res == REGISTRY_FIND_PARTIAL_MATCH) { break; @@ -188,8 +192,8 @@ registry_error_t registry_find(const registry_find_comparator_t compare, node->type = REGISTRY_NODE_SCHEMA; node->value.schema = schema; return 0; - } - + } + /* if a partial match is found, we need to keep searching for its children, but can break the loop */ if (res == REGISTRY_FIND_PARTIAL_MATCH) { break; @@ -220,8 +224,8 @@ registry_error_t registry_find(const registry_find_comparator_t compare, node->type = REGISTRY_NODE_INSTANCE; node->value.instance = instance; return 0; - } - + } + /* if a partial match is found, we need to keep searching for its children, but can break the loop */ if (res == REGISTRY_FIND_PARTIAL_MATCH) { break; @@ -249,7 +253,8 @@ registry_error_t registry_find(const registry_find_comparator_t compare, /* if a partial match is found, we need to keep searching for its children */ if (res == REGISTRY_FIND_PARTIAL_MATCH) { const registry_parameter_t *parameter; - res = _find_parameter_by_group(node->value.group.group, compare, context, ¶meter); + res = _find_parameter_by_group(node->value.group.group, compare, context, + ¶meter); if (res == REGISTRY_FIND_EXACT_MATCH) { node->type = REGISTRY_NODE_PARAMETER; From 0410dbdc029897ab5d285ed9b6f50f2cbccf7ec3 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 13:14:29 +0200 Subject: [PATCH 106/117] fixup! sys/registry/storage: add vfs based storage Format --- sys/registry/storage/storage_vfs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/registry/storage/storage_vfs.c b/sys/registry/storage/storage_vfs.c index 99b9f4419d74..bc1568fa78bf 100644 --- a/sys/registry/storage/storage_vfs.c +++ b/sys/registry/storage/storage_vfs.c @@ -36,10 +36,10 @@ #include "registry/storage.h" static registry_error_t load(const registry_storage_instance_t *storage, - const load_cb_t load_cb); + const load_cb_t load_cb); static registry_error_t save(const registry_storage_instance_t *storage, - const registry_node_t *node, - const registry_value_t *value); + const registry_node_t *node, + const registry_value_t *value); registry_storage_t registry_storage_vfs = { .load = load, @@ -105,7 +105,7 @@ static int _umount(vfs_mount_t *mount) } static registry_error_t load(const registry_storage_instance_t *storage, - const load_cb_t load_cb) + const load_cb_t load_cb) { vfs_mount_t *mount = storage->data; @@ -281,7 +281,7 @@ static registry_error_t save(const registry_storage_instance_t *storage, assert(node->type == REGISTRY_NODE_PARAMETER); assert(node->value.parameter.parameter != NULL); assert(node->value.parameter.instance != NULL); - + vfs_mount_t *mount = storage->data; /* mount */ From ba4533d10f7524b139aee46210ea1ad4c1ba22af Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 13:14:42 +0200 Subject: [PATCH 107/117] fixup! sys/registry/storage: add heap based storage Format --- sys/registry/storage/storage_heap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/registry/storage/storage_heap.c b/sys/registry/storage/storage_heap.c index b5ede64a3263..71d175348d5f 100644 --- a/sys/registry/storage/storage_heap.c +++ b/sys/registry/storage/storage_heap.c @@ -58,7 +58,7 @@ registry_storage_t registry_storage_heap = { }; static registry_error_t load(const registry_storage_instance_t *storage, - const load_cb_t load_cb) + const load_cb_t load_cb) { (void)storage; @@ -70,8 +70,8 @@ static registry_error_t load(const registry_storage_instance_t *storage, } static registry_error_t save(const registry_storage_instance_t *storage, - const registry_node_t *node, - const registry_value_t *value) + const registry_node_t *node, + const registry_value_t *value) { assert(node->type == REGISTRY_NODE_PARAMETER); assert(node->value.parameter.parameter != NULL); From f233a276e0da1b9b25eb2d2ecdb6dda34a3700f5 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 13:16:32 +0200 Subject: [PATCH 108/117] fixup! sys/registry: add sys namespace Format --- sys/include/registry/namespace/sys.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/include/registry/namespace/sys.h b/sys/include/registry/namespace/sys.h index 1391265624a9..02208e984f51 100644 --- a/sys/include/registry/namespace/sys.h +++ b/sys/include/registry/namespace/sys.h @@ -11,7 +11,7 @@ * @ingroup sys * @brief RIOT Registry Namespace Sys module * @{ - * + * * This module provides common sys configuration schemas for the RIOT Registry sys module * * @file @@ -36,8 +36,8 @@ extern registry_namespace_t registry_sys; * of pointers. */ typedef enum { - REGISTRY_SYS_BOARD_LED = 0, - REGISTRY_SYS_RGB_LED = 1, + REGISTRY_SYS_BOARD_LED = 0, + REGISTRY_SYS_RGB_LED = 1, } registry_sys_indices_t; #ifdef __cplusplus From 8999642cefc51b073f9049566de5d719a1139876 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 13:16:52 +0200 Subject: [PATCH 109/117] fixup! sys/registry: add tests namespace Format --- sys/include/registry/namespace/tests.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/include/registry/namespace/tests.h b/sys/include/registry/namespace/tests.h index 0e717559f4d4..203b544715d7 100644 --- a/sys/include/registry/namespace/tests.h +++ b/sys/include/registry/namespace/tests.h @@ -11,7 +11,7 @@ * @ingroup tests * @brief RIOT Registry Namespace Tests module * @{ - * + * * This module provides common test schemas for the RIOT Registry sys module * * @file From 958157c93a7f0d3e83ec6af5fdd04e3eabc706f0 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 15:05:52 +0200 Subject: [PATCH 110/117] fixup! sys/registry: add tests namespace Remove test namespace --- sys/include/registry/namespace/tests.h | 48 --- sys/include/registry/namespace/tests/full.h | 91 ------ sys/include/registry/namespace/tests/nested.h | 56 ---- sys/registry/namespace/tests/Kconfig | 19 -- sys/registry/namespace/tests/Makefile | 9 - sys/registry/namespace/tests/Makefile.dep | 4 - .../tests/definitions/0001_full.yaml | 71 ----- .../namespace/tests/namespace_tests.c | 51 --- .../namespace/tests/namespace_tests_full.c | 299 ------------------ .../namespace/tests/namespace_tests_nested.c | 120 ------- 10 files changed, 768 deletions(-) delete mode 100644 sys/include/registry/namespace/tests.h delete mode 100644 sys/include/registry/namespace/tests/full.h delete mode 100644 sys/include/registry/namespace/tests/nested.h delete mode 100644 sys/registry/namespace/tests/Kconfig delete mode 100644 sys/registry/namespace/tests/Makefile delete mode 100644 sys/registry/namespace/tests/Makefile.dep delete mode 100644 sys/registry/namespace/tests/definitions/0001_full.yaml delete mode 100644 sys/registry/namespace/tests/namespace_tests.c delete mode 100644 sys/registry/namespace/tests/namespace_tests_full.c delete mode 100644 sys/registry/namespace/tests/namespace_tests_nested.c diff --git a/sys/include/registry/namespace/tests.h b/sys/include/registry/namespace/tests.h deleted file mode 100644 index 203b544715d7..000000000000 --- a/sys/include/registry/namespace/tests.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests RIOT Registry Tests Namespace - * @ingroup tests - * @brief RIOT Registry Namespace Tests module - * @{ - * - * This module provides common test schemas for the RIOT Registry sys module - * - * @file - * - * @author Lasse Rosenow - */ - -#ifndef REGISTRY_NAMESPACE_TESTS_H -#define REGISTRY_NAMESPACE_TESTS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "registry.h" - -extern registry_namespace_t registry_tests; - -/** - * @brief This ENUM defines the IDs of configuration schemas in the "tests" namespace. - * The IDs are needed by the int_path module to identify schemas using IDs instead - * of pointers. - */ -typedef enum { - REGISTRY_TESTS_FULL, - REGISTRY_TESTS_NESTED, -} registry_tests_indices_t; - -#ifdef __cplusplus -} -#endif - -#endif /* REGISTRY_NAMESPACE_TESTS_H */ -/** @} */ diff --git a/sys/include/registry/namespace/tests/full.h b/sys/include/registry/namespace/tests/full.h deleted file mode 100644 index ab7459cabc6f..000000000000 --- a/sys/include/registry/namespace/tests/full.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_full RIOT Registry Schema: Full - * @ingroup sys - * @brief RIOT Registry Full Schema using all possible data types of the riot registry - * @{ - * - * @file - * - * @author Lasse Rosenow - */ - -#ifndef REGISTRY_NAMESPACE_TESTS_FULL_H -#define REGISTRY_NAMESPACE_TESTS_FULL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "registry.h" - -/* FULL */ -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) || IS_ACTIVE(DOXYGEN) - -extern const registry_parameter_t registry_tests_full_opaque; -extern const registry_parameter_t registry_tests_full_string; -extern const registry_parameter_t registry_tests_full_boolean; -extern const registry_parameter_t registry_tests_full_u8; -extern const registry_parameter_t registry_tests_full_u16; -extern const registry_parameter_t registry_tests_full_u32; -extern const registry_parameter_t registry_tests_full_u64; -extern const registry_parameter_t registry_tests_full_i8; -extern const registry_parameter_t registry_tests_full_i16; -extern const registry_parameter_t registry_tests_full_i32; -extern const registry_parameter_t registry_tests_full_i64; -extern const registry_parameter_t registry_tests_full_f32; -extern const registry_parameter_t registry_tests_full_f64; -extern registry_schema_t registry_tests_full; - -typedef struct { - uint8_t value; -} registry_tests_full_instance_opaque_t; - -typedef struct { - clist_node_t node; - registry_tests_full_instance_opaque_t opaque; - char string[50]; - bool boolean; - uint8_t u8; - uint16_t u16; - uint32_t u32; - uint64_t u64; - int8_t i8; - int16_t i16; - int32_t i32; - int64_t i64; - float f32; - double f64; -} registry_tests_full_instance_t; - -typedef enum { - REGISTRY_TESTS_FULL_OPAQUE, - REGISTRY_TESTS_FULL_STRING, - REGISTRY_TESTS_FULL_BOOLEAN, - REGISTRY_TESTS_FULL_U8, - REGISTRY_TESTS_FULL_U16, - REGISTRY_TESTS_FULL_U32, - REGISTRY_TESTS_FULL_U64, - REGISTRY_TESTS_FULL_I8, - REGISTRY_TESTS_FULL_I16, - REGISTRY_TESTS_FULL_I32, - REGISTRY_TESTS_FULL_I64, - REGISTRY_TESTS_FULL_F32, - REGISTRY_TESTS_FULL_F64, -} registry_tests_full_indices_t; - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* MODULE_REGISTRY_NAMESPACE_TESTS_FULL */ -/** @} */ diff --git a/sys/include/registry/namespace/tests/nested.h b/sys/include/registry/namespace/tests/nested.h deleted file mode 100644 index 77e8cc78afcb..000000000000 --- a/sys/include/registry/namespace/tests/nested.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_nested RIOT Registry Schema: Nested - * @ingroup sys - * @brief RIOT Registry Nested Schema representing different nesting levels of a configuration schema - * @{ - * - * @file - * - * @author Lasse Rosenow - */ - -#ifndef REGISTRY_NAMESPACE_TESTS_NESTED_H -#define REGISTRY_NAMESPACE_TESTS_NESTED_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "registry.h" - -/* NESTED */ -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) - -extern const registry_parameter_t registry_tests_nested_parameter; -extern const registry_group_t registry_tests_nested_group; -extern const registry_parameter_t registry_tests_nested_group_parameter; -extern registry_schema_t registry_tests_nested; - -typedef struct { - clist_node_t node; - uint8_t parameter; - uint8_t group_parameter; -} registry_tests_nested_instance_t; - -typedef enum { - REGISTRY_TESTS_NESTED_PARAMETER, - REGISTRY_TESTS_NESTED_GROUP, - REGISTRY_TESTS_NESTED_GROUP_PARAMETER, -} registry_tests_nested_indices_t; - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* MODULE_REGISTRY_NAMESPACE_TESTS_NESTED */ -/** @} */ diff --git a/sys/registry/namespace/tests/Kconfig b/sys/registry/namespace/tests/Kconfig deleted file mode 100644 index 86e1bf1dd574..000000000000 --- a/sys/registry/namespace/tests/Kconfig +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2023 HAW Hamburg -# -# This file is subject to the terms and conditions of the GNU Lesser -# General Public License v2.1. See the file LICENSE in the top level -# directory for more details. -# - -menuconfig MODULE_REGISTRY_NAMESPACE_TESTS - bool "REGISTRY_NAMESPACE_TESTS" - depends on MODULE_REGISTRY_NAMESPACE - help - Namespace Tests module providing common testing configuration schemas for the RIOT Registry sys module. - -if MODULE_REGISTRY_NAMESPACE_TESTS - -config MODULE_REGISTRY_NAMESPACE_TESTS_FULL - bool "Full schema" - -endif # MODULE_REGISTRY_NAMESPACE_TESTS \ No newline at end of file diff --git a/sys/registry/namespace/tests/Makefile b/sys/registry/namespace/tests/Makefile deleted file mode 100644 index 6819aae6b801..000000000000 --- a/sys/registry/namespace/tests/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -MODULE := registry_namespace_tests - -BASE_MODULE := registry - -SRC := namespace_tests.c - -SUBMODULES := 1 - -include $(RIOTBASE)/Makefile.base diff --git a/sys/registry/namespace/tests/Makefile.dep b/sys/registry/namespace/tests/Makefile.dep deleted file mode 100644 index ad4e1881883f..000000000000 --- a/sys/registry/namespace/tests/Makefile.dep +++ /dev/null @@ -1,4 +0,0 @@ -# Enable "registry_namespace_tests" module for all schemas -ifneq (,$(filter registry_namespace_tests_%,$(USEMODULE))) - USEMODULE += registry_namespace_tests -endif diff --git a/sys/registry/namespace/tests/definitions/0001_full.yaml b/sys/registry/namespace/tests/definitions/0001_full.yaml deleted file mode 100644 index 63132f58bff7..000000000000 --- a/sys/registry/namespace/tests/definitions/0001_full.yaml +++ /dev/null @@ -1,71 +0,0 @@ -# yaml-language-server: $schema=../../../../../dist/tools/registry_gen/schema.json -id: 1 -name: rgb -description: Representation of an rgb color. -items: - - id: 0 - name: opaque - description: Opaque data type property. - type: opaque - size: 50 - - - id: 1 - name: string - description: String data type property. - type: string - size: 50 - - - id: 2 - name: boolean - description: Boolean data type property. - type: bool - - - id: 3 - name: u8 - description: 8 bit unsigned integer data type property. - type: uint8 - - - id: 4 - name: u16 - description: 16 bit unsigned integer data type property. - type: uint16 - - - id: 5 - name: u32 - description: 32 bit unsigned integer data type property. - type: uint32 - - - id: 6 - name: u64 - description: 64 bit unsigned integer data type property. - type: uint64 - - - id: 7 - name: i8 - description: 8 bit integer data type property. - type: int8 - - - id: 8 - name: i16 - description: 16 bit integer data type property. - type: int16 - - - id: 9 - name: i32 - description: 32 bit integer data type property. - type: int32 - - - id: 10 - name: i64 - description: 64 bit integer data type property. - type: int64 - - - id: 11 - name: f32 - description: 64 bit integer data type property. - type: float32 - - - id: 12 - name: f64 - description: 64 bit integer data type property. - type: float64 diff --git a/sys/registry/namespace/tests/namespace_tests.c b/sys/registry/namespace/tests/namespace_tests.c deleted file mode 100644 index 86ddba168922..000000000000 --- a/sys/registry/namespace/tests/namespace_tests.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests RIOT Registry Tests Namespace - * @ingroup tests - * @brief RIOT Registry Namespace Tests module providing common tests configuration schemas for the RIOT Registry sys module - * @{ - * - * @file - * - * @author Lasse Rosenow - */ - -#include - -#define ENABLE_DEBUG (0) -#include "debug.h" -#include "kernel_defines.h" -#include "registry.h" - -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/full.h" -#include "registry/namespace/tests/nested.h" - -static const registry_schema_t *_schemas[] = { -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) - ®istry_tests_full, -#endif -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) - ®istry_tests_nested, -#endif -}; - -registry_namespace_t registry_tests = { -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "tests", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "Tests namespace", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schemas = _schemas, - .schemas_len = ARRAY_SIZE(_schemas), -}; - -REGISTRY_ADD_NAMESPACE(tests, registry_tests); diff --git a/sys/registry/namespace/tests/namespace_tests_full.c b/sys/registry/namespace/tests/namespace_tests_full.c deleted file mode 100644 index 9608b3951e69..000000000000 --- a/sys/registry/namespace/tests/namespace_tests_full.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_full RIOT Registry Schema: Full - * @ingroup sys - * @brief RIOT Registry Full Schema using all possible data types of the riot registry - * @{ - * - * @file - * - * @author Lasse Rosenow - * - * @} - */ - -#include -#include -#include -#include - -#define ENABLE_DEBUG (0) -#include "debug.h" -#include "kernel_defines.h" -#include "registry.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/full.h" - -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) || IS_ACTIVE(DOXYGEN) - -/* Mapping */ -static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, - void **val, size_t *val_len) -{ - registry_tests_full_instance_t *_instance = - (registry_tests_full_instance_t *)instance->data; - - switch (parameter_id) { - case REGISTRY_TESTS_FULL_OPAQUE: - *val = &_instance->opaque; - *val_len = sizeof(_instance->opaque); - break; - - case REGISTRY_TESTS_FULL_STRING: - *val = &_instance->string; - *val_len = sizeof(_instance->string); - break; - - case REGISTRY_TESTS_FULL_BOOLEAN: - *val = &_instance->boolean; - *val_len = sizeof(_instance->boolean); - break; - - case REGISTRY_TESTS_FULL_U8: - *val = &_instance->u8; - *val_len = sizeof(_instance->u8); - break; - - case REGISTRY_TESTS_FULL_U16: - *val = &_instance->u16; - *val_len = sizeof(_instance->u16); - break; - - case REGISTRY_TESTS_FULL_U32: - *val = &_instance->u32; - *val_len = sizeof(_instance->u32); - break; - - case REGISTRY_TESTS_FULL_U64: - *val = &_instance->u64; - *val_len = sizeof(_instance->u64); - break; - - case REGISTRY_TESTS_FULL_I8: - *val = &_instance->i8; - *val_len = sizeof(_instance->i8); - break; - - case REGISTRY_TESTS_FULL_I16: - *val = &_instance->i16; - *val_len = sizeof(_instance->i16); - break; - - case REGISTRY_TESTS_FULL_I32: - *val = &_instance->i32; - *val_len = sizeof(_instance->i32); - break; - - case REGISTRY_TESTS_FULL_I64: - *val = &_instance->i64; - *val_len = sizeof(_instance->i64); - break; - - case REGISTRY_TESTS_FULL_F32: - *val = &_instance->f32; - *val_len = sizeof(_instance->f32); - break; - - case REGISTRY_TESTS_FULL_F64: - *val = &_instance->f64; - *val_len = sizeof(_instance->f64); - break; - } -} - -/* Schema parameters */ -const registry_parameter_t registry_tests_full_opaque = { - .id = REGISTRY_TESTS_FULL_OPAQUE, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "opaque", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_OPAQUE, -}; - -const registry_parameter_t registry_tests_full_string = { - .id = REGISTRY_TESTS_FULL_STRING, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "string", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_STRING, -}; - -const registry_parameter_t registry_tests_full_boolean = { - .id = REGISTRY_TESTS_FULL_BOOLEAN, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "boolean", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_BOOL, -}; - -const registry_parameter_t registry_tests_full_u8 = { - .id = REGISTRY_TESTS_FULL_U8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u8", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_UINT8, -}; - -const registry_parameter_t registry_tests_full_u16 = { - .id = REGISTRY_TESTS_FULL_U16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u16", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_UINT16, -}; - -const registry_parameter_t registry_tests_full_u32 = { - .id = REGISTRY_TESTS_FULL_U32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_UINT32, -}; - -const registry_parameter_t registry_tests_full_u64 = { - .id = REGISTRY_TESTS_FULL_U64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "u64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_UINT64, -}; - -const registry_parameter_t registry_tests_full_i8 = { - .id = REGISTRY_TESTS_FULL_I8, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i8", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_INT8, -}; - -const registry_parameter_t registry_tests_full_i16 = { - .id = REGISTRY_TESTS_FULL_I16, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i16", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_INT16, -}; - -const registry_parameter_t registry_tests_full_i32 = { - .id = REGISTRY_TESTS_FULL_I32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_INT32, -}; - -const registry_parameter_t registry_tests_full_i64 = { - .id = REGISTRY_TESTS_FULL_I64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "i64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_INT64, -}; - -const registry_parameter_t registry_tests_full_f32 = { - .id = REGISTRY_TESTS_FULL_F32, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "f32", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_FLOAT32, -}; - -const registry_parameter_t registry_tests_full_f64 = { - .id = REGISTRY_TESTS_FULL_F64, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "f64", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_full, - .type = REGISTRY_TYPE_FLOAT64, -}; - -/* Schema */ -registry_schema_t registry_tests_full = { - .id = REGISTRY_TESTS_FULL, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "full", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .namespace = ®istry_tests, - .mapping = mapping, - .groups = NULL, - .groups_len = 0, - .parameters = (const registry_parameter_t *[]) { - ®istry_tests_full_opaque, - ®istry_tests_full_string, - ®istry_tests_full_boolean, - ®istry_tests_full_u8, - ®istry_tests_full_u16, - ®istry_tests_full_u32, - ®istry_tests_full_u64, - ®istry_tests_full_i8, - ®istry_tests_full_i16, - ®istry_tests_full_i32, - ®istry_tests_full_i64, - ®istry_tests_full_f32, - ®istry_tests_full_f64, - }, - .parameters_len = 13, -}; - -#endif diff --git a/sys/registry/namespace/tests/namespace_tests_nested.c b/sys/registry/namespace/tests/namespace_tests_nested.c deleted file mode 100644 index 9210785b55d2..000000000000 --- a/sys/registry/namespace/tests/namespace_tests_nested.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2023 HAW Hamburg - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup sys_registry_namespace_tests_nested RIOT Registry Schema: Nested - * @ingroup sys - * @brief RIOT Registry Nested Schema representing different nesting levels of a configuration schema - * @{ - * - * @file - * - * @author Lasse Rosenow - * - * @} - */ - -#include -#include -#include -#include - -#define ENABLE_DEBUG (0) -#include "debug.h" -#include "kernel_defines.h" -#include "registry.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/nested.h" - -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) - -/* Mapping */ -static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, - void **val, size_t *val_len) -{ - registry_tests_nested_instance_t *_instance = - (registry_tests_nested_instance_t *)instance->data; - - switch (parameter_id) { - case REGISTRY_TESTS_NESTED_PARAMETER: - *val = &_instance->parameter; - *val_len = sizeof(_instance->parameter); - break; - - case REGISTRY_TESTS_NESTED_GROUP_PARAMETER: - *val = &_instance->group_parameter; - *val_len = sizeof(_instance->group_parameter); - break; - } -} - -/* Schema parameters */ -const registry_parameter_t registry_tests_nested_parameter = { - .id = REGISTRY_TESTS_NESTED_PARAMETER, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "parameter", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_nested, - .type = REGISTRY_TYPE_UINT8, -}; - -const registry_parameter_t registry_tests_nested_group_parameter = { - .id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "parameter", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_nested, - .type = REGISTRY_TYPE_UINT8, -}; - -/* Schema groups */ -const registry_group_t registry_tests_nested_group = { - .id = REGISTRY_TESTS_NESTED_GROUP, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "group", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .schema = ®istry_tests_nested, - .groups = NULL, - .groups_len = 0, - .parameters = (const registry_parameter_t *[]) { - ®istry_tests_nested_group_parameter, - }, - .parameters_len = 1, -}; - -/* Schema */ -registry_schema_t registry_tests_nested = { - .id = REGISTRY_TESTS_NESTED, -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) - .name = "nested", -#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ -#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) - .description = "", -#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ - .namespace = ®istry_tests, - .mapping = mapping, - .groups = (const registry_group_t *[]) { - ®istry_tests_nested_group, - }, - .groups_len = 1, - .parameters = (const registry_parameter_t *[]) { - ®istry_tests_nested_parameter, - }, - .parameters_len = 1, -}; - -#endif From 305fc97e8c4d6272a024459a99160457b2dffa60 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 15:06:20 +0200 Subject: [PATCH 111/117] fixup! sys: add runtime configuration registry Fix small bug --- sys/registry/registry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/registry/registry.c b/sys/registry/registry.c index 83d35adea909..4dbe52a07209 100644 --- a/sys/registry/registry.c +++ b/sys/registry/registry.c @@ -312,7 +312,7 @@ static registry_error_t _registry_export_schema( clist_node_t *node = schema->instances.next; if (!node) { - return -REGISTRY_ERROR_SCHEMA_HAS_NO_INSTANCE; + return REGISTRY_ERROR_NONE; } do { From a927ce3e3ad5c0f4703c2ce70343b3d0451e9eb6 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 15:06:54 +0200 Subject: [PATCH 112/117] fixup! tests/unittests: add registry tests Migrate to local test namespace --- tests/unittests/tests-registry/Makefile | 4 +- .../unittests/tests-registry/Makefile.include | 6 +- .../tests-registry/namespace/Makefile | 3 + .../namespace/definitions/0001_full.yaml | 71 +++++ .../namespace/namespace_tests.c | 47 +++ .../namespace/namespace_tests_full.c | 295 ++++++++++++++++++ .../namespace/namespace_tests_nested.c | 116 +++++++ .../tests-registry/namespace/tests.h | 48 +++ .../tests-registry/namespace/tests/full.h | 87 ++++++ .../tests-registry/namespace/tests/nested.h | 52 +++ tests/unittests/tests-registry/tests-commit.c | 23 +- tests/unittests/tests-registry/tests-export.c | 19 +- .../unittests/tests-registry/tests-get-set.c | 15 +- 13 files changed, 750 insertions(+), 36 deletions(-) create mode 100644 tests/unittests/tests-registry/namespace/Makefile create mode 100644 tests/unittests/tests-registry/namespace/definitions/0001_full.yaml create mode 100644 tests/unittests/tests-registry/namespace/namespace_tests.c create mode 100644 tests/unittests/tests-registry/namespace/namespace_tests_full.c create mode 100644 tests/unittests/tests-registry/namespace/namespace_tests_nested.c create mode 100644 tests/unittests/tests-registry/namespace/tests.h create mode 100644 tests/unittests/tests-registry/namespace/tests/full.h create mode 100644 tests/unittests/tests-registry/namespace/tests/nested.h diff --git a/tests/unittests/tests-registry/Makefile b/tests/unittests/tests-registry/Makefile index 9c9ae9884ad6..e90483f4f15a 100644 --- a/tests/unittests/tests-registry/Makefile +++ b/tests/unittests/tests-registry/Makefile @@ -1 +1,3 @@ -include $(RIOTBASE)/Makefile.base \ No newline at end of file +DIRS += namespace + +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-registry/Makefile.include b/tests/unittests/tests-registry/Makefile.include index a308a6bcdeb6..5c37ee79b853 100644 --- a/tests/unittests/tests-registry/Makefile.include +++ b/tests/unittests/tests-registry/Makefile.include @@ -1,4 +1,2 @@ -CFLAGS += -DCONFIG_REGISTRY_ENABLE_META_NAME - -USEMODULE += registry_namespace_tests_full -USEMODULE += registry_namespace_tests_nested +USEMODULE += registry +USEMODULE += tests-registry-namespace diff --git a/tests/unittests/tests-registry/namespace/Makefile b/tests/unittests/tests-registry/namespace/Makefile new file mode 100644 index 000000000000..dc31b2f88174 --- /dev/null +++ b/tests/unittests/tests-registry/namespace/Makefile @@ -0,0 +1,3 @@ +MODULE = tests-registry-namespace + +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-registry/namespace/definitions/0001_full.yaml b/tests/unittests/tests-registry/namespace/definitions/0001_full.yaml new file mode 100644 index 000000000000..63132f58bff7 --- /dev/null +++ b/tests/unittests/tests-registry/namespace/definitions/0001_full.yaml @@ -0,0 +1,71 @@ +# yaml-language-server: $schema=../../../../../dist/tools/registry_gen/schema.json +id: 1 +name: rgb +description: Representation of an rgb color. +items: + - id: 0 + name: opaque + description: Opaque data type property. + type: opaque + size: 50 + + - id: 1 + name: string + description: String data type property. + type: string + size: 50 + + - id: 2 + name: boolean + description: Boolean data type property. + type: bool + + - id: 3 + name: u8 + description: 8 bit unsigned integer data type property. + type: uint8 + + - id: 4 + name: u16 + description: 16 bit unsigned integer data type property. + type: uint16 + + - id: 5 + name: u32 + description: 32 bit unsigned integer data type property. + type: uint32 + + - id: 6 + name: u64 + description: 64 bit unsigned integer data type property. + type: uint64 + + - id: 7 + name: i8 + description: 8 bit integer data type property. + type: int8 + + - id: 8 + name: i16 + description: 16 bit integer data type property. + type: int16 + + - id: 9 + name: i32 + description: 32 bit integer data type property. + type: int32 + + - id: 10 + name: i64 + description: 64 bit integer data type property. + type: int64 + + - id: 11 + name: f32 + description: 64 bit integer data type property. + type: float32 + + - id: 12 + name: f64 + description: 64 bit integer data type property. + type: float64 diff --git a/tests/unittests/tests-registry/namespace/namespace_tests.c b/tests/unittests/tests-registry/namespace/namespace_tests.c new file mode 100644 index 000000000000..dfffb170c54d --- /dev/null +++ b/tests/unittests/tests-registry/namespace/namespace_tests.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests RIOT Registry Tests Namespace + * @ingroup tests + * @brief RIOT Registry Namespace Tests module providing common tests configuration schemas for the RIOT Registry sys module + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" + +#include "tests.h" +#include "tests/full.h" +#include "tests/nested.h" + +static const registry_schema_t *_schemas[] = { + ®istry_tests_full, + ®istry_tests_nested, +}; + +registry_namespace_t registry_tests = { +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "tests", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "Tests namespace", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schemas = _schemas, + .schemas_len = ARRAY_SIZE(_schemas), +}; + +REGISTRY_ADD_NAMESPACE(tests, registry_tests); diff --git a/tests/unittests/tests-registry/namespace/namespace_tests_full.c b/tests/unittests/tests-registry/namespace/namespace_tests_full.c new file mode 100644 index 000000000000..06ccb0fe7dd6 --- /dev/null +++ b/tests/unittests/tests-registry/namespace/namespace_tests_full.c @@ -0,0 +1,295 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_full RIOT Registry Schema: Full + * @ingroup sys + * @brief RIOT Registry Full Schema using all possible data types of the riot registry + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" +#include "tests.h" +#include "tests/full.h" + +/* Mapping */ +static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, + void **val, size_t *val_len) +{ + registry_tests_full_instance_t *_instance = + (registry_tests_full_instance_t *)instance->data; + + switch (parameter_id) { + case REGISTRY_TESTS_FULL_OPAQUE: + *val = &_instance->opaque; + *val_len = sizeof(_instance->opaque); + break; + + case REGISTRY_TESTS_FULL_STRING: + *val = &_instance->string; + *val_len = sizeof(_instance->string); + break; + + case REGISTRY_TESTS_FULL_BOOLEAN: + *val = &_instance->boolean; + *val_len = sizeof(_instance->boolean); + break; + + case REGISTRY_TESTS_FULL_U8: + *val = &_instance->u8; + *val_len = sizeof(_instance->u8); + break; + + case REGISTRY_TESTS_FULL_U16: + *val = &_instance->u16; + *val_len = sizeof(_instance->u16); + break; + + case REGISTRY_TESTS_FULL_U32: + *val = &_instance->u32; + *val_len = sizeof(_instance->u32); + break; + + case REGISTRY_TESTS_FULL_U64: + *val = &_instance->u64; + *val_len = sizeof(_instance->u64); + break; + + case REGISTRY_TESTS_FULL_I8: + *val = &_instance->i8; + *val_len = sizeof(_instance->i8); + break; + + case REGISTRY_TESTS_FULL_I16: + *val = &_instance->i16; + *val_len = sizeof(_instance->i16); + break; + + case REGISTRY_TESTS_FULL_I32: + *val = &_instance->i32; + *val_len = sizeof(_instance->i32); + break; + + case REGISTRY_TESTS_FULL_I64: + *val = &_instance->i64; + *val_len = sizeof(_instance->i64); + break; + + case REGISTRY_TESTS_FULL_F32: + *val = &_instance->f32; + *val_len = sizeof(_instance->f32); + break; + + case REGISTRY_TESTS_FULL_F64: + *val = &_instance->f64; + *val_len = sizeof(_instance->f64); + break; + } +} + +/* Schema parameters */ +const registry_parameter_t registry_tests_full_opaque = { + .id = REGISTRY_TESTS_FULL_OPAQUE, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "opaque", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_OPAQUE, +}; + +const registry_parameter_t registry_tests_full_string = { + .id = REGISTRY_TESTS_FULL_STRING, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "string", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_STRING, +}; + +const registry_parameter_t registry_tests_full_boolean = { + .id = REGISTRY_TESTS_FULL_BOOLEAN, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "boolean", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_BOOL, +}; + +const registry_parameter_t registry_tests_full_u8 = { + .id = REGISTRY_TESTS_FULL_U8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_UINT8, +}; + +const registry_parameter_t registry_tests_full_u16 = { + .id = REGISTRY_TESTS_FULL_U16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_UINT16, +}; + +const registry_parameter_t registry_tests_full_u32 = { + .id = REGISTRY_TESTS_FULL_U32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_UINT32, +}; + +const registry_parameter_t registry_tests_full_u64 = { + .id = REGISTRY_TESTS_FULL_U64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "u64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_UINT64, +}; + +const registry_parameter_t registry_tests_full_i8 = { + .id = REGISTRY_TESTS_FULL_I8, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i8", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_INT8, +}; + +const registry_parameter_t registry_tests_full_i16 = { + .id = REGISTRY_TESTS_FULL_I16, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i16", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_INT16, +}; + +const registry_parameter_t registry_tests_full_i32 = { + .id = REGISTRY_TESTS_FULL_I32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_INT32, +}; + +const registry_parameter_t registry_tests_full_i64 = { + .id = REGISTRY_TESTS_FULL_I64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "i64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_INT64, +}; + +const registry_parameter_t registry_tests_full_f32 = { + .id = REGISTRY_TESTS_FULL_F32, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f32", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_FLOAT32, +}; + +const registry_parameter_t registry_tests_full_f64 = { + .id = REGISTRY_TESTS_FULL_F64, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "f64", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_full, + .type = REGISTRY_TYPE_FLOAT64, +}; + +/* Schema */ +registry_schema_t registry_tests_full = { + .id = REGISTRY_TESTS_FULL, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "full", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .namespace = ®istry_tests, + .mapping = mapping, + .groups = NULL, + .groups_len = 0, + .parameters = (const registry_parameter_t *[]) { + ®istry_tests_full_opaque, + ®istry_tests_full_string, + ®istry_tests_full_boolean, + ®istry_tests_full_u8, + ®istry_tests_full_u16, + ®istry_tests_full_u32, + ®istry_tests_full_u64, + ®istry_tests_full_i8, + ®istry_tests_full_i16, + ®istry_tests_full_i32, + ®istry_tests_full_i64, + ®istry_tests_full_f32, + ®istry_tests_full_f64, + }, + .parameters_len = 13, +}; diff --git a/tests/unittests/tests-registry/namespace/namespace_tests_nested.c b/tests/unittests/tests-registry/namespace/namespace_tests_nested.c new file mode 100644 index 000000000000..75c73ce79fa8 --- /dev/null +++ b/tests/unittests/tests-registry/namespace/namespace_tests_nested.c @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_nested RIOT Registry Schema: Nested + * @ingroup sys + * @brief RIOT Registry Nested Schema representing different nesting levels of a configuration schema + * @{ + * + * @file + * + * @author Lasse Rosenow + * + * @} + */ + +#include +#include +#include +#include + +#define ENABLE_DEBUG (0) +#include "debug.h" +#include "kernel_defines.h" +#include "registry.h" +#include "tests.h" +#include "tests/nested.h" + +/* Mapping */ +static void mapping(const registry_parameter_id_t parameter_id, const registry_instance_t *instance, + void **val, size_t *val_len) +{ + registry_tests_nested_instance_t *_instance = + (registry_tests_nested_instance_t *)instance->data; + + switch (parameter_id) { + case REGISTRY_TESTS_NESTED_PARAMETER: + *val = &_instance->parameter; + *val_len = sizeof(_instance->parameter); + break; + + case REGISTRY_TESTS_NESTED_GROUP_PARAMETER: + *val = &_instance->group_parameter; + *val_len = sizeof(_instance->group_parameter); + break; + } +} + +/* Schema parameters */ +const registry_parameter_t registry_tests_nested_parameter = { + .id = REGISTRY_TESTS_NESTED_PARAMETER, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "parameter", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_nested, + .type = REGISTRY_TYPE_UINT8, +}; + +const registry_parameter_t registry_tests_nested_group_parameter = { + .id = REGISTRY_TESTS_NESTED_GROUP_PARAMETER, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "parameter", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_nested, + .type = REGISTRY_TYPE_UINT8, +}; + +/* Schema groups */ +const registry_group_t registry_tests_nested_group = { + .id = REGISTRY_TESTS_NESTED_GROUP, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "group", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .schema = ®istry_tests_nested, + .groups = NULL, + .groups_len = 0, + .parameters = (const registry_parameter_t *[]) { + ®istry_tests_nested_group_parameter, + }, + .parameters_len = 1, +}; + +/* Schema */ +registry_schema_t registry_tests_nested = { + .id = REGISTRY_TESTS_NESTED, +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) + .name = "nested", +#endif /* CONFIG_REGISTRY_ENABLE_META_NAME */ +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_DESCRIPTION) || IS_ACTIVE(DOXYGEN) + .description = "", +#endif /* CONFIG_REGISTRY_ENABLE_META_DESCRIPTION */ + .namespace = ®istry_tests, + .mapping = mapping, + .groups = (const registry_group_t *[]) { + ®istry_tests_nested_group, + }, + .groups_len = 1, + .parameters = (const registry_parameter_t *[]) { + ®istry_tests_nested_parameter, + }, + .parameters_len = 1, +}; diff --git a/tests/unittests/tests-registry/namespace/tests.h b/tests/unittests/tests-registry/namespace/tests.h new file mode 100644 index 000000000000..203b544715d7 --- /dev/null +++ b/tests/unittests/tests-registry/namespace/tests.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests RIOT Registry Tests Namespace + * @ingroup tests + * @brief RIOT Registry Namespace Tests module + * @{ + * + * This module provides common test schemas for the RIOT Registry sys module + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_TESTS_H +#define REGISTRY_NAMESPACE_TESTS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +extern registry_namespace_t registry_tests; + +/** + * @brief This ENUM defines the IDs of configuration schemas in the "tests" namespace. + * The IDs are needed by the int_path module to identify schemas using IDs instead + * of pointers. + */ +typedef enum { + REGISTRY_TESTS_FULL, + REGISTRY_TESTS_NESTED, +} registry_tests_indices_t; + +#ifdef __cplusplus +} +#endif + +#endif /* REGISTRY_NAMESPACE_TESTS_H */ +/** @} */ diff --git a/tests/unittests/tests-registry/namespace/tests/full.h b/tests/unittests/tests-registry/namespace/tests/full.h new file mode 100644 index 000000000000..b4e627a8c73b --- /dev/null +++ b/tests/unittests/tests-registry/namespace/tests/full.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_full RIOT Registry Schema: Full + * @ingroup sys + * @brief RIOT Registry Full Schema using all possible data types of the riot registry + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_TESTS_FULL_H +#define REGISTRY_NAMESPACE_TESTS_FULL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/* FULL */ +extern const registry_parameter_t registry_tests_full_opaque; +extern const registry_parameter_t registry_tests_full_string; +extern const registry_parameter_t registry_tests_full_boolean; +extern const registry_parameter_t registry_tests_full_u8; +extern const registry_parameter_t registry_tests_full_u16; +extern const registry_parameter_t registry_tests_full_u32; +extern const registry_parameter_t registry_tests_full_u64; +extern const registry_parameter_t registry_tests_full_i8; +extern const registry_parameter_t registry_tests_full_i16; +extern const registry_parameter_t registry_tests_full_i32; +extern const registry_parameter_t registry_tests_full_i64; +extern const registry_parameter_t registry_tests_full_f32; +extern const registry_parameter_t registry_tests_full_f64; +extern registry_schema_t registry_tests_full; + +typedef struct { + uint8_t value; +} registry_tests_full_instance_opaque_t; + +typedef struct { + clist_node_t node; + registry_tests_full_instance_opaque_t opaque; + char string[50]; + bool boolean; + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + int8_t i8; + int16_t i16; + int32_t i32; + int64_t i64; + float f32; + double f64; +} registry_tests_full_instance_t; + +typedef enum { + REGISTRY_TESTS_FULL_OPAQUE, + REGISTRY_TESTS_FULL_STRING, + REGISTRY_TESTS_FULL_BOOLEAN, + REGISTRY_TESTS_FULL_U8, + REGISTRY_TESTS_FULL_U16, + REGISTRY_TESTS_FULL_U32, + REGISTRY_TESTS_FULL_U64, + REGISTRY_TESTS_FULL_I8, + REGISTRY_TESTS_FULL_I16, + REGISTRY_TESTS_FULL_I32, + REGISTRY_TESTS_FULL_I64, + REGISTRY_TESTS_FULL_F32, + REGISTRY_TESTS_FULL_F64, +} registry_tests_full_indices_t; + +#ifdef __cplusplus +} +#endif + +#endif /* MODULE_REGISTRY_NAMESPACE_TESTS_FULL */ +/** @} */ diff --git a/tests/unittests/tests-registry/namespace/tests/nested.h b/tests/unittests/tests-registry/namespace/tests/nested.h new file mode 100644 index 000000000000..0b58a97ad2d8 --- /dev/null +++ b/tests/unittests/tests-registry/namespace/tests/nested.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_registry_namespace_tests_nested RIOT Registry Schema: Nested + * @ingroup sys + * @brief RIOT Registry Nested Schema representing different nesting levels of a configuration schema + * @{ + * + * @file + * + * @author Lasse Rosenow + */ + +#ifndef REGISTRY_NAMESPACE_TESTS_NESTED_H +#define REGISTRY_NAMESPACE_TESTS_NESTED_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "registry.h" + +/* NESTED */ +extern const registry_parameter_t registry_tests_nested_parameter; +extern const registry_group_t registry_tests_nested_group; +extern const registry_parameter_t registry_tests_nested_group_parameter; +extern registry_schema_t registry_tests_nested; + +typedef struct { + clist_node_t node; + uint8_t parameter; + uint8_t group_parameter; +} registry_tests_nested_instance_t; + +typedef enum { + REGISTRY_TESTS_NESTED_PARAMETER, + REGISTRY_TESTS_NESTED_GROUP, + REGISTRY_TESTS_NESTED_GROUP_PARAMETER, +} registry_tests_nested_indices_t; + +#ifdef __cplusplus +} +#endif + +#endif /* MODULE_REGISTRY_NAMESPACE_TESTS_NESTED */ +/** @} */ diff --git a/tests/unittests/tests-registry/tests-commit.c b/tests/unittests/tests-registry/tests-commit.c index dd86d8da1e7d..052e3f6b72ba 100644 --- a/tests/unittests/tests-registry/tests-commit.c +++ b/tests/unittests/tests-registry/tests-commit.c @@ -30,18 +30,17 @@ #include "registry.h" #include "tests-registry.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/nested.h" - -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) +#include "namespace/tests.h" +#include "namespace/tests/nested.h" static bool successful = false; static registry_group_or_parameter_id_t parameter_id; static registry_group_or_parameter_id_t group_id; static registry_error_t commit_parameter_cb(const registry_commit_cb_scope_t scope, - const registry_group_or_parameter_id_t *group_or_parameter_id, - const void *context) + const registry_group_or_parameter_id_t * + group_or_parameter_id, + const void *context) { (void)context; @@ -54,8 +53,9 @@ static registry_error_t commit_parameter_cb(const registry_commit_cb_scope_t sco } static registry_error_t commit_group_cb(const registry_commit_cb_scope_t scope, - const registry_group_or_parameter_id_t *group_or_parameter_id, - const void *context) + const registry_group_or_parameter_id_t * + group_or_parameter_id, + const void *context) { (void)context; @@ -68,8 +68,9 @@ static registry_error_t commit_group_cb(const registry_commit_cb_scope_t scope, } static registry_error_t commit_instance_cb(const registry_commit_cb_scope_t scope, - const registry_group_or_parameter_id_t *group_or_parameter_id, - const void *context) + const registry_group_or_parameter_id_t * + group_or_parameter_id, + const void *context) { (void)context; @@ -225,6 +226,4 @@ Test *tests_registry_commit_tests(void) return (Test *)®istry_tests; } -#endif - /** @} */ diff --git a/tests/unittests/tests-registry/tests-export.c b/tests/unittests/tests-registry/tests-export.c index 7506d4bc94a6..0ff8d0f60761 100644 --- a/tests/unittests/tests-registry/tests-export.c +++ b/tests/unittests/tests-registry/tests-export.c @@ -30,10 +30,8 @@ #include "registry.h" #include "tests-registry.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/nested.h" - -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) +#include "namespace/tests.h" +#include "namespace/tests/nested.h" static bool successful = false; @@ -51,7 +49,7 @@ static registry_instance_t test_nested_instance_1 = { }; static registry_error_t export_parameter_cb(const registry_node_t *node, - const void *context) + const void *context) { (void)context; @@ -65,7 +63,7 @@ static registry_error_t export_parameter_cb(const registry_node_t *node, } static registry_error_t export_group_cb(const registry_node_t *node, - const void *context) + const void *context) { (void)context; @@ -78,7 +76,7 @@ static registry_error_t export_group_cb(const registry_node_t *node, } static registry_error_t export_instance_cb(const registry_node_t *node, - const void *context) + const void *context) { (void)context; @@ -90,7 +88,7 @@ static registry_error_t export_instance_cb(const registry_node_t *node, } static registry_error_t export_schema_cb(const registry_node_t *node, - const void *context) + const void *context) { (void)context; @@ -103,7 +101,7 @@ static registry_error_t export_schema_cb(const registry_node_t *node, } static registry_error_t export_namespace_cb(const registry_node_t *node, - const void *context) + const void *context) { (void)context; @@ -159,6 +157,7 @@ static void tests_registry_export_group(void) /* check if group gets exported */ const registry_group_id_t group_id = REGISTRY_TESTS_NESTED_GROUP; + successful = false; registry_export(&node, &export_group_cb, 0, &group_id); TEST_ASSERT(successful); @@ -386,6 +385,4 @@ Test *tests_registry_export_tests(void) return (Test *)®istry_tests; } -#endif - /** @} */ diff --git a/tests/unittests/tests-registry/tests-get-set.c b/tests/unittests/tests-registry/tests-get-set.c index 169b2c8428c0..52f0352a1fae 100644 --- a/tests/unittests/tests-registry/tests-get-set.c +++ b/tests/unittests/tests-registry/tests-get-set.c @@ -30,17 +30,15 @@ #include "registry.h" #include "tests-registry.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/full.h" +#include "namespace/tests.h" +#include "namespace/tests/full.h" #define FLOAT_MAX_CHAR_COUNT ((FLT_MAX_10_EXP + 1) + 1 + 1 + 6) // (FLT_MAX_10_EXP + 1) + sign + dot + 6 decimal places #define DOUBLE_MAX_CHAR_COUNT ((DBL_MAX_10_EXP + 1) + 1 + 1 + 6) // (DBL_MAX_10_EXP + 1) + sign + dot + 6 decimal places -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_FULL) || IS_ACTIVE(DOXYGEN) - static registry_error_t commit_cb(const registry_commit_cb_scope_t scope, - const registry_group_or_parameter_id_t *group_or_parameter_id, - const void *context) + const registry_group_or_parameter_id_t *group_or_parameter_id, + const void *context) { (void)scope; (void)group_or_parameter_id; @@ -103,6 +101,7 @@ static void tests_registry_min_values(void) const registry_tests_full_instance_opaque_t input_opaque = { .value = 0, }; + node.value.parameter.parameter = ®istry_tests_full_opaque; registry_set(&node, &input_opaque, sizeof(input_opaque)); @@ -254,6 +253,7 @@ static void tests_registry_zero_values(void) const registry_tests_full_instance_opaque_t input_opaque = { .value = 0, }; + node.value.parameter.parameter = ®istry_tests_full_opaque; registry_set(&node, &input_opaque, sizeof(input_opaque)); @@ -406,6 +406,7 @@ static void tests_registry_max_values(void) const registry_tests_full_instance_opaque_t input_opaque = { .value = UINT8_MAX, }; + node.value.parameter.parameter = ®istry_tests_full_opaque; registry_set(&node, &input_opaque, sizeof(input_opaque)); @@ -568,6 +569,4 @@ Test *tests_registry_get_set_tests(void) return (Test *)®istry_tests; } -#endif - /** @} */ From 500e7ef24bdffbd3be192a5021dc95b097befb6e Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 15:07:10 +0200 Subject: [PATCH 113/117] fixup! tests/unittests: add registry_int_path tests Migrate to local test namespace --- .../unittests/tests-registry_int_path/Makefile | 4 +++- .../tests-registry_int_path/Makefile.include | 3 ++- .../unittests/tests-registry_int_path/namespace | 1 + .../tests-registry_int_path.c | 17 ++++++++--------- 4 files changed, 14 insertions(+), 11 deletions(-) create mode 120000 tests/unittests/tests-registry_int_path/namespace diff --git a/tests/unittests/tests-registry_int_path/Makefile b/tests/unittests/tests-registry_int_path/Makefile index 9c9ae9884ad6..e90483f4f15a 100644 --- a/tests/unittests/tests-registry_int_path/Makefile +++ b/tests/unittests/tests-registry_int_path/Makefile @@ -1 +1,3 @@ -include $(RIOTBASE)/Makefile.base \ No newline at end of file +DIRS += namespace + +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-registry_int_path/Makefile.include b/tests/unittests/tests-registry_int_path/Makefile.include index fd79cc7645b0..c0906ef1ed59 100644 --- a/tests/unittests/tests-registry_int_path/Makefile.include +++ b/tests/unittests/tests-registry_int_path/Makefile.include @@ -1,2 +1,3 @@ USEMODULE += registry_int_path -USEMODULE += registry_namespace_tests_nested + +USEMODULE += tests-registry-namespace diff --git a/tests/unittests/tests-registry_int_path/namespace b/tests/unittests/tests-registry_int_path/namespace new file mode 120000 index 000000000000..6a0bcd8e750e --- /dev/null +++ b/tests/unittests/tests-registry_int_path/namespace @@ -0,0 +1 @@ +../tests-registry/namespace \ No newline at end of file diff --git a/tests/unittests/tests-registry_int_path/tests-registry_int_path.c b/tests/unittests/tests-registry_int_path/tests-registry_int_path.c index 303e0c7baee6..d13fde3b6cef 100644 --- a/tests/unittests/tests-registry_int_path/tests-registry_int_path.c +++ b/tests/unittests/tests-registry_int_path/tests-registry_int_path.c @@ -33,10 +33,8 @@ #include "mtd.h" #include "registry.h" #include "registry/int_path.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/nested.h" - -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) +#include "namespace/tests.h" +#include "namespace/tests/nested.h" static registry_tests_nested_instance_t test_instance_data = { .parameter = 9, @@ -77,7 +75,8 @@ static void tests_registry_to_parameter_int_path(void) TEST_ASSERT_EQUAL_INT(registry_tests.id, path.value.parameter_path.namespace_id); TEST_ASSERT_EQUAL_INT(registry_tests_nested.id, path.value.parameter_path.schema_id); TEST_ASSERT_EQUAL_INT(test_instance.id, path.value.parameter_path.instance_id); - TEST_ASSERT_EQUAL_INT(registry_tests_nested_parameter.id, path.value.parameter_path.parameter_id); + TEST_ASSERT_EQUAL_INT(registry_tests_nested_parameter.id, + path.value.parameter_path.parameter_id); } static void tests_registry_to_group_int_path(void) @@ -162,7 +161,8 @@ static void tests_registry_from_group_or_parameter_int_path(void) TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.value.parameter.instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)node.value.parameter.parameter); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, + (int)node.value.parameter.parameter); /* group */ @@ -203,7 +203,8 @@ static void tests_registry_from_parameter_int_path(void) TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); TEST_ASSERT_EQUAL_INT((int)&test_instance, (int)node.value.parameter.instance); - TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, (int)node.value.parameter.parameter); + TEST_ASSERT_EQUAL_INT((int)®istry_tests_nested_group_parameter, + (int)node.value.parameter.parameter); } static void tests_registry_from_group_int_path(void) @@ -313,6 +314,4 @@ void tests_registry_int_path(void) TESTS_RUN(tests_registry_int_path_tests()); } -#endif - /** @} */ From 91006b672250b3e97d533aab188140c32399f5fb Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 15:07:31 +0200 Subject: [PATCH 114/117] fixup! tests/unittests: add registry_storage tests Migrate to local test namespace --- .../unittests/tests-registry_storage/Makefile | 4 ++- .../tests-registry_storage/Makefile.include | 3 +- .../tests-registry_storage/namespace | 1 + .../tests-registry_storage.c | 31 ++++++++----------- 4 files changed, 19 insertions(+), 20 deletions(-) create mode 120000 tests/unittests/tests-registry_storage/namespace diff --git a/tests/unittests/tests-registry_storage/Makefile b/tests/unittests/tests-registry_storage/Makefile index 9c9ae9884ad6..e90483f4f15a 100644 --- a/tests/unittests/tests-registry_storage/Makefile +++ b/tests/unittests/tests-registry_storage/Makefile @@ -1 +1,3 @@ -include $(RIOTBASE)/Makefile.base \ No newline at end of file +DIRS += namespace + +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-registry_storage/Makefile.include b/tests/unittests/tests-registry_storage/Makefile.include index bfd89dd4f3bd..524ab54bf748 100644 --- a/tests/unittests/tests-registry_storage/Makefile.include +++ b/tests/unittests/tests-registry_storage/Makefile.include @@ -1,2 +1,3 @@ USEMODULE += registry_storage -USEMODULE += registry_namespace_tests_nested + +USEMODULE += tests-registry-namespace diff --git a/tests/unittests/tests-registry_storage/namespace b/tests/unittests/tests-registry_storage/namespace new file mode 120000 index 000000000000..6a0bcd8e750e --- /dev/null +++ b/tests/unittests/tests-registry_storage/namespace @@ -0,0 +1 @@ +../tests-registry/namespace \ No newline at end of file diff --git a/tests/unittests/tests-registry_storage/tests-registry_storage.c b/tests/unittests/tests-registry_storage/tests-registry_storage.c index 73ed1591a4d9..89d92b925f4a 100644 --- a/tests/unittests/tests-registry_storage/tests-registry_storage.c +++ b/tests/unittests/tests-registry_storage/tests-registry_storage.c @@ -32,10 +32,8 @@ #include "registry/storage.h" #include "tests-registry_storage.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/nested.h" - -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) +#include "namespace/tests.h" +#include "namespace/tests/nested.h" #define _TESTS_REGISTRY_LOAD_STORED_VALUE 60 @@ -55,10 +53,10 @@ static registry_instance_t test_nested_instance = { }; static registry_error_t load(const registry_storage_instance_t *storage, - const load_cb_t load_cb); + const load_cb_t load_cb); static registry_error_t save(const registry_storage_instance_t *storage, - const registry_node_t *node, - const registry_value_t *value); + const registry_node_t *node, + const registry_value_t *value); static registry_storage_t storage_test = { .load = load, @@ -73,7 +71,7 @@ static registry_storage_instance_t storage_test_instance = { }; static registry_error_t load(const registry_storage_instance_t *storage, - const load_cb_t load_cb) + const load_cb_t load_cb) { if (storage == &storage_test_instance) { registry_node_t node = { @@ -91,10 +89,9 @@ static registry_error_t load(const registry_storage_instance_t *storage, } static registry_error_t save(const registry_storage_instance_t *storage, - const registry_node_t *node, - const registry_value_t *value) + const registry_node_t *node, + const registry_value_t *value) { - if (storage == &storage_test_instance && node->value.parameter.instance == &test_nested_instance && node->value.parameter.parameter == ®istry_tests_nested_group_parameter && @@ -164,7 +161,7 @@ static void tests_registry_save_group(void) .group = ®istry_tests_nested_group, }, }; - + registry_storage_save(&storage_test_instance, &node); TEST_ASSERT(successful); @@ -176,7 +173,7 @@ static void tests_registry_save_instance(void) .type = REGISTRY_NODE_INSTANCE, .value.instance = &test_nested_instance, }; - + registry_storage_save(&storage_test_instance, &node); TEST_ASSERT(successful); @@ -188,7 +185,7 @@ static void tests_registry_save_schema(void) .type = REGISTRY_NODE_SCHEMA, .value.schema = ®istry_tests_nested, }; - + registry_storage_save(&storage_test_instance, &node); TEST_ASSERT(successful); @@ -200,7 +197,7 @@ static void tests_registry_save_namespace(void) .type = REGISTRY_NODE_NAMESPACE, .value.namespace = ®istry_tests, }; - + registry_storage_save(&storage_test_instance, &node); TEST_ASSERT(successful); @@ -208,7 +205,7 @@ static void tests_registry_save_namespace(void) static void tests_registry_save_all(void) { - + registry_storage_save(&storage_test_instance, NULL); TEST_ASSERT(successful); @@ -238,6 +235,4 @@ void tests_registry_storage(void) TESTS_RUN(tests_registry_storage_tests()); } -#endif - /** @} */ From fd87b09ce2c7ba69105fdf4cac9ded223ccd6de2 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 15:07:48 +0200 Subject: [PATCH 115/117] fixup! tests/unittests: add registry_storage_heap tests Migrate to local test namespace --- tests/unittests/tests-registry_storage_heap/Makefile | 4 +++- .../unittests/tests-registry_storage_heap/Makefile.include | 3 ++- tests/unittests/tests-registry_storage_heap/namespace | 1 + .../tests-registry_storage_heap.c | 6 +++--- 4 files changed, 9 insertions(+), 5 deletions(-) create mode 120000 tests/unittests/tests-registry_storage_heap/namespace diff --git a/tests/unittests/tests-registry_storage_heap/Makefile b/tests/unittests/tests-registry_storage_heap/Makefile index 9c9ae9884ad6..e90483f4f15a 100644 --- a/tests/unittests/tests-registry_storage_heap/Makefile +++ b/tests/unittests/tests-registry_storage_heap/Makefile @@ -1 +1,3 @@ -include $(RIOTBASE)/Makefile.base \ No newline at end of file +DIRS += namespace + +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-registry_storage_heap/Makefile.include b/tests/unittests/tests-registry_storage_heap/Makefile.include index cafcaad6421b..d82a4fa7f631 100644 --- a/tests/unittests/tests-registry_storage_heap/Makefile.include +++ b/tests/unittests/tests-registry_storage_heap/Makefile.include @@ -1,3 +1,4 @@ USEMODULE += registry_storage_heap USEMODULE += registry_int_path -USEMODULE += registry_namespace_tests_nested + +USEMODULE += tests-registry-namespace diff --git a/tests/unittests/tests-registry_storage_heap/namespace b/tests/unittests/tests-registry_storage_heap/namespace new file mode 120000 index 000000000000..6a0bcd8e750e --- /dev/null +++ b/tests/unittests/tests-registry_storage_heap/namespace @@ -0,0 +1 @@ +../tests-registry/namespace \ No newline at end of file diff --git a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c index 2251a06e4157..b48b8935e017 100644 --- a/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c +++ b/tests/unittests/tests-registry_storage_heap/tests-registry_storage_heap.c @@ -29,10 +29,10 @@ #include "registry/storage.h" #include "tests-registry_storage_heap.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/nested.h" +#include "namespace/tests.h" +#include "namespace/tests/nested.h" -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) +#if IS_USED(MODULE_REGISTRY_STORAGE_HEAP) || IS_ACTIVE(DOXYGEN) static registry_tests_nested_instance_t test_nested_instance_data = { .parameter = 9, From d9a7f68896470143cb4ec1f986a37272ded435a4 Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 15:08:03 +0200 Subject: [PATCH 116/117] fixup! tests/unittests: add registry_storage_vfs tests Migrate to local test namespace --- tests/unittests/tests-registry_storage_vfs/Makefile | 4 +++- tests/unittests/tests-registry_storage_vfs/Makefile.include | 3 ++- tests/unittests/tests-registry_storage_vfs/namespace | 1 + .../tests-registry_storage_vfs/tests-registry_storage_vfs.c | 6 +++--- 4 files changed, 9 insertions(+), 5 deletions(-) create mode 120000 tests/unittests/tests-registry_storage_vfs/namespace diff --git a/tests/unittests/tests-registry_storage_vfs/Makefile b/tests/unittests/tests-registry_storage_vfs/Makefile index 9c9ae9884ad6..e90483f4f15a 100644 --- a/tests/unittests/tests-registry_storage_vfs/Makefile +++ b/tests/unittests/tests-registry_storage_vfs/Makefile @@ -1 +1,3 @@ -include $(RIOTBASE)/Makefile.base \ No newline at end of file +DIRS += namespace + +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-registry_storage_vfs/Makefile.include b/tests/unittests/tests-registry_storage_vfs/Makefile.include index 247d9a98c5ff..838a823cc5c1 100644 --- a/tests/unittests/tests-registry_storage_vfs/Makefile.include +++ b/tests/unittests/tests-registry_storage_vfs/Makefile.include @@ -6,4 +6,5 @@ USEMODULE += vfs USEMODULE += registry_storage_vfs USEMODULE += registry_int_path -USEMODULE += registry_namespace_tests_nested + +USEMODULE += tests-registry-namespace diff --git a/tests/unittests/tests-registry_storage_vfs/namespace b/tests/unittests/tests-registry_storage_vfs/namespace new file mode 120000 index 000000000000..6a0bcd8e750e --- /dev/null +++ b/tests/unittests/tests-registry_storage_vfs/namespace @@ -0,0 +1 @@ +../tests-registry/namespace \ No newline at end of file diff --git a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c index cb8e4acc97c0..978d49c75700 100644 --- a/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c +++ b/tests/unittests/tests-registry_storage_vfs/tests-registry_storage_vfs.c @@ -33,10 +33,10 @@ #include "registry/storage.h" #include "tests-registry_storage_vfs.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/nested.h" +#include "namespace/tests.h" +#include "namespace/tests/nested.h" -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) +#if IS_USED(MODULE_REGISTRY_STORAGE_VFS) || IS_ACTIVE(DOXYGEN) static registry_tests_nested_instance_t test_nested_instance_data = { .parameter = 9, From f68fbb1241aa83fe2407207acdfd0132bd88e27f Mon Sep 17 00:00:00 2001 From: Lasse Rosenow Date: Tue, 7 May 2024 15:08:26 +0200 Subject: [PATCH 117/117] fixup! tests/unittests: add registry_string_path tests Migrate to local test namespace --- tests/unittests/tests-registry_string_path/Makefile | 4 +++- .../tests-registry_string_path/Makefile.include | 3 ++- tests/unittests/tests-registry_string_path/namespace | 1 + .../tests-registry_string_path.c | 11 ++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) create mode 120000 tests/unittests/tests-registry_string_path/namespace diff --git a/tests/unittests/tests-registry_string_path/Makefile b/tests/unittests/tests-registry_string_path/Makefile index 9c9ae9884ad6..e90483f4f15a 100644 --- a/tests/unittests/tests-registry_string_path/Makefile +++ b/tests/unittests/tests-registry_string_path/Makefile @@ -1 +1,3 @@ -include $(RIOTBASE)/Makefile.base \ No newline at end of file +DIRS += namespace + +include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-registry_string_path/Makefile.include b/tests/unittests/tests-registry_string_path/Makefile.include index d81d6741258c..385bacd9e2ea 100644 --- a/tests/unittests/tests-registry_string_path/Makefile.include +++ b/tests/unittests/tests-registry_string_path/Makefile.include @@ -1,2 +1,3 @@ USEMODULE += registry_string_path -USEMODULE += registry_namespace_tests_nested + +USEMODULE += tests-registry-namespace diff --git a/tests/unittests/tests-registry_string_path/namespace b/tests/unittests/tests-registry_string_path/namespace new file mode 120000 index 000000000000..6a0bcd8e750e --- /dev/null +++ b/tests/unittests/tests-registry_string_path/namespace @@ -0,0 +1 @@ +../tests-registry/namespace \ No newline at end of file diff --git a/tests/unittests/tests-registry_string_path/tests-registry_string_path.c b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c index 06249274a44f..f1110e4c3ffd 100644 --- a/tests/unittests/tests-registry_string_path/tests-registry_string_path.c +++ b/tests/unittests/tests-registry_string_path/tests-registry_string_path.c @@ -34,10 +34,10 @@ #include "mtd.h" #include "registry.h" #include "registry/string_path.h" -#include "registry/namespace/tests.h" -#include "registry/namespace/tests/nested.h" +#include "namespace/tests.h" +#include "namespace/tests/nested.h" -#if IS_USED(MODULE_REGISTRY_NAMESPACE_TESTS_NESTED) || IS_ACTIVE(DOXYGEN) +#if IS_ACTIVE(CONFIG_REGISTRY_ENABLE_META_NAME) || IS_ACTIVE(DOXYGEN) static registry_tests_nested_instance_t test_instance_data = { .parameter = 9, @@ -147,6 +147,7 @@ static void tests_registry_from_parameter_string_path(void) registry_node_t node; const char *str[] = { "tests", "nested", "instance-1", "group", "parameter" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_PARAMETER, node.type); @@ -161,6 +162,7 @@ static void tests_registry_from_group_string_path(void) registry_node_t node; const char *str[] = { "tests", "nested", "instance-1", "group" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_GROUP, node.type); @@ -175,6 +177,7 @@ static void tests_registry_from_instance_string_path(void) registry_node_t node; const char *str[] = { "tests", "nested", "instance-1" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_INSTANCE, node.type); @@ -188,6 +191,7 @@ static void tests_registry_from_schema_string_path(void) registry_node_t node; const char *str[] = { "tests", "nested" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_SCHEMA, node.type); @@ -200,6 +204,7 @@ static void tests_registry_from_namespace_string_path(void) registry_node_t node; const char *str[] = { "tests" }; + registry_node_from_string_path(str, ARRAY_SIZE(str), &node); TEST_ASSERT_EQUAL_INT(REGISTRY_NODE_NAMESPACE, node.type);