aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2016-04-13 13:19:10 +0200
committerHans Nilsson <[email protected]>2016-04-29 13:17:52 +0200
commit020e62c9619b518620d216cf0caef55fe129d4c3 (patch)
tree8249e590918f2ffc6ef256b2a691be9a9b09983d
parent223b123f576e726c18bcd38fa2b866d23f1a14a3 (diff)
downloadotp-020e62c9619b518620d216cf0caef55fe129d4c3.tar.gz
otp-020e62c9619b518620d216cf0caef55fe129d4c3.tar.bz2
otp-020e62c9619b518620d216cf0caef55fe129d4c3.zip
ssh: centralize and adjust port spawning for test_suites into ssh_test_lib
-rw-r--r--lib/ssh/test/ssh_algorithms_SUITE.erl6
-rw-r--r--lib/ssh/test/ssh_test_cli.erl9
-rw-r--r--lib/ssh/test/ssh_test_lib.erl35
-rw-r--r--lib/ssh/test/ssh_to_openssh_SUITE.erl5
4 files changed, 39 insertions, 16 deletions
diff --git a/lib/ssh/test/ssh_algorithms_SUITE.erl b/lib/ssh/test/ssh_algorithms_SUITE.erl
index 3a8eec46a8..7965561c22 100644
--- a/lib/ssh/test/ssh_algorithms_SUITE.erl
+++ b/lib/ssh/test/ssh_algorithms_SUITE.erl
@@ -231,10 +231,8 @@ sshc_simple_exec(Config) ->
" -o StrictHostKeyChecking=no",
" ",Host," 1+1."]),
ct:log("~p",[Cmd]),
- SshPort = open_port({spawn, Cmd}, [binary, stderr_to_stdout,
- overlapped_io %only affects windows
- ]),
- ssh_test_lib:rcv_expected({data,<<"2\n">>}, SshPort, ?TIMEOUT).
+ OpenSsh = ssh_test_lib:open_port({spawn, Cmd}, [eof,exit_status]),
+ ssh_test_lib:rcv_expected({data,<<"2\n">>}, OpenSsh, ?TIMEOUT).
%%--------------------------------------------------------------------
%% Connect to the ssh server of the OS
diff --git a/lib/ssh/test/ssh_test_cli.erl b/lib/ssh/test/ssh_test_cli.erl
index 697ddb730d..f96b9967d2 100644
--- a/lib/ssh/test/ssh_test_cli.erl
+++ b/lib/ssh/test/ssh_test_cli.erl
@@ -75,10 +75,11 @@ terminate(_Why, _S) ->
run_portprog(User, cli, TmpDir) ->
Pty_bin = os:find_executable("cat"),
- open_port({spawn_executable, Pty_bin},
- [stream, {cd, TmpDir}, {env, [{"USER", User}]},
- {args, []}, binary,
- exit_status, use_stdio, stderr_to_stdout]).
+ ssh_test_lib:open_port({spawn_executable, Pty_bin},
+ [stream,
+ {cd, TmpDir},
+ {env, [{"USER", User}]},
+ {args, []}]).
get_ssh_user(Ref) ->
[{user, User}] = ssh:connection_info(Ref, [user]),
diff --git a/lib/ssh/test/ssh_test_lib.erl b/lib/ssh/test/ssh_test_lib.erl
index 15f10fa1ae..927c9343d1 100644
--- a/lib/ssh/test/ssh_test_lib.erl
+++ b/lib/ssh/test/ssh_test_lib.erl
@@ -201,16 +201,27 @@ rcv_expected(Expect, SshPort, Timeout) ->
{SshPort, Expect} ->
ct:log("Got expected ~p from ~p",[Expect,SshPort]),
catch port_close(SshPort),
- ok;
+ rcv_lingering(50);
Other ->
- ct:log("Got UNEXPECTED ~p",[Other]),
- rcv_expected(SshPort, Expect, Timeout)
+ ct:log("Got UNEXPECTED ~p~nExpect ~p",[Other, {SshPort,Expect}]),
+ rcv_expected(Expect, SshPort, Timeout)
after Timeout ->
catch port_close(SshPort),
ct:fail("Did not receive answer")
end.
+rcv_lingering(Timeout) ->
+ receive
+ Msg ->
+ ct:log("Got LINGERING ~p",[Msg]),
+ rcv_lingering(Timeout)
+
+ after Timeout ->
+ ct:log("No more lingering messages",[]),
+ ok
+ end.
+
receive_exec_result(Msg) ->
ct:log("Expect data! ~p", [Msg]),
@@ -481,8 +492,9 @@ openssh_supports(ClientOrServer, Tag, Alg) when ClientOrServer == sshc ;
%% Check if we have a "newer" ssh client that supports these test cases
ssh_client_supports_Q() ->
- ErlPort = open_port({spawn, "ssh -Q cipher"}, [exit_status, stderr_to_stdout]),
- 0 == check_ssh_client_support2(ErlPort).
+ 0 == check_ssh_client_support2(
+ ?MODULE:open_port({spawn, "ssh -Q cipher"})
+ ).
check_ssh_client_support2(P) ->
receive
@@ -701,3 +713,16 @@ has_inet6_address() ->
catch
throw:6 -> true
end.
+
+%%%----------------------------------------------------------------
+open_port(Arg1) ->
+ ?MODULE:open_port(Arg1, []).
+
+open_port(Arg1, ExtraOpts) ->
+ erlang:open_port(Arg1,
+ [binary,
+ stderr_to_stdout,
+ exit_status,
+ use_stdio,
+ overlapped_io, hide %only affects windows
+ | ExtraOpts]).
diff --git a/lib/ssh/test/ssh_to_openssh_SUITE.erl b/lib/ssh/test/ssh_to_openssh_SUITE.erl
index ea057ed8a5..2be75fd7f3 100644
--- a/lib/ssh/test/ssh_to_openssh_SUITE.erl
+++ b/lib/ssh/test/ssh_to_openssh_SUITE.erl
@@ -378,9 +378,8 @@ erlang_server_openssh_client_public_key_X(Config, PubKeyAlg) ->
Cmd = "ssh -p " ++ integer_to_list(Port) ++
" -o UserKnownHostsFile=" ++ KnownHosts ++
" " ++ Host ++ " 1+1.",
- SshPort = open_port({spawn, Cmd}, [binary, stderr_to_stdout]),
-
- ssh_test_lib:rcv_expected({data,<<"2\n">>}, SshPort, ?TIMEOUT),
+ OpenSsh = ssh_test_lib:open_port({spawn, Cmd}),
+ ssh_test_lib:rcv_expected({data,<<"2\n">>}, OpenSsh, ?TIMEOUT),
ssh:stop_daemon(Pid).
%%--------------------------------------------------------------------