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