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

« back to all changes in this revision

Viewing changes to lib/jinterface/test/jinterface_SUITE_data/MboxLinkUnlink.java

  • 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 2004-2010. 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
import com.ericsson.otp.erlang.*;
 
21
 
 
22
class MboxLinkUnlink {
 
23
 
 
24
    /*
 
25
      Implements test case jinterface_SUITE:mbox_link_unlink/1
 
26
 
 
27
 
 
28
 
 
29
    */
 
30
 
 
31
    private static final int java_link_and_exit = 1;
 
32
    private static final int erl_link_and_exit = 2;
 
33
    private static final int erl_link_java_exit = 3;
 
34
    private static final int java_link_erl_exit = 4;
 
35
    private static final int internal_link_linking_exits = 5;
 
36
    private static final int internal_link_linked_exits = 6;
 
37
    private static final int internal_unlink_linking_exits = 7;
 
38
    private static final int internal_unlink_linked_exits = 8;
 
39
    private static final int normal_exit = 9;
 
40
    private static final int kill_mbox = 10;
 
41
    private static final int kill_erl_proc_from_java = 11;
 
42
    private static final int kill_mbox_from_erlang = 12;
 
43
    private static final int erl_exit_with_reason_any_term = 13;
 
44
    private static final int java_exit_with_reason_any_term = 14;
 
45
 
 
46
    private static boolean dbg = true;
 
47
 
 
48
 
 
49
    public static void main(String argv[]) {
 
50
 
 
51
 
 
52
        //String cookie = argv[0];
 
53
        String erlNode = argv[1];
 
54
        OtpErlangObject expected = null;
 
55
        boolean waiting = false;
 
56
 
 
57
        try { //
 
58
            OtpNode node = new OtpNode("javanode");
 
59
            OtpMbox mainMbox = node.createMbox();
 
60
 
 
61
            try {
 
62
                // Initiate and set up connection to erlang process
 
63
                OtpMbox mbox = node.createMbox();
 
64
                OtpMbox mbox2;
 
65
 
 
66
                OtpErlangObject[] msg = {mainMbox.self(),mbox.self()};
 
67
                mbox.send("erl_link_server", erlNode, new OtpErlangTuple(msg));
 
68
                OtpErlangObject o = mbox.receive(1000);
 
69
                if (o == null) System.exit(1);
 
70
                OtpErlangTuple tuple = (OtpErlangTuple)o;
 
71
                int tag = (int)((OtpErlangLong)tuple.elementAt(0)).longValue();
 
72
 
 
73
                switch (tag) {
 
74
 
 
75
                case java_exit_with_reason_any_term:
 
76
                case java_link_and_exit:
 
77
                    dbg("Java got \"java_link_and_exit\" or " +
 
78
                        "\"java_exit_with_reason_any_term\"");
 
79
                    mbox.link((OtpErlangPid)tuple.elementAt(1));
 
80
                    mbox.send((OtpErlangPid)tuple.elementAt(1),
 
81
                              new OtpErlangAtom("ok"));
 
82
                    mbox.exit(tuple.elementAt(2));
 
83
                    break;
 
84
                case erl_exit_with_reason_any_term:
 
85
                case erl_link_and_exit:
 
86
                    dbg("Java got \"erl_link_and_exit\" or " +
 
87
                        "\"erl_exit_with_reason_any_term\"");
 
88
                    mbox.send((OtpErlangPid)tuple.elementAt(1),
 
89
                              new OtpErlangAtom("ok"));
 
90
                    waiting = true;
 
91
                    expected = tuple.elementAt(2);
 
92
                    mbox.receive(1000);
 
93
                    System.exit(2);
 
94
                case erl_link_java_exit:
 
95
                    dbg("Java got \"erl_link_java_exit\"");
 
96
                    mbox.exit(tuple.elementAt(2));
 
97
                    break;
 
98
                case java_link_erl_exit:
 
99
                    dbg("Java got \"java_link_erl_exit\"");
 
100
                    mbox.link((OtpErlangPid)tuple.elementAt(1));
 
101
                    mbox.send((OtpErlangPid)tuple.elementAt(1),
 
102
                              new OtpErlangAtom("ok"));
 
103
                    waiting = true;
 
104
                    expected = tuple.elementAt(2);
 
105
                    mbox.receive(1000);
 
106
                    System.exit(3);
 
107
                case internal_link_linking_exits:
 
108
                    dbg("Java got \"internal_link_linking_exits\"");
 
109
                    mbox2 = node.createMbox();
 
110
                    mbox.link(mbox2.self());
 
111
                    mbox.exit(tuple.elementAt(2));
 
112
                    waiting = true;
 
113
                    expected = tuple.elementAt(2);
 
114
                    mbox2.receive(1000); // hanging waiting for exit
 
115
                    System.exit(4);  // got someting other than exit
 
116
                case internal_link_linked_exits:
 
117
                    dbg("Java got \"internal_link_linked_exits\"");
 
118
                    mbox2 = node.createMbox();
 
119
                    mbox.link(mbox2.self());
 
120
                    mbox2.exit(tuple.elementAt(2));
 
121
                    waiting = true;
 
122
                    expected = tuple.elementAt(2);
 
123
                    mbox.receive(1000); // hanging waiting for exit
 
124
                    System.exit(5);  // got someting other than exit
 
125
                case internal_unlink_linking_exits:
 
126
                    dbg("Java got \"internal_unlink_linking_exits\"");
 
127
                    mbox2 = node.createMbox();
 
128
                    mbox.link(mbox2.self());
 
129
                    mbox.unlink(mbox2.self());
 
130
                    mbox.link(mbox2.self());
 
131
                    mbox2.unlink(mbox.self());
 
132
                    mbox2.exit(tuple.elementAt(2));
 
133
                    if (mbox.receive(500)!=null) System.exit(6);
 
134
                    break;
 
135
                case internal_unlink_linked_exits:
 
136
                    dbg("Java got \"internal_unlink_linked_exits\"");
 
137
                    mbox2 = node.createMbox();
 
138
                    mbox.link(mbox2.self());
 
139
                    mbox.unlink(mbox2.self());
 
140
                    mbox.link(mbox2.self());
 
141
                    mbox2.unlink(mbox.self());
 
142
                    mbox.exit(tuple.elementAt(2));
 
143
                    if (mbox2.receive(500)!=null) System.exit(7);
 
144
                    break;
 
145
                case normal_exit:
 
146
                    dbg("Java got \"normal_exit\"");
 
147
                    mbox.close();
 
148
                    break;
 
149
                case kill_mbox:
 
150
                    dbg("Java got \"kill_mbox\"");
 
151
                    mbox.exit("kill");
 
152
                    break;
 
153
                case kill_erl_proc_from_java:
 
154
                    dbg("Java got \"kill_erl_proc_from_java\"");
 
155
                    mbox.exit((OtpErlangPid)tuple.elementAt(1),"kill");
 
156
                    break;
 
157
                case kill_mbox_from_erlang:
 
158
                    dbg("Java got \"kill_mbox_from_erlang\"");
 
159
                    /* This will make the testcase successful, but it is
 
160
                       not the correct way to do it...
 
161
                       Mbox should probably just die when the kill signal is
 
162
                       received from erlang (or other mbox).
 
163
 
 
164
                    try {
 
165
                        mbox.receive(1000);
 
166
                        System.exit(8);
 
167
                    }
 
168
                    catch (OtpErlangExit exit) {
 
169
                        if(!(exit.reason().equals(new OtpErlangAtom("kill"))))
 
170
                            System.exit(9);
 
171
                        mbox.exit("killed");
 
172
                    }
 
173
                    */
 
174
                    break;
 
175
                }
 
176
            }
 
177
            catch (OtpErlangExit exit) {
 
178
                dbg("Java got exit: " + exit.reason());
 
179
                if(!(waiting && exit.reason().equals(expected)))
 
180
                    System.exit(10);
 
181
            }
 
182
 
 
183
            OtpErlangAtom done = new OtpErlangAtom("done");
 
184
            mainMbox.send("erl_link_server", erlNode, done);
 
185
            OtpErlangObject o = mainMbox.receive(1000);
 
186
            if (o == null) System.exit(11);
 
187
            else if (!((OtpErlangAtom)o).equals(done))
 
188
                System.exit(12);
 
189
 
 
190
        }
 
191
        catch (Exception e) {
 
192
            System.out.println("EXCEPTION: " + e);
 
193
            System.exit(13);
 
194
        }
 
195
    }
 
196
 
 
197
    private static void dbg(String str) {
 
198
        if (dbg) System.out.println(str);
 
199
    }
 
200
 
 
201
}