Skip to content

Commit 842f693

Browse files
committed
add some testcases for conformance
1 parent 06f0260 commit 842f693

File tree

12 files changed

+234
-9
lines changed

12 files changed

+234
-9
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set(schema_tests test_ietf test_augment test_deviation test_refine test_typedef
1313
if(CMAKE_BUILD_TYPE MATCHES debug)
1414
list(APPEND schema_tests test_extensions)
1515
endif(CMAKE_BUILD_TYPE MATCHES debug)
16-
set(conformance_tests test_sec6_1_1 test_sec6_2 test_sec5_1 test_sec5_5 test_sec6_1_3 test_sec6_2_1 test_sec7_1 test_sec7_2 test_sec7_3 test_sec7_3_1 test_sec7_3_4 test_sec7_5_2 test_sec7_5_4 test_sec7_5_5 test_sec7_6_2 test_sec7_6_3 test_sec7_6_4 test_sec7_6_5 test_sec7_7_2 test_sec7_7_3 test_sec7_7_4 test_sec7_7_5 test_sec7_8_1 test_sec7_8_2 test_sec7_8_3 test_sec7_9_1 test_sec7_9_2 test_sec7_9_3 test_sec7_9_4 test_sec7_10 test_sec7_11 test_sec7_12_1 test_sec7_12_2 test_sec7_13_1 test_sec7_13_2 test_sec7_13_3 test_sec7_14 test_sec7_15 test_sec7_16_1 test_sec7_16_2 test_sec7_18_1 test_sec7_18_2 test_sec7_18_3_1 test_sec7_18_3_2 test_sec7_19_1 test_sec7_19_2 test_sec7_19_5 test_sec9_2 test_sec9_3 test_sec9_4_4 test_sec9_4_6 test_sec9_5 test_sec9_6 test_sec9_7 test_sec9_8 test_sec9_9 test_sec9_10 test_sec9_11 test_sec9_12 test_sec9_13)
16+
set(conformance_tests test_sec6_1_1 test_sec6_2 test_sec5_1 test_sec5_5 test_sec6_1_3 test_sec6_2_1 test_sec7_1 test_sec7_2 test_sec7_3 test_sec7_3_1 test_sec7_3_4 test_sec7_5_2 test_sec7_5_4 test_sec7_5_5 test_sec7_6_2 test_sec7_6_3 test_sec7_6_4 test_sec7_6_5 test_sec7_7_2 test_sec7_7_3 test_sec7_7_4 test_sec7_7_5 test_sec7_8_1 test_sec7_8_2 test_sec7_8_3 test_sec7_9_1 test_sec7_9_2 test_sec7_9_3 test_sec7_9_4 test_sec7_10 test_sec7_11 test_sec7_12_1 test_sec7_12_2 test_sec7_13_1 test_sec7_13_2 test_sec7_13_3 test_sec7_14 test_sec7_15 test_sec7_15_1 test_sec7_16_1 test_sec7_16_2 test_sec7_18_1 test_sec7_18_2 test_sec7_18_3_1 test_sec7_18_3_2 test_sec7_19_1 test_sec7_19_2 test_sec7_19_5 test_sec9_2 test_sec9_3 test_sec9_4_4 test_sec9_4_6 test_sec9_5 test_sec9_6 test_sec9_7 test_sec9_8 test_sec9_9 test_sec9_10 test_sec9_11 test_sec9_12 test_sec9_13)
1717
set(internal_tests test_lyb test_hash_table test_state_lists)
1818

1919
include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR})

tests/conformance/sec7_1/mod7.yang

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module mod7 {
2+
prefix abc;
3+
namespace "urn:cesnet:mod7";
4+
5+
yang-version 1.5;
6+
}
7+
//yang-version only support 1 or 1.1
8+

