< prev index next >

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

Print this page




  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 package org.graalvm.compiler.core.test;
  24 
  25 import java.io.File;
  26 import java.io.IOException;
  27 import java.lang.reflect.Field;
  28 import java.lang.reflect.Method;
  29 import java.nio.file.Files;
  30 import java.nio.file.Path;
  31 import java.nio.file.Paths;
  32 import java.util.Comparator;
  33 
  34 import org.graalvm.compiler.printer.GraalDebugHandlersFactory;



  35 import org.graalvm.compiler.test.AddExports;

  36 import org.junit.Test;
  37 
  38 @AddExports("jdk.internal.vm.compiler/org.graalvm.compiler.printer")
  39 public class GraalDebugHandlersFactoryTest extends GraalCompilerTest {
  40 
  41     @Test
  42     public void createUniqueTest() throws Exception {
  43         Field maxFileNameLengthField = GraalDebugHandlersFactory.class.getDeclaredField("MAX_FILE_NAME_LENGTH");

  44         maxFileNameLengthField.setAccessible(true);



  45         int maxFileNameLength = maxFileNameLengthField.getInt(null);
  46         Method createUniqueMethod = GraalDebugHandlersFactory.class.getDeclaredMethod("createUnique", Path.class, String.class, String.class, String.class, boolean.class);
  47         createUniqueMethod.setAccessible(true);
  48         Path tmpDir = Files.createTempDirectory(Paths.get("."), "createUniqueTest");

  49         try {
  50             for (boolean createDirectory : new boolean[]{true, false}) {
  51                 for (String ext : new String[]{"", ".bgv", ".graph-strings"}) {
  52                     for (int i = 0; i < maxFileNameLength + 5; i++) {
  53                         String id = new String(new char[i]).replace('\0', 'i');
  54                         String label = "";
  55                         createUniqueMethod.invoke(null, tmpDir, id, label, ext, createDirectory);
  56 
  57                         id = "";
  58                         label = new String(new char[i]).replace('\0', 'l');
  59                         createUniqueMethod.invoke(null, tmpDir, id, label, ext, createDirectory);
  60                     }
  61                 }
  62             }
  63         } finally {
  64             deleteTree(tmpDir);
  65         }
  66     }
  67 
  68     private static void deleteTree(Path root) throws IOException {
  69         Files.walk(root).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
  70     }
  71 }


  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 package org.graalvm.compiler.core.test;
  24 
  25 import java.io.File;
  26 import java.io.IOException;
  27 import java.lang.reflect.Field;
  28 import java.lang.reflect.Method;
  29 import java.nio.file.Files;
  30 import java.nio.file.Path;
  31 import java.nio.file.Paths;
  32 import java.util.Comparator;
  33 
  34 import org.graalvm.compiler.debug.DebugOptions;
  35 import org.graalvm.compiler.debug.PathUtilities;
  36 import org.graalvm.compiler.options.OptionKey;
  37 import org.graalvm.compiler.options.OptionValues;
  38 import org.graalvm.compiler.test.AddExports;
  39 import org.junit.Assume;
  40 import org.junit.Test;
  41 
  42 @AddExports("jdk.internal.vm.compiler/org.graalvm.compiler.printer")
  43 public class GraalDebugHandlersFactoryTest extends GraalCompilerTest {
  44 
  45     @Test
  46     public void createUniqueTest() throws Exception {
  47         Field maxFileNameLengthField = PathUtilities.class.getDeclaredField("MAX_FILE_NAME_LENGTH");
  48         try {
  49             maxFileNameLengthField.setAccessible(true);
  50         } catch (RuntimeException ex) {
  51             Assume.assumeFalse("If InaccessibleObjectException is thrown, skip the test, we are on JDK9", ex.getClass().getSimpleName().equals("InaccessibleObjectException"));
  52         }
  53         int maxFileNameLength = maxFileNameLengthField.getInt(null);
  54         Method createUniqueMethod = PathUtilities.class.getDeclaredMethod("createUnique", OptionValues.class, OptionKey.class, String.class, String.class, String.class, boolean.class);
  55         createUniqueMethod.setAccessible(true);
  56         Path tmpDir = Files.createTempDirectory(Paths.get("."), "createUniqueTest");
  57         OptionValues options = new OptionValues(OptionValues.asMap(DebugOptions.DumpPath, tmpDir.toString()));
  58         try {
  59             for (boolean createDirectory : new boolean[]{true, false}) {
  60                 for (String ext : new String[]{"", ".bgv", ".graph-strings"}) {
  61                     for (int i = 0; i < maxFileNameLength + 5; i++) {
  62                         String id = new String(new char[i]).replace('\0', 'i');
  63                         String label = "";
  64                         createUniqueMethod.invoke(null, options, null, id, label, ext, createDirectory);
  65 
  66                         id = "";
  67                         label = new String(new char[i]).replace('\0', 'l');
  68                         createUniqueMethod.invoke(null, options, null, id, label, ext, createDirectory);
  69                     }
  70                 }
  71             }
  72         } finally {
  73             deleteTree(tmpDir);
  74         }
  75     }
  76 
  77     private static void deleteTree(Path root) throws IOException {
  78         Files.walk(root).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
  79     }
  80 }
< prev index next >