diff options
-rw-r--r-- | lib/snmp/test/snmp_agent_test.erl | 5 | ||||
-rw-r--r-- | lib/snmp/test/snmp_agent_test_lib.erl | 23 | ||||
-rw-r--r-- | lib/snmp/test/snmp_test_global_sys_monitor.erl | 99 |
3 files changed, 101 insertions, 26 deletions
diff --git a/lib/snmp/test/snmp_agent_test.erl b/lib/snmp/test/snmp_agent_test.erl index 4a797efbe5..1ff8c2e057 100644 --- a/lib/snmp/test/snmp_agent_test.erl +++ b/lib/snmp/test/snmp_agent_test.erl @@ -772,6 +772,8 @@ init_per_testcase(Case, Config) when is_list(Config) -> Result = init_per_testcase1(Case, Config), + snmp_test_global_sys_monitor:reset_events(), + p("init_per_testcase -> done when" "~n Result: ~p" "~n Nodes: ~p", [Result, erlang:nodes()]), @@ -821,6 +823,9 @@ end_per_testcase(Case, Config) when is_list(Config) -> "~n Nodes: ~p", [Config, erlang:nodes()]), display_log(Config), + + p("system events during test: " + "~n ~p", [snmp_test_global_sys_monitor:events()]), Result = end_per_testcase1(Case, Config), diff --git a/lib/snmp/test/snmp_agent_test_lib.erl b/lib/snmp/test/snmp_agent_test_lib.erl index ddc901216e..b1c29c4235 100644 --- a/lib/snmp/test/snmp_agent_test_lib.erl +++ b/lib/snmp/test/snmp_agent_test_lib.erl @@ -332,7 +332,7 @@ await_tc_runner_started(Runner, OldFlag) -> {tc_runner_started, Runner} -> ?PRINT2("TC runner start acknowledged~n"), ok - after 10000 -> + after 10000 -> %% We should *really* not have to wait this long, but... trap_exit(OldFlag), unlink_and_flush_exit(Runner), RunnerInfo = process_info(Runner), @@ -367,6 +367,8 @@ await_tc_runner_done(Runner, OldFlag) -> case Ret of {error, Reason} -> exit(Reason); + {skip, _} = SKIP -> + exit(SKIP); OK -> OK end @@ -1332,10 +1334,23 @@ do_expect2(Check, Type, Err, Idx, ExpVBs, To) {Type2, Err2, Idx2, VBs2}, ReqId}}; - Error -> - io_format_expect("received error (16): " + + {error, timeout} = Error -> + SysEvs = snmp_test_global_sys_monitor:events(), + io_format_expect("got timeout (16) when system events:" + "~n ~p", [SysEvs]), + if + (SysEvs =/= []) -> + Error; + true -> + {skip, {system_events, SysEvs}} + end; + + + Error -> + io_format_expect("received error (17): " "~n Error: ~p", [Error]), - Error + Error end. diff --git a/lib/snmp/test/snmp_test_global_sys_monitor.erl b/lib/snmp/test/snmp_test_global_sys_monitor.erl index 04dbc72133..eafb96621a 100644 --- a/lib/snmp/test/snmp_test_global_sys_monitor.erl +++ b/lib/snmp/test/snmp_test_global_sys_monitor.erl @@ -20,8 +20,11 @@ -module(snmp_test_global_sys_monitor). --export([start/0, stop/0, log/1, - init/1]). +-export([start/0, stop/0, + reset_events/0, + events/0, + log/1]). +-export([init/1]). -define(NAME, ?MODULE). @@ -33,11 +36,18 @@ start() -> proc_lib:start(?MODULE, init, [Parent]). stop() -> - global:send(?NAME, {?MODULE, stop}). + cast(stop). +%% This does not reset the global counter but the "collector" +%% See events for more info. +reset_events() -> + cast(reset_events). + +events() -> + call(events). log(Event) -> - global:send(?NAME, {?MODULE, node(), Event}). + cast({node(), Event}). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -48,7 +58,7 @@ init(Parent) -> yes -> info_msg("Starting", []), proc_lib:init_ack(Parent, {ok, self()}), - loop(#{parent => Parent}); + loop(#{parent => Parent, ev_cnt => 0, evs => []}); no -> warning_msg("Already started", []), proc_lib:init_ack(Parent, {error, already_started}), @@ -61,10 +71,19 @@ init(Parent) -> loop(State) -> receive {?MODULE, stop} -> - warning_msg("Stopping", []), + warning_msg("Stopping with ~w events counted", + [maps:get(ev_cnt, State)]), exit(normal); - {?MODULE, Node, Event} -> + {?MODULE, reset_events} -> + loop(State#{evs => []}); + + {?MODULE, Ref, From, events} -> + Evs = maps:get(evs, State), + From ! {?MODULE, Ref, lists:reverse(Evs)}, + loop(State); + + {?MODULE, {Node, Event}} -> State2 = process_event(State, Node, Event), loop(State2); @@ -109,21 +128,27 @@ process_event(State, Node, Event) -> %% System Monitor events -process_system_event(State, Node, Pid, TS, long_gc, Info) -> +%% We only *count* system events +process_system_event(#{ev_cnt := Cnt, evs := Evs} = State, + Node, Pid, TS, long_gc = Ev, Info) -> print_system_event("Long GC", Node, Pid, TS, Info), - State; -process_system_event(State, Node, Pid, TS, long_schedule, Info) -> + State#{ev_cnt => Cnt + 1, evs => [{Node, Ev} | Evs]}; +process_system_event(#{ev_cnt := Cnt, evs := Evs} = State, + Node, Pid, TS, long_schedule = Ev, Info) -> print_system_event("Long Schedule", Node, Pid, TS, Info), - State; -process_system_event(State, Node, Pid, TS, large_heap, Info) -> + State#{ev_cnt => Cnt + 1, evs => [{Node, Ev} | Evs]}; +process_system_event(#{ev_cnt := Cnt, evs := Evs} = State, + Node, Pid, TS, large_heap = Ev, Info) -> print_system_event("Large Heap", Node, Pid, TS, Info), - State; -process_system_event(State, Node, Pid, TS, busy_port, Info) -> + State#{ev_cnt => Cnt + 1, evs => [{Node, Ev} | Evs]}; +process_system_event(#{ev_cnt := Cnt, evs := Evs} = State, + Node, Pid, TS, busy_port = Ev, Info) -> print_system_event("Busy port", Node, Pid, TS, Info), - State; -process_system_event(State, Node, Pid, TS, busy_dist_port, Info) -> + State#{ev_cnt => Cnt + 1, evs => [{Node, Ev} | Evs]}; +process_system_event(#{ev_cnt := Cnt, evs := Evs} = State, + Node, Pid, TS, busy_dist_port = Ev, Info) -> print_system_event("Busy dist port", Node, Pid, TS, Info), - State; + State#{ev_cnt => Cnt + 1, evs => [{Node, Ev} | Evs]}; %% And everything else process_system_event(State, Node, Pid, TS, Tag, Info) -> @@ -143,6 +168,36 @@ f(F, A) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +cast(Msg) -> + try global:send(?NAME, {?MODULE, Msg}) of + Pid when is_pid(Pid) -> + ok + catch + C:E:_ -> + {error, {catched, C, E}} + end. + +call(Req) -> + call(Req, infinity). + +call(Req, Timeout) -> + Ref = make_ref(), + try global:send(?NAME, {?MODULE, Ref, self(), Req}) of + Pid when is_pid(Pid) -> + receive + {?MODULE, Ref, Rep} -> + Rep + after Timeout -> + {error, timeout} + end + catch + C:E:_ -> + {error, {catched, C, E}} + end. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + info_msg(F, A) -> error_logger:info_msg(format_msg(F, A), []). @@ -151,9 +206,9 @@ warning_msg(F, A) -> format_msg(F, A) -> - lists:flatten(io_lib:format( - "~n" ++ - "****** SNMP TEST GLOBAL SYSTEM MONITOR ******~n~n" ++ - F ++ "~n~n", - A)). + f("~n" ++ + "****** SNMP TEST GLOBAL SYSTEM MONITOR ******~n~n" ++ + F ++ + "~n~n", + A). |