test/hotspot/jtreg/runtime/appcds/BootClassPathMismatch.java
changeset 50199 83d8b3a25f25
parent 48979 514c73a1955b
child 51990 6003e034cdd8
equal deleted inserted replaced
50198:db3c6bb7f856 50199:83d8b3a25f25
    32  *          jdk.jartool/sun.tools.jar
    32  *          jdk.jartool/sun.tools.jar
    33  * @compile test-classes/Hello.java
    33  * @compile test-classes/Hello.java
    34  * @run main BootClassPathMismatch
    34  * @run main BootClassPathMismatch
    35  */
    35  */
    36 
    36 
       
    37 import jdk.test.lib.cds.CDSOptions;
       
    38 import jdk.test.lib.cds.CDSTestUtils;
    37 import jdk.test.lib.process.OutputAnalyzer;
    39 import jdk.test.lib.process.OutputAnalyzer;
    38 import java.io.File;
    40 import java.io.File;
    39 import java.nio.file.Files;
    41 import java.nio.file.Files;
    40 import java.nio.file.FileAlreadyExistsException;
    42 import java.nio.file.FileAlreadyExistsException;
    41 import java.nio.file.StandardCopyOption;
    43 import java.nio.file.StandardCopyOption;
    49         JarBuilder.getOrCreateHelloJar();
    51         JarBuilder.getOrCreateHelloJar();
    50         copyHelloToNewDir();
    52         copyHelloToNewDir();
    51 
    53 
    52         BootClassPathMismatch test = new BootClassPathMismatch();
    54         BootClassPathMismatch test = new BootClassPathMismatch();
    53         test.testBootClassPathMismatch();
    55         test.testBootClassPathMismatch();
    54         test.testBootClassPathMismatch2();
    56         test.testBootClassPathMismatchWithAppClass();
       
    57         test.testBootClassPathMismatchWithBadPath();
       
    58         test.testBootClassPathMatchWithAppend();
    55         test.testBootClassPathMatch();
    59         test.testBootClassPathMatch();
    56     }
    60     }
    57 
    61 
    58     /* Error should be detected if:
    62     /* Archive contains boot classes only, with Hello class on -Xbootclasspath/a path.
       
    63      *
       
    64      * Error should be detected if:
    59      * dump time: -Xbootclasspath/a:${testdir}/hello.jar
    65      * dump time: -Xbootclasspath/a:${testdir}/hello.jar
    60      * run-time : -Xbootclasspath/a:${testdir}/newdir/hello.jar
    66      * run-time : -Xbootclasspath/a:${testdir}/newdir/hello.jar
       
    67      *
       
    68      * or
       
    69      * dump time: -Xbootclasspath/a:${testdir}/newdir/hello.jar
       
    70      * run-time : -Xbootclasspath/a:${testdir}/hello.jar
    61      */
    71      */
    62     public void testBootClassPathMismatch() throws Exception {
    72     public void testBootClassPathMismatch() throws Exception {
    63         String appJar = JarBuilder.getOrCreateHelloJar();
    73         String appJar = JarBuilder.getOrCreateHelloJar();
    64         String appClasses[] = {"Hello"};
    74         String appClasses[] = {"Hello"};
    65         TestCommon.dump(
       
    66             appJar, appClasses, "-Xbootclasspath/a:" + appJar);
       
    67         String testDir = TestCommon.getTestDir("newdir");
    75         String testDir = TestCommon.getTestDir("newdir");
    68         String otherJar = testDir + File.separator + "hello.jar";
    76         String otherJar = testDir + File.separator + "hello.jar";
       
    77 
       
    78         TestCommon.dump(appJar, appClasses, "-Xbootclasspath/a:" + appJar);
    69         TestCommon.run(
    79         TestCommon.run(
    70                 "-cp", appJar, "-verbose:class", "-Xbootclasspath/a:" + otherJar, "Hello")
    80                 "-cp", appJar, "-Xbootclasspath/a:" + otherJar, "Hello")
       
    81             .assertAbnormalExit(mismatchMessage);
       
    82 
       
    83         TestCommon.dump(appJar, appClasses, "-Xbootclasspath/a:" + otherJar);
       
    84         TestCommon.run(
       
    85                 "-cp", appJar, "-Xbootclasspath/a:" + appJar, "Hello")
    71             .assertAbnormalExit(mismatchMessage);
    86             .assertAbnormalExit(mismatchMessage);
    72     }
    87     }
    73 
    88 
    74     /* Error should be detected if:
    89     /* Archive contains boot classes only.
    75      * dump time: <no bootclasspath specified>
    90      *
    76      * run-time : -Xbootclasspath/a:${testdir}/hello.jar
    91      * Error should be detected if:
       
    92      * dump time: -Xbootclasspath/a:${testdir}/newdir/hello.jar
       
    93      * run-time : -Xbootclasspath/a:${testdir}/newdir/hello.jar1
    77      */
    94      */
    78     public void testBootClassPathMismatch2() throws Exception {
    95     public void testBootClassPathMismatchWithBadPath() throws Exception {
    79         String appJar = JarBuilder.getOrCreateHelloJar();
       
    80         String appClasses[] = {"Hello"};
    96         String appClasses[] = {"Hello"};
    81         TestCommon.dump(appJar, appClasses);
    97         String testDir = TestCommon.getTestDir("newdir");
       
    98         String appJar = testDir + File.separator + "hello.jar";
       
    99         String otherJar = testDir + File.separator + "hello.jar1";
       
   100 
       
   101         TestCommon.dump(appJar, appClasses, "-Xbootclasspath/a:" + appJar);
    82         TestCommon.run(
   102         TestCommon.run(
    83                 "-cp", appJar, "-verbose:class", "-Xbootclasspath/a:" + appJar, "Hello")
   103                 "-cp", appJar, "-Xbootclasspath/a:" + otherJar, "Hello")
    84             .assertAbnormalExit(mismatchMessage);
   104             .assertAbnormalExit(mismatchMessage);
    85     }
   105     }
    86 
   106 
    87     /* No error if:
   107     /* Archive contains boot classes only, with Hello loaded from -Xbootclasspath/a at dump time.
       
   108      *
       
   109      * No error if:
    88      * dump time: -Xbootclasspath/a:${testdir}/hello.jar
   110      * dump time: -Xbootclasspath/a:${testdir}/hello.jar
    89      * run-time : -Xbootclasspath/a:${testdir}/hello.jar
   111      * run-time : -Xbootclasspath/a:${testdir}/hello.jar
    90      */
   112      */
    91     public void testBootClassPathMatch() throws Exception {
   113     public void testBootClassPathMatch() throws Exception {
    92         String appJar = TestCommon.getTestJar("hello.jar");
   114         String appJar = TestCommon.getTestJar("hello.jar");
    97                 "-cp", appJar, "-verbose:class",
   119                 "-cp", appJar, "-verbose:class",
    98                 "-Xbootclasspath/a:" + appJar, "Hello")
   120                 "-Xbootclasspath/a:" + appJar, "Hello")
    99             .assertNormalExit("[class,load] Hello source: shared objects file");
   121             .assertNormalExit("[class,load] Hello source: shared objects file");
   100     }
   122     }
   101 
   123 
       
   124     /* Archive contains boot classes only, runtime add -Xbootclasspath/a path.
       
   125      *
       
   126      * No error:
       
   127      * dump time: No -Xbootclasspath/a
       
   128      * run-time : -Xbootclasspath/a:${testdir}/hello.jar
       
   129      */
       
   130     public void testBootClassPathMatchWithAppend() throws Exception {
       
   131       CDSOptions opts = new CDSOptions().setUseVersion(false);
       
   132       OutputAnalyzer out = CDSTestUtils.createArchive(opts);
       
   133       CDSTestUtils.checkDump(out);
       
   134 
       
   135       String appJar = JarBuilder.getOrCreateHelloJar();
       
   136       opts.addPrefix("-Xbootclasspath/a:" + appJar, "-showversion").addSuffix("Hello");
       
   137       CDSTestUtils.runWithArchiveAndCheck(opts);
       
   138     }
       
   139 
       
   140     /* Archive contains app classes, with Hello on -cp path at dump time.
       
   141      *
       
   142      * Error should be detected if:
       
   143      * dump time: <no bootclasspath specified>
       
   144      * run-time : -Xbootclasspath/a:${testdir}/hello.jar
       
   145      */
       
   146     public void testBootClassPathMismatchWithAppClass() throws Exception {
       
   147         String appJar = JarBuilder.getOrCreateHelloJar();
       
   148         String appClasses[] = {"Hello"};
       
   149         TestCommon.dump(appJar, appClasses);
       
   150         TestCommon.run(
       
   151                 "-cp", appJar, "-Xbootclasspath/a:" + appJar, "Hello")
       
   152             .assertAbnormalExit(mismatchMessage);
       
   153     }
       
   154 
   102     private static void copyHelloToNewDir() throws Exception {
   155     private static void copyHelloToNewDir() throws Exception {
   103         String classDir = System.getProperty("test.classes");
   156         String classDir = System.getProperty("test.classes");
   104         String dstDir = classDir + File.separator + "newdir";
   157         String dstDir = classDir + File.separator + "newdir";
   105         try {
   158         try {
   106             Files.createDirectory(Paths.get(dstDir));
   159             Files.createDirectory(Paths.get(dstDir));
   107         } catch (FileAlreadyExistsException e) { }
   160         } catch (FileAlreadyExistsException e) { }
   108 
   161 
       
   162         // copy as hello.jar
   109         Files.copy(Paths.get(classDir, "hello.jar"),
   163         Files.copy(Paths.get(classDir, "hello.jar"),
   110             Paths.get(dstDir, "hello.jar"),
   164             Paths.get(dstDir, "hello.jar"),
   111             StandardCopyOption.REPLACE_EXISTING);
   165             StandardCopyOption.REPLACE_EXISTING);
       
   166 
       
   167         // copy as hello.jar1
       
   168         Files.copy(Paths.get(classDir, "hello.jar"),
       
   169             Paths.get(dstDir, "hello.jar1"),
       
   170             StandardCopyOption.REPLACE_EXISTING);
   112     }
   171     }
   113 }
   172 }