4
%% Copyright Ericsson AB 2000-2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
21
-module(erl_global_SUITE).
23
-include_lib("test_server/include/test_server.hrl").
24
-include("erl_global_SUITE_data/erl_global_test_cases.hrl").
26
-export([all/0,suite/0,init_per_suite/1,end_per_suite/1,
27
init_per_testcase/2,end_per_testcase/2,
28
erl_global_registration/1, erl_global_whereis/1, erl_global_names/1]).
30
-import(runner, [get_term/1,send_term/2]).
32
-define(GLOBAL_NAME, global_register_node_test).
35
[erl_global_registration, erl_global_whereis, erl_global_names].
37
suite() -> [{ct_hooks,[ts_install_cth]}].
39
init_per_suite(Config) ->
42
end_per_suite(_Config) ->
45
init_per_testcase(_Case, Config) ->
46
Dog = ?t:timetrap(?t:minutes(0.25)),
47
[{watchdog, Dog}|Config].
49
end_per_testcase(_Case, Config) ->
50
Dog = ?config(watchdog, Config),
51
test_server:timetrap_cancel(Dog),
54
erl_global_registration(Config) when is_list(Config) ->
55
?line P = runner:start(?interpret),
56
?line {ok, Fd} = erl_connect(P, node(), 42, erlang:get_cookie(), 0),
58
?line ok = erl_global_register(P, Fd, ?GLOBAL_NAME),
59
?line ok = erl_global_unregister(P, Fd, ?GLOBAL_NAME),
61
?line 0 = erl_close_connection(P,Fd),
62
?line runner:send_eot(P),
63
?line runner:recv_eot(P),
66
erl_global_whereis(Config) when is_list(Config) ->
67
?line P = runner:start(?interpret),
68
?line {ok, Fd} = erl_connect(P, node(), 42, erlang:get_cookie(), 0),
71
?line yes = global:register_name(?GLOBAL_NAME, Self),
72
?line Self = erl_global_whereis(P, Fd, ?GLOBAL_NAME),
73
?line global:unregister_name(?GLOBAL_NAME),
74
?line 0 = erl_close_connection(P, Fd),
75
?line runner:send_eot(P),
76
?line runner:recv_eot(P),
79
erl_global_names(Config) when is_list(Config) ->
80
?line P = runner:start(?interpret),
81
?line {ok, Fd} = erl_connect(P, node(), 42, erlang:get_cookie(), 0),
84
?line global:register_name(?GLOBAL_NAME, Self),
85
?line {Names1, _N1} = erl_global_names(P, Fd),
86
?line true = lists:member(atom_to_list(?GLOBAL_NAME), Names1),
87
?line global:unregister_name(?GLOBAL_NAME),
88
?line {Names2, _N2} = erl_global_names(P, Fd),
89
?line false = lists:member(atom_to_list(?GLOBAL_NAME), Names2),
90
?line 0 = erl_close_connection(P, Fd),
91
?line runner:send_eot(P),
92
?line runner:recv_eot(P),
95
%%% Interface functions for erl_interface functions.
97
erl_connect(P, Node, Num, Cookie, Creation) ->
98
send_command(P, erl_connect, [Num, Node, Cookie, Creation]),
100
{term,{Fd,_}} when Fd >= 0 -> {ok,Fd};
101
{term,{-1,Errno}} -> {error,Errno}
104
erl_close_connection(P, FD) ->
105
send_command(P, erl_close_connection, [FD]),
107
{term,Int} when is_integer(Int) -> Int
110
erl_global_register(P, Fd, Name) ->
111
send_command(P, erl_global_register, [Fd,Name]),
114
erl_global_whereis(P, Fd, Name) ->
115
send_command(P, erl_global_whereis, [Fd,Name]),
121
erl_global_names(P, Fd) ->
122
send_command(P, erl_global_names, [Fd]),
128
erl_global_unregister(P, Fd, Name) ->
129
send_command(P, erl_global_unregister, [Fd,Name]),
132
get_send_result(P) ->
136
{term,{-1, Errno}} -> {error,Errno};
138
?t:fail(bad_return_value)
141
send_command(P, Name, Args) ->
142
runner:send_term(P, {Name,list_to_tuple(Args)}).