diff options
-rw-r--r-- | erts/emulator/test/receive_SUITE.erl | 23 | ||||
-rw-r--r-- | erts/emulator/test/system_profile_SUITE.erl | 3 | ||||
-rw-r--r-- | erts/etc/unix/to_erl.c | 4 | ||||
-rw-r--r-- | lib/diameter/src/base/diameter_peer_fsm.erl | 65 | ||||
-rw-r--r-- | lib/diameter/src/base/diameter_watchdog.erl | 19 | ||||
-rw-r--r-- | lib/diameter/test/diameter_transport_SUITE.erl | 7 | ||||
-rw-r--r-- | lib/os_mon/src/disksup.erl | 4 | ||||
-rw-r--r-- | lib/os_mon/test/disksup_SUITE.erl | 295 | ||||
-rw-r--r-- | lib/snmp/test/Makefile | 2 |
9 files changed, 202 insertions, 220 deletions
diff --git a/erts/emulator/test/receive_SUITE.erl b/erts/emulator/test/receive_SUITE.erl index b070e2b986..2e7ac1f50c 100644 --- a/erts/emulator/test/receive_SUITE.erl +++ b/erts/emulator/test/receive_SUITE.erl @@ -59,22 +59,25 @@ end_per_testcase(_Func, Config) -> ?t:timetrap_cancel(Dog). call_with_huge_message_queue(Config) when is_list(Config) -> - ?line Pid = spawn_link(fun echo_loop/0), + Pid = spawn_link(fun echo_loop/0), - ?line {Time,ok} = tc(fun() -> calls(10, Pid) end), + {Time,ok} = tc(fun() -> calls(10, Pid) end), - ?line [self() ! {msg,N} || N <- lists:seq(1, 500000)], + [self() ! {msg,N} || N <- lists:seq(1, 500000)], erlang:garbage_collect(), - ?line {NewTime,ok} = tc(fun() -> calls(10, Pid) end), + {NewTime1,ok} = tc(fun() -> calls(10, Pid) end), + {NewTime2,ok} = tc(fun() -> calls(10, Pid) end), + io:format("Time for empty message queue: ~p", [Time]), - io:format("Time for huge message queue: ~p", [NewTime]), + io:format("Time1 for huge message queue: ~p", [NewTime1]), + io:format("Time2 for huge message queue: ~p", [NewTime2]), - case (NewTime+1) / (Time+1) of + case hd(lists:sort([(NewTime1+1) / (Time+1), (NewTime2+1) / (Time+1)])) of Q when Q < 10 -> ok; Q -> - io:format("Q = ~p", [Q]), - ?line ?t:fail() + io:format("Best Q = ~p", [Q]), + ?t:fail() end, ok. @@ -95,8 +98,8 @@ call(Pid, Msg) -> end. receive_in_between(Config) when is_list(Config) -> - ?line Pid = spawn_link(fun echo_loop/0), - ?line [{ok,{a,b}} = call2(Pid, {a,b}) || _ <- lists:seq(1, 100000)], + Pid = spawn_link(fun echo_loop/0), + [{ok,{a,b}} = call2(Pid, {a,b}) || _ <- lists:seq(1, 100000)], ok. call2(Pid, Msg) -> diff --git a/erts/emulator/test/system_profile_SUITE.erl b/erts/emulator/test/system_profile_SUITE.erl index ba94a371be..a387c08ef9 100644 --- a/erts/emulator/test/system_profile_SUITE.erl +++ b/erts/emulator/test/system_profile_SUITE.erl @@ -198,7 +198,9 @@ check_multi_scheduling_block(Nodes) -> Pid = start_profiler_process(), undefined = erlang:system_profile(Pid, [scheduler]), {ok, Supervisor} = start_load(Nodes), + wait(600), erlang:system_flag(multi_scheduling, block), + wait(600), erlang:system_flag(multi_scheduling, unblock), {Pid, [scheduler]} = erlang:system_profile(undefined, []), Events = get_profiler_events(), @@ -213,7 +215,6 @@ check_block_system(Nodes) -> Pid = start_profiler_process(), undefined = erlang:system_profile(Pid, [scheduler]), {ok, Supervisor} = start_load(Nodes), - % FIXME: remove wait !! wait(300), undefined = erlang:system_monitor(Dummy, [busy_port]), {Dummy, [busy_port]} = erlang:system_monitor(undefined, []), diff --git a/erts/etc/unix/to_erl.c b/erts/etc/unix/to_erl.c index 0f27b64811..b9e397cbf2 100644 --- a/erts/etc/unix/to_erl.c +++ b/erts/etc/unix/to_erl.c @@ -339,7 +339,7 @@ int main(int argc, char **argv) tty_smode.c_cc[VTIME] =0;/* Note that VTIME is the same as VEOL! */ tty_smode.c_cc[VINTR] =3; - tcsetattr(0, TCSANOW, &tty_smode); + tcsetattr(0, TCSADRAIN, &tty_smode); #ifdef DEBUG show_terminal_settings(&tty_smode); @@ -484,7 +484,7 @@ int main(int argc, char **argv) * Reset terminal characterstics * XXX */ - tcsetattr(0, TCSANOW, &tty_rmode); + tcsetattr(0, TCSADRAIN, &tty_rmode); return 0; } diff --git a/lib/diameter/src/base/diameter_peer_fsm.erl b/lib/diameter/src/base/diameter_peer_fsm.erl index 4e55864168..2b99ecc59c 100644 --- a/lib/diameter/src/base/diameter_peer_fsm.erl +++ b/lib/diameter/src/base/diameter_peer_fsm.erl @@ -28,7 +28,8 @@ -behaviour(gen_server). %% Interface towards diameter_watchdog. --export([start/3]). +-export([start/3, + result_code/2]). %% gen_server callbacks -export([init/1, @@ -62,7 +63,6 @@ %% Keys in process dictionary. -define(CB_KEY, cb). %% capabilities callback -define(DPR_KEY, dpr). %% disconnect callback --define(DWA_KEY, dwa). %% outgoing DWA -define(REF_KEY, ref). %% transport_ref() -define(Q_KEY, q). %% transport start queue -define(START_KEY, start). %% start of connected transport @@ -177,14 +177,9 @@ init(T) -> proc_lib:init_ack({ok, self()}), gen_server:enter_loop(?MODULE, [], i(T)). -i({Ack, WPid, {M, Ref} = T, Opts, {Mask, - Nodes, - Dict0, - #diameter_service{capabilities = LCaps} - = Svc}}) -> +i({Ack, WPid, {M, Ref} = T, Opts, {Mask, Nodes, Dict0, Svc}}) -> erlang:monitor(process, WPid), wait(Ack, WPid), - putr(?DWA_KEY, dwa(LCaps)), diameter_stats:reg(Ref), {[Cs,Ds], Rest} = proplists:split(Opts, [capabilities_cb, disconnect_cb]), putr(?CB_KEY, {Ref, [F || {_,F} <- Cs]}), @@ -612,9 +607,7 @@ rcv(Name, _, #state{state = PS}) Name == 'CEA' -> {stop, {Name, PS}}; -rcv(N, Pkt, S) - when N == 'DWR'; - N == 'DPR' -> +rcv('DPR' = N, Pkt, S) -> handle_request(N, Pkt, S); %% DPA in response to DPR and with the expected identifiers. @@ -717,8 +710,8 @@ build_answer(Type, errors = Es} = Pkt, S) -> - RC = rc(H, Es), - {answer(Type, RC, Es, S), post(Type, RC, Pkt, S)}. + {RC, FailedAVP} = result_code(H, Es), + {answer(Type, RC, FailedAVP, S), post(Type, RC, Pkt, S)}. inband_security([]) -> ?NO_INBAND_SECURITY; @@ -734,7 +727,7 @@ cea(CEA, RC, Dict0) -> post('CER' = T, RC, Pkt, S) -> {T, caps(S), {RC, Pkt}}; -post(_, _, _, _) -> +post('DPR', _, _, _) -> ok. rejected({capabilities_cb, _F, Reason}, T, S) -> @@ -743,13 +736,10 @@ rejected({capabilities_cb, _F, Reason}, T, S) -> rejected(discard, T, _) -> close(T); rejected({N, Es}, T, S) -> - {answer('CER', N, Es, S), T}; + {answer('CER', N, failed_avp(N, Es), S), T}; rejected(N, T, S) -> rejected({N, []}, T, S). -answer(Type, RC, Es, S) -> - set(answer(Type, RC, S), failed_avp(RC, Es)). - failed_avp(RC, [{RC, Avp} | _]) -> [{'Failed-AVP', [{'AVP', [Avp]}]}]; failed_avp(RC, [_ | Es]) -> @@ -757,6 +747,9 @@ failed_avp(RC, [_ | Es]) -> failed_avp(_, [] = No) -> No. +answer(Type, RC, FailedAVP, S) -> + set(answer(Type, RC, S), FailedAVP). + answer(Type, RC, S) -> answer_message(answer(Type, S), RC). @@ -784,29 +777,29 @@ set(['answer-message' | _] = Ans, FailedAvp) -> set([_|_] = Ans, FailedAvp) -> Ans ++ FailedAvp. -%% rc/2 +%% result_code/2 -rc(#diameter_header{is_error = true}, _) -> - 3008; %% DIAMETER_INVALID_HDR_BITS +result_code(#diameter_header{is_error = true}, _) -> + {3008, []}; %% DIAMETER_INVALID_HDR_BITS -rc(_, [Bs|_]) +result_code(_, [Bs|_]) when is_bitstring(Bs) -> %% from old code - 3009; %% DIAMETER_INVALID_HDR_BITS + {3009, []}; %% DIAMETER_INVALID_HDR_BITS -rc(#diameter_header{version = ?DIAMETER_VERSION}, Es) -> +result_code(#diameter_header{version = ?DIAMETER_VERSION}, Es) -> rc(Es); -rc(_, _) -> - 5011. %% DIAMETER_UNSUPPORTED_VERSION +result_code(_, _) -> + {5011, []}. %% DIAMETER_UNSUPPORTED_VERSION %% rc/1 rc([]) -> - 2001; %% DIAMETER_SUCCESS -rc([{RC,_}|_]) -> - RC; + {2001, []}; %% DIAMETER_SUCCESS +rc([{RC, _} | _] = Es) -> + {RC, failed_avp(RC, Es)}; rc([RC|_]) -> - RC. + {RC, []}. %% DIAMETER_INVALID_HDR_BITS 3008 %% A request was received whose bits in the Diameter header were @@ -832,9 +825,6 @@ rc([RC|_]) -> %% answer/2 -answer('DWR', _) -> - getr(?DWA_KEY); - answer(Name, #state{service = #diameter_service{capabilities = Caps}}) -> a(Name, Caps). @@ -1019,15 +1009,6 @@ report({M, _, _, _, _} = T) report(_) -> ok. -%% dwa/1 - -dwa(#diameter_caps{origin_host = OH, - origin_realm = OR, - origin_state_id = OSI}) -> - ['DWA', {'Origin-Host', OH}, - {'Origin-Realm', OR}, - {'Origin-State-Id', OSI}]. - %% dpr/2 %% %% The RFC isn't clear on whether DPR should be send in a non-Open diff --git a/lib/diameter/src/base/diameter_watchdog.erl b/lib/diameter/src/base/diameter_watchdog.erl index 88ccf630e2..7e75801718 100644 --- a/lib/diameter/src/base/diameter_watchdog.erl +++ b/lib/diameter/src/base/diameter_watchdog.erl @@ -201,7 +201,7 @@ common_dictionary(Apps) -> %% means a user won't be able either send of receive %% messages in the common dictionary: incoming request %% will be answered with 3007 and outgoing requests cannot - %% be sent. The dictionary returned here is oly used for + %% be sent. The dictionary returned here is only used for %% messages diameter sends and receives: CER/CEA, DPR/DPA %% and DWR/DWA. ?BASE @@ -545,10 +545,15 @@ recv(Name, Pkt, S) -> %% rcv/3 +rcv('DWR', Pkt, #watchdog{transport = TPid, + dictionary = Dict0, + sequence = Mask}) -> + send(TPid, {send, encode(dwa(Pkt), Mask, Dict0)}), + ?LOG(send, 'DWA'); + rcv(N, _, _) when N == 'CER'; N == 'CEA'; - N == 'DWR'; N == 'DWA'; N == 'DPR'; N == 'DPA' -> @@ -642,6 +647,9 @@ rcv('DWA', #watchdog{status = reopen, %% REOPEN Receive non-DWA Throwaway() REOPEN +rcv('DWR', #watchdog{status = reopen} = S) -> + S; %% ensure DWA: the RFC isn't explicit about answering + rcv(_, #watchdog{status = reopen} = S) -> throwaway(S). @@ -782,6 +790,13 @@ dwr(#diameter_caps{origin_host = OH, {'Origin-Realm', OR}, {'Origin-State-Id', OSI}]. +%% dwa/1 + +dwa(#diameter_packet{header = H, errors = Es}) -> + {RC, FailedAVP} = diameter_peer_fsm:result_code(H, Es), + ['DWA', {'Result-Code', RC} + | tl(getr(dwr)) ++ FailedAVP]. + %% restrict_nodes/1 restrict_nodes(false) -> diff --git a/lib/diameter/test/diameter_transport_SUITE.erl b/lib/diameter/test/diameter_transport_SUITE.erl index 97f4cec11f..9408fae62c 100644 --- a/lib/diameter/test/diameter_transport_SUITE.erl +++ b/lib/diameter/test/diameter_transport_SUITE.erl @@ -180,12 +180,13 @@ reconnect({listen, Ref}) -> [_] = diameter_reg:wait({diameter_tcp, listener, {LRef, '_'}}), true = diameter_reg:add_new({?MODULE, Ref, LRef}), - %% Wait for partner to request transport death: kill to force the - %% peer to reconnect. + %% Wait for partner to request transport death. TPid = abort(SvcName, LRef, Ref), + %% Kill transport to force the peer to reconnect. exit(TPid, kill), + %% Wait for the partner again. abort(SvcName, LRef, Ref); reconnect({connect, Ref}) -> @@ -200,7 +201,7 @@ reconnect({connect, Ref}) -> %% reconnection attempts. abort(SvcName, Pid, Ref), - %% Transport does down and is reestablished. + %% Transport goes down and is reestablished. ?RECV(#diameter_event{service = SvcName, info = {down, CRef, _, _}}), ?RECV(#diameter_event{service = SvcName, info = {reconnect, CRef, _}}), ?RECV(#diameter_event{service = SvcName, info = {up, CRef, _, _, _}}), diff --git a/lib/os_mon/src/disksup.erl b/lib/os_mon/src/disksup.erl index 8c8bbe843a..278da26a20 100644 --- a/lib/os_mon/src/disksup.erl +++ b/lib/os_mon/src/disksup.erl @@ -263,10 +263,10 @@ check_disk_space({unix, dragonfly}, Port, Threshold) -> Result = my_cmd("/bin/df -k -t ufs,hammer", Port), check_disks_solaris(skip_to_eol(Result), Threshold); check_disk_space({unix, freebsd}, Port, Threshold) -> - Result = my_cmd("/bin/df -k -t ufs", Port), + Result = my_cmd("/bin/df -k -l", Port), check_disks_solaris(skip_to_eol(Result), Threshold); check_disk_space({unix, openbsd}, Port, Threshold) -> - Result = my_cmd("/bin/df -k -t ffs", Port), + Result = my_cmd("/bin/df -k -l", Port), check_disks_solaris(skip_to_eol(Result), Threshold); check_disk_space({unix, netbsd}, Port, Threshold) -> Result = my_cmd("/bin/df -k -t ffs", Port), diff --git a/lib/os_mon/test/disksup_SUITE.erl b/lib/os_mon/test/disksup_SUITE.erl index c1ff2c6afc..9c65d8b692 100644 --- a/lib/os_mon/test/disksup_SUITE.erl +++ b/lib/os_mon/test/disksup_SUITE.erl @@ -34,11 +34,11 @@ -define(default_timeout, ?t:minutes(1)). init_per_suite(Config) when is_list(Config) -> - ?line ok = application:start(os_mon), + ok = application:start(os_mon), Config. end_per_suite(Config) when is_list(Config) -> - ?line ok = application:stop(os_mon), + ok = application:stop(os_mon), Config. init_per_testcase(unavailable, Config) -> @@ -78,80 +78,71 @@ end_per_group(_GroupName, Config) -> Config. -api(suite) -> - []; -api(doc) -> - ["Test of API functions"]; +api(suite) -> []; +api(doc) -> ["Test of API functions"]; api(Config) when is_list(Config) -> %% get_disk_data() - ?line [{Id, KByte, Capacity}|_] = disksup:get_disk_data(), - ?line true = io_lib:printable_list(Id), - ?line true = is_integer(KByte), - ?line true = is_integer(Capacity), - ?line true = KByte>0, - ?line true = Capacity>0, + [{Id,KByte,Capacity}|_] = get_disk_data(), + true = io_lib:printable_list(Id), + true = is_integer(KByte), + true = is_integer(Capacity), + true = Capacity>0, + true = KByte>0, %% get_check_interval() - ?line 1800000 = disksup:get_check_interval(), + 1800000 = disksup:get_check_interval(), %% set_check_interval(Minutes) - ?line ok = disksup:set_check_interval(20), - ?line 1200000 = disksup:get_check_interval(), - ?line {'EXIT',{badarg,_}} = (catch disksup:set_check_interval(0.5)), - ?line 1200000 = disksup:get_check_interval(), - ?line ok = disksup:set_check_interval(30), + ok = disksup:set_check_interval(20), + 1200000 = disksup:get_check_interval(), + {'EXIT',{badarg,_}} = (catch disksup:set_check_interval(0.5)), + 1200000 = disksup:get_check_interval(), + ok = disksup:set_check_interval(30), %% get_almost_full_threshold() - ?line 80 = disksup:get_almost_full_threshold(), + 80 = disksup:get_almost_full_threshold(), %% set_almost_full_threshold(Float) - ?line ok = disksup:set_almost_full_threshold(0.90), - ?line 90 = disksup:get_almost_full_threshold(), - ?line {'EXIT',{badarg,_}} = + ok = disksup:set_almost_full_threshold(0.90), + 90 = disksup:get_almost_full_threshold(), + {'EXIT',{badarg,_}} = (catch disksup:set_almost_full_threshold(-0.5)), - ?line 90 = disksup:get_almost_full_threshold(), - ?line ok = disksup:set_almost_full_threshold(0.80), + 90 = disksup:get_almost_full_threshold(), + ok = disksup:set_almost_full_threshold(0.80), ok. -config(suite) -> - []; -config(doc) -> - ["Test configuration"]; +config(suite) -> []; +config(doc) -> ["Test configuration"]; config(Config) when is_list(Config) -> %% Change configuration parameters and make sure change is reflected %% when disksup is restarted - ?line ok = - application:set_env(os_mon, disk_space_check_interval, 29), - ?line ok = - application:set_env(os_mon, disk_almost_full_threshold, 0.81), + ok = application:set_env(os_mon, disk_space_check_interval, 29), + ok = application:set_env(os_mon, disk_almost_full_threshold, 0.81), - ?line ok = supervisor:terminate_child(os_mon_sup, disksup), - ?line {ok, _Child1} = supervisor:restart_child(os_mon_sup, disksup), + ok = supervisor:terminate_child(os_mon_sup, disksup), + {ok, _Child1} = supervisor:restart_child(os_mon_sup, disksup), - ?line 1740000 = disksup:get_check_interval(), - ?line 81 = disksup:get_almost_full_threshold(), + 1740000 = disksup:get_check_interval(), + 81 = disksup:get_almost_full_threshold(), %% Also try this with bad parameter values, should be ignored - ?line ok = + ok = application:set_env(os_mon, disk_space_check_interval, 0.5), - ?line ok = + ok = application:set_env(os_mon, disk_almost_full_threshold, -0.81), - ?line ok = supervisor:terminate_child(os_mon_sup, disksup), - ?line {ok, _Child2} = supervisor:restart_child(os_mon_sup, disksup), + ok = supervisor:terminate_child(os_mon_sup, disksup), + {ok, _Child2} = supervisor:restart_child(os_mon_sup, disksup), - ?line 1800000 = disksup:get_check_interval(), - ?line 80 = disksup:get_almost_full_threshold(), + 1800000 = disksup:get_check_interval(), + 80 = disksup:get_almost_full_threshold(), %% Reset configuration parameters - ?line ok = - application:set_env(os_mon, disk_space_check_interval, 30), - ?line ok = - application:set_env(os_mon, disk_almost_full_threshold, 0.80), - + ok = application:set_env(os_mon, disk_space_check_interval, 30), + ok = application:set_env(os_mon, disk_almost_full_threshold, 0.80), ok. %%---------------------------------------------------------------------- @@ -159,24 +150,22 @@ config(Config) when is_list(Config) -> %% changes too much during its course, or if there are timing problems %% with the alarm_handler receiving the alarms too late %%---------------------------------------------------------------------- -alarm(suite) -> - []; -alarm(doc) -> - ["Test that alarms are set and cleared"]; +alarm(suite) -> []; +alarm(doc) -> ["Test that alarms are set and cleared"]; alarm(Config) when is_list(Config) -> %% Find out how many disks exceed the threshold %% and make sure the corresponding number of alarms is set - ?line Threshold1 = disksup:get_almost_full_threshold(), % 80 - ?line Data1 = disksup:get_disk_data(), - ?line Over1 = over_threshold(Data1, Threshold1), - ?line Alarms1 = get_alarms(), + Threshold1 = disksup:get_almost_full_threshold(), % 80 + Data1 = disksup:get_disk_data(), + Over1 = over_threshold(Data1, Threshold1), + Alarms1 = get_alarms(), if Over1==length(Alarms1) -> - ?line true; + true; true -> dump_info(), - ?line ?t:fail({bad_alarms, Threshold1, Data1, Alarms1}) + ?t:fail({bad_alarms, Threshold1, Data1, Alarms1}) end, %% Try to find a disk with space usage below Threshold1, @@ -187,24 +176,24 @@ alarm(Config) when is_list(Config) -> true -> false end end, - ?line case until(Fun1, Data1) of + case until(Fun1, Data1) of {_, _, Cap1} -> Threshold2 = Cap1-1, - ?line ok = + ok = disksup:set_almost_full_threshold(Threshold2/100), - ?line disksup ! timeout, % force a disk check - ?line Data2 = disksup:get_disk_data(), - ?line Over2 = over_threshold(Data2, Threshold2), - ?line Alarms2 = get_alarms(), + disksup ! timeout, % force a disk check + Data2 = disksup:get_disk_data(), + Over2 = over_threshold(Data2, Threshold2), + Alarms2 = get_alarms(), if Over2==length(Alarms2), Over2>Over1 -> - ?line true; + true; true -> dump_info(), - ?line ?t:fail({bad_alarms, Threshold2, Data2, Alarms2}) + ?t:fail({bad_alarms, Threshold2, Data2, Alarms2}) end; false -> - ?line ignore + ignore end, %% Find out the highest space usage among all disks @@ -216,40 +205,35 @@ alarm(Config) when is_list(Config) -> true -> MaxAcc end end, - ?line case lists:foldl(Fun2, 0, Data1) of + case lists:foldl(Fun2, 0, Data1) of Max when Max<100 -> Threshold3 = Max+1, - ?line ok = - disksup:set_almost_full_threshold(Threshold3/100), - ?line disksup ! timeout, % force a disk check - ?line Data3 = disksup:get_disk_data(), - ?line Over3 = over_threshold(Data3, Threshold3), - ?line Alarms3 = get_alarms(), + ok = disksup:set_almost_full_threshold(Threshold3/100), + disksup ! timeout, % force a disk check + Data3 = disksup:get_disk_data(), + Over3 = over_threshold(Data3, Threshold3), + Alarms3 = get_alarms(), if Over3==0, length(Alarms3)==0 -> - ?line ok; + ok; true -> dump_info(), - ?line ?t:fail({bad_alarms, Threshold3, Data3, Alarms3}) + ?t:fail({bad_alarms, Threshold3, Data3, Alarms3}) end; 100 -> - ?line ignore + ignore end, %% Reset threshold - ?line ok = disksup:set_almost_full_threshold(Threshold1/100), - + ok = disksup:set_almost_full_threshold(Threshold1/100), ok. over_threshold(Data, Threshold) -> Data2 = remove_duplicated_disks(lists:keysort(1, Data)), - lists:foldl(fun({_Id, _Kbyte, Cap}, N) when Cap>=Threshold -> - N+1; - (_DiskData, N) -> - N - end, - 0, - Data2). + lists:foldl(fun + ({_Id, _Kbyte, Cap}, N) when Cap>=Threshold -> N+1; + (_DiskData, N) -> N + end, 0, Data2). %% On some platforms (for example MontaVista) data for one disk can be %% "duplicated": @@ -278,33 +262,30 @@ remove_duplicated_disks([]) -> []. get_alarms() -> - lists:filter(fun({{disk_almost_full, _Disk},_}) -> true; - (_) -> false - end, - alarm_handler:get_alarms()). + lists:filter(fun + ({{disk_almost_full, _Disk},_}) -> true; + (_) -> false + end, alarm_handler:get_alarms()). until(Fun, [H|T]) -> case Fun(H) of true -> H; - false -> - until(Fun, T) + false -> until(Fun, T) end; -until(_Fun, []) -> - false. +until(_Fun, []) -> false. -port(suite) -> - []; +port(suite) -> []; port(doc) -> ["Test that disksup handles a terminating port program"]; port(Config) when is_list(Config) -> - ?line Str = os:cmd("ps -ef | grep '[d]isksup'"), + Str = os:cmd("ps -ef | grep '[d]isksup'"), case io_lib:fread("~s ~s", Str) of - {ok, [_Uid,Pid], _Rest} -> + {ok, [_Uid,Pid], _Rest} -> %% Monitor disksup - ?line MonRef = erlang:monitor(process, disksup), - ?line [{_Disk1,Kbyte1,_Cap1}|_] = disksup:get_disk_data(), - ?line true = Kbyte1>0, + MonRef = erlang:monitor(process, disksup), + [{_Disk1,Kbyte1,_Cap1}|_] = disksup:get_disk_data(), + true = Kbyte1>0, %% Kill the port program case os:cmd("kill -9 " ++ Pid) of @@ -315,17 +296,16 @@ port(Config) when is_list(Config) -> {'DOWN', MonRef, _, _, {port_died, _Reason}} -> ok; {'DOWN', MonRef, _, _, Reason} -> - ?line ?t:fail({unexpected_exit_reason, Reason}) + ?t:fail({unexpected_exit_reason, Reason}) after 3000 -> - ?line ?t:fail({still_alive, Str}) + ?t:fail({still_alive, Str}) end, %% Give os_mon_sup time to restart disksup ?t:sleep(?t:seconds(3)), - ?line [{_Disk2,Kbyte2,_Cap2}|_] = - disksup:get_disk_data(), - ?line true = Kbyte2>0, + [{_Disk2,Kbyte2,_Cap2}|_] = disksup:get_disk_data(), + true = Kbyte2>0, ok; @@ -337,68 +317,61 @@ port(Config) when is_list(Config) -> {skip, {os_pid_not_found, Str}} end. -terminate(suite) -> - []; +terminate(suite) -> []; terminate(Config) when is_list(Config) -> - ?line ok = application:set_env(os_mon, start_disksup, false), - ?line ok = supervisor:terminate_child(os_mon_sup, disksup), + ok = application:set_env(os_mon, start_disksup, false), + ok = supervisor:terminate_child(os_mon_sup, disksup), ok. -unavailable(suite) -> - []; +unavailable(suite) -> []; unavailable(doc) -> ["Test correct behaviour when service is unavailable"]; unavailable(Config) when is_list(Config) -> %% Make sure all API functions return their dummy values - ?line [{"none",0,0}] = disksup:get_disk_data(), - ?line 1800000 = disksup:get_check_interval(), - ?line ok = disksup:set_check_interval(5), - ?line 80 = disksup:get_almost_full_threshold(), - ?line ok = disksup:set_almost_full_threshold(0.9), - + [{"none",0,0}] = disksup:get_disk_data(), + 1800000 = disksup:get_check_interval(), + ok = disksup:set_check_interval(5), + 80 = disksup:get_almost_full_threshold(), + ok = disksup:set_almost_full_threshold(0.9), ok. restart(suite) -> []; restart(Config) when is_list(Config) -> - ?line ok = application:set_env(os_mon, start_disksup, true), - ?line {ok, _Pid} = supervisor:restart_child(os_mon_sup, disksup), + ok = application:set_env(os_mon, start_disksup, true), + {ok, _Pid} = supervisor:restart_child(os_mon_sup, disksup), ok. -otp_5910(suite) -> - []; +otp_5910(suite) -> []; otp_5910(doc) -> ["Test that alarms are cleared if disksup crashes or " "if OS_Mon is stopped"]; otp_5910(Config) when is_list(Config) -> %% Make sure disksup sets at least one alarm - ?line Data = disksup:get_disk_data(), - ?line Threshold0 = disksup:get_almost_full_threshold(), - ?line Threshold = case over_threshold(Data, Threshold0) of - 0 -> - [{_Id,_Kbyte,Cap}|_] = Data, - ?line ok = disksup:set_almost_full_threshold((Cap-1)/100), - Cap-1; - _N -> - Threshold0 - end, - ?line ok = application:set_env(os_mon, - disk_almost_full_threshold, - Threshold/100), - ?line disksup ! timeout, % force a disk check - ?line Data2 = disksup:get_disk_data(), - ?line Over = over_threshold(Data2, Threshold), - ?line Alarms = get_alarms(), + Data = disksup:get_disk_data(), + Threshold0 = disksup:get_almost_full_threshold(), + Threshold = case over_threshold(Data, Threshold0) of + 0 -> + [{_Id,_Kbyte,Cap}|_] = Data, + ok = disksup:set_almost_full_threshold((Cap-1)/100), + Cap-1; + _N -> Threshold0 + end, + ok = application:set_env(os_mon, disk_almost_full_threshold, Threshold/100), + disksup ! timeout, % force a disk check + Data2 = disksup:get_disk_data(), + Over = over_threshold(Data2, Threshold), + Alarms = get_alarms(), if Over==0 -> - ?line ?t:fail({threshold_too_low, Data2, Threshold}); + ?t:fail({threshold_too_low, Data2, Threshold}); Over==length(Alarms) -> ok; true -> dump_info(), - ?line ?t:fail({bad_alarms, Threshold, Data2, Alarms}) + ?t:fail({bad_alarms, Threshold, Data2, Alarms}) end, %% Kill disksup @@ -407,34 +380,42 @@ otp_5910(Config) when is_list(Config) -> %% Wait a little to make sure disksup has been restarted, %% then make sure the alarms are set once, but not twice ?t:sleep(?t:seconds(1)), - ?line Data3 = disksup:get_disk_data(), - ?line Alarms2 = get_alarms(), + Data3 = disksup:get_disk_data(), + Alarms2 = get_alarms(), if - length(Alarms2)==length(Alarms) -> - ok; + length(Alarms2)==length(Alarms) -> ok; true -> dump_info(), - ?line ?t:fail({bad_alarms, Threshold, Data3, Alarms,Alarms2}) + ?t:fail({bad_alarms,Threshold,Data3,Alarms,Alarms2}) end, %% Stop OS_Mon and make sure all disksup alarms are cleared - ?line ok = application:stop(os_mon), + ok = application:stop(os_mon), ?t:sleep(?t:seconds(1)), - ?line Alarms3 = get_alarms(), - if - length(Alarms3)==0 -> - ok; - true -> - ?line ?t:fail({alarms_not_cleared, Alarms3}) + Alarms3 = get_alarms(), + case get_alarms() of + [] -> ok; + _ -> ?t:fail({alarms_not_cleared, Alarms3}) end, %% Reset threshold and restart OS_Mon - ?line ok = application:set_env(os_mon, - disksup_almost_full_threshold, 0.8), - ?line ok = disksup:set_almost_full_threshold(0.8), - ?line ok = application:start(os_mon), - + ok = application:set_env(os_mon, disksup_almost_full_threshold, 0.8), + ok = disksup:set_almost_full_threshold(0.8), + ok = application:start(os_mon), ok. dump_info() -> io:format("Status: ~p~n", [sys:get_status(disksup)]). + +% filter get_disk_data and remove entriew with zero capacity +% "non-normal" filesystems report zero capacity +% - Perhaps errorneous 'df -k -l'? +% - Always list filesystems by type '-t ufs,zfs,..' instead? +% It is unclear what the intention was from the beginning. +get_disk_data() -> + get_disk_data(disksup:get_disk_data()). + +get_disk_data([{"none",0,0}=E]) -> [E]; +get_disk_data([{_,_,0}|Es]) -> get_disk_data(Es); +get_disk_data([E|Es]) -> [E|get_disk_data(Es)]; +get_disk_data([]) -> []. diff --git a/lib/snmp/test/Makefile b/lib/snmp/test/Makefile index 546d46a002..f22b7ea8ee 100644 --- a/lib/snmp/test/Makefile +++ b/lib/snmp/test/Makefile @@ -86,7 +86,7 @@ RELSYSDIR = $(RELEASE_PATH)/snmp_test # SNMP FLAGS # ---------------------------------------------------- ifeq ($(SNMP_DEBUG),) - SNMP_DEBUG = d + # SNMP_DEBUG = d endif ifeq ($(SNMP_DEBUG),e) |