Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach001/attach001TestRunner.java
40951 views
/*1* Copyright (c) 2008, 2021, 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/jvmti/AttachOnDemand/attach001.27* VM Testbase keywords: [jpda, jvmti, noras, feature_282, vm6, jdk]28* VM Testbase readme:29* Description :30* Test tries to load java and jvmti agents to the VM after the VM has started using31* Attach API (com.sun.tools.attach).32* Test is based on the nsk.share.aod framework. In the terms of this framework33* java application running in the VM where agent is loaded to is called 'target application'.34* In this test target application tries to attach java and native agents to the same VM where target application35* is running. Test just checks that agents can connect and run (agents don't perform any specific36* checks).37*38* @library /vmTestbase39* /test/lib40* @build nsk.jvmti.AttachOnDemand.attach001.attach001TestRunner41*42* @comment create SimpleAgent00.jar in current directory43* @build nsk.jvmti.AttachOnDemand.sharedAgents.SimpleAgent0044* @run driver jdk.test.lib.helpers.ClassFileInstaller nsk.jvmti.AttachOnDemand.sharedAgents.SimpleAgent0045* @run driver ExecDriver --cmd46* ${compile.jdk}/bin/jar47* -cfm SimpleAgent00.jar ${test.src}/../sharedAgents/SimpleAgent00.mf48* nsk/jvmti/AttachOnDemand/sharedAgents/SimpleAgent00.class49*50* @run main/othervm/native51* -XX:+UsePerfData52* -Djdk.attach.allowAttachSelf53* nsk.jvmti.AttachOnDemand.attach001.attach001TestRunner54* -jdk ${test.jdk}55* -javaOpts="-XX:+UsePerfData -Djdk.attach.allowAttachSelf ${test.vm.opts} ${test.java.opts}"56* -ja SimpleAgent00.jar57* -na simpleAgent0058*/5960package nsk.jvmti.AttachOnDemand.attach001;6162import nsk.share.Failure;63import nsk.share.aod.*;64import nsk.share.test.TestUtils;6566/*67* Test tries to attach agents to the same VM where target application is running68* (test starts target application class in the separate thread instead of separate process).69*/70public class attach001TestRunner extends AODTestRunner {71attach001TestRunner(String[] args) {72super(args);73}7475class TargetThread extends Thread {76boolean finishedSuccessfully;7778public void run() {79try {80new TargetApplicationWaitingAgents().runTargetApplication(new String[] {81"-" + AODTargetArgParser.agentsNumberParam,82Integer.valueOf(argParser.getAgents().size()).toString() });8384finishedSuccessfully = true;85} catch (Throwable t) {86log.complain("Unexpected exception: " + t);87t.printStackTrace(log.getOutStream());88}89}90}9192protected void runTest() {93try {94TargetThread thread = new TargetThread();95thread.start();9697// default test actions - attach agents to the given VM98doTestActions(getCurrentVMId());99100thread.join();101102if (!thread.finishedSuccessfully) {103TestUtils.testFailed("Unexpected error during test execution (see log for details)");104}105} catch (Failure f) {106throw f;107} catch (Throwable t) {108TestUtils.unexpctedException(t);109}110}111112public static void main(String[] args) {113new attach001TestRunner(args).runTest();114}115}116117118