50018
|
1 |
/*
|
|
2 |
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
package nsk.jdi.EventQueue.remove_l;
|
|
25 |
|
|
26 |
import com.sun.jdi.VirtualMachine;
|
|
27 |
import com.sun.jdi.request.EventRequest;
|
|
28 |
import com.sun.jdi.VMDisconnectedException;
|
|
29 |
import com.sun.jdi.event.*;
|
|
30 |
|
|
31 |
import java.io.*;
|
|
32 |
|
|
33 |
import nsk.share.*;
|
|
34 |
import nsk.share.jpda.*;
|
|
35 |
import nsk.share.jdi.*;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* The test checks that a VMDisconnectedException thrown by
|
|
39 |
* the JDI method <b>com.sun.jdi.request.EventQueue.remove(int)</b>
|
|
40 |
* will be preceded by a <code>VMDisconnectEvent</code>
|
|
41 |
* after <code>com.sun.jdi.VirtualMachine.exit()</code> call.
|
|
42 |
*/
|
|
43 |
public class remove_l003 {
|
|
44 |
public static final int PASSED = 0;
|
|
45 |
public static final int FAILED = 2;
|
|
46 |
public static final int JCK_STATUS_BASE = 95;
|
|
47 |
static final String DEBUGGEE_CLASS =
|
|
48 |
"nsk.jdi.EventQueue.remove_l.remove_l003t";
|
|
49 |
static final String COMMAND_READY = "ready";
|
|
50 |
static final String COMMAND_QUIT = "quit";
|
|
51 |
|
|
52 |
private ArgumentHandler argHandler;
|
|
53 |
private Log log;
|
|
54 |
private IOPipe pipe;
|
|
55 |
private Debugee debuggee;
|
|
56 |
private CheckEvents chkEvents;
|
|
57 |
private EventQueue eventQ;
|
|
58 |
private volatile int tot_res = FAILED;
|
|
59 |
|
|
60 |
public static void main(String argv[]) {
|
|
61 |
System.exit(run(argv,System.out) + JCK_STATUS_BASE);
|
|
62 |
}
|
|
63 |
|
|
64 |
public static int run(String argv[], PrintStream out) {
|
|
65 |
return new remove_l003().runIt(argv, out);
|
|
66 |
}
|
|
67 |
|
|
68 |
private int runIt(String args[], PrintStream out) {
|
|
69 |
argHandler = new ArgumentHandler(args);
|
|
70 |
log = new Log(out, argHandler);
|
|
71 |
Binder binder = new Binder(argHandler, log);
|
|
72 |
|
|
73 |
debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);
|
|
74 |
debuggee.redirectStderr(log, "remove_l003t.err> ");
|
|
75 |
pipe = debuggee.createIOPipe();
|
|
76 |
VirtualMachine vm = debuggee.VM();
|
|
77 |
|
|
78 |
eventQ = vm.eventQueue();
|
|
79 |
chkEvents = new CheckEvents();
|
|
80 |
chkEvents.setDaemon(true);
|
|
81 |
chkEvents.start();
|
|
82 |
|
|
83 |
debuggee.resume();
|
|
84 |
String cmd = pipe.readln();
|
|
85 |
if (!cmd.equals(COMMAND_READY)) {
|
|
86 |
log.complain("TEST BUG: unknown debuggee's command: " + cmd);
|
|
87 |
tot_res = FAILED;
|
|
88 |
return quitDebuggee(FAILED);
|
|
89 |
}
|
|
90 |
|
|
91 |
log.display("Invoking VirtualMachine.exit() ...");
|
|
92 |
vm.exit(JCK_STATUS_BASE + PASSED);
|
|
93 |
|
|
94 |
return quitDebuggee(PASSED);
|
|
95 |
}
|
|
96 |
|
|
97 |
class CheckEvents extends Thread {
|
|
98 |
public void run() {
|
|
99 |
boolean gotVMDisconnect = false; // VMDisconnectEvent is received
|
|
100 |
boolean gotVMDeath = false; // VMDeathEvent is received
|
|
101 |
EventSet eventSet = null;
|
|
102 |
|
|
103 |
log.display("CheckEvents: starts JDI events processing");
|
|
104 |
while (true) {
|
|
105 |
try {
|
|
106 |
eventSet = eventQ.remove(argHandler.getWaitTime()*30000);
|
|
107 |
if (eventSet == null) {
|
|
108 |
log.display("CheckEvents: specified time for the next available event has elapsed");
|
|
109 |
continue;
|
|
110 |
}
|
|
111 |
EventIterator eventIter = eventSet.eventIterator();
|
|
112 |
while (eventIter.hasNext()) {
|
|
113 |
Event event = eventIter.nextEvent();
|
|
114 |
if (event instanceof VMDisconnectEvent) {
|
|
115 |
gotVMDisconnect = true;
|
|
116 |
log.display("CheckEvents: got expected VMDisconnectEvent");
|
|
117 |
break;
|
|
118 |
} else if (event instanceof VMStartEvent) {
|
|
119 |
log.display("CheckEvents: got VMStartEvent");
|
|
120 |
} else if (event instanceof VMDeathEvent) {
|
|
121 |
gotVMDeath = true;
|
|
122 |
log.display("CheckEvents: got VMDeathEvent");
|
|
123 |
}
|
|
124 |
if (!gotVMDisconnect && !gotVMDeath &&
|
|
125 |
eventSet.suspendPolicy() !=
|
|
126 |
EventRequest.SUSPEND_NONE) {
|
|
127 |
log.display("CheckEvents: calling EventSet.resume() ...");
|
|
128 |
eventSet.resume();
|
|
129 |
}
|
|
130 |
}
|
|
131 |
} catch(InterruptedException e) {
|
|
132 |
log.complain("TEST INCOMPLETE: caught " + e);
|
|
133 |
tot_res = FAILED;
|
|
134 |
} catch(VMDisconnectedException e) {
|
|
135 |
if (gotVMDisconnect) {
|
|
136 |
log.display("\nCHECK PASSED: caught expected VMDisconnectedException preceded by a VMDisconnectEvent\n");
|
|
137 |
tot_res = PASSED;
|
|
138 |
} else {
|
|
139 |
log.complain("\nTEST FAILED: caught VMDisconnectedException without preceding VMDisconnectEvent\n");
|
|
140 |
e.printStackTrace();
|
|
141 |
tot_res = FAILED;
|
|
142 |
}
|
|
143 |
break;
|
|
144 |
}
|
|
145 |
}
|
|
146 |
log.display("CheckEvents: stopped JDI events processing");
|
|
147 |
}
|
|
148 |
}
|
|
149 |
|
|
150 |
private int quitDebuggee(int stat) {
|
|
151 |
if (chkEvents != null) {
|
|
152 |
try {
|
|
153 |
if (chkEvents.isAlive())
|
|
154 |
chkEvents.join(argHandler.getWaitTime()*60000);
|
|
155 |
} catch (InterruptedException e) {
|
|
156 |
log.complain("TEST INCOMPLETE: caught InterruptedException "
|
|
157 |
+ e);
|
|
158 |
tot_res = FAILED;
|
|
159 |
}
|
|
160 |
if (chkEvents.isAlive()) {
|
|
161 |
if (stat == PASSED) {
|
|
162 |
log.complain("TEST FAILED: CheckEvents thread is still alive,\n"
|
|
163 |
+ "\tbut it should stop JDI events processing and exit");
|
|
164 |
chkEvents.interrupt();
|
|
165 |
tot_res = FAILED;
|
|
166 |
}
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
// pipe.println(COMMAND_QUIT);
|
|
171 |
debuggee.waitFor();
|
|
172 |
int debStat = debuggee.getStatus();
|
|
173 |
if (debStat != (JCK_STATUS_BASE + PASSED)) {
|
|
174 |
log.complain("TEST FAILED: debuggee's process finished with status: "
|
|
175 |
+ debStat);
|
|
176 |
tot_res = FAILED;
|
|
177 |
} else
|
|
178 |
log.display("Debuggee's process finished with status: "
|
|
179 |
+ debStat);
|
|
180 |
|
|
181 |
return tot_res;
|
|
182 |
}
|
|
183 |
}
|