test/jdk/tools/jlink/plugins/VendorInfoPluginsTest.java
changeset 58842 6c255334120d
child 58915 02ae223a11dc
equal deleted inserted replaced
58836:31ec3e55fa3d 58842:6c255334120d
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     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
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import jdk.test.lib.process.*;
       
    25 
       
    26 import tests.Helper;
       
    27 
       
    28 /* @test
       
    29  * @bug 8232080
       
    30  * @summary Test the --vendor-version --vendor-url-bug plugins
       
    31  * @library ../../lib
       
    32  * @library /test/lib
       
    33  * @modules java.base/jdk.internal.jimage
       
    34  *          jdk.jdeps/com.sun.tools.classfile
       
    35  *          jdk.jlink/jdk.tools.jlink.internal
       
    36  *          jdk.jlink/jdk.tools.jmod
       
    37  *          jdk.jlink/jdk.tools.jimage
       
    38  *          jdk.compiler
       
    39  * @build tests.*
       
    40  * @run main VendorInfoPluginsTest
       
    41  */
       
    42 
       
    43 public class VendorInfoPluginsTest {
       
    44 
       
    45     public static class Crasher {
       
    46 
       
    47         public static void main(String ... args) throws Exception {
       
    48             var uc = Class.forName("sun.misc.Unsafe");
       
    49             var f = uc.getDeclaredField("theUnsafe");
       
    50             f.setAccessible(true);
       
    51             var u = (sun.misc.Unsafe)f.get(null);
       
    52             for (long a = 0; a < Long.MAX_VALUE; a += 8)
       
    53                 u.putLong(a, -1L);
       
    54         }
       
    55 
       
    56     }
       
    57 
       
    58     private static final String VERSION = "XyzzyVM 3.14.15";
       
    59     private static final String BUG_URL = "https://bugs.xyzzy.com/";
       
    60     private static final String VM_BUG_URL = "https://bugs.xyzzy.com/crash/";
       
    61 
       
    62     public static void main(String[] args) throws Throwable {
       
    63 
       
    64         Helper helper = Helper.newHelper();
       
    65         if (helper == null) {
       
    66             System.err.println("Test not run");
       
    67             return;
       
    68         }
       
    69 
       
    70         var module = "vendorinfo";
       
    71         helper.generateDefaultJModule(module);
       
    72         var image = helper.generateDefaultImage(new String[] {
       
    73                 "--add-modules", "jdk.unsupported",
       
    74                 "--vendor-version", VERSION,
       
    75                 "--vendor-bug-url", BUG_URL,
       
    76                 "--vendor-vm-bug-url", VM_BUG_URL },
       
    77             module).assertSuccess();
       
    78         helper.checkImage(image, module, null, null);
       
    79 
       
    80         // Properties and --version
       
    81         var launcher
       
    82             = image.resolve("bin/java"
       
    83                             + (System.getProperty("os.name").startsWith("Windows")
       
    84                                ? ".exe" : "")).toString();
       
    85         var oa = ProcessTools.executeProcess(launcher,
       
    86                                              "-XshowSettings:properties",
       
    87                                              "--version");
       
    88         oa.stderrShouldMatch("^ +java.vendor.url.bug = " + BUG_URL + "$");
       
    89         oa.stderrShouldMatch("^ +java.vendor.version = " + VERSION + "$");
       
    90         oa.stdoutShouldMatch("^.*Runtime Environment " + VERSION + " \\(build.*$");
       
    91         oa.stdoutShouldMatch("^.*Server VM " + VERSION + " \\(build.*$");
       
    92 
       
    93         // VM error log
       
    94         oa = ProcessTools.executeProcess(launcher,
       
    95                                          "--class-path",
       
    96                                          System.getProperty("test.classes"),
       
    97                                          "VendorInfoPluginsTest$Crasher");
       
    98         oa.stdoutShouldMatch("^# +" + VM_BUG_URL + "$");
       
    99         oa.stdoutShouldMatch("^.*Runtime Environment " + VERSION + " \\(.*$");
       
   100         oa.stdoutShouldMatch("^.*Server VM " + VERSION + " \\(.*$");
       
   101 
       
   102     }
       
   103 
       
   104 }