< prev index next >

test/tools/launcher/modules/patch/basic/PatchTest.java

Print this page




  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  * @library /lib/testlibrary
  27  * @modules jdk.compiler
  28  * @build PatchTest CompilerUtils JarUtils jdk.testlibrary.*
  29  * @run testng PatchTest
  30  * @summary Basic test for -Xpatch
  31  */
  32 
  33 import java.io.File;
  34 import java.nio.file.Files;
  35 import java.nio.file.Path;
  36 import java.nio.file.Paths;

  37 import java.util.stream.Collectors;
  38 import java.util.stream.Stream;
  39 
  40 import static jdk.testlibrary.ProcessTools.*;
  41 
  42 import org.testng.annotations.BeforeTest;
  43 import org.testng.annotations.Test;
  44 import static org.testng.Assert.*;
  45 
  46 
  47 /**
  48  * Compiles and launches a test that uses -Xpatch with two directories of
  49  * classes to override existing and add new classes to modules in the
  50  * boot layer.
  51  *
  52  * The classes overridden or added via -Xpatch all define a public no-arg
  53  * constructor and override toString to return "hi". This allows the launched
  54  * test to check that the overridden classes are loaded.
  55  */
  56 


 120         for (Path src : Files.newDirectoryStream(SRC2_DIR)) {
 121             Path output = PATCHES2_DIR.resolve(src.getFileName());
 122             String mn = src.getFileName().toString();
 123             compiled  = CompilerUtils.compile(src, output, "-Xmodule:" + mn);
 124             assertTrue(compiled, "classes did not compile");
 125             JarUtils.createJarFile(PATCHES_DIR.resolve(mn + "-2.jar"), output);
 126         }
 127 
 128     }
 129 
 130     /**
 131      * Run test with patches to java.base, jdk.naming.dns and jdk.compiler
 132      */
 133     void runTest(String basePatches, String dnsPatches, String compilerPatches)
 134         throws Exception
 135     {
 136         // the argument to the test is the list of classes overridden or added
 137         String arg = Stream.of(CLASSES).collect(Collectors.joining(","));
 138 
 139         int exitValue
 140             =  executeTestJava("-Xpatch:java.base=" + basePatches,

 141                                "-Xpatch:jdk.naming.dns=" + dnsPatches,
 142                                "-Xpatch:jdk.compiler=" + compilerPatches,
 143                                "-XaddExports:java.base/java.lang2=test",
 144                                "-XaddExports:jdk.naming.dns/com.sun.jndi.dns=test",
 145                                "-XaddExports:jdk.naming.dns/com.sun.jndi.dns2=test",
 146                                "-XaddExports:jdk.compiler/com.sun.tools.javac2=test",
 147                                "-addmods", "jdk.naming.dns,jdk.compiler",
 148                                "-mp", MODS_DIR.toString(),
 149                                "-m", "test/jdk.test.Main", arg)
 150                 .outputTo(System.out)
 151                 .errorTo(System.out)
 152                 .getExitValue();
 153 
 154         assertTrue(exitValue == 0);
 155     }
 156 
 157 
 158     /**
 159      * Run test with -Xpatch and exploded patches
 160      */
 161     public void testWithExplodedPatches() throws Exception {
 162 
 163         // patches1/java.base:patches2/java.base
 164         String basePatches = PATCHES1_DIR.resolve("java.base")
 165                 + File.pathSeparator + PATCHES2_DIR.resolve("java.base");
 166 
 167         String dnsPatches = PATCHES1_DIR.resolve("jdk.naming.dns")
 168                 + File.pathSeparator + PATCHES2_DIR.resolve("jdk.naming.dns");
 169 
 170         String compilerPatches = PATCHES1_DIR.resolve("jdk.compiler")
 171                 + File.pathSeparator + PATCHES2_DIR.resolve("jdk.compiler");




  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  * @library /lib/testlibrary
  27  * @modules jdk.compiler
  28  * @build PatchTest CompilerUtils JarUtils jdk.testlibrary.*
  29  * @run testng PatchTest
  30  * @summary Basic test for -Xpatch
  31  */
  32 
  33 import java.io.File;
  34 import java.nio.file.Files;
  35 import java.nio.file.Path;
  36 import java.nio.file.Paths;
  37 import java.util.Arrays;
  38 import java.util.stream.Collectors;
  39 import java.util.stream.Stream;
  40 
  41 import static jdk.testlibrary.ProcessTools.*;
  42 
  43 import org.testng.annotations.BeforeTest;
  44 import org.testng.annotations.Test;
  45 import static org.testng.Assert.*;
  46 
  47 
  48 /**
  49  * Compiles and launches a test that uses -Xpatch with two directories of
  50  * classes to override existing and add new classes to modules in the
  51  * boot layer.
  52  *
  53  * The classes overridden or added via -Xpatch all define a public no-arg
  54  * constructor and override toString to return "hi". This allows the launched
  55  * test to check that the overridden classes are loaded.
  56  */
  57 


 121         for (Path src : Files.newDirectoryStream(SRC2_DIR)) {
 122             Path output = PATCHES2_DIR.resolve(src.getFileName());
 123             String mn = src.getFileName().toString();
 124             compiled  = CompilerUtils.compile(src, output, "-Xmodule:" + mn);
 125             assertTrue(compiled, "classes did not compile");
 126             JarUtils.createJarFile(PATCHES_DIR.resolve(mn + "-2.jar"), output);
 127         }
 128 
 129     }
 130 
 131     /**
 132      * Run test with patches to java.base, jdk.naming.dns and jdk.compiler
 133      */
 134     void runTest(String basePatches, String dnsPatches, String compilerPatches)
 135         throws Exception
 136     {
 137         // the argument to the test is the list of classes overridden or added
 138         String arg = Stream.of(CLASSES).collect(Collectors.joining(","));
 139 
 140         int exitValue
 141             = executeModularTest("test", "jdk.test.Main",
 142                   Arrays.asList("-Xpatch:java.base=" + basePatches,
 143                                 "-Xpatch:jdk.naming.dns=" + dnsPatches,
 144                                 "-Xpatch:jdk.compiler=" + compilerPatches,
 145                                 "-XaddExports:java.base/java.lang2=test",
 146                                 "-XaddExports:jdk.naming.dns/com.sun.jndi.dns=test",
 147                                 "-XaddExports:jdk.naming.dns/com.sun.jndi.dns2=test",
 148                                 "-XaddExports:jdk.compiler/com.sun.tools.javac2=test"),
 149                   null, Arrays.asList(MODS_DIR), Arrays.asList("jdk.naming.dns", "jdk.compiler"),
 150                   arg)



 151                 .getExitValue();
 152 
 153         assertTrue(exitValue == 0);
 154     }
 155 
 156 
 157     /**
 158      * Run test with -Xpatch and exploded patches
 159      */
 160     public void testWithExplodedPatches() throws Exception {
 161 
 162         // patches1/java.base:patches2/java.base
 163         String basePatches = PATCHES1_DIR.resolve("java.base")
 164                 + File.pathSeparator + PATCHES2_DIR.resolve("java.base");
 165 
 166         String dnsPatches = PATCHES1_DIR.resolve("jdk.naming.dns")
 167                 + File.pathSeparator + PATCHES2_DIR.resolve("jdk.naming.dns");
 168 
 169         String compilerPatches = PATCHES1_DIR.resolve("jdk.compiler")
 170                 + File.pathSeparator + PATCHES2_DIR.resolve("jdk.compiler");


< prev index next >