< prev index next >

test/runtime/SharedArchiveFile/PrintSharedArchiveAndExit.java

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