jdk/test/tools/launcher/VersionCheck.java
changeset 34011 b1ce08dd7f17
parent 33987 24ecd3c83f33
child 34392 ae4033cd28f4
equal deleted inserted replaced
34010:3aa306b5485e 34011:b1ce08dd7f17
     1 /*
     1 /*
     2  * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @test
    25  * @test
    26  * @bug 6545058 6611182 8016209
    26  * @bug 6545058 6611182 8016209 8139986
    27  * @summary validate and test -version, -fullversion, and internal, as well as
    27  * @summary validate and test -version, -fullversion, and internal, as well as
    28  *          sanity checks if a tool can be launched.
    28  *          sanity checks if a tool can be launched.
    29  * @compile VersionCheck.java
    29  * @compile VersionCheck.java
    30  * @run main VersionCheck
    30  * @run main VersionCheck
    31  */
    31  */
   113 
   113 
   114     // expected reference strings
   114     // expected reference strings
   115     static String refVersion;
   115     static String refVersion;
   116     static String refFullVersion;
   116     static String refFullVersion;
   117 
   117 
       
   118     static String getAllVersionLines(String... argv) {
       
   119         return getVersion0(true, argv);
       
   120     }
       
   121 
   118     static String getVersion(String... argv) {
   122     static String getVersion(String... argv) {
       
   123         return getVersion0(false, argv);
       
   124     }
       
   125 
       
   126     static String getVersion0(boolean allLines, String... argv) {
   119         TestHelper.TestResult tr = doExec(argv);
   127         TestHelper.TestResult tr = doExec(argv);
   120         StringBuilder out = new StringBuilder();
   128         StringBuilder out = new StringBuilder();
   121         // remove the HotSpot line
   129         // remove the HotSpot line
   122         for (String x : tr.testOutput) {
   130         for (String x : tr.testOutput) {
   123             if (!x.matches(".*Client.*VM.*|.*Server.*VM.*")) {
   131             if (allLines || !x.matches(".*Client.*VM.*|.*Server.*VM.*")) {
   124                 out = out.append(x + "\n");
   132                 out = out.append(x + "\n");
   125             }
   133             }
   126         }
   134         }
   127         return out.toString();
   135         return out.toString();
   128     }
   136     }
   200         }
   208         }
   201         System.out.println("Internal Strings Test: " + failcount);
   209         System.out.println("Internal Strings Test: " + failcount);
   202         return failcount == 0;
   210         return failcount == 0;
   203     }
   211     }
   204 
   212 
       
   213     static boolean testDebugVersion() {
       
   214         String jdkType = System.getProperty("jdk.debug", "release");
       
   215         String versionLines = getAllVersionLines(javaCmd, "-version");
       
   216         if ("release".equals(jdkType)) {
       
   217             jdkType = "";
       
   218         } else {
       
   219             jdkType = jdkType + " ";
       
   220         }
       
   221         String tofind = "(" + jdkType + "build";
       
   222         int idx = versionLines.indexOf(tofind);
       
   223         if (idx < 0) {
       
   224             System.out.println("Did not find first instance of " + tofind);
       
   225             return false;
       
   226         }
       
   227         idx =  versionLines.indexOf(tofind, idx + 1);
       
   228         if (idx < 0) {
       
   229             System.out.println("Did not find first instance of " + tofind);
       
   230             return false;
       
   231         }
       
   232         return true;
       
   233     }
       
   234 
   205     // Initialize
   235     // Initialize
   206     static void init() {
   236     static void init() {
   207         refVersion = getVersion(javaCmd, "-version");
   237         refVersion = getVersion(javaCmd, "-version");
   208         refFullVersion = getVersion(javaCmd, "-fullversion");
   238         refFullVersion = getVersion(javaCmd, "-fullversion");
   209     }
   239     }
   210 
   240 
   211     public static void main(String[] args) {
   241     public static void main(String[] args) {
   212         init();
   242         init();
   213         if (compareJVersionStrings() &&
   243         if (compareJVersionStrings() &&
   214                 compareInternalStrings() &&
   244                 compareInternalStrings() &&
   215                 testToolVersion()) {
   245                 testToolVersion() &&
       
   246                 testDebugVersion()) {
   216             System.out.println("All Version string comparisons: PASS");
   247             System.out.println("All Version string comparisons: PASS");
   217         } else {
   248         } else {
   218             throw new AssertionError("Some tests failed");
   249             throw new AssertionError("Some tests failed");
   219         }
   250         }
   220     }
   251     }
   221 
   252 
   222     static class ToolFilter implements FileFilter {
   253     static class ToolFilter implements FileFilter {
   223         final Iterable<String> exclude ;
   254         final Iterable<String> exclude;
   224         protected ToolFilter(String... exclude) {
   255         protected ToolFilter(String... exclude) {
   225             List<String> tlist = new ArrayList<>();
   256             List<String> tlist = new ArrayList<>();
   226             this.exclude = tlist;
   257             this.exclude = tlist;
   227             for (String x : exclude) {
   258             for (String x : exclude) {
   228                 String str = x + ((isWindows) ? EXE_FILE_EXT : "");
   259                 String str = x + ((isWindows) ? EXE_FILE_EXT : "");