Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/tools/attach/ProviderTest.java
38855 views
/*1* Copyright (c) 2005, 2013 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*/2223import java.io.File;24import jdk.testlibrary.OutputAnalyzer;25import jdk.testlibrary.JDKToolLauncher;26import jdk.testlibrary.ProcessTools;27import com.sun.tools.attach.VirtualMachine;28import com.sun.tools.attach.spi.AttachProvider;2930/*31* @test32* @bug 6173612 6273707 6277253 6335921 6348630 6342019 638175733* @summary Basic unit tests for the VM attach mechanism.34* @library /lib/testlibrary35* @build jdk.testlibrary.* SimpleProvider36* @run main ProviderTest37*38* The test will attach and detach to/from the running Application.39*/40public class ProviderTest {4142/*43* The actual tests are in the nested class TestMain below.44* The responsibility of this class is to:45* 1. Build the needed jar.46* 2. Run tests in ProviderTest.TestMain.47*/48public static void main(String args[]) throws Throwable {49try {50buildJar();51runTests();52} catch (Throwable t) {53System.out.println("TestProvider got unexpected exception: " + t);54t.printStackTrace();55throw t;56}57}5859/**60* Runs the actual tests in the nested class TestMain.61* We need to run the tests in a separate process,62* because we need to add to the classpath.63*/64private static void runTests() throws Throwable {65final String sep = File.separator;66String testClassPath = System.getProperty("test.class.path", "");67String testClasses = System.getProperty("test.classes", "") + sep;68String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep;6970// Need to add SimpleProvider.jar and tools.jar to classpath.71String classpath =72testClassPath + File.pathSeparator +73testClasses + "SimpleProvider.jar" + File.pathSeparator +74jdkLib + "tools.jar";7576String[] args = {77"-classpath",78classpath,79"ProviderTest$TestMain" };80OutputAnalyzer output = ProcessTools.executeTestJvm(args);81output.shouldHaveExitValue(0);82}8384/**85* Will build the SimpleProvider.jar.86*/87private static void buildJar() throws Throwable {88final String sep = File.separator;89String testClasses = System.getProperty("test.classes", "?") + sep;90String testSrc = System.getProperty("test.src", "?") + sep;91String serviceDir = "META-INF" + sep + "services" + sep;9293RunnerUtil.createJar(94"-cf", testClasses + "SimpleProvider.jar",95"-C", testClasses, "SimpleProvider.class",96"-C", testClasses, "SimpleVirtualMachine.class",97"-C", testSrc,98serviceDir + "com.sun.tools.attach.spi.AttachProvider");99}100101/**102* This is the actual test code that attaches to the running Application.103* This class is run in a separate process.104*/105public static class TestMain {106public static void main(String args[]) throws Exception {107// deal with internal builds where classes are loaded from the108// 'classes' directory rather than rt.jar109ClassLoader cl = AttachProvider.class.getClassLoader();110if (cl != ClassLoader.getSystemClassLoader()) {111System.out.println("Attach API not loaded by system class loader - test skipped");112return;113}114VirtualMachine.attach("simple:1234").detach();115}116}117}118119120