Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/ConnectedVMs.java
38855 views
/*1* Copyright (c) 2000, 2012, 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* @author Robert Field27*28* @run build TestScaffold VMConnection TargetListener TargetAdapter29* @run compile -g InstTarg.java30* @run main ConnectedVMs Kill31* @run main ConnectedVMs Resume-to-exit32* @run main ConnectedVMs dispose()33* @run main ConnectedVMs exit()34*35* @summary ConnectedVMs checks the method36* VirtualMachineManager.connectedVirtualMachines()37*/38import com.sun.jdi.*;39import com.sun.jdi.event.*;40import com.sun.jdi.request.*;41import java.util.List;4243public class ConnectedVMs extends TestScaffold {44static int failCount = 0;;45static String passName;4647public static void main(String args[]) throws Exception {48new ConnectedVMs(args[0]).startTests();49if (failCount > 0) {50throw new RuntimeException(51"VirtualMachineManager.connectedVirtualMachines() " +52failCount + " tests failed");53} else {54System.out.println(55"VirtualMachineManager.connectedVirtualMachines() tests passed");56}57}5859ConnectedVMs(String name) throws Exception {60super(new String[0]);61passName = name;62System.out.println("create " + passName);63}6465void vms(int expected) {66List vms = Bootstrap.virtualMachineManager().67connectedVirtualMachines();68if (vms.size() != expected) {69System.out.println("FAILURE! " + passName +70" - expected: " + expected +71", got: " + vms.size());72++failCount;73}74}7576protected void runTests() throws Exception {77System.out.println("Testing " + passName);78vms(0);79startToMain("InstTarg");80ThreadReference thread = waitForVMStart();81StepEvent stepEvent = stepIntoLine(thread);82vms(1);8384// pick a way to die based on the input arg.85if (passName.equals("Kill")) {86vm().process().destroy();87} else if (passName.equals("Resume-to-exit")) {88vm().resume();89} else if (passName.equals("dispose()")) {90vm().dispose();91} else if (passName.equals("exit()")) {92vm().exit(1);93} else {94throw new Exception("Unknown pass name");95}9697resumeToVMDisconnect();98vms(0);99}100}101102103