tests/conformance/sec7_1/mod8.yang

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module mod8 {
2+
yang-version "1";
3+
namespace "urn:cesnet:mod8";
4+
prefix mmm;
5+
6+
import mod_1 {
7+
prefix m;
8+
revision-date "2019-09-19";
9+
}
10+
//revision-date time not found
11+
}
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module mod1 {
2+
prefix abc;
3+
namespace "urn:cesnet:mod1";
4+
5+
yang-version 1.1;
6+
7+
action act {
8+
reference "test reference";
9+
description "test description";
10+
}
11+
// action not in container or node
12+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module mod2 {
2+
prefix abc;
3+
namespace "urn:cesnet:mod2";
4+
5+
yang-version 1.1;
6+
7+
list aa {
8+
key name;
9+
leaf name {
10+
type string;
11+
}
12+
13+
action act {
14+
reference "test reference";
15+
description "test description";
16+
17+
input {
18+
typedef in {
19+
type string;
20+
}
21+
}
22+
23+
output {
24+
typedef out {
25+
type string;
26+
}
27+
}
28+
29+
}
30+
}
31+
}
32+

tests/conformance/sec7_2/mod7.yang

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
submodule sub7 {
2+
3+
belongs-to mod3 {
4+
prefix aaa;
5+
}
6+
}
7+
//not the main submodule
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module mod9{
2+
prefix abc;
3+
namespace "urn:cesnet:mod9";
4+
5+
typedef uint32 {
6+
type uint32;
7+
default 10;
8+
}
9+
// typedef name duplicates a built-in type
10+
}

tests/conformance/test_sec7_1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
#define TEST_DIR "sec7_1"
2929
#define TEST_NAME test_sec7_1
30-
#define TEST_SCHEMA_COUNT 6
31-
#define TEST_SCHEMA_LOAD_FAIL 1,1,1,1,1,0
30+
#define TEST_SCHEMA_COUNT 8
31+
#define TEST_SCHEMA_LOAD_FAIL 1,1,1,1,1,0,1,1
3232
#define TEST_DATA_FILE_COUNT 0
3333
#define TEST_DATA_FILE_LOAD_FAIL 0
3434

tests/conformance/test_sec7_10.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ teardown_f(void **state)
7272
}
7373

