aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test/src
diff options
context:
space:
mode:
authorPeter Andersson <[email protected]>2014-01-24 12:19:05 +0100
committerPeter Andersson <[email protected]>2014-01-27 19:38:10 +0100
commitf40f4686848bbabb9357b33d08d4b4039d9d7c63 (patch)
tree2454e84d3f3f1b9c649892a42651e5a2aa8c9a4b /lib/common_test/src
parentda730dc3f7a6e46c0341146a69871934d07120e0 (diff)
downloadotp-f40f4686848bbabb9357b33d08d4b4039d9d7c63.tar.gz
otp-f40f4686848bbabb9357b33d08d4b4039d9d7c63.tar.bz2
otp-f40f4686848bbabb9357b33d08d4b4039d9d7c63.zip
Implement tests for logging traffic for multiple telnet connections
Also fix remaining problems in source code
Diffstat (limited to 'lib/common_test/src')
-rw-r--r--lib/common_test/src/ct_conn_log_h.erl28
-rw-r--r--lib/common_test/src/ct_telnet.erl10
-rw-r--r--lib/common_test/src/unix_telnet.erl8
3 files changed, 18 insertions, 28 deletions
diff --git a/lib/common_test/src/ct_conn_log_h.erl b/lib/common_test/src/ct_conn_log_h.erl
index 286844d526..6e0e0baab2 100644
--- a/lib/common_test/src/ct_conn_log_h.erl
+++ b/lib/common_test/src/ct_conn_log_h.erl
@@ -52,7 +52,7 @@ open_files([],State) ->
do_open_files([{Tag,File}|Logs],Acc) ->
- case file:open(File, [write,{encoding,utf8}]) of
+ case file:open(File, [write,append,{encoding,utf8}]) of
{ok,Fd} ->
do_open_files(Logs,[{Tag,Fd}|Acc]);
{error,Reason} ->
@@ -63,17 +63,12 @@ do_open_files([],Acc) ->
handle_event({_Type, GL, _Msg}, State) when node(GL) /= node() ->
{ok, State};
-handle_event({_Type,_GL,{Pid,{ct_connection,Action,ConnName},Report}},State) ->
- %% NOTE: if the format of this event is changed
- %% ({ct_connection,Action,ConnName}) then remember to change
- %% test_server_h:report_receiver as well!!!
- Info = conn_info(Pid,#conn_log{name=ConnName,action=Action}),
+handle_event({_Type,_GL,{Pid,{ct_connection,Mod,Action,ConnName},Report}},
+ State) ->
+ Info = conn_info(Pid,#conn_log{name=ConnName,action=Action,module=Mod}),
write_report(now(),Info,Report,State),
{ok, State};
handle_event({_Type,_GL,{Pid,Info=#conn_log{},Report}},State) ->
- %% NOTE: if the format of this event is changed
- %% (Info=#conn_log{}) then remember to change
- %% test_server_h:report_receiver as well!!!
write_report(now(),conn_info(Pid,Info),Report,State),
{ok, State};
handle_event({error_report,_,{Pid,_,[{ct_connection,ConnName}|R]}},State) ->
@@ -151,12 +146,7 @@ format_head(ConnMod,_,Time,Text) ->
io_lib:format("~n~ts",[Head]).
format_title(raw,#conn_log{client=Client}=Info) ->
- case actionstr(Info) of
- {no_server,Action} ->
- io_lib:format("Client ~w ~s",[Client,Action]);
- Action ->
- io_lib:format("Client ~w ~s ~ts",[Client,Action,serverstr(Info)])
- end;
+ io_lib:format("Client ~w ~s ~ts",[Client,actionstr(Info),serverstr(Info)]);
format_title(_,Info) ->
Title = pad_char_end(?WIDTH,pretty_title(Info),$=),
io_lib:format("~n~ts", [Title]).
@@ -211,10 +201,8 @@ pretty_title(#conn_log{client=Client}=Info) ->
actionstr(#conn_log{action=send}) -> "----->";
actionstr(#conn_log{action=cmd}) -> "----->";
actionstr(#conn_log{action=recv}) -> "<-----";
-actionstr(#conn_log{action=open}) -> "open session to";
-actionstr(#conn_log{action=close}) -> "close session to";
-actionstr(#conn_log{action=info}) -> {no_server,"info"};
-actionstr(#conn_log{action=error}) -> {no_server,"error"};
+actionstr(#conn_log{action=open}) -> "opened session to";
+actionstr(#conn_log{action=close}) -> "closed session to";
actionstr(_) -> "<---->".
serverstr(#conn_log{name=undefined,address={undefined,_}}) ->
@@ -222,7 +210,7 @@ serverstr(#conn_log{name=undefined,address={undefined,_}}) ->
serverstr(#conn_log{name=undefined,address=Address}) ->
io_lib:format("~p",[Address]);
serverstr(#conn_log{name=Alias,address={undefined,_}}) ->
- io_lib:format("~w()",[Alias]);
+ io_lib:format("~w",[Alias]);
serverstr(#conn_log{name=Alias,address=Address}) ->
io_lib:format("~w(~p)",[Alias,Address]).
diff --git a/lib/common_test/src/ct_telnet.erl b/lib/common_test/src/ct_telnet.erl
index 5fc89be0c5..f9dd62ee37 100644
--- a/lib/common_test/src/ct_telnet.erl
+++ b/lib/common_test/src/ct_telnet.erl
@@ -181,7 +181,7 @@ open(KeyOrName,ConnType,TargetMod,Extra) ->
end;
Bool -> Bool
end,
- log(undefined,open,"Opening connection ~p to ~p",
+ log(undefined,open,"Connecting to ~p(~p)",
[KeyOrName,Addr1]),
ct_gen_conn:start(KeyOrName,full_addr(Addr1,ConnType),
{TargetMod,KeepAlive,Extra},?MODULE)
@@ -200,7 +200,7 @@ open(KeyOrName,ConnType,TargetMod,Extra) ->
close(Connection) ->
case get_handle(Connection) of
{ok,Pid} ->
- log(undefined,close,"Closing connection for handle: ~w",[Pid]),
+ log(undefined,close,"Connection closed, handle: ~w",[Pid]),
case ct_gen_conn:stop(Pid) of
{error,{process_down,Pid,noproc}} ->
{error,already_closed};
@@ -600,9 +600,9 @@ reconnect(Ip,Port,N,State=#state{name=Name,
%% @hidden
terminate(TelnPid,State) ->
- log(State,close,"Closing telnet connection.\nId: ~w",[TelnPid]),
- ct_telnet_client:close(TelnPid).
-
+ Result = ct_telnet_client:close(TelnPid),
+ log(State,close,"Telnet connection for ~w closed.",[TelnPid]),
+ Result.
%%%=================================================================
%%% Internal function
diff --git a/lib/common_test/src/unix_telnet.erl b/lib/common_test/src/unix_telnet.erl
index 8b24e959e8..e049c3bf39 100644
--- a/lib/common_test/src/unix_telnet.erl
+++ b/lib/common_test/src/unix_telnet.erl
@@ -137,19 +137,21 @@ connect1(Name,Ip,Port,Timeout,KeepAlive,Username,Password) ->
{error,Error}
end;
Error ->
- log(Name,recv,"Login failed\n~p\n",[Error]),
+ log(Name,recv,"Login to ~p:~p failed\n~p\n",[Ip,Port,Error]),
{error,Error}
end;
{ok,[{prompt,_OtherPrompt1},{prompt,_OtherPrompt2}],_} ->
{ok,Pid};
Error ->
log(Name,error,
- "Did not get expected prompt\n~p\n",[Error]),
+ "Did not get expected prompt from ~p:~p\n~p\n",
+ [Ip,Port,Error]),
{error,Error}
end;
Error ->
log(Name,error,
- "Could not open telnet connection\n~p\n",[Error]),
+ "Could not open telnet connection to ~p:~p\n~p\n",
+ [Ip,Port,Error]),
Error
end,
end_gen_log(),