test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath

test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /**
  26  * @test
  27  * @requires vm.cds
  28  * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/appcds
  29  * @modules jdk.compiler
  30  *          jdk.jartool/sun.tools.jar
  31  *          jdk.jlink
  32  * @run main MainModuleOnly
  33  * @summary Test some scenarios with a main modular jar specified in the --module-path and -cp options in the command line.
  34  */
  35 
  36 import java.io.File;
  37 import java.nio.file.Files;
  38 import java.nio.file.Path;
  39 import java.nio.file.Paths;

  40 
  41 import jdk.test.lib.process.OutputAnalyzer;

  42 import jdk.testlibrary.ProcessTools;
  43 
  44 public class MainModuleOnly {
  45 
  46     private static final Path USER_DIR = Paths.get(System.getProperty("user.dir"));
  47 
  48     private static final String TEST_SRC = System.getProperty("test.src");
  49 
  50     private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
  51     private static final Path MODS_DIR = Paths.get("mods");
  52 
  53     // the module name of the test module
  54     private static final String TEST_MODULE1 = "com.simple";
  55 
  56     // the module main class
  57     private static final String MAIN_CLASS = "com.simple.Main";
  58 
  59     private static Path moduleDir = null;
  60     private static Path moduleDir2 = null;
  61     private static Path destJar = null;


 160             .assertSilentlyDisabledCDS(out -> {
 161                 out.shouldHaveExitValue(0)
 162                    .shouldMatch("CDS is disabled when the.*option is specified")
 163                    .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar");
 164             });
 165         // modify the timestamp of the jar file
 166         (new File(destJar.toString())).setLastModified(System.currentTimeMillis() + 2000);
 167         // run with the archive and the jar with modified timestamp.
 168         // It should fail due to timestamp of the jar doesn't match the one
 169         // used during dump time.
 170         TestCommon.run("-Xlog:class+load=trace",
 171                        "-cp", destJar.toString(),
 172                        "--module-path", moduleDir.toString(),
 173                        "-m", TEST_MODULE1)
 174             .assertAbnormalExit(
 175                 "A jar file is not the one used while building the shared archive file:");
 176         // create an archive with a non-empty directory in the --module-path.
 177         // The dumping process will exit with an error due to non-empty directory
 178         // in the --module-path.
 179         output = TestCommon.createArchive(destJar.toString(), appClasses,
 180                                           "-Xlog:class+load=trace",
 181                                           "--module-path", MODS_DIR.toString(),
 182                                           "-m", TEST_MODULE1);
 183         output.shouldHaveExitValue(1)
 184               .shouldMatch("Error: non-empty directory.*com.simple");












































 185     }
 186 }


  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /**
  26  * @test
  27  * @requires vm.cds
  28  * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/appcds
  29  * @modules jdk.compiler
  30  *          jdk.jartool/sun.tools.jar
  31  *          jdk.jlink
  32  * @run main MainModuleOnly
  33  * @summary Test some scenarios with a main modular jar specified in the --module-path and -cp options in the command line.
  34  */
  35 
  36 import java.io.File;
  37 import java.nio.file.Files;
  38 import java.nio.file.Path;
  39 import java.nio.file.Paths;
  40 import java.util.Arrays;
  41 
  42 import jdk.test.lib.process.OutputAnalyzer;
  43 import jdk.test.lib.Platform;
  44 import jdk.testlibrary.ProcessTools;
  45 
  46 public class MainModuleOnly {
  47 
  48     private static final Path USER_DIR = Paths.get(System.getProperty("user.dir"));
  49 
  50     private static final String TEST_SRC = System.getProperty("test.src");
  51 
  52     private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
  53     private static final Path MODS_DIR = Paths.get("mods");
  54 
  55     // the module name of the test module
  56     private static final String TEST_MODULE1 = "com.simple";
  57 
  58     // the module main class
  59     private static final String MAIN_CLASS = "com.simple.Main";
  60 
  61     private static Path moduleDir = null;
  62     private static Path moduleDir2 = null;
  63     private static Path destJar = null;


 162             .assertSilentlyDisabledCDS(out -> {
 163                 out.shouldHaveExitValue(0)
 164                    .shouldMatch("CDS is disabled when the.*option is specified")
 165                    .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar");
 166             });
 167         // modify the timestamp of the jar file
 168         (new File(destJar.toString())).setLastModified(System.currentTimeMillis() + 2000);
 169         // run with the archive and the jar with modified timestamp.
 170         // It should fail due to timestamp of the jar doesn't match the one
 171         // used during dump time.
 172         TestCommon.run("-Xlog:class+load=trace",
 173                        "-cp", destJar.toString(),
 174                        "--module-path", moduleDir.toString(),
 175                        "-m", TEST_MODULE1)
 176             .assertAbnormalExit(
 177                 "A jar file is not the one used while building the shared archive file:");
 178         // create an archive with a non-empty directory in the --module-path.
 179         // The dumping process will exit with an error due to non-empty directory
 180         // in the --module-path.
 181         output = TestCommon.createArchive(destJar.toString(), appClasses,

 182                                           "--module-path", MODS_DIR.toString(),
 183                                           "-m", TEST_MODULE1);
 184         output.shouldHaveExitValue(1)
 185               .shouldMatch("Error: non-empty directory.*com.simple");
 186 
 187         // test module path with very long length
 188         //
 189         // This test can't be run on the windows platform due to an existing
 190         // issue in ClassLoader::get_canonical_path() (JDK-8190737).
 191         if (Platform.isWindows()) {
 192             System.out.println("Long module path test cannot be tested on the Windows platform.");
 193             return;
 194         }
 195         Path longDir = USER_DIR;
 196         int pathLen = longDir.toString().length();
 197         int PATH_LEN = 2034;
 198         int MAX_DIR_LEN = 250;
 199         while (pathLen < PATH_LEN) {
 200             int remaining = PATH_LEN - pathLen;
 201             int subPathLen = remaining > MAX_DIR_LEN ? MAX_DIR_LEN : remaining;
 202             char[] chars = new char[subPathLen];
 203             Arrays.fill(chars, 'x');
 204             String subPath = new String(chars);
 205             longDir = Paths.get(longDir.toString(), subPath);
 206             pathLen = longDir.toString().length();
 207         }
 208         File longDirFile = new File(longDir.toString());
 209         try {
 210             longDirFile.mkdirs();
 211         } catch (Exception e) {
 212             throw e;
 213         }
 214         Path longDirJar = longDir.resolve(TEST_MODULE1 + ".jar");
 215         // IOException results from the Files.copy() call on platform
 216         // such as MacOS X. Test can't be proceeded further with the
 217         // exception.
 218         try {
 219             Files.copy(destJar, longDirJar);
 220         } catch (java.io.IOException ioe) {
 221             System.out.println("Caught IOException from Files.copy(). Cannot continue.");
 222             return;
 223         }
 224         output = TestCommon.createArchive(destJar.toString(), appClasses,
 225                                           "-Xlog:exceptions=trace",
 226                                           "--module-path", longDirJar.toString(),
 227                                           "-m", TEST_MODULE1);
 228         output.shouldHaveExitValue(1)
 229               .shouldMatch("os::stat error.*ENAMETOOLONG.*CDS dump aborted");
 230     }
 231 }
test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File