< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DumpPathTest.java

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2017, 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.core.test;
  26 
  27 import java.io.IOException;
  28 import java.nio.file.DirectoryStream;
  29 import java.nio.file.Files;
  30 import java.nio.file.Path;

  31 
  32 import jdk.internal.vm.compiler.collections.EconomicMap;
  33 import org.graalvm.compiler.debug.DebugOptions;
  34 import org.graalvm.compiler.debug.DebugOptions.PrintGraphTarget;
  35 import org.graalvm.compiler.options.OptionKey;
  36 import org.graalvm.compiler.options.OptionValues;
  37 import org.junit.Test;
  38 
  39 /**
  40  * Check that setting the dump path results in files ending up in the right directory with matching
  41  * names.
  42  */
  43 public class DumpPathTest extends GraalCompilerTest {
  44 
  45     public static Object snippet() {
  46         return new String("snippet");
  47     }
  48 
  49     @Test
  50     public void testDump() throws IOException {
  51         assumeManagementLibraryIsLoadable();
  52         Path dumpDirectoryPath = Files.createTempDirectory("DumpPathTest");
  53         String[] extensions = new String[]{".cfg", ".bgv", ".graph-strings"};
  54         EconomicMap<OptionKey<?>, Object> overrides = OptionValues.newOptionMap();
  55         overrides.put(DebugOptions.DumpPath, dumpDirectoryPath.toString());
  56         overrides.put(DebugOptions.PrintCFG, true);
  57         overrides.put(DebugOptions.PrintGraph, PrintGraphTarget.File);
  58         overrides.put(DebugOptions.PrintCanonicalGraphStrings, true);
  59         overrides.put(DebugOptions.Dump, "*");
  60 
  61         // Generate dump files.
  62         test(new OptionValues(getInitialOptions(), overrides), "snippet");
  63         // Check that IGV files got created, in the right place.
  64         checkForFiles(dumpDirectoryPath, extensions);
  65 
  66         // Clean up the generated files.
  67         removeDirectory(dumpDirectoryPath);
  68     }
  69 
  70     /**
  71      * Check that the given directory contains file or directory names with all the given
  72      * extensions.
  73      */
  74     private static void checkForFiles(Path directoryPath, String[] extensions) throws IOException {
  75         String[] paths = new String[extensions.length];
  76         try (DirectoryStream<Path> stream = Files.newDirectoryStream(directoryPath)) {
  77             for (Path filePath : stream) {
  78                 String fileName = filePath.getFileName().toString();
  79                 for (int i = 0; i < extensions.length; i++) {
  80                     String extension = extensions[i];
  81                     if (fileName.endsWith(extensions[i])) {
  82                         assertTrue(paths[i] == null, "multiple files found for %s in %s", extension, directoryPath);
  83                         paths[i] = fileName.replace(extensions[i], "");
  84                     }
  85                 }
  86             }
  87         }
   1 /*
   2  * Copyright (c) 2017, 2019, 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.core.test;
  26 
  27 import java.io.IOException;
  28 import java.nio.file.DirectoryStream;
  29 import java.nio.file.Files;
  30 import java.nio.file.Path;
  31 import java.nio.file.Paths;
  32 
  33 import jdk.internal.vm.compiler.collections.EconomicMap;
  34 import org.graalvm.compiler.debug.DebugOptions;
  35 import org.graalvm.compiler.debug.DebugOptions.PrintGraphTarget;
  36 import org.graalvm.compiler.options.OptionKey;
  37 import org.graalvm.compiler.options.OptionValues;
  38 import org.junit.Test;
  39 
  40 /**
  41  * Check that setting the dump path results in files ending up in the right directory with matching
  42  * names.
  43  */
  44 public class DumpPathTest extends GraalCompilerTest {
  45 
  46     public static Object snippet() {
  47         return new String("snippet");
  48     }
  49 
  50     @Test
  51     public void testDump() throws IOException {
  52         assumeManagementLibraryIsLoadable();
  53         try (TemporaryDirectory temp = new TemporaryDirectory(Paths.get("."), "DumpPathTest")) {
  54             String[] extensions = new String[]{".cfg", ".bgv", ".graph-strings"};
  55             EconomicMap<OptionKey<?>, Object> overrides = OptionValues.newOptionMap();
  56             overrides.put(DebugOptions.DumpPath, temp.toString());
  57             overrides.put(DebugOptions.PrintCFG, true);
  58             overrides.put(DebugOptions.PrintGraph, PrintGraphTarget.File);
  59             overrides.put(DebugOptions.PrintCanonicalGraphStrings, true);
  60             overrides.put(DebugOptions.Dump, "*");
  61 
  62             // Generate dump files.
  63             test(new OptionValues(getInitialOptions(), overrides), "snippet");
  64             // Check that IGV files got created, in the right place.
  65             checkForFiles(temp.path, extensions);
  66         }


  67     }
  68 
  69     /**
  70      * Check that the given directory contains file or directory names with all the given
  71      * extensions.
  72      */
  73     private static void checkForFiles(Path directoryPath, String[] extensions) throws IOException {
  74         String[] paths = new String[extensions.length];
  75         try (DirectoryStream<Path> stream = Files.newDirectoryStream(directoryPath)) {
  76             for (Path filePath : stream) {
  77                 String fileName = filePath.getFileName().toString();
  78                 for (int i = 0; i < extensions.length; i++) {
  79                     String extension = extensions[i];
  80                     if (fileName.endsWith(extensions[i])) {
  81                         assertTrue(paths[i] == null, "multiple files found for %s in %s", extension, directoryPath);
  82                         paths[i] = fileName.replace(extensions[i], "");
  83                     }
  84                 }
  85             }
  86         }
< prev index next >