diff options
Diffstat (limited to 'lib/snmp')
-rw-r--r-- | lib/snmp/doc/src/files.mk | 3 | ||||
-rw-r--r-- | lib/snmp/doc/src/snmpc_cmd.xml | 191 | ||||
-rw-r--r-- | lib/snmp/test/snmp_app_test.erl | 44 | ||||
-rw-r--r-- | lib/snmp/test/snmp_manager_config_test.erl | 105 |
4 files changed, 300 insertions, 43 deletions
diff --git a/lib/snmp/doc/src/files.mk b/lib/snmp/doc/src/files.mk index f8462098be..c906ba0cf2 100644 --- a/lib/snmp/doc/src/files.mk +++ b/lib/snmp/doc/src/files.mk @@ -65,6 +65,9 @@ XML_MANAGER_REF3_FILES = \ snmpm_network_interface_filter.xml \ snmpm_user.xml +XML_REF1_FILES = \ + $(XML_COMP_REF1_FILES) + XML_REF3_FILES = \ $(XML_APP_REF3_FILES) \ $(XML_COMP_REF3_FILES) \ diff --git a/lib/snmp/doc/src/snmpc_cmd.xml b/lib/snmp/doc/src/snmpc_cmd.xml new file mode 100644 index 0000000000..9358382a10 --- /dev/null +++ b/lib/snmp/doc/src/snmpc_cmd.xml @@ -0,0 +1,191 @@ +<?xml version="1.0" encoding="iso-8859-1" ?> +<!DOCTYPE comref SYSTEM "comref.dtd"> + +<comref> + <header> + <copyright> + <year>2011</year><year>2011</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + </legalnotice> + + <title>snmpc</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev></rev> + <file>snmpc_cmd.xml</file> + </header> + <com>snmpc(command)</com> + <comsummary>SNMP MIB compiler frontend</comsummary> + <description> + <p>The <c><![CDATA[snmpc]]></c> program provides a way to run + the SNMP MIB compiler of the Erlang system. </p> + </description> + + <funcs> + <func> + <name>snmpc [options] file.mib | file.bin</name> + <fsummary>Compile MIBs</fsummary> + <desc> + <p><c><![CDATA[snmpc]]></c> compile a SNMP MIB file, + see <seealso marker="snmpc#compile">compile/1,2</seealso> for + more info. </p> + <p>It can also be used to generate a header file (.hrl) + with definitions of Erlang constants for the objects in + the MIB, see + <seealso marker="snmpc#mib_to_hrl">mib_to_hrl/1</seealso>. </p> + </desc> + </func> + </funcs> + + <section> + <title>Compiler options</title> + <p>The following options are supported (note that most of these relate + to the compilation of the MIB file):</p> + <taglist> + <tag>--help</tag> + <item> + <p>Prints help info.</p> + </item> + + <tag>--version</tag> + <item> + <p>Prints application and mib format version.</p> + </item> + + <tag>--verbosity <em>verbosity</em></tag> + <item> + <p>Print debug info. </p> + <p><c>verbosity</c> = <c>trace</c> | <c>debug</c> | <c>log</c> | <c>info</c> | <c>silence</c></p> + <p>Defaults to <c>silence</c>.</p> + </item> + + <tag>--warnings</tag> + <item> + <p>Print warning messages. </p> + </item> + + <tag>--o <em>directory</em></tag> + <item> + <p>The directory where the compiler should place the output files. + If not specified, output files will be placed in the current working + directory.</p> + </item> + + <tag>--i <em>Directory</em></tag> + <item> + <p>Specifies the path to search for imported (compiled) MIB files. + By default, the current working directory is always included. </p> + <p>This option can be present several times, each time specifying + <em>one</em> path. </p> + </item> + + <tag>--il <em>Directory</em></tag> + <item> + <p>This option (include_lib), specifies a list of directories to + search for imported MIBs. It assumes that the first element in + the directory name corresponds to an OTP application. The compiler + will find the current installed version. For example, the value + ["snmp/mibs/"] will be replaced by ["snmp-3.1.1/mibs/"] (or what + the current version may be in the system). The current directory + and the "snmp-home"/priv/mibs/ are always listed last in the + include path. </p> + </item> + + <tag>--sgc</tag> + <item> + <p>This option (skip group check), if present, disables the + group check of the mib compiler. + That is, should the OBJECT-GROUP and the NOTIFICATION-GROUP + macro(s) be checked for correctness or not. </p> + </item> + + <tag>--dep</tag> + <item> + <p>Keep deprecated definition(s). + If not specified the compiler will ignore deprecated definitions. </p> + </item> + + <tag>--desc</tag> + <item> + <p>The DESCRIPTION field will be included. </p> + </item> + + <tag>--ref</tag> + <item> + <p>The REFERENCE field will be included. </p> + </item> + + <tag>--imp</tag> + <item> + <p>The IMPORTS field will be included. </p> + </item> + + <tag>--mi</tag> + <item> + <p>The MODULE-IDENTITY field will be included. </p> + </item> + + <tag>--mc</tag> + <item> + <p>The MODULE-COMPLIANCE field will be included. </p> + </item> + + <tag>--ac</tag> + <item> + <p>The AGENT-CAPABILITIES field will be included. </p> + </item> + + <tag>--mod <em>module</em></tag> + <item> + <p>The module which implements all the instrumentation functions. </p> + <p>The name of all instrumentation functions must be the + same as the corresponding managed object it implements. </p> + </item> + + <tag>--nd</tag> + <item> + <p>The default instrumentation functions will <em>not</em> be + used if a managed object have no instrumentation function. + Instead this will be reported as an error, and the compilation + aborts. </p> + </item> + + <tag>--rrnac</tag> + <item> + <p>This option, if present, specifies that the row name assign check + shall not be done strictly according to the SMI (which allows only + the value 1). </p> + <p>With this option, all values greater than zero is allowed (>= 1). + This means that the error will be converted to a warning. </p> + <p>By default it is not included, but if this option is present + it will be. </p> + </item> + + </taglist> + </section> + + <section> + <title>SEE ALSO</title> + <p><seealso marker="erlc">erlc(1)</seealso>, + <seealso marker="compiler:compile">compile(3)</seealso>, + <seealso marker="snmp:snmpc">snmpc(3)</seealso></p> + </section> +</comref> + diff --git a/lib/snmp/test/snmp_app_test.erl b/lib/snmp/test/snmp_app_test.erl index 64dd638f83..27a7b4af2e 100644 --- a/lib/snmp/test/snmp_app_test.erl +++ b/lib/snmp/test/snmp_app_test.erl @@ -300,6 +300,25 @@ undef_funcs(Config) when is_list(Config) -> xref:stop(XRef), analyze_undefined_function_calls(Undefs, Mods, []). +valid_undef(crypto = CalledMod) -> + case (catch CalledMod:version()) of + Version when is_list(Version) -> + %% The called module was crypto and the version + %% function returns a valid value. + %% This means that the function is + %% actually undefined... + true; + _ -> + %% The called module was crypto but the version + %% function does *not* return a valid value. + %% This means the crypto was not actually not + %% build, which is an case snmp handles. + false + end; +valid_undef(_) -> + true. + + analyze_undefined_function_calls([], _, []) -> ok; analyze_undefined_function_calls([], _, AppUndefs) -> @@ -312,14 +331,25 @@ analyze_undefined_function_calls([{{Mod, _F, _A}, _C} = AppUndef|Undefs], {Calling,Called} = AppUndef, {Mod1,Func1,Ar1} = Calling, {Mod2,Func2,Ar2} = Called, - io:format("undefined function call: " - "~n ~w:~w/~w calls ~w:~w/~w~n", - [Mod1,Func1,Ar1,Mod2,Func2,Ar2]), - analyze_undefined_function_calls(Undefs, AppModules, - [AppUndef|AppUndefs]); + %% If the called module is crypto, then we will *not* + %% fail if crypto is not built (since crypto is actually + %% not built for all platforms) + case valid_undef(Mod2) of + true -> + io:format("undefined function call: " + "~n ~w:~w/~w calls ~w:~w/~w~n", + [Mod1,Func1,Ar1,Mod2,Func2,Ar2]), + analyze_undefined_function_calls( + Undefs, AppModules, [AppUndef|AppUndefs]); + false -> + io:format("skipping ~p (calling ~w:~w/~w)~n", + [Mod, Mod2, Func2, Ar2]), + analyze_undefined_function_calls(Undefs, + AppModules, AppUndefs) + end; false -> - io:format("dropping ~p~n", [Mod]), - analyze_undefined_function_calls(Undefs, AppModules, AppUndefs) + io:format("dropping ~p~n", [Mod]), + analyze_undefined_function_calls(Undefs, AppModules, AppUndefs) end. %% This function is used simply to avoid cut-and-paste errors later... diff --git a/lib/snmp/test/snmp_manager_config_test.erl b/lib/snmp/test/snmp_manager_config_test.erl index a72dd0cc22..e38a99d413 100644 --- a/lib/snmp/test/snmp_manager_config_test.erl +++ b/lib/snmp/test/snmp_manager_config_test.erl @@ -169,36 +169,41 @@ all() -> groups() -> [{start_and_stop, [], - [simple_start_and_stop, start_without_mandatory_opts1, - start_without_mandatory_opts2, - start_with_all_valid_opts, start_with_unknown_opts, - start_with_incorrect_opts, - start_with_invalid_manager_conf_file1, - start_with_invalid_users_conf_file1, - start_with_invalid_agents_conf_file1, - start_with_invalid_usm_conf_file1]}, - {normal_op, [], - [{group, system}, {group, agents}, {group, users}, - {group, usm_users}, {group, counter}, - {group, stats_counter}]}, - {system, [], [simple_system_op]}, - {users, [], - [register_user_using_file, register_user_using_function, - register_user_failed_using_function1]}, - {agents, [], - [register_agent_using_file, - register_agent_using_function, - register_agent_failed_using_function1]}, - {usm_users, [], - [register_usm_user_using_file, - register_usm_user_using_function, - register_usm_user_failed_using_function1, - update_usm_user_info]}, - {counter, [], [create_and_increment]}, - {stats_counter, [], [stats_create_and_increment]}, - {tickets, [], [otp_7219, {group, otp_8395}]}, - {otp_8395, [], - [otp_8395_1, otp_8395_2, otp_8395_3, otp_8395_4]}]. + [simple_start_and_stop, + start_without_mandatory_opts1, + start_without_mandatory_opts2, + start_with_all_valid_opts, start_with_unknown_opts, + start_with_incorrect_opts, + start_with_invalid_manager_conf_file1, + start_with_invalid_users_conf_file1, + start_with_invalid_agents_conf_file1, + start_with_invalid_usm_conf_file1]}, + {normal_op, [], + [{group, system}, + {group, agents}, + {group, users}, + {group, usm_users}, + {group, counter}, + {group, stats_counter}]}, + {system, [], [simple_system_op]}, + {users, [], + [register_user_using_file, + register_user_using_function, + register_user_failed_using_function1]}, + {agents, [], + [register_agent_using_file, + register_agent_using_function, + register_agent_failed_using_function1]}, + {usm_users, [], + [register_usm_user_using_file, + register_usm_user_using_function, + register_usm_user_failed_using_function1, + update_usm_user_info]}, + {counter, [], [create_and_increment]}, + {stats_counter, [], [stats_create_and_increment]}, + {tickets, [], [otp_7219, {group, otp_8395}]}, + {otp_8395, [], + [otp_8395_1, otp_8395_2, otp_8395_3, otp_8395_4]}]. init_per_group(_GroupName, Config) -> Config. @@ -816,7 +821,10 @@ start_with_invalid_users_conf_file1(Conf) when is_list(Conf) -> p("start"), process_flag(trap_exit, true), ConfDir = ?config(manager_conf_dir, Conf), - DbDir = ?config(manager_db_dir, Conf), + DbDir = ?config(manager_db_dir, Conf), + + verify_dir_existing(conf, ConfDir), + verify_dir_existing(db, DbDir), Opts = [{versions, [v1]}, {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], @@ -917,7 +925,10 @@ start_with_invalid_agents_conf_file1(Conf) when is_list(Conf) -> p("start"), process_flag(trap_exit, true), ConfDir = ?config(manager_conf_dir, Conf), - DbDir = ?config(manager_db_dir, Conf), + DbDir = ?config(manager_db_dir, Conf), + + verify_dir_existing(conf, ConfDir), + verify_dir_existing(db, DbDir), Opts = [{versions, [v1]}, {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], @@ -2022,7 +2033,6 @@ register_usm_user_using_file(Conf) when is_list(Conf) -> %% -- p("done"), ok. -%% ?SKIP(not_yet_implemented). %% @@ -2651,9 +2661,21 @@ write_usm_conf2(Dir, Str) -> write_conf_file(Dir, File, Str) -> - ?line {ok, Fd} = file:open(filename:join(Dir, File), write), - ?line ok = io:format(Fd, "~s", [Str]), - file:close(Fd). + case file:open(filename:join(Dir, File), write) of + {ok, Fd} -> + ?line ok = io:format(Fd, "~s", [Str]), + file:close(Fd); + {error, Reason} -> + Info = + [{dir, Dir, case (catch file:read_file_info(Dir)) of + {ok, FI} -> + FI; + _ -> + undefined + end}, + {file, File}], + exit({failed_writing_conf_file, Info, Reason}) + end. maybe_start_crypto() -> @@ -2679,6 +2701,17 @@ maybe_stop_crypto() -> %% ------ +verify_dir_existing(DirName, Dir) -> + case file:read_file_info(Dir) of + {ok, _} -> + ok; + {error, Reason} -> + exit({non_existing_dir, DirName, Dir, Reason}) + end. + + +%% ------ + str(X) -> lists:flatten(io_lib:format("~w", [X])). |