< prev index next >

test/tools/launcher/modules/patch/systemmodules/PatchSystemModules.java

Print this page

        

@@ -1,7 +1,7 @@
 /**
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -21,13 +21,12 @@
  * questions.
  */
 
 /*
  * @test
- * @bug 8157068
- * @summary Patch java.base and user module with Hashes attribute tied with
- *          other module.
+ * @bug 8157068 8177844
+ * @summary Patch java.base and user module with ModuleHashes attribute
  * @library /lib/testlibrary
  * @modules jdk.compiler
  * @build CompilerUtils
  * @run testng PatchSystemModules
  */

@@ -57,10 +56,11 @@
     private static final Path JMODS = Paths.get(JAVA_HOME, "jmods");
     private static final Path MODS_DIR = Paths.get("mods");
     private static final Path JARS_DIR = Paths.get("jars");
     private static final Path PATCH_DIR = Paths.get("patches");
     private static final Path IMAGE = Paths.get("image");
+    private static final Path NEW_M1_JAR = JARS_DIR.resolve("new_m1.jar");
 
     private static final String JAVA_BASE = "java.base";
     private final String[] modules = new String[] { "m1", "m2" };
 
     @BeforeTest

@@ -83,12 +83,20 @@
         // create an image with only m1 and m2
         if (Files.exists(JMODS)) {
             // create an image with m1,m2
             createImage();
         }
+
+        // create new copy of m1.jar
+        jar("--create",
+            "--file=" + NEW_M1_JAR.toString(),
+            "-C", MODS_DIR.resolve("m1").toString(), ".");
     }
 
+    /*
+     * Test patching system module and user module on module path
+     */
     @Test
     public void test() throws Throwable {
         Path patchedJavaBase = PATCH_DIR.resolve(JAVA_BASE);
         Path patchedM2 = PATCH_DIR.resolve("m2");
 

@@ -105,10 +113,13 @@
                 "--patch-module", "m2=" + patchedM2.toString(),
                 "--module-path", MODS_DIR.toString(),
                 "-m", "m1/p1.Main", "2");
     }
 
+    /*
+     * Test --patch-module on a custom image
+     */
     @Test
     public void testImage() throws Throwable {
         if (Files.notExists(JMODS))
             return;
 

@@ -123,31 +134,53 @@
         runTest(IMAGE,
                 "--patch-module", "m2=" + patchedM2.toString(),
                 "-m", "m1/p1.Main", "2");
     }
 
+    /*
+     * Test a module linked in a system hashed in ModuleHashes attribute
+     * cannot be upgraded
+     */
     @Test
-    public void upgradeTiedModule() throws Throwable {
+    public void upgradeHashedModule() throws Throwable {
         if (Files.notExists(JMODS))
             return;
 
-        Path m1 = MODS_DIR.resolve("m1.jar");
+        // Fail to upgrade m1.jar with mismatched hash
+        runTestWithExitCode(getJava(IMAGE),
+                "--upgrade-module-path", NEW_M1_JAR.toString(),
+                "-m", "m1/p1.Main", "ShouldNeverRun");
 
-        // create another m1.jar
-        jar("--create",
-            "--file=" + m1.toString(),
-            "-C", MODS_DIR.resolve("m1").toString(), ".");
+        // test when SystemModules fast path is not enabled, i.e. exploded image
+        runTestWithExitCode(getJava(IMAGE),
+                "--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE),
+                "--upgrade-module-path", NEW_M1_JAR.toString(),
+                "-m", "m1/p1.Main", "ShouldNeverRun");
+    }
 
-        // Fail to upgrade m1.jar with mismatched hash
+    /*
+     * Test a module linked in a system hashed in ModuleHashes attribute
+     * cannot be upgraded combining with --patch-module and --upgrade-module-path
+     */
+    @Test
+    public void patchHashedModule() throws Throwable {
+        if (Files.notExists(JMODS))
+            return;
+
+        // --patch-module does not disable hash check.
+        // Test that a hashed module cannot be upgraded.
         runTestWithExitCode(getJava(IMAGE),
-                "--upgrade-module-path", m1.toString(),
-                "-m", "m1/p1.Main");
+                "--patch-module", "m1=.jar",
+                "--upgrade-module-path", NEW_M1_JAR.toString(),
+                "-m", "m1/p1.Main", "ShouldNeverRun");
 
+        // test when SystemModules fast path is not enabled, i.e. exploded image
         runTestWithExitCode(getJava(IMAGE),
                 "--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE),
-                "--upgrade-module-path", m1.toString(),
-                "-m", "m1/p1.Main", "1");
+                "--patch-module", "m1=.jar",
+                "--upgrade-module-path", NEW_M1_JAR.toString(),
+                "-m", "m1/p1.Main", "ShouldNeverRun");
     }
 
     private void runTestWithExitCode(String... options) throws Throwable {
         assertTrue(executeCommand(options)
                         .outputTo(System.out)
< prev index next >