--- old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/CompilationWrapperTest.java 2017-11-03 23:56:31.871794906 -0700 +++ new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/CompilationWrapperTest.java 2017-11-03 23:56:31.545780318 -0700 @@ -122,7 +122,7 @@ * Tests compilation requested by Truffle. */ @Test - public void testTruffleCompilation() throws IOException, InterruptedException { + public void testTruffleCompilation1() throws IOException, InterruptedException { testHelper(Collections.emptyList(), Arrays.asList( "-Dgraal.CompilationFailureAction=ExitVM", @@ -130,6 +130,22 @@ "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); } + /** + * Tests that TruffleCompilationExceptionsAreFatal works as expected. + */ + @Test + public void testTruffleCompilation2() throws IOException, InterruptedException { + Probe[] probes = { + new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1), + }; + testHelper(Arrays.asList(probes), + Arrays.asList( + "-Dgraal.CompilationFailureAction=Silent", + "-Dgraal.TruffleCompilationExceptionsAreFatal=true", + "-Dgraal.CrashAt=root test1"), + "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); + } + private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose"); private static void testHelper(List initialProbes, List extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException { @@ -149,14 +165,17 @@ } List probes = new ArrayList<>(initialProbes); - Probe diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1); - probes.add(diagnosticProbe); - probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) { - @Override - String test() { - return actualOccurrences > 0 ? null : "expected at least 1 occurrence"; - } - }); + Probe diagnosticProbe = null; + if (!extraVmArgs.contains("-Dgraal.TruffleCompilationExceptionsAreFatal=true")) { + diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1); + probes.add(diagnosticProbe); + probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) { + @Override + String test() { + return actualOccurrences > 0 ? null : "expected at least 1 occurrence"; + } + }); + } for (String line : proc.output) { for (Probe probe : probes) { @@ -171,38 +190,42 @@ Assert.fail(String.format("Did not find expected occurences of '%s' in output of command: %s%n%s", probe.substring, error, proc)); } } - - String diagnosticOutputZip = diagnosticProbe.lastMatchingLine.substring(diagnosticProbe.substring.length()).trim(); - - List dumpPathEntries = Arrays.asList(dumpPath.list()); - - File zip = new File(diagnosticOutputZip).getAbsoluteFile(); - Assert.assertTrue(zip.toString(), zip.exists()); - Assert.assertTrue(zip + " not in " + dumpPathEntries, dumpPathEntries.contains(zip.getName())); - try { - int bgv = 0; - int cfg = 0; - ZipFile dd = new ZipFile(diagnosticOutputZip); - List entries = new ArrayList<>(); - for (Enumeration e = dd.entries(); e.hasMoreElements();) { - ZipEntry ze = e.nextElement(); - String name = ze.getName(); - entries.add(name); - if (name.endsWith(".bgv")) { - bgv++; - } else if (name.endsWith(".cfg")) { - cfg++; + if (diagnosticProbe != null) { + String line = diagnosticProbe.lastMatchingLine; + int substringStart = line.indexOf(diagnosticProbe.substring); + int substringLength = diagnosticProbe.substring.length(); + String diagnosticOutputZip = line.substring(substringStart + substringLength).trim(); + + List dumpPathEntries = Arrays.asList(dumpPath.list()); + + File zip = new File(diagnosticOutputZip).getAbsoluteFile(); + Assert.assertTrue(zip.toString(), zip.exists()); + Assert.assertTrue(zip + " not in " + dumpPathEntries, dumpPathEntries.contains(zip.getName())); + try { + int bgv = 0; + int cfg = 0; + ZipFile dd = new ZipFile(diagnosticOutputZip); + List entries = new ArrayList<>(); + for (Enumeration e = dd.entries(); e.hasMoreElements();) { + ZipEntry ze = e.nextElement(); + String name = ze.getName(); + entries.add(name); + if (name.endsWith(".bgv")) { + bgv++; + } else if (name.endsWith(".cfg")) { + cfg++; + } } + if (bgv == 0) { + Assert.fail(String.format("Expected at least one .bgv file in %s: %s%n%s", diagnosticOutputZip, entries, proc)); + } + if (cfg == 0) { + Assert.fail(String.format("Expected at least one .cfg file in %s: %s", diagnosticOutputZip, entries)); + } + } finally { + zip.delete(); + dumpPath.delete(); } - if (bgv == 0) { - Assert.fail(String.format("Expected at least one .bgv file in %s: %s%n%s", diagnosticOutputZip, entries, proc)); - } - if (cfg == 0) { - Assert.fail(String.format("Expected at least one .cfg file in %s: %s", diagnosticOutputZip, entries)); - } - } finally { - zip.delete(); - dumpPath.delete(); } } }