src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/DumpPathTest.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58299 6df94ce3ab2f
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     1
/*
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     4
 *
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     8
 *
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    13
 * accompanied this code).
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    14
 *
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    18
 *
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    21
 * questions.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 49873
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 49873
diff changeset
    24
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    25
package org.graalvm.compiler.core.test;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    26
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    27
import java.io.IOException;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    28
import java.nio.file.DirectoryStream;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    29
import java.nio.file.Files;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    30
import java.nio.file.Path;
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    31
import java.nio.file.Paths;
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    32
49873
26ebfe8ce852 8199755: Update Graal
dlong
parents: 48861
diff changeset
    33
import jdk.internal.vm.compiler.collections.EconomicMap;
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    34
import org.graalvm.compiler.debug.DebugOptions;
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    35
import org.graalvm.compiler.debug.DebugOptions.PrintGraphTarget;
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    36
import org.graalvm.compiler.options.OptionKey;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    37
import org.graalvm.compiler.options.OptionValues;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    38
import org.junit.Test;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    39
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    40
/**
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    41
 * Check that setting the dump path results in files ending up in the right directory with matching
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    42
 * names.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    43
 */
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    44
public class DumpPathTest extends GraalCompilerTest {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    45
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    46
    public static Object snippet() {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    47
        return new String("snippet");
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    48
    }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    49
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    50
    @Test
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    51
    public void testDump() throws IOException {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    52
        assumeManagementLibraryIsLoadable();
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    53
        try (TemporaryDirectory temp = new TemporaryDirectory(Paths.get("."), "DumpPathTest")) {
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    54
            String[] extensions = new String[]{".cfg", ".bgv", ".graph-strings"};
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    55
            EconomicMap<OptionKey<?>, Object> overrides = OptionValues.newOptionMap();
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    56
            overrides.put(DebugOptions.DumpPath, temp.toString());
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    57
            overrides.put(DebugOptions.PrintCFG, true);
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    58
            overrides.put(DebugOptions.PrintGraph, PrintGraphTarget.File);
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    59
            overrides.put(DebugOptions.PrintCanonicalGraphStrings, true);
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    60
            overrides.put(DebugOptions.Dump, "*");
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    61
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    62
            // Generate dump files.
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    63
            test(new OptionValues(getInitialOptions(), overrides), "snippet");
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    64
            // Check that IGV files got created, in the right place.
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    65
            checkForFiles(temp.path, extensions);
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
    66
        }
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    67
    }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    68
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    69
    /**
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    70
     * Check that the given directory contains file or directory names with all the given
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    71
     * extensions.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    72
     */
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    73
    private static void checkForFiles(Path directoryPath, String[] extensions) throws IOException {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    74
        String[] paths = new String[extensions.length];
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    75
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(directoryPath)) {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    76
            for (Path filePath : stream) {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    77
                String fileName = filePath.getFileName().toString();
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    78
                for (int i = 0; i < extensions.length; i++) {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    79
                    String extension = extensions[i];
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    80
                    if (fileName.endsWith(extensions[i])) {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    81
                        assertTrue(paths[i] == null, "multiple files found for %s in %s", extension, directoryPath);
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    82
                        paths[i] = fileName.replace(extensions[i], "");
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    83
                    }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    84
                }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    85
            }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    86
        }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    87
        for (int i = 0; i < paths.length; i++) {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    88
            assertTrue(paths[i] != null, "missing file for extension %s in %s", extensions[i], directoryPath);
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    89
        }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    90
        // Ensure that all file names are the same.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    91
        for (int i = 1; i < paths.length; i++) {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    92
            assertTrue(paths[0].equals(paths[i]), paths[0] + " != " + paths[i]);
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    93
        }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    94
    }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    95
}