4
%% Copyright Ericsson AB 1998-2009. All Rights Reserved.
4
%% Copyright Ericsson AB 1998-2010. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
19
19
-module(epmd_SUITE).
31
31
-define(MEDIUM_PAUSE, ?t:seconds(1)).
32
32
-define(LONG_PAUSE, ?t:seconds(5)).
34
% Information about nodes
35
-record(node_info, {port, node_type, prot, lvsn, hvsn, node_name, extra}).
34
37
% Test server specific exports
35
38
-export([all/1, init_per_testcase/2, fin_per_testcase/2]).
76
82
-define(REG_REPEAT_LIM,1000).
78
84
% Message codes in epmd protocol
79
-define(EPMD_ALIVE_REQ, $a).
80
-define(EPMD_ALIVE_OK_RESP, $Y).
81
-define(EPMD_PORT_REQ, $p).
85
-define(EPMD_ALIVE_REQ, $a).
86
-define(EPMD_ALIVE2_REQ, $x).
87
-define(EPMD_ALIVE_OK_RESP, $Y).
88
-define(EPMD_ALIVE2_RESP, $y).
89
-define(EPMD_PORT_REQ, $p).
90
-define(EPMD_PORT_PLEASE2_REQ, $z).
91
-define(EPMD_PORT2_RESP, $w).
82
92
-define(EPMD_NAMES_REQ, $n).
83
93
-define(EPMD_DUMP_REQ, $d).
84
94
-define(EPMD_KILL_REQ, $k).
182
195
register_node(Name,?DUMMY_PORT).
184
197
register_node(Name, Port) ->
187
M = [?EPMD_ALIVE_REQ, put16(Port), Name],
188
case send(Sock, [size16(M), M]) of
191
{ok, [?EPMD_ALIVE_OK_RESP,_D1,_D0]} ->
194
test_server:format("recv on sock ~w: ~p~n",
199
test_server:format("send on sock ~w: ~w~n",[Sock,Other]),
198
case send_req([?EPMD_ALIVE_REQ, put16(Port), Name]) of
201
{ok, [?EPMD_ALIVE_OK_RESP,_D1,_D0]} ->
204
test_server:format("recv on sock ~w: ~p~n",
212
register_node_v2(Port, NodeType, Prot, HVsn, LVsn, Name, Extra) ->
213
Req = [?EPMD_ALIVE2_REQ, put16(Port), NodeType, Prot,
214
put16(HVsn), put16(LVsn),
216
size16(Extra), Extra],
217
case send_req(Req) of
220
{ok, [?EPMD_ALIVE2_RESP,_Res=0,_C0,_C1]} ->
223
test_server:format("recv on sock ~w: ~p~n",
231
% Internal function to fetch information about a node
233
port_please_v2(Name) ->
234
case send_req([?EPMD_PORT_PLEASE2_REQ, Name]) of
236
case recv_until_sock_closes(Sock) of
238
parse_port2_resp(Resp);
240
test_server:format("recv on sock ~w: ~p~n",
248
parse_port2_resp(Resp) ->
249
case list_to_binary(Resp) of
250
<<?EPMD_PORT2_RESP,Res,Port:16,NodeType,Prot,HVsn:16,LVsn:16,
251
NLen:16,NodeName:NLen/binary,
252
ELen:16,Extra:ELen/binary>> when Res =:= 0 ->
253
{ok, #node_info{port=Port,node_type=NodeType,prot=Prot,
255
node_name=binary_to_list(NodeName),
256
extra=binary_to_list(Extra)}};
203
test_server:format("Connect on port ~w: ~p~n",[Port,Other]),
258
test_server:format("invalid port2 resp: ~p~n",
209
263
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211
265
name_with_null_inside(doc) ->
633
687
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689
returns_valid_empty_extra(doc) ->
690
["Check that an empty extra is prefixed by a two byte length"];
691
returns_valid_empty_extra(suite) ->
693
returns_valid_empty_extra(Config) when list(Config) ->
694
?line ok = epmdrun(),
695
?line {ok,Sock} = register_node_v2(4711, 72, 0, 5, 5, "foo", []),
696
?line {ok,#node_info{extra=[]}} = port_please_v2("foo"),
697
?line ok = close(Sock),
700
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
702
returns_valid_populated_extra_with_nulls(doc) ->
703
["Check a populated extra with embedded null characters"];
704
returns_valid_populated_extra_with_nulls(suite) ->
706
returns_valid_populated_extra_with_nulls(Config) when list(Config) ->
707
?line ok = epmdrun(),
708
?line {ok,Sock} = register_node_v2(4711, 72, 0, 5, 5, "foo", "ABC\000\000"),
709
?line {ok,#node_info{extra="ABC\000\000"}} = port_please_v2("foo"),
710
?line ok = close(Sock),
713
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634
714
% Terminate all tests with killing epmd.
899
case send(Sock, [size16(Req), Req]) of
903
test_server:format("Failed to send ~w on sock ~w: ~w~n",
908
test_server:format("Connect failed when sending ~w: ~p~n",
913
recv_until_sock_closes(Sock) ->
914
recv_until_sock_closes_2(Sock,[]).
916
recv_until_sock_closes_2(Sock,AccData) ->
919
recv_until_sock_closes_2(Sock,AccData++Data);
816
926
sleep(MilliSeconds) ->
817
927
timer:sleep(MilliSeconds).