< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/OptionsInFileTest.java

Print this page




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


  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 }
< prev index next >