Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/tools/jinfo/JInfoTest.java
41149 views
1
/*
2
* Copyright (c) 2005, 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
import java.util.ArrayList;
25
import java.util.Arrays;
26
import java.util.List;
27
import java.util.regex.Matcher;
28
import java.util.regex.Pattern;
29
import java.io.IOException;
30
31
import jdk.test.lib.JDKToolLauncher;
32
import jdk.test.lib.Utils;
33
import jdk.test.lib.process.OutputAnalyzer;
34
import jdk.test.lib.process.ProcessTools;
35
import jdk.test.lib.apps.LingeredApp;
36
37
/*
38
* @test
39
* @summary Unit test for jinfo utility
40
*
41
* @library /test/lib
42
* @modules java.base/jdk.internal.misc
43
* java.management
44
* jdk.jcmd
45
*
46
* @run main JInfoTest
47
*/
48
public class JInfoTest {
49
50
private static ProcessBuilder processBuilder = new ProcessBuilder();
51
52
public static void main(String[] args) throws Exception {
53
classNameMatch();
54
setMultipleFlags();
55
setFlag();
56
}
57
58
private static void setFlag() throws Exception {
59
System.out.println("#### setFlag ####");
60
LingeredApp app1 = new JInfoTestLingeredApp();
61
LingeredApp app2 = new JInfoTestLingeredApp();
62
try {
63
String[] params = new String[0];;
64
LingeredApp.startAppExactJvmOpts(app1, params);
65
LingeredApp.startAppExactJvmOpts(app2, params);
66
OutputAnalyzer output = jinfo("-flag", "MinHeapFreeRatio=1", "JInfoTestLingeredApp");
67
output.shouldHaveExitValue(0);
68
output = jinfo("-flag", "MinHeapFreeRatio", "JInfoTestLingeredApp");
69
output.shouldHaveExitValue(0);
70
documentMatch(output.getStdout(), ".*MinHeapFreeRatio=1.*MinHeapFreeRatio=1.*");
71
} finally {
72
// LingeredApp.stopApp can throw an exception
73
try {
74
JInfoTestLingeredApp.stopApp(app1);
75
} finally {
76
JInfoTestLingeredApp.stopApp(app2);
77
}
78
}
79
}
80
81
private static void setMultipleFlags() throws Exception {
82
System.out.println("#### setMultipleFlags ####");
83
OutputAnalyzer output = jinfo("-sysprops", "-flag", "MinHeapFreeRatio=1", "-flags", "JInfoTestLingeredApp");
84
output.shouldHaveExitValue(1);
85
}
86
87
private static void classNameMatch() throws Exception {
88
System.out.println("#### classNameMatch ####");
89
LingeredApp app1 = new JInfoTestLingeredApp();
90
LingeredApp app2 = new JInfoTestLingeredApp();
91
try {
92
String[] params = new String[0];
93
LingeredApp.startAppExactJvmOpts(app1, params);
94
LingeredApp.startAppExactJvmOpts(app2, params);
95
OutputAnalyzer output = jinfo("JInfoTestLingeredApp");
96
output.shouldHaveExitValue(0);
97
// "Runtime Environment" written once per proc
98
documentMatch(output.getStdout(), ".*Runtime Environment.*Runtime Environment.*");
99
} finally {
100
// LingeredApp.stopApp can throw an exception
101
try {
102
JInfoTestLingeredApp.stopApp(app1);
103
} finally {
104
JInfoTestLingeredApp.stopApp(app2);
105
}
106
}
107
}
108
109
private static void documentMatch(String data, String pattern){
110
Matcher matcher = Pattern.compile(pattern, Pattern.DOTALL).matcher(data);
111
if (!matcher.find()) {
112
throw new RuntimeException("'" + pattern + "' missing from stdout \n");
113
}
114
}
115
116
private static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
117
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
118
launcher.addVMArgs(Utils.getTestJavaOpts());
119
if (toolArgs != null) {
120
for (String toolArg : toolArgs) {
121
launcher.addToolArg(toolArg);
122
}
123
}
124
125
processBuilder.command(launcher.getCommand());
126
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
127
128
return output;
129
}
130
}
131
132
// Sometime there is LingeredApp's from other test still around
133
class JInfoTestLingeredApp extends LingeredApp {
134
}
135
136