hotspot/test/compiler/aot/cli/jaotc/JaotcTestHelper.java
author iignatyev
Fri, 18 Aug 2017 14:54:43 -0700
changeset 46826 dae7992b1615
parent 46804 db2cd95b294c
permissions -rw-r--r--
8183337: hotspot/compiler/aot tests fail due to missed tools Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     1
/*
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     4
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     8
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    13
 * accompanied this code).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    14
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    18
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    21
 * questions.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    22
 */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    23
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    24
package compiler.aot.cli.jaotc;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    25
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    26
import compiler.aot.AotCompiler;
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    27
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    28
import java.io.File;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    29
import java.io.IOException;
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    30
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    31
import jdk.test.lib.process.ExitCode;
46804
db2cd95b294c 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 46289
diff changeset
    32
import jdk.test.lib.Platform;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    33
import jdk.test.lib.JDKToolLauncher;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    34
import jdk.test.lib.Utils;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    35
import jdk.test.lib.cli.CommandLineOptionTest;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    37
import jdk.test.lib.process.ProcessTools;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    38
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    39
public class JaotcTestHelper {
46804
db2cd95b294c 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 46289
diff changeset
    40
    public static final String DEFAULT_LIB_PATH = "./unnamed." + Platform.sharedLibraryExt();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    41
    public static final String DEFAULT_LIBRARY_LOAD_MESSAGE = "loaded    " + DEFAULT_LIB_PATH
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    42
            + "  aot library";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    43
    private static final String ENABLE_AOT = "-XX:+UseAOT";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    44
    private static final String AOT_LIBRARY = "-XX:AOTLibrary=" + DEFAULT_LIB_PATH;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    45
    private static final String PRINT_AOT = "-XX:+PrintAOT";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    46
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    47
    public static OutputAnalyzer compileLibrary(String... args) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    48
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jaotc");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    49
        for (String vmOpt : Utils.getTestJavaOpts()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    50
            launcher.addVMArg(vmOpt);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    51
        }
43425
c5dc48e6d9e6 8172054: Aot tests should include Java assertions into AOT compiled code
kvn
parents: 42650
diff changeset
    52
        launcher.addToolArg("--compile-with-assertions");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    53
        for (String arg : args) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    54
            launcher.addToolArg(arg);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    55
        }
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    56
        String linker = AotCompiler.resolveLinker();
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    57
        if (linker != null) {
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    58
            launcher.addToolArg("--linker-path");
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    59
            launcher.addToolArg(linker);
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    60
        }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    61
        String[] cmd = launcher.getCommand();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    62
        try {
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    63
            return ProcessTools.executeCommand(cmd);
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    64
        } catch (Throwable e) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    65
            throw new Error("Can't start test process: " + e, e);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    66
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    67
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    68
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    69
    public static void checkLibraryUsage(String classToRun) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    70
        checkLibraryUsage(classToRun, new String[]{DEFAULT_LIBRARY_LOAD_MESSAGE}, null);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    71
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    72
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    73
    public static void checkLibraryUsage(String classToRun, String[] expectedOutput,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    74
            String[] unexpectedOutput) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    75
        try {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    76
            CommandLineOptionTest.verifyJVMStartup(expectedOutput, unexpectedOutput,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    77
                    "Unexpected exit code", "Unexpected output", ExitCode.OK,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    78
                    /* addTestVMOpts */ true, ENABLE_AOT, AOT_LIBRARY, PRINT_AOT, classToRun);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    79
        } catch (Throwable t) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    80
            throw new Error("Library usage verification failed: " + t, t);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    81
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    82
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    83
43464
f38fde4a6b52 8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents: 43425
diff changeset
    84
    public static String getClassAotCompilationFilename(Class<?> classToCompile) {
46289
bobv
parents: 43464 46260
diff changeset
    85
        return classToCompile.getName().replaceAll("\\.","/") + ".class";
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    86
    }
43464
f38fde4a6b52 8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents: 43425
diff changeset
    87
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    88
    public static String getClassAotCompilationName(Class<?> classToCompile) {
43464
f38fde4a6b52 8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents: 43425
diff changeset
    89
        return classToCompile.getName();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    90
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    91
}