Path: blob/master/test/jdk/com/sun/jdi/ConnectedVMs.java
41149 views
/*1* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 432914026* @summary ConnectedVMs checks the method27* VirtualMachineManager.connectedVirtualMachines()28* @author Robert Field29*30* @run build TestScaffold VMConnection TargetListener TargetAdapter31* @run compile -g InstTarg.java32* @run driver ConnectedVMs Kill33* @run driver ConnectedVMs Resume-to-exit34* @run driver ConnectedVMs dispose()35* @run driver ConnectedVMs exit()36*/37import com.sun.jdi.*;38import com.sun.jdi.event.*;39import com.sun.jdi.request.*;40import java.util.List;4142public class ConnectedVMs extends TestScaffold {43static int failCount = 0;;44static String passName;4546public static void main(String args[]) throws Exception {47new ConnectedVMs(args[0]).startTests();48if (failCount > 0) {49throw new RuntimeException(50"VirtualMachineManager.connectedVirtualMachines() " +51failCount + " tests failed");52} else {53System.out.println(54"VirtualMachineManager.connectedVirtualMachines() tests passed");55}56}5758ConnectedVMs(String name) throws Exception {59super(new String[0]);60passName = name;61System.out.println("create " + passName);62}6364void vms(int expected) {65List vms = Bootstrap.virtualMachineManager().66connectedVirtualMachines();67if (vms.size() != expected) {68System.out.println("FAILURE! " + passName +69" - expected: " + expected +70", got: " + vms.size());71++failCount;72}73}7475protected void runTests() throws Exception {76System.out.println("Testing " + passName);77vms(0);78startToMain("InstTarg");79ThreadReference thread = waitForVMStart();80StepEvent stepEvent = stepIntoLine(thread);81vms(1);8283// pick a way to die based on the input arg.84if (passName.equals("Kill")) {85vm().process().destroy();86} else if (passName.equals("Resume-to-exit")) {87vm().resume();88} else if (passName.equals("dispose()")) {89vm().dispose();90} else if (passName.equals("exit()")) {91vm().exit(1);92} else {93throw new Exception("Unknown pass name");94}9596resumeToVMDisconnect();97vms(0);98}99}100101102