author | ccheung |
Fri, 17 May 2019 08:29:55 -0700 | |
changeset 54927 | 1512d88b24c6 |
parent 51990 | 6003e034cdd8 |
child 55524 | b279ae9843b8 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
54927 | 2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
48138 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
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 |
/* |
|
26 |
* @test |
|
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 | 29 |
* @library /test/lib |
30 |
* @modules java.base/jdk.internal.misc |
|
31 |
* java.management |
|
32 |
* jdk.jartool/sun.tools.jar |
|
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 | 35 |
*/ |
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 | 39 |
import jdk.test.lib.process.OutputAnalyzer; |
40 |
import java.io.File; |
|
41 |
import java.nio.file.Files; |
|
42 |
import java.nio.file.FileAlreadyExistsException; |
|
43 |
import java.nio.file.StandardCopyOption; |
|
44 |
import java.nio.file.Paths; |
|
45 |
||
46 |
||
47 |
public class BootClassPathMismatch { |
|
48 |
private static final String mismatchMessage = "shared class paths mismatch"; |
|
49 |
||
50 |
public static void main(String[] args) throws Exception { |
|
51 |
JarBuilder.getOrCreateHelloJar(); |
|
52 |
copyHelloToNewDir(); |
|
53 |
||
54 |
BootClassPathMismatch test = new BootClassPathMismatch(); |
|
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 | 58 |
if (!TestCommon.isDynamicArchive()) { |
59 |
// this test is not applicable to dynamic archive since |
|
60 |
// there is no class to be archived in the top archive |
|
61 |
test.testBootClassPathMatchWithAppend(); |
|
62 |
} |
|
48138 | 63 |
test.testBootClassPathMatch(); |
64 |
} |
|
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 | 69 |
* dump time: -Xbootclasspath/a:${testdir}/hello.jar |
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 | 75 |
*/ |
76 |
public void testBootClassPathMismatch() throws Exception { |
|
77 |
String appJar = JarBuilder.getOrCreateHelloJar(); |
|
78 |
String appClasses[] = {"Hello"}; |
|
79 |
String testDir = TestCommon.getTestDir("newdir"); |
|
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 | 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 | 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 | 93 |
} |
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 | 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 | 117 |
* dump time: -Xbootclasspath/a:${testdir}/hello.jar |
118 |
* run-time : -Xbootclasspath/a:${testdir}/hello.jar |
|
119 |
*/ |
|
120 |
public void testBootClassPathMatch() throws Exception { |
|
121 |
String appJar = TestCommon.getTestJar("hello.jar"); |
|
122 |
String appClasses[] = {"Hello"}; |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48469
diff
changeset
|
123 |
TestCommon.dump( |
48138 | 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 | 129 |
} |
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 | 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 | 163 |
private static void copyHelloToNewDir() throws Exception { |
164 |
String classDir = System.getProperty("test.classes"); |
|
165 |
String dstDir = classDir + File.separator + "newdir"; |
|
166 |
try { |
|
167 |
Files.createDirectory(Paths.get(dstDir)); |
|
168 |
} catch (FileAlreadyExistsException e) { } |
|
169 |
||
50199
83d8b3a25f25
8199807: AppCDS performs overly restrictive path matching check.
jiangli
parents:
48979
diff
changeset
|
170 |
// copy as hello.jar |
48138 | 171 |
Files.copy(Paths.get(classDir, "hello.jar"), |
172 |
Paths.get(dstDir, "hello.jar"), |
|
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 | 179 |
} |
180 |
} |