Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/tools/attach/ProviderTest.java
41153 views
1
/*
2
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
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
*
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.
22
*/
23
24
import java.io.File;
25
import jdk.test.lib.process.OutputAnalyzer;
26
import jdk.test.lib.process.ProcessTools;
27
import com.sun.tools.attach.VirtualMachine;
28
import com.sun.tools.attach.spi.AttachProvider;
29
30
/*
31
* @test
32
* @bug 6173612 6273707 6277253 6335921 6348630 6342019 6381757
33
* @summary Basic unit tests for the VM attach mechanism. The test will attach
34
* and detach to/from the running Application.
35
*
36
* @library /test/lib
37
* @modules jdk.attach
38
* jdk.jartool/sun.tools.jar
39
*
40
* @run build SimpleProvider
41
* @run main ProviderTest
42
*/
43
public class ProviderTest {
44
45
/*
46
* The actual tests are in the nested class TestMain below.
47
* The responsibility of this class is to:
48
* 1. Build the needed jar.
49
* 2. Run tests in ProviderTest.TestMain.
50
*/
51
public static void main(String args[]) throws Throwable {
52
try {
53
buildJar();
54
runTests();
55
} catch (Throwable t) {
56
System.out.println("TestProvider got unexpected exception: " + t);
57
t.printStackTrace();
58
throw t;
59
}
60
}
61
62
/**
63
* Runs the actual tests in the nested class TestMain.
64
* We need to run the tests in a separate process,
65
* because we need to add to the classpath.
66
*/
67
private static void runTests() throws Throwable {
68
final String sep = File.separator;
69
String testClassPath = System.getProperty("test.class.path", "");
70
String testClasses = System.getProperty("test.classes", "") + sep;
71
String jdkLib = System.getProperty("test.jdk", ".") + sep + "lib" + sep;
72
73
// Need to add SimpleProvider.jar to classpath.
74
String classpath =
75
testClassPath + File.pathSeparator +
76
testClasses + "SimpleProvider.jar";
77
78
String[] args = {
79
"-classpath",
80
classpath,
81
"ProviderTest$TestMain" };
82
OutputAnalyzer output = ProcessTools.executeTestJvm(args);
83
output.shouldHaveExitValue(0);
84
}
85
86
/**
87
* Will build the SimpleProvider.jar.
88
*/
89
private static void buildJar() throws Throwable {
90
final String sep = File.separator;
91
String testClasses = System.getProperty("test.classes", "?") + sep;
92
String testSrc = System.getProperty("test.src", "?") + sep;
93
String serviceDir = "META-INF" + sep + "services" + sep;
94
95
RunnerUtil.createJar(
96
"-cf", testClasses + "SimpleProvider.jar",
97
"-C", testClasses, "SimpleProvider.class",
98
"-C", testClasses, "SimpleVirtualMachine.class",
99
"-C", testSrc,
100
serviceDir + "com.sun.tools.attach.spi.AttachProvider");
101
}
102
103
/**
104
* This is the actual test code that attaches to the running Application.
105
* This class is run in a separate process.
106
*/
107
public static class TestMain {
108
public static void main(String args[]) throws Exception {
109
// deal with internal builds where classes are loaded from the
110
// 'classes' directory rather than rt.jar
111
ClassLoader cl = AttachProvider.class.getClassLoader();
112
if (cl != ClassLoader.getSystemClassLoader()) {
113
System.out.println("Attach API not loaded by system class loader - test skipped");
114
return;
115
}
116
VirtualMachine.attach("simple:1234").detach();
117
}
118
}
119
}
120
121