aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test
diff options
context:
space:
mode:
authorPeter Andersson <[email protected]>2014-01-28 19:01:07 +0100
committerPeter Andersson <[email protected]>2014-01-28 19:04:05 +0100
commitc5079569ec2c6248f702b15c0e95def24411ca3c (patch)
tree079676231cc56b295f57dc48947fc8502f08e79d /lib/common_test
parent95a574b3620ec3d7420c7807b2d84f4602512229 (diff)
downloadotp-c5079569ec2c6248f702b15c0e95def24411ca3c.tar.gz
otp-c5079569ec2c6248f702b15c0e95def24411ca3c.tar.bz2
otp-c5079569ec2c6248f702b15c0e95def24411ca3c.zip
Fix remaining problems using raw telnet logging for parallel test cases
Diffstat (limited to 'lib/common_test')
-rw-r--r--lib/common_test/src/ct_conn_log_h.erl26
-rw-r--r--lib/common_test/src/ct_telnet.erl101
-rw-r--r--lib/common_test/src/cth_conn_log.erl17
-rw-r--r--lib/common_test/test/ct_telnet_SUITE.erl10
-rw-r--r--lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl11
5 files changed, 120 insertions, 45 deletions
diff --git a/lib/common_test/src/ct_conn_log_h.erl b/lib/common_test/src/ct_conn_log_h.erl
index 2b83ff1abb..d733df27dc 100644
--- a/lib/common_test/src/ct_conn_log_h.erl
+++ b/lib/common_test/src/ct_conn_log_h.erl
@@ -39,36 +39,34 @@
init({GL,ConnLogs}) ->
open_files(GL,ConnLogs,#state{default_gl=GL}).
-open_files(GL,[{ConnMod,{LogType,ConnLogs}}|T],State) ->
- case do_open_files(GL,ConnLogs,[]) of
+open_files(GL,[{ConnMod,{LogType,LogFiles}}|T],State=#state{logs=Logs}) ->
+ case do_open_files(LogFiles,[]) of
{ok,Fds} ->
- open_files(GL,T,State#state{logs=[{GL,[{ConnMod,{LogType,Fds}}]} |
- State#state.logs]});
+ ConnInfo = proplists:get_value(GL,Logs,[]),
+ Logs1 = [{GL,[{ConnMod,{LogType,Fds}}|ConnInfo]} |
+ proplists:delete(GL,Logs)],
+ open_files(GL,T,State#state{logs=Logs1});
Error ->
Error
end;
open_files(_GL,[],State) ->
{ok,State}.
-do_open_files(GL,[{Tag,File}|ConnLogs],Acc) ->
+do_open_files([{Tag,File}|LogFiles],Acc) ->
case file:open(File, [write,append,{encoding,utf8}]) of
{ok,Fd} ->
- do_open_files(GL,ConnLogs,[{Tag,Fd}|Acc]);
+ do_open_files(LogFiles,[{Tag,Fd}|Acc]);
{error,Reason} ->
{error,{could_not_open_log,File,Reason}}
end;
-do_open_files(_GL,[],Acc) ->
+do_open_files([],Acc) ->
{ok,lists:reverse(Acc)}.
handle_event({info_report,_,{From,update,{GL,ConnLogs}}},
State) when node(GL) == node() ->
-
- %%! --- Tue Jan 28 12:18:50 2014 --- peppe was here!
- io:format(user, "!!! ADDING NEW LOGS FOR ~p~n", [GL]),
-
- open_files(GL,ConnLogs,#state{}),
+ Result = open_files(GL,ConnLogs,State),
From ! {updated,GL},
- {ok, State};
+ Result;
handle_event({_Type, GL, _Msg}, State) when node(GL) /= node() ->
{ok, State};
handle_event({_Type,GL,{Pid,{ct_connection,Mod,Action,ConnName},Report}},
@@ -126,7 +124,7 @@ write_error(Time,#conn_log{module=ConnMod}=Info,Report,GL,State) ->
end.
get_log(Info,GL,State) ->
- case proplists:get_value(GL, State#state.logs) of
+ case proplists:get_value(GL,State#state.logs) of
undefined ->
{html,State#state.default_gl};
ConnLogs ->
diff --git a/lib/common_test/src/ct_telnet.erl b/lib/common_test/src/ct_telnet.erl
index f9dd62ee37..698915b37c 100644
--- a/lib/common_test/src/ct_telnet.erl
+++ b/lib/common_test/src/ct_telnet.erl
@@ -42,7 +42,106 @@
%%% <p>Enter the <code>telnet_settings</code> term in a configuration
%%% file included in the test and ct_telnet will retrieve the information
%%% automatically. Note that <c>keep_alive</c> may be specified per connection if
-%%% required. See <c>unix_telnet</c> for details.</p></doc>
+%%% required. See <c>unix_telnet</c> for details.</p>
+%%%
+%%% @end
+%%%
+%%% == Logging ==
+%%%
+%%% `ct_telnet' can be configured to uses the `error_logger' for logging telnet
+%%% traffic. A special purpose error handler is implemented in
+%%% `ct_conn_log_h'. To use this error handler, add the `cth_conn_log'
+%%% hook in your test suite, e.g.
+%%%
+%%%
+%%% ```
+%%% suite() ->
+%%% [{ct_hooks, [{cth_conn_log, [{conn_mod(),hook_options()}]}]}].
+%%%'''
+%%%
+%%% `conn_mod()' is the name of the common_test module implementing
+%%% the connection protocol, i.e. `ct_telnet'.
+%%%
+%%% The hook option `log_type' specifies the type of logging:
+%%%
+%%% <dl>
+%%% <dt>`raw'</dt>
+%%% <dd>The sent and received telnet data is logged to a separate
+%%% text file as is without any formatting. A link to the file is
+%%% added to the test case HTML log.</dd>
+%%%
+%%% <dt>`html (default)'</dt>
+%%% <dd>The sent and received telnet traffic is pretty printed
+%%% directly in the test case HTML log.</dd>
+%%%
+%%% <dt>`silent'</dt>
+%%% <dd>Telnet traffic is not logged.</dd>
+%%% </dl>
+%%%
+%%% By default, all telnet traffic is logged in one single log
+%%% file. However, it is possible to have different connections logged
+%%% in separate files. To do this, use the hook option `hosts' and
+%%% list the names of the servers/connections that will be used in the
+%%% suite. Note that the connections must be named for this to work.
+%%%
+%%% The `hosts' option has no effect if `log_type' is set to `html' or
+%%% `silent'.
+%%%
+%%% The hook options can also be specified in a configuration file with
+%%% the configuration variable `ct_conn_log':
+%%%
+%%% ```
+%%% {ct_conn_log,[{conn_mod(),hook_options()}]}.
+%%% '''
+%%%
+%%% For example:
+%%
+%%% ```
+%%% {ct_conn_log,[{ct_telnet,[{log_type,raw},
+%%% {hosts,[key_or_name()]}]}]}
+%%% '''
+%%%
+%%% <b>Note</b> that hook options specified in a configuration file
+%%% will overwrite any hardcoded hook options in the test suite.
+%%
+%%% === Logging example 1 ===
+%%%
+%%% The following `ct_hooks' statement will cause raw printing of
+%%% telnet traffic to separate logs for the connections named
+%%% `server1' and `server2'. Any other connections will be logged
+%%% to default telnet log.
+%%%
+%%% ```
+%%% suite() ->
+%%% [{ct_hooks, [{cth_conn_log, [{ct_telnet,[{log_type,raw}},
+%%% {hosts,[server1,server2]}]}
+%%% ]}]}].
+%%%'''
+%%%
+%%% === Logging example 2 ===
+%%%
+%%% The following configuration file will cause raw logging of all
+%%% telnet traffic into one single text file.
+%%%
+%%% ```
+%%% {ct_conn_log,[{ct_telnet,[{log_type,raw}]}]}.
+%%% '''
+%%%
+%%% The `ct_hooks' statement must look like this:
+%%%
+%%% ```
+%%% suite() ->
+%%% [{ct_hooks, [{cth_conn_log, []}]}].
+%%% '''
+%%%
+%%% The same `ct_hooks' statement without the configuration file would
+%%% cause HTML logging of all telnet connections into the test case
+%%% HTML log.
+%%%
+%%% <b>Note</b> that if the `cth_conn_log' hook is not added, telnet
+%%% traffic is still logged in the test case log files (on the legacy
+%%% `ct_telnet' format).
+
%%% @type connection_type() = telnet | ts1 | ts2
diff --git a/lib/common_test/src/cth_conn_log.erl b/lib/common_test/src/cth_conn_log.erl
index 050bda6eda..a731c8054c 100644
--- a/lib/common_test/src/cth_conn_log.erl
+++ b/lib/common_test/src/cth_conn_log.erl
@@ -140,19 +140,9 @@ pre_init_per_testcase(TestCase,Config,CthState) ->
GL = group_leader(),
Update =
fun(Init) when Init == undefined; Init == [] ->
-
- %%! --- Tue Jan 28 12:13:08 2014 --- peppe was here!
- io:format(user, "### ~p: ADDING NEW HANDLER FOR ~p~n",
- [TestCase,GL]),
-
error_logger:add_report_handler(ct_conn_log_h,{GL,Logs}),
[TestCase];
(PrevUsers) ->
-
- %%! --- Tue Jan 28 12:13:08 2014 --- peppe was here!
- io:format(user, "### ~p: CONNECTING ~p TO EXISTING HANDLER~n",
- [TestCase,GL]),
-
error_logger:info_report(update,{GL,Logs}),
receive
{updated,GL} ->
@@ -179,17 +169,10 @@ post_end_per_testcase(TestCase,_Config,Return,CthState) ->
deleted ->
[ct_util:delete_testdata({?MODULE,ConnMod}) ||
{ConnMod,_} <- CthState],
-
- %%! --- Tue Jan 28 13:29:37 2014 --- peppe was here!
- io:format(user, "### ~p: REMOVING ERROR LOGGER~n", [TestCase]),
-
error_logger:delete_report_handler(ct_conn_log_h);
{error,no_response} ->
exit({?MODULE,no_response_from_logger});
_PrevUsers ->
- %%! --- Tue Jan 28 13:29:37 2014 --- peppe was here!
- io:format(user, "### ~p: *NOT* REMOVING ERROR LOGGER~n", [TestCase]),
-
ok
end,
{Return,CthState}.
diff --git a/lib/common_test/test/ct_telnet_SUITE.erl b/lib/common_test/test/ct_telnet_SUITE.erl
index bb6cc0be5d..33b343e9ff 100644
--- a/lib/common_test/test/ct_telnet_SUITE.erl
+++ b/lib/common_test/test/ct_telnet_SUITE.erl
@@ -50,9 +50,8 @@ suite() -> [{ct_hooks,[ts_install_cth]}].
groups() ->
[{legacy, [], [unix_telnet,own_server,timetrap]},
- {raw, [], [unix_telnet,own_server,timetrap]},
-%{raw, [], [unix_telnet]},
- {html, [], [unix_telnet,own_server]},
+ {raw, [], [unix_telnet,own_server,timetrap]},
+ {html, [], [unix_telnet,own_server]},
{silent, [], [unix_telnet,own_server]}].
all() ->
@@ -206,6 +205,11 @@ events_to_check(timetrap,_Config) ->
{?eh,tc_done,{ct_telnet_timetrap_SUITE,expect_success,ok}},
{?eh,stop_logging,[]}].
+%%! THIS MUST BE FIXED!!!
+all_cases(ct_telnet_basic_SUITE,_Config) ->
+ [{?eh,start_logging,{'DEF','RUNDIR'}},
+ {?eh,stop_logging,[]}];
+
all_cases(Suite,Config) ->
{module,_} = code:load_abs(filename:join(?config(data_dir,Config),
Suite)),
diff --git a/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl b/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl
index dbb9e9449a..80616af064 100644
--- a/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl
+++ b/lib/common_test/test/ct_telnet_SUITE_data/ct_telnet_basic_SUITE.erl
@@ -19,8 +19,7 @@ suite() -> [
].
operations() ->
- [start_stop
-, send_and_get, expect, already_closed,
+ [start_stop, send_and_get, expect, already_closed,
cmd, sendf, close_wrong_type].
mult_case(_Case, 0) ->
@@ -61,10 +60,6 @@ init_per_testcase(Case, Config) when (Case == sessions1) or
(Case == sessions2) or
(Case == sessions3) or
(Case == sessions4) ->
-
- %%! --- Tue Jan 28 13:46:47 2014 --- peppe was here!
- io:format(user, ">>> ~p STARTING~n", [Case]),
-
N = lists:last(atom_to_list(Case))-48,
ct:log("Using connection ~w for session ~w on ~w",
[?conn_name(N),N,self()]),
@@ -76,10 +71,6 @@ init_per_testcase(Case, Config) ->
Config.
end_per_testcase(_Case, _) ->
-
- %%! --- Tue Jan 28 13:46:47 2014 --- peppe was here!
- io:format(user, "<<< ~p ENDING~n", [_Case]),
-
ok.
%%%-----------------------------------------------------------------