├── .gitattributes ├── .github └── workflows │ ├── ci.yml │ ├── cifuzz.yml │ └── devel-push.yml ├── .mailmap ├── CMakeLists.txt ├── CMakeModules ├── ABICheck.cmake ├── FindCMocka.cmake ├── FindPCRE2.cmake ├── FindUncrustify.cmake ├── FindXXHash.cmake ├── GenCoverage.cmake ├── GenDoc.cmake ├── SourceFormat.cmake ├── UseCompat.cmake └── uninstall.cmake ├── CONTRIBUTING.md ├── Doxyfile.in ├── FindLibYANG.cmake ├── LICENSE ├── README.md ├── SECURITY.md ├── codecov.yml ├── compat ├── check_includes.sh ├── compat.c ├── compat.h.in ├── posix-shims │ ├── libgen.h │ ├── strings.h │ └── unistd.h └── strptime.c ├── distro ├── README.md ├── config │ └── apkg.toml ├── pkg │ ├── deb │ │ ├── README.Debian │ │ ├── README.source │ │ ├── changelog │ │ ├── compat │ │ ├── control │ │ ├── copyright │ │ ├── gbp.conf │ │ ├── libyang-dev.install │ │ ├── libyang-modules.install │ │ ├── libyang-tools.examples │ │ ├── libyang-tools.install │ │ ├── libyang3.install │ │ ├── rules │ │ ├── source │ │ │ └── format │ │ ├── tests │ │ │ ├── control │ │ │ └── yanglint │ │ └── watch │ └── rpm │ │ └── libyang.spec ├── scripts │ ├── make-archive.sh │ └── upstream-version.sh └── tests │ ├── control │ ├── test-pkg-config.sh │ └── test-yanglint.sh ├── doc ├── build.dox ├── cesnet-style.css ├── compat_report_1_2.html ├── compat_report_2_3.html ├── logo.png ├── transition_1_2.dox └── transition_2_3.dox ├── libyang.pc.in ├── models ├── ietf-datastores@2018-02-14.h ├── ietf-datastores@2018-02-14.yang ├── ietf-inet-types@2013-07-15.h ├── ietf-inet-types@2013-07-15.yang ├── ietf-yang-library@2019-01-04.h ├── ietf-yang-library@2019-01-04.yang ├── ietf-yang-metadata@2016-08-05.h ├── ietf-yang-metadata@2016-08-05.yang ├── ietf-yang-schema-mount@2019-01-14.h ├── ietf-yang-schema-mount@2019-01-14.yang ├── ietf-yang-structure-ext@2020-06-17.h ├── ietf-yang-structure-ext@2020-06-17.yang ├── ietf-yang-types@2013-07-15.h ├── ietf-yang-types@2013-07-15.yang ├── yang@2025-01-29.h └── yang@2025-01-29.yang ├── src ├── context.c ├── context.h ├── dict.c ├── dict.h ├── diff.c ├── diff.h ├── hash_table.c ├── hash_table.h ├── hash_table_internal.h ├── in.c ├── in.h ├── in_internal.h ├── json.c ├── json.h ├── libyang.h ├── log.c ├── log.h ├── ly_common.c ├── ly_common.h ├── ly_config.h.in ├── lyb.c ├── lyb.h ├── out.c ├── out.h ├── out_internal.h ├── parser_common.c ├── parser_data.h ├── parser_internal.h ├── parser_json.c ├── parser_lyb.c ├── parser_schema.h ├── parser_xml.c ├── parser_yang.c ├── parser_yin.c ├── path.c ├── path.h ├── plugins.c ├── plugins.h ├── plugins_exts.c ├── plugins_exts.h ├── plugins_exts │ ├── metadata.c │ ├── metadata.h │ ├── nacm.c │ ├── schema_mount.c │ ├── structure.c │ └── yangdata.c ├── plugins_internal.h ├── plugins_types.c ├── plugins_types.h ├── plugins_types │ ├── binary.c │ ├── bits.c │ ├── boolean.c │ ├── date_and_time.c │ ├── decimal64.c │ ├── empty.c │ ├── enumeration.c │ ├── hex_string.c │ ├── identityref.c │ ├── instanceid.c │ ├── instanceid_keys.c │ ├── integer.c │ ├── ipv4_address.c │ ├── ipv4_address_no_zone.c │ ├── ipv4_prefix.c │ ├── ipv6_address.c │ ├── ipv6_address_no_zone.c │ ├── ipv6_prefix.c │ ├── leafref.c │ ├── lyds_tree.c │ ├── node_instanceid.c │ ├── string.c │ ├── time_period.c │ ├── union.c │ └── xpath1.0.c ├── printer_data.c ├── printer_data.h ├── printer_internal.h ├── printer_json.c ├── printer_lyb.c ├── printer_schema.c ├── printer_schema.h ├── printer_tree.c ├── printer_xml.c ├── printer_yang.c ├── printer_yin.c ├── schema_compile.c ├── schema_compile.h ├── schema_compile_amend.c ├── schema_compile_amend.h ├── schema_compile_node.c ├── schema_compile_node.h ├── schema_features.c ├── schema_features.h ├── set.c ├── set.h ├── tree.h ├── tree_data.c ├── tree_data.h ├── tree_data_common.c ├── tree_data_free.c ├── tree_data_hash.c ├── tree_data_internal.h ├── tree_data_new.c ├── tree_data_sorted.c ├── tree_data_sorted.h ├── tree_edit.h ├── tree_schema.c ├── tree_schema.h ├── tree_schema_common.c ├── tree_schema_free.c ├── tree_schema_free.h ├── tree_schema_internal.h ├── validation.c ├── validation.h ├── version.h.in ├── xml.c ├── xml.h ├── xpath.c └── xpath.h ├── tests ├── CMakeLists.txt ├── cstr.sh ├── fuzz │ ├── CMakeLists.txt │ ├── README.md │ ├── corpus │ │ ├── lyd_parse_mem_json │ │ │ ├── pull11438 │ │ │ ├── pull1203 │ │ │ ├── pull1269 │ │ │ ├── pull1269_2 │ │ │ ├── pull1280 │ │ │ ├── pull1347_number │ │ │ ├── pull1347_strings │ │ │ ├── pull1348 │ │ │ ├── pull1460 │ │ │ ├── pull1460_2 │ │ │ ├── pull1571 │ │ │ ├── pull1585 │ │ │ ├── pull1626 │ │ │ ├── pull1693 │ │ │ ├── pull1696_1 │ │ │ └── pull1696_2 │ │ ├── lyd_parse_mem_xml │ │ │ ├── issue1074 │ │ │ ├── issue1131 │ │ │ ├── issue1132 │ │ │ ├── issue1132_2 │ │ │ ├── issue1132_3 │ │ │ ├── pull1129_1 │ │ │ ├── pull1129_2 │ │ │ ├── pull1529 │ │ │ ├── pull1537 │ │ │ └── pull1562 │ │ └── lys_parse_mem │ │ │ ├── issue1004.yang │ │ │ ├── issue1025.yang │ │ │ ├── issue1027.yang │ │ │ ├── issue1040.yang │ │ │ ├── issue1041.yang │ │ │ ├── issue1042_base-yang-types.yang │ │ │ ├── issue1042_test-type-provider-b.yang │ │ │ ├── issue1042_test-type-provider.yang │ │ │ ├── issue1043.yang │ │ │ ├── issue722.yang │ │ │ ├── issue723.yang │ │ │ ├── issue724.yang │ │ │ ├── issue728.yang │ │ │ ├── issue733.yang │ │ │ ├── issue734.yang │ │ │ ├── issue735.yang │ │ │ ├── issue739.yang │ │ │ ├── issue740.yang │ │ │ ├── issue741.yang │ │ │ ├── issue742.yang │ │ │ ├── issue769.yang │ │ │ ├── issue771.yang │ │ │ ├── issue772.yang │ │ │ ├── issue773.yang │ │ │ ├── issue774.yang │ │ │ ├── issue777.yang │ │ │ ├── issue780.yang │ │ │ ├── issue788.yang │ │ │ ├── issue789.yang │ │ │ ├── issue791.yang │ │ │ ├── issue791_2.yang │ │ │ ├── issue795.yang │ │ │ ├── issue804.yang │ │ │ ├── issue805.yang │ │ │ ├── issue807.yang │ │ │ ├── issue826.yang │ │ │ ├── issue827.yang │ │ │ ├── issue872.yang │ │ │ ├── issue874.yang │ │ │ ├── issue970.yang │ │ │ ├── issue973.yang │ │ │ ├── issue975.yang │ │ │ ├── issue976_a.yang │ │ │ ├── issue976_b.yang │ │ │ ├── issue979_a.yang │ │ │ ├── issue979_b.yang │ │ │ ├── pull1524.yang │ │ │ ├── pull1568.yang │ │ │ ├── pull1592.yang │ │ │ ├── pull958.yang │ │ │ └── pull960.yang │ ├── fuzz_regression_test.c │ ├── lyd_parse_mem_json.c │ ├── lyd_parse_mem_xml.c │ ├── lys_parse_mem.c │ ├── main.c │ └── yang_parse_module.c ├── ld.supp ├── modules │ └── yang │ │ ├── iana-if-type@2014-05-08.yang │ │ ├── ietf-interfaces@2014-05-08.yang │ │ ├── ietf-ip@2014-06-16.yang │ │ ├── ietf-netconf-acm@2018-02-14.yang │ │ ├── ietf-netconf-nmda@2019-01-07.yang │ │ ├── ietf-netconf-with-defaults@2011-06-01.yang │ │ ├── ietf-netconf@2011-06-01.yang │ │ ├── ietf-origin@2018-02-14.yang │ │ ├── ietf-restconf@2017-01-26.yang │ │ ├── notifications@2008-07-14.yang │ │ ├── sm-extension.yang │ │ ├── sm-mod.yang │ │ ├── sm-modp.yang │ │ ├── sm-rpcnotif.yang │ │ └── sm.yang ├── perf │ ├── CMakeLists.txt │ ├── perf.c │ └── perf.yang ├── plugins │ ├── CMakeLists.txt │ ├── invalid.c │ └── simple.c ├── style │ ├── CMakeLists.txt │ └── cpp_compat.c ├── tests_config.h.in ├── tool_i.tcl ├── tool_ni.tcl ├── utests │ ├── CMakeLists.txt │ ├── basic │ │ ├── test_common.c │ │ ├── test_context.c │ │ ├── test_hash_table.c │ │ ├── test_inout.c │ │ ├── test_json.c │ │ ├── test_plugins.c │ │ ├── test_set.c │ │ ├── test_xml.c │ │ ├── test_xpath.c │ │ └── test_yanglib.c │ ├── data │ │ ├── test_diff.c │ │ ├── test_lyb.c │ │ ├── test_merge.c │ │ ├── test_new.c │ │ ├── test_parser_json.c │ │ ├── test_parser_xml.c │ │ ├── test_printer_json.c │ │ ├── test_printer_xml.c │ │ ├── test_tree_data.c │ │ ├── test_tree_data_sorted.c │ │ └── test_validation.c │ ├── extensions │ │ ├── test_metadata.c │ │ ├── test_nacm.c │ │ ├── test_schema_mount.c │ │ ├── test_structure.c │ │ └── test_yangdata.c │ ├── node │ │ └── list.c │ ├── restriction │ │ ├── test_pattern.c │ │ └── test_range.c │ ├── schema │ │ ├── test_printer_tree.c │ │ ├── test_schema.c │ │ ├── test_tree_schema_compile.c │ │ ├── test_yang.c │ │ └── test_yin.c │ ├── types │ │ ├── binary.c │ │ ├── bits.c │ │ ├── boolean.c │ │ ├── decimal64.c │ │ ├── empty.c │ │ ├── enumeration.c │ │ ├── identityref.c │ │ ├── inet_types.c │ │ ├── instanceid.c │ │ ├── instanceid_keys.c │ │ ├── int16.c │ │ ├── int32.c │ │ ├── int64.c │ │ ├── int8.c │ │ ├── leafref.c │ │ ├── string.c │ │ ├── uint16.c │ │ ├── uint32.c │ │ ├── uint64.c │ │ ├── uint8.c │ │ ├── union.c │ │ └── yang_types.c │ └── utests.h ├── yanglint │ ├── CMakeLists.txt │ ├── README.md │ ├── common.tcl │ ├── data │ │ ├── modaction.xml │ │ ├── modaction_ds.xml │ │ ├── modaction_nc.xml │ │ ├── modaction_reply.xml │ │ ├── modaction_reply_nc.xml │ │ ├── modconfig.xml │ │ ├── modconfig2.xml │ │ ├── modconfig_ctx.xml │ │ ├── moddatanodes.xml │ │ ├── moddefault.xml │ │ ├── modimp_type_ctx.xml │ │ ├── modleaf.djson │ │ ├── modleaf.dxml │ │ ├── modleaf.xml │ │ ├── modleafref.xml │ │ ├── modleafref2.xml │ │ ├── modmandatory.xml │ │ ├── modmandatory_invalid.xml │ │ ├── modmerge.xml │ │ ├── modmerge2.xml │ │ ├── modmerge3.xml │ │ ├── modnotif.xml │ │ ├── modnotif2.xml │ │ ├── modnotif2_nc.xml │ │ ├── modnotif_ds.xml │ │ ├── modnotif_nc.xml │ │ ├── modoper_leafref_action.xml │ │ ├── modoper_leafref_action_reply.xml │ │ ├── modoper_leafref_ds.xml │ │ ├── modoper_leafref_notif.xml │ │ ├── modoper_leafref_notif2.xml │ │ ├── modoper_leafref_notif_err.xml │ │ ├── modoper_leafref_rpc.xml │ │ ├── modoper_leafref_rpc_reply.xml │ │ ├── modrpc.xml │ │ ├── modrpc_nc.xml │ │ ├── modrpc_reply.xml │ │ ├── modrpc_reply_nc.xml │ │ ├── modsm.xml │ │ ├── modsm2.xml │ │ ├── modsm_ctx_ext.xml │ │ └── modsm_ctx_main.xml │ ├── interactive │ │ ├── add.test │ │ ├── all.tcl │ │ ├── clear.test │ │ ├── completion.test │ │ ├── data_default.test │ │ ├── data_format.test │ │ ├── data_in_format.test │ │ ├── data_merge.test │ │ ├── data_not_strict.test │ │ ├── data_operational.test │ │ ├── data_present.test │ │ ├── data_type.test │ │ ├── data_xpath.test │ │ ├── extdata.test │ │ ├── feature.test │ │ ├── list.test │ │ ├── load.test │ │ ├── ly.tcl │ │ ├── modcwd.yang │ │ ├── print.test │ │ └── searchpath.test │ ├── modules │ │ ├── ietf-interfaces.yang │ │ ├── ietf-ip.yang │ │ ├── ietf-netconf-acm.yang │ │ ├── ietf-netconf-with-defaults@2011-06-01.yang │ │ ├── ietf-netconf@2011-06-01.yang │ │ ├── modaction.yang │ │ ├── modconfig-augment.yang │ │ ├── modconfig.yang │ │ ├── moddatanodes.yang │ │ ├── moddefault.yang │ │ ├── modextleafref.yang │ │ ├── modfeature.yang │ │ ├── modimp-cwd.yang │ │ ├── modimp-path.yang │ │ ├── modimp-type.yang │ │ ├── modinclude.yang │ │ ├── modleaf.yang │ │ ├── modleafref.yang │ │ ├── modmandatory.yang │ │ ├── modmerge.yang │ │ ├── modmust.yang │ │ ├── modnotif.yang │ │ ├── modoper-leafref.yang │ │ ├── modpath.yang │ │ ├── modrpc.yang │ │ ├── modsm-augment.yang │ │ ├── modsm.yang │ │ ├── modsub.yang │ │ └── modtypedef.yang │ └── non-interactive │ │ ├── all.tcl │ │ ├── data_default.test │ │ ├── data_in_format.test │ │ ├── data_merge.test │ │ ├── data_not_strict.test │ │ ├── data_operational.test │ │ ├── data_present.test │ │ ├── data_type.test │ │ ├── data_xpath.test │ │ ├── disabled_searchdir.test │ │ ├── ext_data.test │ │ ├── extended_leafref.test │ │ ├── format.test │ │ ├── list.test │ │ ├── ly.tcl │ │ ├── make_implemented.test │ │ ├── modcwd.yang │ │ ├── path.test │ │ └── yang_library_file.test └── yangre │ ├── CMakeLists.txt │ ├── all.tcl │ ├── arg.test │ ├── file.test │ ├── files │ ├── empty.txt │ ├── empty_str.txt │ ├── empty_str_err.txt │ ├── one_pattern.txt │ ├── two_patterns.txt │ ├── two_patterns_err.txt │ ├── two_patterns_invert_match.txt │ └── two_patterns_invert_match_err.txt │ ├── invert_match.test │ ├── ly.tcl │ └── pattern.test ├── tools ├── CMakeLists.txt ├── config.h.in ├── lint │ ├── CMakeLists.txt │ ├── cmd.c │ ├── cmd.h │ ├── cmd_add.c │ ├── cmd_clear.c │ ├── cmd_data.c │ ├── cmd_debug.c │ ├── cmd_extdata.c │ ├── cmd_feature.c │ ├── cmd_help.c │ ├── cmd_list.c │ ├── cmd_load.c │ ├── cmd_print.c │ ├── cmd_searchpath.c │ ├── cmd_verb.c │ ├── common.c │ ├── common.h │ ├── completion.c │ ├── completion.h │ ├── configuration.c │ ├── configuration.h │ ├── examples │ │ ├── README.md │ │ ├── action-reply.xml │ │ ├── action.xml │ │ ├── config-acm.xml │ │ ├── config-missing-key.xml │ │ ├── config-unknown-element.xml │ │ ├── data-acm.xml │ │ ├── data-ip.xml │ │ ├── data-malformed-xml.xml │ │ ├── data-malformed-xml2.xml │ │ ├── data-missing-key.xml │ │ ├── data-out-of-range-value.xml │ │ ├── datastore.xml │ │ ├── iana-if-type.yang │ │ ├── ietf-interfaces.yang │ │ ├── ietf-ip.yang │ │ ├── ietf-netconf-acm-when.yang │ │ ├── ietf-netconf-acm-when.yin │ │ ├── ietf-netconf-acm-when2.yin │ │ ├── ietf-netconf-acm.yang │ │ ├── module1.yang │ │ ├── module1b.yang │ │ ├── module2.yang │ │ ├── module2.yin │ │ ├── module3.yang │ │ ├── module4.yang │ │ ├── nested-notification.xml │ │ ├── notification.xml │ │ ├── rpc-reply.xml │ │ ├── rpc.xml │ │ ├── sm-context-extension.xml │ │ ├── sm-context-main.xml │ │ ├── sm-data.xml │ │ ├── sm-extension.yang │ │ ├── sm-main.yang │ │ └── sm-mod.yang │ ├── linenoise │ │ ├── LICENSE │ │ ├── linenoise.c │ │ ├── linenoise.h │ │ ├── utf8.c │ │ └── utf8.h │ ├── main.c │ ├── main_ni.c │ ├── main_ni_only.c │ ├── yanglint.1 │ ├── yl_opt.c │ ├── yl_opt.h │ ├── yl_schema_features.c │ └── yl_schema_features.h └── re │ ├── CMakeLists.txt │ ├── main.c │ └── yangre.1 └── uncrustify.cfg /.gitattributes: -------------------------------------------------------------------------------- 1 | # the tests check that LF is kept as a LF in the checkout 2 | tests/modules/yang/ietf-netconf@*.yang -text 3 | tests/modules/yang/ietf-netconf-nmda@*.yang -text 4 | -------------------------------------------------------------------------------- /.github/workflows/cifuzz.yml: -------------------------------------------------------------------------------- 1 | name: CIFuzz 2 | on: [pull_request] 3 | jobs: 4 | Fuzzing: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Build Fuzzers 8 | id: build 9 | uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master 10 | with: 11 | oss-fuzz-project-name: 'libyang' 12 | dry-run: false 13 | - name: Run Fuzzers 14 | uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master 15 | with: 16 | oss-fuzz-project-name: 'libyang' 17 | fuzz-seconds: 300 18 | dry-run: false 19 | - name: Upload Crash 20 | uses: actions/upload-artifact@main 21 | if: failure() && steps.build.outcome == 'success' 22 | with: 23 | name: artifacts 24 | path: ./out/artifacts 25 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | David Sedlák 2 | FredGan 3 | Juraj Vijtiuk <30860583+jvijtiuk@users.noreply.github.com> 4 | Juraj Vijtiuk <30860583+jvijtiuk@users.noreply.github.com> 5 | Michal Vasko 6 | Radek Krejci 7 | -------------------------------------------------------------------------------- /CMakeModules/FindCMocka.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find CMocka 2 | # Once done this will define 3 | # 4 | # CMOCKA_ROOT_DIR - Set this variable to the root installation of CMocka 5 | # 6 | # Read-Only variables: 7 | # CMOCKA_FOUND - system has CMocka 8 | # CMOCKA_INCLUDE_DIR - the CMocka include directory 9 | # CMOCKA_LIBRARIES - Link these to use CMocka 10 | # CMOCKA_DEFINITIONS - Compiler switches required for using CMocka 11 | # 12 | #============================================================================= 13 | # Copyright (c) 2011-2012 Andreas Schneider 14 | # 15 | # Distributed under the OSI-approved BSD License (the "License"); 16 | # see accompanying file Copyright.txt for details. 17 | # 18 | # This software is distributed WITHOUT ANY WARRANTY; without even the 19 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 | # See the License for more information. 21 | #============================================================================= 22 | # 23 | 24 | find_path(CMOCKA_INCLUDE_DIR 25 | NAMES 26 | cmocka.h 27 | PATHS 28 | ${CMOCKA_ROOT_DIR}/include 29 | ) 30 | 31 | find_library(CMOCKA_LIBRARY 32 | NAMES 33 | cmocka 34 | PATHS 35 | ${CMOCKA_ROOT_DIR}/include 36 | ) 37 | 38 | if (CMOCKA_LIBRARY) 39 | set(CMOCKA_LIBRARIES 40 | ${CMOCKA_LIBRARIES} 41 | ${CMOCKA_LIBRARY} 42 | ) 43 | endif (CMOCKA_LIBRARY) 44 | 45 | include(FindPackageHandleStandardArgs) 46 | find_package_handle_standard_args(CMocka DEFAULT_MSG CMOCKA_LIBRARIES CMOCKA_INCLUDE_DIR) 47 | 48 | # show the CMOCKA_INCLUDE_DIR and CMOCKA_LIBRARIES variables only in the advanced view 49 | mark_as_advanced(CMOCKA_INCLUDE_DIR CMOCKA_LIBRARIES) 50 | -------------------------------------------------------------------------------- /CMakeModules/FindPCRE2.cmake: -------------------------------------------------------------------------------- 1 | # - Find pcre 2 | # Find the native PCRE2 headers and libraries. 3 | # 4 | # PCRE2_INCLUDE_DIRS - where to find pcre.h, etc. 5 | # PCRE2_LIBRARIES - List of libraries when using pcre. 6 | # PCRE2_FOUND - True if pcre found. 7 | include(FindPackageHandleStandardArgs) 8 | 9 | if(PCRE2_LIBRARIES AND PCRE2_INCLUDE_DIRS) 10 | # in cache already 11 | set(PCRE2_FOUND TRUE) 12 | else() 13 | find_path(PCRE2_INCLUDE_DIR 14 | NAMES 15 | pcre2.h 16 | PATHS 17 | /usr/include 18 | /usr/local/include 19 | /opt/local/include 20 | /sw/include 21 | ${CMAKE_INCLUDE_PATH} 22 | ${CMAKE_INSTALL_PREFIX}/include) 23 | 24 | # Look for the library. 25 | if (WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") 26 | # For the Debug build, the pcre2 library is called pcre2-8d. The Release build should be pcre2-8. 27 | find_library(PCRE2_LIBRARY pcre2-8d) 28 | else() 29 | find_library(PCRE2_LIBRARY 30 | NAMES 31 | pcre2-8 32 | PATHS 33 | /usr/lib 34 | /usr/lib64 35 | /usr/local/lib 36 | /usr/local/lib64 37 | /opt/local/lib 38 | /sw/lib 39 | ${CMAKE_LIBRARY_PATH} 40 | ${CMAKE_INSTALL_PREFIX}/lib) 41 | endif() 42 | 43 | if(PCRE2_INCLUDE_DIR AND PCRE2_LIBRARY) 44 | # learn pcre2 version 45 | file(STRINGS ${PCRE2_INCLUDE_DIR}/pcre2.h PCRE2_VERSION_MAJOR 46 | REGEX "#define[ ]+PCRE2_MAJOR[ ]+[0-9]+") 47 | string(REGEX MATCH " [0-9]+" PCRE2_VERSION_MAJOR ${PCRE2_VERSION_MAJOR}) 48 | string(STRIP "${PCRE2_VERSION_MAJOR}" PCRE2_VERSION_MAJOR) 49 | 50 | file(STRINGS ${PCRE2_INCLUDE_DIR}/pcre2.h PCRE2_VERSION_MINOR 51 | REGEX "#define[ ]+PCRE2_MINOR[ ]+[0-9]+") 52 | string(REGEX MATCH " [0-9]+" PCRE2_VERSION_MINOR ${PCRE2_VERSION_MINOR}) 53 | string(STRIP "${PCRE2_VERSION_MINOR}" PCRE2_VERSION_MINOR) 54 | 55 | set(PCRE2_VERSION ${PCRE2_VERSION_MAJOR}.${PCRE2_VERSION_MINOR}) 56 | endif() 57 | 58 | set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) 59 | set(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) 60 | mark_as_advanced(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES) 61 | 62 | # Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE. 63 | find_package_handle_standard_args(PCRE2 FOUND_VAR PCRE2_FOUND 64 | REQUIRED_VARS PCRE2_LIBRARY PCRE2_INCLUDE_DIR 65 | VERSION_VAR PCRE2_VERSION) 66 | endif() 67 | -------------------------------------------------------------------------------- /CMakeModules/FindUncrustify.cmake: -------------------------------------------------------------------------------- 1 | # - Find uncrustify 2 | # Find the uncrustify binary. 3 | # 4 | # UNCRUSTIFY - path ot the binary 5 | # UNCRUSTIFY_VERSION - found version 6 | # UNCRUSTIFY_FOUND - True if uncrustify found. 7 | include(FindPackageHandleStandardArgs) 8 | 9 | find_program(UNCRUSTIFY uncrustify) 10 | if(UNCRUSTIFY) 11 | execute_process(COMMAND ${UNCRUSTIFY} --version OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE VERSION) 12 | string(FIND ${VERSION} "-" START_IDX) 13 | math(EXPR START_IDX "${START_IDX} + 1") 14 | string(SUBSTRING "${VERSION}" ${START_IDX} -1 VERSION) 15 | 16 | string(FIND ${VERSION} "-" LEN) 17 | string(SUBSTRING "${VERSION}" 0 ${LEN} UNCRUSTIFY_VERSION) 18 | endif() 19 | 20 | # Handle the QUIETLY and REQUIRED arguments and set UNCRUSTIFY_FOUND to TRUE if all listed variables are TRUE. 21 | find_package_handle_standard_args(Uncrustify REQUIRED_VARS UNCRUSTIFY VERSION_VAR UNCRUSTIFY_VERSION) 22 | -------------------------------------------------------------------------------- /CMakeModules/FindXXHash.cmake: -------------------------------------------------------------------------------- 1 | # Try to find XXHash 2 | # Once done this will define 3 | # 4 | # Read-Only variables: 5 | # XXHASH_FOUND - system has XXHash 6 | # XXHASH_INCLUDE_DIR - the XXHash include directory 7 | # XXHASH_LIBRARY - Link these to use XXHash 8 | 9 | find_path(XXHASH_INCLUDE_DIR 10 | NAMES 11 | xxhash.h 12 | PATHS 13 | /usr/include 14 | /usr/local/include 15 | /opt/local/include 16 | /sw/include 17 | ${CMAKE_INCLUDE_PATH} 18 | ${CMAKE_INSTALL_PREFIX}/include 19 | ) 20 | 21 | find_library(XXHASH_LIBRARY 22 | NAMES 23 | xxhash 24 | libxxhash 25 | PATHS 26 | PATHS 27 | /usr/lib 28 | /usr/lib64 29 | /usr/local/lib 30 | /usr/local/lib64 31 | /opt/local/lib 32 | /sw/lib 33 | ${CMAKE_LIBRARY_PATH} 34 | ${CMAKE_INSTALL_PREFIX}/lib 35 | ) 36 | 37 | include(FindPackageHandleStandardArgs) 38 | find_package_handle_standard_args(XXHash FOUND_VAR XXHASH_FOUND REQUIRED_VARS XXHASH_INCLUDE_DIR XXHASH_LIBRARY) 39 | -------------------------------------------------------------------------------- /CMakeModules/GenDoc.cmake: -------------------------------------------------------------------------------- 1 | # Prepare building doxygen documentation 2 | macro(GEN_DOC INPUT_FILES PROJECT_VERSION PROJECT_DESCRIPTION DOC_LOGO) 3 | find_package(Doxygen) 4 | if(DOXYGEN_FOUND) 5 | find_program(DOT_PATH dot PATH_SUFFIXES graphviz2.38/bin graphviz/bin) 6 | if(DOT_PATH) 7 | set(HAVE_DOT "YES") 8 | else() 9 | set(HAVE_DOT "NO") 10 | message(AUTHOR_WARNING "Doxygen: to generate UML diagrams please install graphviz") 11 | endif() 12 | 13 | # target doc 14 | add_custom_target(doc 15 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile 16 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 17 | 18 | # generate list with spaces as separators 19 | string(REPLACE ";" " " DOXY_INPUT "${INPUT_FILES}") 20 | 21 | # make other arguments into variables 22 | set(PROJECT_VERSION ${PROJECT_VERSION}) 23 | set(PROJECT_DESCRIPTION ${PROJECT_DESCRIPTION}) 24 | set(DOC_LOGO ${DOC_LOGO}) 25 | 26 | configure_file(Doxyfile.in Doxyfile) 27 | endif() 28 | endmacro() 29 | -------------------------------------------------------------------------------- /CMakeModules/SourceFormat.cmake: -------------------------------------------------------------------------------- 1 | # format source files with uncrustify 2 | 3 | # check that format checking is available - always use before SOURCE_FORMAT 4 | macro(SOURCE_FORMAT_ENABLE) 5 | if(NOT ${ARGC} EQUAL 1) 6 | message(FATAL_ERROR "source_format_enable() needs the required Uncrustify version!") 7 | endif() 8 | 9 | find_package(Uncrustify ${ARGV0}) 10 | if(UNCRUSTIFY_FOUND) 11 | set(SOURCE_FORMAT_ENABLED TRUE) 12 | else() 13 | set(SOURCE_FORMAT_ENABLED FALSE) 14 | endif() 15 | endmacro() 16 | 17 | # files are expected to be a list and relative paths are resolved wtih respect to CMAKE_SOURCE DIR 18 | macro(SOURCE_FORMAT) 19 | if(NOT ${ARGC}) 20 | message(FATAL_ERROR "source_format() needs a list of files to format!") 21 | endif() 22 | 23 | if(SOURCE_FORMAT_ENABLED) 24 | add_custom_target(format 25 | COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --no-backup --replace ${ARGN} 26 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 27 | COMMENT "Formating sources with ${UNCRUSTIFY} ...") 28 | 29 | add_custom_target(format-check 30 | COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --check ${ARGN} 31 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 32 | COMMENT "Checking format of the sources with ${UNCRUSTIFY} ...") 33 | 34 | set(SOURCE_FORMAT_ENABLED TRUE) 35 | endif() 36 | endmacro() 37 | -------------------------------------------------------------------------------- /CMakeModules/uninstall.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.2) 2 | 3 | set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") 4 | 5 | if(NOT EXISTS ${MANIFEST}) 6 | message(FATAL_ERROR "Cannot find install manifest: ${MANIFEST}") 7 | endif() 8 | 9 | file(STRINGS ${MANIFEST} files) 10 | foreach(file ${files}) 11 | if(EXISTS ${file} OR IS_SYMLINK ${file}) 12 | message(STATUS "Removing: ${file}") 13 | 14 | execute_process(COMMAND rm -f ${file} 15 | RESULT_VARIABLE result 16 | OUTPUT_QUIET 17 | ERROR_VARIABLE stderr 18 | ERROR_STRIP_TRAILING_WHITESPACE 19 | ) 20 | 21 | if(NOT ${result} EQUAL 0) 22 | message(FATAL_ERROR "${stderr}") 23 | endif() 24 | else() 25 | message(STATUS "Does-not-exist: ${file}") 26 | endif() 27 | endforeach(file) 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2024, CESNET 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of CESNET nor the names of 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | If you discover a security-related issue (a crash), please report it based on the instructions below. 4 | 5 | ## Reporting a Vulnerability 6 | 7 | Please **DO NOT** file a public issue, instead report the vulnerability on the relevant 8 | [GitHub security](https://github.com/CESNET/libyang/security) page. If you do not receive any reaction within 48 hours, 9 | please also send an email to [mvasko@cesnet.cz]. 10 | 11 | ## Review Process 12 | 13 | After receiving the report, an initial triage and technical analysis is performed to confirm the report and determine 14 | its scope. We may request additional information in this stage of the process. 15 | 16 | Once a reviewer has confirmed the relevance of the report, a draft security advisory will be created on GitHub. The 17 | draft advisory will be used to discuss the issue with maintainers, the reporter(s), and where applicable, other affected 18 | parties under embargo. 19 | 20 | If the vulnerability is accepted, a timeline for developing a patch, public disclosure, and patch release will be 21 | determined. If there is an embargo period on public disclosure before the patch release, the reporter(s) are expected to 22 | participate in the discussion of the timeline and abide by agreed upon dates for public disclosure. 23 | 24 | Usually, the reasonably complex issues are fixed within hours of being reported. 25 | 26 | ## Supported Versions 27 | 28 | After an issue is fixed, it **WILL NOT** be backported to any released version. Instead, it is kept in the public `devel` 29 | branch, which is periodically merged into the main branch when a new release is due. So, the issue will be fixed in the 30 | next release after it is fixed. 31 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: 2 | layout: header, changes, diff 3 | 4 | coverage: 5 | precision: 2 6 | round: nearest 7 | 8 | ignore: 9 | - compat/.* 10 | - tests/.* 11 | 12 | status: 13 | project: 14 | default: 15 | target: auto 16 | if_no_uploads: error 17 | 18 | patch: 19 | default: 20 | if_no_uploads: error 21 | 22 | changes: true 23 | 24 | parsers: 25 | gcov: 26 | branch_detection: 27 | macro: no 28 | loop: no 29 | conditional: no 30 | method: no 31 | 32 | -------------------------------------------------------------------------------- /compat/check_includes.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | RETVAL=0 4 | 5 | # params - paths to the source files to search 6 | SRC="$*" 7 | 8 | # param FUNC - name of the function in compat to check 9 | check_compat_func () { 10 | FILES=`grep -rE "([^[:alnum:]]|^)$1\([^\)]+\)" --include=\*.{c,h} $SRC | cut -d: -f1 | uniq` 11 | for f in $FILES; do 12 | grep -q "#include \"compat.h\"" $f 13 | if [ $? -ne 0 ]; then 14 | echo "Missing #include \"compat.h\" in file $f for function $1()" 15 | RETVAL=$((RETVAL+1)) 16 | fi 17 | done 18 | } 19 | 20 | check_compat_macro () { 21 | FILES=`grep -rE "([^[:alnum:]]|^)$1([^[:alnum:]]|$)" --include=\*.{c,h} $SRC | cut -d: -f1 | uniq` 22 | for f in $FILES; do 23 | grep -q "#include \"compat.h\"" $f 24 | if [ $? -ne 0 ]; then 25 | echo "Missing #include \"compat.h\" in file $f for macro $1" 26 | RETVAL=$((RETVAL+1)) 27 | fi 28 | done 29 | } 30 | 31 | check_compat_func vdprintf 32 | check_compat_func asprintf 33 | check_compat_func vasprintf 34 | check_compat_func getline 35 | check_compat_func strndup 36 | check_compat_func strnstr 37 | check_compat_func strdupa 38 | check_compat_func strchrnul 39 | check_compat_func get_current_dir_name 40 | check_compat_func pthread_mutex_timedlock 41 | check_compat_func UNUSED 42 | check_compat_macro _PACKED 43 | 44 | exit $RETVAL 45 | -------------------------------------------------------------------------------- /compat/posix-shims/libgen.h: -------------------------------------------------------------------------------- 1 | char *dirname(char *path); 2 | -------------------------------------------------------------------------------- /compat/posix-shims/strings.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef HAVE_STRCASECMP 4 | #ifdef _MSC_VER 5 | #define strcasecmp _stricmp 6 | #else 7 | #error No strcasecmp() implementation for this platform is available. 8 | #endif 9 | #endif 10 | 11 | #ifndef HAVE_STRNCASECMP 12 | #ifdef _MSC_VER 13 | #define strncasecmp _strnicmp 14 | #else 15 | #error No strncasecmp() implementation for this platform is available. 16 | #endif 17 | #endif 18 | -------------------------------------------------------------------------------- /compat/posix-shims/unistd.h: -------------------------------------------------------------------------------- 1 | #ifndef _UNISTD_H 2 | #define _UNISTD_H 1 3 | 4 | /* headers are broken on Windows, which means that some of them simply *have* to come first */ 5 | # include 6 | # include 7 | 8 | /* This is intended as a drop-in replacement for unistd.h on Windows. 9 | * Please add functionality as neeeded. 10 | * https://stackoverflow.com/a/826027/1202830 11 | */ 12 | 13 | #include 14 | #include 15 | #include /* for getpid() and the exec..() family */ 16 | #include /* for _getcwd() and _chdir() */ 17 | 18 | #define srandom srand 19 | #define random rand 20 | 21 | /* Values for the second argument to access. 22 | These may be OR'd together. */ 23 | #define R_OK 4 /* Test for read permission. */ 24 | #define W_OK 2 /* Test for write permission. */ 25 | #define X_OK 0 /* jkt: unsupported on Windows, so we don't really care */ 26 | #define F_OK 0 /* Test for existence. */ 27 | 28 | #define access _access 29 | #define dup2 _dup2 30 | #define execve _execve 31 | #define ftruncate _chsize 32 | #define unlink _unlink 33 | #define fileno _fileno 34 | #define getcwd _getcwd 35 | #define chdir _chdir 36 | #define isatty _isatty 37 | #define lseek _lseek 38 | #define fsync _commit 39 | #define timegm _mkgmtime 40 | /* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */ 41 | 42 | #define ssize_t SSIZE_T 43 | 44 | #define STDIN_FILENO 0 45 | #define STDOUT_FILENO 1 46 | #define STDERR_FILENO 2 47 | /* should be in some equivalent to */ 48 | typedef __int8 int8_t; 49 | typedef __int16 int16_t; 50 | typedef __int32 int32_t; 51 | typedef __int64 int64_t; 52 | typedef unsigned __int8 uint8_t; 53 | typedef unsigned __int16 uint16_t; 54 | typedef unsigned __int32 uint32_t; 55 | typedef unsigned __int64 uint64_t; 56 | 57 | #include 58 | #ifndef PATH_MAX 59 | #define PATH_MAX MAX_PATH 60 | #endif 61 | #ifndef _POSIX_PATH_MAX 62 | #define _POSIX_PATH_MAX 256 63 | #endif 64 | 65 | #ifndef S_ISREG 66 | # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) 67 | #endif 68 | #ifndef S_ISDIR 69 | # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) 70 | #endif 71 | #ifndef S_IRUSR 72 | # define S_IRUSR _S_IREAD 73 | #endif 74 | #ifndef S_IWUSR 75 | # define S_IWUSR _S_IWRITE 76 | #endif 77 | 78 | #endif /* unistd.h */ 79 | -------------------------------------------------------------------------------- /distro/README.md: -------------------------------------------------------------------------------- 1 | # upstream packaging 2 | 3 | ## RPM-based system (Fedora, CentOS, SUSE, ...) quickstart 4 | ``` 5 | sudo dnf install -y git rpm-build python3-pip 6 | pip3 install apkg 7 | apkg build -i 8 | ``` 9 | See apkg docs: https://pkg.labs.nic.cz/pages/apkg/ 10 | -------------------------------------------------------------------------------- /distro/config/apkg.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "libyang" 3 | make_archive_script = "distro/scripts/make-archive.sh" 4 | 5 | [upstream] 6 | archive_url = "https://github.com/CESNET/libyang/archive/v{{ version }}/libyang-{{ version }}.tar.gz" 7 | version_script = "distro/scripts/upstream-version.sh" 8 | 9 | [apkg] 10 | compat = 2 11 | -------------------------------------------------------------------------------- /distro/pkg/deb/README.Debian: -------------------------------------------------------------------------------- 1 | Debian packaging for libyang 2 | ============================ 3 | 4 | Where to file issues 5 | -------------------- 6 | 7 | Please file issues on the Debian BTS as usual. You could also open issues 8 | on github, but if it's something about the Debian packaging it's better to 9 | stick with the proper Debian ways. The Debian BTS is where other people 10 | involved with Debian go look for bugs regarding a package, so that's where 11 | they should be. 12 | 13 | Building straight off git 14 | ------------------------- 15 | 16 | Just the normal: 17 | 18 | ``` 19 | git clone https://github.com/CESNET/libyang -b debian/master 20 | cd libyang 21 | dpkg-buildpackage 22 | ``` 23 | 24 | Building a Debian .dsc 25 | ---------------------- 26 | 27 | Again, pretty much the normal: 28 | 29 | ``` 30 | git clone https://github.com/CESNET/libyang -b debian/master 31 | wget -Olibyang_0.16.105.orig.tar.gz https://github.com/CESNET/libyang/archive/v0.16-r3.tar.gz 32 | cd libyang 33 | dpkg-source -b . 34 | ``` 35 | 36 | (Note the diverging release numbering though.) 37 | 38 | -- Ondřej Surý >, Fri, 22 May 2020 11:10:55 +0200 39 | -------------------------------------------------------------------------------- /distro/pkg/deb/README.source: -------------------------------------------------------------------------------- 1 | This module uses gbp and upstream git repository 2 | 3 | To update this package, first import the changes from upstream: 4 | - git fetch --all 5 | 6 | Find the latest version: 7 | VERSION=$(git describe --tags $(git rev-list '--tags=v2*' --max-count=1) | sed 's/^v//') 8 | echo $VERSION 9 | 10 | Update debian/sid branch 11 | - git checkout debian/master 12 | - git merge v$VERSION 13 | 14 | Update the debian/copyright file: 15 | - cme update dpkg-copyright 16 | See also https://github.com/dod38fr/config-model/wiki/Updating-debian-copyright-file-with-cme 17 | 18 | Check patches (and cleanup if necessary): 19 | - gbp pq rebase --commit --drop 20 | 21 | Download upstream tarball: 22 | - uscan --download --verbose --download-version $VERSION 23 | 24 | Add pristine-tar: 25 | - pristine-tar commit ../libyang_$VERSION.orig.tar.gz v$VERSION 26 | 27 | Generate a temporary changelog: 28 | - gbp dch --new-version=$VERSION-1 --snapshot --auto --commit debian/ 29 | 30 | Test the first build:: 31 | - gbp buildpackage --git-ignore-new --git-pristine-tar --git-no-purge 32 | 33 | Regenerate the symbol file (See https://qt-kde-team.pages.debian.net/symbolfiles.html) 34 | - pkgkde-symbolshelper batchpatch -v $VERSION < /buildlog 35 | 36 | See https://www.debian.org/doc/manuals/maint-guide/advanced.en.html#librarysymbols 37 | and dpkg-gensymbols man page 38 | 39 | Update the changelog: 40 | - gbp dch -Ra -c 41 | 42 | Once everything is fine, build a source package and tag: 43 | - gbp buildpackage -S --git-tag 44 | 45 | Push on salsa: 46 | - gbp push 47 | 48 | For more details, see 49 | https://honk.sigxcpu.org/projects/git-buildpackage/manual-html/gbp.import.upstream-git.html#gbp.import.upstream.git.notarball 50 | 51 | Maintainer Notes (moved from README.md) 52 | ======================================= 53 | 54 | * the project version number is actually the SO ABI version. The release 55 | point numbers (0.16-r3) isn't used for Debian. 56 | 57 | * it's intentional that the SONAME is libyang.so.0.16 and not libyang.so.0. 58 | ABI compatibility is indicated by the first two numbers being equal; 59 | the third number is incremented for compatible changes. cf. 60 | CESNET/libyang#656 61 | 62 | * the watch file doesn't work yet but the libyang people agreed to make 63 | future release tags the same as the internal version number. At that point 64 | the watch file will work. 65 | 66 | -- Ondřej Surý >, Tue, 21 Jul 2020 16:31:52 +0200 67 | -------------------------------------------------------------------------------- /distro/pkg/deb/changelog: -------------------------------------------------------------------------------- 1 | libyang3 ({{ version }}-{{ release }}) unstable; urgency=medium 2 | 3 | * upstream packaging 4 | 5 | -- Ondřej Surý Tue, 04 May 2021 22:20:03 +0200 6 | -------------------------------------------------------------------------------- /distro/pkg/deb/compat: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /distro/pkg/deb/gbp.conf: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | pristine-tar = False 3 | debian-branch = master 4 | upstream-tree = SLOPPY 5 | -------------------------------------------------------------------------------- /distro/pkg/deb/libyang-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/libyang/*.h 2 | usr/lib/*/*.so 3 | usr/lib/*/pkgconfig/*.pc 4 | -------------------------------------------------------------------------------- /distro/pkg/deb/libyang-modules.install: -------------------------------------------------------------------------------- 1 | usr/share/yang/modules/libyang 2 | -------------------------------------------------------------------------------- /distro/pkg/deb/libyang-tools.examples: -------------------------------------------------------------------------------- 1 | tools/lint/examples/* 2 | -------------------------------------------------------------------------------- /distro/pkg/deb/libyang-tools.install: -------------------------------------------------------------------------------- 1 | usr/bin/yanglint 2 | usr/bin/yangre 3 | usr/share/man/man1 4 | -------------------------------------------------------------------------------- /distro/pkg/deb/libyang3.install: -------------------------------------------------------------------------------- 1 | usr/lib/*/*.so.* 2 | -------------------------------------------------------------------------------- /distro/pkg/deb/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | #export DH_VERBOSE=1 3 | export DEB_BUILD_MAINT_OPTIONS = hardening=+all 4 | 5 | include /usr/share/dpkg/default.mk 6 | 7 | %: 8 | dh $@ 9 | 10 | override_dh_auto_configure: 11 | dh_auto_configure -- \ 12 | -DCMAKE_BUILD_TYPE:String="Release" 13 | -------------------------------------------------------------------------------- /distro/pkg/deb/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /distro/pkg/deb/tests/control: -------------------------------------------------------------------------------- 1 | Tests: yanglint 2 | Depends: gzip, 3 | libyang-tools 4 | -------------------------------------------------------------------------------- /distro/pkg/deb/tests/yanglint: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | # Setup the test file 6 | trap 'rm -f "${TESTFILE}"; rmdir "${TESTDIR}"' EXIT 7 | TESTDIR=$(mktemp -d /tmp/yanglint.XXXXXX) 8 | TESTFILE="${TESTDIR}/ietf-interfaces.yang" 9 | 10 | # Unpack or copy the test file 11 | if test -f /usr/share/doc/libyang-tools/examples/ietf-interfaces.yang.gz; then 12 | gunzip -c < /usr/share/doc/libyang-tools/examples/ietf-interfaces.yang.gz > "${TESTFILE}" 13 | else 14 | cp /usr/share/doc/libyang-tools/examples/ietf-interfaces.yang "${TESTFILE}" 15 | fi 16 | 17 | # Lint the test file 18 | yanglint "${TESTFILE}" 19 | -------------------------------------------------------------------------------- /distro/pkg/deb/watch: -------------------------------------------------------------------------------- 1 | version=4 2 | opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%libyang-$1.tar.gz%" \ 3 | https://github.com/CESNET/libyang/releases \ 4 | (?:.*?/)?v?(\d[\d.]*)(?:-r\d+)?\.tar\.gz debian uupdate 5 | -------------------------------------------------------------------------------- /distro/scripts/make-archive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # create archive from current source using git 3 | 4 | VERSION=$(git log --oneline -n1 --grep="^VERSION" | rev | cut -d' ' -f1 | rev) 5 | 6 | NAMEVER=libyang-$VERSION 7 | ARCHIVE=$NAMEVER.tar.gz 8 | 9 | git archive --format tgz --output $ARCHIVE --prefix $NAMEVER/ HEAD 10 | mkdir -p pkg/archives/dev/ 11 | mv $ARCHIVE pkg/archives/dev/ 12 | 13 | # apkg expects stdout to list archive files 14 | echo pkg/archives/dev/$ARCHIVE 15 | -------------------------------------------------------------------------------- /distro/scripts/upstream-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # get latest upstream libyang version from github 3 | 4 | RLS_URL=https://api.github.com/repos/CESNET/libyang/releases 5 | VERSION=$(curl -s $RLS_URL | grep tag_name | cut -d '"' -f 4 | sort --version-sort | tail -n 1) 6 | VERSION=${VERSION#v} 7 | echo $VERSION 8 | -------------------------------------------------------------------------------- /distro/tests/control: -------------------------------------------------------------------------------- 1 | Tests: test-pkg-config.sh test-yanglint.sh 2 | -------------------------------------------------------------------------------- /distro/tests/test-pkg-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ex 3 | 4 | version=`pkg-config --modversion libyang` 5 | echo "$version" | grep '2\.[0-9.]\+' 6 | -------------------------------------------------------------------------------- /distro/tests/test-yanglint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ex 3 | 4 | version=`yanglint --version` 5 | echo "$version" | grep '2\.[0-9.]\+' 6 | -------------------------------------------------------------------------------- /doc/cesnet-style.css: -------------------------------------------------------------------------------- 1 | /* CESNET blue: #0068a2 */ 2 | 3 | body { 4 | background-color: #fff; 5 | } 6 | 7 | div.header { 8 | background-image: none; 9 | background-color: #fff; 10 | } 11 | 12 | div.contents { 13 | background-color: #fff; 14 | padding: 1.618em 3.236em; 15 | max-width: 60em; 16 | margin: auto; 17 | margin-left: 0; 18 | text-align: justify; 19 | } 20 | 21 | .sm-dox { 22 | background-image: none; 23 | background-color: #0068a2; 24 | border-bottom: 1px solid white; 25 | } 26 | 27 | .sm-dox a { 28 | background-image: none; 29 | border-right: 1px solid white; 30 | color: white; 31 | text-shadow: none; 32 | } 33 | 34 | .sm-dox a:hover { 35 | background-image: none; 36 | background-color: rgba(0,0,0,0.3); 37 | } 38 | 39 | .sm-dox ul a:hover { 40 | background-image: none; 41 | background-color: #ddd; 42 | text-shadow: none; 43 | color: #555; 44 | } 45 | 46 | .navpath ul { 47 | background-image: none; 48 | background-color: #0068a2; 49 | } 50 | 51 | .navpath li.footer { 52 | color: white; 53 | } 54 | img.footer { 55 | height: 20px; 56 | } 57 | 58 | .navpath li.navelem a { 59 | color: white; 60 | text-shadow: none; 61 | } 62 | 63 | #side-nav { 64 | background-color: #343131; 65 | } 66 | 67 | #nav-tree::-webkit-scrollbar { 68 | width: 5px; 69 | } 70 | 71 | #nav-tree::-webkit-scrollbar-track { 72 | background: #333; 73 | border-radius: 50px; 74 | } 75 | 76 | #nav-tree::-webkit-scrollbar-thumb { 77 | background: #ccc; 78 | border-radius: 50px; 79 | } 80 | 81 | #nav-tree { 82 | background: none; 83 | } 84 | 85 | #nav-tree .item { 86 | padding-top: 10px; 87 | padding-bottom: 10px; 88 | } 89 | 90 | #nav-tree .item:hover { 91 | background-color: rgba(255,255,255,0.2); 92 | } 93 | 94 | #nav-tree a { 95 | color: #fff; 96 | font-size: 1.2em; 97 | } 98 | 99 | #nav-tree .selected { 100 | background-image: none; 101 | background-color: #0068a2; 102 | } 103 | 104 | #nav-tree-contents { 105 | margin: 0; 106 | } 107 | -------------------------------------------------------------------------------- /doc/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CESNET/libyang/da7272e19d9e27d1bfdd68108fa9dce25fbdf5e8/doc/logo.png -------------------------------------------------------------------------------- /libyang.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 3 | libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | 5 | Name: @PROJECT_NAME@ 6 | Description: @LIBYANG_DESCRIPTION@ 7 | Version: @LIBYANG_VERSION@ 8 | Requires.private: libpcre2-8 9 | Libs: -L${libdir} -lyang 10 | Libs.private: -lpcre2-8 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /src/diff.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file diff.h 3 | * @author Michal Vasko 4 | * @brief internal diff header 5 | * 6 | * Copyright (c) 2020 - 2025 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 | #ifndef LY_DIFF_H_ 16 | #define LY_DIFF_H_ 17 | 18 | #include 19 | 20 | #include "log.h" 21 | 22 | struct lyd_node; 23 | 24 | /** 25 | * @brief Internal structure for storing current (virtual) user-ordered instances order. 26 | */ 27 | struct lyd_diff_userord { 28 | const struct lysc_node *schema; /**< User-ordered list/leaf-list schema node. */ 29 | uint64_t pos; /**< Current position in the second tree. */ 30 | const struct lyd_node **inst; /**< Sized array of current instance order. */ 31 | }; 32 | 33 | /** 34 | * @brief Diff operations. 35 | */ 36 | enum lyd_diff_op { 37 | LYD_DIFF_OP_CREATE, /**< Subtree created. */ 38 | LYD_DIFF_OP_DELETE, /**< Subtree deleted. */ 39 | LYD_DIFF_OP_REPLACE, /**< Node value changed or (leaf-)list instance moved. */ 40 | LYD_DIFF_OP_NONE /**< No change of an existing inner node or default flag change of a term node. */ 41 | }; 42 | 43 | /** 44 | * @brief Add a new change into diff. 45 | * 46 | * @param[in] node Node (subtree) to add into diff. 47 | * @param[in] op Operation to set. 48 | * @param[in] orig_default Original default metadata to set. 49 | * @param[in] orig_value Original value metadata to set. 50 | * @param[in] key Key metadata to set. 51 | * @param[in] value Value metadata to set. 52 | * @param[in] position Position metadata to set. 53 | * @param[in] orig_key Original key metadata to set. 54 | * @param[in] orig_position Original position metadata to set. 55 | * @param[in,out] diff Diff to append to. 56 | * @param[out] diff_node Optional created diff node. 57 | * @return LY_ERR value. 58 | */ 59 | LIBYANG_API_DECL LY_ERR lyd_diff_add(const struct lyd_node *node, enum lyd_diff_op op, const char *orig_default, 60 | const char *orig_value, const char *key, const char *value, const char *position, const char *orig_key, 61 | const char *orig_position, struct lyd_node **diff, struct lyd_node **diff_node); 62 | 63 | #endif /* LY_DIFF_H_ */ 64 | -------------------------------------------------------------------------------- /src/in_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file in_internal.h 3 | * @author Radek Krejci 4 | * @author Michal Vasko 5 | * @brief Internal structures and functions for libyang parsers 6 | * 7 | * Copyright (c) 2020 - 2023 CESNET, z.s.p.o. 8 | * 9 | * This source code is licensed under BSD 3-Clause License (the "License"). 10 | * You may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * https://opensource.org/licenses/BSD-3-Clause 14 | */ 15 | 16 | #ifndef LY_IN_INTERNAL_H_ 17 | #define LY_IN_INTERNAL_H_ 18 | 19 | #include "in.h" 20 | 21 | /** 22 | * @brief Parser input structure specifying where the data are read. 23 | */ 24 | struct ly_in { 25 | LY_IN_TYPE type; /**< type of the output to select the output method */ 26 | const char *current; /**< Current position in the input data */ 27 | const char *func_start; /**< Input data position when the last parser function was executed */ 28 | const char *start; /**< Input data start */ 29 | size_t length; /**< mmap() length (if used) */ 30 | 31 | union { 32 | int fd; /**< file descriptor for LY_IN_FD type */ 33 | FILE *f; /**< file structure for LY_IN_FILE and LY_IN_FILEPATH types */ 34 | 35 | struct { 36 | int fd; /**< file descriptor for LY_IN_FILEPATH */ 37 | char *filepath; /**< stored original filepath */ 38 | } fpath; /**< filepath structure for LY_IN_FILEPATH */ 39 | } method; /**< type-specific information about the output */ 40 | uint64_t line; /**< current line of the input */ 41 | }; 42 | 43 | /** 44 | * @brief Increment line counter. 45 | * @param[in] IN The input handler. 46 | */ 47 | #define LY_IN_NEW_LINE(IN) \ 48 | (IN)->line++ 49 | 50 | #endif /* LY_IN_INTERNAL_H_ */ 51 | -------------------------------------------------------------------------------- /src/ly_config.h.in: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ly_config.h 3 | * @author Radek Krejci 4 | * @uathor Michal Vasko 5 | * @brief Various variables provided by cmake and compile time options. 6 | * 7 | * Copyright (c) 2021 - 2024 CESNET, z.s.p.o. 8 | * 9 | * This source code is licensed under BSD 3-Clause License (the "License"). 10 | * You may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * https://opensource.org/licenses/BSD-3-Clause 14 | */ 15 | 16 | #ifndef LY_CONFIG_H_ 17 | #define LY_CONFIG_H_ 18 | 19 | #ifdef _WIN32 20 | /* headers are broken on Windows, which means that some of them simply *have* to come first */ 21 | # include 22 | # include 23 | #endif 24 | 25 | /** size of fixed_mem in lyd_value, minimum is 8 (B) */ 26 | #define LYD_VALUE_FIXED_MEM_SIZE @LYD_VALUE_SIZE@ 27 | 28 | /** plugins */ 29 | #define LYPLG_SUFFIX "@CMAKE_SHARED_MODULE_SUFFIX@" 30 | #define LYPLG_SUFFIX_LEN (sizeof LYPLG_SUFFIX - 1) 31 | #define LYPLG_TYPE_DIR "@PLUGINS_DIR_TYPES@" 32 | #define LYPLG_EXT_DIR "@PLUGINS_DIR_EXTENSIONS@" 33 | 34 | /** atomic compiler operations, to be able to use uint32_t */ 35 | #ifndef _WIN32 36 | # define LY_ATOMIC_INC_BARRIER(var) __sync_fetch_and_add(&(var), 1) 37 | # define LY_ATOMIC_DEC_BARRIER(var) __sync_fetch_and_sub(&(var), 1) 38 | #else 39 | # include 40 | # define LY_ATOMIC_INC_BARRIER(var) InterlockedExchangeAdd(&(var), 1) 41 | # define LY_ATOMIC_DEC_BARRIER(var) InterlockedExchangeAdd(&(var), -1) 42 | #endif 43 | 44 | /** printf compiler attribute */ 45 | #ifdef __GNUC__ 46 | # define _FORMAT_PRINTF(FORM, ARGS) __attribute__((format (printf, FORM, ARGS))) 47 | #else 48 | # define _FORMAT_PRINTF(FORM, ARGS) 49 | #endif 50 | 51 | /** Exporting symbols to a shared library and importing back afterwards 52 | * 53 | * - use LIBYANG_API_DECL to mark a declaration in the public header 54 | * - use LIBYANG_API_DEF to mark a definition (in the source code for the actual implementaiton) 55 | * */ 56 | #ifdef _MSC_VER 57 | # ifndef STATIC 58 | # define LIBYANG_API_DEF __declspec(dllexport) 59 | # ifdef LIBYANG_BUILD 60 | # define LIBYANG_API_DECL __declspec(dllexport) 61 | # else 62 | # define LIBYANG_API_DECL __declspec(dllimport) 63 | # endif 64 | # endif 65 | #else 66 | /* 67 | * If the compiler supports attribute to mark objects as hidden, mark all 68 | * objects as hidden and export only objects explicitly marked to be part of 69 | * the public API. 70 | */ 71 | # define LIBYANG_API_DEF __attribute__((visibility("default"))) 72 | # define LIBYANG_API_DECL 73 | #endif 74 | 75 | #endif /* LY_CONFIG_H_ */ 76 | -------------------------------------------------------------------------------- /src/plugins_exts/metadata.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file metadata.h 3 | * @author Radek Krejci 4 | * @author Michal Vasko 5 | * @brief ietf-yang-metadata API 6 | * 7 | * Copyright (c) 2019 - 2022 CESNET, z.s.p.o. 8 | * 9 | * This source code is licensed under BSD 3-Clause License (the "License"). 10 | * You may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * https://opensource.org/licenses/BSD-3-Clause 14 | */ 15 | 16 | #ifndef LY_PLUGINS_EXTS_METADATA_H_ 17 | #define LY_PLUGINS_EXTS_METADATA_H_ 18 | 19 | #include "plugins_exts.h" 20 | #include "tree_data.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * @brief Metadata structure. 28 | * 29 | * The structure provides information about metadata of a data element. Such attributes must map to 30 | * annotations as specified in RFC 7952. The only exception is the filter type (in NETCONF get operations) 31 | * and edit-config's operation attributes. In XML, they are represented as standard XML attributes. In JSON, 32 | * they are represented as JSON elements starting with the '@' character (for more information, see the 33 | * YANG metadata RFC. 34 | * 35 | */ 36 | struct lyd_meta { 37 | struct lyd_node *parent; /**< data node where the metadata is placed */ 38 | struct lyd_meta *next; /**< pointer to the next metadata of the same element */ 39 | struct lysc_ext_instance *annotation; /**< pointer to the annotation's definition */ 40 | const char *name; /**< metadata name */ 41 | struct lyd_value value; /**< metadata value representation */ 42 | }; 43 | 44 | /** 45 | * @brief Get the (canonical) value of a metadata node. 46 | * 47 | * @param[in] meta Metadata node to use. 48 | * @return Canonical value. 49 | */ 50 | static inline const char * 51 | lyd_get_meta_value(const struct lyd_meta *meta) 52 | { 53 | if (meta) { 54 | const struct lyd_value *value = &meta->value; 55 | 56 | return value->_canonical ? value->_canonical : lyd_value_get_canonical(meta->annotation->module->ctx, value); 57 | } 58 | 59 | return NULL; 60 | } 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* LY_PLUGINS_EXTS_METADATA_H_ */ 67 | -------------------------------------------------------------------------------- /src/schema_features.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file schema_features.h 3 | * @author Michal Vasko 4 | * @brief Header for schema features. 5 | * 6 | * Copyright (c) 2015 - 2020 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 | #ifndef LY_SCHEMA_FEATURES_H_ 16 | #define LY_SCHEMA_FEATURES_H_ 17 | 18 | #include "log.h" 19 | 20 | struct ly_ctx; 21 | struct lysp_module; 22 | struct lysp_qname; 23 | 24 | /** 25 | * @brief Evaluate if-features array. 26 | * 27 | * @param[in] ctx libyang context. 28 | * @param[in] iffeatures Sized array of if-features to evaluate. 29 | * @param[out] enabled Whether if-features evaluated to true or false. 30 | * @return LY_SUCCESS on success. 31 | * @return LY_ERR on error. 32 | */ 33 | LY_ERR lys_eval_iffeatures(const struct ly_ctx *ctx, const struct lysp_qname *iffeatures, ly_bool *enabled); 34 | 35 | /** 36 | * @brief Check whether all enabled features have their if-features satisfied. 37 | * 38 | * @param[in] pmod Parsed module features to check. 39 | * @return LY_SUCCESS on success. 40 | * @return LY_EDENIED if there was an enabled feature with disabled if-feature. 41 | */ 42 | LY_ERR lys_check_features(const struct lysp_module *pmod); 43 | 44 | /** 45 | * @brief Set the specified features of a parsed module ignoring their own if-features. These are all checked before 46 | * compiling the module(s). 47 | * 48 | * @param[in] pmod Parsed module to modify. 49 | * @param[in] features Array of features ended with NULL to be enabled if the module is being implemented. 50 | * The feature string '*' enables all and array of length 1 with only the terminating NULL explicitly disables all 51 | * the features. In case the parameter is NULL, the features are untouched - left disabled in newly loaded module or 52 | * with the current features settings in case the module is already present in the context. 53 | * @return LY_SUCCESS on success. 54 | * @return LY_EEXIST if the specified features were already set. 55 | * @return LY_ERR on error. 56 | */ 57 | LY_ERR lys_set_features(struct lysp_module *pmod, const char **features); 58 | 59 | /** 60 | * @brief Compile if-features of features in the provided module and all its submodules. 61 | * 62 | * @param[in] pmod Parsed module to process. 63 | * @return LY_ERR value. 64 | */ 65 | LY_ERR lys_compile_feature_iffeatures(struct lysp_module *pmod); 66 | 67 | #endif /* LY_SCHEMA_FEATURES_H_ */ 68 | -------------------------------------------------------------------------------- /src/version.h.in: -------------------------------------------------------------------------------- 1 | /** 2 | * @file version.h 3 | * @author Radek Krejci 4 | * @author Michal Vasko 5 | * @brief libyang version definitions 6 | * 7 | * Copyright (c) 2020 - 2024 CESNET, z.s.p.o. 8 | * 9 | * This source code is licensed under BSD 3-Clause License (the "License"). 10 | * You may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * https://opensource.org/licenses/BSD-3-Clause 14 | */ 15 | 16 | #ifndef LY_VERSION_H_ 17 | #define LY_VERSION_H_ 18 | 19 | #include "ly_config.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #define LY_VERSION_MAJOR @LIBYANG_MAJOR_SOVERSION@ /**< libyang major version number */ 26 | #define LY_VERSION_MINOR @LIBYANG_MINOR_SOVERSION@ /**< libyang minor version number */ 27 | #define LY_VERSION_MICRO @LIBYANG_MICRO_SOVERSION@ /**< libyang micro version number */ 28 | #define LY_VERSION "@LIBYANG_SOVERSION_FULL@" /**< libyang version string */ 29 | 30 | #define LY_PROJ_VERSION_MAJOR @LIBYANG_MAJOR_VERSION@ /**< project major version number */ 31 | #define LY_PROJ_VERSION_MINOR @LIBYANG_MINOR_VERSION@ /**< project minor version number */ 32 | #define LY_PROJ_VERSION_MICRO @LIBYANG_MICRO_VERSION@ /**< project micro version number */ 33 | #define LY_PROJ_VERSION "@LIBYANG_VERSION@" /**< project version string */ 34 | 35 | /** 36 | * @brief Get libyang major SO version. 37 | * 38 | * @return LY version. 39 | */ 40 | LIBYANG_API_DECL uint32_t ly_version_so_major(void); 41 | 42 | /** 43 | * @brief Get libyang minor SO version. 44 | * 45 | * @return LY version. 46 | */ 47 | LIBYANG_API_DECL uint32_t ly_version_so_minor(void); 48 | 49 | /** 50 | * @brief Get libyang micro SO version. 51 | * 52 | * @return LY version. 53 | */ 54 | LIBYANG_API_DECL uint32_t ly_version_so_micro(void); 55 | 56 | /** 57 | * @brief Get libyang string SO version. 58 | * 59 | * @return LY version. 60 | */ 61 | LIBYANG_API_DECL const char *ly_version_so_str(void); 62 | 63 | /** 64 | * @brief Get libyang major project version. 65 | * 66 | * @return LY version. 67 | */ 68 | LIBYANG_API_DECL uint32_t ly_version_proj_major(void); 69 | 70 | /** 71 | * @brief Get libyang minor project version. 72 | * 73 | * @return LY version. 74 | */ 75 | LIBYANG_API_DECL uint32_t ly_version_proj_minor(void); 76 | 77 | /** 78 | * @brief Get libyang micro project version. 79 | * 80 | * @return LY version. 81 | */ 82 | LIBYANG_API_DECL uint32_t ly_version_proj_micro(void); 83 | 84 | /** 85 | * @brief Get libyang string project version. 86 | * 87 | * @return LY version. 88 | */ 89 | LIBYANG_API_DECL const char *ly_version_proj_str(void); 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /* LY_VERSION_H_ */ 96 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Correct RPATH usage on OS X 2 | set(CMAKE_MACOSX_RPATH TRUE) 3 | 4 | configure_file("${PROJECT_SOURCE_DIR}/tests/tests_config.h.in" "${PROJECT_BINARY_DIR}/tests/tests_config.h" ESCAPE_QUOTES @ONLY) 5 | include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR}) 6 | include_directories(${PROJECT_BINARY_DIR}/tests/) 7 | 8 | function(ly_add_utest) 9 | cmake_parse_arguments(ADDTEST "" "NAME;WRAP" "SOURCES" ${ARGN}) 10 | set(TEST_NAME utest_${ADDTEST_NAME}) 11 | 12 | foreach(TEST_SOURCE ${ADDTEST_SOURCES}) 13 | list(APPEND TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SOURCE}) 14 | endforeach() 15 | 16 | add_executable(${TEST_NAME} ${TEST_SOURCES} $) 17 | target_compile_definitions(${TEST_NAME} PRIVATE LIBYANG_BUILD) 18 | 19 | # Set common attributes of all tests 20 | set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") 21 | target_link_libraries(${TEST_NAME} ${CMOCKA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS}) 22 | if (NOT WIN32) 23 | target_link_libraries(${TEST_NAME} m) 24 | else() 25 | target_link_libraries(${TEST_NAME} ${COMPAT_WIN_LIBRARIES}) 26 | endif() 27 | if (NOT APPLE) 28 | if (ADDTEST_WRAP) 29 | set_target_properties(${TEST_NAME} PROPERTIES LINK_FLAGS "${ADDTEST_WRAP}") 30 | endif() 31 | endif() 32 | 33 | if (XXHASH_FOUND) 34 | target_link_libraries(${TEST_NAME} ${XXHASH_LIBRARY}) 35 | endif() 36 | add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) 37 | set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "MALLOC_CHECK_=3") 38 | 39 | if(ENABLE_VALGRIND_TESTS) 40 | add_test(${TEST_NAME}_valgrind valgrind --leak-check=full --show-leak-kinds=all --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp --error-exitcode=1 ${CMAKE_BINARY_DIR}/tests/${TEST_NAME}) 41 | endif() 42 | endfunction() 43 | 44 | if(ENABLE_TESTS) 45 | add_subdirectory(plugins) 46 | add_subdirectory(utests) 47 | if(NOT WIN32) 48 | add_subdirectory(style) 49 | add_subdirectory(fuzz) 50 | endif() 51 | add_subdirectory(yanglint) 52 | add_subdirectory(yangre) 53 | endif() 54 | if(ENABLE_PERF_TESTS) 55 | add_subdirectory(perf) 56 | endif() 57 | 58 | set(format_sources ${format_sources} PARENT_SCOPE) 59 | -------------------------------------------------------------------------------- /tests/fuzz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(ENABLE_FUZZ_TARGETS) 2 | set(fuzz_targets lys_parse_mem lyd_parse_mem_xml lyd_parse_mem_json yang_parse_module) 3 | 4 | if(FUZZER STREQUAL "AFL") 5 | foreach(target_name IN LISTS fuzz_targets) 6 | add_executable(${target_name}_fuzz_harness ${target_name}.c main.c) 7 | target_link_libraries(${target_name}_fuzz_harness yang) 8 | endforeach() 9 | elseif() 10 | foreach(target_name IN LISTS fuzz_targets) 11 | add_executable(${target_name}_fuzz_harness ${target_name}.c) 12 | set_source_files_properties(${target_name}.c PROPERTIES COMPILE_FLAGS "-fsanitize=fuzzer") 13 | target_link_libraries(${target_name}_fuzz_harness yang "-fsanitize=fuzzer") 14 | endforeach() 15 | endif() 16 | endif() 17 | 18 | if(ENABLE_TESTS) 19 | add_executable(fuzz_regression_test fuzz_regression_test.c) 20 | set(fuzz_regression_tests lys_parse_mem lyd_parse_mem_xml lyd_parse_mem_json) 21 | foreach(target_name IN LISTS fuzz_regression_tests) 22 | file(COPY ${CMAKE_SOURCE_DIR}/tests/fuzz/corpus/${target_name} DESTINATION ${CMAKE_BINARY_DIR}/tests/fuzz/) 23 | add_executable(regress_fuzz_${target_name} ${target_name}.c main.c) 24 | set_target_properties(regress_fuzz_${target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests/fuzz/${target_name}") 25 | target_link_libraries(regress_fuzz_${target_name} yang) 26 | add_test(NAME regress_fuzz_${target_name} COMMAND fuzz_regression_test regress_fuzz_${target_name} . WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fuzz/${target_name}) 27 | endforeach() 28 | endif() 29 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull11438: -------------------------------------------------------------------------------- 1 | {"0R:0::809e-47,-689e-47,-689e-489e-47":[809e-47,-689e-47,-689e-4709e-47,-689e-47,-689e-489e-47":[809e-47,-689e-47,-689e-47647,-688Je7,-6889e647,-688Je7,-6889e-47" -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1203: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1269: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1269_2: -------------------------------------------------------------------------------- 1 | [[], []] 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1280: -------------------------------------------------------------------------------- 1 | "\u1 -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1347_number: -------------------------------------------------------------------------------- 1 | {"200 -11-10T23:00:00Z": 1E+2} 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1347_strings: -------------------------------------------------------------------------------- 1 | {"200 -11-10T23:00:00Z": "hello w\rld"}, 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1348: -------------------------------------------------------------------------------- 1 | "a\tHt\\\\HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH(HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHXHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH\\\\\\\\\" 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1460: -------------------------------------------------------------------------------- 1 | "viøonisionp\u\ -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1460_2: -------------------------------------------------------------------------------- 1 | "viøonisionp\uGAAA" 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1571: -------------------------------------------------------------------------------- 1 | {"@types:uint32":{"typus:@uint32":1,"typus:@uint32":2,"typJs:uint32":3}} 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1585: -------------------------------------------------------------------------------- 1 | {"@types:uint32":{"@":{"ns:int32":{"a":[1 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1626: -------------------------------------------------------------------------------- 1 | {"@types:uint32":{"@":{">:1,":9,"\\\\\\\\\\:2,":8,":3,":7,":-402 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1693: -------------------------------------------------------------------------------- 1 | {"types:cont":{"":"","":{}}} -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1696_1: -------------------------------------------------------------------------------- 1 | {"types:cont":{"leaflt30,1,10,2]xxnt32":1,"types:uint":1,"types:uinis2":922337203685477}} -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_json/pull1696_2: -------------------------------------------------------------------------------- 1 | {"types:cont":{"leaflt30,1,GGGGGGGGGGGGGGGGGGGGGGGGGGGGG10,2]xxnt32":1,"types:ui~t":1,"types:uinis2":922337203685477}} -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_xml/issue1074: -------------------------------------------------------------------------------- 1 | 2 | x 3 | 1 4 | 5 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_xml/issue1131: -------------------------------------------------------------------------------- 1 | s=""?> 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_xml/issue1132: -------------------------------------------------------------------------------- 1 | ��/doc> oc> 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lyd_parse_mem_xml/pull1529: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue1004.yang: -------------------------------------------------------------------------------- 1 | module a { 2 | yang-version 1.1; 3 | namespace "a"; 4 | prefix a; 5 | 6 | leaf-list A { 7 | type pt8; 8 | default 0; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue1025.yang: -------------------------------------------------------------------------------- 1 | module a { 2 | yang-version 1.1; 3 | namespace "urn:all"; 4 | prefix all_mod; 5 | 6 | grouping group1 { 7 | leaf leaf1 { 8 | type int64 { 9 | range "1000 .. 50000" { 10 | error:message 11 | "Spec"; 12 | } 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue1027.yang: -------------------------------------------------------------------------------- 1 | module d{ 2 | namespace ""; 3 | prefix d; 4 | leaf f { 5 | type string; 6 | must ":e"; 7 | default ""; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue1040.yang: -------------------------------------------------------------------------------- 1 | module a { 2 | namespace "a"; 3 | prefix a; 4 | 5 | container c { 6 | leaf r { 7 | type leafref{ 8 | path "../p"; 9 | } 10 | default false; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue1041.yang: -------------------------------------------------------------------------------- 1 | module foo { 2 | namespace foo; 3 | prefix foo; 4 | yang-version 1.1; 5 | 6 | container root { 7 | } 8 | container top { 9 | notification top-notification { 10 | } 11 | } 12 | 13 | list top-list { 14 | key key-leaf; 15 | 16 | leaf key-leaf { 17 | type string; 18 | } 19 | 20 | notification top-list-notification { 21 | } 22 | } 23 | 24 | grouping grp { 25 | notification grp-notification { 26 | } 27 | } 28 | 29 | augment "/root" { 30 | uses grp; 31 | notification aug-notification { 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue1042_base-yang-types.yang: -------------------------------------------------------------------------------- 1 | module issue1042_base-yang-types { 2 | yang-version 1.1; 3 | namespace "urn:opendaylight:org:test:base:yang:types"; 4 | prefix "tp"; 5 | 6 | typedef yang-boolean { 7 | type boolean; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue1042_test-type-provider-b.yang: -------------------------------------------------------------------------------- 1 | module issue1042_test-type-provider-b { 2 | yang-version 1.1; 3 | namespace "urn:opendaylight:org:test:type:provider:b:model"; 4 | prefix "tp"; 5 | 6 | import issue1042_test-type-provider { prefix prov; } 7 | 8 | leaf id { 9 | type leafref { 10 | path "/prov:foo/prov:bars/prov:bar-item/prov:id"; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue1042_test-type-provider.yang: -------------------------------------------------------------------------------- 1 | module issue1042_test-type-provider { 2 | yang-version 1.1; 3 | namespace "urn:opendaylight:org:test:type:provider:model"; 4 | prefix "tp"; 5 | 6 | import issue1042_base-yang-types { prefix types; } 7 | 8 | container construction-type-test { 9 | leaf yang-boolean { 10 | type types:yang-boolean; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue1043.yang: -------------------------------------------------------------------------------- 1 | module SUPf-entity { 2 | yang-version 1.1; 3 | namespace "urn:ietf:params:xml:ns:yang:ietf-entity"; 4 | prefix ent; 5 | 6 | grouping ROLLBACK-ATTRIBUTES { leaf force { 7 | when "9./best-efmmmmmmmmmmmmmmmmmmmmm|mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmfort = 'falsq'" { 8 | } 9 | type boolean; 10 | default "false"; 11 | } 12 | leaf best-effort { 13 | when ". 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue740.yang: -------------------------------------------------------------------------------- 1 | module xpath-1.1 { 2 | namespace "urn:xpath-1.1"; 3 | prefix xp; 4 | 5 | container top { 6 | leaf identref { 7 | type mdentityref { 8 | base:iwo; 9 | pattern '[A-Z]+'; 10 | pattern '[A-Z]+'; 11 | pattern '[A-Z]+'; 12 | pattern '[A-Z]+'; 13 | pattern '[./key2, 2, 3), 'a') and not(starts-with(./key2, 'a')))"; 14 | } 15 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue741.yang: -------------------------------------------------------------------------------- 1 | module mod6 { 2 | prefix adc; 3 | namespace "http://www.example.com"; 4 | 5 | grouping g { 6 | list ll { 7 | leaf:date { 8 | type string; 9 | } 10 | } 11 | } 12 | 13 | container ccc { 14 | uses g; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue742.yang: -------------------------------------------------------------------------------- 1 | module links { 2 | yang-version 1.1; 3 | namespace "urn:mo:1"; 4 | prefix yang; 5 | 6 | import ietf-yang-metadata { 7 | prefix md; 8 | revision-date 2016-08-05; 9 | } 10 | 11 | md:annotation value { 12 | reference "RFC7950 section 7.7.9."; 13 | description; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue769.yang: -------------------------------------------------------------------------------- 1 | module mod6 { 2 | 3 | prefix abc; 4 | namespace "http://www.example.c; 5 | yang-version 1.1; 6 | 7 | container cont1 { 8 | //x" { 9 | 10 | } 11 | 12 | augment "/aug-cont" { 13 | list list2 { 14 | key "key2"; 15 | leaf key2 { 16 | type string; 17 | } 18 | } 19 | notification nn { 20 | typedef Mt { 21 | type string { 22 | length "1..255"; 23 | } 24 | } 25 | 26 | container log { 27 | grouping g { 28 | notification nn { 29 | type j2an; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue771.yang: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CESNET/libyang/da7272e19d9e27d1bfdd68108fa9dce25fbdf5e8/tests/fuzz/corpus/lys_parse_mem/issue771.yang -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue772.yang: -------------------------------------------------------------------------------- 1 | module all { 2 | yang-version 1.1; 3 | namespace "urn:all"; 4 | prefix all_mod; 5 | 6 | grouping t1 { 7 | uses group1 { 8 | } 9 | 10 | leaf leaf12 { 11 | type bits { 12 | bit flag0 { 13 | position 0; 14 | if-feature "feat1"; 15 | } 16 | bit flag1; 17 | bit flag2 { 18 | position 2; 19 | } 20 | 21 | bit flag3 { 22 | position 3; 23 | } 24 | } 25 | default "flag0 flag3"; 26 | } 27 | 28 | list list1 { 29 | key "leaf18"; 30 | unique "leaf1--------------------------------------------------- leaf leaT18 { 31 | type string; 32 | } 33 | 34 | 35 | action act1 { 36 | input ons on thg leaf"; 37 | leaf leaf30 { 38 | type string; 39 | } 40 | } 41 | } 42 | 43 | augment "/cont1" { 44 | leaf leaf17 { 45 | type ideZtityref { 46 | base all_imp:iden44; 47 | } 48 | must "../leaf17 = 'all_imp:iden } 49 | 50 | action act1 { 51 | t5'"; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue773.yang: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CESNET/libyang/da7272e19d9e27d1bfdd68108fa9dce25fbdf5e8/tests/fuzz/corpus/lys_parse_mem/issue773.yang -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue774.yang: -------------------------------------------------------------------------------- 1 | module state-lists { 2 | yang-version 1.1; 3 | namespace "urn:state-lists"; 4 | prefix sl; 5 | 6 | container cont { 7 | config false; 8 | grouping group1 { 9 | leaf leaf3 { 10 | type tdef2 { 11 | length "3..9 | 30..40"; 12 | pattern "[ac 13 | }*"; 14 | } 15 | 16 | units "none"; 17 | default "aaa"; 18 | } 19 | 20 | typedef tdef2 { 21 | type string { 22 | length "2..17 | 20..50"; 23 | pattern "[ab]*"; 24 | } 25 | } 26 | 27 | container cont1 { 28 | uses group1 { 29 | if-feature "feat2"; 30 | refine "leaf1" { 31 | if-feature "feat3"; 32 | must "24 - 4 = number('20')"; 33 | default "25"; 34 | config true; 35 | mandatory false; 36 | description "dsc"; 37 | reference "none"; 38 | } 39 | } 40 | 41 | leaf leaf4 { 42 | type int64 { 43 | range "1000 .. 50000" { 44 | error-message 45 | "Special e 46 | } 47 | ."; 48 | } 49 | } 50 | } 51 | 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue777.yang: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CESNET/libyang/da7272e19d9e27d1bfdd68108fa9dce25fbdf5e8/tests/fuzz/corpus/lys_parse_mem/issue777.yang -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue780.yang: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CESNET/libyang/da7272e19d9e27d1bfdd68108fa9dce25fbdf5e8/tests/fuzz/corpus/lys_parse_mem/issue780.yang -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue788.yang: -------------------------------------------------------------------------------- 1 | module d00000000 { 2 | namespace "n"; 3 | prefix d; 4 | leaf l1 { 5 | type string; 6 | when "/l0{k='when']"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue789.yang: -------------------------------------------------------------------------------- 1 | module m { 2 | prefix p; 3 | namespace "n"; 4 | grouping g { 5 | } 6 | 7 | grouping s { 8 | uses g; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue791.yang: -------------------------------------------------------------------------------- 1 | module m { 2 | include "" 3 | } 4 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue791_2.yang: -------------------------------------------------------------------------------- 1 | module m { 2 | namespace "n"; 3 | prefix p; 4 | 5 | container c { 6 | leaf trg-bits { 7 | type bits { 8 | bit b1; 9 | bit ""; 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue795.yang: -------------------------------------------------------------------------------- 1 | module m { 2 | prefix p; 3 | namespace "n"; 4 | list l { 5 | must ""; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue804.yang: -------------------------------------------------------------------------------- 1 | module m { 2 | prefix p; 3 | namespace n; 4 | list l { 5 | if-feature 0(; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue805.yang: -------------------------------------------------------------------------------- 1 | module d{ 2 | namespace n; 3 | prefix p; 4 | list l { 5 | when ""; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue807.yang: -------------------------------------------------------------------------------- 1 | module d{ 2 | namespace ""; 3 | prefix d; 4 | leaf f { 5 | type string; 6 | must "0e"; 7 | default ""; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue872.yang: -------------------------------------------------------------------------------- 1 | module d{ 2 | namespace "";prefix d; 3 | leaf f{ 4 | type w0iiiiiiiiiiiiiiiiiiiiiiiiiiiii0000; 5 | default ""; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue874.yang: -------------------------------------------------------------------------------- 1 | module o00 { prefix c; namespace "00t000000w0000p00000 2 | 00n000e0000n00000 3 | 4 | 0cANG m0dule de0in0s an 'exten0ion' s0atemns 5 | for defining 0etadat0 an0Copyri0ht (0) 2016 IE00 T0uct and th0 persons identifi4.0 of the IETF Tru0t0s Le0a0 P0ovi0i00s 6 | Relatin0 t0 IE0F D0cu0e0 of RFC 7 (/tru0te0.ietf0org0license-info0. 7 | 8 | Th0s ve00io0 of thi0 YA0G mod0le i0 pa't of RFC 78 (http:/0www-e0itor.!rg/info/0fc0902); see the 0FC i000lf 9 | f0r fodule, i ";revision 2016-08-05{ 10 | description 11 | "Initial revision."; 12 | reference "RFC 7952: Defining and 0sin0 0etada0a with YANG"; 13 | } 14 | 15 | extension annotation{ 16 | argument name; 17 | description "This extension allows f0r defietadat0tadata an00tation0 in 18 | YAN0 modules. 0he 0sion."; 19 | reference "RFC 7952: Defining and 0sin0 0etada0a with YANG"; 20 | } 21 | 22 | extension annotation{ 23 | argument name; 24 | description " YAN0 modules. 0he 0sion."; 25 | reference "RFC 7952: Defining and 0sin0 0etada0a with YANG"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/fuzz/corpus/lys_parse_mem/issue970.yang: -------------------------------------------------------------------------------- 1 | module p{ 2 | namespace ""; 3 | prefix p; 4 | 5 | container ports{ 6 | list port { 7 | key name; 8 | leaf name{ 9 | type string;} 10 | } 11 | } 12 | augment "/ports/port" { 13 | when "0 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char **argv) 11 | { 12 | DIR *d; 13 | struct dirent *dir; 14 | pid_t p = 0; 15 | int input_fd = 0; 16 | int status = 0; 17 | int rc = 0; 18 | struct stat path_stat; 19 | 20 | if (argc != 3) { 21 | fprintf(stderr, "invalid number of arguments. Call like this ./fuzz_regression_test fuzz_harness corpus_dir\n"); 22 | return EXIT_FAILURE; 23 | } 24 | 25 | d = opendir(argv[2]); 26 | if (!d) { 27 | fprintf(stderr, "error opening dir %s\n", argv[2]); 28 | return EXIT_FAILURE; 29 | } 30 | 31 | while ((dir = readdir(d)) != NULL) { 32 | stat(dir->d_name, &path_stat); 33 | if (!S_ISREG(path_stat.st_mode)) { 34 | continue; 35 | } 36 | 37 | p = fork(); 38 | if (p == -1) { 39 | fprintf(stderr, "fork failed\n"); 40 | return EXIT_FAILURE; 41 | } else if (p == 0) { 42 | input_fd = open(dir->d_name, O_RDONLY); 43 | if (input_fd == -1) { 44 | fprintf(stderr, "error opening input file %s\n", dir->d_name); 45 | return EXIT_FAILURE; 46 | } 47 | 48 | dup2(input_fd, STDIN_FILENO); 49 | execl(argv[1], argv[1], NULL); 50 | return EXIT_SUCCESS; 51 | } 52 | 53 | rc = waitpid(p, &status, 0); 54 | if (rc == -1) { 55 | fprintf(stderr, "waitpid failed\n"); 56 | return EXIT_FAILURE; 57 | } 58 | 59 | if (!WIFEXITED(status)) { 60 | fprintf(stderr, "test %s - %s failed\n", argv[1], dir->d_name); 61 | return EXIT_FAILURE; 62 | } 63 | 64 | printf("test %s - %s successful\n", argv[1], dir->d_name); 65 | } 66 | 67 | closedir(d); 68 | 69 | return EXIT_SUCCESS; 70 | } 71 | -------------------------------------------------------------------------------- /tests/fuzz/lys_parse_mem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "libyang.h" 6 | 7 | int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len) 8 | { 9 | struct ly_ctx *ctx = NULL; 10 | static bool log = false; 11 | char *data = NULL; 12 | LY_ERR err; 13 | 14 | if (!log) { 15 | ly_log_options(0); 16 | log = true; 17 | } 18 | 19 | err = ly_ctx_new(NULL, 0, &ctx); 20 | if (err != LY_SUCCESS) { 21 | fprintf(stderr, "Failed to create context\n"); 22 | exit(EXIT_FAILURE); 23 | } 24 | 25 | data = malloc(len + 1); 26 | if (data == NULL) { 27 | return 0; 28 | } 29 | 30 | memcpy(data, buf, len); 31 | data[len] = 0; 32 | 33 | lys_parse_mem(ctx, data, LYS_IN_YANG, NULL); 34 | ly_ctx_destroy(ctx); 35 | free(data); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /tests/fuzz/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len); 6 | 7 | #ifdef __AFL_COMPILER 8 | 9 | int main(void) { 10 | int ret; 11 | uint8_t buf[64 * 1024]; 12 | 13 | #ifdef __AFL_LOOP 14 | while (__AFL_LOOP(10000)) 15 | #endif 16 | { 17 | ret = fread(buf, 1, sizeof(buf), stdin); 18 | if (ret < 0) { 19 | return 0; 20 | } 21 | 22 | LLVMFuzzerTestOneInput(buf, ret); 23 | 24 | } 25 | 26 | return 0; 27 | } 28 | 29 | #else 30 | 31 | int 32 | main(void) 33 | { 34 | int ret; 35 | uint8_t buf[64 * 1024]; 36 | 37 | ret = fread(buf, 1, sizeof(buf), stdin); 38 | if (ret < 0) { 39 | return 0; 40 | } 41 | 42 | LLVMFuzzerTestOneInput(buf, ret); 43 | 44 | return 0; 45 | } 46 | 47 | #endif /* __AFL_COMPILER */ 48 | -------------------------------------------------------------------------------- /tests/fuzz/yang_parse_module.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "libyang.h" 6 | 7 | int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len) 8 | { 9 | struct lys_module *mod; 10 | uint8_t *data = NULL; 11 | struct ly_ctx *ctx = NULL; 12 | static bool log = false; 13 | LY_ERR err; 14 | 15 | if (!log) { 16 | ly_log_options(0); 17 | log = true; 18 | } 19 | 20 | err = ly_ctx_new(NULL, 0, &ctx); 21 | if (err != LY_SUCCESS) { 22 | fprintf(stderr, "Failed to create new context\n"); 23 | return 0; 24 | } 25 | 26 | data = malloc(len + 1); 27 | if (data == NULL) { 28 | fprintf(stderr, "Out of memory\n"); 29 | return 0; 30 | } 31 | memcpy(data, buf, len); 32 | data[len] = 0; 33 | 34 | lys_parse_mem(ctx, (const char *)data, LYS_IN_YANG, &mod); 35 | 36 | free(data); 37 | ly_ctx_destroy(ctx); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /tests/ld.supp: -------------------------------------------------------------------------------- 1 | { 2 | dl's thread-local data 3 | Memcheck:Leak 4 | match-leak-kinds: reachable 5 | fun:calloc 6 | fun:_dlerror_run 7 | fun:dlopen@@GLIBC_2.2.5 8 | } 9 | -------------------------------------------------------------------------------- /tests/modules/yang/sm-extension.yang: -------------------------------------------------------------------------------- 1 | module sm-extension { 2 | yang-version 1.1; 3 | namespace "urn:sm-ext"; 4 | prefix "sm-ext"; 5 | 6 | list tlist { 7 | key "name"; 8 | leaf name { 9 | type uint32; 10 | } 11 | } 12 | container tcont { 13 | leaf tleaf { 14 | type uint32; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/modules/yang/sm-mod.yang: -------------------------------------------------------------------------------- 1 | module sm-mod { 2 | yang-version 1.1; 3 | namespace "urn:sm-mod"; 4 | prefix "sm-mod"; 5 | 6 | import sm-modp { 7 | prefix smp; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/modules/yang/sm-modp.yang: -------------------------------------------------------------------------------- 1 | module sm-modp { 2 | yang-version 1.1; 3 | namespace "urn:sm-modp"; 4 | prefix "sm-modp"; 5 | 6 | import ietf-yang-schema-mount { 7 | prefix yangmnt; 8 | } 9 | 10 | revision 2017-01-26; 11 | 12 | container ncmp { 13 | yangmnt:mount-point "root"; 14 | } 15 | 16 | container not-compiled { 17 | leaf first { 18 | type string; 19 | } 20 | leaf second { 21 | type string; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/modules/yang/sm-rpcnotif.yang: -------------------------------------------------------------------------------- 1 | module sm-rpcnotif { 2 | yang-version 1.1; 3 | namespace "urn:rpcnotif"; 4 | prefix "smrn"; 5 | 6 | container cont { 7 | notification cn; 8 | action cr { 9 | input { 10 | leaf in { 11 | type string; 12 | } 13 | } 14 | output { 15 | leaf out { 16 | type string; 17 | } 18 | } 19 | } 20 | } 21 | rpc r1; 22 | rpc r2; 23 | notification n1; 24 | notification n2; 25 | } 26 | -------------------------------------------------------------------------------- /tests/modules/yang/sm.yang: -------------------------------------------------------------------------------- 1 | module sm { 2 | yang-version 1.1; 3 | namespace "urn:sm"; 4 | prefix "sm"; 5 | 6 | import ietf-yang-schema-mount { 7 | prefix yangmnt; 8 | } 9 | import ietf-interfaces { 10 | prefix if; 11 | } 12 | 13 | container root { 14 | yangmnt:mount-point "root"; 15 | } 16 | container root2 { 17 | yangmnt:mount-point "root"; 18 | } 19 | container root3 { 20 | list ls { 21 | key name; 22 | leaf name { 23 | type string; 24 | } 25 | yangmnt:mount-point "mnt-root"; 26 | } 27 | } 28 | leaf target { 29 | type string; 30 | } 31 | 32 | augment /if:interfaces/if:interface { 33 | leaf sm-name { 34 | type leafref { 35 | path "/sm:target"; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/perf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(format_sources 2 | ${format_sources} 3 | ${CMAKE_CURRENT_SOURCE_DIR}/perf.c 4 | PARENT_SCOPE) 5 | 6 | add_executable(ly_perf ${CMAKE_CURRENT_SOURCE_DIR}/perf.c $) 7 | set_target_properties(ly_perf PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") 8 | target_link_libraries(ly_perf ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS}) 9 | if(XXHASH_FOUND) 10 | target_link_libraries(ly_perf ${XXHASH_LIBRARY}) 11 | endif() 12 | 13 | if(NOT WIN32) 14 | target_link_libraries(ly_perf m) 15 | endif() 16 | 17 | add_test(NAME ly_perf_1000 COMMAND ly_perf 1000 10) 18 | add_test(NAME ly_perf_100000 COMMAND ly_perf 100000 3) 19 | -------------------------------------------------------------------------------- /tests/perf/perf.yang: -------------------------------------------------------------------------------- 1 | module perf { 2 | yang-version 1.1; 3 | namespace "urn:sysrepo:tests:perf"; 4 | prefix p; 5 | 6 | container cont { 7 | list lst { 8 | key "k1 k2"; 9 | 10 | leaf k1 { 11 | type uint32; 12 | } 13 | 14 | leaf k2 { 15 | type string; 16 | } 17 | 18 | leaf l { 19 | type string; 20 | } 21 | 22 | leaf-list lfl { 23 | type uint32; 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/plugins/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CMakeParseArguments) 2 | 3 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 4 | 5 | function(ly_add_plugin) 6 | cmake_parse_arguments(ADDPLUGIN "" "NAME" "SOURCES" ${ARGN}) 7 | set(PLUGIN_NAME plugin_${ADDPLUGIN_NAME}) 8 | 9 | foreach(PLUGIN_SOURCE ${ADDPLUGIN_SOURCES}) 10 | list(APPEND PLUGIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN_SOURCE}) 11 | endforeach() 12 | 13 | add_library(${PLUGIN_NAME} MODULE ${PLUGIN_SOURCES}) 14 | set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "") 15 | target_link_libraries(${PLUGIN_NAME} yang) 16 | endfunction(ly_add_plugin) 17 | 18 | ly_add_plugin(NAME invalid SOURCES invalid.c) 19 | ly_add_plugin(NAME simple SOURCES simple.c) 20 | -------------------------------------------------------------------------------- /tests/plugins/invalid.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file invalid.c 3 | * @author Radek Krejci 4 | * @brief Invalid testing plugins implementation 5 | * 6 | * Copyright (c) 2021 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 16 | 17 | #include "libyang.h" 18 | #include "plugins_exts.h" 19 | #include "plugins_types.h" 20 | 21 | /* 22 | * EXTENSION PLUGIN 23 | */ 24 | 25 | /** 26 | * @brief Instead of plugin description, only the API version is declared. 27 | * 28 | * Here should be LY_PLUGINS_EXTENSIONS used. 29 | */ 30 | uint32_t plugins_extensions_apiver__ = LYPLG_EXT_API_VERSION; 31 | 32 | /* 33 | * TYPE PLUGIN 34 | */ 35 | 36 | /** 37 | * @brief Instead of plugin description, only the API version is declared. 38 | * 39 | * Here should be LYPLG_TYPES used. 40 | */ 41 | uint32_t plugins_types_apiver__ = LYPLG_TYPE_API_VERSION; 42 | -------------------------------------------------------------------------------- /tests/style/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_test(NAME headers 2 | COMMAND ${CMAKE_SOURCE_DIR}/compat/check_includes.sh ${CMAKE_SOURCE_DIR}/src/ ${CMAKE_SOURCE_DIR}/tools/lint/ ${CMAKE_SOURCE_DIR}/tools/re/) 3 | 4 | if(${SOURCE_FORMAT_ENABLED}) 5 | add_test(NAME format WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cmake --build ${CMAKE_BINARY_DIR} --target format-check) 6 | endif() 7 | 8 | # just compile 9 | add_executable(cpp_compat cpp_compat.c $) 10 | target_include_directories(cpp_compat BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) 11 | target_link_libraries(cpp_compat ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS} m) 12 | if(XXHASH_FOUND) 13 | target_link_libraries(cpp_compat ${XXHASH_LIBRARY}) 14 | endif() 15 | 16 | target_compile_options(cpp_compat PUBLIC "-Werror=c++-compat") 17 | -------------------------------------------------------------------------------- /tests/tests_config.h.in: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tests_config.h 3 | * @author Radek Krejci 4 | * @brief cmocka tests configuration header. 5 | * 6 | * Copyright (c) 2015 - 2021 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 | #ifndef LYTEST_CONFIG_H_ 15 | #define LYTEST_CONFIG_H_ 16 | 17 | #define TESTS_SRC "@CMAKE_CURRENT_SOURCE_DIR@" 18 | #define TESTS_BIN "@CMAKE_CURRENT_BINARY_DIR@" 19 | 20 | #define TESTS_DIR_MODULES_YANG TESTS_SRC"/modules/yang" 21 | 22 | /** 23 | * @brief Macro for support of callgrind header and macros. 24 | */ 25 | #cmakedefine HAVE_CALLGRIND 26 | 27 | #endif /* LYTEST_CONFIG_H_ */ 28 | -------------------------------------------------------------------------------- /tests/utests/types/int16.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file int16.c 3 | * @author Michal Vasko 4 | * @brief test for int16 values 5 | * 6 | * Copyright (c) 2021 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 UTEST HEADER */ 16 | #define _UTEST_MAIN_ 17 | #include "../utests.h" 18 | 19 | /* GLOBAL INCLUDE HEADERS */ 20 | #include 21 | 22 | /* LOCAL INCLUDE HEADERS */ 23 | #include "libyang.h" 24 | #include "path.h" 25 | #include "plugins_internal.h" 26 | 27 | #define MODULE_CREATE_YANG(MOD_NAME, NODES) \ 28 | "module " MOD_NAME " {\n" \ 29 | " yang-version 1.1;\n" \ 30 | " namespace \"urn:tests:" MOD_NAME "\";\n" \ 31 | " prefix pref;\n" \ 32 | NODES \ 33 | "}\n" 34 | 35 | #define TEST_SUCCESS_XML(MOD_NAME, DATA, TYPE, ...) \ 36 | { \ 37 | struct lyd_node *tree; \ 38 | const char *data = "" DATA ""; \ 39 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); \ 40 | CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "port", 0, LYS_LEAF, 0, 0, 0, 0); \ 41 | CHECK_LYD_NODE_TERM((struct lyd_node_term *)tree, 0, 0, 0, 0, 1, TYPE, ## __VA_ARGS__); \ 42 | lyd_free_all(tree); \ 43 | } 44 | 45 | #define TEST_ERROR_XML(MOD_NAME, DATA) \ 46 | {\ 47 | struct lyd_node *tree; \ 48 | const char *data = "" DATA ""; \ 49 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); \ 50 | assert_null(tree); \ 51 | } 52 | 53 | static void 54 | test_data_xml(void **state) 55 | { 56 | const char *schema; 57 | 58 | /* xml test */ 59 | schema = MODULE_CREATE_YANG("defs", "leaf port {type int16 {range -20..-10;}}"); 60 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); 61 | 62 | TEST_ERROR_XML("defs", "100"); 63 | CHECK_LOG_CTX("Unsatisfied range - value \"100\" is out of the allowed range.", "/defs:port", 1); 64 | } 65 | 66 | int 67 | main(void) 68 | { 69 | const struct CMUnitTest tests[] = { 70 | UTEST(test_data_xml), 71 | }; 72 | 73 | return cmocka_run_group_tests(tests, NULL, NULL); 74 | } 75 | -------------------------------------------------------------------------------- /tests/utests/types/int32.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file int32.c 3 | * @author Michal Vasko 4 | * @brief test for int32 values 5 | * 6 | * Copyright (c) 2021 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 UTEST HEADER */ 16 | #define _UTEST_MAIN_ 17 | #include "../utests.h" 18 | 19 | /* GLOBAL INCLUDE HEADERS */ 20 | #include 21 | 22 | /* LOCAL INCLUDE HEADERS */ 23 | #include "libyang.h" 24 | #include "path.h" 25 | #include "plugins_internal.h" 26 | 27 | #define MODULE_CREATE_YANG(MOD_NAME, NODES) \ 28 | "module " MOD_NAME " {\n" \ 29 | " yang-version 1.1;\n" \ 30 | " namespace \"urn:tests:" MOD_NAME "\";\n" \ 31 | " prefix pref;\n" \ 32 | NODES \ 33 | "}\n" 34 | 35 | #define TEST_SUCCESS_XML(MOD_NAME, DATA, TYPE, ...) \ 36 | { \ 37 | struct lyd_node *tree; \ 38 | const char *data = "" DATA ""; \ 39 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); \ 40 | CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "port", 0, LYS_LEAF, 0, 0, 0, 0); \ 41 | CHECK_LYD_NODE_TERM((struct lyd_node_term *)tree, 0, 0, 0, 0, 1, TYPE, ## __VA_ARGS__); \ 42 | lyd_free_all(tree); \ 43 | } 44 | 45 | #define TEST_ERROR_XML(MOD_NAME, DATA) \ 46 | {\ 47 | struct lyd_node *tree; \ 48 | const char *data = "" DATA ""; \ 49 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); \ 50 | assert_null(tree); \ 51 | } 52 | 53 | static void 54 | test_data_xml(void **state) 55 | { 56 | const char *schema; 57 | 58 | /* xml test */ 59 | schema = MODULE_CREATE_YANG("defs", "leaf port {type int32;}"); 60 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); 61 | 62 | TEST_ERROR_XML("defs", "0x01"); 63 | CHECK_LOG_CTX("Invalid type int32 value \"0x01\".", "/defs:port", 1); 64 | } 65 | 66 | int 67 | main(void) 68 | { 69 | const struct CMUnitTest tests[] = { 70 | UTEST(test_data_xml), 71 | }; 72 | 73 | return cmocka_run_group_tests(tests, NULL, NULL); 74 | } 75 | -------------------------------------------------------------------------------- /tests/utests/types/int64.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file int64.c 3 | * @author Michal Vasko 4 | * @brief test for int32 values 5 | * 6 | * Copyright (c) 2021 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 UTEST HEADER */ 16 | #define _UTEST_MAIN_ 17 | #include "../utests.h" 18 | 19 | /* GLOBAL INCLUDE HEADERS */ 20 | #include 21 | 22 | /* LOCAL INCLUDE HEADERS */ 23 | #include "libyang.h" 24 | #include "path.h" 25 | #include "plugins_internal.h" 26 | 27 | #define MODULE_CREATE_YANG(MOD_NAME, NODES) \ 28 | "module " MOD_NAME " {\n" \ 29 | " yang-version 1.1;\n" \ 30 | " namespace \"urn:tests:" MOD_NAME "\";\n" \ 31 | " prefix pref;\n" \ 32 | NODES \ 33 | "}\n" 34 | 35 | #define TEST_SUCCESS_XML(MOD_NAME, DATA, TYPE, ...) \ 36 | { \ 37 | struct lyd_node *tree; \ 38 | const char *data = "" DATA ""; \ 39 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); \ 40 | CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "port", 0, LYS_LEAF, 0, 0, 0, 0); \ 41 | CHECK_LYD_NODE_TERM((struct lyd_node_term *)tree, 0, 0, 0, 0, 1, TYPE, ## __VA_ARGS__); \ 42 | lyd_free_all(tree); \ 43 | } 44 | 45 | #define TEST_ERROR_XML(MOD_NAME, DATA) \ 46 | {\ 47 | struct lyd_node *tree; \ 48 | const char *data = "" DATA ""; \ 49 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); \ 50 | assert_null(tree); \ 51 | } 52 | 53 | static void 54 | test_data_xml(void **state) 55 | { 56 | const char *schema; 57 | 58 | /* xml test */ 59 | schema = MODULE_CREATE_YANG("defs", "leaf port {type int64;}"); 60 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); 61 | 62 | TEST_ERROR_XML("defs", ""); 63 | CHECK_LOG_CTX("Invalid type int64 empty value.", "/defs:port", 1); 64 | 65 | TEST_ERROR_XML("defs", " "); 66 | CHECK_LOG_CTX("Invalid type int64 empty value.", "/defs:port", 1); 67 | 68 | TEST_ERROR_XML("defs", "-10 xxx"); 69 | CHECK_LOG_CTX("Invalid type int64 value \"-10 xxx\".", "/defs:port", 1); 70 | } 71 | 72 | int 73 | main(void) 74 | { 75 | const struct CMUnitTest tests[] = { 76 | UTEST(test_data_xml), 77 | }; 78 | 79 | return cmocka_run_group_tests(tests, NULL, NULL); 80 | } 81 | -------------------------------------------------------------------------------- /tests/utests/types/uint16.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uint16.c 3 | * @author Michal Vasko 4 | * @brief test for uint16 values 5 | * 6 | * Copyright (c) 2021 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 UTEST HEADER */ 16 | #define _UTEST_MAIN_ 17 | #include "../utests.h" 18 | 19 | /* GLOBAL INCLUDE HEADERS */ 20 | #include 21 | 22 | /* LOCAL INCLUDE HEADERS */ 23 | #include "libyang.h" 24 | #include "path.h" 25 | #include "plugins_internal.h" 26 | 27 | #define MODULE_CREATE_YANG(MOD_NAME, NODES) \ 28 | "module " MOD_NAME " {\n" \ 29 | " yang-version 1.1;\n" \ 30 | " namespace \"urn:tests:" MOD_NAME "\";\n" \ 31 | " prefix pref;\n" \ 32 | NODES \ 33 | "}\n" 34 | 35 | #define TEST_SUCCESS_XML(MOD_NAME, DATA, TYPE, ...) \ 36 | { \ 37 | struct lyd_node *tree; \ 38 | const char *data = "" DATA ""; \ 39 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); \ 40 | CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "port", 0, LYS_LEAF, 0, 0, 0, 0); \ 41 | CHECK_LYD_NODE_TERM((struct lyd_node_term *)tree, 0, 0, 0, 0, 1, TYPE, ## __VA_ARGS__); \ 42 | lyd_free_all(tree); \ 43 | } 44 | 45 | #define TEST_ERROR_XML(MOD_NAME, DATA) \ 46 | {\ 47 | struct lyd_node *tree; \ 48 | const char *data = "" DATA ""; \ 49 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); \ 50 | assert_null(tree); \ 51 | } 52 | 53 | static void 54 | test_data_xml(void **state) 55 | { 56 | const char *schema; 57 | 58 | /* xml test */ 59 | schema = MODULE_CREATE_YANG("defs", "leaf port {type uint16 {range 150..200;}}"); 60 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); 61 | 62 | TEST_ERROR_XML("defs", "\n 1500 \t\n "); 63 | CHECK_LOG_CTX("Unsatisfied range - value \"1500\" is out of the allowed range.", "/defs:port", 3); 64 | } 65 | 66 | int 67 | main(void) 68 | { 69 | const struct CMUnitTest tests[] = { 70 | UTEST(test_data_xml), 71 | }; 72 | 73 | return cmocka_run_group_tests(tests, NULL, NULL); 74 | } 75 | -------------------------------------------------------------------------------- /tests/utests/types/uint32.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uint32.c 3 | * @author Michal Vasko 4 | * @brief test for uint32 values 5 | * 6 | * Copyright (c) 2021 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 UTEST HEADER */ 16 | #define _UTEST_MAIN_ 17 | #include "../utests.h" 18 | 19 | /* GLOBAL INCLUDE HEADERS */ 20 | #include 21 | 22 | /* LOCAL INCLUDE HEADERS */ 23 | #include "libyang.h" 24 | #include "path.h" 25 | #include "plugins_internal.h" 26 | 27 | #define MODULE_CREATE_YANG(MOD_NAME, NODES) \ 28 | "module " MOD_NAME " {\n" \ 29 | " yang-version 1.1;\n" \ 30 | " namespace \"urn:tests:" MOD_NAME "\";\n" \ 31 | " prefix pref;\n" \ 32 | NODES \ 33 | "}\n" 34 | 35 | #define TEST_SUCCESS_XML(MOD_NAME, DATA, TYPE, ...) \ 36 | { \ 37 | struct lyd_node *tree; \ 38 | const char *data = "" DATA ""; \ 39 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); \ 40 | CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "port", 0, LYS_LEAF, 0, 0, 0, 0); \ 41 | CHECK_LYD_NODE_TERM((struct lyd_node_term *)tree, 0, 0, 0, 0, 1, TYPE, ## __VA_ARGS__); \ 42 | lyd_free_all(tree); \ 43 | } 44 | 45 | #define TEST_ERROR_XML(MOD_NAME, DATA) \ 46 | {\ 47 | struct lyd_node *tree; \ 48 | const char *data = "" DATA ""; \ 49 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); \ 50 | assert_null(tree); \ 51 | } 52 | 53 | static void 54 | test_data_xml(void **state) 55 | { 56 | const char *schema; 57 | 58 | /* xml test */ 59 | schema = MODULE_CREATE_YANG("defs", "leaf port {type uint32;}"); 60 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); 61 | 62 | TEST_ERROR_XML("defs", "-10"); 63 | CHECK_LOG_CTX("Value \"-10\" is out of type uint32 min/max bounds.", "/defs:port", 1); 64 | } 65 | 66 | int 67 | main(void) 68 | { 69 | const struct CMUnitTest tests[] = { 70 | UTEST(test_data_xml), 71 | }; 72 | 73 | return cmocka_run_group_tests(tests, NULL, NULL); 74 | } 75 | -------------------------------------------------------------------------------- /tests/utests/types/uint64.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uint64.c 3 | * @author Michal Vasko 4 | * @brief test for uint64 values 5 | * 6 | * Copyright (c) 2021 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 UTEST HEADER */ 16 | #define _UTEST_MAIN_ 17 | #include "../utests.h" 18 | 19 | /* GLOBAL INCLUDE HEADERS */ 20 | #include 21 | 22 | /* LOCAL INCLUDE HEADERS */ 23 | #include "libyang.h" 24 | #include "path.h" 25 | #include "plugins_internal.h" 26 | 27 | #define MODULE_CREATE_YANG(MOD_NAME, NODES) \ 28 | "module " MOD_NAME " {\n" \ 29 | " yang-version 1.1;\n" \ 30 | " namespace \"urn:tests:" MOD_NAME "\";\n" \ 31 | " prefix pref;\n" \ 32 | NODES \ 33 | "}\n" 34 | 35 | #define TEST_SUCCESS_XML(MOD_NAME, DATA, TYPE, ...) \ 36 | { \ 37 | struct lyd_node *tree; \ 38 | const char *data = "" DATA ""; \ 39 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); \ 40 | CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "port", 0, LYS_LEAF, 0, 0, 0, 0); \ 41 | CHECK_LYD_NODE_TERM((struct lyd_node_term *)tree, 0, 0, 0, 0, 1, TYPE, ## __VA_ARGS__); \ 42 | lyd_free_all(tree); \ 43 | } 44 | 45 | #define TEST_ERROR_XML(MOD_NAME, DATA) \ 46 | {\ 47 | struct lyd_node *tree; \ 48 | const char *data = "" DATA ""; \ 49 | CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); \ 50 | assert_null(tree); \ 51 | } 52 | 53 | static void 54 | test_data_xml(void **state) 55 | { 56 | const char *schema; 57 | 58 | /* xml test */ 59 | schema = MODULE_CREATE_YANG("defs", "leaf port {type uint64;}"); 60 | UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL); 61 | 62 | TEST_ERROR_XML("defs", ""); 63 | CHECK_LOG_CTX("Invalid type uint64 empty value.", "/defs:port", 1); 64 | 65 | TEST_ERROR_XML("defs", " "); 66 | CHECK_LOG_CTX("Invalid type uint64 empty value.", "/defs:port", 1); 67 | 68 | TEST_ERROR_XML("defs", "10 xxx"); 69 | CHECK_LOG_CTX("Invalid type uint64 value \"10 xxx\".", "/defs:port", 1); 70 | } 71 | 72 | int 73 | main(void) 74 | { 75 | const struct CMUnitTest tests[] = { 76 | UTEST(test_data_xml), 77 | }; 78 | 79 | return cmocka_run_group_tests(tests, NULL, NULL); 80 | } 81 | -------------------------------------------------------------------------------- /tests/yanglint/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(WIN32 OR NOT ENABLE_YANGLINT_INTERACTIVE) 2 | set(YANGLINT_INTERACTIVE OFF) 3 | else() 4 | set(YANGLINT_INTERACTIVE ON) 5 | endif() 6 | 7 | function(add_yanglint_test) 8 | cmake_parse_arguments(ADDTEST "" "NAME;VIA;SCRIPT" "" ${ARGN}) 9 | set(TEST_NAME yanglint_${ADDTEST_NAME}) 10 | 11 | if(${ADDTEST_VIA} STREQUAL "tclsh") 12 | set(WRAPPER ${PATH_TCLSH}) 13 | else() 14 | message(FATAL_ERROR "build: unexpected wrapper '${ADDTEST_VIA}'") 15 | endif() 16 | 17 | add_test(NAME ${TEST_NAME} COMMAND ${WRAPPER} ${CMAKE_CURRENT_SOURCE_DIR}/${ADDTEST_SCRIPT}) 18 | set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "TESTS_DIR=${CMAKE_CURRENT_SOURCE_DIR}") 19 | set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "YANG_MODULES_DIR=${CMAKE_CURRENT_SOURCE_DIR}/modules") 20 | set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "YANGLINT=${PROJECT_BINARY_DIR}") 21 | endfunction(add_yanglint_test) 22 | 23 | if(ENABLE_TESTS) 24 | # tests of interactive mode using tclsh 25 | find_program(PATH_TCLSH NAMES tclsh) 26 | if(NOT PATH_TCLSH) 27 | message(WARNING "'tclsh' not found! The yanglint(1) interactive tests will not be available.") 28 | else() 29 | if(YANGLINT_INTERACTIVE) 30 | add_yanglint_test(NAME interactive VIA tclsh SCRIPT interactive/all.tcl) 31 | add_yanglint_test(NAME non-interactive VIA tclsh SCRIPT non-interactive/all.tcl) 32 | else() 33 | add_yanglint_test(NAME non-interactive VIA tclsh SCRIPT non-interactive/all.tcl) 34 | endif() 35 | endif() 36 | endif() 37 | -------------------------------------------------------------------------------- /tests/yanglint/data/modaction.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | kv 4 | 5 | some_input 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/yanglint/data/modaction_ds.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | kv 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/yanglint/data/modaction_nc.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | kv 7 | 8 | some_input 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/yanglint/data/modaction_reply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | kv 4 | 5 | -56 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/yanglint/data/modaction_reply_nc.xml: -------------------------------------------------------------------------------- 1 | 3 | -56 4 | 5 | -------------------------------------------------------------------------------- /tests/yanglint/data/modconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | rw 3 | ro 4 | 5 | -------------------------------------------------------------------------------- /tests/yanglint/data/modconfig2.xml: -------------------------------------------------------------------------------- 1 | 2 | rw 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modconfig_ctx.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | main-set 4 | 5 | modconfig 6 | urn:yanglint:modconfig 7 | 8 | 9 | 1 10 | 11 | 12 | 1 13 | 14 | -------------------------------------------------------------------------------- /tests/yanglint/data/moddatanodes.xml: -------------------------------------------------------------------------------- 1 | 2 | x 3 | 1 4 | 2 5 | 6 | 7 | ka1 8 | kb1 9 | v1 10 | 11 | 12 | ka2 13 | kb2 14 | v2 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/yanglint/data/moddefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 3 | 5 4 | 5 | -------------------------------------------------------------------------------- /tests/yanglint/data/modimp_type_ctx.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | main-set 4 | 5 | modimp-type 6 | urn:yanglint:modimp-type 7 | 8 | 9 | 1 10 | 11 | 12 | 1 13 | 14 | -------------------------------------------------------------------------------- /tests/yanglint/data/modleaf.djson: -------------------------------------------------------------------------------- 1 | { 2 | "modleaf:lfl": 7 3 | } 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modleaf.dxml: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /tests/yanglint/data/modleaf.xml: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /tests/yanglint/data/modleafref.xml: -------------------------------------------------------------------------------- 1 | 7 2 | 7 3 | -------------------------------------------------------------------------------- /tests/yanglint/data/modleafref2.xml: -------------------------------------------------------------------------------- 1 | 7 2 | 10 3 | -------------------------------------------------------------------------------- /tests/yanglint/data/modmandatory.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modmandatory_invalid.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modmerge.xml: -------------------------------------------------------------------------------- 1 | 2 | one 3 | 4 4 | 5 | -------------------------------------------------------------------------------- /tests/yanglint/data/modmerge2.xml: -------------------------------------------------------------------------------- 1 | 2 | zero 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modmerge3.xml: -------------------------------------------------------------------------------- 1 | 2 | str 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modnotif.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | nested 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/yanglint/data/modnotif2.xml: -------------------------------------------------------------------------------- 1 | 2 | top 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modnotif2_nc.xml: -------------------------------------------------------------------------------- 1 | 2 | 2010-12-06T08:00:01Z 3 | 4 | top 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/yanglint/data/modnotif_ds.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/yanglint/data/modnotif_nc.xml: -------------------------------------------------------------------------------- 1 | 2 | 2010-12-06T08:00:01Z 3 | 4 | 5 | nested 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/yanglint/data/modoper_leafref_action.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | key_val 4 | 5 | rw 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/yanglint/data/modoper_leafref_action_reply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | key_val 4 | 5 | rw 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/yanglint/data/modoper_leafref_ds.xml: -------------------------------------------------------------------------------- 1 | 2 | rw 3 | ro 4 | 5 | 6 | 7 | key_val 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/yanglint/data/modoper_leafref_notif.xml: -------------------------------------------------------------------------------- 1 | 2 | rw 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modoper_leafref_notif2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | key_val 4 | 5 | rw 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/yanglint/data/modoper_leafref_notif_err.xml: -------------------------------------------------------------------------------- 1 | 2 | rw 3 | ro 4 | 5 | 6 | rw 7 | 8 | -------------------------------------------------------------------------------- /tests/yanglint/data/modoper_leafref_rpc.xml: -------------------------------------------------------------------------------- 1 | 2 | rw 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modoper_leafref_rpc_reply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | rw 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/yanglint/data/modrpc.xml: -------------------------------------------------------------------------------- 1 | 2 | some_input 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modrpc_nc.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | some_input 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/yanglint/data/modrpc_reply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -56 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/yanglint/data/modrpc_reply_nc.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -56 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/yanglint/data/modsm.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 3 | 4 | -------------------------------------------------------------------------------- /tests/yanglint/data/modsm2.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 3 | str 4 | 5 | -------------------------------------------------------------------------------- /tests/yanglint/data/modsm_ctx_ext.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | test-set 4 | 5 | modleaf 6 | urn:yanglint:modleaf 7 | 8 | 9 | 1 10 | 11 | 12 | 1 13 | 14 | 15 | 16 | modsm 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/yanglint/data/modsm_ctx_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | main-set 4 | 5 | modsm 6 | urn:yanglint:modsm 7 | 8 | 9 | modsm-augment 10 | urn:yanglint:modsm-augment 11 | 12 | 13 | 1 14 | 15 | 16 | 1 17 | 18 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/add.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $::env(YANG_MODULES_DIR) 4 | 5 | test add_basic {} { 6 | -setup $ly_setup -cleanup $ly_cleanup -body { 7 | ly_cmd "add $mdir/modleafref.yang" 8 | ly_cmd "list" "I modleafref\r.*I modleaf" 9 | }} 10 | 11 | test add_disable_searchdir_once {add --disable-searchdir} { 12 | -setup $ly_setup -cleanup $ly_cleanup -constraints {!ctest} -body { 13 | ly_cmd "add $mdir/modimp-cwd.yang" 14 | ly_cmd "clear" 15 | ly_cmd_err "add -D $mdir/modimp-cwd.yang" "not found in local searchdirs" 16 | }} 17 | 18 | test add_disable_searchdir_twice {add -D -D} { 19 | -setup $ly_setup -cleanup $ly_cleanup -constraints {!ctest} -body { 20 | ly_cmd "add $mdir/ietf-ip.yang" 21 | ly_cmd "clear" 22 | ly_cmd_err "add -D -D $mdir/ietf-ip.yang" "Loading \"ietf-interfaces\" module failed." 23 | }} 24 | 25 | test add_with_feature {Add module with feature} { 26 | -setup $ly_setup -cleanup $ly_cleanup -body { 27 | ly_cmd "add --feature modfeature:ftr2 $mdir/modfeature.yang" 28 | ly_cmd "feature -a" "modfeature:\r\n\tftr1 \\(off\\)\r\n\tftr2 \\(on\\)" 29 | }} 30 | 31 | test add_make_implemented_once {add --make-implemented} { 32 | -setup $ly_setup -cleanup $ly_cleanup -body { 33 | ly_ignore "add $mdir/modmust.yang" 34 | ly_cmd "list" "I modmust\r.*i modleaf" 35 | ly_cmd "clear" 36 | ly_ignore "add -i $mdir/modmust.yang" 37 | ly_cmd "list" "I modmust\r.*I modleaf" 38 | }} 39 | 40 | test add_make_implemented_twice {add -i -i} { 41 | -setup $ly_setup -cleanup $ly_cleanup -body { 42 | ly_cmd "add $mdir/modimp-type.yang" 43 | ly_cmd "list" "I modimp-type\r.*i modtypedef" 44 | ly_cmd "clear" 45 | ly_cmd "add -i -i $mdir/modimp-type.yang" 46 | ly_cmd "list" "I modimp-type\r.*I modtypedef" 47 | }} 48 | 49 | test add_extended_leafref_enabled {Valid module with --extended-leafref option} { 50 | -setup $ly_setup -cleanup $ly_cleanup -body { 51 | ly_cmd "add -X $mdir/modextleafref.yang" 52 | }} 53 | 54 | test add_extended_leafref_disabled {Expected error if --extended-leafref is not set} { 55 | -setup $ly_setup -cleanup $ly_cleanup -body { 56 | ly_cmd_err "add $mdir/modextleafref.yang" "Unexpected XPath token \"FunctionName\"" 57 | }} 58 | 59 | cleanupTests 60 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/all.tcl: -------------------------------------------------------------------------------- 1 | package require tcltest 2 | 3 | # Hook to determine if any of the tests failed. 4 | # Sets a global variable exitCode to 1 if any test fails otherwise it is set to 0. 5 | proc tcltest::cleanupTestsHook {} { 6 | variable numTests 7 | set ::exitCode [expr {$numTests(Failed) > 0}] 8 | } 9 | 10 | if {[info exists ::env(TESTS_DIR)]} { 11 | tcltest::configure -testdir "$env(TESTS_DIR)/interactive" 12 | } 13 | 14 | tcltest::runAllTests 15 | exit $exitCode 16 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/clear.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $::env(YANG_MODULES_DIR) 4 | set ddir $::env(TESTS_DIR)/data 5 | 6 | test clear_searchpath {searchpath is also deleted} { 7 | -setup $ly_setup -cleanup $ly_cleanup -body { 8 | ly_cmd "searchpath ./" 9 | ly_cmd "clear" 10 | ly_cmd "searchpath" "List of the searchpaths:" -ex 11 | }} 12 | 13 | test clear_make_implemented_once {clear --make-implemented} { 14 | -setup $ly_setup -cleanup $ly_cleanup -body { 15 | ly_cmd "clear -i" 16 | ly_cmd "add $mdir/modmust.yang" 17 | ly_cmd "list" "I modmust\r.*I modleaf" 18 | }} 19 | 20 | test clear_make_implemented_twice {clear -i -i} { 21 | -setup $ly_setup -cleanup $ly_cleanup -body { 22 | ly_cmd "clear -i -i" 23 | ly_cmd "add $mdir/modmust.yang" 24 | ly_cmd "list" "I modmust\r.*I modleaf" 25 | }} 26 | 27 | test clear_ietf_yang_library {clear --yang-library} { 28 | -setup $ly_setup -cleanup $ly_cleanup -body { 29 | # add models 30 | ly_cmd "clear -y" 31 | ly_cmd "list" "I ietf-yang-library" 32 | }} 33 | 34 | test clear_ylf_list {apply --yang-library-file and check result by --list} { 35 | -setup $ly_setup -cleanup $ly_cleanup -body { 36 | ly_cmd "clear -Y $ddir/modimp_type_ctx.xml" 37 | ly_cmd "list" "I modimp-type.*i modtypedef" 38 | }} 39 | 40 | test clear_ylf_make_implemented {apply --yang-library-file and --make-implemented} { 41 | -setup $ly_setup -cleanup $ly_cleanup -body { 42 | ly_cmd "clear -Y $ddir/modimp_type_ctx.xml -i -i" 43 | ly_cmd "list" "I modimp-type.*I modtypedef" 44 | }} 45 | 46 | test clear_ylf_augment_ctx {Setup context by yang-library-file and augment module} { 47 | -setup $ly_setup -cleanup $ly_cleanup -body { 48 | ly_cmd "clear -Y $ddir/modconfig_ctx.xml" 49 | ly_cmd "add $mdir/modconfig-augment.yang" 50 | ly_cmd "print -f tree modconfig" "mca:alf" 51 | }} 52 | 53 | cleanupTests 54 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/data_default.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mods "ietf-netconf-with-defaults moddefault" 4 | set data "$::env(TESTS_DIR)/data/moddefault.xml" 5 | 6 | test data_default_not_set {Print data without --default parameter} { 7 | -setup $ly_setup -cleanup $ly_cleanup -body { 8 | ly_cmd "load $mods" 9 | ly_cmd "data -f xml $data" ".*\r\n" 10 | ly_cmd "data -f json $data" "lf\".*di\"\[^\"]*" 11 | }} 12 | 13 | test data_default_all {data --default all} { 14 | -setup $ly_setup -cleanup $ly_cleanup -body { 15 | ly_cmd "load $mods" 16 | ly_cmd "data -d all -f xml $data" ".*.*\r\n" 17 | ly_cmd "data -d all -f json $data" "lf\".*di\".*ds\"\[^\"]*" 18 | }} 19 | 20 | test data_default_all_tagged {data --default all-tagged} { 21 | -setup $ly_setup -cleanup $ly_cleanup -body { 22 | ly_cmd "load $mods" 23 | ly_cmd "data -d all-tagged -f xml $data" ".*.*\r\n" 24 | ly_cmd "data -d all-tagged -f json $data" "lf\".*di\".*ds\".*@ds\".*default\"\[^\"]*" 25 | }} 26 | 27 | test data_default_trim {data --default trim} { 28 | -setup $ly_setup -cleanup $ly_cleanup -body { 29 | ly_cmd "load $mods" 30 | ly_cmd "data -d trim -f xml $data" "\r\n" 31 | ly_cmd "data -d trim -f json $data" "lf\"\[^\"]*" 32 | }} 33 | 34 | test data_default_implicit_tagged {data --default implicit-tagged} { 35 | -setup $ly_setup -cleanup $ly_cleanup -body { 36 | ly_cmd "load $mods" 37 | ly_cmd "data -d implicit-tagged -f xml $data" ".*5.*\r\n" 38 | ly_cmd "data -d implicit-tagged -f json $data" "lf\".*di\"\[^@]*ds\".*default\"\[^\"]*" 39 | }} 40 | 41 | cleanupTests 42 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/data_format.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set ddir "$::env(TESTS_DIR)/data" 4 | 5 | test data_format_xml {Print data in xml format} { 6 | -setup $ly_setup -cleanup $ly_cleanup -body { 7 | ly_cmd "load modleaf" 8 | ly_cmd "data -f xml $ddir/modleaf.xml" "7" 9 | }} 10 | 11 | test data_format_json {Print data in json format} { 12 | -setup $ly_setup -cleanup $ly_cleanup -body { 13 | ly_cmd "load modleaf" 14 | ly_cmd "data -f json $ddir/modleaf.xml" "{\r\n \"modleaf:lfl\": 7\r\n}" 15 | }} 16 | 17 | test data_format_lyb_err {Print data in lyb format} { 18 | -setup $ly_setup -cleanup $ly_cleanup -body { 19 | ly_cmd "load modleaf" 20 | ly_cmd_err "data -f lyb $ddir/modleaf.xml" "The LYB format requires the -o" 21 | }} 22 | 23 | cleanupTests 24 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/data_in_format.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set ddir "$::env(TESTS_DIR)/data" 4 | 5 | test data_in_format_xml {--in-format xml} { 6 | -setup $ly_setup -cleanup $ly_cleanup -body { 7 | ly_cmd "load modleaf" 8 | ly_cmd "data -F xml $ddir/modleaf.dxml" 9 | ly_cmd_err "data -F json $ddir/modleaf.dxml" "Failed to parse" 10 | ly_cmd_err "data -F lyb $ddir/modleaf.dxml" "Failed to parse" 11 | }} 12 | 13 | test data_in_format_json {--in-format json} { 14 | -setup $ly_setup -cleanup $ly_cleanup -body { 15 | ly_cmd "load modleaf" 16 | ly_cmd "data -F json $ddir/modleaf.djson" 17 | ly_cmd_err "data -F xml $ddir/modleaf.djson" "Failed to parse" 18 | ly_cmd_err "data -F lyb $ddir/modleaf.djson" "Failed to parse" 19 | }} 20 | 21 | cleanupTests 22 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/data_merge.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set ddir "$::env(TESTS_DIR)/data" 4 | 5 | test data_merge_basic {Data is merged and the node is added} { 6 | -setup $ly_setup -cleanup $ly_cleanup -body { 7 | ly_cmd "load modmerge" 8 | ly_cmd "data -m -f xml $ddir/modmerge.xml $ddir/modmerge3.xml" ".*.*" 9 | }} 10 | 11 | test data_merge_validation_failed {Data is merged but validation failed.} { 12 | -setup $ly_setup -cleanup $ly_cleanup -body { 13 | ly_cmd "load modmerge" 14 | ly_cmd "data $ddir/modmerge.xml" 15 | ly_cmd "data $ddir/modmerge2.xml" 16 | ly_cmd "data -m $ddir/modmerge2.xml $ddir/modmerge.xml" 17 | ly_cmd_err "data -m $ddir/modmerge.xml $ddir/modmerge2.xml" "Merged data are not valid" 18 | }} 19 | 20 | test data_merge_dataconfig {The merge option has effect only for 'data' and 'config' TYPEs} { 21 | -setup $ly_setup -cleanup $ly_cleanup -body { 22 | ly_cmd "load modrpc modnotif modconfig modleaf" 23 | set wrn1 "option has effect only for" 24 | ly_cmd_wrn "data -m -t rpc $ddir/modrpc.xml $ddir/modrpc.xml" $wrn1 25 | ly_cmd_wrn "data -m -t notif $ddir/modnotif2.xml $ddir/modnotif2.xml" $wrn1 26 | ly_cmd_wrn "data -m -t get $ddir/modleaf.xml $ddir/modconfig.xml" $wrn1 27 | ly_cmd_wrn "data -m -t getconfig $ddir/modleaf.xml $ddir/modconfig2.xml" $wrn1 28 | ly_cmd_wrn "data -m -t edit $ddir/modleaf.xml $ddir/modconfig2.xml" $wrn1 29 | ly_cmd "data -m -t config $ddir/modleaf.xml $ddir/modconfig2.xml" 30 | ly_cmd "data -m -t data $ddir/modleaf.xml $ddir/modconfig.xml" 31 | }} 32 | 33 | cleanupTests 34 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/data_not_strict.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set ddir $::env(TESTS_DIR)/data 4 | 5 | test data_no_strict_basic {} { 6 | -setup $ly_setup -cleanup $ly_cleanup -body { 7 | ly_cmd "load modleaf" 8 | ly_cmd_err "data $ddir/modmandatory.xml" "No module with namespace \"urn:yanglint:modmandatory\" in the context." 9 | ly_cmd "data -n $ddir/modmandatory.xml" 10 | }} 11 | 12 | test data_no_strict_invalid_data {validation with --no-strict but data are invalid} { 13 | -setup $ly_setup -cleanup $ly_cleanup -body { 14 | set errmsg "Mandatory node \"lft\" instance does not exist." 15 | ly_cmd "load modmandatory" 16 | ly_cmd_err "data -n $ddir/modmandatory_invalid.xml" $errmsg 17 | }} 18 | 19 | test data_no_strict_ignore_invalid_data {--no-strict ignore invalid data if no schema is provided} { 20 | -setup $ly_setup -cleanup $ly_cleanup -body { 21 | ly_cmd "load modleaf" 22 | ly_cmd "data -f xml -n $ddir/modmandatory_invalid.xml $ddir/modleaf.xml" "modleaf.*$" 23 | }} 24 | 25 | cleanupTests 26 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/data_present.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set ddir "$::env(TESTS_DIR)/data" 4 | 5 | test data_present_via_mandatory {validation of mandatory-stmt will pass only with the --present} { 6 | -setup $ly_setup -cleanup $ly_cleanup -body { 7 | ly_cmd "load modleaf modmandatory" 8 | ly_cmd_err "data $ddir/modleaf.xml" "Mandatory node \"lft\" instance does not exist." 9 | ly_cmd "data -e $ddir/modleaf.xml" 10 | }} 11 | 12 | test data_present_merge {validation with --present and --merge} { 13 | -setup $ly_setup -cleanup $ly_cleanup -body { 14 | ly_cmd "load modleaf modmandatory moddefault" 15 | ly_cmd_err "data -m $ddir/modleaf.xml $ddir/moddefault.xml" "Mandatory node \"lft\" instance does not exist." 16 | ly_cmd "data -e -m $ddir/modleaf.xml $ddir/moddefault.xml" 17 | }} 18 | 19 | test data_present_merge_invalid {using --present and --merge but data are invalid} { 20 | -setup $ly_setup -cleanup $ly_cleanup -body { 21 | ly_cmd "load modleaf modmandatory" 22 | ly_cmd_err "data -e -m $ddir/modleaf.xml $ddir/modmandatory_invalid.xml" "Mandatory node \"lft\" instance does not exist." 23 | }} 24 | 25 | cleanupTests 26 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/data_xpath.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set data "$::env(TESTS_DIR)/data/moddatanodes.xml" 4 | 5 | test data_xpath_empty {--xpath to missing node} { 6 | -setup $ly_setup -cleanup $ly_cleanup -body { 7 | ly_cmd "load moddatanodes" 8 | ly_cmd "data -x /moddatanodes:dnc/mis $data" "Empty" 9 | }} 10 | 11 | test data_xpath_leaf {--xpath to leaf node} { 12 | -setup $ly_setup -cleanup $ly_cleanup -body { 13 | ly_cmd "load moddatanodes" 14 | ly_cmd "data -x /moddatanodes:dnc/lf $data" "leaf \"lf\" \\(value: \"x\"\\)" 15 | }} 16 | 17 | test data_xpath_leaflist {--xpath to leaf-list node} { 18 | -setup $ly_setup -cleanup $ly_cleanup -body { 19 | ly_cmd "load moddatanodes" 20 | set r1 "leaf-list \"lfl\" \\(value: \"1\"\\)" 21 | set r2 "leaf-list \"lfl\" \\(value: \"2\"\\)" 22 | ly_cmd "data -x /moddatanodes:dnc/lfl $data" "$r1\r\n $r2" 23 | }} 24 | 25 | test data_xpath_list {--xpath to list} { 26 | -setup $ly_setup -cleanup $ly_cleanup -body { 27 | ly_cmd "load moddatanodes" 28 | set r1 "list \"lt\" \\(\"kalf\": \"ka1\"; \"kblf\": \"kb1\";\\)" 29 | set r2 "list \"lt\" \\(\"kalf\": \"ka2\"; \"kblf\": \"kb2\";\\)" 30 | ly_cmd "data -x /moddatanodes:dnc/con/lt $data" "$r1\r\n $r2" 31 | }} 32 | 33 | test data_xpath_container {--xpath to container} { 34 | -setup $ly_setup -cleanup $ly_cleanup -body { 35 | ly_cmd "load moddatanodes" 36 | ly_cmd "data -x /moddatanodes:dnc/con $data" "container \"con\"" 37 | }} 38 | 39 | test data_xpath_wrong_path {--xpath to a non-existent node} { 40 | -setup $ly_setup -cleanup $ly_cleanup -body { 41 | ly_cmd "load moddatanodes" 42 | ly_cmd_err "data -x /moddatanodes:dnc/wrng $data" "xpath failed" 43 | }} 44 | 45 | test data_xpath_err_format {--xpath cannot be combined with --format} { 46 | -setup $ly_setup -cleanup $ly_cleanup -body { 47 | ly_cmd "load moddatanodes" 48 | ly_cmd_err "data -f xml -x /moddatanodes:dnc/lf $data" "option cannot be combined" 49 | }} 50 | 51 | test data_xpath_err_default {--xpath cannot be combined with --default} { 52 | -setup $ly_setup -cleanup $ly_cleanup -body { 53 | ly_cmd "load moddatanodes ietf-netconf-with-defaults" 54 | ly_cmd_err "data -d all -x /moddatanodes:dnc/lf $data" "option cannot be combined" 55 | }} 56 | 57 | cleanupTests 58 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/extdata.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir "$::env(YANG_MODULES_DIR)" 4 | set ddir "$::env(TESTS_DIR)/data" 5 | 6 | test extdata_set_clear {Set and clear extdata file} { 7 | -setup $ly_setup -cleanup $ly_cleanup -body { 8 | ly_cmd "extdata" "No file set" 9 | ly_cmd "extdata $ddir/modsm_ctx_ext.xml" 10 | ly_cmd "extdata" "$ddir/modsm_ctx_ext.xml" 11 | ly_cmd "extdata -c" 12 | ly_cmd "extdata" "No file set" 13 | }} 14 | 15 | test extdata_clear_cmd {Clear extdata file by 'clear' command} { 16 | -setup $ly_setup -cleanup $ly_cleanup -body { 17 | ly_cmd "extdata $ddir/modsm_ctx_ext.xml" 18 | ly_cmd "clear" 19 | ly_cmd "extdata" "No file set" 20 | }} 21 | 22 | test extdata_one_only {Only one file for extdata} { 23 | -setup $ly_setup -cleanup $ly_cleanup -body { 24 | ly_cmd_err "extdata $ddir/modsm_ctx_ext.xml $ddir/modsm_ctx_ext.xml" "Only one file must be entered" 25 | }} 26 | 27 | test extdata_schema_mount_tree {Print tree output of a model with Schema Mount} { 28 | -setup $ly_setup -cleanup $ly_cleanup -body { 29 | ly_cmd "clear -y" 30 | ly_cmd "searchpath $mdir" 31 | ly_cmd "load modsm" 32 | ly_cmd "extdata $ddir/modsm_ctx_ext.xml" 33 | ly_cmd "print -f tree modsm" "--mp root.*--rw lfl/" 34 | }} 35 | 36 | test ext_data_schema_mount_tree_yanglibfile {Print tree output of a model with Schema Mount and --yang-library-file} { 37 | -setup $ly_setup -cleanup $ly_cleanup -body { 38 | ly_cmd "clear -Y $ddir/modsm_ctx_main.xml" 39 | ly_cmd "searchpath $mdir" 40 | ly_cmd "load modsm" 41 | ly_cmd "extdata $ddir/modsm_ctx_ext.xml" 42 | ly_cmd "print -f tree modsm" "--mp root.*--rw lfl/.*--rw msa:alf?" 43 | }} 44 | 45 | test ext_data_schema_mount_xml {Validating and printing mounted data} { 46 | -setup $ly_setup -cleanup $ly_cleanup -body { 47 | ly_cmd "clear -y" 48 | ly_cmd "searchpath $mdir" 49 | ly_cmd "load modsm" 50 | ly_cmd "extdata $ddir/modsm_ctx_ext.xml" 51 | ly_cmd "data -f xml -t config $ddir/modsm.xml" "" 52 | }} 53 | 54 | test ext_data_schema_mount_xml_yanglibfile {Validating and printing mounted data with --yang-library-file} { 55 | -setup $ly_setup -cleanup $ly_cleanup -body { 56 | ly_cmd "clear -Y $ddir/modsm_ctx_main.xml" 57 | ly_cmd "searchpath $mdir" 58 | ly_cmd "load modsm" 59 | ly_cmd "extdata $ddir/modsm_ctx_ext.xml" 60 | ly_cmd "data -f xml -t config $ddir/modsm2.xml" ".*" 61 | }} 62 | 63 | cleanupTests 64 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/feature.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | test feature_all_default {Default output of feature --all} { 4 | -setup $ly_setup -cleanup $ly_cleanup -body { 5 | ly_cmd "feature -a" "yang:\r\n\t(none)\r\n\r\nietf-yang-schema-mount:\r\n\t(none)\r\n" -ex 6 | }} 7 | 8 | test feature_all_add_module {Add module with only one feature and call feature --all} { 9 | -setup $ly_setup -cleanup $ly_cleanup -body { 10 | ly_cmd "load --feature modfeature:ftr1 modfeature" 11 | ly_cmd "feature -a" "modfeature:\r\n\tftr1 \\(on\\)\r\n\tftr2 \\(off\\)" 12 | }} 13 | 14 | test feature_all_on {Add module with all enabled features and call feature --all} { 15 | -setup $ly_setup -cleanup $ly_cleanup -body { 16 | ly_cmd "load --feature modfeature:* modfeature" 17 | ly_cmd "feature -a" "modfeature:\r\n\tftr1 \\(on\\)\r\n\tftr2 \\(on\\)" 18 | }} 19 | 20 | test feature_one_module {Show features for one module} { 21 | -setup $ly_setup -cleanup $ly_cleanup -body { 22 | ly_cmd "load ietf-ip" 23 | ly_cmd "feature -f ietf-ip" " -F ietf-ip:ipv4-non-contiguous-netmasks,ipv6-privacy-autoconf" -ex 24 | }} 25 | 26 | test feature_more_modules {Show a mix of modules with and without features} { 27 | -setup $ly_setup -cleanup $ly_cleanup -body { 28 | 29 | set features " -F modfeature:ftr1,ftr2\ 30 | -F modleaf:\ 31 | -F ietf-ip:ipv4-non-contiguous-netmasks,ipv6-privacy-autoconf" 32 | 33 | ly_cmd "load ietf-ip modleaf modfeature" 34 | ly_cmd "feature -f modfeature modleaf ietf-ip" $features -ex 35 | }} 36 | 37 | cleanupTests 38 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/list.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | namespace import uti::regex_xml_elements uti::regex_json_pairs 3 | 4 | set modules {ietf-yang-library ietf-inet-types} 5 | 6 | test list_basic {basic test} { 7 | -setup $ly_setup -cleanup $ly_cleanup -body { 8 | ly_cmd "list" "ietf-yang-types" 9 | }} 10 | 11 | test list_format_xml {list --format xml} { 12 | -setup $ly_setup -cleanup $ly_cleanup -body { 13 | ly_cmd "clear -y" 14 | ly_cmd "list -f xml" [regex_xml_elements $modules "name"] 15 | }} 16 | 17 | test list_format_json {list --format json} { 18 | -setup $ly_setup -cleanup $ly_cleanup -body { 19 | ly_cmd "clear -y" 20 | ly_cmd "list -f json" [regex_json_pairs $modules "name"] 21 | }} 22 | 23 | test list_ietf_yang_library {Error due to missing ietf-yang-library} { 24 | -setup $ly_setup -cleanup $ly_cleanup -body { 25 | ly_cmd_err "list -f xml" "Module \"ietf-yang-library\" is not implemented." 26 | }} 27 | 28 | test list_bad_format {Error due to bad format} { 29 | -setup $ly_setup -cleanup $ly_cleanup -body { 30 | ly_cmd "clear -y" 31 | ly_cmd_err "list -f csv" "Unknown output format csv" 32 | }} 33 | 34 | cleanupTests 35 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/load.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | test load_basic {} { 4 | -setup $ly_setup -cleanup $ly_cleanup -body { 5 | ly_cmd "load modleafref" 6 | ly_cmd "list" "I modleafref\r.*I modleaf" 7 | }} 8 | 9 | test load_with_feature {Load module with feature} { 10 | -setup $ly_setup -cleanup $ly_cleanup -body { 11 | ly_cmd "load --feature modfeature:ftr2 modfeature" 12 | ly_cmd "feature -a" "modfeature:\r\n\tftr1 \\(off\\)\r\n\tftr2 \\(on\\)" 13 | }} 14 | 15 | test load_make_implemented_once {load --make-implemented} { 16 | -setup $ly_setup -cleanup $ly_cleanup -body { 17 | ly_ignore "load modmust" 18 | ly_cmd "list" "I modmust\r.*i modleaf" 19 | ly_cmd "clear" 20 | ly_cmd "searchpath $::env(YANG_MODULES_DIR)" 21 | ly_cmd "load -i modmust" 22 | ly_cmd "list" "I modmust\r.*I modleaf" 23 | }} 24 | 25 | test load_make_implemented_twice {load -i -i} { 26 | -setup $ly_setup -cleanup $ly_cleanup -body { 27 | ly_cmd "load modimp-type" 28 | ly_cmd "list" "I modimp-type\r.*i modtypedef" 29 | ly_cmd "clear" 30 | ly_cmd "searchpath $::env(YANG_MODULES_DIR)" 31 | ly_cmd "load -i -i modimp-type" 32 | ly_cmd "list" "I modimp-type\r.*I modtypedef" 33 | }} 34 | 35 | test load_extended_leafref_enabled {Valid module with --extended-leafref option} { 36 | -setup $ly_setup -cleanup $ly_cleanup -body { 37 | ly_cmd "load -X modextleafref" 38 | }} 39 | 40 | test load_extended_leafref_disabled {Expected error if --extended-leafref is not set} { 41 | -setup $ly_setup -cleanup $ly_cleanup -body { 42 | ly_cmd_err "load modextleafref" "Unexpected XPath token \"FunctionName\"" 43 | }} 44 | 45 | cleanupTests 46 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/ly.tcl: -------------------------------------------------------------------------------- 1 | # @brief The main source of functions and variables for testing yanglint in the interactive mode. 2 | 3 | # For testing yanglint. 4 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/common.tcl" : "../common.tcl"}] 5 | # For testing any interactive tool. 6 | source "$::env(TESTS_DIR)/../tool_i.tcl" 7 | 8 | # The script continues by defining variables and functions specific to the interactive yanglint tool. 9 | 10 | # set the timeout to 5 seconds 11 | set timeout 5 12 | # prompt of yanglint 13 | set prompt "> " 14 | # turn off dialog between expect and yanglint 15 | log_user 0 16 | # setting some large terminal width 17 | stty columns 720 18 | 19 | # default setup for every unit test 20 | variable ly_setup { 21 | spawn $TUT 22 | ly_skip_warnings 23 | # Searchpath is set, so modules can be loaded via the 'load' command. 24 | ly_cmd "searchpath $::env(YANG_MODULES_DIR)" 25 | } 26 | 27 | # default cleanup for every unit test 28 | variable ly_cleanup { 29 | ly_exit 30 | } 31 | 32 | # Skip no dir and/or no history warnings and prompt. 33 | proc ly_skip_warnings {} { 34 | global prompt 35 | expect -re "(YANGLINT.*)*$prompt" {} 36 | } 37 | 38 | # Send command 'cmd' to the process, expect error header and then check output string by 'pattern'. 39 | # Parameter cmd is a string of arguments. 40 | # Parameter pattern is a regex. It must not contain a prompt. 41 | proc ly_cmd_err {cmd pattern} { 42 | global prompt 43 | 44 | send -- "${cmd}\r" 45 | expect -- "${cmd}\r\n" 46 | 47 | expect { 48 | -re "YANGLINT\\\[E\\\]: .*${pattern}.*\r\n${prompt}$" {} 49 | -re "libyang\\\[\[0-9]+\\\]: .*${pattern}.*\r\n${prompt}$" {} 50 | -re "\r\n${prompt}$" { 51 | error "unexpected output:\n$expect_out(buffer)" 52 | } 53 | } 54 | } 55 | 56 | # Send command 'cmd' to the process, expect warning header and then check output string by 'pattern'. 57 | # Parameter cmd is a string of arguments. 58 | # Parameter pattern is a regex. It must not contain a prompt. 59 | proc ly_cmd_wrn {cmd pattern} { 60 | ly_cmd_header $cmd "YANGLINT\\\[W\\\]:" $pattern 61 | } 62 | 63 | # Send 'exit' and wait for eof. 64 | proc ly_exit {} { 65 | send "exit\r" 66 | expect eof 67 | } 68 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/modcwd.yang: -------------------------------------------------------------------------------- 1 | module modcwd { 2 | namespace "urn:yanglint:modcwd"; 3 | prefix mc; 4 | } 5 | -------------------------------------------------------------------------------- /tests/yanglint/interactive/searchpath.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $::env(YANG_MODULES_DIR) 4 | 5 | variable ly_setup { 6 | spawn $TUT 7 | ly_skip_warnings 8 | } 9 | 10 | test searchpath_basic {} { 11 | -setup $ly_setup -cleanup $ly_cleanup -body { 12 | ly_cmd "searchpath $mdir" 13 | ly_cmd "searchpath" "$mdir" 14 | ly_cmd "load modleaf" 15 | }} 16 | 17 | test searchpath_clear {searchpath --clear} { 18 | -setup $ly_setup -cleanup $ly_cleanup -body { 19 | ly_cmd "searchpath $mdir" 20 | ly_cmd "searchpath --clear" 21 | ly_cmd_err "load modleaf" "Data model \"modleaf\" not found in local searchdirs" 22 | }} 23 | 24 | cleanupTests 25 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modaction.yang: -------------------------------------------------------------------------------- 1 | module modaction { 2 | yang-version 1.1; 3 | namespace "urn:yanglint:modaction"; 4 | prefix ma; 5 | 6 | container con { 7 | list ls { 8 | key "lfkey"; 9 | leaf lfkey { 10 | type string; 11 | } 12 | action act { 13 | input { 14 | leaf lfi { 15 | type string; 16 | } 17 | } 18 | output { 19 | leaf lfo { 20 | type int16; 21 | } 22 | } 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modconfig-augment.yang: -------------------------------------------------------------------------------- 1 | module modconfig-augment { 2 | yang-version 1.1; 3 | namespace "urn:yanglint:modconfig-augment"; 4 | prefix "mca"; 5 | 6 | import modconfig { 7 | prefix mc; 8 | } 9 | 10 | augment "/mc:mcc" { 11 | leaf alf { 12 | type string; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modconfig.yang: -------------------------------------------------------------------------------- 1 | module modconfig { 2 | namespace "urn:yanglint:modconfig"; 3 | prefix mc; 4 | 5 | container mcc { 6 | leaf lft { 7 | type string; 8 | config true; 9 | mandatory true; 10 | } 11 | leaf lff { 12 | type string; 13 | config false; 14 | mandatory true; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/yanglint/modules/moddatanodes.yang: -------------------------------------------------------------------------------- 1 | module moddatanodes { 2 | yang-version 1.1; 3 | namespace "urn:yanglint:moddatanodes"; 4 | prefix mdn; 5 | 6 | container dnc { 7 | leaf lf { 8 | type string; 9 | } 10 | leaf-list lfl { 11 | type string; 12 | } 13 | leaf mis { 14 | type string; 15 | } 16 | container con { 17 | list lt { 18 | key "kalf kblf"; 19 | leaf kalf { 20 | type string; 21 | } 22 | leaf kblf { 23 | type string; 24 | } 25 | leaf vlf { 26 | type string; 27 | } 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/yanglint/modules/moddefault.yang: -------------------------------------------------------------------------------- 1 | module moddefault { 2 | namespace "urn:yanglint:moddefault"; 3 | prefix md; 4 | 5 | container mdc { 6 | leaf lf { 7 | type uint16; 8 | } 9 | leaf di { 10 | type int16; 11 | default "5"; 12 | } 13 | leaf ds { 14 | type string; 15 | default "str"; 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modextleafref.yang: -------------------------------------------------------------------------------- 1 | module modextleafref { 2 | namespace "urn:yanglint:modextleafref"; 3 | prefix mel; 4 | 5 | list ls { 6 | key k; 7 | leaf k { 8 | type string; 9 | } 10 | leaf lf { 11 | type uint8; 12 | } 13 | } 14 | leaf lfr { 15 | type leafref { 16 | path "../ls/k"; 17 | } 18 | } 19 | leaf lfrderef { 20 | type leafref { 21 | path "deref(../lfr)/../lf"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modfeature.yang: -------------------------------------------------------------------------------- 1 | module modfeature { 2 | namespace "urn:yanglint:modfeature"; 3 | prefix l; 4 | 5 | feature ftr1; 6 | feature ftr2; 7 | } 8 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modimp-cwd.yang: -------------------------------------------------------------------------------- 1 | module modimp-cwd { 2 | namespace "urn:yanglint:modimp-cwd"; 3 | prefix ic; 4 | 5 | import modcwd { 6 | prefix mc; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modimp-path.yang: -------------------------------------------------------------------------------- 1 | module modimp-path { 2 | namespace "urn:yanglint:modimp-path"; 3 | prefix ip; 4 | 5 | import modpath { 6 | prefix mp; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modimp-type.yang: -------------------------------------------------------------------------------- 1 | module modimp-type { 2 | namespace "urn:yanglint:modimp-type"; 3 | prefix mit; 4 | 5 | import modtypedef { 6 | prefix mtd; 7 | } 8 | 9 | leaf lf { 10 | type mtd:mui8; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modinclude.yang: -------------------------------------------------------------------------------- 1 | module modinclude { 2 | yang-version 1.1; 3 | namespace "urn:yanglint:modinclude"; 4 | prefix mi; 5 | 6 | include "modsub"; 7 | 8 | container mic; 9 | } 10 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modleaf.yang: -------------------------------------------------------------------------------- 1 | module modleaf { 2 | namespace "urn:yanglint:modleaf"; 3 | prefix l; 4 | 5 | leaf lfl { 6 | type uint16; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modleafref.yang: -------------------------------------------------------------------------------- 1 | module modleafref { 2 | namespace "urn:yanglint:modleafref"; 3 | prefix m; 4 | 5 | import modleaf { 6 | prefix ml; 7 | } 8 | 9 | leaf lfr { 10 | type leafref { 11 | path "/ml:lfl"; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modmandatory.yang: -------------------------------------------------------------------------------- 1 | module modmandatory { 2 | namespace "urn:yanglint:modmandatory"; 3 | prefix mm; 4 | 5 | container mmc { 6 | leaf lft { 7 | type int16; 8 | mandatory true; 9 | } 10 | leaf lff { 11 | type int16; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modmerge.yang: -------------------------------------------------------------------------------- 1 | module modmerge { 2 | namespace "urn:yanglint:modmerge"; 3 | prefix mm; 4 | 5 | container mmc { 6 | leaf en { 7 | type enumeration { 8 | enum zero; 9 | enum one; 10 | } 11 | } 12 | leaf lm { 13 | type int16; 14 | must "../en != 'zero'"; 15 | } 16 | leaf lf { 17 | type string; 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modmust.yang: -------------------------------------------------------------------------------- 1 | module modmust { 2 | namespace "urn:yanglint:modmust"; 3 | prefix m; 4 | 5 | import modleaf { 6 | prefix ml; 7 | } 8 | 9 | leaf lfm { 10 | type string; 11 | must "/ml:lfl > 0"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modnotif.yang: -------------------------------------------------------------------------------- 1 | module modnotif { 2 | yang-version 1.1; 3 | namespace "urn:yanglint:modnotif"; 4 | prefix mn; 5 | 6 | container con { 7 | notification nfn { 8 | leaf lf { 9 | type string; 10 | } 11 | } 12 | } 13 | 14 | notification nfg { 15 | leaf lf { 16 | type string; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modoper-leafref.yang: -------------------------------------------------------------------------------- 1 | module modoper-leafref { 2 | yang-version 1.1; 3 | namespace "urn:yanglint:modoper-leafref"; 4 | prefix mol; 5 | 6 | import modconfig { 7 | prefix mc; 8 | } 9 | 10 | container cond { 11 | list list { 12 | key "klf"; 13 | leaf klf { 14 | type string; 15 | } 16 | action act { 17 | input { 18 | leaf lfi { 19 | type leafref { 20 | path "/mc:mcc/mc:lft"; 21 | } 22 | } 23 | } 24 | output { 25 | leaf lfo { 26 | type leafref { 27 | path "/mc:mcc/mc:lft"; 28 | } 29 | } 30 | } 31 | } 32 | notification notif { 33 | leaf lfn { 34 | type leafref { 35 | path "/mc:mcc/mc:lft"; 36 | } 37 | } 38 | } 39 | } 40 | } 41 | 42 | rpc rpcg { 43 | input { 44 | leaf lfi { 45 | type leafref { 46 | path "/mc:mcc/mc:lft"; 47 | } 48 | } 49 | } 50 | output { 51 | container cono { 52 | leaf lfo { 53 | type leafref { 54 | path "/mc:mcc/mc:lft"; 55 | } 56 | } 57 | } 58 | } 59 | } 60 | 61 | notification notifg { 62 | leaf lfr { 63 | type leafref { 64 | path "/mc:mcc/mc:lft"; 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modpath.yang: -------------------------------------------------------------------------------- 1 | module modpath { 2 | namespace "urn:yanglint:modpath"; 3 | prefix mp; 4 | } 5 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modrpc.yang: -------------------------------------------------------------------------------- 1 | module modrpc { 2 | namespace "urn:yanglint:modrpc"; 3 | prefix mr; 4 | 5 | rpc rpc { 6 | input { 7 | leaf lfi { 8 | type string; 9 | } 10 | } 11 | output { 12 | container con { 13 | leaf lfo { 14 | type int16; 15 | } 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modsm-augment.yang: -------------------------------------------------------------------------------- 1 | module modsm-augment { 2 | yang-version 1.1; 3 | namespace "urn:yanglint:modsm-augment"; 4 | prefix "msa"; 5 | 6 | import modsm { 7 | prefix msm; 8 | } 9 | 10 | augment "/msm:root" { 11 | leaf alf { 12 | type string; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modsm.yang: -------------------------------------------------------------------------------- 1 | module modsm { 2 | yang-version 1.1; 3 | namespace "urn:yanglint:modsm"; 4 | prefix "msm"; 5 | 6 | import ietf-yang-schema-mount { 7 | prefix sm; 8 | } 9 | 10 | container root { 11 | sm:mount-point "root"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modsub.yang: -------------------------------------------------------------------------------- 1 | submodule modsub { 2 | yang-version 1.1; 3 | belongs-to modinclude { 4 | prefix mi; 5 | } 6 | 7 | container msc; 8 | } 9 | -------------------------------------------------------------------------------- /tests/yanglint/modules/modtypedef.yang: -------------------------------------------------------------------------------- 1 | module modtypedef { 2 | namespace "urn:yanglint:typedef"; 3 | prefix mt; 4 | 5 | typedef mui8 { 6 | type uint8; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/all.tcl: -------------------------------------------------------------------------------- 1 | package require tcltest 2 | 3 | # Hook to determine if any of the tests failed. 4 | # Sets a global variable exitCode to 1 if any test fails otherwise it is set to 0. 5 | proc tcltest::cleanupTestsHook {} { 6 | variable numTests 7 | set ::exitCode [expr {$numTests(Failed) > 0}] 8 | } 9 | 10 | if {[info exists ::env(TESTS_DIR)]} { 11 | tcltest::configure -testdir "$env(TESTS_DIR)/non-interactive" 12 | } 13 | 14 | tcltest::runAllTests 15 | exit $exitCode 16 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/data_default.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mods "$::env(YANG_MODULES_DIR)/ietf-netconf-with-defaults@2011-06-01.yang $::env(YANG_MODULES_DIR)/moddefault.yang" 4 | set data "$::env(TESTS_DIR)/data/moddefault.xml" 5 | 6 | test data_default_not_set {Print data without --default parameter} { 7 | ly_cmd "-f xml $mods $data" ".*\n" 8 | ly_cmd "-f json $mods $data" "lf\".*di\"\[^\"]*" 9 | } {} 10 | 11 | test data_default_all {data --default all} { 12 | ly_cmd "-d all -f xml $mods $data" ".*.*\n" 13 | ly_cmd "-d all -f json $mods $data" "lf\".*di\".*ds\"\[^\"]*" 14 | } {} 15 | 16 | test data_default_all_tagged {data --default all-tagged} { 17 | ly_cmd "-d all-tagged -f xml $mods $data" ".*.*\n" 18 | ly_cmd "-d all-tagged -f json $mods $data" "lf\".*di\".*ds\".*@ds\".*default\"\[^\"]*" 19 | } {} 20 | 21 | test data_default_trim {data --default trim} { 22 | ly_cmd "-d trim -f xml $mods $data" "\n" 23 | ly_cmd "-d trim -f json $mods $data" "lf\"\[^\"]*" 24 | } {} 25 | 26 | test data_default_implicit_tagged {data --default implicit-tagged} { 27 | ly_cmd "-d implicit-tagged -f xml $mods $data" ".*5.*\n" 28 | ly_cmd "-d implicit-tagged -f json $mods $data" "lf\".*di\"\[^@]*ds\".*default\"\[^\"]*" 29 | } {} 30 | 31 | cleanupTests 32 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/data_in_format.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $::env(YANG_MODULES_DIR) 4 | set ddir $::env(TESTS_DIR)/data 5 | 6 | test data_in_format_xml {--in-format xml} { 7 | ly_cmd "-I xml $mdir/modleaf.yang $ddir/modleaf.dxml" 8 | ly_cmd_err "-I json $mdir/modleaf.yang $ddir/modleaf.dxml" "Failed to parse" 9 | ly_cmd_err "-I lyb $mdir/modleaf.yang $ddir/modleaf.dxml" "Failed to parse" 10 | } {} 11 | 12 | test data_in_format_json {--in-format json} { 13 | ly_cmd "-I json $mdir/modleaf.yang $ddir/modleaf.djson" 14 | ly_cmd_err "-I xml $mdir/modleaf.yang $ddir/modleaf.djson" "Failed to parse" 15 | ly_cmd_err "-I lyb $mdir/modleaf.yang $ddir/modleaf.djson" "Failed to parse" 16 | } {} 17 | 18 | cleanupTests 19 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/data_merge.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $::env(YANG_MODULES_DIR) 4 | set ddir $::env(TESTS_DIR)/data 5 | 6 | test data_merge_basic {Data is merged and the node is added} { 7 | ly_cmd "-m -f xml $mdir/modmerge.yang $ddir/modmerge.xml $ddir/modmerge3.xml" ".*.*" 8 | } {} 9 | 10 | test data_merge_validation_failed {Data is merged but validation failed.} { 11 | ly_cmd "$mdir/modmerge.yang $ddir/modmerge.xml" 12 | ly_cmd "$mdir/modmerge.yang $ddir/modmerge2.xml" 13 | ly_cmd "-m $mdir/modmerge.yang $ddir/modmerge2.xml $ddir/modmerge.xml" 14 | ly_cmd_err "-m $mdir/modmerge.yang $ddir/modmerge.xml $ddir/modmerge2.xml" "Merged data are not valid" 15 | } {} 16 | 17 | test data_merge_dataconfig {The merge option has effect only for 'data' and 'config' TYPEs} { 18 | set wrn1 "option has effect only for" 19 | ly_cmd_wrn "-m -t rpc $mdir/modrpc.yang $ddir/modrpc.xml $ddir/modrpc.xml" $wrn1 20 | ly_cmd_wrn "-m -t notif $mdir/modnotif.yang $ddir/modnotif2.xml $ddir/modnotif2.xml" $wrn1 21 | ly_cmd_wrn "-m -t get $mdir/modconfig.yang $mdir/modleaf.yang $ddir/modleaf.xml $ddir/modconfig.xml" $wrn1 22 | ly_cmd_wrn "-m -t getconfig $mdir/modconfig.yang $mdir/modleaf.yang $ddir/modleaf.xml $ddir/modconfig2.xml" $wrn1 23 | ly_cmd_wrn "-m -t edit $mdir/modconfig.yang $mdir/modleaf.yang $ddir/modleaf.xml $ddir/modconfig2.xml" $wrn1 24 | ly_cmd "-m -t config $mdir/modconfig.yang $mdir/modleaf.yang $ddir/modleaf.xml $ddir/modconfig2.xml" 25 | ly_cmd "-m -t data $mdir/modconfig.yang $mdir/modleaf.yang $ddir/modleaf.xml $ddir/modconfig.xml" 26 | } {} 27 | 28 | cleanupTests 29 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/data_not_strict.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $::env(YANG_MODULES_DIR) 4 | set ddir $::env(TESTS_DIR)/data 5 | 6 | test data_no_strict_basic {} { 7 | ly_cmd_err "$ddir/modmandatory.xml $mdir/modleaf.yang" "No module with namespace \"urn:yanglint:modmandatory\" in the context." 8 | ly_cmd "-n $ddir/modmandatory.xml $mdir/modleaf.yang" 9 | } {} 10 | 11 | test data_no_strict_invalid_data {validation with --no-strict but data are invalid} { 12 | set errmsg "Mandatory node \"lft\" instance does not exist." 13 | ly_cmd_err "-n $ddir/modmandatory_invalid.xml $mdir/modmandatory.yang" $errmsg 14 | } {} 15 | 16 | test data_no_strict_ignore_invalid_data {--no-strict ignore invalid data if no schema is provided} { 17 | ly_cmd "-f xml -n $ddir/modmandatory_invalid.xml $ddir/modleaf.xml $mdir/modleaf.yang" "modleaf.*$" 18 | } {} 19 | 20 | cleanupTests 21 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/data_present.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $::env(YANG_MODULES_DIR) 4 | set ddir $::env(TESTS_DIR)/data 5 | 6 | test data_present_via_mandatory {validation of mandatory-stmt will pass only with the --present} { 7 | set mods "$mdir/modleaf.yang $mdir/modmandatory.yang" 8 | ly_cmd_err "$ddir/modleaf.xml $mods" "Mandatory node \"lft\" instance does not exist." 9 | ly_cmd "-e $ddir/modleaf.xml $mods" 10 | } {} 11 | 12 | test data_present_merge {validation with --present and --merge} { 13 | set mods "$mdir/modleaf.yang $mdir/modmandatory.yang $mdir/moddefault.yang" 14 | set data "$ddir/modleaf.xml $ddir/moddefault.xml" 15 | ly_cmd_err "-m $data $mods" "Mandatory node \"lft\" instance does not exist." 16 | ly_cmd "-m -e $data $mods" 17 | } {} 18 | 19 | test data_present_merge_invalid {using --present and --merge but data are invalid} { 20 | set mods "$mdir/modleaf.yang $mdir/modmandatory.yang" 21 | set data "$ddir/modleaf.xml $ddir/modmandatory_invalid.xml" 22 | ly_cmd_err "-e -m $data $mods" "Mandatory node \"lft\" instance does not exist." 23 | } {} 24 | 25 | cleanupTests 26 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/data_xpath.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mod "$::env(YANG_MODULES_DIR)/moddatanodes.yang" 4 | set data "$::env(TESTS_DIR)/data/moddatanodes.xml" 5 | 6 | test data_xpath_empty {--data-path to missing node} { 7 | ly_cmd "-E /moddatanodes:dnc/mis $mod $data" "Empty" 8 | } {} 9 | 10 | test data_xpath_leaf {--xpath to leaf node} { 11 | ly_cmd "-E /moddatanodes:dnc/lf $mod $data" "leaf \"lf\" \\(value: \"x\"\\)" 12 | } {} 13 | 14 | test data_xpath_leaflist {--xpath to leaf-list node} { 15 | set r1 "leaf-list \"lfl\" \\(value: \"1\"\\)" 16 | set r2 "leaf-list \"lfl\" \\(value: \"2\"\\)" 17 | ly_cmd "-E /moddatanodes:dnc/lfl $mod $data" "$r1\n $r2" 18 | } {} 19 | 20 | test data_xpath_list {--xpath to list} { 21 | set r1 "list \"lt\" \\(\"kalf\": \"ka1\"; \"kblf\": \"kb1\";\\)" 22 | set r2 "list \"lt\" \\(\"kalf\": \"ka2\"; \"kblf\": \"kb2\";\\)" 23 | ly_cmd "-E /moddatanodes:dnc/con/lt $mod $data" "$r1\n $r2" 24 | } {} 25 | 26 | test data_xpath_container {--xpath to container} { 27 | ly_cmd "-E /moddatanodes:dnc/con $mod $data" "container \"con\"" 28 | } {} 29 | 30 | test data_xpath_wrong_path {--xpath to a non-existent node} { 31 | ly_cmd_err "-E /moddatanodes:dnc/wrng $mod $data" "xpath failed" 32 | } {} 33 | 34 | test data_xpath_err_format {--xpath cannot be combined with --format} { 35 | ly_cmd_err "-f xml -E /moddatanodes:dnc/lf $mod $data" "option cannot be combined" 36 | } {} 37 | 38 | test data_xpath_err_default {--xpath cannot be combined with --default} { 39 | ly_cmd_err "-d all -E /moddatanodes:dnc/lf $mod $data" "option cannot be combined" 40 | } {} 41 | 42 | cleanupTests 43 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/disabled_searchdir.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $env(YANG_MODULES_DIR) 4 | 5 | # Test should be skipped if called by ctest. 6 | test disable_searchdir_once {Unsuccessfully imports module due to disabled cwd searching} { 7 | -constraints {!ctest} -body { 8 | ly_cmd "$mdir/modimp-cwd.yang" 9 | ly_cmd_err "-D $mdir/modimp-cwd.yang" "not found in local searchdirs" 10 | }} 11 | 12 | test disable_searchdir_twice {Unsuccessfully imports module due to -D -D} { 13 | ly_cmd "$mdir/ietf-ip.yang" 14 | ly_cmd_err "-D -D $mdir/ietf-ip.yang" "Loading \"ietf-interfaces\" module failed." 15 | } {} 16 | 17 | cleanupTests 18 | 19 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/ext_data.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir "$::env(YANG_MODULES_DIR)" 4 | set ddir "$::env(TESTS_DIR)/data" 5 | 6 | test ext_data_schema_mount_tree {Print tree output of a model with Schema Mount} { 7 | # mounting node lfl from modleaf.yang into modsm.yang 8 | set out1 "--mp root.*--rw lfl/" 9 | ly_cmd "-f tree -p $mdir -y -x $ddir/modsm_ctx_ext.xml $mdir/modsm.yang" $out1 10 | } {} 11 | 12 | test ext_data_schema_mount_tree_yanglibfile {Print tree output of a model with Schema Mount and --yang-library-file} { 13 | # yang-library-file context contains an augment node 'alf' for modsm 14 | set out1 "--mp root.*--rw lfl/.*--rw msa:alf?" 15 | ly_cmd "-f tree -p $mdir -Y $ddir/modsm_ctx_main.xml -x $ddir/modsm_ctx_ext.xml $mdir/modsm.yang" $out1 16 | } {} 17 | 18 | test ext_data_schema_mount_xml {Validating and printing mounted data} { 19 | ly_cmd "-f xml -t config -p $mdir -y -x $ddir/modsm_ctx_ext.xml $mdir/modsm.yang $ddir/modsm.xml" "" 20 | } {} 21 | 22 | test ext_data_schema_mount_xml_yanglibfile {Validating and printing mounted data with --yang-library-file} { 23 | set yanglibfile "$ddir/modsm_ctx_main.xml" 24 | set extdata "$ddir/modsm_ctx_ext.xml" 25 | set out1 ".*" 26 | ly_cmd "-f xml -t config -p $mdir -Y $yanglibfile -x $extdata $mdir/modsm.yang $ddir/modsm2.xml" $out1 27 | } {} 28 | 29 | cleanupTests 30 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/extended_leafref.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $::env(YANG_MODULES_DIR) 4 | 5 | test extended_leafref_enabled {Valid module with --extended-leafref option} { 6 | ly_cmd "-X $mdir/modextleafref.yang" 7 | } {} 8 | 9 | test extended_leafref_disabled {Expected error if --extended-leafref is not set} { 10 | ly_cmd_err "$mdir/modextleafref.yang" "Unexpected XPath token \"FunctionName\"" 11 | } {} 12 | 13 | cleanupTests 14 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/list.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | namespace import uti::regex_xml_elements uti::regex_json_pairs 3 | 4 | set modules {ietf-yang-library ietf-inet-types} 5 | 6 | test list_basic {} { 7 | ly_cmd "-l" "ietf-yang-types" 8 | } {} 9 | 10 | test list_format_xml {list --format xml} { 11 | ly_cmd "-y -f xml -l" [regex_xml_elements $modules "name"] 12 | } {} 13 | 14 | test list_format_json {list --format json} { 15 | ly_cmd "-y -f json -l" [regex_json_pairs $modules "name"] 16 | } {} 17 | 18 | test list_ietf_yang_library {Error due to missing ietf-yang-library} { 19 | ly_cmd_err "-f xml -l" "Module \"ietf-yang-library\" is not implemented." 20 | } {} 21 | 22 | test list_bad_format {Error due to bad format} { 23 | ly_cmd_err "-f csv -l" "Unknown output format csv" 24 | } {} 25 | 26 | cleanupTests 27 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/ly.tcl: -------------------------------------------------------------------------------- 1 | # @brief The main source of functions and variables for testing yanglint in the non-interactive mode. 2 | 3 | # For testing yanglint. 4 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/common.tcl" : "../common.tcl"}] 5 | # For testing any non-interactive tool. 6 | source "$::env(TESTS_DIR)/../tool_ni.tcl" 7 | 8 | # The script continues by defining variables and functions specific to the non-interactive yanglint tool. 9 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/make_implemented.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $::env(YANG_MODULES_DIR) 4 | 5 | test make_impl_no_set {Import while --make-implemented is not set} { 6 | ly_cmd "-l $mdir/modleafref.yang" "I modleafref\n.*I modleaf" 7 | } {} 8 | 9 | test make_impl_set_once {--make-implemented} { 10 | ly_cmd "-l -i $mdir/modmust.yang" "I modmust\n.*I modleaf" 11 | } {} 12 | 13 | test make_impl_set_twice {-i -i} { 14 | ly_cmd "-l -i -i $mdir/modimp-type.yang" "I modimp-type\n.*I modtypedef" 15 | } {} 16 | 17 | cleanupTests 18 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/modcwd.yang: -------------------------------------------------------------------------------- 1 | module modcwd { 2 | namespace "urn:yanglint:modcwd"; 3 | prefix mc; 4 | } 5 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/path.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir $env(YANG_MODULES_DIR) 4 | 5 | test path_basic {} { 6 | ly_cmd "-p $::env(TESTS_DIR)/data $::env(YANG_MODULES_DIR)/modimp-path.yang" 7 | } {} 8 | 9 | cleanupTests 10 | -------------------------------------------------------------------------------- /tests/yanglint/non-interactive/yang_library_file.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/non-interactive/ly.tcl" : "ly.tcl"}] 2 | 3 | set mdir "$::env(YANG_MODULES_DIR)" 4 | set ddir "$::env(TESTS_DIR)/data" 5 | 6 | test ylf_list {apply --yang-library-file and check result by --list} { 7 | ly_cmd "-Y $ddir/modimp_type_ctx.xml -p $mdir -l" "I modimp-type.*i modtypedef" 8 | } {} 9 | 10 | test ylf_make_implemented {apply --yang-library-file and --make-implemented} { 11 | ly_cmd "-Y $ddir/modimp_type_ctx.xml -p $mdir -i -i -l" "I modimp-type.*I modtypedef" 12 | } {} 13 | 14 | test ylf_augment_ctx {Setup context by yang-library-file and augment module} { 15 | ly_cmd "-Y $ddir/modconfig_ctx.xml -p $mdir -f tree $mdir/modconfig.yang $mdir/modconfig-augment.yang" "mca:alf" 16 | } {} 17 | 18 | cleanupTests 19 | -------------------------------------------------------------------------------- /tests/yangre/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_program(PATH_TCLSH NAMES tclsh) 2 | if(NOT PATH_TCLSH) 3 | message(WARNING "'tclsh' not found! The yangre test will not be available.") 4 | else() 5 | add_test(NAME "yangre" COMMAND "tclsh" "${CMAKE_CURRENT_SOURCE_DIR}/all.tcl") 6 | set_property(TEST "yangre" APPEND PROPERTY ENVIRONMENT "TESTS_DIR=${CMAKE_CURRENT_SOURCE_DIR}") 7 | set_property(TEST "yangre" APPEND PROPERTY ENVIRONMENT "YANGRE=${PROJECT_BINARY_DIR}") 8 | endif() 9 | -------------------------------------------------------------------------------- /tests/yangre/all.tcl: -------------------------------------------------------------------------------- 1 | package require tcltest 2 | 3 | # Hook to determine if any of the tests failed. 4 | # Sets a global variable exitCode to 1 if any test fails otherwise it is set to 0. 5 | proc tcltest::cleanupTestsHook {} { 6 | variable numTests 7 | set ::exitCode [expr {$numTests(Failed) > 0}] 8 | } 9 | 10 | if {[info exists ::env(TESTS_DIR)]} { 11 | tcltest::configure -testdir "$env(TESTS_DIR)" 12 | } 13 | 14 | tcltest::runAllTests 15 | exit $exitCode 16 | -------------------------------------------------------------------------------- /tests/yangre/arg.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/ly.tcl" : "ly.tcl"}] 2 | 3 | test arg_empty {Missing arguments} { 4 | ly_cmd_err "" "missing parameter to process" 5 | } {} 6 | 7 | test arg_wrong {Wrong argument} { 8 | ly_cmd_err "-j" "invalid option" 9 | } {} 10 | 11 | test arg_help {Print help} { 12 | ly_cmd "-h" "Usage:" 13 | } {} 14 | 15 | test arg_version {Print version} { 16 | ly_cmd "-v" "yangre" 17 | } {} 18 | 19 | cleanupTests 20 | -------------------------------------------------------------------------------- /tests/yangre/file.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/ly.tcl" : "ly.tcl"}] 2 | 3 | set fdir "$::env(TESTS_DIR)/files" 4 | 5 | test file_empty {file is empty} { 6 | ly_cmd "-f $fdir/empty.txt" 7 | } {} 8 | 9 | test file_empty_str { is empty} { 10 | ly_cmd "-f $fdir/empty_str.txt" 11 | } {} 12 | 13 | test file_empty_str_err {empty is not allowed} { 14 | ly_cmd_err "-f $fdir/empty_str_err.txt" "does not conform" 15 | } {} 16 | 17 | test file_one_pattern {one pattern in the file} { 18 | ly_cmd "-f $fdir/one_pattern.txt" 19 | } {} 20 | 21 | test file_two_patterns {two patterns in the file} { 22 | ly_cmd "-f $fdir/two_patterns.txt" 23 | } {} 24 | 25 | test file_two_patterns_err {two patterns and the is wrong} { 26 | ly_cmd_err "-f $fdir/two_patterns_err.txt" "does not conform" 27 | } {} 28 | 29 | test file_two_patterns_invert_match {one pattern is inverted} { 30 | ly_cmd "-f $fdir/two_patterns_invert_match.txt" 31 | } {} 32 | 33 | test file_two_patterns_invert_match_err {one pattern is inverted and the is wrong} { 34 | ly_cmd_err "-f $fdir/two_patterns_invert_match_err.txt" "does not conform to inverted" 35 | } {} 36 | 37 | cleanupTests 38 | -------------------------------------------------------------------------------- /tests/yangre/files/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CESNET/libyang/da7272e19d9e27d1bfdd68108fa9dce25fbdf5e8/tests/yangre/files/empty.txt -------------------------------------------------------------------------------- /tests/yangre/files/empty_str.txt: -------------------------------------------------------------------------------- 1 | "[0-9a-fA-F]*" 2 | 3 | -------------------------------------------------------------------------------- /tests/yangre/files/empty_str_err.txt: -------------------------------------------------------------------------------- 1 | "[0-9a-fA-F]+" 2 | 3 | -------------------------------------------------------------------------------- /tests/yangre/files/one_pattern.txt: -------------------------------------------------------------------------------- 1 | "[0-9a-fA-F]*" 2 | 3 | 1F 4 | -------------------------------------------------------------------------------- /tests/yangre/files/two_patterns.txt: -------------------------------------------------------------------------------- 1 | "[0-9a-fA-F]*" 2 | '[a-zA-Z0-9\-_.]*' 3 | 4 | 1F 5 | -------------------------------------------------------------------------------- /tests/yangre/files/two_patterns_err.txt: -------------------------------------------------------------------------------- 1 | "[0-9a-fA-F]*" 2 | '[a-zA-Z0-9\-_.]*' 3 | 4 | @!@ 5 | -------------------------------------------------------------------------------- /tests/yangre/files/two_patterns_invert_match.txt: -------------------------------------------------------------------------------- 1 | "[a-z]*" 2 | '[a-f]*' 3 | 4 | gh 5 | -------------------------------------------------------------------------------- /tests/yangre/files/two_patterns_invert_match_err.txt: -------------------------------------------------------------------------------- 1 | "[a-z]*" 2 | '[a-f]*' 3 | 4 | ab 5 | -------------------------------------------------------------------------------- /tests/yangre/invert_match.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/ly.tcl" : "ly.tcl"}] 2 | 3 | test invert_match_from_help1 {Test the first pattern from help via invert match} { 4 | ly_cmd_err {-p {"[0-9a-fA-F]*"} -i {1F}} "not conform to inverted" 5 | ly_cmd {-p {"[0-9a-fA-F]*"} -i {GUN}} 6 | } {} 7 | 8 | test invert_match_from_help2 {Test the second pattern from help via invert match} { 9 | ly_cmd_err {-p {'[a-zA-Z0-9\-_.]*'} -i {a-b}} "not conform to inverted" 10 | ly_cmd {-p {'[a-zA-Z0-9\-_.]*'} -i {%@}} 11 | } {} 12 | 13 | test invert_match_from_help3 {Test the third pattern from help via invert match} { 14 | ly_cmd_err {-p {[xX][mM][lL].*} -i {xml-encoding}} "not conform to inverted" 15 | ly_cmd {-p {[xX][mM][lL].*} -i {json}} 16 | } {} 17 | 18 | test invert_match_three_at_once {Test three inverted patterns and once} { 19 | ly_cmd_err {-p {"[0-9a-zA-Z]*"} -i -p {'[a-zA-Z0-9\-_.]*'} -i -p {[xX][mM][lL].*} -i {xml}} "not conform to inverted" 20 | ly_cmd {-p {"[0-9a-zA-Z]*"} -i -p {'[a-zA-Z0-9\-_.]*'} -i -p {[xX][mM][lL].*} -i {%@}} 21 | } {} 22 | 23 | test invert_match_second_is_not {Test three patterns but the second one is not inverted} { 24 | ly_cmd_err {-p {"[0-9a-zA-Z]*"} -i -p {'[a-zA-Z0-9\-_.]*'} -i -p {[xX][mM][lL].*} -i {o_O}} "not conform to inverted" 25 | ly_cmd {-p {"[0-9a-zA-Z]*"} -i -p {'[a-zA-Z0-9\-_.]*'} -p {[xX][mM][lL].*} -i {o_O}} 26 | } {} 27 | 28 | cleanupTests 29 | -------------------------------------------------------------------------------- /tests/yangre/ly.tcl: -------------------------------------------------------------------------------- 1 | # @brief The main source of functions and variables for testing yangre. 2 | 3 | package require tcltest 4 | namespace import ::tcltest::test ::tcltest::cleanupTests 5 | 6 | if { ![info exists ::env(TESTS_DIR)] } { 7 | # the script is not run via 'ctest' so paths must be set 8 | set ::env(TESTS_DIR) "./" 9 | set TUT_PATH "../../build" 10 | } else { 11 | # cmake (ctest) already sets ::env variables 12 | set TUT_PATH $::env(YANGRE) 13 | } 14 | set TUT_NAME "yangre" 15 | source "$::env(TESTS_DIR)/../tool_ni.tcl" 16 | 17 | # The script continues by defining variables and functions specific to the yangre tool. 18 | -------------------------------------------------------------------------------- /tests/yangre/pattern.test: -------------------------------------------------------------------------------- 1 | source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/ly.tcl" : "ly.tcl"}] 2 | 3 | test pattern_from_help1 {Test the first pattern from help} { 4 | ly_cmd {-p {"[0-9a-fA-F]*"} {1F}} 5 | } {} 6 | 7 | test pattern_from_help2 {Test the second pattern from help} { 8 | ly_cmd {-p {'[a-zA-Z0-9\-_.]*'} {a-b}} 9 | } {} 10 | 11 | test pattern_from_help3 {Test the third pattern from help} { 12 | ly_cmd {-p {[xX][mM][lL].*} {xml-encoding}} 13 | } {} 14 | 15 | test pattern_three_at_once {Test three patterns and once} { 16 | ly_cmd {-p {"[0-9a-zA-Z]*"} -p {'[a-zA-Z0-9\-_.]*'} -p {[xX][mM][lL].*} {xml}} 17 | } {} 18 | 19 | cleanupTests 20 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CheckIncludeFile) 2 | 3 | # config file for tools 4 | configure_file(${PROJECT_SOURCE_DIR}/tools/config.h.in ${PROJECT_BINARY_DIR}/tools/config.h @ONLY) 5 | 6 | # find ioctl 7 | check_include_file("sys/ioctl.h" HAVE_IOCTL) 8 | if(NOT HAVE_IOCTL) 9 | message(STATUS "Disabling interactive yanglint, sys/ioctl.h not found...") 10 | set(ENABLE_YANGLINT_INTERACTIVE OFF) 11 | endif() 12 | 13 | # find getopt library on WIN32 14 | if(WIN32) 15 | find_library(GETOPT_LIBRARY NAMES getopt REQUIRED) 16 | find_path(GETOPT_INCLUDE_DIR NAMES getopt.h REQUIRED) 17 | message(STATUS "Found at ${GETOPT_INCLUDE_DIR}, library at ${GETOPT_LIBRARY}") 18 | endif() 19 | 20 | add_subdirectory(lint) 21 | add_subdirectory(re) 22 | 23 | set(format_sources 24 | ${format_sources} 25 | PARENT_SCOPE) 26 | -------------------------------------------------------------------------------- /tools/config.h.in: -------------------------------------------------------------------------------- 1 | /** 2 | * @file config.h 3 | * @author Radek Krejci 4 | * @brief various variables detected by cmake 5 | * 6 | * Copyright (c) 2019 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 | #ifndef YANGLINT_CONFIG_H_ 16 | #define YANGLINT_CONFIG_H_ 17 | 18 | #define PROJECT_VERSION "@LIBYANG_VERSION@" /**< libyang project version string */ 19 | 20 | #endif /* YANGLINT_CONFIG_H_ */ 21 | -------------------------------------------------------------------------------- /tools/lint/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # yanglint 2 | set(lintsrc 3 | main_ni.c 4 | cmd.c 5 | cmd_add.c 6 | cmd_clear.c 7 | cmd_data.c 8 | cmd_list.c 9 | cmd_feature.c 10 | cmd_load.c 11 | cmd_print.c 12 | cmd_searchpath.c 13 | cmd_extdata.c 14 | cmd_help.c 15 | cmd_verb.c 16 | cmd_debug.c 17 | yl_opt.c 18 | yl_schema_features.c 19 | common.c 20 | ) 21 | 22 | if(ENABLE_YANGLINT_INTERACTIVE) 23 | set(lintsrc ${lintsrc} 24 | main.c 25 | completion.c 26 | configuration.c 27 | linenoise/linenoise.c 28 | linenoise/utf8.c) 29 | else() 30 | set(lintsrc ${lintsrc} 31 | main_ni_only.c) 32 | endif() 33 | 34 | set(format_sources 35 | ${format_sources} 36 | ${CMAKE_CURRENT_SOURCE_DIR}/*.c 37 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h 38 | PARENT_SCOPE) 39 | 40 | add_executable(yanglint ${lintsrc} ${compatsrc}) 41 | target_link_libraries(yanglint yang) 42 | install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR}) 43 | install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) 44 | target_include_directories(yanglint BEFORE PRIVATE ${PROJECT_BINARY_DIR}) 45 | 46 | if(WIN32) 47 | target_include_directories(yanglint PRIVATE ${GETOPT_INCLUDE_DIR}) 48 | target_link_libraries(yanglint ${GETOPT_LIBRARY}) 49 | endif() 50 | -------------------------------------------------------------------------------- /tools/lint/completion.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file completion.h 3 | * @author Michal Vasko 4 | * @brief libyang's yanglint tool auto completion header 5 | * 6 | * Copyright (c) 2015 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 | #ifndef COMPLETION_H_ 16 | #define COMPLETION_H_ 17 | 18 | #include "./linenoise/linenoise.h" 19 | 20 | /** 21 | * @brief Command line completion callback. 22 | */ 23 | void complete_cmd(const char *buf, const char *hint, linenoiseCompletions *lc); 24 | 25 | #endif /* COMPLETION_H_ */ 26 | -------------------------------------------------------------------------------- /tools/lint/configuration.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file configuration.h 3 | * @author Michal Vasko 4 | * @brief yanglint configuration header 5 | * 6 | * Copyright (c) 2017 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 | #ifndef CONFIGURATION_H_ 16 | #define CONFIGURATION_H_ 17 | 18 | /** 19 | * @brief Finds the current user's yanglint dir 20 | * @return NULL on failure, dynamically allocated yanglint dir path 21 | * otherwise 22 | */ 23 | char *get_yanglint_dir(void); 24 | 25 | /** 26 | * @brief Checks all the relevant files and directories creating any 27 | * that are missing, sets the saved configuration (currently only history) 28 | */ 29 | void load_config(void); 30 | 31 | /** 32 | * @brief Saves the current configuration (currently only history) 33 | */ 34 | void store_config(void); 35 | 36 | #endif /* CONFIGURATION_H_ */ 37 | -------------------------------------------------------------------------------- /tools/lint/examples/action-reply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | key_val 4 | 5 | some_output 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tools/lint/examples/action.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | key_val 4 | 5 | some_input 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tools/lint/examples/config-acm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | almighty 4 | almighty 5 | test 6 | 7 | almighty 8 | * 9 | * 10 | permit 11 | 12 | 13 | 14 | 15 | test 16 | smith 17 | 18 | 19 | almighty 20 | smith 21 | doe 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tools/lint/examples/config-missing-key.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | almighty 4 | almighty 5 | test 6 | 7 | almighty 8 | * 9 | * 10 | permit 11 | 12 | 13 | 14 | 15 | test 16 | smith 17 | 18 | 19 | almighty 20 | smith 21 | doe 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tools/lint/examples/config-unknown-element.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | almighty 4 | almighty 5 | test 6 | 7 | almighty 8 | * 9 | * 10 | permit 11 | 12 | 13 | 14 | 15 | test 16 | smith 17 | 18 | 19 | almighty 20 | smith 21 | doe 22 | 23 | 24 | 0 25 | 0 26 | 0 27 | 28 | -------------------------------------------------------------------------------- /tools/lint/examples/data-acm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | almighty 4 | almighty 5 | test 6 | 7 | almighty 8 | * 9 | * 10 | permit 11 | 12 | 13 | 14 | 15 | test 16 | smith 17 | 18 | 19 | almighty 20 | smith 21 | doe 22 | 23 | 24 | 0 25 | 0 26 | 0 27 | 28 | -------------------------------------------------------------------------------- /tools/lint/examples/data-ip.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | eth0 4 | Wire Connection 5 | ift:ethernetCsmacd 6 | true 7 | 8 |
192.168.1.15255.255.255.0
9 |
192.168.1.10255.255.255.0
10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /tools/lint/examples/data-malformed-xml.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | almighty 4 | almighty 5 | test 6 | 7 | almighty 8 | * 9 | * 10 | permit 11 | 12 | 13 | 14 | 15 | test 16 | smith 17 | 18 | 19 | almighty 20 | smith 21 | doe 22 | 23 | 24 | 0 25 | 0 26 | 0 27 | 28 | -------------------------------------------------------------------------------- /tools/lint/examples/data-malformed-xml2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | almighty 4 | almighty 5 | test 6 | 7 | almighty * 8 | * 9 | permit 10 | 11 | 12 | 13 | 14 | test 15 | smith 16 | 17 | 18 | almighty 19 | smith 20 | doe 21 | 22 | 23 | 0 24 | 0 25 | 0 26 | 27 | -------------------------------------------------------------------------------- /tools/lint/examples/data-missing-key.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | almighty 4 | almighty 5 | test 6 | 7 | * 8 | * 9 | permit 10 | 11 | 12 | 13 | 14 | test 15 | smith 16 | 17 | 18 | almighty 19 | smith 20 | doe 21 | 22 | 23 | 0 24 | 0 25 | 0 26 | 27 | -------------------------------------------------------------------------------- /tools/lint/examples/data-out-of-range-value.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | almighty 4 | almighty 5 | test 6 | 7 | almighty 8 | * 9 | * 10 | permit 11 | 12 | 13 | 14 | 15 | test 16 | smith 17 | 18 | 19 | almighty 20 | smith 21 | doe 22 | 23 | 24 | -1 25 | 0 26 | 0 27 | 28 | -------------------------------------------------------------------------------- /tools/lint/examples/datastore.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | almighty 4 | almighty 5 | 6 | almighty 7 | * 8 | * 9 | permit 10 | 11 | 12 | 13 | 14 | almighty 15 | smith 16 | 17 | 18 | 19 | 20 | 21 | eth0 22 | Wire Connection 23 | ift:ethernetCsmacd 24 | true 25 | 26 |
192.168.1.1524
27 |
28 |
29 |
30 | -------------------------------------------------------------------------------- /tools/lint/examples/module1.yang: -------------------------------------------------------------------------------- 1 | module module1 { 2 | namespace "urn:yanglint:module"; 3 | prefix m; 4 | leaf m { type string; } 5 | } 6 | -------------------------------------------------------------------------------- /tools/lint/examples/module1b.yang: -------------------------------------------------------------------------------- 1 | module module1b { 2 | namespace "urn:yanglint:module"; 3 | prefix m; 4 | leaf mb { type string; } 5 | } 6 | -------------------------------------------------------------------------------- /tools/lint/examples/module2.yang: -------------------------------------------------------------------------------- 1 | module module2 { 2 | namespace "urn:yanglint:module"; 3 | prefix m; 4 | leaf m { ttype string; } 5 | } 6 | -------------------------------------------------------------------------------- /tools/lint/examples/module2.yin: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tools/lint/examples/module3.yang: -------------------------------------------------------------------------------- 1 | module module3 { 2 | namespace "urn:yanglint:module"; 3 | prefix m; 4 | leaf m { type string; must "../c/a"; } 5 | container c { 6 | leaf b { type string; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tools/lint/examples/module4.yang: -------------------------------------------------------------------------------- 1 | module module4 { 2 | yang-version 1.1; 3 | namespace "urn:module4"; 4 | prefix m4; 5 | 6 | container cont1 { 7 | list list { 8 | key "leaf1"; 9 | leaf leaf1 { 10 | type string; 11 | } 12 | action act { 13 | input { 14 | leaf leaf2 { 15 | type string; 16 | } 17 | } 18 | output { 19 | leaf leaf3 { 20 | type string; 21 | } 22 | } 23 | } 24 | notification notif1 { 25 | leaf leaf4 { 26 | type string; 27 | } 28 | } 29 | } 30 | } 31 | 32 | rpc rpc { 33 | input { 34 | leaf leaf5 { 35 | type string; 36 | } 37 | } 38 | output { 39 | container cont2 { 40 | leaf leaf6 { 41 | type empty; 42 | } 43 | } 44 | } 45 | } 46 | 47 | notification notif2 { 48 | leaf leaf7 { 49 | type empty; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tools/lint/examples/nested-notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | key_val 4 | 5 | some_value 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tools/lint/examples/notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tools/lint/examples/rpc-reply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tools/lint/examples/rpc.xml: -------------------------------------------------------------------------------- 1 | 2 | some_input 3 | 4 | -------------------------------------------------------------------------------- /tools/lint/examples/sm-context-extension.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | test-set 5 | 6 | ietf-datastores 7 | 2018-02-14 8 | urn:ietf:params:xml:ns:yang:ietf-datastores 9 | 10 | 11 | ietf-yang-library 12 | 2019-01-04 13 | urn:ietf:params:xml:ns:yang:ietf-yang-library 14 | 15 | 16 | sm-extension 17 | urn:sm-ext 18 | 19 | 20 | iana-if-type 21 | urn:ietf:params:xml:ns:yang:iana-if-type 22 | 23 | 24 | ietf-yang-types 25 | 2013-07-15 26 | urn:ietf:params:xml:ns:yang:ietf-yang-types 27 | 28 | 29 | sm-mod 30 | 2017-01-26 31 | urn:yanglint:sm-mod 32 | 33 | 34 | 35 | test-schema 36 | test-set 37 | 38 | 39 | ds:running 40 | test-schema 41 | 42 | 43 | ds:operational 44 | test-schema 45 | 46 | 1 47 | 48 | 49 | 1 50 | 51 | 52 | 53 | if 54 | urn:ietf:params:xml:ns:yang:ietf-interfaces 55 | 56 | 57 | sm-main 58 | 59 | 60 | /if:interfaces/if:interface/if:name 61 | /if:interfaces/if:interface/if:type 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /tools/lint/examples/sm-context-main.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | main-set 5 | 6 | ietf-datastores 7 | 2018-02-14 8 | urn:ietf:params:xml:ns:yang:ietf-datastores 9 | 10 | 11 | ietf-yang-library 12 | 2019-01-04 13 | urn:ietf:params:xml:ns:yang:ietf-yang-library 14 | 15 | 16 | ietf-yang-schema-mount 17 | 2019-01-14 18 | urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount 19 | 20 | 21 | sm-main 22 | urn:sm-main 23 | 24 | 25 | iana-if-type 26 | urn:ietf:params:xml:ns:yang:iana-if-type 27 | 28 | 29 | ietf-interfaces 30 | urn:ietf:params:xml:ns:yang:ietf-interfaces 31 | 32 | 33 | ietf-yang-types 34 | 2013-07-15 35 | urn:ietf:params:xml:ns:yang:ietf-yang-types 36 | 37 | 38 | 39 | main-schema 40 | main-set 41 | 42 | 43 | ds:running 44 | main-schema 45 | 46 | 47 | ds:operational 48 | main-schema 49 | 50 | 1 51 | 52 | 53 | 2 54 | 55 | -------------------------------------------------------------------------------- /tools/lint/examples/sm-data.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | eth0 4 | ift:ethernetCsmacd 5 | 6 | 7 | eth1 8 | ift:ethernetCsmacd 9 | 10 | 11 | 12 | 13 | list item 1 14 | 15 | eth0 16 | 1 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tools/lint/examples/sm-extension.yang: -------------------------------------------------------------------------------- 1 | module sm-extension { 2 | yang-version 1.1; 3 | namespace "urn:sm-ext"; 4 | prefix "sm-ext"; 5 | 6 | import ietf-interfaces { 7 | prefix if; 8 | } 9 | import sm-mod { 10 | prefix sm-mod; 11 | } 12 | 13 | revision 2022-09-15 { 14 | description 15 | "initial"; 16 | reference 17 | ""; 18 | } 19 | 20 | list things { 21 | key "name"; 22 | leaf name { 23 | type leafref { 24 | path "/if:interfaces/if:interface/if:name"; 25 | } 26 | } 27 | leaf attribute { 28 | type uint32; 29 | } 30 | } 31 | 32 | augment "/if:interfaces/if:interface" { 33 | leaf thing-attribute { 34 | type leafref { 35 | path "/things/attribute"; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tools/lint/examples/sm-main.yang: -------------------------------------------------------------------------------- 1 | module sm-main { 2 | yang-version 1.1; 3 | namespace "urn:sm-main"; 4 | prefix "sm-main"; 5 | 6 | import ietf-yang-schema-mount { 7 | prefix yangmnt; 8 | } 9 | import ietf-interfaces { 10 | prefix if; 11 | } 12 | 13 | list root { 14 | key "node"; 15 | leaf node { 16 | type string; 17 | } 18 | yangmnt:mount-point "root"; 19 | } 20 | container root2 { 21 | yangmnt:mount-point "root"; 22 | } 23 | container root3 { 24 | list my-list { 25 | key name; 26 | leaf name { 27 | type string; 28 | } 29 | yangmnt:mount-point "mnt-root"; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tools/lint/examples/sm-mod.yang: -------------------------------------------------------------------------------- 1 | module sm-mod { 2 | yang-version 1.1; 3 | namespace "urn:yanglint:sm-mod"; 4 | prefix "sm-mod"; 5 | 6 | revision 2017-01-26 { 7 | description 8 | "initial"; 9 | reference 10 | ""; 11 | } 12 | 13 | container not-compiled { 14 | leaf first { 15 | type string; 16 | } 17 | leaf second { 18 | type string; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tools/lint/linenoise/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2014, Salvatore Sanfilippo 2 | Copyright (c) 2010-2013, Pieter Noordhuis 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /tools/lint/linenoise/utf8.h: -------------------------------------------------------------------------------- 1 | /* encodings/utf8.h -- VERSION 1.0 2 | * 3 | * Guerrilla line editing library against the idea that a line editing lib 4 | * needs to be 20,000 lines of C code. 5 | * 6 | * See linenoise.c for more information. 7 | * 8 | * ------------------------------------------------------------------------ 9 | * 10 | * Copyright (c) 2010-2014, Salvatore Sanfilippo 11 | * Copyright (c) 2010-2013, Pieter Noordhuis 12 | * 13 | * All rights reserved. 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions are 17 | * met: 18 | * 19 | * * Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * 22 | * * Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #ifndef __LINENOISE_ENCODINGS_UTF8_H 40 | #define __LINENOISE_ENCODINGS_UTF8_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | size_t linenoiseUtf8PrevCharLen(const char* buf, size_t buf_len, size_t pos, size_t *col_len); 47 | size_t linenoiseUtf8NextCharLen(const char* buf, size_t buf_len, size_t pos, size_t *col_len); 48 | size_t linenoiseUtf8ReadCode(int fd, char* buf, size_t buf_len, int* cp); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __LINENOISE_ENCODINGS_UTF8_H */ 55 | 56 | -------------------------------------------------------------------------------- /tools/lint/main_ni_only.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file main_ni_only.c 3 | * @brief non-interactive implementation of main() for those platforms without the linenoise library 4 | * 5 | * Copyright (c) 2015-2021 CESNET, z.s.p.o. 6 | * 7 | * This source code is licensed under BSD 3-Clause License (the "License"). 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * https://opensource.org/licenses/BSD-3-Clause 12 | */ 13 | 14 | int main_ni(int argc, char *argv[]); 15 | 16 | int done; /* for cmd.c */ 17 | 18 | int 19 | main(int argc, char *argv[]) 20 | { 21 | return main_ni(argc, argv); 22 | } 23 | -------------------------------------------------------------------------------- /tools/re/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # yangre 2 | 3 | set(resrc 4 | main.c) 5 | 6 | set(format_sources 7 | ${format_sources} 8 | ${CMAKE_CURRENT_SOURCE_DIR}/*.c 9 | PARENT_SCOPE) 10 | 11 | add_executable(yangre ${resrc} ${compatsrc}) 12 | target_link_libraries(yangre yang) 13 | install(TARGETS yangre DESTINATION ${CMAKE_INSTALL_BINDIR}) 14 | install(FILES ${PROJECT_SOURCE_DIR}/tools/re/yangre.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) 15 | target_include_directories(yangre BEFORE PRIVATE ${PROJECT_BINARY_DIR}) 16 | 17 | if(WIN32) 18 | target_include_directories(yangre PRIVATE ${GETOPT_INCLUDE_DIR}) 19 | target_link_libraries(yangre ${GETOPT_LIBRARY}) 20 | endif() 21 | --------------------------------------------------------------------------------