test/hotspot/jtreg/runtime/appcds/BootClassPathMismatch.java
author ccheung
Fri, 17 May 2019 08:29:55 -0700
changeset 54927 1512d88b24c6
parent 51990 6003e034cdd8
child 55524 b279ae9843b8
permissions -rw-r--r--
8207812: Implement Dynamic CDS Archive Summary: Improve the usability of AppCDS Reviewed-by: acorn, jiangli, mseledtsov Contributed-by: ioi.lam@oracle.com, jianglizhou@google.com, calvin.cheung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     1
/*
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     4
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     8
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    13
 * accompanied this code).
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    14
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    18
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    21
 * questions.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    22
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    23
 */
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    24
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    25
/*
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    26
 * @test
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    27
 * @summary bootclasspath mismatch test.
48469
7312ae4465d6 8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents: 48171
diff changeset
    28
 * @requires vm.cds
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    29
 * @library /test/lib
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    31
 *          java.management
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    32
 *          jdk.jartool/sun.tools.jar
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    33
 * @compile test-classes/Hello.java
51990
6003e034cdd8 8209946: [TESTBUG] CDS tests should use "@run driver"
iklam
parents: 50199
diff changeset
    34
 * @run driver BootClassPathMismatch
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    35
 */
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    36
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    37
import jdk.test.lib.cds.CDSOptions;
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    38
import jdk.test.lib.cds.CDSTestUtils;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    39
import jdk.test.lib.process.OutputAnalyzer;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    40
import java.io.File;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    41
import java.nio.file.Files;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    42
import java.nio.file.FileAlreadyExistsException;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    43
import java.nio.file.StandardCopyOption;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    44
import java.nio.file.Paths;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    45
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    46
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    47
public class BootClassPathMismatch {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    48
    private static final String mismatchMessage = "shared class paths mismatch";
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    49
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    50
    public static void main(String[] args) throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    51
        JarBuilder.getOrCreateHelloJar();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    52
        copyHelloToNewDir();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    53
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    54
        BootClassPathMismatch test = new BootClassPathMismatch();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    55
        test.testBootClassPathMismatch();
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    56
        test.testBootClassPathMismatchWithAppClass();
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    57
        test.testBootClassPathMismatchWithBadPath();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    58
        if (!TestCommon.isDynamicArchive()) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    59
            // this test is not applicable to dynamic archive since
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    60
            // there is no class to be archived in the top archive
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    61
            test.testBootClassPathMatchWithAppend();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    62
        }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    63
        test.testBootClassPathMatch();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    64
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    65
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    66
    /* Archive contains boot classes only, with Hello class on -Xbootclasspath/a path.
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    67
     *
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    68
     * Error should be detected if:
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    69
     * dump time: -Xbootclasspath/a:${testdir}/hello.jar
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    70
     * run-time : -Xbootclasspath/a:${testdir}/newdir/hello.jar
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    71
     *
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    72
     * or
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    73
     * dump time: -Xbootclasspath/a:${testdir}/newdir/hello.jar
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    74
     * run-time : -Xbootclasspath/a:${testdir}/hello.jar
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    75
     */
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    76
    public void testBootClassPathMismatch() throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    77
        String appJar = JarBuilder.getOrCreateHelloJar();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    78
        String appClasses[] = {"Hello"};
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    79
        String testDir = TestCommon.getTestDir("newdir");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    80
        String otherJar = testDir + File.separator + "hello.jar";
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    81
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    82
        TestCommon.dump(appJar, appClasses, "-Xbootclasspath/a:" + appJar);
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
    83
        TestCommon.run(
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    84
                "-Xlog:cds",
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    85
                "-cp", appJar, "-Xbootclasspath/a:" + otherJar, "Hello")
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    86
            .assertAbnormalExit(mismatchMessage);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    87
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    88
        TestCommon.dump(appJar, appClasses, "-Xbootclasspath/a:" + otherJar);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    89
        TestCommon.run(
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
    90
                "-Xlog:cds",
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    91
                "-cp", appJar, "-Xbootclasspath/a:" + appJar, "Hello")
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
    92
            .assertAbnormalExit(mismatchMessage);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    93
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    94
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    95
    /* Archive contains boot classes only.
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    96
     *
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    97
     * Error should be detected if:
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    98
     * dump time: -Xbootclasspath/a:${testdir}/newdir/hello.jar
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
    99
     * run-time : -Xbootclasspath/a:${testdir}/newdir/hello.jar1
48171
7ad2d33a0f05 8174101: Bootclasspath append should not invalidate CDS archive
ccheung
parents: 48138
diff changeset
   100
     */
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   101
    public void testBootClassPathMismatchWithBadPath() throws Exception {
48171
7ad2d33a0f05 8174101: Bootclasspath append should not invalidate CDS archive
ccheung
parents: 48138
diff changeset
   102
        String appClasses[] = {"Hello"};
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   103
        String testDir = TestCommon.getTestDir("newdir");
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   104
        String appJar = testDir + File.separator + "hello.jar";
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   105
        String otherJar = testDir + File.separator + "hello.jar1";
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   106
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   107
        TestCommon.dump(appJar, appClasses, "-Xbootclasspath/a:" + appJar);
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
   108
        TestCommon.run(
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   109
                "-Xlog:cds",
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   110
                "-cp", appJar, "-Xbootclasspath/a:" + otherJar, "Hello")
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
   111
            .assertAbnormalExit(mismatchMessage);
48171
7ad2d33a0f05 8174101: Bootclasspath append should not invalidate CDS archive
ccheung
parents: 48138
diff changeset
   112
    }
