author | dholmes |
Wed, 06 Nov 2019 21:18:42 -0500 | |
changeset 58956 | 9a0a5e70eeb2 |
parent 52731 | 157c1130b46e |
permissions | -rw-r--r-- |
2 | 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 | 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; |
51675 | 25 |
import jdk.test.lib.process.OutputAnalyzer; |
26 |
import jdk.test.lib.process.ProcessTools; |
|
2 | 27 |
import com.sun.tools.attach.VirtualMachine; |
28 |
import com.sun.tools.attach.spi.AttachProvider; |
|
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 | 33 |
* @summary Basic unit tests for the VM attach mechanism. The test will attach |
34 |
* and detach to/from the running Application. |
|
35 |
* |
|
51541
69ee8894f5fa
8210022: remove jdk.testlibrary.ProcessThread, TestThread and XRun
iignatyev
parents:
47216
diff
changeset
|
36 |
* @library /test/lib |
44423 | 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 | 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 | 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 | 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 | 118 |
} |
119 |
} |