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.options.OptionKey;
35 import org.graalvm.compiler.options.OptionValues;
36 import org.junit.Test;
37
38 /**
39 * Check that setting the dump path results in files ending up in the right directory with matching
40 * names.
41 */
42 public class DumpPathTest extends GraalCompilerTest {
43
44 public static Object snippet() {
45 return new String("snippet");
46 }
47
48 @Test
49 public void testDump() throws IOException {
50 assumeManagementLibraryIsLoadable();
51 Path dumpDirectoryPath = Files.createTempDirectory("DumpPathTest");
52 String[] extensions = new String[]{".cfg", ".bgv", ".graph-strings"};
53 EconomicMap<OptionKey<?>, Object> overrides = OptionValues.newOptionMap();
54 overrides.put(DebugOptions.DumpPath, dumpDirectoryPath.toString());
55 overrides.put(DebugOptions.PrintGraphFile, true);
56 overrides.put(DebugOptions.PrintCanonicalGraphStrings, true);
57 overrides.put(DebugOptions.Dump, "*");
58
59 // Generate dump files.
60 test(new OptionValues(getInitialOptions(), overrides), "snippet");
61 // Check that Ideal files got created, in the right place.
62 checkForFiles(dumpDirectoryPath, extensions);
63
64 // Clean up the generated files.
65 scrubDirectory(dumpDirectoryPath);
66 }
67
68 /**
69 * Check that the given directory contains file or directory names with all the given
70 * extensions.
71 */
72 private static void checkForFiles(Path directoryPath, String[] extensions) throws IOException {
73 String[] paths = new String[extensions.length];
74 try (DirectoryStream<Path> stream = Files.newDirectoryStream(directoryPath)) {
75 for (Path filePath : stream) {
|
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.PrintGraph, PrintGraphTarget.File);
57 overrides.put(DebugOptions.PrintCanonicalGraphStrings, true);
58 overrides.put(DebugOptions.Dump, "*");
59
60 // Generate dump files.
61 test(new OptionValues(getInitialOptions(), overrides), "snippet");
62 // Check that Ideal files got created, in the right place.
63 checkForFiles(dumpDirectoryPath, extensions);
64
65 // Clean up the generated files.
66 scrubDirectory(dumpDirectoryPath);
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) {
|