test/runtime/SharedArchiveFile/PrintSharedArchiveAndExit.java

Thu, 04 Dec 2014 15:20:09 -0800

author
iklam
date
Thu, 04 Dec 2014 15:20:09 -0800
changeset 7414
0558eb13dcf3
permissions
-rw-r--r--

8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
Summary: in FileMapInfo::fail_continue do not set UseSharedSpaces = false
Reviewed-by: dholmes, ccheung

     1 /*
     2  * Copyright (c) 2014, 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  */
    24 /*
    25  * @test
    26  * @bug 8066670
    27  * @summary Testing -XX:+PrintSharedArchiveAndExit option
    28  * @library /testlibrary
    29  */
    31 import com.oracle.java.testlibrary.*;
    33 public class PrintSharedArchiveAndExit {
    34   public static void main(String[] args) throws Exception {
    35     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    36         "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:dump");
    37     OutputAnalyzer output = new OutputAnalyzer(pb.start());
    38     try {
    39       output.shouldContain("Loading classes to share");
    40       output.shouldHaveExitValue(0);
    42       // (1) With a valid archive
    43       pb = ProcessTools.createJavaProcessBuilder(
    44           "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa",
    45           "-XX:+PrintSharedArchiveAndExit", "-version");
    46       output = new OutputAnalyzer(pb.start());
    47       output.shouldContain("archive is valid");
    48       output.shouldNotContain("java version");     // Should not print JVM version
    49       output.shouldHaveExitValue(0);               // Should report success in error code.
    51       pb = ProcessTools.createJavaProcessBuilder(
    52           "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa",
    53           "-XX:+PrintSharedArchiveAndExit");
    54       output = new OutputAnalyzer(pb.start());
    55       output.shouldContain("archive is valid");
    56       output.shouldNotContain("Usage:");           // Should not print JVM help message
    57       output.shouldHaveExitValue(0);               // Should report success in error code.
    59       // (2) With an invalid archive (boot class path has been prepended)
    60       pb = ProcessTools.createJavaProcessBuilder(
    61           "-Xbootclasspath/p:foo.jar",
    62           "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa",
    63           "-XX:+PrintSharedArchiveAndExit", "-version");
    64       output = new OutputAnalyzer(pb.start());
    65       output.shouldContain("archive is invalid");
    66       output.shouldNotContain("java version");     // Should not print JVM version
    67       output.shouldHaveExitValue(1);               // Should report failure in error code.
    69       pb = ProcessTools.createJavaProcessBuilder(
    70           "-Xbootclasspath/p:foo.jar",
    71           "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa",
    72           "-XX:+PrintSharedArchiveAndExit");
    73       output = new OutputAnalyzer(pb.start());
    74       output.shouldContain("archive is invalid");
    75       output.shouldNotContain("Usage:");           // Should not print JVM help message
    76       output.shouldHaveExitValue(1);               // Should report failure in error code.
    77     } catch (RuntimeException e) {
    78       e.printStackTrace();
    79       output.shouldContain("Unable to use shared archive");
    80       output.shouldHaveExitValue(1);
    81     }
    82   }
    83 }

mercurial