7474
static void
75-
TEST_CHOICE(void **state)
75+
TEST_ANYXML(void **state)
7676
{
7777
struct state *st = (*state);
7878
const int schemas_fail[] = {TEST_SCHEMA_LOAD_FAIL};
@@ -139,7 +139,7 @@ int
139139
main(void)
140140
{
141141
const struct CMUnitTest tests[] = {
142-
cmocka_unit_test_setup_teardown(TEST_CHOICE, setup_f, teardown_f),
142+
cmocka_unit_test_setup_teardown(TEST_ANYXML, setup_f, teardown_f),
143143
};
144144

145145
return cmocka_run_group_tests(tests, NULL, NULL);

tests/conformance/test_sec7_15_1.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/**
2+
* @file test_sec7_1.c
3+
* @author Pavol Vican
4+
* @brief Cmocka test for RFC 6020 section 7.1 (without 7.1.3) conformance.
5+
*
6+
* Copyright (c) 2016 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+
15+
#include <stdio.h>
16+
#include <stdlib.h>
17+
#include <setjmp.h>
18+
#include <errno.h>
19+
#include <unistd.h>
20+
#include <stdarg.h>
21+
#include <cmocka.h>
22+
#include <string.h>
23+
#include <sys/wait.h>
24+
25+
#include "tests/config.h"
26+
#include "libyang.h"
27+
28+
#define TEST_DIR "sec7_15_1"
29+
#define TEST_NAME test_sec7_15_1
30+
#define TEST_SCHEMA_COUNT 2
31+
#define TEST_SCHEMA_LOAD_FAIL 1,0
32+
#define TEST_DATA_FILE_COUNT 0
33+
#define TEST_DATA_FILE_LOAD_FAIL 0
34+
35+
struct state {
36+
struct ly_ctx *ctx;
37+
struct lyd_node *node;
38+
};
39+
40+
static int
41+
setup_f(void **state)
42+
{
43+
struct state *st;
44+
45+
(*state) = st = calloc(1, sizeof *st);
46+
if (!st) {
47+
fprintf(stderr, "Memory allocation error");
48+
return -1;
49+
}
50+
51+
/* libyang context */
52+
st->ctx = ly_ctx_new(TESTS_DIR "/conformance/" TEST_DIR, 0);
53+
if (!st->ctx) {
54+
fprintf(stderr, "Failed to create context.\n");
55+
return -1;
56+
}
57+
58+
return 0;
59+
}
60+
61+
static int
62+
teardown_f(void **state)
63+
{
64+
struct state *st = (*state);
65+
66+
lyd_free(st->node);
67+
ly_ctx_destroy(st->ctx, NULL);
68+
free(st);
69+
(*state) = NULL;
70+
71+
return 0;
72+
}
73+
74+
75+
static void
76+
TEST_ACTION(void **state)
77+
{
78+
struct state *st = (*state);
79+
const int schemas_fail[] = {TEST_SCHEMA_LOAD_FAIL};
80+
const int data_files_fail[] = {TEST_DATA_FILE_LOAD_FAIL};
81+
char buf[1024];
82+
LYS_INFORMAT schema_format = LYS_IN_YANG;
83+
const struct lys_module *mod;
84+
int i, j, ret;
85+
86+
for (i = 0; i < 2; ++i) {
87+
for (j = 0; j < TEST_SCHEMA_COUNT; ++j) {
88+
sprintf(buf, TESTS_DIR "/conformance/" TEST_DIR "/mod%d.%s", j + 1, (schema_format == LYS_IN_YANG ? "yang" : "yin"));
89+
mod = lys_parse_path(st->ctx, buf, schema_format);
90+
if (schemas_fail[j]) {
91+
assert_ptr_equal(mod, NULL);
92+
} else {
93+
assert_ptr_not_equal(mod, NULL);
94+
}
95+
}
96+
97+
for (j = 0; j < TEST_DATA_FILE_COUNT; ++j) {
98+
sprintf(buf, TESTS_DIR "/conformance/data%d.xml", j + 1);
99+
st->node = lyd_parse_path(st->ctx, buf, LYD_XML, LYD_OPT_CONFIG);
100+
if (data_files_fail[j]) {
101+
assert_ptr_not_equal(st->node, NULL);
102+
} else {
103+
assert_ptr_equal(st->node, NULL);
104+
}
105+
}
106+
107+
if (schema_format == LYS_IN_YANG) {
108+
/* convert the modules */
109+
for (j = 0; j < TEST_SCHEMA_COUNT; ++j) {
110+
sprintf(buf, BUILD_DIR "/yang2yin "
111+
TESTS_DIR "/conformance/" TEST_DIR "/mod%d.yang "
112+
TESTS_DIR "/conformance/" TEST_DIR "/mod%d.yin", j + 1, j + 1);
113+
ret = system(buf);
114+
if (ret == -1) {
115+
fprintf(stderr, "system() failed (%s).\n", strerror(errno));
116+
fail();
117+
} else if (WEXITSTATUS(ret) != 0) {
118+
fprintf(stderr, "Executing command \"%s\" finished with %d.\n", buf, WEXITSTATUS(ret));
119+
fail();
120+
}
121+
}
122+
123+
schema_format = LYS_IN_YIN;
124+
} else {
125+
/* remove the modules */
126+
for (j = 0; j < TEST_SCHEMA_COUNT; ++j) {
127+
sprintf(buf, TESTS_DIR "/conformance/" TEST_DIR "/mod%d.yin", j + 1);
128+
if (unlink(buf)) {
129+
fprintf(stderr, "unlink() on \"%s\" failed (%s).\n", buf, strerror(errno));
130+
}
131+
}
132+
}
133+
}
134+
}
135+
136+
int
137+
main(void)
138+
{
139+
const struct CMUnitTest tests[] = {
140+
cmocka_unit_test_setup_teardown(TEST_ACTION, setup_f, teardown_f),
141+
};
142+
143+
return cmocka_run_group_tests(tests, NULL, NULL);
144+
}

0 commit comments

Comments
 (0)