Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/tools/jhsdb/BasicLauncherTest.java
41152 views
1
/*
2
* Copyright (c) 2015, 2020, 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
/**
25
* @test
26
* @summary Basic test for jhsdb launcher
27
* @library /test/lib
28
* @requires vm.hasSA
29
* @build jdk.test.lib.apps.*
30
* @run main BasicLauncherTest
31
*/
32
33
import java.io.BufferedReader;
34
import java.io.IOException;
35
import java.io.OutputStream;
36
import java.io.InputStreamReader;
37
import java.util.ArrayList;
38
import java.util.List;
39
import java.util.Arrays;
40
import java.util.Optional;
41
import jdk.test.lib.process.OutputAnalyzer;
42
import jdk.test.lib.process.ProcessTools;
43
import jdk.test.lib.apps.LingeredApp;
44
import jdk.test.lib.Platform;
45
import jdk.test.lib.JDKToolLauncher;
46
import jdk.test.lib.SA.SATestUtils;
47
import jdk.test.lib.Utils;
48
49
public class BasicLauncherTest {
50
51
private static LingeredApp theApp = null;
52
private static boolean useJavaLauncher = false;
53
54
private static JDKToolLauncher createSALauncher() {
55
JDKToolLauncher launcher = null;
56
if (useJavaLauncher) {
57
// Use java launcher if we need to pass additional parameters to VM
58
// for debugging purpose
59
// e.g. -Xlog:class+load=info:file=/tmp/BasicLauncherTest.log
60
launcher = JDKToolLauncher.createUsingTestJDK("java");
61
launcher.addToolArg("sun.jvm.hotspot.SALauncher");
62
}
63
else {
64
launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
65
}
66
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
67
return launcher;
68
}
69
70
public static void launchCLHSDB()
71
throws IOException {
72
73
System.out.println("Starting LingeredApp");
74
try {
75
theApp = LingeredApp.startApp();
76
77
System.out.println("Starting clhsdb against " + theApp.getPid());
78
JDKToolLauncher launcher = createSALauncher();
79
launcher.addToolArg("clhsdb");
80
launcher.addToolArg("--pid=" + Long.toString(theApp.getPid()));
81
82
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
83
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
84
Process toolProcess = processBuilder.start();
85
86
try (OutputStream out = toolProcess.getOutputStream()) {
87
out.write("universe\n".getBytes());
88
out.write("quit\n".getBytes());
89
}
90
91
// By default child process output stream redirected to pipe, so we are reading it in foreground.
92
Exception unexpected = null;
93
try (BufferedReader reader =
94
new BufferedReader(new InputStreamReader(toolProcess.getInputStream()))) {
95
String line;
96
97
while ((line = reader.readLine()) != null) {
98
line = line.trim();
99
System.out.println(line);
100
101
if (line.contains("unknown subtype of CollectedHeap")) {
102
unexpected = new RuntimeException("CollectedHeap type should be known.");
103
break;
104
}
105
}
106
}
107
108
toolProcess.waitFor();
109
110
if (toolProcess.exitValue() != 0) {
111
throw new RuntimeException("FAILED CLHSDB terminated with non-zero exit code " + toolProcess.exitValue());
112
}
113
114
if (unexpected != null) {
115
throw unexpected;
116
}
117
118
} catch (Exception ex) {
119
throw new RuntimeException("Test ERROR " + ex, ex);
120
} finally {
121
LingeredApp.stopApp(theApp);
122
}
123
}
124
125
public static void launchJStack() throws IOException {
126
System.out.println("Starting LingeredApp");
127
try {
128
theApp = LingeredApp.startApp("-Xmx256m");
129
130
System.out.println("Starting jstack against " + theApp.getPid());
131
JDKToolLauncher launcher = createSALauncher();
132
133
launcher.addToolArg("jstack");
134
launcher.addToolArg("--pid=" + Long.toString(theApp.getPid()));
135
136
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
137
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);;
138
output.shouldContain("No deadlocks found");
139
output.shouldNotContain("illegal bci");
140
output.shouldNotContain("AssertionFailure");
141
output.shouldHaveExitValue(0);
142
143
} catch (Exception ex) {
144
throw new RuntimeException("Test ERROR " + ex, ex);
145
} finally {
146
LingeredApp.stopApp(theApp);
147
}
148
}
149
150
/**
151
*
152
* @param vmArgs - vm and java arguments to launch test app
153
* @return exit code of tool
154
*/
155
public static void launch(String expectedMessage,
156
Optional<String> unexpectedMessage, List<String> toolArgs)
157
throws IOException {
158
159
System.out.println("Starting LingeredApp");
160
try {
161
theApp = LingeredApp.startApp("-Xmx256m");
162
163
System.out.println("Starting " + toolArgs.get(0) + " against " + theApp.getPid());
164
JDKToolLauncher launcher = createSALauncher();
165
166
for (String cmd : toolArgs) {
167
launcher.addToolArg(cmd);
168
}
169
170
launcher.addToolArg("--pid=" + Long.toString(theApp.getPid()));
171
172
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
173
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
174
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);;
175
output.shouldContain(expectedMessage);
176
unexpectedMessage.ifPresent(output::shouldNotContain);
177
output.shouldHaveExitValue(0);
178
179
} catch (Exception ex) {
180
throw new RuntimeException("Test ERROR " + ex, ex);
181
} finally {
182
LingeredApp.stopApp(theApp);
183
}
184
}
185
186
public static void launch(String expectedMessage,
187
String unexpectedMessage, String... toolArgs)
188
throws IOException {
189
190
launch(expectedMessage, Optional.ofNullable(unexpectedMessage),
191
Arrays.asList(toolArgs));
192
}
193
194
public static void main(String[] args) throws Exception {
195
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
196
197
launchCLHSDB();
198
199
launch("compiler detected", null, "jmap", "--clstats");
200
launchJStack();
201
launch("compiler detected", null, "jmap");
202
launch("Java System Properties",
203
"System Properties info not available", "jinfo");
204
launch("java.threads", null, "jsnap");
205
206
// The test throws RuntimeException on error.
207
// IOException is thrown if LingeredApp can't start because of some bad
208
// environment condition
209
System.out.println("Test PASSED");
210
}
211
}
212
213