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