diff options
Diffstat (limited to 'lib/common_test')
| -rw-r--r-- | lib/common_test/doc/src/notes.xml | 16 | ||||
| -rw-r--r-- | lib/common_test/src/ct.erl | 6 | ||||
| -rw-r--r-- | lib/common_test/src/ct_framework.erl | 6 | ||||
| -rw-r--r-- | lib/common_test/src/ct_run.erl | 43 | ||||
| -rw-r--r-- | lib/common_test/src/ct_snmp.erl | 65 | ||||
| -rw-r--r-- | lib/common_test/test/Makefile | 5 | ||||
| -rw-r--r-- | lib/common_test/test/ct_shell_SUITE.erl | 133 | ||||
| -rw-r--r-- | lib/common_test/test/ct_shell_SUITE_data/cfgdata | 2 | ||||
| -rw-r--r-- | lib/common_test/test/ct_snmp_SUITE.erl | 141 | ||||
| -rw-r--r-- | lib/common_test/test/ct_snmp_SUITE_data/snmp.cfg | 20 | ||||
| -rw-r--r-- | lib/common_test/test/ct_snmp_SUITE_data/snmp1_SUITE.erl | 152 | ||||
| -rw-r--r-- | lib/common_test/test/ct_system_error_SUITE.erl | 132 | ||||
| -rw-r--r-- | lib/common_test/test/ct_system_error_SUITE_data/a_SUITE.erl | 122 | ||||
| -rw-r--r-- | lib/common_test/vsn.mk | 2 | 
14 files changed, 800 insertions, 45 deletions
diff --git a/lib/common_test/doc/src/notes.xml b/lib/common_test/doc/src/notes.xml index 64eeb4af92..abe8cb2041 100644 --- a/lib/common_test/doc/src/notes.xml +++ b/lib/common_test/doc/src/notes.xml @@ -32,6 +32,22 @@      <file>notes.xml</file>      </header> +<section><title>Common_Test 1.6.2.1</title> + +    <section><title>Fixed Bugs and Malfunctions</title> +      <list> +        <item> +          <p> +	    The interactive mode (ct_run -shell) would not start +	    properly. This error has been fixed.</p> +          <p> +	    Own Id: OTP-10414</p> +        </item> +      </list> +    </section> + +</section> +  <section><title>Common_Test 1.6.2</title>      <section><title>Fixed Bugs and Malfunctions</title> diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl index 49b51c9207..5014309c0f 100644 --- a/lib/common_test/src/ct.erl +++ b/lib/common_test/src/ct.erl @@ -274,7 +274,8 @@ step(TestDir,Suite,Case,Opts) ->  %%% <c>> ct_telnet:cmd(unix_telnet, "ls .").</c><br/>  %%% <c>{ok,["ls","file1  ...",...]}</c></p>  start_interactive() -> -    ct_util:start(interactive). +    ct_util:start(interactive), +    ok.  %%%-----------------------------------------------------------------  %%% @spec stop_interactive() -> ok @@ -282,7 +283,8 @@ start_interactive() ->  %%% @doc Exit the interactive mode.  %%% @see start_interactive/0  stop_interactive() -> -    ct_util:stop(normal). +    ct_util:stop(normal), +    ok.  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%% MISC INTERFACE diff --git a/lib/common_test/src/ct_framework.erl b/lib/common_test/src/ct_framework.erl index 4d47731239..bec3368869 100644 --- a/lib/common_test/src/ct_framework.erl +++ b/lib/common_test/src/ct_framework.erl @@ -1529,6 +1529,12 @@ report(What,Data) ->  	    end;  	tests_done ->  	    ok; +	severe_error -> +	    ct_event:sync_notify(#event{name=What, +					node=node(), +					data=Data}), +	    ct_util:set_testdata({What,Data}), +	    ok;  	tc_start ->  	    %% Data = {{Suite,Func},LogFileName}  	    ct_event:sync_notify(#event{name=tc_logfile, diff --git a/lib/common_test/src/ct_run.erl b/lib/common_test/src/ct_run.erl index d80d216f9e..4a6a3cdcac 100644 --- a/lib/common_test/src/ct_run.erl +++ b/lib/common_test/src/ct_run.erl @@ -211,6 +211,8 @@ analyze_test_result([Result|Rs], Args) ->      end;  analyze_test_result([], _) ->      ?EXIT_STATUS_TEST_SUCCESSFUL; +analyze_test_result(interactive_mode, _) -> +    interactive_mode;  analyze_test_result(Unknown, _) ->      io:format("\nTest run failed! Reason:\n~p\n\n\n",[Unknown]),      ?EXIT_STATUS_TEST_RUN_FAILED. @@ -218,17 +220,22 @@ analyze_test_result(Unknown, _) ->  finish(Tracing, ExitStatus, Args) ->      stop_trace(Tracing),      timer:sleep(1000), -    %% it's possible to tell CT to finish execution with a call -    %% to a different function than the normal halt/1 BIF -    %% (meant to be used mainly for reading the CT exit status) -    case get_start_opt(halt_with, -		       fun([HaltMod,HaltFunc]) -> {list_to_atom(HaltMod), -						   list_to_atom(HaltFunc)} end, -		       Args) of -	undefined -> -	    halt(ExitStatus); -	{M,F} -> -	    apply(M, F, [ExitStatus]) +    if ExitStatus == interactive_mode -> +	    interactive_mode; +       true -> +	    %% it's possible to tell CT to finish execution with a call +	    %% to a different function than the normal halt/1 BIF +	    %% (meant to be used mainly for reading the CT exit status) +	    case get_start_opt(halt_with, +			       fun([HaltMod,HaltFunc]) ->  +				       {list_to_atom(HaltMod), +					list_to_atom(HaltFunc)} end, +			       Args) of +		undefined -> +		    halt(ExitStatus); +		{M,F} -> +		    apply(M, F, [ExitStatus]) +	    end      end.  script_start1(Parent, Args) -> @@ -635,6 +642,7 @@ script_start4(#opts{label = Label, profile = Profile,  		    verbosity = Verbosity,  		    enable_builtin_hooks = EnableBuiltinHooks,  		    logdir = LogDir, testspecs = Specs}, _Args) -> +      %% label - used by ct_logs      application:set_env(common_test, test_label, Label), @@ -655,7 +663,7 @@ script_start4(#opts{label = Label, profile = Profile,  	    ct_util:set_testdata({logopts, LogOpts}),  	    log_ts_names(Specs),  	    io:nl(), -	    ok; +	    interactive_mode;  	Error ->  	    Error      end; @@ -2184,6 +2192,15 @@ do_run_test(Tests, Skip, Opts) ->  			  end, CleanUp),  	    [code:del_path(Dir) || Dir <- AddedToPath], +	    %% If a severe error has occurred in the test_server, +	    %% we will generate an exception here. +	    case ct_util:get_testdata(severe_error) of +		undefined -> ok; +		SevereError -> +		    ct_logs:log("SEVERE ERROR", "~p\n", [SevereError]), +		    exit(SevereError) +	    end, +  	    case ct_util:get_testdata(stats) of  		Stats = {_Ok,_Failed,{_UserSkipped,_AutoSkipped}} ->  		    Stats; @@ -2776,6 +2793,8 @@ opts2args(EnvStartOpts) ->  			  [{exit_status,[atom_to_list(ExitStatusOpt)]}];  		     ({halt_with,{HaltM,HaltF}}) ->  			  [{halt_with,[atom_to_list(HaltM),atom_to_list(HaltF)]}]; +		     ({interactive_mode,true}) -> +			  [{shell,[]}];  		     ({config,CfgFiles}) ->  			  [{ct_config,[CfgFiles]}];  		     ({userconfig,{CBM,CfgStr=[X|_]}}) when is_integer(X) -> diff --git a/lib/common_test/src/ct_snmp.erl b/lib/common_test/src/ct_snmp.erl index 8fe63e8ed1..02f849201d 100644 --- a/lib/common_test/src/ct_snmp.erl +++ b/lib/common_test/src/ct_snmp.erl @@ -1,7 +1,7 @@  %%  %% %CopyrightBegin%  %% -%% Copyright Ericsson AB 2004-2010. All Rights Reserved. +%% Copyright Ericsson AB 2004-2012. All Rights Reserved.  %%  %% 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 @@ -250,10 +250,8 @@ stop(Config) ->  %%%  %%% @doc Issues a synchronous snmp get request.   get_values(Agent, Oids, MgrAgentConfName) -> -    [Uid, AgentIp, AgentUdpPort | _] =  -	agent_conf(Agent, MgrAgentConfName), -    {ok, SnmpReply, _} = -	snmpm:g(Uid, AgentIp, AgentUdpPort, Oids), +    [Uid | _] = agent_conf(Agent, MgrAgentConfName), +    {ok, SnmpReply, _} = snmpm:sync_get2(Uid, target_name(Agent), Oids),      SnmpReply.  %%% @spec get_next_values(Agent, Oids, MgrAgentConfName) -> SnmpReply  @@ -265,10 +263,8 @@ get_values(Agent, Oids, MgrAgentConfName) ->  %%%  %%% @doc Issues a synchronous snmp get next request.   get_next_values(Agent, Oids, MgrAgentConfName) -> -    [Uid, AgentIp, AgentUdpPort | _] =  -	agent_conf(Agent, MgrAgentConfName), -    {ok, SnmpReply, _} = -	snmpm:gn(Uid, AgentIp, AgentUdpPort, Oids), +    [Uid | _] = agent_conf(Agent, MgrAgentConfName), +    {ok, SnmpReply, _} = snmpm:sync_get_next2(Uid, target_name(Agent), Oids),      SnmpReply.  %%% @spec set_values(Agent, VarsAndVals, MgrAgentConfName, Config) -> SnmpReply @@ -282,13 +278,11 @@ get_next_values(Agent, Oids, MgrAgentConfName) ->  %%% @doc Issues a synchronous snmp set request.   set_values(Agent, VarsAndVals, MgrAgentConfName, Config) ->      PrivDir = ?config(priv_dir, Config), -    [Uid, AgentIp, AgentUdpPort | _] =  -	agent_conf(Agent, MgrAgentConfName), +    [Uid | _] = agent_conf(Agent, MgrAgentConfName),      Oids = lists:map(fun({Oid, _, _}) -> Oid end, VarsAndVals), -    {ok, SnmpGetReply, _} = -	snmpm:g(Uid, AgentIp, AgentUdpPort, Oids), -    {ok, SnmpSetReply, _} = -	snmpm:s(Uid, AgentIp, AgentUdpPort, VarsAndVals), +    TargetName = target_name(Agent), +    {ok, SnmpGetReply, _} = snmpm:sync_get2(Uid, TargetName, Oids), +    {ok, SnmpSetReply, _} = snmpm:sync_set2(Uid, TargetName, VarsAndVals),      case SnmpSetReply of  	{noError, 0, _} when PrivDir /= false ->  	    log(PrivDir, Agent, SnmpGetReply, VarsAndVals); @@ -348,7 +342,7 @@ register_agents(MgrAgentConfName, ManagedAgents) ->      NewSnmpVals = lists:keyreplace(managed_agents, 1, SnmpVals,  				   {managed_agents, ManagedAgents}),      ct_config:update_config(MgrAgentConfName, {snmp, NewSnmpVals}), -    setup_managed_agents(ManagedAgents). +    setup_managed_agents(MgrAgentConfName,ManagedAgents).  %%% @spec register_usm_users(MgrAgentConfName, UsmUsers) ->  ok | {error, Reason}  %%% @@ -486,9 +480,8 @@ setup_agent(true, AgentConfName, SnmpConfName,      file:make_dir(DbDir),          snmp_config:write_agent_snmp_files(ConfDir, Vsns, ManagerIP, TrapUdp,   				       AgentIP, AgentUdp, SysName,  -				       atom_to_list(NotifType),  -				       SecType, Passwd, AgentEngineID,  -				       AgentMaxMsgSize), +				       NotifType, SecType, Passwd, +				       AgentEngineID, AgentMaxMsgSize),      override_default_configuration(Config, AgentConfName), @@ -497,7 +490,8 @@ setup_agent(true, AgentConfName, SnmpConfName,  					 {verbosity, trace}]},  			       {agent_type, master},  			       {agent_verbosity, trace}, -			       {net_if, [{verbosity, trace}]}], +			       {net_if, [{verbosity, trace}]}, +			       {versions, Vsns}],  			      ct:get_config({SnmpConfName,agent})),      application:set_env(snmp, agent, SnmpEnv).  %%%--------------------------------------------------------------------------- @@ -535,7 +529,7 @@ manager_register(true, MgrAgentConfName) ->      setup_usm_users(UsmUsers, EngineID),      setup_users(Users), -    setup_managed_agents(Agents). +    setup_managed_agents(MgrAgentConfName,Agents).  %%%---------------------------------------------------------------------------  setup_users(Users) -> @@ -543,10 +537,11 @@ setup_users(Users) ->  			  snmpm:register_user(Id, Module, Data)  		  end, Users).  %%%---------------------------------------------------------------------------    -setup_managed_agents([]) -> +setup_managed_agents(_,[]) ->      ok; -setup_managed_agents([{_, [Uid, AgentIp, AgentUdpPort, AgentConf]} | +setup_managed_agents(AgentConfName, +		     [{AgentName, [Uid, AgentIp, AgentUdpPort, AgentConf0]} |  		      Rest]) ->      NewAgentIp = case AgentIp of  		     IpTuple when is_tuple(IpTuple) -> @@ -556,12 +551,19 @@ setup_managed_agents([{_, [Uid, AgentIp, AgentUdpPort, AgentConf]} |  			 [IpTuple|_] = Hostent#hostent.h_addr_list,  			 IpTuple  		 end, -    ok = snmpm:register_agent(Uid, NewAgentIp, AgentUdpPort),    -    lists:foreach(fun({Item, Val}) -> -			  snmpm:update_agent_info(Uid, NewAgentIp,  -						  AgentUdpPort, Item, Val) -		  end, AgentConf), -    setup_managed_agents(Rest). +    AgentConf = +	case lists:keymember(engine_id,1,AgentConf0) of +	    true -> +		AgentConf0; +	    false -> +		DefaultEngineID = ct:get_config({AgentConfName,agent_engine_id}, +						?AGENT_ENGINE_ID), +		[{engine_id,DefaultEngineID}|AgentConf0] +	end, +    ok = snmpm:register_agent(Uid, target_name(AgentName), +			      [{address,NewAgentIp},{port,AgentUdpPort} | +			       AgentConf]), +    setup_managed_agents(AgentConfName,Rest).  %%%---------------------------------------------------------------------------  setup_usm_users(UsmUsers, EngineID)->      lists:foreach(fun({UsmUser, Conf}) -> @@ -769,3 +771,8 @@ override_vacm(Config, VacmConf) ->         File = filename:join(Dir,"vacm.conf"),      file:delete(File),      snmp_config:write_agent_vacm_config(Dir, "", VacmConf). + +%%%--------------------------------------------------------------------------- + +target_name(Agent) -> +    atom_to_list(Agent). diff --git a/lib/common_test/test/Makefile b/lib/common_test/test/Makefile index 7628ada61a..7691920993 100644 --- a/lib/common_test/test/Makefile +++ b/lib/common_test/test/Makefile @@ -50,7 +50,10 @@ MODULES= \  	ct_netconfc_SUITE \  	ct_basic_html_SUITE \  	ct_auto_compile_SUITE \ -	ct_verbosity_SUITE +	ct_verbosity_SUITE \ +	ct_shell_SUITE \ +	ct_system_error_SUITE \ +	ct_snmp_SUITE  ERL_FILES= $(MODULES:%=%.erl) diff --git a/lib/common_test/test/ct_shell_SUITE.erl b/lib/common_test/test/ct_shell_SUITE.erl new file mode 100644 index 0000000000..4b8c43d800 --- /dev/null +++ b/lib/common_test/test/ct_shell_SUITE.erl @@ -0,0 +1,133 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2010-2012. All Rights Reserved. +%% +%% 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. +%% +%% %CopyrightEnd% +%% + +%%%------------------------------------------------------------------- +%%% File: ct_shell_SUITE +%%% +%%% Description: +%%% Test that the interactive mode starts properly +%%% +%%% The suites used for the test are located in the data directory. +%%%------------------------------------------------------------------- +-module(ct_shell_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("common_test/include/ct_event.hrl"). + +-define(eh, ct_test_support_eh). + +%%-------------------------------------------------------------------- +%% TEST SERVER CALLBACK FUNCTIONS +%%-------------------------------------------------------------------- + +init_per_suite(Config) -> +    Config1 = ct_test_support:init_per_suite(Config), +    Config1. + +end_per_suite(Config) -> +    ct_test_support:end_per_suite(Config). + +init_per_testcase(TestCase, Config) -> +    ct_test_support:init_per_testcase(TestCase, Config). + +end_per_testcase(TestCase, Config) -> +    ct_test_support:end_per_testcase(TestCase, Config). + +suite() -> [{ct_hooks,[ts_install_cth]}]. + +all() ->  +    [start_interactive]. + +%%-------------------------------------------------------------------- +%% TEST CASES +%%-------------------------------------------------------------------- + +%%%----------------------------------------------------------------- +%%% +start_interactive(Config) -> +    DataDir = ?config(data_dir, Config), +    CfgFile = filename:join(DataDir, "cfgdata"), + +    {Opts,ERPid} = setup([{interactive_mode,true},{config,CfgFile}], +			 Config), +    CTNode = proplists:get_value(ct_node, Config), +    Level = proplists:get_value(trace_level, Config), +    test_server:format(Level, "Saving start opts on ~p: ~p~n", +		       [CTNode, Opts]), +    rpc:call(CTNode, application, set_env, +	     [common_test, run_test_start_opts, Opts]), +    test_server:format(Level, "Calling ct_run:script_start() on ~p~n", +		       [CTNode]), + +    interactive_mode = rpc:call(CTNode, ct_run, script_start, []), + +    ok = rpc:call(CTNode, ct, require, [key1]), +    value1 = rpc:call(CTNode, ct, get_config, [key1]), +    ok = rpc:call(CTNode, ct, require, [x,key2]), +    value2 = rpc:call(CTNode, ct, get_config, [x]), + +    ok = rpc:call(CTNode, ct, stop_interactive, []), + +    case rpc:call(CTNode, erlang, whereis, [ct_util_server]) of +	undefined -> +	    ok; +	_ -> +	    test_server:format(Level, +			       "ct_util_server not stopped on ~p yet, waiting 5 s...~n", +			       [CTNode]), +	    timer:sleep(5000), +	    undefined = rpc:call(CTNode, erlang, whereis, [ct_util_server]) +    end, +    Events = ct_test_support:get_events(ERPid, Config), + +    ct_test_support:log_events(start_interactive, +			       reformat(Events, ?eh), +			       ?config(priv_dir, Config), +			       Opts), +    TestEvents = test_events(start_interactive), +    ok = ct_test_support:verify_events(TestEvents, Events, Config). + +%%%----------------------------------------------------------------- +%%% HELP FUNCTIONS +%%%----------------------------------------------------------------- + +setup(Test, Config) -> +    Opts0 = ct_test_support:get_opts(Config), +    Level = ?config(trace_level, Config), +    EvHArgs = [{cbm,ct_test_support},{trace_level,Level}], +    Opts = Opts0 ++ [{event_handler,{?eh,EvHArgs}}|Test], +    ERPid = ct_test_support:start_event_receiver(Config), +    {Opts,ERPid}. + +reformat(Events, EH) -> +    ct_test_support:reformat(Events, EH). + +%%%----------------------------------------------------------------- +%%% TEST EVENTS +%%%----------------------------------------------------------------- + +test_events(start_interactive) -> +    [ +     {?eh,start_logging,{'DEF','RUNDIR'}}, +     {?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}}, +     {?eh,test_done,{'DEF','STOP_TIME'}}, +     {?eh,stop_logging,[]} +    ]. diff --git a/lib/common_test/test/ct_shell_SUITE_data/cfgdata b/lib/common_test/test/ct_shell_SUITE_data/cfgdata new file mode 100644 index 0000000000..23a40ad21a --- /dev/null +++ b/lib/common_test/test/ct_shell_SUITE_data/cfgdata @@ -0,0 +1,2 @@ +{key1,value1}. +{key2,value2}. diff --git a/lib/common_test/test/ct_snmp_SUITE.erl b/lib/common_test/test/ct_snmp_SUITE.erl new file mode 100644 index 0000000000..848752b816 --- /dev/null +++ b/lib/common_test/test/ct_snmp_SUITE.erl @@ -0,0 +1,141 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2012. All Rights Reserved. +%% +%% 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. +%% +%% %CopyrightEnd% +%% + +%%%------------------------------------------------------------------- +%%% File: ct_snmp_SUITE +%%% +%%% Description: +%%% Test ct_snmp module +%%% +%%%------------------------------------------------------------------- +-module(ct_snmp_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("common_test/include/ct_event.hrl"). + +-define(eh, ct_test_support_eh). + +%%-------------------------------------------------------------------- +%% TEST SERVER CALLBACK FUNCTIONS +%%-------------------------------------------------------------------- + +%%-------------------------------------------------------------------- +%% Description: Since Common Test starts another Test Server +%% instance, the tests need to be performed on a separate node (or +%% there will be clashes with logging processes etc). +%%-------------------------------------------------------------------- +init_per_suite(Config) -> +    Config1 = ct_test_support:init_per_suite(Config), +    Config1. + +end_per_suite(Config) -> +    ct_test_support:end_per_suite(Config). + +init_per_testcase(TestCase, Config) -> +    ct_test_support:init_per_testcase(TestCase, Config). + +end_per_testcase(TestCase, Config) -> +    ct_test_support:end_per_testcase(TestCase, Config). + +suite() -> [{ct_hooks,[ts_install_cth]}]. + +all() -> +    [ +     default +    ]. + +%%-------------------------------------------------------------------- +%% TEST CASES +%%-------------------------------------------------------------------- + +%%%----------------------------------------------------------------- +%%% +default(Config) when is_list(Config) -> +    DataDir = ?config(data_dir, Config), +    Suite = filename:join(DataDir, "snmp1_SUITE"), +    CfgFile = filename:join(DataDir, "snmp.cfg"), +    {Opts,ERPid} = setup([{suite,Suite},{config,CfgFile}, +			  {label,default}], Config), + +    ok = execute(default, Opts, ERPid, Config). + + +%%%----------------------------------------------------------------- +%%% HELP FUNCTIONS +%%%----------------------------------------------------------------- + +setup(Test, Config) -> +    Opts0 = ct_test_support:get_opts(Config), +    Level = ?config(trace_level, Config), +    EvHArgs = [{cbm,ct_test_support},{trace_level,Level}], +    Opts = Opts0 ++ [{event_handler,{?eh,EvHArgs}}|Test], +    ERPid = ct_test_support:start_event_receiver(Config), +    {Opts,ERPid}. + +execute(Name, Opts, ERPid, Config) -> +    ok = ct_test_support:run(Opts, Config), +    Events = ct_test_support:get_events(ERPid, Config), + +    ct_test_support:log_events(Name, +			       reformat(Events, ?eh), +			       ?config(priv_dir, Config), +			       Opts), + +    TestEvents = events_to_check(Name,Config), +    ct_test_support:verify_events(TestEvents, Events, Config). + +reformat(Events, EH) -> +    ct_test_support:reformat(Events, EH). + +%%%----------------------------------------------------------------- +%%% TEST EVENTS +%%%----------------------------------------------------------------- +events_to_check(_TestName,Config) -> +    {module,_} = code:load_abs(filename:join(?config(data_dir,Config), +					     snmp1_SUITE)), +    TCs = get_tcs(), +    code:purge(snmp1_SUITE), +    code:delete(snmp1_SUITE), + +    OneTest = +	[{?eh,start_logging,{'DEF','RUNDIR'}}] ++ +	[{?eh,tc_done,{snmp1_SUITE,TC,ok}} || TC <- TCs] ++ +	[{?eh,stop_logging,[]}], + +    %% 2 tests (ct:run_test + script_start) is default +    OneTest ++ OneTest. + + +get_tcs() -> +    All = snmp1_SUITE:all(), +    Groups = +	try snmp1_SUITE:groups() +	catch error:undef -> [] +	end, +    flatten_tcs(All,Groups). + +flatten_tcs([H|T],Groups) when is_atom(H) -> +    [H|flatten_tcs(T,Groups)]; +flatten_tcs([{group,Group}|T],Groups) -> +    TCs = proplists:get_value(Group,Groups), +    flatten_tcs(TCs ++ T,Groups); +flatten_tcs([],_) -> +    []. diff --git a/lib/common_test/test/ct_snmp_SUITE_data/snmp.cfg b/lib/common_test/test/ct_snmp_SUITE_data/snmp.cfg new file mode 100644 index 0000000000..b0ac0e6a96 --- /dev/null +++ b/lib/common_test/test/ct_snmp_SUITE_data/snmp.cfg @@ -0,0 +1,20 @@ +%% -*- erlang -*- +{snmp, [{start_agent,true}, +	{users,[{user_name,[snmp1_SUITE,[]]}]}, +	{managed_agents,[{agent_name, [user_name, {127,0,0,1}, 4000, +				       [{engine_id,"ct_snmp-test-engine"}, +					{version,v2}]]}]}, +	{engine_id,"ct_snmp-test-engine"}, +	{agent_vsns,[v2]} +       ]}. +{snmp_app,[{manager, [{config, [{verbosity, silence}]}, +		      {server,[{verbosity,silence}]}, +		      {net_if,[{verbosity,silence}]}, +		      {versions,[v2]} +		     ]}, +	   {agent, [{config, [{verbosity, silence}]}, +		    {net_if,[{verbosity,silence}]}, +		    {mib_server,[{verbosity,silence}]}, +		    {local_db,[{verbosity,silence}]}, +		    {agent_verbosity,silence} +		   ]}]}. diff --git a/lib/common_test/test/ct_snmp_SUITE_data/snmp1_SUITE.erl b/lib/common_test/test/ct_snmp_SUITE_data/snmp1_SUITE.erl new file mode 100644 index 0000000000..dcc5c5378b --- /dev/null +++ b/lib/common_test/test/ct_snmp_SUITE_data/snmp1_SUITE.erl @@ -0,0 +1,152 @@ +%%-------------------------------------------------------------------- +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2012. All Rights Reserved. +%% +%% 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. +%% +%% %CopyrightEnd% +%% +%%---------------------------------------------------------------------- +%% File: ct_snmp_SUITE.erl +%% +%% Description: +%%    This file contains the test cases for the ct_snmp API. +%% +%% @author Support +%% @doc Test  of SNMP support in common_test +%% @end +%%---------------------------------------------------------------------- +%%---------------------------------------------------------------------- +-module(snmp1_SUITE). +-include_lib("common_test/include/ct.hrl"). +-include_lib("snmp/include/STANDARD-MIB.hrl"). +-include_lib("snmp/include/snmp_types.hrl"). + +-compile(export_all). + +%% Default timetrap timeout (set in init_per_testcase). +-define(default_timeout, ?t:minutes(1)). + +%% SNMP user stuff +-behaviour(snmpm_user). +-export([handle_error/3, +	 handle_agent/5, +	 handle_pdu/4, +	 handle_trap/3, +	 handle_inform/3, +	 handle_report/3]). + + +suite() -> +    [{require, snmp_mgr_agent, snmp}, +     {require, snmp_app_cfg, snmp_app}]. + +all() -> +    [start_stop, +    {group,get_set}]. + + +groups() -> +    [{get_set,[get_values,get_next_values,set_values]}]. + +init_per_group(get_set, Config) -> +    ok = ct_snmp:start(Config,snmp_mgr_agent,snmp_app_cfg), +    Config. + +end_per_group(get_set, Config) -> +    ok = ct_snmp:stop(Config), +    Config. + +init_per_testcase(_Case, Config) -> +    Dog = test_server:timetrap(?default_timeout), +    [{watchdog, Dog}|Config]. + +end_per_testcase(_Case, Config) -> +    Dog=?config(watchdog, Config), +    test_server:timetrap_cancel(Dog), +    ok. + +init_per_suite(Config) -> +    Config. + +end_per_suite(Config) -> +    Config. + +break(_Config) -> +    test_server:break(""), +    ok. + +start_stop(Config) -> +    ok = ct_snmp:start(Config,snmp_mgr_agent,snmp_app_cfg), +    timer:sleep(1000), +    {snmp,_,_} = lists:keyfind(snmp,1,application:which_applications()), +    [_|_] = filelib:wildcard("*/*.conf",?config(priv_dir,Config)), + +    ok = ct_snmp:stop(Config), +    timer:sleep(1000), +    false = lists:keyfind(snmp,1,application:which_applications()), +    [] = filelib:wildcard("*/*.conf",?config(priv_dir,Config)), +    ok. + +get_values(_Config) -> +    Oids1 = [?sysDescr_instance, ?sysName_instance], +    {noError,_,V1} = ct_snmp:get_values(agent_name,Oids1,snmp_mgr_agent), +    [#varbind{oid=?sysDescr_instance,value="Erlang SNMP agent"}, +     #varbind{oid=?sysName_instance,value="ct_test"}] = V1, +    ok. + +get_next_values(_Config) -> +    Oids2 = [?system], +    {noError,_,V2} = ct_snmp:get_next_values(agent_name,Oids2,snmp_mgr_agent), +    [#varbind{oid=?sysDescr_instance,value="Erlang SNMP agent"}] = V2, +    ok. + +set_values(Config) -> +    Oid3 = ?sysName_instance, +    NewName = "ct_test changed by " ++ atom_to_list(?MODULE), +    VarsAndVals = [{Oid3,s,NewName}], +    {noError,_,_} = +	ct_snmp:set_values(agent_name,VarsAndVals,snmp_mgr_agent,Config), + +    Oids4 = [?sysName_instance], +    {noError,_,V4} = ct_snmp:get_values(agent_name,Oids4,snmp_mgr_agent), +    [#varbind{oid=?sysName_instance,value=NewName}] = V4, + +    ok. + + +%%%----------------------------------------------------------------- +%%% SNMP Manager User callback +handle_error(ReqId, Reason, UserData) -> +    erlang:display({handle_error,ReqId, Reason, UserData}), +    ignore. + +handle_agent(Addr, Port, Type, SnmpInfo, UserData) -> +    erlang:display({handle_agent,Addr, Port, Type, SnmpInfo, UserData}), +    ignore. + +handle_pdu(TargetName, ReqId, SnmpPduInfo, UserData) -> +    erlang:display({handle_pdu,TargetName, ReqId, SnmpPduInfo, UserData}), +    ignore. + +handle_trap(TargetName, SnmpTrapInfo, UserData) -> +    erlang:display({handle_trap,TargetName, SnmpTrapInfo, UserData}), +    ignore. + +handle_inform(TargetName, SnmpInformInfo, UserData) -> +    erlang:display({handle_inform,TargetName, SnmpInformInfo, UserData}), +    ignore. + +handle_report(TargetName, SnmpReportInfo, UserData) -> +    erlang:display({handle_report,TargetName, SnmpReportInfo, UserData}), +    ignore. diff --git a/lib/common_test/test/ct_system_error_SUITE.erl b/lib/common_test/test/ct_system_error_SUITE.erl new file mode 100644 index 0000000000..f00f470c33 --- /dev/null +++ b/lib/common_test/test/ct_system_error_SUITE.erl @@ -0,0 +1,132 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2012. All Rights Reserved. +%% +%% 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. +%% +%% %CopyrightEnd% +%% + +%%%------------------------------------------------------------------- +%%% File: ct_system_error_SUITE +%%% +%%% Description: +%%% +%%% Test that severe system errors (such as failure to write logs) are +%%% noticed and handled. +%%%------------------------------------------------------------------- +-module(ct_system_error_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("common_test/include/ct_event.hrl"). + +-define(eh, ct_test_support_eh). + +%%-------------------------------------------------------------------- +%% TEST SERVER CALLBACK FUNCTIONS +%%-------------------------------------------------------------------- + +%%-------------------------------------------------------------------- +%% Description: Since Common Test starts another Test Server +%% instance, the tests need to be performed on a separate node (or +%% there will be clashes with logging processes etc). +%%-------------------------------------------------------------------- +init_per_suite(Config) -> +    Config1 = ct_test_support:init_per_suite(Config), +    Config1. + +end_per_suite(Config) -> +    ct_test_support:end_per_suite(Config). + +init_per_testcase(TestCase, Config) -> +    ct_test_support:init_per_testcase(TestCase, Config). + +end_per_testcase(TestCase, Config) -> +    ct_test_support:end_per_testcase(TestCase, Config). + +suite() -> [{ct_hooks,[ts_install_cth]}]. + +all() -> +    [ +     test_server_failing_logs +    ]. + +%%-------------------------------------------------------------------- +%% TEST CASES +%%-------------------------------------------------------------------- + +%%%----------------------------------------------------------------- +%%% +test_server_failing_logs(Config) -> +    TC = test_server_failing_logs, +    DataDir = ?config(data_dir, Config), +    Suite = filename:join(DataDir, "a_SUITE"), +    {Opts,ERPid} = setup([{suite,Suite},{label,TC}], Config), +    crash_test_server(Config), +    {error,{cannot_create_log_dir,__}} = ct_test_support:run(Opts, Config), +    Events = ct_test_support:get_events(ERPid, Config), +    ct_test_support:log_events(TC, +			       reformat(Events, ?eh), +			       ?config(priv_dir, Config), +			       Opts), + +    TestEvents = events_to_check(TC), +    ok = ct_test_support:verify_events(TestEvents, Events, Config). + +crash_test_server(Config) -> +    DataDir = ?config(data_dir, Config), +    Root = ?config(priv_dir, Config), +    [$@|Host] = lists:dropwhile(fun(C) -> +					C =/= $@ +				end, atom_to_list(node())), +    Format = filename:join(Root, +			   "ct_run.ct@" ++ Host ++ +			       ".~4..0w-~2..0w-~2..0w_" +			   "~2..0w.~2..0w.~2..0w"), +    [C2,C1|_] = lists:reverse(filename:split(DataDir)), +    LogDir = C1 ++ "." ++ C2 ++ ".a_SUITE.logs", +    T = calendar:datetime_to_gregorian_seconds(calendar:local_time()), +    [begin +	 {{Y,Mon,D},{H,Min,S}} = +	     calendar:gregorian_seconds_to_datetime(T+Offset), +	 Dir0 = io_lib:format(Format, [Y,Mon,D,H,Min,S]), +	 Dir = lists:flatten(Dir0), +	 file:make_dir(Dir), +	 File = filename:join(Dir, LogDir), +	 file:write_file(File, "anything goes\n") +     end || Offset <- lists:seq(0, 20)], +    ok. + +%%%----------------------------------------------------------------- +%%% HELP FUNCTIONS +%%%----------------------------------------------------------------- + +setup(Test, Config) -> +    Opts0 = ct_test_support:get_opts(Config), +    Level = ?config(trace_level, Config), +    EvHArgs = [{cbm,ct_test_support},{trace_level,Level}], +    Opts = Opts0 ++ [{event_handler,{?eh,EvHArgs}}|Test], +    ERPid = ct_test_support:start_event_receiver(Config), +    {Opts,ERPid}. + +reformat(Events, EH) -> +    ct_test_support:reformat(Events, EH). + +%%%----------------------------------------------------------------- +%%% TEST EVENTS +%%%----------------------------------------------------------------- + +events_to_check(_Test) -> +    [{?eh,severe_error,{cannot_create_log_dir,{'_','_'}}}]. diff --git a/lib/common_test/test/ct_system_error_SUITE_data/a_SUITE.erl b/lib/common_test/test/ct_system_error_SUITE_data/a_SUITE.erl new file mode 100644 index 0000000000..c6e3ddfd5d --- /dev/null +++ b/lib/common_test/test/ct_system_error_SUITE_data/a_SUITE.erl @@ -0,0 +1,122 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2012. All Rights Reserved. +%% +%% 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. +%% +%% %CopyrightEnd% +%% +-module(a_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). + +%%-------------------------------------------------------------------- +%% @spec suite() -> Info +%% Info = [tuple()] +%% @end +%%-------------------------------------------------------------------- +suite() -> +    [{timetrap,{seconds,10}}]. + +%%-------------------------------------------------------------------- +%% @spec init_per_suite(Config0) -> +%%     Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} +%% Config0 = Config1 = [tuple()] +%% Reason = term() +%% @end +%%-------------------------------------------------------------------- +init_per_suite(Config) -> +    Config. + +%%-------------------------------------------------------------------- +%% @spec end_per_suite(Config0) -> void() | {save_config,Config1} +%% Config0 = Config1 = [tuple()] +%% @end +%%-------------------------------------------------------------------- +end_per_suite(_Config) -> +    ok. + +%%-------------------------------------------------------------------- +%% @spec init_per_group(GroupName, Config0) -> +%%               Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} +%% GroupName = atom() +%% Config0 = Config1 = [tuple()] +%% Reason = term() +%% @end +%%-------------------------------------------------------------------- +init_per_group(_GroupName, Config) -> +    Config. + +%%-------------------------------------------------------------------- +%% @spec end_per_group(GroupName, Config0) -> +%%               void() | {save_config,Config1} +%% GroupName = atom() +%% Config0 = Config1 = [tuple()] +%% @end +%%-------------------------------------------------------------------- +end_per_group(_GroupName, _Config) -> +    ok. + +%%-------------------------------------------------------------------- +%% @spec init_per_testcase(TestCase, Config0) -> +%%               Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} +%% TestCase = atom() +%% Config0 = Config1 = [tuple()] +%% Reason = term() +%% @end +%%-------------------------------------------------------------------- +init_per_testcase(_TestCase, Config) -> +    Config. + +%%-------------------------------------------------------------------- +%% @spec end_per_testcase(TestCase, Config0) -> +%%               void() | {save_config,Config1} | {fail,Reason} +%% TestCase = atom() +%% Config0 = Config1 = [tuple()] +%% Reason = term() +%% @end +%%-------------------------------------------------------------------- +end_per_testcase(_TestCase, _Config) -> +    ok. + +%%-------------------------------------------------------------------- +%% @spec groups() -> [Group] +%% Group = {GroupName,Properties,GroupsAndTestCases} +%% GroupName = atom() +%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}] +%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase] +%% TestCase = atom() +%% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}} +%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | +%%              repeat_until_any_ok | repeat_until_any_fail +%% N = integer() | forever +%% @end +%%-------------------------------------------------------------------- +groups() -> +    []. + +%%-------------------------------------------------------------------- +%% @spec all() -> GroupsAndTestCases | {skip,Reason} +%% GroupsAndTestCases = [{group,GroupName} | TestCase] +%% GroupName = atom() +%% TestCase = atom() +%% Reason = term() +%% @end +%%-------------------------------------------------------------------- +all() -> +    [tc1]. + +tc1(_C) -> +    ok. diff --git a/lib/common_test/vsn.mk b/lib/common_test/vsn.mk index 877aa775fd..5c9fdfc47e 100644 --- a/lib/common_test/vsn.mk +++ b/lib/common_test/vsn.mk @@ -1 +1 @@ -COMMON_TEST_VSN = 1.6.2 +COMMON_TEST_VSN = 1.6.2.1  | 
