test/jdk/com/sun/tools/attach/ProviderTest.java
author mbaesken
Tue, 03 Sep 2019 16:52:55 +0200
changeset 58000 62926eb5e40e
parent 52731 157c1130b46e
permissions -rw-r--r--
8230485: add handling of aix tar in configure Reviewed-by: erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51541
69ee8894f5fa 8210022: remove jdk.testlibrary.ProcessThread, TestThread and XRun
iignatyev
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    24
import java.io.File;
51675
b487c1e914d0 8210112: remove jdk.testlibrary.ProcessTools
iignatyev
parents: 51541
diff changeset
    25
import jdk.test.lib.process.OutputAnalyzer;
b487c1e914d0 8210112: remove jdk.testlibrary.ProcessTools
iignatyev
parents: 51541
diff changeset
    26
import jdk.test.lib.process.ProcessTools;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import com.sun.tools.attach.VirtualMachine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.attach.spi.AttachProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    30
/*
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    31
 * @test
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    32
 * @bug 6173612 6273707 6277253 6335921 6348630 6342019 6381757
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30820
diff changeset
    33
 * @summary Basic unit tests for the VM attach mechanism. The test will attach
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30820
diff changeset
    34
 * and detach to/from the running Application.
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30820
diff changeset
    35
 *
51541
69ee8894f5fa 8210022: remove jdk.testlibrary.ProcessThread, TestThread and XRun
iignatyev
parents: 47216
diff changeset
    36
 * @library /test/lib
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30820
diff changeset
    37
 * @modules jdk.attach
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 28760
diff changeset
    38
 *          jdk.jartool/sun.tools.jar
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30820
diff changeset
    39
 *
52731
157c1130b46e 8214431: tests failed because can't find jdk.testlibrary.* in test directory or libraries
mli
parents: 51675
diff changeset
    40
 * @run build SimpleProvider
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    41
 * @run main ProviderTest
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    42
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class ProviderTest {
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    44
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    45
    /*
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    46
     * The actual tests are in the nested class TestMain below.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    47
     * The responsibility of this class is to:
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    48
     * 1. Build the needed jar.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    49
     * 2. Run tests in ProviderTest.TestMain.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    50
     */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    51
    public static void main(String args[]) throws Throwable {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    52
        try {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    53
            buildJar();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    54
            runTests();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    55
        } catch (Throwable t) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    56
            System.out.println("TestProvider got unexpected exception: " + t);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    57
            t.printStackTrace();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    58
            throw t;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    60
    }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    61
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    62
    /**
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    63
     * Runs the actual tests in the nested class TestMain.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    64
     * We need to run the tests in a separate process,
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    65
     * because we need to add to the classpath.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    66
     */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    67
    private static void runTests() throws Throwable {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    68
        final String sep = File.separator;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    69
        String testClassPath = System.getProperty("test.class.path", "");
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    70
        String testClasses = System.getProperty("test.classes", "") + sep;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    71
        String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    72
28760
b83d51c77b31 8067945: SVC jdk/test/* should be cleaned from JRE layout dependency
ykantser
parents: 24366
diff changeset
    73
        // Need to add SimpleProvider.jar to classpath.
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    74
        String classpath =
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    75
                testClassPath + File.pathSeparator +
28760
b83d51c77b31 8067945: SVC jdk/test/* should be cleaned from JRE layout dependency
ykantser
parents: 24366
diff changeset
    76
                testClasses + "SimpleProvider.jar";
21968
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    77
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    78
        String[] args = {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    79
                "-classpath",
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    80
                classpath,
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    81
                "ProviderTest$TestMain" };
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    82
        OutputAnalyzer output = ProcessTools.executeTestJvm(args);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    83
        output.shouldHaveExitValue(0);
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    84
    }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    85
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    86
    /**
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    87
     * Will build the SimpleProvider.jar.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    88
     */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    89
    private static void buildJar() throws Throwable {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    90
        final String sep = File.separator;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    91
        String testClasses = System.getProperty("test.classes", "?") + sep;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    92
        String testSrc = System.getProperty("test.src", "?") + sep;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    93
        String serviceDir = "META-INF" + sep + "services" + sep;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    94
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    95
        RunnerUtil.createJar(
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    96
            "-cf", testClasses + "SimpleProvider.jar",
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    97
            "-C", testClasses, "SimpleProvider.class",
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    98
            "-C", testClasses, "SimpleVirtualMachine.class",
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
    99
            "-C", testSrc,
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   100
            serviceDir + "com.sun.tools.attach.spi.AttachProvider");
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   101
    }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   102
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   103
    /**
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   104
     * This is the actual test code that attaches to the running Application.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   105
     * This class is run in a separate process.
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   106
     */
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   107
    public static class TestMain {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   108
        public static void main(String args[]) throws Exception {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   109
            // deal with internal builds where classes are loaded from the
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   110
            // 'classes' directory rather than rt.jar
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   111
            ClassLoader cl = AttachProvider.class.getClassLoader();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   112
            if (cl != ClassLoader.getSystemClassLoader()) {
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   113
                System.out.println("Attach API not loaded by system class loader - test skipped");
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   114
                return;
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   115
            }
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   116
            VirtualMachine.attach("simple:1234").detach();
619035df6988 6461635: [TESTBUG] BasicTests.sh test fails intermittently
sla
parents: 5506
diff changeset
   117
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
}