Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider01/AttachProvider01.java
41161 views
/*1* Copyright (c) 2008, 2020, 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*26* @summary converted from VM Testbase nsk/aod/AttachProvider/AttachProvider01.27* VM Testbase keywords: [feature_282, jdk]28* VM Testbase readme:29* Description :30* Test checks work of Attach API (com.sun.tools.attach).31* Test is based on the nsk.share.aod framework.32* This test checks that method AttachProvider.listVirtualMachines() returns33* VirtualMachineDescriptors for 2 VMs started by this test.34*35* @library /vmTestbase /test/hotspot/jtreg/vmTestbase36* /test/lib37* @build nsk.share.aod.DummyTargetApplication38* @run main/othervm39* -XX:+UsePerfData40* nsk.aod.AttachProvider.AttachProvider01.AttachProvider0141* -jdk ${test.jdk}42* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"43* -target nsk.share.aod.DummyTargetApplication44*/4546package nsk.aod.AttachProvider.AttachProvider01;4748import com.sun.tools.attach.VirtualMachine;49import com.sun.tools.attach.VirtualMachineDescriptor;50import com.sun.tools.attach.spi.AttachProvider;51import nsk.share.aod.AODTestRunner;52import nsk.share.test.TestUtils;5354import java.util.List;5556/*57* Test checks method AttachProvider.listVirtualMachines()58* (test checks that collection returned by AttachProvider.listVirtualMachines() contains current VM59* and another VM started by this test)60*/61public class AttachProvider01 extends AODTestRunner {6263public AttachProvider01(String[] args) {64super(args);65}6667public void doTestActions(String targetVMId) {68String currentVMId = getCurrentVMId();6970for (AttachProvider provider : AttachProvider.providers()) {71log.display("Checking AttachProvider.listVirtualMachines() (provider: " + provider + ")");72checkList(provider.listVirtualMachines(), currentVMId, targetVMId);73}74}7576private void checkList(List<VirtualMachineDescriptor> vmDescriptors, String currentVMId, String targetVMId) {77VirtualMachineDescriptor currentVMDesc = null;78VirtualMachineDescriptor targetVMDesc = null;7980for (VirtualMachineDescriptor vmDescriptor : VirtualMachine.list()) {81log.display("VirtualMachineDescriptor: " + vmDescriptor);8283if (vmDescriptor.id().equals(currentVMId)) {84currentVMDesc = vmDescriptor;85} else if (vmDescriptor.id().equals(targetVMId)) {86targetVMDesc = vmDescriptor;87}88}8990TestUtils.assertNotNull(currentVMDesc, "VirtualMachine.list() didn't return descriptor for the current VM");91TestUtils.assertNotNull(targetVMDesc, "VirtualMachine.list() didn't return descriptor for VM with id '" +92targetVMId + "'");93}9495public static void main(String[] args) {96new AttachProvider01(args).runTest();97}98}99100101