summaryrefslogtreecommitdiff
path: root/lib/ssh
diff options
context:
space:
mode:
authorHans Nilsson <hans@erlang.org>2020-06-02 15:24:28 +0200
committerHans Nilsson <hans@erlang.org>2020-06-16 11:42:34 +0200
commit88ca70b9d7236f5454e446e7f3eeda3dafbbae55 (patch)
tree0475606295798b7e3a809f9c39457200da7344a9 /lib/ssh
parent3a0ff7163a01d26d98b7c4f683d19c9c3204cde2 (diff)
downloaderlang-88ca70b9d7236f5454e446e7f3eeda3dafbbae55.tar.gz
ssh: Increase coverage on ssh_dbg code
Diffstat (limited to 'lib/ssh')
-rw-r--r--lib/ssh/src/ssh_client_channel.erl6
-rw-r--r--lib/ssh/src/ssh_connection_handler.erl41
-rw-r--r--lib/ssh/src/ssh_dbg.erl73
-rw-r--r--lib/ssh/test/ssh_compat_SUITE.erl1
-rw-r--r--lib/ssh/test/ssh_dbg_SUITE.erl42
5 files changed, 81 insertions, 82 deletions
diff --git a/lib/ssh/src/ssh_client_channel.erl b/lib/ssh/src/ssh_client_channel.erl
index 5ffdf49e9b..bb16d878fa 100644
--- a/lib/ssh/src/ssh_client_channel.erl
+++ b/lib/ssh/src/ssh_client_channel.erl
@@ -436,7 +436,7 @@ ssh_dbg_format(channel_events, {call, {?MODULE,handle_call, [Call,From,State]}})
];
ssh_dbg_format(channel_events, {return_from, {?MODULE,handle_call,3}, Ret}) ->
["Server Channel call returned:\n",
- io_lib:format("~p~n", [ssh_dbg:reduce_state(Ret)])
+ io_lib:format("~p~n", [ssh_dbg:reduce_state(Ret,#state{})])
];
ssh_dbg_format(channel_events, {call, {?MODULE,handle_cast, [Cast,State]}}) ->
@@ -445,7 +445,7 @@ ssh_dbg_format(channel_events, {call, {?MODULE,handle_cast, [Cast,State]}}) ->
];
ssh_dbg_format(channel_events, {return_from, {?MODULE,handle_cast,2}, Ret}) ->
["Server Channel cast returned:\n",
- io_lib:format("~p~n", [ssh_dbg:reduce_state(Ret)])
+ io_lib:format("~p~n", [ssh_dbg:reduce_state(Ret,#state{})])
];
ssh_dbg_format(channel_events, {call, {?MODULE,handle_info, [Info,State]}}) ->
@@ -454,7 +454,7 @@ ssh_dbg_format(channel_events, {call, {?MODULE,handle_info, [Info,State]}}) ->
];
ssh_dbg_format(channel_events, {return_from, {?MODULE,handle_info,2}, Ret}) ->
["Server Channel info returned:\n",
- io_lib:format("~p~n", [ssh_dbg:reduce_state(Ret)])
+ io_lib:format("~p~n", [ssh_dbg:reduce_state(Ret,#state{})])
].
hdr(Title, S) ->
diff --git a/lib/ssh/src/ssh_connection_handler.erl b/lib/ssh/src/ssh_connection_handler.erl
index 5e5ed9b79a..48f07584ca 100644
--- a/lib/ssh/src/ssh_connection_handler.erl
+++ b/lib/ssh/src/ssh_connection_handler.erl
@@ -414,7 +414,8 @@ alg(ConnectionHandler) ->
| undefined,
auth_user :: string()
| undefined,
- connection_state :: #connection{},
+ connection_state :: #connection{}
+ | undefined,
latest_channel_id = 0 :: non_neg_integer()
| undefined,
transport_protocol :: atom()
@@ -2567,7 +2568,7 @@ ssh_dbg_format(connection_events, {call, {?MODULE,handle_event, [EventType, Even
];
ssh_dbg_format(connection_events, {return_from, {?MODULE,handle_event,4}, Ret}) ->
["Connection event result\n",
- io_lib:format("~p~n", [event_handler_result(Ret)])
+ io_lib:format("~p~n", [ssh_dbg:reduce_state(Ret, #data{})])
];
ssh_dbg_format(renegotiation, {call, {?MODULE,init_renegotiate_timers,[OldState,NewState,D]}}) ->
@@ -2659,39 +2660,3 @@ ssh_dbg_format(disconnect, {call,{?MODULE,send_disconnect,
ssh_dbg_format(renegotiation, {return_from, {?MODULE,send_disconnect,7}, _Ret}) ->
skip.
-
-event_handler_result({next_state, NextState, _NewData}) ->
- {next_state, NextState, "#data{}"};
-event_handler_result({next_state, NextState, _NewData, Actions}) ->
- {next_state, NextState, "#data{}", Actions};
-event_handler_result(R) ->
- state_callback_result(R).
-
-state_callback_result({keep_state, _NewData}) ->
- {keep_state, "#data{}"};
-state_callback_result({keep_state, _NewData, Actions}) ->
- {keep_state, "#data{}", Actions};
-state_callback_result(keep_state_and_data) ->
- keep_state_and_data;
-state_callback_result({keep_state_and_data, Actions}) ->
- {keep_state_and_data, Actions};
-state_callback_result({repeat_state, _NewData}) ->
- {repeat_state, "#data{}"};
-state_callback_result({repeat_state, _NewData, Actions}) ->
- {repeat_state, "#data{}", Actions};
-state_callback_result(repeat_state_and_data) ->
- repeat_state_and_data;
-state_callback_result({repeat_state_and_data, Actions}) ->
- {repeat_state_and_data, Actions};
-state_callback_result(stop) ->
- stop;
-state_callback_result({stop, Reason}) ->
- {stop, Reason};
-state_callback_result({stop, Reason, _NewData}) ->
- {stop, Reason, "#data{}"};
-state_callback_result({stop_and_reply, Reason, Replies}) ->
- {stop_and_reply, Reason, Replies};
-state_callback_result({stop_and_reply, Reason, Replies, _NewData}) ->
- {stop_and_reply, Reason, Replies, "#data{}"};
-state_callback_result(R) ->
- R.
diff --git a/lib/ssh/src/ssh_dbg.erl b/lib/ssh/src/ssh_dbg.erl
index f8391224f8..f8750dc070 100644
--- a/lib/ssh/src/ssh_dbg.erl
+++ b/lib/ssh/src/ssh_dbg.erl
@@ -67,7 +67,7 @@
]).
-export([shrink_bin/1,
- reduce_state/1,
+ reduce_state/2, reduce_state/3,
wr_record/3]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2]).
@@ -167,17 +167,22 @@ shrink_bin(T) when is_tuple(T) -> list_to_tuple(shrink_bin(tuple_to_list(T)));
shrink_bin(X) -> X.
%%%----------------------------------------------------------------
-%% Replace last element (the state) with "#<state-name>{}"
-reduce_state(T) ->
- try
- erlang:setelement(size(T),
- T,
- lists:concat(['#',element(1,element(size(T),T)),'{}'])
- )
- catch
- _:_ ->
- T
- end.
+%% Replace any occurence of {Name,...}, with "#Name{}"
+reduce_state(T, RecordExample) ->
+ Name = element(1, RecordExample),
+ Arity = size(RecordExample),
+ reduce_state(T, Name, Arity).
+
+%% Replace any occurence of {Name,...}, with "#Name{}"
+reduce_state(T, Name, Arity) when element(1,T) == Name,
+ size(T) == Arity ->
+ lists:concat(['#',Name,'{}']);
+reduce_state(L, Name, Arity) when is_list(L) ->
+ [reduce_state(E,Name,Arity) || E <- L];
+reduce_state(T, Name, Arity) when is_tuple(T) ->
+ list_to_tuple( reduce_state(tuple_to_list(T),Name,Arity) );
+reduce_state(X, _, _) ->
+ X.
%%%================================================================
-record(data, {
@@ -341,34 +346,22 @@ switch(X, Types) when is_list(Types) ->
%%% {send,Msg,To}
%%% {'receive',Msg}
-trace_pid({trace,Pid,_}) -> Pid;
-trace_pid({trace,Pid,_,_}) -> Pid;
-trace_pid({trace,Pid,_,_,_}) -> Pid;
-trace_pid({trace,Pid,_,_,_,_}) -> Pid;
-trace_pid({trace,Pid,_,_,_,_,_}) -> Pid;
-trace_pid({trace_ts,Pid,_,_TS}) -> Pid;
-trace_pid({trace_ts,Pid,_,_,_TS}) -> Pid;
-trace_pid({trace_ts,Pid,_,_,_,_TS}) -> Pid;
-trace_pid({trace_ts,Pid,_,_,_,_,_TS}) -> Pid;
-trace_pid({trace_ts,Pid,_,_,_,_,_,_TS}) -> Pid.
-
-trace_ts({trace_ts,_Pid,_,TS}) -> ts(TS);
-trace_ts({trace_ts,_Pid,_,_,TS}) -> ts(TS);
-trace_ts({trace_ts,_Pid,_,_,_,TS}) -> ts(TS);
-trace_ts({trace_ts,_Pid,_,_,_,_,TS}) -> ts(TS);
-trace_ts({trace_ts,_Pid,_,_,_,_,_,TS}) -> ts(TS);
-trace_ts(_) -> "-".
-
-trace_info({trace,_Pid,A}) -> A;
-trace_info({trace,_Pid,A,B}) -> {A,B};
-trace_info({trace,_Pid,A,B,C}) -> {A,B,C};
-trace_info({trace,_Pid,A,B,C,D}) -> {A,B,C,D};
-trace_info({trace,_Pid,A,B,C,D,E}) -> {A,B,C,D,E};
-trace_info({trace_ts,_Pid,A,_TS}) -> A;
-trace_info({trace_ts,_Pid,A,B,_TS}) -> {A,B};
-trace_info({trace_ts,_Pid,A,B,C,_TS}) -> {A,B,C};
-trace_info({trace_ts,_Pid,A,B,C,D,_TS}) -> {A,B,C,D};
-trace_info({trace_ts,_Pid,A,B,C,D,E,_TS}) -> {A,B,C,D,E}.
+%% Pick 2nd element, the Pid
+trace_pid(T) when element(1,T)==trace
+ ; element(1,T)==trace_ts ->
+ element(2,T).
+
+%% Pick last element, the Time Stamp, and format it
+trace_ts(T) when element(1,T)==trace_ts ->
+ ts( element(size(T), T) ).
+
+%% Make a tuple of all elements but the 1st, 2nd and last
+trace_info(T) ->
+ case tuple_to_list(T) of
+ [trace,_Pid | Info] -> list_to_tuple(Info);
+ [trace_ts,_Pid | InfoTS] -> list_to_tuple(
+ lists:droplast(InfoTS))
+ end.
try_all_types_in_all_modules(TypesOn, Arg, WriteFun, Acc0) ->
diff --git a/lib/ssh/test/ssh_compat_SUITE.erl b/lib/ssh/test/ssh_compat_SUITE.erl
index b1fa138716..e0a5eb8de5 100644
--- a/lib/ssh/test/ssh_compat_SUITE.erl
+++ b/lib/ssh/test/ssh_compat_SUITE.erl
@@ -267,6 +267,7 @@ login_otp_is_server(Config) ->
all_algorithms_sftp_exec_reneg_otp_is_client(Config) ->
CommonAlgs = proplists:get_value(common_remote_server_algs, Config),
{IP,Port} = ip_port(Config),
+ssh_dbg:start(), ssh_dbg:on([renegotiation]),
chk_all_algos(?FUNCTION_NAME, CommonAlgs, Config,
fun(Tag, Alg) ->
PrefAlgs =
diff --git a/lib/ssh/test/ssh_dbg_SUITE.erl b/lib/ssh/test/ssh_dbg_SUITE.erl
index 8df9c8093a..4b2a89beb2 100644
--- a/lib/ssh/test/ssh_dbg_SUITE.erl
+++ b/lib/ssh/test/ssh_dbg_SUITE.erl
@@ -47,7 +47,8 @@ groups() ->
dbg_alg_terminate,
dbg_ssh_messages,
dbg_connections,
- dbg_channels]},
+ dbg_channels,
+ all_dbg]},
{circ_buf, [], [cb_basic,
cb_print,
cb_macros_print
@@ -353,6 +354,37 @@ dbg_channels(Config) ->
stop_and_fail_if_unhandled_dbg_msgs(Ref, [C,D], Pid).
%%--------------------------------------------------------------------
+all_dbg(Config) ->
+ SystemDir = proplists:get_value(data_dir, Config),
+ UserDir = proplists:get_value(priv_dir, Config),
+
+ Dir0 = filename:join(proplists:get_value(priv_dir,Config), ssh_test_lib:random_chars(10)),
+ file:make_dir(Dir0),
+ Dir = w2l(Config, Dir0),
+ ct:log("~p:~p created the directory~nsDir0 = ~p~nDir = ~p", [?MODULE,?LINE,Dir0,Dir]),
+
+ AllTags = ssh_dbg:start(),
+ {ok,AllTags} = ssh_dbg:on(AllTags),
+
+ {_, Host, Port} =
+ ssh_test_lib:daemon([{system_dir, SystemDir},
+ {user_dir, UserDir},
+ {user_passwords, [{?USR,?PWD}]}
+ ]),
+
+ {ok, ChPid, _C} =
+ ssh_sftp:start_channel(Host, Port,
+ [{user_dir, UserDir},
+ {user,?USR},
+ {password,?PWD},
+ {user_interaction, false},
+ {silently_accept_hosts, true}
+ ]),
+
+ {ok, _Files} = ssh_sftp:list_dir(ChPid, Dir).
+
+
+%%--------------------------------------------------------------------
cb_basic(_Config) ->
%% Check that the circular buffer is disabled at start:
[] = ssh_dbg:cbuf_list(),
@@ -470,3 +502,11 @@ dbg_SKIP(Ref, Prefixes, UnexpectedAcc) ->
lists:reverse(UnexpectedAcc)
end.
+%%%----------------------------------------------------------------
+w2l(P) ->
+ ssh_test_lib:winpath_to_linuxpath(P).
+
+w2l(Config, P) ->
+ W2L = proplists:get_value(w2l, Config, fun(X) -> X end),
+ W2L(P).
+