Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VirtualMachine06.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/VirtualMachine06.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 methods VirtualMachine.loadAgent(String agent) and33* VirtualMachine.loadAgent(String agent, String options).34* Test checks following cases:35* - it is possible to pass options to agent using loadAgent(String agent, String options)36* - it is possible to specify null options (in this case null is passed to the agentmain)37* - if agent throws exception from 'agentmain' VirtualMachine.loadAgent throws AgentInitializationException38*39* @library /vmTestbase /test/hotspot/jtreg/vmTestbase40* /test/lib41*42*43* @comment compile VM06Agent0[0-3].java to current directory44* @build nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent0045* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent0146* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent0247* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent0348* @run driver jdk.test.lib.helpers.ClassFileInstaller49* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent0050* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent0151* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent0252* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent0353*54* @comment create VM06Agent0[0-3].jar in current directory55* @run driver ExecDriver --cmd56* ${test.jdk}/bin/jar57* -cmf ${test.src}/VM06Agent00.mf58* VM06Agent00.jar59* nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent00.class60* @run driver ExecDriver --cmd61* ${test.jdk}/bin/jar62* -cmf ${test.src}/VM06Agent01.mf63* VM06Agent01.jar64* nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent01.class65* @run driver ExecDriver --cmd66* ${test.jdk}/bin/jar67* -cmf ${test.src}/VM06Agent02.mf68* VM06Agent02.jar69* nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent02.class70* @run driver ExecDriver --cmd71* ${test.jdk}/bin/jar72* -cmf ${test.src}/VM06Agent03.mf73* VM06Agent03.jar74* nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent03.class75*76*77* @build nsk.share.aod.TargetApplicationWaitingAgents78* @run main/othervm79* -XX:+UsePerfData80* nsk.aod.VirtualMachine.VirtualMachine06.VirtualMachine0681* -jdk ${test.jdk}82* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"83* -target nsk.share.aod.TargetApplicationWaitingAgents84* -ja VM06Agent00.jar,VM06Agent01.jar,VM06Agent02.jar,VM06Agent03.jar85*/8687package nsk.aod.VirtualMachine.VirtualMachine06;8889import com.sun.tools.attach.AgentInitializationException;90import com.sun.tools.attach.VirtualMachine;91import nsk.share.TestBug;92import nsk.share.aod.AODTestRunner;93import nsk.share.aod.AgentInformation;94import nsk.share.test.TestUtils;9596import java.util.List;9798/*99* Test checks following methods:100* - VirtualMachine.loadAgent(String)101* - VirtualMachine.loadAgent(String, String)102*/103public class VirtualMachine06 extends AODTestRunner {104105public VirtualMachine06(String[] args) {106super(args);107}108109public void doTestActions(String targetVMId) throws Throwable {110// check that all required parameters were passed to the test111List<AgentInformation> agents = argParser.getAgents();112if (agents.size() != 4) {113throw new TestBug("Test requires 4 agents, actually " + agents.size() + " were specified");114}115for (AgentInformation agent : agents) {116if (!agent.jarAgent) {117throw new TestBug("Non JAR agent was specified");118}119}120121VirtualMachine vm = VirtualMachine.attach(targetVMId);122123try {124AgentInformation agent;125126agent = agents.get(0);127log.display("Loading '" + agent.pathToAgent + "'");128// pass null options to agent129vm.loadAgent(agent.pathToAgent);130131agent = agents.get(1);132log.display("Loading '" + agent.pathToAgent + "'");133// pass null options to agent134vm.loadAgent(agent.pathToAgent, null);135136agent = agents.get(2);137log.display("Loading '" + agent.pathToAgent + "'");138// pass non-null options to agent139vm.loadAgent(agent.pathToAgent, "VirtualMachine06_TestOptions");140141agent = agents.get(3);142log.display("Loading '" + agent.pathToAgent + "' (this agent throws exception from agentmain)");143try {144// check agent throwing exception from agentmain145vm.loadAgent(agent.pathToAgent);146TestUtils.testFailed("Expected AgentInitializationException wasn't thrown");147} catch (AgentInitializationException e) {148// expected exception149}150} finally {151vm.detach();152}153}154155public static void main(String[] args) {156new VirtualMachine06(args).runTest();157}158}159160161