src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DumpPathTest.java
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DumpPathTest.java Thu Oct 17 20:27:44 2019 +0100
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DumpPathTest.java Thu Oct 17 20:53:35 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
import jdk.internal.vm.compiler.collections.EconomicMap;
import org.graalvm.compiler.debug.DebugOptions;
@@ -49,21 +50,20 @@
@Test
public void testDump() throws IOException {
assumeManagementLibraryIsLoadable();
- Path dumpDirectoryPath = Files.createTempDirectory("DumpPathTest");
- String[] extensions = new String[]{".cfg", ".bgv", ".graph-strings"};
- EconomicMap<OptionKey<?>, Object> overrides = OptionValues.newOptionMap();
- overrides.put(DebugOptions.DumpPath, dumpDirectoryPath.toString());
- overrides.put(DebugOptions.PrintGraph, PrintGraphTarget.File);
- overrides.put(DebugOptions.PrintCanonicalGraphStrings, true);
- overrides.put(DebugOptions.Dump, "*");
+ try (TemporaryDirectory temp = new TemporaryDirectory(Paths.get("."), "DumpPathTest")) {
+ String[] extensions = new String[]{".cfg", ".bgv", ".graph-strings"};
+ EconomicMap<OptionKey<?>, Object> overrides = OptionValues.newOptionMap();
+ overrides.put(DebugOptions.DumpPath, temp.toString());
+ overrides.put(DebugOptions.PrintCFG, true);
+ overrides.put(DebugOptions.PrintGraph, PrintGraphTarget.File);
+ overrides.put(DebugOptions.PrintCanonicalGraphStrings, true);
+ overrides.put(DebugOptions.Dump, "*");
- // Generate dump files.
- test(new OptionValues(getInitialOptions(), overrides), "snippet");
- // Check that Ideal files got created, in the right place.
- checkForFiles(dumpDirectoryPath, extensions);
-
- // Clean up the generated files.
- scrubDirectory(dumpDirectoryPath);
+ // Generate dump files.
+ test(new OptionValues(getInitialOptions(), overrides), "snippet");
+ // Check that IGV files got created, in the right place.
+ checkForFiles(temp.path, extensions);
+ }
}
/**
@@ -92,24 +92,4 @@
assertTrue(paths[0].equals(paths[i]), paths[0] + " != " + paths[i]);
}
}
-
- /**
- * Remove the temporary directory.
- */
- private static void scrubDirectory(Path directoryPath) {
- try {
- try (DirectoryStream<Path> stream = Files.newDirectoryStream(directoryPath)) {
- for (Path filePath : stream) {
- if (Files.isRegularFile(filePath)) {
- Files.delete(filePath);
- } else if (Files.isDirectory(filePath)) {
- scrubDirectory(filePath);
- }
- }
- }
- Files.delete(directoryPath);
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- }
}