1 /* 2 * Copyright (c) 2013, 2018, 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 24 25 package org.graalvm.compiler.hotspot.test; 26 27 import static org.graalvm.compiler.debug.DebugOptions.Dump; 28 import static org.graalvm.compiler.debug.DebugOptions.MethodFilter; 29 import static org.graalvm.compiler.debug.DebugOptions.PrintGraph; 30 import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine; 31 import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments; 32 33 import java.io.File; 34 import java.io.FileOutputStream; 35 import java.io.IOException; 36 import java.io.PrintStream; 37 import java.util.List; 38 39 import org.graalvm.compiler.core.test.GraalCompilerTest; 40 import org.graalvm.compiler.debug.DebugOptions.PrintGraphTarget; 41 import org.graalvm.compiler.test.SubprocessUtil; 42 import org.graalvm.compiler.test.SubprocessUtil.Subprocess; 43 import org.junit.Assert; 44 import org.junit.Test; 45 46 /** 47 * Tests reading options from a file specified by the {@code graal.options.file}. 48 */ 49 public class OptionsInFileTest extends GraalCompilerTest { 50 @Test 51 public void test() throws IOException, InterruptedException { 52 String methodFilterValue = "a very unlikely method name"; 53 String debugFilterValue = "a very unlikely debug scope"; 54 File optionsFile = File.createTempFile("options", ".properties").getAbsoluteFile(); 55 try { 56 Assert.assertFalse(methodFilterValue.equals(MethodFilter.getDefaultValue())); 57 Assert.assertFalse(debugFilterValue.equals(Dump.getDefaultValue())); 58 Assert.assertEquals(PrintGraphTarget.File, PrintGraph.getDefaultValue()); 59 60 try (PrintStream out = new PrintStream(new FileOutputStream(optionsFile))) { 61 out.println(MethodFilter.getName() + "=" + methodFilterValue); 62 out.println(Dump.getName() + "=" + debugFilterValue); 63 out.println(PrintGraph.getName() + " = Network"); 64 } 65 66 List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine()); 67 vmArgs.removeIf(a -> a.startsWith("-Dgraal.")); 68 vmArgs.add("-Dgraal.options.file=" + optionsFile); 69 vmArgs.add("-XX:+JVMCIPrintProperties"); 70 Subprocess proc = SubprocessUtil.java(vmArgs); 71 String[] expected = { 72 "graal.MethodFilter := \"a very unlikely method name\"", 73 "graal.Dump := \"a very unlikely debug scope\"", 74 "graal.PrintGraph := Network"}; 75 for (String line : proc.output) { 76 for (int i = 0; i < expected.length; i++) { 77 if (expected[i] != null && line.contains(expected[i])) { 78 expected[i] = null; 79 } 80 } 81 } 82 83 for (int i = 0; i < expected.length; i++) { 84 if (expected[i] != null) { 85 Assert.fail(String.format("Did not find '%s' in output of command:%n%s", expected[i], proc)); 86 } 87 } 88 } finally { 89 optionsFile.delete(); 90 } 91 } 92 }