~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/erl_interface/test/erl_global_SUITE.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 2000-2011. All Rights Reserved.
 
5
%%
 
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/.
 
11
%%
 
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
 
15
%% under the License.
 
16
%%
 
17
%% %CopyrightEnd%
 
18
%%
 
19
 
 
20
%%
 
21
-module(erl_global_SUITE).
 
22
 
 
23
-include_lib("test_server/include/test_server.hrl").
 
24
-include("erl_global_SUITE_data/erl_global_test_cases.hrl").
 
25
 
 
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]).
 
29
 
 
30
-import(runner, [get_term/1,send_term/2]).
 
31
 
 
32
-define(GLOBAL_NAME, global_register_node_test).
 
33
 
 
34
all() ->
 
35
    [erl_global_registration, erl_global_whereis, erl_global_names].
 
36
 
 
37
suite() -> [{ct_hooks,[ts_install_cth]}].
 
38
 
 
39
init_per_suite(Config) ->
 
40
    Config.
 
41
 
 
42
end_per_suite(_Config) ->
 
43
    ok.
 
44
 
 
45
init_per_testcase(_Case, Config) ->
 
46
    Dog = ?t:timetrap(?t:minutes(0.25)),
 
47
    [{watchdog, Dog}|Config].
 
48
 
 
49
end_per_testcase(_Case, Config) ->
 
50
    Dog = ?config(watchdog, Config),
 
51
    test_server:timetrap_cancel(Dog),
 
52
    ok.
 
53
 
 
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),
 
57
 
 
58
    ?line ok = erl_global_register(P, Fd, ?GLOBAL_NAME),
 
59
    ?line ok = erl_global_unregister(P, Fd, ?GLOBAL_NAME),
 
60
 
 
61
    ?line 0 = erl_close_connection(P,Fd),
 
62
    ?line runner:send_eot(P),
 
63
    ?line runner:recv_eot(P),
 
64
    ok.
 
65
 
 
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),
 
69
 
 
70
    ?line Self = self(),
 
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),
 
77
    ok.
 
78
 
 
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),
 
82
 
 
83
    ?line Self = self(),
 
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),
 
93
    ok.
 
94
 
 
95
%%% Interface functions for erl_interface functions.
 
96
 
 
97
erl_connect(P, Node, Num, Cookie, Creation) ->
 
98
    send_command(P, erl_connect, [Num, Node, Cookie, Creation]),
 
99
    case get_term(P) of
 
100
        {term,{Fd,_}} when Fd >= 0 -> {ok,Fd};
 
101
        {term,{-1,Errno}} -> {error,Errno}
 
102
    end.
 
103
 
 
104
erl_close_connection(P, FD) ->
 
105
    send_command(P, erl_close_connection, [FD]),
 
106
    case get_term(P) of
 
107
        {term,Int} when is_integer(Int) -> Int
 
108
    end.
 
109
 
 
110
erl_global_register(P, Fd, Name) ->
 
111
    send_command(P, erl_global_register, [Fd,Name]),
 
112
    get_send_result(P).
 
113
 
 
114
erl_global_whereis(P, Fd, Name) ->
 
115
    send_command(P, erl_global_whereis, [Fd,Name]),
 
116
    case get_term(P) of
 
117
        {term, What} ->
 
118
            What
 
119
    end.
 
120
 
 
121
erl_global_names(P, Fd) ->
 
122
    send_command(P, erl_global_names, [Fd]),
 
123
    case get_term(P) of
 
124
        {term, What} ->
 
125
            What
 
126
    end.
 
127
 
 
128
erl_global_unregister(P, Fd, Name) ->
 
129
    send_command(P, erl_global_unregister, [Fd,Name]),
 
130
    get_send_result(P).
 
131
 
 
132
get_send_result(P) ->
 
133
    case get_term(P) of
 
134
        {term,{1,_}} -> ok;
 
135
        {term,{0, 0}} -> ok;
 
136
        {term,{-1, Errno}} -> {error,Errno};
 
137
        {term,{_,_}}->
 
138
            ?t:fail(bad_return_value)
 
139
    end.
 
140
 
 
141
send_command(P, Name, Args) ->
 
142
    runner:send_term(P, {Name,list_to_tuple(Args)}).