aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPeter Andersson <[email protected]>2013-09-02 11:45:24 +0200
committerPeter Andersson <[email protected]>2013-09-02 11:45:24 +0200
commita2d3e57f475b391f9e338503a2a5eead78930e5d (patch)
treef51b67cc6787073569b4a4c9ec1b4610bda849d0 /lib
parent6144fd582667642fdacba8018eef464a780aba17 (diff)
parent517879c44e0703b69fe8fc4499e656a318cd1a85 (diff)
downloadotp-a2d3e57f475b391f9e338503a2a5eead78930e5d.tar.gz
otp-a2d3e57f475b391f9e338503a2a5eead78930e5d.tar.bz2
otp-a2d3e57f475b391f9e338503a2a5eead78930e5d.zip
Merge branch 'maint'
Diffstat (limited to 'lib')
-rw-r--r--lib/common_test/src/cth_log_redirect.erl120
-rw-r--r--lib/test_server/src/Makefile1
-rw-r--r--lib/test_server/src/test_server.app.src1
-rw-r--r--lib/test_server/src/test_server.erl1
-rw-r--r--lib/test_server/src/test_server_ctrl.erl12
-rw-r--r--lib/test_server/src/test_server_h.erl148
6 files changed, 109 insertions, 174 deletions
diff --git a/lib/common_test/src/cth_log_redirect.erl b/lib/common_test/src/cth_log_redirect.erl
index 83fc879967..a030701f19 100644
--- a/lib/common_test/src/cth_log_redirect.erl
+++ b/lib/common_test/src/cth_log_redirect.erl
@@ -25,8 +25,11 @@
%% CTH Callbacks
--export([id/1, init/2, post_init_per_group/4, pre_end_per_group/3,
- post_end_per_testcase/4]).
+-export([id/1, init/2,
+ pre_init_per_suite/3, pre_end_per_suite/3, post_end_per_suite/4,
+ pre_init_per_group/3, post_init_per_group/4,
+ pre_end_per_group/3, post_end_per_group/4,
+ pre_init_per_testcase/3, post_end_per_testcase/4]).
%% Event handler Callbacks
-export([init/1,
@@ -35,6 +38,12 @@
-include("ct.hrl").
+-record(eh_state, {log_func,
+ curr_suite,
+ curr_group,
+ curr_func,
+ parallel_tcs = false}).
+
id(_Opts) ->
?MODULE.
@@ -42,6 +51,23 @@ init(?MODULE, _Opts) ->
error_logger:add_report_handler(?MODULE),
tc_log_async.
+
+pre_init_per_suite(Suite, Config, State) ->
+ set_curr_func({Suite,init_per_suite}, Config),
+ {Config, State}.
+
+pre_end_per_suite(Suite, Config, State) ->
+ set_curr_func({Suite,end_per_suite}, Config),
+ {Config, State}.
+
+post_end_per_suite(_Suite, Config, Return, State) ->
+ set_curr_func(undefined, Config),
+ {Return, State}.
+
+pre_init_per_group(Group, Config, State) ->
+ set_curr_func({group,Group,init_per_group}, Config),
+ {Config, State}.
+
post_init_per_group(Group, Config, Result, tc_log_async) ->
case lists:member(parallel,proplists:get_value(
tc_group_properties,Config,[])) of
@@ -53,6 +79,10 @@ post_init_per_group(Group, Config, Result, tc_log_async) ->
post_init_per_group(_Group, _Config, Result, State) ->
{Result, State}.
+pre_init_per_testcase(TC, Config, State) ->
+ set_curr_func(TC, Config),
+ {Config, State}.
+
post_end_per_testcase(_TC, _Config, Result, State) ->
%% Make sure that the event queue is flushed
%% before ending this test case.
@@ -60,18 +90,23 @@ post_end_per_testcase(_TC, _Config, Result, State) ->
{Result, State}.
pre_end_per_group(Group, Config, {tc_log, Group}) ->
+ set_curr_func({group,Group,end_per_group}, Config),
{Config, set_log_func(tc_log_async)};
-pre_end_per_group(_Group, Config, State) ->
+pre_end_per_group(Group, Config, State) ->
+ set_curr_func({group,Group,end_per_group}, Config),
{Config, State}.
+post_end_per_group(_Group, Config, Return, State) ->
+ set_curr_func({group,undefined}, Config),
+ {Return, State}.
%% Copied and modified from sasl_report_tty_h.erl
init(_Type) ->
- {ok, tc_log_async}.
+ {ok, #eh_state{log_func = tc_log_async}}.
handle_event({_Type, GL, _Msg}, State) when node(GL) /= node() ->
{ok, State};
-handle_event(Event, LogFunc) ->
+handle_event(Event, #eh_state{log_func = LogFunc} = State) ->
case lists:keyfind(sasl, 1, application:which_applications()) of
false ->
sasl_not_started;
@@ -80,7 +115,8 @@ handle_event(Event, LogFunc) ->
SReport = sasl_report:format_report(group_leader(), ErrLogType,
tag_event(Event)),
if is_list(SReport) ->
- ct_logs:LogFunc(sasl, ?STD_IMPORTANCE, "System", SReport, []);
+ SaslHeader = format_header(State),
+ ct_logs:LogFunc(sasl, ?STD_IMPORTANCE, SaslHeader, SReport, []);
true -> %% Report is an atom if no logging is to be done
ignore
end
@@ -88,20 +124,47 @@ handle_event(Event, LogFunc) ->
EReport = error_logger_tty_h:write_event(
tag_event(Event),io_lib),
if is_list(EReport) ->
- ct_logs:LogFunc(error_logger, ?STD_IMPORTANCE, "System", EReport, []);
+ ErrHeader = format_header(State),
+ ct_logs:LogFunc(error_logger, ?STD_IMPORTANCE, ErrHeader, EReport, []);
true -> %% Report is an atom if no logging is to be done
ignore
end,
- {ok, LogFunc}.
+ {ok, State}.
handle_info(_,State) -> {ok, State}.
handle_call(flush,State) ->
{ok, ok, State};
-handle_call({set_logfunc,NewLogFunc},_) ->
- {ok, NewLogFunc, NewLogFunc};
-handle_call(_Query, _State) -> {error, bad_query}.
+
+handle_call({set_curr_func,{group,Group,Conf},Config}, State) ->
+ Parallel = case proplists:get_value(tc_group_properties, Config) of
+ undefined -> false;
+ Props -> lists:member(parallel, Props)
+ end,
+ {ok, ok, State#eh_state{curr_group = Group,
+ curr_func = Conf,
+ parallel_tcs = Parallel}};
+handle_call({set_curr_func,{group,undefined},_Config}, State) ->
+ {ok, ok, State#eh_state{curr_group = undefined,
+ curr_func = undefined,
+ parallel_tcs = false}};
+handle_call({set_curr_func,{Suite,Conf},_Config}, State) ->
+ {ok, ok, State#eh_state{curr_suite = Suite,
+ curr_func = Conf,
+ parallel_tcs = false}};
+handle_call({set_curr_func,undefined,_Config}, State) ->
+ {ok, ok, State#eh_state{curr_suite = undefined,
+ curr_func = undefined,
+ parallel_tcs = false}};
+handle_call({set_curr_func,TC,_Config}, State) ->
+ {ok, ok, State#eh_state{curr_func = TC}};
+
+handle_call({set_logfunc,NewLogFunc},State) ->
+ {ok, NewLogFunc, State#eh_state{log_func = NewLogFunc}};
+
+handle_call(_Query, _State) ->
+ {error, bad_query}.
terminate(_State) ->
error_logger:delete_report_handler(?MODULE),
@@ -110,5 +173,40 @@ terminate(_State) ->
tag_event(Event) ->
{calendar:local_time(), Event}.
+set_curr_func(CurrFunc, Config) ->
+ gen_event:call(error_logger, ?MODULE, {set_curr_func, CurrFunc, Config}).
+
set_log_func(Func) ->
gen_event:call(error_logger, ?MODULE, {set_logfunc, Func}).
+
+%%%-----------------------------------------------------------------
+
+format_header(#eh_state{curr_suite = Suite,
+ curr_group = undefined,
+ curr_func = undefined}) ->
+ io_lib:format("System report during ~w", [Suite]);
+
+format_header(#eh_state{curr_suite = Suite,
+ curr_group = undefined,
+ curr_func = TcOrConf}) ->
+ io_lib:format("System report during ~w:~w/1",
+ [Suite,TcOrConf]);
+
+format_header(#eh_state{curr_suite = Suite,
+ curr_group = Group,
+ curr_func = Conf}) when Conf == init_per_group;
+ Conf == end_per_group ->
+ io_lib:format("System report during ~w:~w/2 for ~w",
+ [Suite,Conf,Group]);
+
+format_header(#eh_state{curr_suite = Suite,
+ curr_group = Group,
+ parallel_tcs = true}) ->
+ io_lib:format("System report during ~w in ~w",
+ [Group,Suite]);
+
+format_header(#eh_state{curr_suite = Suite,
+ curr_group = Group,
+ curr_func = TC}) ->
+ io_lib:format("System report during ~w:~w/1 in ~w",
+ [Suite,TC,Group]).
diff --git a/lib/test_server/src/Makefile b/lib/test_server/src/Makefile
index ebc5f5b71b..ab4dd4d95d 100644
--- a/lib/test_server/src/Makefile
+++ b/lib/test_server/src/Makefile
@@ -45,7 +45,6 @@ MODULES= test_server_ctrl \
test_server_node \
test_server \
test_server_sup \
- test_server_h \
erl2html2
TS_MODULES= \
diff --git a/lib/test_server/src/test_server.app.src b/lib/test_server/src/test_server.app.src
index 163f370a47..42e78ed279 100644
--- a/lib/test_server/src/test_server.app.src
+++ b/lib/test_server/src/test_server.app.src
@@ -23,7 +23,6 @@
erl2html2,
test_server_ctrl,
test_server,
- test_server_h,
test_server_io,
test_server_node,
test_server_sup
diff --git a/lib/test_server/src/test_server.erl b/lib/test_server/src/test_server.erl
index c350f758ce..6ddb2b615f 100644
--- a/lib/test_server/src/test_server.erl
+++ b/lib/test_server/src/test_server.erl
@@ -389,7 +389,6 @@ run_test_case_apply({CaseNum,Mod,Func,Args,Name,
os:putenv("VALGRIND_LOGFILE_INFIX",atom_to_list(Mod)++"."++
atom_to_list(Func)++"-")
end,
- test_server_h:testcase({Mod,Func,1}),
ProcBef = erlang:system_info(process_count),
Result = run_test_case_apply(Mod, Func, Args, Name, RunInit,
TimetrapData),
diff --git a/lib/test_server/src/test_server_ctrl.erl b/lib/test_server/src/test_server_ctrl.erl
index ffa21d054c..4a10684ea5 100644
--- a/lib/test_server/src/test_server_ctrl.erl
+++ b/lib/test_server/src/test_server_ctrl.erl
@@ -479,12 +479,6 @@ init([]) ->
test_server_sup:call_trace(TraceSpec)
end,
process_flag(trap_exit, true),
- case lists:keysearch(sasl, 1, application:which_applications()) of
- {value,_} ->
- test_server_h:install();
- false ->
- ok
- end,
%% copy format_exception setting from init arg to application environment
case init:get_argument(test_server_format_exception) of
{ok,[[TSFE]]} ->
@@ -1067,12 +1061,6 @@ terminate(_Reason, State) ->
end,
kill_all_jobs(State#state.jobs),
test_server_node:kill_nodes(),
- case lists:keysearch(sasl, 1, application:which_applications()) of
- {value,_} ->
- test_server_h:restore();
- _ ->
- ok
- end,
ok.
kill_all_jobs([{_Name,JobPid}|Jobs]) ->
diff --git a/lib/test_server/src/test_server_h.erl b/lib/test_server/src/test_server_h.erl
deleted file mode 100644
index 24063ddb10..0000000000
--- a/lib/test_server/src/test_server_h.erl
+++ /dev/null
@@ -1,148 +0,0 @@
-%%
-%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2005-2013. 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(test_server_h).
--behaviour(gen_event).
-
-%% API
--export([install/0, restore/0]).
--export([testcase/1]).
-
-%% gen_event callbacks
--export([init/1, handle_event/2, handle_call/2,
- handle_info/2, terminate/2, code_change/3]).
-
--record(state, {kernel, sasl, testcase}).
-
-%%====================================================================
-%% API
-%%====================================================================
-
-install() ->
- case gen_event:add_handler(error_logger, ?MODULE, []) of
- ok ->
- error_logger:delete_report_handler(sasl_report_tty_h),
- gen_event:delete_handler(error_logger, error_logger_tty_h, []),
- ok;
- Error ->
- Error
- end.
-
-restore() ->
- gen_event:add_handler(error_logger, error_logger_tty_h, []),
- error_logger:add_report_handler(sasl_report_tty_h, all),
- gen_event:delete_handler(error_logger, ?MODULE, []).
-
-testcase(Testcase) ->
- gen_event:call(error_logger, ?MODULE, {set_testcase, Testcase}, 10*60*1000).
-
-%%====================================================================
-%% gen_event callbacks
-%%====================================================================
-
-init([]) ->
-
- %% error_logger_tty_h initialization
- User = set_group_leader(),
-
- %% sasl_report_tty_h initialization
- Type = all,
-
- {ok, #state{kernel={User, []}, sasl=Type}}.
-
-set_group_leader() ->
- case whereis(user) of
- User when is_pid(User) ->
- link(User),
- group_leader(User, self()),
- User;
- _ ->
- false
- end.
-
-handle_event({_Type, GL, _Msg}, State) when node(GL)/=node() ->
- {ok, State};
-handle_event({Tag, _GL, {_Pid, Type, _Report}} = Event, State) ->
- SASL = lists:keyfind(sasl, 1, application:which_applications()),
- case report_receiver(Tag, Type) of
- sasl when SASL /= false ->
- {ok,ErrLogType} = application:get_env(sasl, errlog_type),
- SReport = sasl_report:format_report(group_leader(), ErrLogType,
- tag_event(Event)),
- if is_list(SReport) ->
- tag(State#state.testcase),
- sasl_report_tty_h:handle_event(Event,
- State#state.sasl);
- true -> %% Report is an atom if no logging is to be done
- ignore
- end;
- sasl -> %% SASL not running
- ignore;
- kernel ->
- tag(State#state.testcase),
- error_logger_tty_h:handle_event(Event, State#state.kernel);
- none ->
- ignore
- end,
- {ok, State};
-handle_event(_Event, State) ->
- {ok, State}.
-
-handle_call({set_testcase, Testcase}, State) ->
- {ok, ok, State#state{testcase=Testcase}};
-handle_call(_Query, _State) ->
- {error, bad_query}.
-
-handle_info({emulator,GL,_Chars}=Event, State) when node(GL)==node() ->
- tag(State#state.testcase),
- error_logger_tty_h:handle_info(Event, State#state.kernel),
- {ok, State};
-handle_info(_Msg, State) ->
- {ok, State}.
-
-terminate(_Reason, _State) ->
- ok.
-
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-report_receiver(error_report, supervisor_report) -> sasl;
-report_receiver(error_report, crash_report) -> sasl;
-report_receiver(info_report, progress) -> sasl;
-report_receiver(error, _) -> kernel;
-report_receiver(error_report, _) -> kernel;
-report_receiver(warning_msg, _) -> kernel;
-report_receiver(warning_report, _) -> kernel;
-report_receiver(info, _) -> kernel;
-report_receiver(info_msg, _) -> kernel;
-report_receiver(info_report,Tuple)
- when is_tuple(Tuple) andalso
- (element(1,Tuple)==ct_connection orelse
- element(1,Tuple)==conn_log) ->
- none;
-report_receiver(info_report, _) -> kernel;
-report_receiver(_, _) -> none.
-
-tag({M,F,A}) when is_atom(M), is_atom(F), is_integer(A) ->
- io:format(user, "~n=TESTCASE: ~w:~w/~w", [M,F,A]);
-tag(Testcase) ->
- io:format(user, "~n=TESTCASE: ~p", [Testcase]).
-
-tag_event(Event) ->
- {calendar:local_time(), Event}.