2
|
1 |
/*
|
|
2 |
* Copyright 2000-2001 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @test
|
|
26 |
* @bug 4329140
|
|
27 |
* @author Robert Field
|
|
28 |
*
|
|
29 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter
|
|
30 |
* @run compile -g InstTarg.java
|
|
31 |
* @run main ConnectedVMs InstTarg
|
|
32 |
*
|
|
33 |
* @summary ConnectedVMs checks the method
|
|
34 |
* VirtualMachineManager.connectedVirtualMachines()
|
|
35 |
*/
|
|
36 |
import com.sun.jdi.*;
|
|
37 |
import com.sun.jdi.event.*;
|
|
38 |
import com.sun.jdi.request.*;
|
|
39 |
import java.util.List;
|
|
40 |
|
|
41 |
public class ConnectedVMs extends TestScaffold {
|
|
42 |
static int failCount = 0;;
|
|
43 |
static int pass;
|
|
44 |
static String[] passNames = {"Kill", "Resume to exit",
|
|
45 |
"dispose()", "exit()"};
|
|
46 |
|
|
47 |
public static void main(String args[]) throws Exception {
|
|
48 |
for (pass=0; pass < passNames.length; pass++) {
|
|
49 |
new ConnectedVMs(args).startTests();
|
|
50 |
}
|
|
51 |
if (failCount > 0) {
|
|
52 |
throw new RuntimeException(
|
|
53 |
"VirtualMachineManager.connectedVirtualMachines() " +
|
|
54 |
failCount + " tests failed");
|
|
55 |
} else {
|
|
56 |
System.out.println(
|
|
57 |
"VirtualMachineManager.connectedVirtualMachines() tests passed");
|
|
58 |
}
|
|
59 |
}
|
|
60 |
|
|
61 |
ConnectedVMs(String args[]) throws Exception {
|
|
62 |
super(args);
|
|
63 |
System.out.println("create");
|
|
64 |
}
|
|
65 |
|
|
66 |
void vms(int expected) {
|
|
67 |
List vms = Bootstrap.virtualMachineManager().
|
|
68 |
connectedVirtualMachines();
|
|
69 |
if (vms.size() != expected) {
|
|
70 |
System.out.println("FAILURE! " + passNames[pass] +
|
|
71 |
" - expected: " + expected +
|
|
72 |
", got: " + vms.size());
|
|
73 |
++failCount;
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
protected void runTests() throws Exception {
|
|
78 |
System.out.println("Testing " + passNames[pass]);
|
|
79 |
vms(0);
|
|
80 |
startToMain("InstTarg");
|
|
81 |
ThreadReference thread = waitForVMStart();
|
|
82 |
StepEvent stepEvent = stepIntoLine(thread);
|
|
83 |
vms(1);
|
|
84 |
|
|
85 |
// pick a way to die
|
|
86 |
switch (pass) {
|
|
87 |
case 0:
|
|
88 |
vm().process().destroy();
|
|
89 |
break;
|
|
90 |
case 1:
|
|
91 |
vm().resume();
|
|
92 |
break;
|
|
93 |
case 2:
|
|
94 |
vm().dispose();
|
|
95 |
break;
|
|
96 |
case 3:
|
|
97 |
vm().exit(1);
|
|
98 |
break;
|
|
99 |
}
|
|
100 |
|
|
101 |
resumeToVMDisconnect();
|
|
102 |
vms(0);
|
|
103 |
}
|
|
104 |
}
|