Skip to content

Commit c47eebb

Browse files
committed
add unit test to trigger crash + feature resolve problem with leafref in augments
1 parent b92d68b commit c47eebb

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

tests/schema/test_augment.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,38 @@ test_leafref(void **state)
145145
}
146146
}
147147

148+
static void
149+
test_leafref_w_feature1(void **state)
150+
{
151+
int length;
152+
char *path = *state;
153+
const struct lys_module *module;
154+
155+
ly_ctx_set_searchdir(ctx, path);
156+
length = strlen(path);
157+
strcpy(path + length, "/leafref_w_feature1-mod3.yang");
158+
if (!(module = lys_parse_path(ctx, path, LYS_IN_YANG))) {
159+
fail();
160+
}
161+
lys_print_mem(&yang_modules[YANG_MOD_IDX(0)], module, LYS_OUT_YANG, NULL);
162+
}
163+
164+
static void
165+
test_leafref_w_feature2(void **state)
166+
{
167+
int length;
168+
char *path = *state;
169+
const struct lys_module *module;
170+
171+
ly_ctx_set_searchdir(ctx, path);
172+
length = strlen(path);
173+
strcpy(path + length, "/leafref_w_feature2-mod1.yang");
174+
if (!(module = lys_parse_path(ctx, path, LYS_IN_YANG))) {
175+
fail();
176+
}
177+
lys_print_mem(&yang_modules[YANG_MOD_IDX(0)], module, LYS_OUT_YANG, NULL);
178+
}
179+
148180
static void
149181
test_target_augment(void **state)
150182
{
@@ -291,6 +323,8 @@ main(void)
291323
cmocka_unit_test_setup_teardown(test_target_include_submodule, setup_ctx_yin, teardown_ctx),
292324
cmocka_unit_test_setup_teardown(test_leafref, setup_ctx_yin, teardown_ctx),
293325
cmocka_unit_test_setup_teardown(test_target_augment, setup_ctx_yin, teardown_ctx),
326+
cmocka_unit_test_setup_teardown(test_leafref_w_feature1, setup_ctx_yang, teardown_ctx),
327+
cmocka_unit_test_setup_teardown(test_leafref_w_feature2, setup_ctx_yang, teardown_ctx),
294328
cmocka_unit_test_setup_teardown(test_unres_augment, setup_ctx_yin, teardown_ctx),
295329
cmocka_unit_test_setup_teardown(test_import_augment_target, setup_ctx_yin, teardown_ctx),
296330
cmocka_unit_test_setup_teardown(test_target_include_submodule, setup_ctx_yang, teardown_ctx),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module leafref_w_feature1-mod1 {
2+
3+
namespace "urn:fri:params:xml:ns:yang:leafref_w_feature1-mod1";
4+
prefix lr-w-ftr1-m1;
5+
6+
feature feature1;
7+
8+
container cont1 {
9+
if-feature feature1;
10+
}
11+
}
12+
13+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module leafref_w_feature1-mod2 {
2+
3+
namespace "urn:fri:params:xml:ns:yang:leafref_w_feature1-mod2";
4+
prefix lr-w-ftr1-m2;
5+
6+
import leafref_w_feature1-mod1 {
7+
prefix lr-w-ftr1-m1;
8+
}
9+
10+
typedef list2-ref {
11+
type leafref {
12+
path "/lr-w-ftr1-m1:cont1"
13+
+ "/lr-w-ftr1-m2:cont2"
14+
+ "/lr-w-ftr1-m2:list2"
15+
+ "/lr-w-ftr1-m2:name";
16+
}
17+
}
18+
19+
augment "/lr-w-ftr1-m1:cont1" {
20+
21+
description "mod2's cont1 augment";
22+
23+
container cont2 {
24+
list list2 {
25+
key name;
26+
leaf name {
27+
type string;
28+
}
29+
}
30+
}
31+
}
32+
}
33+
34+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module leafref_w_feature1-mod3 {
2+
3+
namespace "urn:fri:params:xml:ns:yang:leafref_w_feature1-mod3";
4+
prefix lr-w-ftr1-m3;
5+
6+
import leafref_w_feature1-mod1 {
7+
prefix lr-w-ftr1-m1;
8+
}
9+
import leafref_w_feature1-mod2 {
10+
prefix lr-w-ftr1-m2;
11+
}
12+
13+
augment "/lr-w-ftr1-m1:cont1" {
14+
15+
description "mod3's cont1 augment";
16+
17+
container cont3 {
18+
list list3 {
19+
key name;
20+
leaf name {
21+
type string;
22+
}
23+
choice choice3 {
24+
case case3 {
25+
leaf-list llist3 {
26+
type lr-w-ftr1-m2:list2-ref;
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module leafref_w_feature2-mod1 {
2+
3+
namespace "urn:fri:params:xml:ns:yang:leafref_w_feature2-mod1";
4+
prefix lr-w-ftr2-m1;
5+
6+
feature feature2;
7+
8+
container cont1 {
9+
if-feature feature2;
10+
}
11+
12+
augment "/cont1" {
13+
14+
container cont11 {
15+
16+
list list11 {
17+
key name;
18+
19+
leaf name {
20+
type string;
21+
}
22+
}
23+
}
24+
}
25+
26+
augment "/cont1" {
27+
28+
container cont12 {
29+
30+
list list12 {
31+
key name;
32+
33+
leaf name {
34+
type string;
35+
}
36+
37+
leaf-list llist12 {
38+
type leafref {
39+
path "/cont1/cont11/list11/name";
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)