jdk/test/tools/launcher/VersionCheck.java
author smarks
Thu, 25 Aug 2016 21:58:38 -0700
changeset 40555 face0a3ae86c
parent 40198 725b19ace748
child 42767 8ea2f3d10b8c
permissions -rw-r--r--
8164834: remove jdeprscan from tools/launcher/VersionCheck.java Reviewed-by: sundar, darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39881
c082c149d6eb 8162746: VersionCheck.java failure after change for JDK-8160921
darcy
parents: 37540
diff changeset
     2
 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
39881
c082c149d6eb 8162746: VersionCheck.java failure after change for JDK-8160921
darcy
parents: 37540
diff changeset
    26
 * @bug 6545058 6611182 8016209 8139986 8162746
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    27
 * @summary validate and test -version, -fullversion, and internal, as well as
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    28
 *          sanity checks if a tool can be launched.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @compile VersionCheck.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run main VersionCheck
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.File;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    34
import java.io.FileFilter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ArrayList;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    37
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    40
public class VersionCheck extends TestHelper {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    42
    // tools that do not accept -J-option
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    43
    static final String[] BLACKLIST_JOPTION = {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    44
        "controlpanel",
15529
8112eb76bda3 8007135: tools/launcher/VersionCheck.java failing with new tool jabswitch
ksrini
parents: 14998
diff changeset
    45
        "jabswitch",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    46
        "java-rmi",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    47
        "java-rmi.cgi",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    48
        "java",
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27190
diff changeset
    49
        "javacpl",
34434
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    50
        "jaccessinspector",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    51
        "jaccessinspector-32",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    52
        "jaccesswalker",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    53
        "jaccesswalker-32",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    54
        "javaw",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    55
        "javaws",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    56
        "jcontrol",
18152
804f7c54faa6 8016209: TEST_BUG: non-compliant jmc in the bin directory hangs testing
ksrini
parents: 16029
diff changeset
    57
        "jmc",
21327
9fc34e0b2a47 8026873: tools/launcher/VersionCheck.java fails in jprt because of jmc.ini
kizune
parents: 18152
diff changeset
    58
        "jmc.ini",
39881
c082c149d6eb 8162746: VersionCheck.java failure after change for JDK-8160921
darcy
parents: 37540
diff changeset
    59
        "jweblauncher",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    60
        "jvisualvm",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    61
        "packager",
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27190
diff changeset
    62
        "ssvagent",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    63
        "unpack200",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    64
        "wsimport"
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    65
    };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    67
    // tools that do not accept -version
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    68
    static final String[] BLACKLIST_VERSION = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        "appletviewer",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    70
        "controlpanel",
34434
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    71
        "jaccessinspector",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    72
        "jaccessinspector-32",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    73
        "jaccesswalker",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    74
        "jaccesswalker-32",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        "jar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        "jarsigner",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    77
        "java-rmi",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    78
        "java-rmi.cgi",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        "javadoc",
27942
b43cb0ec4975 8066841: Need to exclude javacpl in tools/launcher/VersionCheck.java
ksrini
parents: 27565
diff changeset
    80
        "javacpl",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    81
        "javaws",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    82
        "jcmd",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        "jconsole",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    84
        "jcontrol",
40555
face0a3ae86c 8164834: remove jdeprscan from tools/launcher/VersionCheck.java
smarks
parents: 40198
diff changeset
    85
        "jdeprscan",
14998
b9a99aac309e 8005634: tools/launcher/VersionCheck.java fails version check on jdeps
chegar
parents: 12301
diff changeset
    86
        "jdeps",
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27190
diff changeset
    87
        "jimage",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        "jinfo",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34434
diff changeset
    89
        "jlink",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        "jmap",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34434
diff changeset
    91
        "jmod",
18152
804f7c54faa6 8016209: TEST_BUG: non-compliant jmc in the bin directory hangs testing
ksrini
parents: 16029
diff changeset
    92
        "jmc",
21327
9fc34e0b2a47 8026873: tools/launcher/VersionCheck.java fails in jprt because of jmc.ini
kizune
parents: 18152
diff changeset
    93
        "jmc.ini",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        "jps",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    95
        "jrunscript",
16029
4e88242da117 8008914: Add nashorn to the tl build
jjg
parents: 15529
diff changeset
    96
        "jjs",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        "jstack",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        "jstat",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        "jstatd",
39881
c082c149d6eb 8162746: VersionCheck.java failure after change for JDK-8160921
darcy
parents: 37540
diff changeset
   100
        "jweblauncher",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   101
        "jvisualvm",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        "keytool",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   103
        "kinit",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   104
        "klist",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   105
        "ktab",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        "orbd",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        "pack200",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   108
        "packager",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        "policytool",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        "rmic",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        "rmid",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        "rmiregistry",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   113
        "schemagen", // returns error code 127
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        "serialver",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        "servertool",
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27190
diff changeset
   116
        "ssvagent",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        "tnameserv",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   118
        "unpack200",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        "wsgen",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        "wsimport",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        "xjc"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    // expected reference strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    static String refVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    static String refFullVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   128
    static String getAllVersionLines(String... argv) {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   129
        return getVersion0(true, argv);
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   130
    }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   131
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    static String getVersion(String... argv) {
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   133
        return getVersion0(false, argv);
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   134
    }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   135
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   136
    static String getVersion0(boolean allLines, String... argv) {
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   137
        TestHelper.TestResult tr = doExec(argv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        StringBuilder out = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        // remove the HotSpot line
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   140
        for (String x : tr.testOutput) {
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   141
            if (allLines || !x.matches(".*Client.*VM.*|.*Server.*VM.*")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                out = out.append(x + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return out.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   148
    /*
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   149
     * this tests if the tool can take a version string and returns
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   150
     * a 0 exit code, it is not possible to validate the contents
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   151
     * of the -version output as they are inconsistent.
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   152
     */
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   153
    static boolean testToolVersion() {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   154
        TestHelper.testExitValue = 0;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   155
        for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_VERSION))) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   156
            String x = f.getAbsolutePath();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   157
            System.out.println("Testing (-version): " + x);
37540
e92d95400f31 8154470: defines.h confused about PROGNAME and JAVA_ARGS
martin
parents: 36511
diff changeset
   158
            TestResult tr = doExec(x, "-version");
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   159
            tr.checkPositive();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   160
        }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   161
        return TestHelper.testExitValue == 0;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   162
    }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   163
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   164
    static boolean compareJVersionStrings() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        int failcount = 0;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   166
        for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_JOPTION))) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   167
            String x = f.getAbsolutePath();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   168
            System.out.println("Testing (-J-version): " + x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            String testStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            testStr = getVersion(x, "-J-version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (refVersion.compareTo(testStr) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                failcount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                System.out.println("Error: " + x +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                   " fails -J-version comparison");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                System.out.println("Expected:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                System.out.print(refVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                System.out.println("Actual:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                System.out.print(testStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            testStr = getVersion(x, "-J-fullversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (refFullVersion.compareTo(testStr) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                failcount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                System.out.println("Error: " + x +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                   " fails -J-fullversion comparison");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                System.out.println("Expected:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                System.out.print(refFullVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                System.out.println("Actual:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                System.out.print(testStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        System.out.println("Version Test: " + failcount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return failcount == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    static boolean compareInternalStrings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        int failcount = 0;
34392
ae4033cd28f4 8144533: VersionCheck.java failing after Verona changes in dev
ksrini
parents: 34011
diff changeset
   199
        String bStr = refVersion.substring(refVersion.indexOf("build") +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                           "build".length() + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                           refVersion.lastIndexOf(")"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        String expectedFullVersion = "fullversion:" + bStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   205
        Map<String, String> envMap = new HashMap<>();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   206
        envMap.put(TestHelper.JLDEBUG_KEY, "true");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   207
        TestHelper.TestResult tr = doExec(envMap, javaCmd, "-version");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   208
        List<String> alist = new ArrayList<>();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   209
        alist.addAll(tr.testOutput);
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   210
        for (String x : tr.testOutput) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   211
            alist.add(x.trim());
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   212
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (!alist.contains(expectedFullVersion)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            System.out.println("Error: could not find " + expectedFullVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            failcount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        System.out.println("Internal Strings Test: " + failcount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return failcount == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   222
    static boolean testDebugVersion() {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   223
        String jdkType = System.getProperty("jdk.debug", "release");
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   224
        String versionLines = getAllVersionLines(javaCmd, "-version");
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   225
        if ("release".equals(jdkType)) {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   226
            jdkType = "";
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   227
        } else {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   228
            jdkType = jdkType + " ";
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   229
        }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   230
        String tofind = "(" + jdkType + "build";
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   231
        int idx = versionLines.indexOf(tofind);
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   232
        if (idx < 0) {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   233
            System.out.println("Did not find first instance of " + tofind);
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   234
            return false;
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   235
        }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   236
        idx =  versionLines.indexOf(tofind, idx + 1);
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   237
        if (idx < 0) {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   238
            System.out.println("Did not find first instance of " + tofind);
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   239
            return false;
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   240
        }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   241
        return true;
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   242
    }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   243
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    // Initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    static void init() {
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   246
        refVersion = getVersion(javaCmd, "-version");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   247
        refFullVersion = getVersion(javaCmd, "-fullversion");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        init();
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   252
        if (compareJVersionStrings() &&
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   253
                compareInternalStrings() &&
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   254
                testToolVersion() &&
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   255
                testDebugVersion()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            System.out.println("All Version string comparisons: PASS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            throw new AssertionError("Some tests failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   261
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   262
    static class ToolFilter implements FileFilter {
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   263
        final Iterable<String> exclude;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   264
        protected ToolFilter(String... exclude) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   265
            List<String> tlist = new ArrayList<>();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   266
            this.exclude = tlist;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   267
            for (String x : exclude) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   268
                String str = x + ((isWindows) ? EXE_FILE_EXT : "");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   269
                tlist.add(str.toLowerCase());
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   270
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   271
        }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   272
        @Override
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   273
        public boolean accept(File pathname) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   274
            if (!pathname.isFile() || !pathname.canExecute()) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   275
                return false;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   276
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   277
            String name = pathname.getName().toLowerCase();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   278
            if (isWindows && !name.endsWith(EXE_FILE_EXT)) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   279
                return false;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   280
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   281
            for (String x : exclude) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   282
                if (name.endsWith(x)) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   283
                    return false;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   284
                }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   285
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   286
            return true;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   287
        }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   288
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}