diff options
author | Peter Andersson <[email protected]> | 2014-03-10 16:22:25 +0100 |
---|---|---|
committer | Peter Andersson <[email protected]> | 2014-03-12 16:00:14 +0100 |
commit | 5667601be38a2e35fbbe59491f448f947bfcc73c (patch) | |
tree | 005d9d79402b2a99b7411c329bb5bf58051fc827 /lib/common_test/src | |
parent | 609349f6acac4b03b8cac53eb9ad456a2b2d5536 (diff) | |
download | otp-5667601be38a2e35fbbe59491f448f947bfcc73c.tar.gz otp-5667601be38a2e35fbbe59491f448f947bfcc73c.tar.bz2 otp-5667601be38a2e35fbbe59491f448f947bfcc73c.zip |
Add test cases and fix some problems with logging and with the telnet client
Diffstat (limited to 'lib/common_test/src')
-rw-r--r-- | lib/common_test/src/ct_gen_conn.erl | 2 | ||||
-rw-r--r-- | lib/common_test/src/ct_telnet.erl | 16 | ||||
-rw-r--r-- | lib/common_test/src/ct_telnet_client.erl | 41 | ||||
-rw-r--r-- | lib/common_test/src/unix_telnet.erl | 4 |
4 files changed, 41 insertions, 22 deletions
diff --git a/lib/common_test/src/ct_gen_conn.erl b/lib/common_test/src/ct_gen_conn.erl index 078d6b1a44..239f5b5f25 100644 --- a/lib/common_test/src/ct_gen_conn.erl +++ b/lib/common_test/src/ct_gen_conn.erl @@ -344,7 +344,7 @@ loop(Opts) -> link(NewPid), put(conn_pid,NewPid), loop(Opts#gen_opts{conn_pid=NewPid, - cb_state=NewState}); + cb_state=NewState}); Error -> ct_util:unregister_connection(self()), log("Reconnect failed. Giving up!", diff --git a/lib/common_test/src/ct_telnet.erl b/lib/common_test/src/ct_telnet.erl index 096e893720..8c3ce03732 100644 --- a/lib/common_test/src/ct_telnet.erl +++ b/lib/common_test/src/ct_telnet.erl @@ -281,8 +281,16 @@ open(KeyOrName,ConnType,TargetMod,Extra) -> end, log(undefined,open,"Connecting to ~p(~p)", [KeyOrName,Addr1]), - ct_gen_conn:start(KeyOrName,full_addr(Addr1,ConnType), - {TargetMod,KeepAlive,Extra},?MODULE) + Reconnect = + case ct:get_config({telnet_settings,reconnection_attempts}) of + 0 -> false; + _ -> true + end, + ct_gen_conn:start(full_addr(Addr1,ConnType), + {TargetMod,KeepAlive,Extra}, + ?MODULE, [{name,KeyOrName}, + {reconnect,Reconnect}, + {old,true}]) end. %%%----------------------------------------------------------------- @@ -601,11 +609,9 @@ handle_msg({cmd,Cmd,Timeout},State) -> end_gen_log(), {Return,State#state{buffer=NewBuffer,prompt=Prompt}}; handle_msg({send,Cmd},State) -> - log(State,send,"Cmd: ~p",[Cmd]), - + log(State,send,"Sending: ~p",[Cmd]), debug_cont_gen_log("Throwing Buffer:",[]), debug_log_lines(State#state.buffer), - case {State#state.type,State#state.prompt} of {ts,_} -> silent_teln_expect(State#state.name, diff --git a/lib/common_test/src/ct_telnet_client.erl b/lib/common_test/src/ct_telnet_client.erl index f18496cdc2..ce30dcb74b 100644 --- a/lib/common_test/src/ct_telnet_client.erl +++ b/lib/common_test/src/ct_telnet_client.erl @@ -32,12 +32,11 @@ -module(ct_telnet_client). +%% -define(debug, true). + -export([open/2, open/3, open/4, open/5, close/1]). -export([send_data/2, get_data/1]). -%%! --- Sun Mar 9 22:03:49 2014 --- peppe was here! --define(debug, true). - -define(TELNET_PORT, 23). -define(OPEN_TIMEOUT,10000). -define(IDLE_TIMEOUT,10000). @@ -105,7 +104,7 @@ get_data(Pid) -> Pid ! {get_data,self()}, receive {data,Data} -> - {ok, Data} + {ok,Data} end. @@ -116,7 +115,7 @@ init(Parent, Server, Port, Timeout, KeepAlive, ConnName) -> {ok,Sock} -> dbg("~p connected to: ~p (port: ~w, keep_alive: ~w)\n", [ConnName,Server,Port,KeepAlive]), - send([?IAC,?DO,?SUPPRESS_GO_AHEAD], Sock), + send([?IAC,?DO,?SUPPRESS_GO_AHEAD], Sock, ConnName), Parent ! {open,self()}, loop(#state{conn_name=ConnName, get_data=10, keep_alive=KeepAlive}, Sock, []), @@ -130,6 +129,7 @@ loop(State, Sock, Acc) -> {tcp_closed,_} -> dbg("Connection closed\n", []), Data = lists:reverse(lists:append(Acc)), + dbg("Printing queued messages: ~tp",[Data]), ct_telnet:log(State#state.conn_name, general_io, "~ts", [lists:sublist(Data, @@ -142,11 +142,11 @@ loop(State, Sock, Acc) -> ok end; {tcp,_,Msg0} -> - dbg("tcp msg: ~p~n",[Msg0]), + dbg("tcp msg: ~tp~n",[Msg0]), Msg = check_msg(Sock,Msg0,[]), loop(State, Sock, [Msg | Acc]); {send_data,Data} -> - send(Data, Sock), + send(Data, Sock, State#state.conn_name), loop(State, Sock, Acc); {get_data,Pid} -> NewState = @@ -162,7 +162,7 @@ loop(State, Sock, Acc) -> _ -> Data = lists:reverse(lists:append(Acc)), Len = length(Data), - dbg("get_data ~p\n",[Data]), + dbg("get_data ~tp\n",[Data]), ct_telnet:log(State#state.conn_name, general_io, "~ts", [lists:sublist(Data, @@ -176,7 +176,8 @@ loop(State, Sock, Acc) -> NewState = case State of #state{keep_alive = true, get_data = 0} -> - if Acc == [] -> send([?IAC,?NOP], Sock); + if Acc == [] -> send([?IAC,?NOP], Sock, + State#state.conn_name); true -> ok end, State#state{get_data=10}; @@ -185,10 +186,10 @@ loop(State, Sock, Acc) -> end, {NewAcc,Pos} = case erlang:is_process_alive(Pid) of - true -> + true when Acc /= [] -> Data = lists:reverse(lists:append(Acc)), Len = length(Data), - dbg("get_data_delayed ~p\n",[Data]), + dbg("get_data_delayed ~tp\n",[Data]), ct_telnet:log(State#state.conn_name, general_io, "~ts", [lists:sublist(Data, @@ -196,6 +197,10 @@ loop(State, Sock, Acc) -> Len)]), Pid ! {data,Data}, {[],1}; + true when Acc == [] -> + dbg("get_data_delayed nodata\n",[]), + Pid ! {data,[]}, + {[],1}; false -> {Acc,NewState#state.log_pos} end, @@ -206,6 +211,7 @@ loop(State, Sock, Acc) -> ok; true -> Data = lists:reverse(lists:append(Acc)), + dbg("Printing queued messages: ~tp",[Data]), ct_telnet:log(State#state.conn_name, general_io, "~ts", [lists:sublist(Data, @@ -218,11 +224,12 @@ loop(State, Sock, Acc) -> Data = lists:reverse(lists:append(Acc)), case Data of [] -> - send([?IAC,?NOP], Sock), + send([?IAC,?NOP], Sock, State#state.conn_name), loop(State, Sock, Acc); _ when State#state.log_pos == length(Data)+1 -> loop(State, Sock, Acc); _ -> + dbg("Idle timeout, printing ~tp\n",[Data]), Len = length(Data), ct_telnet:log(State#state.conn_name, general_io, "~ts", @@ -236,12 +243,18 @@ loop(State, Sock, Acc) -> wait(true, Time) -> Time; wait(false, _) -> infinity. -send(Data, Sock) -> +send(Data, Sock, ConnName) -> case Data of [?IAC|_] = Cmd -> cmd_dbg(Cmd); _ -> - dbg("Sending: ~p\n", [Data]) + dbg("Sending: ~tp\n", [Data]), + try io_lib:format("[~w] ~ts", [?MODULE,Data]) of + Str -> + ct_telnet:log(ConnName, general_io, Str, []) + catch + _:_ -> ok + end end, gen_tcp:send(Sock, Data), ok. diff --git a/lib/common_test/src/unix_telnet.erl b/lib/common_test/src/unix_telnet.erl index 5854725c17..b05386a5ab 100644 --- a/lib/common_test/src/unix_telnet.erl +++ b/lib/common_test/src/unix_telnet.erl @@ -143,13 +143,13 @@ connect1(Name,Ip,Port,Timeout,KeepAlive,Username,Password) -> {ok,[{prompt,_OtherPrompt1},{prompt,_OtherPrompt2}],_} -> {ok,Pid}; Error -> - log(Name,error, + log(Name,conn_error, "Did not get expected prompt from ~p:~p\n~p\n", [Ip,Port,Error]), {error,Error} end; Error -> - log(Name,error, + log(Name,conn_error, "Could not open telnet connection to ~p:~p\n~p\n", [Ip,Port,Error]), Error |