Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/compiler/complog/share/LogCompilationTest.java
41161 views
1
/*
2
* Copyright (c) 2013, 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
package vm.compiler.complog.share;
24
25
import jdk.test.lib.Utils;
26
import nsk.share.TestBug;
27
import nsk.share.TestFailure;
28
import nsk.share.log.Log;
29
import nsk.share.log.LogSupport;
30
import vm.share.options.Option;
31
import vm.share.options.OptionSupport;
32
import vm.share.process.ProcessExecutor;
33
34
import java.io.File;
35
import java.io.FileNotFoundException;
36
import java.io.FileOutputStream;
37
import java.io.PrintStream;
38
import java.lang.reflect.Constructor;
39
import java.util.ArrayList;
40
import java.util.Collections;
41
import java.util.List;
42
43
/**
44
* Test executor for all tests that require compilation log analysis.
45
* Next options should be passed to LogCompilationTest:
46
* <b>-testClass</b> test to be executed;
47
* <b>-testedJava</b> path to testing java binary;
48
* <b>-parserClass</b> parser that will be used for compilation log analysis;
49
* <b>-timeout</b> timeout in secoonds.
50
*/
51
52
public class LogCompilationTest extends OptionSupport implements Runnable {
53
54
@Option(name="testClass", description="Test to be executed.")
55
protected String testClass;
56
57
@Option(name="parserClass", description="Parser for compilation log.")
58
protected String parserClass;
59
60
@Option(name="timeout", description="Timeout value in seconds.", default_value="1800")
61
protected int timeout;
62
63
@Option(name="testedJava", description="Java binary to be tested.")
64
protected String testedJava;
65
66
@Option(name="parserOptions", description="Options that will be passed to compilation log parser.", default_value="")
67
protected String parserOptions;
68
69
protected Log log = new LogSupport(System.out);
70
protected Log testLog;
71
72
public static final String compilationLog = "hotspot.log";
73
74
public static void main(String[] args) {
75
LogCompilationTest.setupAndRun(new LogCompilationTest(), args);
76
}
77
78
public void run() {
79
execute();
80
parse();
81
}
82
83
private String[] getJVMOptions() {
84
List<String> options = new ArrayList<>();
85
Collections.addAll(options, Utils.getTestJavaOpts());
86
options.add("-XX:+UnlockDiagnosticVMOptions");
87
options.add("-XX:+LogCompilation");
88
options.add("-XX:LogFile=" + compilationLog);
89
return options.toArray(new String[0]);
90
}
91
92
private LogCompilationParser getParser() {
93
try {
94
Class<?> parser = Class.forName(parserClass);
95
Constructor<?> ctor = parser.getConstructor();
96
return (LogCompilationParser) ctor.newInstance();
97
} catch (Throwable e) {
98
throw new TestBug("Parser could not be instantiated.", e);
99
}
100
}
101
102
private void execute() {
103
String[] options = getJVMOptions();
104
ProcessExecutor executor = new ProcessExecutor();
105
try {
106
testLog = new LogSupport(new PrintStream(new FileOutputStream("test.log")));
107
} catch (FileNotFoundException e) {
108
throw new TestFailure("Can't create test log file.", e);
109
}
110
111
executor.logStdOutErr("Test>>", testLog);
112
executor.addArg(testedJava);
113
executor.addArgs(options);
114
executor.addArg(testClass);
115
executor.start();
116
int exitCode = executor.waitFor(timeout * 1000);
117
118
if (exitCode != 0) {
119
if (new File("hs_err_pid" + executor.getPid() + ".log").exists()) {
120
throw new TestFailure("Test crashed. Exit code: " + exitCode);
121
} else {
122
throw new TestFailure("Test exited with non-zero code: " + exitCode);
123
}
124
}
125
}
126
127
private void parse() {
128
File hotspotLog = new File(compilationLog);
129
LogCompilationParser parser = getParser();
130
parser.setOptions(parserOptions);
131
parser.setLog(log);
132
try {
133
parser.parse(hotspotLog);
134
} catch (Throwable e) {
135
throw new TestFailure("Error occurred during compilation log parsing.",e);
136
}
137
}
138
139
}
140
141