diff options
author | Raimo Niskanen <[email protected]> | 2018-06-11 15:26:16 +0200 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2018-06-11 15:26:16 +0200 |
commit | 2241b602a33d872a8fc057bafaba770b76491394 (patch) | |
tree | 26fe69a967e9b05a6aba1737d4d79adb838bb241 /lib | |
parent | 558f6498f51242f2a668bae08b0bfff41f591bf4 (diff) | |
parent | 03ca198787cc2ac787f96636f68b26eb4dcdee70 (diff) | |
download | otp-2241b602a33d872a8fc057bafaba770b76491394.tar.gz otp-2241b602a33d872a8fc057bafaba770b76491394.tar.bz2 otp-2241b602a33d872a8fc057bafaba770b76491394.zip |
Merge branch 'raimo/snmp/parse-mc_new_type-first-master/ERIERL-161/OTP-14196'
* raimo/snmp/parse-mc_new_type-first-master/ERIERL-161/OTP-14196:
Add test case
Parse #mc_new_type{}s before definitions_loop/2
Diffstat (limited to 'lib')
-rw-r--r-- | lib/snmp/src/compile/snmpc.erl | 66 | ||||
-rw-r--r-- | lib/snmp/test/snmp_compiler_test.erl | 23 | ||||
-rw-r--r-- | lib/snmp/test/snmp_test_data/OTP14196-MIB.mib | 47 |
3 files changed, 105 insertions, 31 deletions
diff --git a/lib/snmp/src/compile/snmpc.erl b/lib/snmp/src/compile/snmpc.erl index 4416626a4c..7f627d66d9 100644 --- a/lib/snmp/src/compile/snmpc.erl +++ b/lib/snmp/src/compile/snmpc.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2017. All Rights Reserved. +%% Copyright Ericsson AB 1997-2018. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -456,6 +456,7 @@ compile_parsed_data(#pdata{mib_name = MibName, RelChk = get_relaxed_row_name_assign_check(Opts), Data = #dldata{deprecated = Deprecated, relaxed_row_name_assign_check = RelChk}, + mc_new_type_loop(Definitions), put(augmentations, false), definitions_loop(Definitions, Data), MibName. @@ -481,7 +482,40 @@ do_update_imports([{{Mib, ImportsFromMib0},_Line}|Imports], Acc) -> update_status(Name, Status) -> #cdata{status_ets = Ets} = get(cdata), ets:insert(Ets, {Name, Status}). - + + +mc_new_type_loop( + [{#mc_new_type{ + name = NewTypeName, + macro = Macro, + syntax = OldType, + display_hint = DisplayHint},Line}|T]) -> + ?vlog2("typeloop -> new_type:" + "~n Macro: ~p" + "~n NewTypeName: ~p" + "~n OldType: ~p" + "~n DisplayHint: ~p", + [Macro, NewTypeName, OldType, DisplayHint], Line), + ensure_macro_imported(Macro,Line), + Types = (get(cdata))#cdata.asn1_types, + case lists:keysearch(NewTypeName, #asn1_type.aliasname, Types) of + {value,_} -> + snmpc_lib:print_error("Type ~w already defined.", + [NewTypeName],Line); + false -> + %% NameOfOldType = element(2,OldType), + ASN1 = snmpc_lib:make_ASN1type(OldType), + snmpc_lib:add_cdata(#cdata.asn1_types, + [ASN1#asn1_type{aliasname = NewTypeName, + imported = false, + display_hint = DisplayHint}]) + end, + mc_new_type_loop(T); +mc_new_type_loop([_|T]) -> + mc_new_type_loop(T); +mc_new_type_loop([]) -> + ok. + %% A deprecated object definitions_loop([{#mc_object_type{name = ObjName, status = deprecated}, @@ -745,32 +779,8 @@ definitions_loop([{#mc_object_type{name = NameOfTable, ColMEs]), definitions_loop(RestObjs, Data); -definitions_loop([{#mc_new_type{name = NewTypeName, - macro = Macro, - syntax = OldType, - display_hint = DisplayHint},Line}|T], - Data) -> - ?vlog2("defloop -> new_type:" - "~n Macro: ~p" - "~n NewTypeName: ~p" - "~n OldType: ~p" - "~n DisplayHint: ~p", - [Macro, NewTypeName, OldType, DisplayHint], Line), - ensure_macro_imported(Macro,Line), - Types = (get(cdata))#cdata.asn1_types, - case lists:keysearch(NewTypeName, #asn1_type.aliasname, Types) of - {value,_} -> - snmpc_lib:print_error("Type ~w already defined.", - [NewTypeName],Line); - false -> - %% NameOfOldType = element(2,OldType), - ASN1 = snmpc_lib:make_ASN1type(OldType), - snmpc_lib:add_cdata(#cdata.asn1_types, - [ASN1#asn1_type{aliasname = NewTypeName, - imported = false, - display_hint = DisplayHint}]) - end, - definitions_loop(T, Data); +definitions_loop([{#mc_new_type{},_}|T], Data) -> + definitions_loop(T, Data); %% Plain variable definitions_loop([{#mc_object_type{name = NewVarName, diff --git a/lib/snmp/test/snmp_compiler_test.erl b/lib/snmp/test/snmp_compiler_test.erl index 2b6bba4ee6..0a7b729d1f 100644 --- a/lib/snmp/test/snmp_compiler_test.erl +++ b/lib/snmp/test/snmp_compiler_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2017. All Rights Reserved. +%% Copyright Ericsson AB 2003-2018. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -58,7 +58,8 @@ otp_10799/1, otp_10808/1, otp_14145/1, - otp_13014/1 + otp_13014/1, + otp_14196/1 ]). %%---------------------------------------------------------------------- @@ -138,7 +139,7 @@ all() -> groups() -> [{tickets, [], [otp_6150, otp_8574, otp_8595, otp_10799, otp_10808, otp_14145, - otp_13014]}]. + otp_13014, otp_14196]}]. init_per_group(_GroupName, Config) -> Config. @@ -489,6 +490,22 @@ otp_13014(Config) when is_list(Config) -> TableInfo, ok. +%%====================================================================== + +otp_14196(suite) -> + []; +otp_14196(Config) when is_list(Config) -> + put(tname, otp14196), + p("starting with Config: ~p~n", [Config]), + + Dir = ?config(case_top_dir, Config), + MibDir = ?config(mib_dir, Config), + MibFile = join(MibDir, "OTP14196-MIB.mib"), + ?line {ok, Mib} = + snmpc:compile(MibFile, [{outdir, Dir}, {verbosity, trace}]), + p("Mib: ~n~p~n", [Mib]), + ok. + %%====================================================================== diff --git a/lib/snmp/test/snmp_test_data/OTP14196-MIB.mib b/lib/snmp/test/snmp_test_data/OTP14196-MIB.mib new file mode 100644 index 0000000000..0b3c718a02 --- /dev/null +++ b/lib/snmp/test/snmp_test_data/OTP14196-MIB.mib @@ -0,0 +1,47 @@ +OTP14196-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, OBJECT-TYPE, snmpModules, mib-2 + FROM SNMPv2-SMI + TEXTUAL-CONVENTION + FROM SNMPv2-TC + OBJECT-GROUP + FROM SNMPv2-CONF + ; + +otp14196MIB MODULE-IDENTITY + LAST-UPDATED "1004210000Z" + ORGANIZATION "" + CONTACT-INFO + "" + DESCRIPTION + "Test mib for OTP-14196" + ::= { snmpModules 1 } + +testCompliances OBJECT IDENTIFIER ::= { otp14196MIB 1 } +test OBJECT IDENTIFIER ::= { mib-2 15 } + +typeA OBJECT-TYPE + SYNTAX TypeAType + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "Test type for OTP-14196" + ::= { test 4711 } + +TypeAType ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "" + SYNTAX INTEGER + +testGroups OBJECT IDENTIFIER ::= { testCompliances 1 } + +testGroupA OBJECT-GROUP + OBJECTS { typeA } + STATUS current + DESCRIPTION + "" + ::= { testGroups 17 } + +END |