7ad2d33a0f05 8174101: Bootclasspath append should not invalidate CDS archive
ccheung
parents: 48138
diff changeset
   113
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   114
    /* Archive contains boot classes only, with Hello loaded from -Xbootclasspath/a at dump time.
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   115
     *
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   116
     * No error if:
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   117
     * dump time: -Xbootclasspath/a:${testdir}/hello.jar
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   118
     * run-time : -Xbootclasspath/a:${testdir}/hello.jar
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   119
     */
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   120
    public void testBootClassPathMatch() throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   121
        String appJar = TestCommon.getTestJar("hello.jar");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   122
        String appClasses[] = {"Hello"};
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
   123
        TestCommon.dump(
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   124
            appJar, appClasses, "-Xbootclasspath/a:" + appJar);
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
   125
        TestCommon.run(
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
   126
                "-cp", appJar, "-verbose:class",
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
   127
                "-Xbootclasspath/a:" + appJar, "Hello")
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48469
diff changeset
   128
            .assertNormalExit("[class,load] Hello source: shared objects file");
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   129
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   130
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   131
    /* Archive contains boot classes only, runtime add -Xbootclasspath/a path.
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   132
     *
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   133
     * No error:
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   134
     * dump time: No -Xbootclasspath/a
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   135
     * run-time : -Xbootclasspath/a:${testdir}/hello.jar
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   136
     */
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   137
    public void testBootClassPathMatchWithAppend() throws Exception {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   138
      CDSOptions opts = new CDSOptions().setUseVersion(false);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   139
      OutputAnalyzer out = CDSTestUtils.createArchive(opts);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   140
      CDSTestUtils.checkDump(out);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   141
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   142
      String appJar = JarBuilder.getOrCreateHelloJar();
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   143
      opts.addPrefix("-Xbootclasspath/a:" + appJar, "-showversion").addSuffix("Hello");
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   144
      CDSTestUtils.runWithArchiveAndCheck(opts);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   145
    }
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   146
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   147
    /* Archive contains app classes, with Hello on -cp path at dump time.
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   148
     *
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   149
     * Error should be detected if:
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   150
     * dump time: <no bootclasspath specified>
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   151
     * run-time : -Xbootclasspath/a:${testdir}/hello.jar
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   152
     */
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   153
    public void testBootClassPathMismatchWithAppClass() throws Exception {
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   154
        String appJar = JarBuilder.getOrCreateHelloJar();
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   155
        String appClasses[] = {"Hello"};
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   156
        TestCommon.dump(appJar, appClasses);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   157
        TestCommon.run(
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 51990
diff changeset
   158
                "-Xlog:cds",
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   159
                "-cp", appJar, "-Xbootclasspath/a:" + appJar, "Hello")
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   160
            .assertAbnormalExit(mismatchMessage);
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   161
    }
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   162
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   163
    private static void copyHelloToNewDir() throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   164
        String classDir = System.getProperty("test.classes");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   165
        String dstDir = classDir + File.separator + "newdir";
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   166
        try {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   167
            Files.createDirectory(Paths.get(dstDir));
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   168
        } catch (FileAlreadyExistsException e) { }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   169
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   170
        // copy as hello.jar
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   171
        Files.copy(Paths.get(classDir, "hello.jar"),
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   172
            Paths.get(dstDir, "hello.jar"),
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   173
            StandardCopyOption.REPLACE_EXISTING);
50199
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   174
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   175
        // copy as hello.jar1
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   176
        Files.copy(Paths.get(classDir, "hello.jar"),
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   177
            Paths.get(dstDir, "hello.jar1"),
83d8b3a25f25 8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents: 48979
diff changeset
   178
            StandardCopyOption.REPLACE_EXISTING);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   179
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   180
}