1 /* |
1 /* |
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
22 */ |
22 */ |
23 |
23 |
24 |
24 |
25 package org.graalvm.compiler.hotspot.test; |
25 package org.graalvm.compiler.hotspot.test; |
26 |
26 |
|
27 import static org.graalvm.compiler.test.SubprocessUtil.getPackageOpeningOptions; |
27 import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine; |
28 import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine; |
28 import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments; |
29 import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments; |
29 |
30 |
30 import java.io.File; |
31 import java.io.File; |
31 import java.io.IOException; |
32 import java.io.IOException; |
|
33 import java.nio.file.Path; |
32 import java.util.ArrayList; |
34 import java.util.ArrayList; |
33 import java.util.Arrays; |
35 import java.util.Arrays; |
34 import java.util.Collections; |
36 import java.util.Collections; |
35 import java.util.Enumeration; |
37 import java.util.Enumeration; |
36 import java.util.List; |
38 import java.util.List; |
46 |
48 |
47 /** |
49 /** |
48 * Tests support for dumping graphs and other info useful for debugging a compiler crash. |
50 * Tests support for dumping graphs and other info useful for debugging a compiler crash. |
49 */ |
51 */ |
50 public class CompilationWrapperTest extends GraalCompilerTest { |
52 public class CompilationWrapperTest extends GraalCompilerTest { |
|
53 |
|
54 private static List<String> join(List<String> l1, List<String> l2) { |
|
55 ArrayList<String> result = new ArrayList<>(l1.size() + l2.size()); |
|
56 result.addAll(l1); |
|
57 result.addAll(l2); |
|
58 return result; |
|
59 } |
51 |
60 |
52 /** |
61 /** |
53 * Tests compilation requested by the VM. |
62 * Tests compilation requested by the VM. |
54 */ |
63 */ |
55 @Test |
64 @Test |
149 */ |
158 */ |
150 @Test |
159 @Test |
151 public void testTruffleCompilation1() throws IOException, InterruptedException { |
160 public void testTruffleCompilation1() throws IOException, InterruptedException { |
152 assumeManagementLibraryIsLoadable(); |
161 assumeManagementLibraryIsLoadable(); |
153 testHelper(Collections.emptyList(), |
162 testHelper(Collections.emptyList(), |
154 Arrays.asList( |
163 join(getPackageOpeningOptions(), |
155 "-Dgraal.CompilationFailureAction=ExitVM", |
164 Arrays.asList( |
156 "-Dgraal.TrufflePerformanceWarningsAreFatal=true", |
165 "-Dgraal.CompilationFailureAction=ExitVM", |
157 "-Dgraal.CrashAt=root test1"), |
166 "-Dgraal.TrufflePerformanceWarningsAreFatal=true", |
|
167 "-Dgraal.CrashAt=root test1")), |
158 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); |
168 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); |
159 } |
169 } |
160 |
170 |
161 /** |
171 /** |
162 * Tests that TruffleCompilationExceptionsAreFatal works as expected. |
172 * Tests that TruffleCompilationExceptionsAreFatal works as expected. |
165 public void testTruffleCompilation2() throws IOException, InterruptedException { |
175 public void testTruffleCompilation2() throws IOException, InterruptedException { |
166 Probe[] probes = { |
176 Probe[] probes = { |
167 new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1), |
177 new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1), |
168 }; |
178 }; |
169 testHelper(Arrays.asList(probes), |
179 testHelper(Arrays.asList(probes), |
170 Arrays.asList( |
180 join(getPackageOpeningOptions(), |
171 "-Dgraal.CompilationFailureAction=Silent", |
181 Arrays.asList( |
172 "-Dgraal.TruffleCompilationExceptionsAreFatal=true", |
182 "-Dgraal.CompilationFailureAction=Silent", |
173 "-Dgraal.CrashAt=root test1"), |
183 "-Dgraal.TruffleCompilationExceptionsAreFatal=true", |
|
184 "-Dgraal.CrashAt=root test1")), |
174 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); |
185 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); |
175 } |
186 } |
176 |
187 |
177 /** |
188 /** |
178 * Tests that TrufflePerformanceWarningsAreFatal generates diagnostic output. |
189 * Tests that TrufflePerformanceWarningsAreFatal generates diagnostic output. |
182 assumeManagementLibraryIsLoadable(); |
193 assumeManagementLibraryIsLoadable(); |
183 Probe[] probes = { |
194 Probe[] probes = { |
184 new Probe("Exiting VM due to TrufflePerformanceWarningsAreFatal=true", 1), |
195 new Probe("Exiting VM due to TrufflePerformanceWarningsAreFatal=true", 1), |
185 }; |
196 }; |
186 testHelper(Arrays.asList(probes), |
197 testHelper(Arrays.asList(probes), |
187 Arrays.asList( |
198 join(getPackageOpeningOptions(), |
188 "-Dgraal.CompilationFailureAction=Silent", |
199 Arrays.asList( |
189 "-Dgraal.TrufflePerformanceWarningsAreFatal=true", |
200 "-Dgraal.CompilationFailureAction=Silent", |
190 "-Dgraal.CrashAt=root test1:PermanentBailout"), |
201 "-Dgraal.TrufflePerformanceWarningsAreFatal=true", |
|
202 "-Dgraal.CrashAt=root test1:PermanentBailout")), |
191 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); |
203 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); |
192 } |
204 } |
193 |
205 |
194 private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose"); |
206 private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose"); |
195 |
207 |
207 Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs); |
219 Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs); |
208 if (VERBOSE) { |
220 if (VERBOSE) { |
209 System.out.println(proc); |
221 System.out.println(proc); |
210 } |
222 } |
211 |
223 |
212 List<Probe> probes = new ArrayList<>(initialProbes); |
224 try { |
213 Probe diagnosticProbe = null; |
225 List<Probe> probes = new ArrayList<>(initialProbes); |
214 if (!extraVmArgs.contains("-Dgraal.TruffleCompilationExceptionsAreFatal=true")) { |
226 Probe diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1); |
215 diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1); |
|
216 probes.add(diagnosticProbe); |
227 probes.add(diagnosticProbe); |
217 probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) { |
228 probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) { |
218 @Override |
229 @Override |
219 String test() { |
230 String test() { |
220 return actualOccurrences > 0 ? null : "expected at least 1 occurrence"; |
231 return actualOccurrences > 0 ? null : "expected at least 1 occurrence"; |
221 } |
232 } |
222 }); |
233 }); |
223 } |
234 |
224 |
235 for (String line : proc.output) { |
225 for (String line : proc.output) { |
236 for (Probe probe : probes) { |
|
237 if (probe.matches(line)) { |
|
238 break; |
|
239 } |
|
240 } |
|
241 } |
226 for (Probe probe : probes) { |
242 for (Probe probe : probes) { |
227 if (probe.matches(line)) { |
243 String error = probe.test(); |
228 break; |
244 if (error != null) { |
229 } |
245 Assert.fail(String.format("Did not find expected occurences of '%s' in output of command: %s%n%s", probe.substring, error, proc)); |
230 } |
246 } |
231 } |
247 } |
232 for (Probe probe : probes) { |
|
233 String error = probe.test(); |
|
234 if (error != null) { |
|
235 Assert.fail(String.format("Did not find expected occurences of '%s' in output of command: %s%n%s", probe.substring, error, proc)); |
|
236 } |
|
237 } |
|
238 if (diagnosticProbe != null) { |
|
239 String line = diagnosticProbe.lastMatchingLine; |
248 String line = diagnosticProbe.lastMatchingLine; |
240 int substringStart = line.indexOf(diagnosticProbe.substring); |
249 int substringStart = line.indexOf(diagnosticProbe.substring); |
241 int substringLength = diagnosticProbe.substring.length(); |
250 int substringLength = diagnosticProbe.substring.length(); |
242 String diagnosticOutputZip = line.substring(substringStart + substringLength).trim(); |
251 String diagnosticOutputZip = line.substring(substringStart + substringLength).trim(); |
243 |
252 |