From 8a0a09ef168210326b29273b20520aee339aaf40 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Thu, 27 Jun 2013 23:29:16 +0200 Subject: Allow calls to ct:pal and ct:print even if CT is not running Also make sure calls to ct:log and ct:pal don't cause crash if test_server is not running (could happen during startup or shutdown of CT). OTP-11176 --- lib/common_test/src/ct_logs.erl | 12 +++++++++++- lib/common_test/src/ct_util.erl | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'lib/common_test') diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index f5355bfefe..d80de889ca 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -446,6 +446,8 @@ tc_print(Category,Importance,Format,Args) -> ct_util:get_verbosity('$unspecified'); {error,bad_invocation} -> ?MAX_VERBOSITY; + {error,_Failure} -> + ?MAX_VERBOSITY; Val -> Val end, @@ -3072,4 +3074,12 @@ unexpected_io(Pid,ct_internal,List,#logger_state{ct_log_fd=Fd}=State) -> unexpected_io(Pid,_Category,List,State) -> IoFun = create_io_fun(Pid,State), Data = io_lib:format("~ts", [lists:foldl(IoFun, [], List)]), - test_server_io:print_unexpected(Data). + %% if unexpected io comes in during startup or shutdown, test_server + %% might not be running - if so (noproc exit), simply ignore the printout + try test_server_io:print_unexpected(Data) of + _ -> + ok + catch + _:{noproc,_} -> ok; + _:Reason -> exit(Reason) + end. diff --git a/lib/common_test/src/ct_util.erl b/lib/common_test/src/ct_util.erl index 68e76c2396..abda87c2cd 100644 --- a/lib/common_test/src/ct_util.erl +++ b/lib/common_test/src/ct_util.erl @@ -286,14 +286,23 @@ get_start_dir() -> %% handle verbosity outside ct_util_server (let the client read %% the verbosity table) to avoid possible deadlock situations set_verbosity(Elem = {_Category,_Level}) -> - ets:insert(?verbosity_table, Elem), - ok. + try ets:insert(?verbosity_table, Elem) of + _ -> + ok + catch + _:Reason -> + {error,Reason} + end. + get_verbosity(Category) -> - case ets:lookup(?verbosity_table, Category) of + try ets:lookup(?verbosity_table, Category) of [{Category,Level}] -> Level; _ -> undefined + catch + _:Reason -> + {error,Reason} end. loop(Mode,TestData,StartDir) -> -- cgit v1.2.3 From 1151a45d49e90383931c92433b15b754156b833d Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Fri, 28 Jun 2013 01:00:24 +0200 Subject: Add test OTP-11176 --- lib/common_test/test/ct_test_support.erl | 14 ++++++++++---- lib/common_test/test/ct_verbosity_SUITE.erl | 26 +++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) (limited to 'lib/common_test') diff --git a/lib/common_test/test/ct_test_support.erl b/lib/common_test/test/ct_test_support.erl index 6bcac12326..4132995bf6 100644 --- a/lib/common_test/test/ct_test_support.erl +++ b/lib/common_test/test/ct_test_support.erl @@ -36,6 +36,8 @@ verify_events/3, verify_events/4, reformat/2, log_events/4, join_abs_dirs/2]). +-export([start_slave/3, slave_stop/1]). + -export([ct_test_halt/1]). -include_lib("kernel/include/file.hrl"). @@ -66,10 +68,14 @@ init_per_suite(Config, Level) -> start_slave(Config, Level). -start_slave(Config,Level) -> +start_slave(Config, Level) -> + start_slave(ct, Config, Level). + +start_slave(NodeName, Config, Level) -> [_,Host] = string:tokens(atom_to_list(node()), "@"), - test_server:format(0, "Trying to start ~s~n", ["ct@"++Host]), - case slave:start(Host, ct, []) of + test_server:format(0, "Trying to start ~s~n", + [atom_to_list(NodeName)++"@"++Host]), + case slave:start(Host, NodeName, []) of {error,Reason} -> test_server:fail(Reason); {ok,CTNode} -> @@ -77,7 +83,7 @@ start_slave(Config,Level) -> IsCover = test_server:is_cover(), if IsCover -> cover:start(CTNode); - true-> + true -> ok end, diff --git a/lib/common_test/test/ct_verbosity_SUITE.erl b/lib/common_test/test/ct_verbosity_SUITE.erl index 32488b1db9..1aa71953ec 100644 --- a/lib/common_test/test/ct_verbosity_SUITE.erl +++ b/lib/common_test/test/ct_verbosity_SUITE.erl @@ -53,9 +53,19 @@ init_per_suite(Config) -> end_per_suite(Config) -> ct_test_support:end_per_suite(Config). +init_per_testcase(no_crashing, Config) -> + Opts = ct_test_support:start_slave(ctX, Config, 50), + XNode = proplists:get_value(ct_node, Opts), + ct:pal("Node ~p started!", [XNode]), + [{xnode,XNode} | Config]; init_per_testcase(TestCase, Config) -> ct_test_support:init_per_testcase(TestCase, Config). +end_per_testcase(no_crashing, Config) -> + XNode = proplists:get_value(xnode, Config), + ct_test_support:slave_stop(XNode), + ct:pal("Node ~p stopped!", [XNode]), + ok; end_per_testcase(TestCase, Config) -> ct_test_support:end_per_testcase(TestCase, Config). @@ -72,7 +82,8 @@ all() -> combine_categories, testspec_only, merge_with_testspec, - possible_deadlock + possible_deadlock, + no_crashing ]. %%-------------------------------------------------------------------- @@ -188,6 +199,19 @@ possible_deadlock(Config) -> ok = execute(TC, Opts, ERPid, Config). +%%%----------------------------------------------------------------- +%%% +no_crashing(Config) -> + XNode = proplists:get_value(xnode, Config), + ok = rpc:call(XNode, ct, print, ["hello",[]]), + ok = rpc:call(XNode, ct, pal, ["hello",[]]), + ok = rpc:call(XNode, ct, log, ["hello",[]]), + Data = io_lib:format("hello", []), + {badrpc,{'EXIT',{noproc,_}}} = + (catch rpc:call(XNode, test_server_io, print_unexpected, [Data])), + ok. + + %%%----------------------------------------------------------------- %%% HELP FUNCTIONS %%%----------------------------------------------------------------- -- cgit v1.2.3 From ac887c1fab12ab3c2502489cb747b08daa2214ea Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Fri, 28 Jun 2013 16:26:24 +0200 Subject: Make the CT logger print to stdout if test_server is not running OTP-11176 --- lib/common_test/src/ct_logs.erl | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'lib/common_test') diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index d80de889ca..bd37b690b6 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -692,14 +692,15 @@ logger_loop(State) -> false -> %% Group leader is dead, so write to the %% CtLog or unexpected_io log instead - unexpected_io(Pid,Category,List,State), + unexpected_io(Pid,Category,Importance, + List,State), logger_loop(State) end; {ct_log,_Fd,TCGLs} -> %% If category is ct_internal then write %% to ct_log, else write to unexpected_io %% log - unexpected_io(Pid,Category,List,State), + unexpected_io(Pid,Category,Importance,List,State), logger_loop(State#logger_state{ tc_groupleaders = TCGLs}) end; @@ -800,7 +801,7 @@ print_to_log(sync, FromPid, Category, TCGL, List, State) -> IoFun = create_io_fun(FromPid, State), io:format(TCGL,"~ts", [lists:foldl(IoFun, [], List)]); true -> - unexpected_io(FromPid,Category,List,State) + unexpected_io(FromPid,Category,?MAX_IMPORTANCE,List,State) end, State; @@ -816,7 +817,8 @@ print_to_log(async, FromPid, Category, TCGL, List, State) -> end; true -> fun() -> - unexpected_io(FromPid,Category,List,State) + unexpected_io(FromPid,Category,?MAX_IMPORTANCE, + List,State) end end, case State#logger_state.async_print_jobs of @@ -3068,18 +3070,20 @@ html_encoding(latin1) -> html_encoding(utf8) -> "utf-8". -unexpected_io(Pid,ct_internal,List,#logger_state{ct_log_fd=Fd}=State) -> +unexpected_io(Pid,ct_internal,_Importance,List,State) -> IoFun = create_io_fun(Pid,State), - io:format(Fd, "~ts", [lists:foldl(IoFun, [], List)]); -unexpected_io(Pid,_Category,List,State) -> + io:format(State#logger_state.ct_log_fd, "~ts", + [lists:foldl(IoFun, [], List)]); +unexpected_io(Pid,Category,Importance,List,State) -> IoFun = create_io_fun(Pid,State), Data = io_lib:format("~ts", [lists:foldl(IoFun, [], List)]), %% if unexpected io comes in during startup or shutdown, test_server - %% might not be running - if so (noproc exit), simply ignore the printout + %% might not be running - if so (noproc exit), simply print to + %% stdout instead (will result in double printouts when pal is used) try test_server_io:print_unexpected(Data) of _ -> ok catch - _:{noproc,_} -> ok; + _:{noproc,_} -> tc_print(Category,Importance,Data,[]); _:Reason -> exit(Reason) end. -- cgit v1.2.3