test/jdk/tools/launcher/VersionCheck.java
author herrick
Fri, 07 Dec 2018 19:07:08 -0500
branchJDK-8200758-branch
changeset 57065 2446962c555c
parent 52850 f527b24990d7
child 57106 ea870b9ce89a
permissions -rw-r--r--
8214982: jpackage causes failures in existing HelpFlagsTest and VersionCheck tests Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
48841
0937e5f799df 8190378: Removal of CORBA and Java EE modules
lancea
parents: 47224
diff changeset
     2
 * Copyright (c) 2007, 2018, 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.
45944
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 43537
diff changeset
    29
 * @modules jdk.compiler
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 43537
diff changeset
    30
 *          jdk.zipfs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @compile VersionCheck.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main VersionCheck
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.File;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    36
import java.io.FileFilter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.ArrayList;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    39
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.List;
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
    41
import java.util.HashSet;
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
    42
import java.util.Set;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    44
public class VersionCheck extends TestHelper {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    46
    // tools that do not accept -J-option
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    47
    static final String[] BLACKLIST_JOPTION = {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    48
        "controlpanel",
15529
8112eb76bda3 8007135: tools/launcher/VersionCheck.java failing with new tool jabswitch
ksrini
parents: 14998
diff changeset
    49
        "jabswitch",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    50
        "java-rmi",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    51
        "java-rmi.cgi",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    52
        "java",
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27190
diff changeset
    53
        "javacpl",
34434
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    54
        "jaccessinspector",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    55
        "jaccessinspector-32",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    56
        "jaccesswalker",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    57
        "jaccesswalker-32",
42767
8ea2f3d10b8c 8171414: tools/launcher/VersionCheck.java failed with AssertionError due to new tool jaotc
jwilhelm
parents: 40555
diff changeset
    58
        "jaotc",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    59
        "javaw",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    60
        "javaws",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    61
        "jcontrol",
18152
804f7c54faa6 8016209: TEST_BUG: non-compliant jmc in the bin directory hangs testing
ksrini
parents: 16029
diff changeset
    62
        "jmc",
21327
9fc34e0b2a47 8026873: tools/launcher/VersionCheck.java fails in jprt because of jmc.ini
kizune
parents: 18152
diff changeset
    63
        "jmc.ini",
39881
c082c149d6eb 8162746: VersionCheck.java failure after change for JDK-8160921
darcy
parents: 37540
diff changeset
    64
        "jweblauncher",
57065
2446962c555c 8214982: jpackage causes failures in existing HelpFlagsTest and VersionCheck tests
herrick
parents: 52850
diff changeset
    65
        "jpackage",
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27190
diff changeset
    66
        "ssvagent",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    67
        "unpack200",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    68
    };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    70
    // tools that do not accept -version
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    71
    static final String[] BLACKLIST_VERSION = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        "appletviewer",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    73
        "controlpanel",
34434
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    74
        "jaccessinspector",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    75
        "jaccessinspector-32",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    76
        "jaccesswalker",
16dd60e78af4 8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents: 34392
diff changeset
    77
        "jaccesswalker-32",
42767
8ea2f3d10b8c 8171414: tools/launcher/VersionCheck.java failed with AssertionError due to new tool jaotc
jwilhelm
parents: 40555
diff changeset
    78
        "jaotc",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        "jar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        "jarsigner",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    81
        "java-rmi",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    82
        "java-rmi.cgi",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        "javadoc",
27942
b43cb0ec4975 8066841: Need to exclude javacpl in tools/launcher/VersionCheck.java
ksrini
parents: 27565
diff changeset
    84
        "javacpl",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    85
        "javaws",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    86
        "jcmd",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        "jconsole",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    88
        "jcontrol",
40555
face0a3ae86c 8164834: remove jdeprscan from tools/launcher/VersionCheck.java
smarks
parents: 40198
diff changeset
    89
        "jdeprscan",
14998
b9a99aac309e 8005634: tools/launcher/VersionCheck.java fails version check on jdeps
chegar
parents: 12301
diff changeset
    90
        "jdeps",
52850
f527b24990d7 8205516: JFR tool
egahlin
parents: 48841
diff changeset
    91
        "jfr",
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27190
diff changeset
    92
        "jimage",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        "jinfo",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34434
diff changeset
    94
        "jlink",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        "jmap",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34434
diff changeset
    96
        "jmod",
18152
804f7c54faa6 8016209: TEST_BUG: non-compliant jmc in the bin directory hangs testing
ksrini
parents: 16029
diff changeset
    97
        "jmc",
21327
9fc34e0b2a47 8026873: tools/launcher/VersionCheck.java fails in jprt because of jmc.ini
kizune
parents: 18152
diff changeset
    98
        "jmc.ini",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        "jps",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   100
        "jrunscript",
16029
4e88242da117 8008914: Add nashorn to the tl build
jjg
parents: 15529
diff changeset
   101
        "jjs",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        "jstack",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        "jstat",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        "jstatd",
39881
c082c149d6eb 8162746: VersionCheck.java failure after change for JDK-8160921
darcy
parents: 37540
diff changeset
   105
        "jweblauncher",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        "keytool",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   107
        "kinit",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   108
        "klist",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   109
        "ktab",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        "pack200",
57065
2446962c555c 8214982: jpackage causes failures in existing HelpFlagsTest and VersionCheck tests
herrick
parents: 52850
diff changeset
   111
        "jpackage",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        "rmic",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        "rmid",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        "rmiregistry",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        "serialver",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        "servertool",
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27190
diff changeset
   117
        "ssvagent",
48841
0937e5f799df 8190378: Removal of CORBA and Java EE modules
lancea
parents: 47224
diff changeset
   118
        "unpack200"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // expected reference strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    static String refVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    static String refFullVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   125
    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
   126
        return getVersion0(true, argv);
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   127
    }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   128
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    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
   130
        return getVersion0(false, argv);
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   131
    }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   132
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   133
    static String getVersion0(boolean allLines, String... argv) {
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   134
        TestHelper.TestResult tr = doExec(argv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        StringBuilder out = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // remove the HotSpot line
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   137
        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
   138
            if (allLines || !x.matches(".*Client.*VM.*|.*Server.*VM.*")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                out = out.append(x + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return out.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   145
    /*
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   146
     * Checks if the tools accept "-version" option (exit code is zero).
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   147
     * The output of the tools run with "-version" is not verified.
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   148
     */
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   149
    static String testToolVersion() {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   150
        System.out.println("=== testToolVersion === ");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   151
        Set<String> failed = new HashSet<>();
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   152
        for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_VERSION))) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   153
            String x = f.getAbsolutePath();
37540
e92d95400f31 8154470: defines.h confused about PROGNAME and JAVA_ARGS
martin
parents: 36511
diff changeset
   154
            TestResult tr = doExec(x, "-version");
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   155
            System.out.println("Testing " + f.getName());
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   156
            System.out.println("#> " + x + " -version");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   157
            tr.testOutput.forEach(System.out::println);
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   158
            System.out.println("#> echo $?");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   159
            System.out.println(tr.exitValue);
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   160
            if (!tr.isOK()) {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   161
                System.out.println("failed");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   162
                failed.add(f.getName());
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   163
            }
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   164
        }
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   165
        if (failed.isEmpty()) {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   166
            System.out.println("testToolVersion passed");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   167
            return "";
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   168
        } else {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   169
            System.out.println("testToolVersion failed");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   170
            return "testToolVersion: " + failed + "; ";
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   171
        }
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   172
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   173
    }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   174
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   175
    static String testJVersionStrings() {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   176
        System.out.println("=== testJVersionStrings === ");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   177
        Set<String> failed = new HashSet<>();
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   178
        for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_JOPTION))) {
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   179
            System.out.println("Testing " + f.getName());
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   180
            String x = f.getAbsolutePath();
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   181
            String testStr = getVersion(x, "-J-version");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (refVersion.compareTo(testStr) != 0) {
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   183
                failed.add(f.getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                System.out.println("Error: " + x +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                   " fails -J-version comparison");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                System.out.println("Expected:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                System.out.print(refVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                System.out.println("Actual:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                System.out.print(testStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            testStr = getVersion(x, "-J-fullversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if (refFullVersion.compareTo(testStr) != 0) {
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   194
                failed.add(f.getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                System.out.println("Error: " + x +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                   " fails -J-fullversion comparison");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                System.out.println("Expected:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                System.out.print(refFullVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                System.out.println("Actual:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                System.out.print(testStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   203
        if (failed.isEmpty()) {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   204
            System.out.println("testJVersionStrings passed");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   205
            return "";
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   206
        } else {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   207
            System.out.println("testJVersionStrings failed");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   208
            return "testJVersionStrings: " + failed + "; ";
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   209
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   212
    static String testInternalStrings() {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   213
        System.out.println("=== testInternalStrings === ");
34392
ae4033cd28f4 8144533: VersionCheck.java failing after Verona changes in dev
ksrini
parents: 34011
diff changeset
   214
        String bStr = refVersion.substring(refVersion.indexOf("build") +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                           "build".length() + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                           refVersion.lastIndexOf(")"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        String expectedFullVersion = "fullversion:" + bStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   220
        Map<String, String> envMap = new HashMap<>();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   221
        envMap.put(TestHelper.JLDEBUG_KEY, "true");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   222
        TestHelper.TestResult tr = doExec(envMap, javaCmd, "-version");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   223
        List<String> alist = new ArrayList<>();
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   224
        tr.testOutput.stream().map(String::trim).forEach(alist::add);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   226
        if (alist.contains(expectedFullVersion)) {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   227
            System.out.println("testInternalStrings passed");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   228
            return "";
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   229
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            System.out.println("Error: could not find " + expectedFullVersion);
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   231
            tr.testOutput.forEach(System.out::println);
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   232
            System.out.println("testInternalStrings failed");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   233
            return "testInternalStrings; ";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   237
    static String testDebugVersion() {
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   238
        System.out.println("=== testInternalStrings === ");
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   239
        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
   240
        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
   241
        if ("release".equals(jdkType)) {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   242
            jdkType = "";
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   243
        } else {
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   244
            jdkType = jdkType + " ";
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   245
        }
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   246
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   247
        String tofind = "(" + jdkType + "build";
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   248
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   249
        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
   250
        if (idx < 0) {
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   251
            System.out.println("versionLines " + versionLines);
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   252
            System.out.println("Did not find first instance of " + tofind);
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   253
            return "testDebugVersion; ";
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   254
        }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   255
        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
   256
        if (idx < 0) {
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   257
            System.out.println("versionLines " + versionLines);
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   258
            System.out.println("Did not find second instance of " + tofind);
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   259
            return "testDebugVersion; ";
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   260
        }
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   261
        System.out.println("testDebugVersion passed");
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   262
        return "";
34011
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   263
    }
b1ce08dd7f17 8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents: 33987
diff changeset
   264
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    // Initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    static void init() {
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   267
        refVersion = getVersion(javaCmd, "-version");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   268
        refFullVersion = getVersion(javaCmd, "-fullversion");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        init();
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   273
        String errorMessage = "";
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   274
        errorMessage += testJVersionStrings();
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   275
        errorMessage += testInternalStrings();
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   276
        errorMessage += testToolVersion();
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   277
        errorMessage += testDebugVersion();
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   278
        if (errorMessage.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            System.out.println("All Version string comparisons: PASS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } else {
43525
2b4d0a8e7557 8171441: tools/launcher/VersionCheck.java doesn't report names of tools which failed checks
dfazunen
parents: 42767
diff changeset
   281
            throw new AssertionError("VersionCheck failed: " + errorMessage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   284
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   285
    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
   286
        final Iterable<String> exclude;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   287
        protected ToolFilter(String... exclude) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   288
            List<String> tlist = new ArrayList<>();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   289
            this.exclude = tlist;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   290
            for (String x : exclude) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   291
                String str = x + ((isWindows) ? EXE_FILE_EXT : "");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   292
                tlist.add(str.toLowerCase());
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   293
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   294
        }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   295
        @Override
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   296
        public boolean accept(File pathname) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   297
            if (!pathname.isFile() || !pathname.canExecute()) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   298
                return false;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   299
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   300
            String name = pathname.getName().toLowerCase();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   301
            if (isWindows && !name.endsWith(EXE_FILE_EXT)) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   302
                return false;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   303
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   304
            for (String x : exclude) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   305
                if (name.endsWith(x)) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   306
                    return false;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   307
                }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   308
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   309
            return true;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   310
        }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   311
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
}