1 /*
   2  * Copyright (c) 2018, 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 /*
  26  * @test
  27  * @summary Compare archived system modules with non-archived.
  28  * @requires vm.cds.archived.java.heap
  29  * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/appcds
  30  * @modules java.base/jdk.internal.misc
  31  *          java.management
  32  *          jdk.jartool/sun.tools.jar
  33  * @compile PrintSystemModulesApp.java
  34  * @run driver ClassFileInstaller -jar app.jar PrintSystemModulesApp
  35  * @run driver ArchivedModuleCompareTest
  36  */
  37 
  38 import jdk.test.lib.process.OutputAnalyzer;
  39 import jdk.test.lib.process.ProcessTools;
  40 
  41 public class ArchivedModuleCompareTest {
  42     public static void main(String[] args) throws Exception {
  43         String appJar = ClassFileInstaller.getJarPath("app.jar");
  44 
  45         // Test case 1)
  46         // Compare the list of archived system module names with non-archived
  47         // list. They must be the same.
  48         System.out.println("---------------- Test case 1 -----------------");
  49         OutputAnalyzer output = TestCommon.dump(appJar,
  50                         TestCommon.list("PrintSystemModulesApp"));
  51         TestCommon.checkDump(output);
  52 
  53         output = TestCommon.execOff("-cp", appJar, "PrintSystemModulesApp");
  54         output.shouldHaveExitValue(0);
  55         String bootModules1 = output.getStdout();
  56 
  57         output = TestCommon.exec(appJar, "PrintSystemModulesApp");
  58         TestCommon.checkExec(output);
  59         if (output.getStderr().contains("sharing")) {
  60             String bootModules2 = output.getStdout();
  61             TestCommon.checkOutputStrings(bootModules1, bootModules2, ", ");
  62         }
  63 
  64         // Test case 2)
  65         // Verify --show-module-resolution output with the output from
  66         // -Xshare:off run
  67         System.out.println("---------------- Test case 2 -----------------");
  68         output = TestCommon.execOff("-cp", appJar,
  69                                     "--show-module-resolution",
  70                                     "-version");
  71         output.shouldHaveExitValue(0);
  72         String moduleResolutionOut1 = output.getStdout();
  73 
  74         output = TestCommon.exec(appJar,
  75                                  "--show-module-resolution",
  76                                  "-version");
  77         TestCommon.checkExec(output);
  78         if (output.getStderr().contains("sharing")) {
  79             String moduleResolutionOut2 = output.getStdout();
  80             TestCommon.checkOutputStrings(
  81                 moduleResolutionOut1, moduleResolutionOut2, "\n");
  82         }
  83     }
  84 }