diff options
Diffstat (limited to 'lib/stdlib/test/sys_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/sys_SUITE.erl | 133 |
1 files changed, 80 insertions, 53 deletions
diff --git a/lib/stdlib/test/sys_SUITE.erl b/lib/stdlib/test/sys_SUITE.erl index 573fa6f358..fcc4419569 100644 --- a/lib/stdlib/test/sys_SUITE.erl +++ b/lib/stdlib/test/sys_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2014. All Rights Reserved. +%% Copyright Ericsson AB 1996-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. @@ -22,7 +22,7 @@ init_per_group/2,end_per_group/2,log/1,log_to_file/1, stats/1,trace/1,suspend/1,install/1,special_process/1]). -export([handle_call/3,terminate/2,init/1]). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -define(server,sys_SUITE_server). @@ -53,7 +53,6 @@ end_per_group(_GroupName, Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -log(suite) -> []; log(Config) when is_list(Config) -> {ok,_Server} = start(), ok = sys:log(?server,true), @@ -63,9 +62,8 @@ log(Config) when is_list(Config) -> stop(), ok. -log_to_file(suite) -> []; log_to_file(Config) when is_list(Config) -> - TempName = test_server:temp_name(?config(priv_dir,Config) ++ "sys."), + TempName = test_server:temp_name(proplists:get_value(priv_dir,Config) ++ "sys."), {ok,_Server} = start(), ok = sys:log_to_file(?server,TempName), {ok,-44} = public_call(44), @@ -74,20 +72,19 @@ log_to_file(Config) when is_list(Config) -> Msg1 = io:get_line(Fd,''), Msg2 = io:get_line(Fd,''), file:close(Fd), - lists:prefix("*DBG* sys_SUITE_server got call {req,44} from ",Msg1), - lists:prefix("*DBG* sys_SUITE_server sent {ok,-44} to ",Msg2), + "*DBG* sys_SUITE_server got call {req,44} from " ++ _ = Msg1, + "*DBG* sys_SUITE_server sent {ok,-44} to " ++ _ = Msg2, stop(), ok. -stats(suite) -> []; stats(Config) when is_list(Config) -> Self = self(), {ok,_Server} = start(), ok = sys:statistics(?server,true), {ok,-44} = public_call(44), {ok,Stats} = sys:statistics(?server,get), - lists:member({messages_in,1},Stats), - lists:member({messages_out,1},Stats), + true = lists:member({messages_in,1}, Stats), + true = lists:member({messages_out,1}, Stats), ok = sys:statistics(?server,false), {status,_Pid,{module,_Mod},[_PDict,running,Self,_,_]} = sys:get_status(?server), @@ -95,43 +92,40 @@ stats(Config) when is_list(Config) -> stop(), ok. -trace(suite) -> []; trace(Config) when is_list(Config) -> {ok,_Server} = start(), - test_server:sleep(2000), - test_server:capture_start(), + ct:sleep(2000), + ct:capture_start(), sys:trace(?server,true), {ok,-44} = public_call(44), %% ho, hum, allow for the io to reach us.. - test_server:sleep(1000), - test_server:capture_stop(), - [Msg1,Msg2] = test_server:capture_get(), - lists:prefix("*DBG* sys_SUITE_server got call {req,44} from ",Msg1), - lists:prefix("*DBG* sys_SUITE_server sent {ok,-44} to ",Msg2), + ct:sleep(1000), + ct:capture_stop(), + [Msg1,Msg2] = ct:capture_get(), + "*DBG* sys_SUITE_server got call {req,44} from " ++ _ = Msg1, + "*DBG* sys_SUITE_server sent {ok,-44} to " ++ _ = Msg2, stop(), ok. -suspend(suite) -> []; suspend(Config) when is_list(Config) -> - ?line {ok,_Server} = start(), - ?line sys:suspend(?server,1000), - ?line {'EXIT',_} = (catch public_call(48)), - ?line {status,_,_,[_,suspended,_,_,_]} = sys:get_status(?server), - ?line sys:suspend(?server,1000), %% doing it twice is no error - ?line {'EXIT',_} = (catch public_call(48)), - ?line sys:resume(?server), - ?line {status,_,_,[_,running,_,_,_]} = sys:get_status(?server), - ?line {ok,-48} = (catch public_call(48)), - ?line sys:resume(?server), %% doing it twice is no error - ?line {ok,-48} = (catch public_call(48)), - ?line stop(), + {ok,_Server} = start(), + sys:suspend(?server,1000), + {'EXIT',_} = (catch public_call(48)), + {status,_,_,[_,suspended,_,_,_]} = sys:get_status(?server), + sys:suspend(?server,1000), %% doing it twice is no error + {'EXIT',_} = (catch public_call(48)), + sys:resume(?server), + {status,_,_,[_,running,_,_,_]} = sys:get_status(?server), + {ok,-48} = (catch public_call(48)), + sys:resume(?server), %% doing it twice is no error + {ok,-48} = (catch public_call(48)), + stop(), ok. -install(suite) -> []; install(Config) when is_list(Config) -> - ?line {ok,_Server} = start(), - ?line Master = self(), - ?line SpyFun = + {ok,_Server} = start(), + Master = self(), + SpyFun = fun(func_state,Event,ProcState) -> case Event of {in,{'$gen_call',_From,{req,Arg}}} -> @@ -139,24 +133,46 @@ install(Config) when is_list(Config) -> Master ! {spy_got,{request,Arg},ProcState}; Other -> io:format("Trigged other=~p\n",[Other]) - end + end, + func_state end, - ?line sys:install(?server,{SpyFun,func_state}), - ?line {ok,-1} = (catch public_call(1)), - ?line sys:no_debug(?server), - ?line {ok,-2} = (catch public_call(2)), - ?line sys:install(?server,{SpyFun,func_state}), - ?line sys:install(?server,{SpyFun,func_state}), - ?line {ok,-3} = (catch public_call(3)), - ?line sys:remove(?server,SpyFun), - ?line {ok,-4} = (catch public_call(4)), - ?line Msgs = test_server:messages_get(), - ?line [{spy_got,{request,1},sys_SUITE_server}, - {spy_got,{request,3},sys_SUITE_server}] = Msgs, - ?line stop(), + sys:install(?server,{SpyFun,func_state}), + {ok,-1} = (catch public_call(1)), + sys:no_debug(?server), + {ok,-2} = (catch public_call(2)), + sys:install(?server,{SpyFun,func_state}), + sys:install(?server,{SpyFun,func_state}), + {ok,-3} = (catch public_call(3)), + {ok,-4} = (catch public_call(4)), + sys:remove(?server,SpyFun), + {ok,-5} = (catch public_call(5)), + [{spy_got,{request,1},sys_SUITE_server}, + {spy_got,{request,3},sys_SUITE_server}, + {spy_got,{request,4},sys_SUITE_server}] = get_messages(), + + sys:install(?server,{id1, SpyFun, func_state}), + sys:install(?server,{id1, SpyFun, func_state}), %% should not be installed + sys:install(?server,{id2, SpyFun, func_state}), + {ok,-1} = (catch public_call(1)), + %% We have two SpyFun installed: + [{spy_got,{request,1},sys_SUITE_server}, + {spy_got,{request,1},sys_SUITE_server}] = get_messages(), + sys:remove(?server, id1), + {ok,-1} = (catch public_call(1)), + %% We have one SpyFun installed: + [{spy_got,{request,1},sys_SUITE_server}] = get_messages(), + sys:no_debug(?server), + {ok,-1} = (catch public_call(1)), + [] = get_messages(), + stop(), ok. -special_process(suite) -> []; +get_messages() -> + receive + Msg -> [Msg|get_messages()] + after 1 -> [] + end. + special_process(Config) when is_list(Config) -> ok = spec_proc(sys_sp1), ok = spec_proc(sys_sp2). @@ -203,7 +219,7 @@ spec_proc(Mod) -> {Mod,system_get_state},{throw,fail}},_}} -> ok end, - ok = sys:terminate(Mod, normal), + ok = sync_terminate(Mod), {ok,_} = Mod:start_link(4), ok = case catch sys:replace_state(Mod, fun(_) -> {} end) of {} -> @@ -212,7 +228,7 @@ spec_proc(Mod) -> {Mod,system_replace_state},{throw,fail}},_}} -> ok end, - ok = sys:terminate(Mod, normal), + ok = sync_terminate(Mod), {ok,_} = Mod:start_link(4), StateFun = fun(_) -> error(fail) end, ok = case catch sys:replace_state(Mod, StateFun) of @@ -224,7 +240,18 @@ spec_proc(Mod) -> {'EXIT',{{callback_failed,StateFun,{error,fail}},_}} -> ok end, - ok = sys:terminate(Mod, normal). + ok = sync_terminate(Mod). + +sync_terminate(Mod) -> + P = whereis(Mod), + MRef = erlang:monitor(process,P), + ok = sys:terminate(Mod, normal), + receive + {'DOWN',MRef,_,_,normal} -> + ok + end, + undefined = whereis(Mod), + ok. %%%%%%%%%%%%%%%%%%%% %% Dummy server |