Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/tools/jhsdb/heapconfig/TmtoolTestScenario.java
41153 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
import java.io.BufferedReader;
24
import java.io.IOException;
25
import java.io.InputStreamReader;
26
import java.math.BigDecimal;
27
import java.util.ArrayList;
28
import java.util.Arrays;
29
import java.util.Collections;
30
import java.util.HashMap;
31
import java.util.List;
32
import java.util.Map;
33
import java.util.logging.Level;
34
import java.util.logging.Logger;
35
36
import jdk.test.lib.apps.LingeredApp;
37
import jdk.test.lib.JDKToolLauncher;
38
import jdk.test.lib.SA.SATestUtils;
39
import jdk.test.lib.Utils;
40
41
public class TmtoolTestScenario {
42
43
private final ArrayList<String> toolOutput = new ArrayList<String>();
44
private LingeredApp theApp = null;
45
private final String toolName;
46
private final String[] toolArgs;
47
48
/**
49
* @param toolName - name of tool to test
50
* @param toolArgs - tool arguments
51
* @return the object
52
*/
53
public static TmtoolTestScenario create(String toolName, String... toolArgs) {
54
return new TmtoolTestScenario(toolName, toolArgs);
55
}
56
57
/**
58
* @return STDOUT of tool
59
*/
60
public List<String> getToolOutput() {
61
return toolOutput;
62
}
63
64
/**
65
*
66
* @return STDOUT of test app
67
*/
68
public List<String> getAppOutput() {
69
return theApp.getOutput().getStdoutAsList();
70
}
71
72
/**
73
* @return Value of the app output with -XX:+PrintFlagsFinal as a map.
74
*/
75
public Map<String, String> parseFlagsFinal() {
76
List<String> astr = getAppOutput();
77
Map<String, String> vmMap = new HashMap<String, String>();
78
79
for (String line : astr) {
80
String[] lv = line.trim().split("\\s+");
81
try {
82
vmMap.put(lv[1], lv[3]);
83
} catch (ArrayIndexOutOfBoundsException ex) {
84
// ignore mailformed lines
85
}
86
}
87
return vmMap;
88
}
89
90
/**
91
*
92
* @param vmArgs - vm and java arguments to launch test app
93
* @return exit code of tool
94
*/
95
public int launch(String... vmArgs) {
96
System.out.println("Starting LingeredApp");
97
try {
98
try {
99
List<String> vmArgsExtended = new ArrayList<String>();
100
vmArgsExtended.add("-XX:+UsePerfData");
101
Collections.addAll(vmArgsExtended, vmArgs);
102
theApp = new LingeredApp();
103
LingeredApp.startAppExactJvmOpts(theApp, vmArgsExtended.toArray(new String[0]));
104
105
System.out.println("Starting " + toolName + " against " + theApp.getPid());
106
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
107
launcher.addToolArg(toolName);
108
109
for (String cmd : toolArgs) {
110
launcher.addToolArg(cmd);
111
}
112
launcher.addToolArg("--pid");
113
launcher.addToolArg(Long.toString(theApp.getPid()));
114
115
ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);
116
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
117
Process toolProcess = processBuilder.start();
118
119
// By default child process output stream redirected to pipe, so we are reading it in foreground.
120
BufferedReader reader = new BufferedReader(new InputStreamReader(toolProcess.getInputStream()));
121
122
String line;
123
while ((line = reader.readLine()) != null) {
124
toolOutput.add(line.trim());
125
}
126
127
toolProcess.waitFor();
128
129
return toolProcess.exitValue();
130
} finally {
131
LingeredApp.stopApp(theApp);
132
}
133
} catch (IOException | InterruptedException ex) {
134
throw new RuntimeException("Test ERROR " + ex, ex);
135
}
136
}
137
138
private TmtoolTestScenario(String toolName, String[] toolArgs) {
139
this.toolName = toolName;
140
this.toolArgs = toolArgs;
141
}
142
143
}
144
145