Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine01/VirtualMachine01.java
41160 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/VirtualMachine/VirtualMachine01.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* Test checks that methods of VirtualMachine throws expected exceptions33* in following cases:34* - VirtualMachine.attach(null) should throw NullPointerException35* - VirtualMachine.attach(<invalid vm id>) should throw AttachNotSupportedException36* - VirtualMachine.loadAgent(null), VirtualMachine.loadAgentLibrary(null),37* VirtualMachine.loadAgentPath(null) should throw NullPointerException38*39* @library /vmTestbase /test/hotspot/jtreg/vmTestbase40* /test/lib41* @build nsk.share.aod.DummyTargetApplication42* @run main/othervm43* -XX:+UsePerfData44* nsk.aod.VirtualMachine.VirtualMachine01.VirtualMachine0145* -jdk ${test.jdk}46* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"47* -target nsk.share.aod.DummyTargetApplication48*/4950package nsk.aod.VirtualMachine.VirtualMachine01;5152import com.sun.tools.attach.AttachNotSupportedException;53import com.sun.tools.attach.VirtualMachine;54import com.sun.tools.attach.VirtualMachineDescriptor;55import com.sun.tools.attach.spi.AttachProvider;56import nsk.share.aod.AODTestRunner;57import nsk.share.test.TestUtils;5859/*60* Test provokes exception which should be thrown by VirtualMachine methods:61* - VirtualMachine.attach(null) should throw NullPointerException62* - VirtualMachine.attach(<invalid vm id>) should throw AttachNotSupportedException63* - VirtualMachine.loadAgent(null), VirtualMachine.loadAgentLibrary(null),64* VirtualMachine.loadAgentPath(null) should throw NullPointerException65*/66public class VirtualMachine01 extends AODTestRunner {6768VirtualMachine01(String[] args) {69super(args);70}7172public void doTestActions(String targetVMId) throws Throwable {73try {74log.display("VirtualMachine.attach((String)null)");75VirtualMachine.attach((String) null);76TestUtils.testFailed("NullPointerException wasn't thrown");77} catch (NullPointerException e) {78log.display("Expected exception: " + e);79}8081try {82log.display("VirtualMachine.attach((VirtualMachineDescriptor)null)");83VirtualMachine.attach((VirtualMachineDescriptor) null);84TestUtils.testFailed("NullPointerException wasn't thrown");85} catch (NullPointerException e) {86log.display("Expected exception: " + e);87}8889final String invalidVMId = "InvalidID";9091try {92log.display("VirtualMachine.attach(" + invalidVMId + ")");93VirtualMachine.attach(invalidVMId);94TestUtils.testFailed("AttachNotSupportedException wasn't thrown");95} catch (AttachNotSupportedException e) {96log.display("Expected exception: " + e);97}9899try {100TestUtils.assertTrue(AttachProvider.providers().size() > 0, "AttachProvider.providers() returns empty list");101log.display("Create VirtualMachineDescriptor using provider '" + AttachProvider.providers().get(0) + "'");102VirtualMachineDescriptor vmd = new VirtualMachineDescriptor(AttachProvider.providers().get(0), invalidVMId);103log.display("VirtualMachine.attach(new VirtualMachineDescriptor(provider, " + invalidVMId + "))");104VirtualMachine.attach(vmd);105TestUtils.testFailed("AttachNotSupportedException wasn't thrown");106} catch (AttachNotSupportedException e) {107log.display("Expected exception: " + e);108}109110// create VirtualMachine object VM to check non-static methods111112VirtualMachine vm = VirtualMachine.attach(targetVMId);113try {114try {115log.display("VirtualMachine.loadAgent(null)");116vm.loadAgent(null);117TestUtils.testFailed("NullPointerException wasn't thrown");118} catch (NullPointerException e) {119log.display("Expected exception: " + e);120}121122try {123log.display("VirtualMachine.loadAgent(null, null)");124vm.loadAgent(null, null);125TestUtils.testFailed("NullPointerException wasn't thrown");126} catch (NullPointerException e) {127log.display("Expected exception: " + e);128}129130try {131log.display("VirtualMachine.loadAgentLibrary(null)");132vm.loadAgentLibrary(null);133TestUtils.testFailed("NullPointerException wasn't thrown");134} catch (NullPointerException e) {135log.display("Expected exception: " + e);136}137138try {139log.display("VirtualMachine.loadAgentLibrary(null, null)");140vm.loadAgentLibrary(null, null);141TestUtils.testFailed("NullPointerException wasn't thrown");142} catch (NullPointerException e) {143log.display("Expected exception: " + e);144}145146try {147log.display("VirtualMachine.loadAgentPath(null)");148vm.loadAgentPath(null);149TestUtils.testFailed("NullPointerException wasn't thrown");150} catch (NullPointerException e) {151log.display("Expected exception: " + e);152}153154try {155log.display("VirtualMachine.loadAgentPath(null, null)");156vm.loadAgentPath(null, null);157TestUtils.testFailed("NullPointerException wasn't thrown");158} catch (NullPointerException e) {159log.display("Expected exception: " + e);160}161162} finally {163vm.detach();164}165}166167public static void main(String[] args) {168new VirtualMachine01(args).runTest();169}170171}172173174