Skip to content

Commit de6e864

Browse files
committed
schema cmp UPDATE latest schema-comparison changes
1 parent 4ffda1b commit de6e864

5 files changed

Lines changed: 140 additions & 22 deletions

File tree

‎modules/ietf-yang-schema-comparison-output@2026-09-02.yang‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module ietf-yang-schema-comparison-output {
2121
import ietf-yang-semver {
2222
prefix ysv;
2323
reference
24-
"RFC XXXX: YANG Semantic Versioning";
24+
"RFC YYYY: YANG Semantic Versioning";
2525
}
2626

2727
organization

‎modules/ietf-yang-schema-comparison@2026-09-02.yang‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,56 +57,62 @@ module ietf-yang-schema-comparison {
5757
extension ed-change-at {
5858
argument semver;
5959
description
60-
"Marks statements in a new revision of a module
60+
"Marks statements in the specified version of a module
6161
that introduces an editorial change of the statement.
6262
63-
The argument marks the most recent version of the
64-
module where the statement has been changed.
63+
This extension may appear multiple times in a single
64+
statement and can also be combined with the other
65+
extensions in this module but each MUST always have
66+
a unique semver argument.
6567
6668
Can only be a substatement of 'pattern', 'when',
6769
'must', 'description', 'reference', 'presence', or
6870
extension instance statements.";
6971
reference
70-
"RFC 7950: The YANG 1.1 Data Modeling Language, section 11;
71-
RFC 6020: YANG - A Data Modeling Language for the Network
72-
Configuration Protocol (NETCONF), section 10";
72+
"RFC YYYY: YANG Semantic Versioning, section 4.4.";
7373
}
7474

7575
extension bc-change-at {
7676
argument semver;
7777
description
78-
"Marks statements in a new revision of a module
78+
"Marks statements in the specified version of a module
7979
that introduces a backwards-compatible change of
8080
the statement.
8181
82-
The argument marks the most recent version of the
83-
module where the statement has been changed.
82+
This extension may appear multiple times in a single
83+
statement and can also be combined with the other
84+
extensions in this module but each MUST always have
85+
a unique semver argument.
8486
8587
Can only be a substatement of 'pattern', 'when',
8688
'must', 'description', 'reference', 'presence', or
8789
extension instance statements.";
8890
reference
89-
"RFC 7950: The YANG 1.1 Data Modeling Language, section 11;
91+
"RFC 7950: The YANG 1.1 Data Modeling Language, section 11.;
9092
RFC 6020: YANG - A Data Modeling Language for the Network
91-
Configuration Protocol (NETCONF), section 10";
93+
Configuration Protocol (NETCONF), section 10.;
94+
RFC ZZZZ: Updated YANG Module Revision Handling, section 3.1.1.";
9295
}
9396

9497
extension nbc-change-at {
9598
argument semver;
9699
description
97-
"Marks statements in a new revision of a module
100+
"Marks statements in the specified version of a module
98101
that introduces a non-backwards-compatible change of
99102
the statement.
100103
101-
The argument marks the most recent version of the
102-
module where the statement has been changed.
104+
This extension may appear multiple times in a single
105+
statement and can also be combined with the other
106+
extensions in this module but each MUST always have
107+
a unique semver argument.
103108
104109
Can only be a substatement of 'pattern', 'when',
105110
'must', 'description', 'reference', 'presence', or
106111
extension instance statements.";
107112
reference
108-
"RFC 7950: The YANG 1.1 Data Modeling Language, section 11;
113+
"RFC 7950: The YANG 1.1 Data Modeling Language, section 11.;
109114
RFC 6020: YANG - A Data Modeling Language for the Network
110-
Configuration Protocol (NETCONF), section 10";
115+
Configuration Protocol (NETCONF), section 10.;
116+
RFC ZZZZ: Updated YANG Module Revision Handling, section 3.1.2.";
111117
}
112118
}

‎src/plugins_exts/schema_comparison.c‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "ly_array.h"
2121
#include "parser_internal.h"
2222
#include "plugins_exts.h"
23+
#include "plugins_internal.h"
24+
#include "tree_schema_internal.h"
2325

2426
/**
2527
* @brief Parse backwards-compatible extension instances.
@@ -29,16 +31,53 @@
2931
static LY_ERR
3032
schema_cmp_change_at_parse(struct lysp_ctx *pctx, struct lysp_ext_instance *ext)
3133
{
34+
const struct lysp_ext_instance *exts = NULL;
35+
LYA_COUNT_T u;
36+
struct lyplg_ext *ext_plugin, *parent_ext_plugin;
37+
3238
/* check that the extension is instantiated at an allowed place */
33-
if ((ext->parent_stmt != LY_STMT_PATTERN) && (ext->parent_stmt != LY_STMT_WHEN) &&
34-
(ext->parent_stmt != LY_STMT_MUST) && (ext->parent_stmt != LY_STMT_DESCRIPTION) &&
35-
(ext->parent_stmt != LY_STMT_REFERENCE) && (ext->parent_stmt != LY_STMT_PRESENCE) &&
36-
(ext->parent_stmt != LY_STMT_EXTENSION_INSTANCE)) {
39+
switch (ext->parent_stmt) {
40+
case LY_STMT_PATTERN:
41+
case LY_STMT_MUST:
42+
exts = ((struct lysp_restr *)ext->parent)->exts;
43+
break;
44+
case LY_STMT_WHEN:
45+
exts = ((struct lysp_when *)ext->parent)->exts;
46+
break;
47+
case LY_STMT_DESCRIPTION:
48+
case LY_STMT_REFERENCE:
49+
case LY_STMT_PRESENCE:
50+
/* meh */
51+
break;
52+
case LY_STMT_EXTENSION_INSTANCE:
53+
exts = ((struct lysp_ext_instance *)ext->parent)->exts;
54+
break;
55+
default:
3756
lyplg_ext_parse_log(pctx, ext, LY_LLWRN, 0, "Extension %s is not allowed in a \"%s\" statement.", ext->name,
3857
lyplg_ext_stmt2str(ext->parent_stmt));
3958
return LY_ENOT;
4059
}
4160

61+
/* check argument */
62+
if (lyplg_ext_semver_parse(PARSER_CTX(pctx), ext->argument, 0, 0, NULL)) {
63+
lyplg_ext_parse_log(pctx, ext, LY_LLERR, LY_EVALID, "Extension %s argument semver \"%s\" invalid.", ext->name,
64+
ext->argument);
65+
return LY_EVALID;
66+
}
67+
68+
ext_plugin = LYSC_GET_EXT_PLG(ext->plugin_ref);
69+
70+
/* check for duplication */
71+
LYA_FOR(exts, u) {
72+
parent_ext_plugin = LYSC_GET_EXT_PLG(exts[u].plugin_ref);
73+
if ((&exts[u] != ext) && parent_ext_plugin && !strcmp(parent_ext_plugin->id, ext_plugin->id) &&
74+
!strcmp(exts[u].argument, ext->argument)) {
75+
lyplg_ext_parse_log(pctx, ext, LY_LLERR, LY_EVALID, "Extension %s semver \"%s\" is a duplicate of %s semver \"%s\".",
76+
ext->name, ext->argument, exts[u].name, exts[u].argument);
77+
return LY_EVALID;
78+
}
79+
}
80+
4281
return LY_SUCCESS;
4382
}
4483

‎tests/utests/CMakeLists.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,6 @@ if(LY_HAVE_REGEX_H)
8787
endif()
8888
ly_add_utest(NAME revisions SOURCES extensions/test_revisions.c)
8989
ly_add_utest(NAME semver SOURCES extensions/test_semver.c)
90+
ly_add_utest(NAME schema_comparison SOURCES extensions/test_schema_comparison.c)
9091

91-
ly_add_utest(NAME schema_comparison SOURCES schema_comparison/test_schema_comparison.c)
92+
ly_add_utest(NAME schema_comparison_output SOURCES schema_comparison/test_schema_comparison.c)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @file test_schema_comparison.c
3+
* @author Michal Vasko <mvasko@cesnet.cz>
4+
* @brief unit tests for schema-comparison extensions support
5+
*
6+
* Copyright (c) 2026 CESNET, z.s.p.o.
7+
*
8+
* This source code is licensed under BSD 3-Clause License (the "License").
9+
* You may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*/
14+
#define _UTEST_MAIN_
15+
#include "utests.h"
16+
17+
#include "libyang.h"
18+
19+
static void
20+
test_change_at(void **state)
21+
{
22+
struct lys_module *mod;
23+
const char *yang;
24+
25+
/* load ietf-yang-schema-comaprison */
26+
assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-yang-schema-comparison", NULL, NULL));
27+
28+
/* valid yang */
29+
yang = "module a {namespace urn:a; prefix a;"
30+
"import ietf-yang-schema-comparison {prefix yscmp;}"
31+
"leaf a {type string {pattern '[a-z]+' {yscmp:bc-change-at 1.1.0;}}}"
32+
"}";
33+
UTEST_ADD_MODULE(yang, LYS_IN_YANG, NULL, &mod);
34+
35+
/* wrong statement */
36+
yang = "module b {namespace urn:b; prefix b;"
37+
"import ietf-yang-schema-comparison {prefix yscmp;}"
38+
"leaf a {type string {yscmp:bc-change-at 1.1.0;}}"
39+
"}";
40+
UTEST_ADD_MODULE(yang, LYS_IN_YANG, NULL, &mod);
41+
CHECK_LOG_CTX("Ext plugin \"ly2 schema-comparison\": Extension yscmp:bc-change-at is not allowed in a \"type\" statement.",
42+
"/b:{type='string'}/{ext-inst='yscmp:bc-change-at'}/1.1.0", 0);
43+
44+
/* duplicate */
45+
yang = "module c {namespace urn:c; prefix c;"
46+
"import ietf-yang-schema-comparison {prefix yscmp;}"
47+
"leaf a {type string {pattern 'a' {yscmp:bc-change-at 1.1.0; yscmp:ed-change-at 1.1.0;}}}"
48+
"}";
49+
UTEST_INVALID_MODULE(yang, LYS_IN_YANG, NULL, LY_EVALID);
50+
CHECK_LOG_CTX("Ext plugin \"ly2 schema-comparison\": Extension yscmp:bc-change-at semver \"1.1.0\" "
51+
"is a duplicate of yscmp:ed-change-at semver \"1.1.0\".",
52+
"/c:{pattern='a'}/{ext-inst='yscmp:bc-change-at'}/1.1.0", 0);
53+
54+
/* invalid argument */
55+
yang = "module c {namespace urn:c; prefix c;"
56+
"import ietf-yang-schema-comparison {prefix yscmp;}"
57+
"leaf a {type string; description \"eh\" {yscmp:bc-change-at 1.1.1a;}}"
58+
"}";
59+
UTEST_INVALID_MODULE(yang, LYS_IN_YANG, NULL, LY_EVALID);
60+
CHECK_LOG_CTX("Ext plugin \"ly2 schema-comparison\": Extension yscmp:bc-change-at argument semver \"1.1.1a\" invalid.",
61+
"/c:{description}/{ext-inst='yscmp:bc-change-at'}/1.1.1a", 0);
62+
}
63+
64+
int
65+
main(void)
66+
{
67+
const struct CMUnitTest tests[] = {
68+
UTEST(test_change_at),
69+
};
70+
71+
return cmocka_run_group_tests(tests, NULL, NULL);
72+
}

0 commit comments

Comments
 (0)