1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018, Olivier MATZ <zer0@droids-corp.org>
11 #include <ecoli_string.h>
12 #include <ecoli_malloc.h>
13 #include <ecoli_keyval.h>
14 #include <ecoli_node.h>
15 #include <ecoli_log.h>
16 #include <ecoli_test.h>
17 #include <ecoli_config.h>
19 EC_LOG_TYPE_REGISTER(config);
21 const char *ec_config_reserved_keys[] = {
29 __ec_config_dump(FILE *out, const char *key, const struct ec_config *config,
32 ec_config_dict_validate(const struct ec_keyval *dict,
33 const struct ec_config_schema *schema);
36 ec_config_key_is_reserved(const char *name)
40 for (i = 0; i < EC_COUNT_OF(ec_config_reserved_keys); i++) {
41 if (!strcmp(name, ec_config_reserved_keys[i]))
47 /* return ec_value type as a string */
49 ec_config_type_str(enum ec_config_type type)
52 case EC_CONFIG_TYPE_BOOL: return "bool";
53 case EC_CONFIG_TYPE_INT64: return "int64";
54 case EC_CONFIG_TYPE_UINT64: return "uint64";
55 case EC_CONFIG_TYPE_STRING: return "string";
56 case EC_CONFIG_TYPE_NODE: return "node";
57 case EC_CONFIG_TYPE_LIST: return "list";
58 case EC_CONFIG_TYPE_DICT: return "dict";
59 default: return "unknown";
64 ec_config_schema_len(const struct ec_config_schema *schema)
70 for (i = 0; schema[i].type != EC_CONFIG_TYPE_NONE; i++)
76 __ec_config_schema_validate(const struct ec_config_schema *schema,
77 enum ec_config_type type)
82 if (type == EC_CONFIG_TYPE_LIST) {
83 if (schema[0].key != NULL) {
85 EC_LOG(EC_LOG_ERR, "list schema key must be NULL\n");
88 } else if (type == EC_CONFIG_TYPE_DICT) {
89 for (i = 0; schema[i].type != EC_CONFIG_TYPE_NONE; i++) {
90 if (schema[i].key == NULL) {
93 "dict schema key should not be NULL\n");
99 EC_LOG(EC_LOG_ERR, "invalid schema type\n");
103 for (i = 0; schema[i].type != EC_CONFIG_TYPE_NONE; i++) {
104 if (schema[i].key != NULL &&
105 ec_config_key_is_reserved(schema[i].key)) {
108 "key name <%s> is reserved\n", schema[i].key);
111 /* check for duplicate name if more than one element */
112 for (j = i + 1; schema[j].type != EC_CONFIG_TYPE_NONE; j++) {
113 if (!strcmp(schema[i].key, schema[j].key)) {
116 "duplicate key <%s> in schema\n",
122 switch (schema[i].type) {
123 case EC_CONFIG_TYPE_BOOL:
124 case EC_CONFIG_TYPE_INT64:
125 case EC_CONFIG_TYPE_UINT64:
126 case EC_CONFIG_TYPE_STRING:
127 case EC_CONFIG_TYPE_NODE:
128 if (schema[i].subschema != NULL || ec_config_schema_len(
129 schema[i].subschema) != 0) {
132 "key <%s> should not have subtype/subschema\n",
137 case EC_CONFIG_TYPE_LIST:
138 if (schema[i].subschema == NULL || ec_config_schema_len(
139 schema[i].subschema) != 1) {
142 "key <%s> must have subschema of length 1\n",
147 case EC_CONFIG_TYPE_DICT:
148 if (schema[i].subschema == NULL || ec_config_schema_len(
149 schema[i].subschema) == 0) {
152 "key <%s> must have subschema\n",
158 EC_LOG(EC_LOG_ERR, "invalid type for key <%s>\n",
164 if (schema[i].subschema == NULL)
167 ret = __ec_config_schema_validate(schema[i].subschema,
170 EC_LOG(EC_LOG_ERR, "cannot parse subschema %s%s\n",
171 schema[i].key ? "key=" : "",
172 schema[i].key ? : "");
181 ec_config_schema_validate(const struct ec_config_schema *schema)
183 return __ec_config_schema_validate(schema, EC_CONFIG_TYPE_DICT);
187 __ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema,
192 for (i = 0; schema[i].type != EC_CONFIG_TYPE_NONE; i++) {
193 fprintf(out, "%*s" "%s%s%stype=%s desc='%s'\n",
195 schema[i].key ? "key=": "",
196 schema[i].key ? : "",
197 schema[i].key ? " ": "",
198 ec_config_type_str(schema[i].type),
200 if (schema[i].subschema == NULL)
202 __ec_config_schema_dump(out, schema[i].subschema,
208 ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema)
210 fprintf(out, "------------------- schema dump:\n");
212 if (schema == NULL) {
213 fprintf(out, "no schema\n");
217 __ec_config_schema_dump(out, schema, 0);
220 enum ec_config_type ec_config_get_type(const struct ec_config *config)
226 ec_config_bool(bool boolean)
228 struct ec_config *value = NULL;
230 value = ec_calloc(1, sizeof(*value));
234 value->type = EC_CONFIG_TYPE_BOOL;
235 value->boolean = boolean;
241 ec_config_i64(int64_t i64)
243 struct ec_config *value = NULL;
245 value = ec_calloc(1, sizeof(*value));
249 value->type = EC_CONFIG_TYPE_INT64;
256 ec_config_u64(uint64_t u64)
258 struct ec_config *value = NULL;
260 value = ec_calloc(1, sizeof(*value));
264 value->type = EC_CONFIG_TYPE_UINT64;
270 /* duplicate string */
272 ec_config_string(const char *string)
274 struct ec_config *value = NULL;
280 s = ec_strdup(string);
284 value = ec_calloc(1, sizeof(*value));
288 value->type = EC_CONFIG_TYPE_STRING;
299 /* "consume" the node */
301 ec_config_node(struct ec_node *node)
303 struct ec_config *value = NULL;
308 value = ec_calloc(1, sizeof(*value));
312 value->type = EC_CONFIG_TYPE_NODE;
326 struct ec_config *value = NULL;
327 struct ec_keyval *dict = NULL;
333 value = ec_calloc(1, sizeof(*value));
337 value->type = EC_CONFIG_TYPE_DICT;
343 ec_keyval_free(dict);
351 struct ec_config *value = NULL;
353 value = ec_calloc(1, sizeof(*value));
357 value->type = EC_CONFIG_TYPE_LIST;
358 TAILQ_INIT(&value->list);
363 ssize_t ec_config_count(const struct ec_config *config)
365 const struct ec_config *child;
368 switch (config->type) {
369 case EC_CONFIG_TYPE_LIST:
371 TAILQ_FOREACH(child, &config->list, next)
374 case EC_CONFIG_TYPE_DICT:
382 const struct ec_config_schema *
383 ec_config_schema_lookup(const struct ec_config_schema *schema,
388 for (i = 0; schema[i].type != EC_CONFIG_TYPE_NONE; i++) {
389 if (!strcmp(key, schema[i].key))
398 ec_config_schema_type(const struct ec_config_schema *schema_elt)
400 return schema_elt->type;
403 const struct ec_config_schema *
404 ec_config_schema_sub(const struct ec_config_schema *schema_elt)
406 return schema_elt->subschema;
410 ec_config_free(struct ec_config *value)
415 switch (value->type) {
416 case EC_CONFIG_TYPE_STRING:
417 ec_free(value->string);
419 case EC_CONFIG_TYPE_NODE:
420 ec_node_free(value->node);
422 case EC_CONFIG_TYPE_LIST:
423 while (!TAILQ_EMPTY(&value->list)) {
425 v = TAILQ_FIRST(&value->list);
426 TAILQ_REMOVE(&value->list, v, next);
430 case EC_CONFIG_TYPE_DICT:
431 ec_keyval_free(value->dict);
441 ec_config_list_cmp(const struct ec_config_list *list1,
442 const struct ec_config_list *list2)
444 const struct ec_config *v1, *v2;
446 for (v1 = TAILQ_FIRST(list1), v2 = TAILQ_FIRST(list2);
447 v1 != NULL && v2 != NULL;
448 v1 = TAILQ_NEXT(v1, next), v2 = TAILQ_NEXT(v2, next)) {
449 if (ec_config_cmp(v1, v2))
452 if (v1 != NULL || v2 != NULL)
458 /* XXX -> ec_keyval_cmp() */
460 ec_config_dict_cmp(const struct ec_keyval *d1,
461 const struct ec_keyval *d2)
463 const struct ec_config *v1, *v2;
464 struct ec_keyval_iter *iter = NULL;
467 if (ec_keyval_len(d1) != ec_keyval_len(d2))
470 for (iter = ec_keyval_iter(d1);
471 ec_keyval_iter_valid(iter);
472 ec_keyval_iter_next(iter)) {
473 key = ec_keyval_iter_get_key(iter);
474 v1 = ec_keyval_iter_get_val(iter);
475 v2 = ec_keyval_get(d2, key);
477 if (ec_config_cmp(v1, v2))
481 ec_keyval_iter_free(iter);
485 ec_keyval_iter_free(iter);
490 ec_config_cmp(const struct ec_config *value1,
491 const struct ec_config *value2)
493 if (value1 == NULL || value2 == NULL) {
498 if (value1->type != value2->type)
501 switch (value1->type) {
502 case EC_CONFIG_TYPE_BOOL:
503 if (value1->boolean == value2->boolean)
505 case EC_CONFIG_TYPE_INT64:
506 if (value1->i64 == value2->i64)
508 case EC_CONFIG_TYPE_UINT64:
509 if (value1->u64 == value2->u64)
511 case EC_CONFIG_TYPE_STRING:
512 if (!strcmp(value1->string, value2->string))
514 case EC_CONFIG_TYPE_NODE:
515 if (value1->node == value2->node)
517 case EC_CONFIG_TYPE_LIST:
518 return ec_config_list_cmp(&value1->list, &value2->list);
519 case EC_CONFIG_TYPE_DICT:
520 return ec_config_dict_cmp(value1->dict, value2->dict);
529 ec_config_list_validate(const struct ec_config_list *list,
530 const struct ec_config_schema *sch)
532 const struct ec_config *value;
534 TAILQ_FOREACH(value, list, next) {
535 if (value->type != sch->type) {
540 if (value->type == EC_CONFIG_TYPE_LIST) {
541 if (ec_config_list_validate(&value->list,
544 } else if (value->type == EC_CONFIG_TYPE_DICT) {
545 if (ec_config_dict_validate(value->dict,
555 ec_config_dict_validate(const struct ec_keyval *dict,
556 const struct ec_config_schema *schema)
558 const struct ec_config *value;
559 struct ec_keyval_iter *iter = NULL;
560 const struct ec_config_schema *sch;
563 for (iter = ec_keyval_iter(dict);
564 ec_keyval_iter_valid(iter);
565 ec_keyval_iter_next(iter)) {
567 key = ec_keyval_iter_get_key(iter);
568 value = ec_keyval_iter_get_val(iter);
569 sch = ec_config_schema_lookup(schema, key);
570 if (sch == NULL || sch->type != value->type) {
574 if (value->type == EC_CONFIG_TYPE_LIST) {
575 if (ec_config_list_validate(&value->list,
578 } else if (value->type == EC_CONFIG_TYPE_DICT) {
579 if (ec_config_dict_validate(value->dict,
585 ec_keyval_iter_free(iter);
589 ec_keyval_iter_free(iter);
594 ec_config_validate(const struct ec_config *dict,
595 const struct ec_config_schema *schema)
597 if (dict->type != EC_CONFIG_TYPE_DICT || schema == NULL) {
602 if (ec_config_dict_validate(dict->dict, schema) < 0)
612 ec_config_dict_get(const struct ec_config *config, const char *key)
614 if (config == NULL) {
619 if (config->type != EC_CONFIG_TYPE_DICT) {
624 return ec_keyval_get(config->dict, key);
628 ec_config_list_first(struct ec_config *list)
630 if (list == NULL || list->type != EC_CONFIG_TYPE_LIST) {
635 return TAILQ_FIRST(&list->list);
639 ec_config_list_next(struct ec_config *list, struct ec_config *config)
642 return TAILQ_NEXT(config, next);
645 /* value is consumed */
646 int ec_config_dict_set(struct ec_config *config, const char *key,
647 struct ec_config *value)
649 void (*free_cb)(struct ec_config *) = ec_config_free;
651 if (config == NULL || key == NULL || value == NULL) {
655 if (config->type != EC_CONFIG_TYPE_DICT) {
660 return ec_keyval_set(config->dict, key, value,
661 (void (*)(void *))free_cb);
664 ec_config_free(value);
668 int ec_config_dict_del(struct ec_config *config, const char *key)
670 if (config == NULL || key == NULL) {
674 if (config->type != EC_CONFIG_TYPE_DICT) {
679 return ec_keyval_del(config->dict, key);
682 /* value is consumed */
684 ec_config_list_add(struct ec_config *list,
685 struct ec_config *value)
687 if (list == NULL || list->type != EC_CONFIG_TYPE_LIST || value == NULL) {
692 TAILQ_INSERT_TAIL(&list->list, value, next);
697 ec_config_free(value);
701 int ec_config_list_del(struct ec_config *list, struct ec_config *config)
703 if (list == NULL || list->type != EC_CONFIG_TYPE_LIST) {
708 TAILQ_REMOVE(&list->list, config, next);
709 ec_config_free(config);
713 static struct ec_config *
714 ec_config_list_dup(const struct ec_config_list *list)
716 struct ec_config *dup = NULL, *v, *value;
718 dup = ec_config_list();
722 TAILQ_FOREACH(v, list, next) {
723 value = ec_config_dup(v);
726 if (ec_config_list_add(dup, value) < 0)
737 static struct ec_config *
738 ec_config_dict_dup(const struct ec_keyval *dict)
740 struct ec_config *dup = NULL, *value;
741 struct ec_keyval_iter *iter = NULL;
744 dup = ec_config_dict();
748 for (iter = ec_keyval_iter(dict);
749 ec_keyval_iter_valid(iter);
750 ec_keyval_iter_next(iter)) {
751 key = ec_keyval_iter_get_key(iter);
752 value = ec_config_dup(ec_keyval_iter_get_val(iter));
755 if (ec_config_dict_set(dup, key, value) < 0)
758 ec_keyval_iter_free(iter);
764 ec_keyval_iter_free(iter);
769 ec_config_dup(const struct ec_config *config)
771 if (config == NULL) {
776 switch (config->type) {
777 case EC_CONFIG_TYPE_BOOL:
778 return ec_config_bool(config->boolean);
779 case EC_CONFIG_TYPE_INT64:
780 return ec_config_i64(config->i64);
781 case EC_CONFIG_TYPE_UINT64:
782 return ec_config_u64(config->u64);
783 case EC_CONFIG_TYPE_STRING:
784 return ec_config_string(config->string);
785 case EC_CONFIG_TYPE_NODE:
786 return ec_config_node(ec_node_clone(config->node));
787 case EC_CONFIG_TYPE_LIST:
788 return ec_config_list_dup(&config->list);
789 case EC_CONFIG_TYPE_DICT:
790 return ec_config_dict_dup(config->dict);
800 ec_config_list_dump(FILE *out, const char *key,
801 const struct ec_config_list *list, size_t indent)
803 const struct ec_config *v;
805 fprintf(out, "%*s" "%s%s%stype=list\n", (int)indent * 4, "",
810 TAILQ_FOREACH(v, list, next) {
811 if (__ec_config_dump(out, NULL, v, indent + 1) < 0)
819 ec_config_dict_dump(FILE *out, const char *key, const struct ec_keyval *dict,
822 const struct ec_config *value;
823 struct ec_keyval_iter *iter;
826 fprintf(out, "%*s" "%s%s%stype=dict\n", (int)indent * 4, "",
831 for (iter = ec_keyval_iter(dict);
832 ec_keyval_iter_valid(iter);
833 ec_keyval_iter_next(iter)) {
834 k = ec_keyval_iter_get_key(iter);
835 value = ec_keyval_iter_get_val(iter);
836 if (__ec_config_dump(out, k, value, indent + 1) < 0)
839 ec_keyval_iter_free(iter);
843 ec_keyval_iter_free(iter);
848 __ec_config_dump(FILE *out, const char *key, const struct ec_config *value,
851 char *val_str = NULL;
853 switch (value->type) {
854 case EC_CONFIG_TYPE_BOOL:
856 ec_asprintf(&val_str, "true");
858 ec_asprintf(&val_str, "false");
860 case EC_CONFIG_TYPE_INT64:
861 ec_asprintf(&val_str, "%"PRIu64, value->u64);
863 case EC_CONFIG_TYPE_UINT64:
864 ec_asprintf(&val_str, "%"PRIi64, value->i64);
866 case EC_CONFIG_TYPE_STRING:
867 ec_asprintf(&val_str, "%s", value->string);
869 case EC_CONFIG_TYPE_NODE:
870 ec_asprintf(&val_str, "%p", value->node);
872 case EC_CONFIG_TYPE_LIST:
873 return ec_config_list_dump(out, key, &value->list, indent);
874 case EC_CONFIG_TYPE_DICT:
875 return ec_config_dict_dump(out, key, value->dict, indent);
881 /* errno is already set on error */
885 fprintf(out, "%*s" "%s%s%stype=%s val=%s\n", (int)indent * 4, "",
889 ec_config_type_str(value->type), val_str);
900 ec_config_dump(FILE *out, const struct ec_config *config)
902 fprintf(out, "------------------- config dump:\n");
904 if (config == NULL) {
905 fprintf(out, "no config\n");
909 if (__ec_config_dump(out, NULL, config, 0) < 0)
910 fprintf(out, "error while dumping\n");
913 /* LCOV_EXCL_START */
914 static const struct ec_config_schema sch_intlist_elt[] = {
916 .desc = "This is a description for int",
917 .type = EC_CONFIG_TYPE_INT64,
920 .type = EC_CONFIG_TYPE_NONE,
924 static const struct ec_config_schema sch_dict[] = {
927 .desc = "This is a description for int",
928 .type = EC_CONFIG_TYPE_INT64,
932 .desc = "This is a description for int2",
933 .type = EC_CONFIG_TYPE_INT64,
936 .type = EC_CONFIG_TYPE_NONE,
940 static const struct ec_config_schema sch_dictlist_elt[] = {
942 .desc = "This is a description for dict",
943 .type = EC_CONFIG_TYPE_DICT,
944 .subschema = sch_dict,
947 .type = EC_CONFIG_TYPE_NONE,
951 static const struct ec_config_schema sch_baseconfig[] = {
954 .desc = "This is a description for bool",
955 .type = EC_CONFIG_TYPE_BOOL,
959 .desc = "This is a description for int",
960 .type = EC_CONFIG_TYPE_INT64,
964 .desc = "This is a description for string",
965 .type = EC_CONFIG_TYPE_STRING,
969 .desc = "This is a description for node",
970 .type = EC_CONFIG_TYPE_NODE,
974 .desc = "This is a description for list",
975 .type = EC_CONFIG_TYPE_LIST,
976 .subschema = sch_intlist_elt,
979 .key = "my_dictlist",
980 .desc = "This is a description for list",
981 .type = EC_CONFIG_TYPE_LIST,
982 .subschema = sch_dictlist_elt,
985 .type = EC_CONFIG_TYPE_NONE,
989 static int ec_config_testcase(void)
991 struct ec_node *node = NULL;
992 struct ec_keyval *dict = NULL;
993 const struct ec_config *value = NULL;
994 struct ec_config *config = NULL, *config2 = NULL;
995 struct ec_config *list = NULL, *subconfig = NULL;
996 struct ec_config *list_, *config_;
1000 testres |= EC_TEST_CHECK(ec_config_key_is_reserved("id"),
1001 "'id' should be reserved");
1002 testres |= EC_TEST_CHECK(!ec_config_key_is_reserved("foo"),
1003 "'foo' should not be reserved");
1005 node = ec_node("empty", EC_NO_ID);
1009 if (ec_config_schema_validate(sch_baseconfig) < 0) {
1010 EC_LOG(EC_LOG_ERR, "invalid config schema\n");
1014 ec_config_schema_dump(stdout, sch_baseconfig);
1016 config = ec_config_dict();
1020 ret = ec_config_dict_set(config, "my_bool", ec_config_bool(true));
1021 testres |= EC_TEST_CHECK(ret == 0, "cannot set boolean");
1022 value = ec_config_dict_get(config, "my_bool");
1023 testres |= EC_TEST_CHECK(
1025 value->type == EC_CONFIG_TYPE_BOOL &&
1026 value->boolean == true,
1027 "unexpected boolean value");
1029 ret = ec_config_dict_set(config, "my_int", ec_config_i64(1234));
1030 testres |= EC_TEST_CHECK(ret == 0, "cannot set int");
1031 value = ec_config_dict_get(config, "my_int");
1032 testres |= EC_TEST_CHECK(
1034 value->type == EC_CONFIG_TYPE_INT64 &&
1036 "unexpected int value");
1038 testres |= EC_TEST_CHECK(
1039 ec_config_validate(config, sch_baseconfig) == 0,
1040 "cannot validate config\n");
1042 ret = ec_config_dict_set(config, "my_string", ec_config_string("toto"));
1043 testres |= EC_TEST_CHECK(ret == 0, "cannot set string");
1044 value = ec_config_dict_get(config, "my_string");
1045 testres |= EC_TEST_CHECK(
1047 value->type == EC_CONFIG_TYPE_STRING &&
1048 !strcmp(value->string, "toto"),
1049 "unexpected string value");
1051 list = ec_config_list();
1055 subconfig = ec_config_dict();
1056 if (subconfig == NULL)
1059 ret = ec_config_dict_set(subconfig, "my_int", ec_config_i64(1));
1060 testres |= EC_TEST_CHECK(ret == 0, "cannot set int");
1061 value = ec_config_dict_get(subconfig, "my_int");
1062 testres |= EC_TEST_CHECK(
1064 value->type == EC_CONFIG_TYPE_INT64 &&
1066 "unexpected int value");
1068 ret = ec_config_dict_set(subconfig, "my_int2", ec_config_i64(2));
1069 testres |= EC_TEST_CHECK(ret == 0, "cannot set int");
1070 value = ec_config_dict_get(subconfig, "my_int2");
1071 testres |= EC_TEST_CHECK(
1073 value->type == EC_CONFIG_TYPE_INT64 &&
1075 "unexpected int value");
1077 testres |= EC_TEST_CHECK(
1078 ec_config_validate(subconfig, sch_dict) == 0,
1079 "cannot validate subconfig\n");
1081 ret = ec_config_list_add(list, subconfig);
1082 subconfig = NULL; /* freed */
1083 testres |= EC_TEST_CHECK(ret == 0, "cannot add in list");
1085 subconfig = ec_config_dict();
1086 if (subconfig == NULL)
1089 ret = ec_config_dict_set(subconfig, "my_int", ec_config_i64(3));
1090 testres |= EC_TEST_CHECK(ret == 0, "cannot set int");
1091 value = ec_config_dict_get(subconfig, "my_int");
1092 testres |= EC_TEST_CHECK(
1094 value->type == EC_CONFIG_TYPE_INT64 &&
1096 "unexpected int value");
1098 ret = ec_config_dict_set(subconfig, "my_int2", ec_config_i64(4));
1099 testres |= EC_TEST_CHECK(ret == 0, "cannot set int");
1100 value = ec_config_dict_get(subconfig, "my_int2");
1101 testres |= EC_TEST_CHECK(
1103 value->type == EC_CONFIG_TYPE_INT64 &&
1105 "unexpected int value");
1107 testres |= EC_TEST_CHECK(
1108 ec_config_validate(subconfig, sch_dict) == 0,
1109 "cannot validate subconfig\n");
1111 ret = ec_config_list_add(list, subconfig);
1112 subconfig = NULL; /* freed */
1113 testres |= EC_TEST_CHECK(ret == 0, "cannot add in list");
1115 ret = ec_config_dict_set(config, "my_dictlist", list);
1117 testres |= EC_TEST_CHECK(ret == 0, "cannot set list");
1119 testres |= EC_TEST_CHECK(
1120 ec_config_validate(config, sch_baseconfig) == 0,
1121 "cannot validate config\n");
1123 list_ = ec_config_dict_get(config, "my_dictlist");
1124 for (config_ = ec_config_list_first(list_); config_ != NULL;
1125 config_ = ec_config_list_next(list_, config_)) {
1126 ec_config_dump(stdout, config_);
1129 ec_config_dump(stdout, config);
1131 config2 = ec_config_dup(config);
1132 testres |= EC_TEST_CHECK(config2 != NULL, "cannot duplicate config");
1133 testres |= EC_TEST_CHECK(
1134 ec_config_cmp(config, config2) == 0,
1135 "fail to compare config");
1136 ec_config_free(config2);
1139 /* remove the first element */
1140 ec_config_list_del(list_, ec_config_list_first(list_));
1141 testres |= EC_TEST_CHECK(
1142 ec_config_validate(config, sch_baseconfig) == 0,
1143 "cannot validate config\n");
1145 ec_config_dump(stdout, config);
1147 ec_config_free(list);
1148 ec_config_free(subconfig);
1149 ec_config_free(config);
1150 ec_keyval_free(dict);
1156 ec_config_free(list);
1157 ec_config_free(subconfig);
1158 ec_config_free(config);
1159 ec_config_free(config2);
1160 ec_keyval_free(dict);
1165 /* LCOV_EXCL_STOP */
1167 static struct ec_test ec_config_test = {
1169 .test = ec_config_testcase,
1172 EC_TEST_REGISTER(ec_config_test);