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