105 public void testVMCompilation3() throws IOException, InterruptedException { 106 final int maxProblems = 4; 107 Probe[] probes = { 108 new Probe("To capture more information for diagnosing or reporting a compilation", maxProblems), 109 new Probe("Retrying compilation of", maxProblems), 110 new Probe("adjusting CompilationFailureAction from Diagnose to Print", 1), 111 new Probe("adjusting CompilationFailureAction from Print to Silent", 1), 112 }; 113 testHelper(Arrays.asList(probes), Arrays.asList("-XX:+BootstrapJVMCI", 114 "-XX:+UseJVMCICompiler", 115 "-Dgraal.CompilationFailureAction=Diagnose", 116 "-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems, 117 "-Dgraal.CrashAt=Object.*,String.*", 118 "-version")); 119 } 120 121 /** 122 * Tests compilation requested by Truffle. 123 */ 124 @Test 125 public void testTruffleCompilation() throws IOException, InterruptedException { 126 testHelper(Collections.emptyList(), 127 Arrays.asList( 128 "-Dgraal.CompilationFailureAction=ExitVM", 129 "-Dgraal.CrashAt=root test1"), 130 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); 131 } 132 133 private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose"); 134 135 private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException { 136 final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile(); 137 List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine()); 138 vmArgs.removeIf(a -> a.startsWith("-Dgraal.")); 139 vmArgs.remove("-esa"); 140 vmArgs.remove("-ea"); 141 vmArgs.add("-Dgraal.DumpPath=" + dumpPath); 142 // Force output to a file even if there's a running IGV instance available. 143 vmArgs.add("-Dgraal.PrintGraphFile=true"); 144 vmArgs.addAll(extraVmArgs); 145 146 Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs); 147 if (VERBOSE) { 148 System.out.println(proc); 149 } 150 151 List<Probe> probes = new ArrayList<>(initialProbes); 152 Probe diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1); 153 probes.add(diagnosticProbe); 154 probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) { 155 @Override 156 String test() { 157 return actualOccurrences > 0 ? null : "expected at least 1 occurrence"; 158 } 159 }); 160 161 for (String line : proc.output) { 162 for (Probe probe : probes) { 163 if (probe.matches(line)) { 164 break; 165 } 166 } 167 } 168 for (Probe probe : probes) { 169 String error = probe.test(); 170 if (error != null) { 171 Assert.fail(String.format("Did not find expected occurences of '%s' in output of command: %s%n%s", probe.substring, error, proc)); 172 } 173 } 174 175 String diagnosticOutputZip = diagnosticProbe.lastMatchingLine.substring(diagnosticProbe.substring.length()).trim(); 176 177 List<String> dumpPathEntries = Arrays.asList(dumpPath.list()); 178 179 File zip = new File(diagnosticOutputZip).getAbsoluteFile(); 180 Assert.assertTrue(zip.toString(), zip.exists()); 181 Assert.assertTrue(zip + " not in " + dumpPathEntries, dumpPathEntries.contains(zip.getName())); 182 try { 183 int bgv = 0; 184 int cfg = 0; 185 ZipFile dd = new ZipFile(diagnosticOutputZip); 186 List<String> entries = new ArrayList<>(); 187 for (Enumeration<? extends ZipEntry> e = dd.entries(); e.hasMoreElements();) { 188 ZipEntry ze = e.nextElement(); 189 String name = ze.getName(); 190 entries.add(name); 191 if (name.endsWith(".bgv")) { 192 bgv++; 193 } else if (name.endsWith(".cfg")) { 194 cfg++; 195 } 196 } 197 if (bgv == 0) { 198 Assert.fail(String.format("Expected at least one .bgv file in %s: %s%n%s", diagnosticOutputZip, entries, proc)); 199 } 200 if (cfg == 0) { 201 Assert.fail(String.format("Expected at least one .cfg file in %s: %s", diagnosticOutputZip, entries)); 202 } 203 } finally { 204 zip.delete(); 205 dumpPath.delete(); 206 } 207 } 208 } | 105 public void testVMCompilation3() throws IOException, InterruptedException { 106 final int maxProblems = 4; 107 Probe[] probes = { 108 new Probe("To capture more information for diagnosing or reporting a compilation", maxProblems), 109 new Probe("Retrying compilation of", maxProblems), 110 new Probe("adjusting CompilationFailureAction from Diagnose to Print", 1), 111 new Probe("adjusting CompilationFailureAction from Print to Silent", 1), 112 }; 113 testHelper(Arrays.asList(probes), Arrays.asList("-XX:+BootstrapJVMCI", 114 "-XX:+UseJVMCICompiler", 115 "-Dgraal.CompilationFailureAction=Diagnose", 116 "-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems, 117 "-Dgraal.CrashAt=Object.*,String.*", 118 "-version")); 119 } 120 121 /** 122 * Tests compilation requested by Truffle. 123 */ 124 @Test 125 public void testTruffleCompilation1() throws IOException, InterruptedException { 126 testHelper(Collections.emptyList(), 127 Arrays.asList( 128 "-Dgraal.CompilationFailureAction=ExitVM", 129 "-Dgraal.CrashAt=root test1"), 130 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); 131 } 132 133 /** 134 * Tests that TruffleCompilationExceptionsAreFatal works as expected. 135 */ 136 @Test 137 public void testTruffleCompilation2() throws IOException, InterruptedException { 138 Probe[] probes = { 139 new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1), 140 }; 141 testHelper(Arrays.asList(probes), 142 Arrays.asList( 143 "-Dgraal.CompilationFailureAction=Silent", 144 "-Dgraal.TruffleCompilationExceptionsAreFatal=true", 145 "-Dgraal.CrashAt=root test1"), 146 "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test"); 147 } 148 149 private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose"); 150 151 private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException { 152 final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile(); 153 List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine()); 154 vmArgs.removeIf(a -> a.startsWith("-Dgraal.")); 155 vmArgs.remove("-esa"); 156 vmArgs.remove("-ea"); 157 vmArgs.add("-Dgraal.DumpPath=" + dumpPath); 158 // Force output to a file even if there's a running IGV instance available. 159 vmArgs.add("-Dgraal.PrintGraphFile=true"); 160 vmArgs.addAll(extraVmArgs); 161 162 Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs); 163 if (VERBOSE) { 164 System.out.println(proc); 165 } 166 167 List<Probe> probes = new ArrayList<>(initialProbes); 168 Probe diagnosticProbe = null; 169 if (!extraVmArgs.contains("-Dgraal.TruffleCompilationExceptionsAreFatal=true")) { 170 diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1); 171 probes.add(diagnosticProbe); 172 probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) { 173 @Override 174 String test() { 175 return actualOccurrences > 0 ? null : "expected at least 1 occurrence"; 176 } 177 }); 178 } 179 180 for (String line : proc.output) { 181 for (Probe probe : probes) { 182 if (probe.matches(line)) { 183 break; 184 } 185 } 186 } 187 for (Probe probe : probes) { 188 String error = probe.test(); 189 if (error != null) { 190 Assert.fail(String.format("Did not find expected occurences of '%s' in output of command: %s%n%s", probe.substring, error, proc)); 191 } 192 } 193 if (diagnosticProbe != null) { 194 String line = diagnosticProbe.lastMatchingLine; 195 int substringStart = line.indexOf(diagnosticProbe.substring); 196 int substringLength = diagnosticProbe.substring.length(); 197 String diagnosticOutputZip = line.substring(substringStart + substringLength).trim(); 198 199 List<String> dumpPathEntries = Arrays.asList(dumpPath.list()); 200 201 File zip = new File(diagnosticOutputZip).getAbsoluteFile(); 202 Assert.assertTrue(zip.toString(), zip.exists()); 203 Assert.assertTrue(zip + " not in " + dumpPathEntries, dumpPathEntries.contains(zip.getName())); 204 try { 205 int bgv = 0; 206 int cfg = 0; 207 ZipFile dd = new ZipFile(diagnosticOutputZip); 208 List<String> entries = new ArrayList<>(); 209 for (Enumeration<? extends ZipEntry> e = dd.entries(); e.hasMoreElements();) { 210 ZipEntry ze = e.nextElement(); 211 String name = ze.getName(); 212 entries.add(name); 213 if (name.endsWith(".bgv")) { 214 bgv++; 215 } else if (name.endsWith(".cfg")) { 216 cfg++; 217 } 218 } 219 if (bgv == 0) { 220 Assert.fail(String.format("Expected at least one .bgv file in %s: %s%n%s", diagnosticOutputZip, entries, proc)); 221 } 222 if (cfg == 0) { 223 Assert.fail(String.format("Expected at least one .cfg file in %s: %s", diagnosticOutputZip, entries)); 224 } 225 } finally { 226 zip.delete(); 227 dumpPath.delete(); 228 } 229 } 230 } 231 } |