Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach036/attach036TestRunner.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/attach036.27* VM Testbase keywords: [jpda, jvmti, noras, feature_282, vm6, jdk]28* VM Testbase readme:29* Description :30* Test tries to load java agents to the VM after the VM has started using31* Attach API (com.sun.tools.attach).32* This is negative test, it checks that attempt to attach java agent fails if33* main agent class has no proper 'agentmain' method.34*35* @library /vmTestbase36* /test/lib37* @build nsk.jvmti.AttachOnDemand.attach036.attach036TestRunner38*39* @comment create attach036Agent00.jar in current directory40* @build nsk.jvmti.AttachOnDemand.attach036.attach036Agent0041* @run driver jdk.test.lib.helpers.ClassFileInstaller nsk.jvmti.AttachOnDemand.attach036.attach036Agent0042* @run driver ExecDriver --cmd43* ${compile.jdk}/bin/jar44* -cfm attach036Agent00.jar ${test.src}/attach036Agent00.mf45* nsk/jvmti/AttachOnDemand/attach036/attach036Agent00.class46*47* @run main/othervm48* -XX:+UsePerfData49* -Djdk.attach.allowAttachSelf50* nsk.jvmti.AttachOnDemand.attach036.attach036TestRunner51* -jdk ${test.jdk}52* -ja attach036Agent00.jar53*/5455package nsk.jvmti.AttachOnDemand.attach036;5657import com.sun.tools.attach.AgentInitializationException;58import nsk.share.*;59import nsk.share.aod.*;60import nsk.share.test.TestUtils;6162/*63* Negative test: checks that java agent fails to attach if main agent class64* has no proper agentmain method65* (test tries to attach java agent to the same VM where attach036TestRunner is running)66*/67public class attach036TestRunner extends AODTestRunner {6869public attach036TestRunner(String[] args) {70super(args);71}7273protected void runTest() {74try {75String currentVMId = getCurrentVMId();7677AgentsAttacher attacher = new AgentsAttacher(currentVMId, argParser.getAgents(), log);7879try {80attacher.attachAgents();81TestUtils.testFailed("Expected AgentLoadException wasn't thrown");82} catch (Failure failure) {83if (failure.getCause() != null) {84if (failure.getCause() instanceof AgentInitializationException)85log.display("Expected AgentInitializationException was thrown");86else87TestUtils.testFailed("Unexpected exception was thrown instead of AgentInitializationException: " + failure);88} else89throw failure;90}91} catch (Failure f) {92throw f;93} catch (Throwable t) {94TestUtils.unexpctedException(t);95}96}9798public static void main(String[] args) {99new attach036TestRunner(args).runTest();100}101}102103104