author | iklam |
Fri, 09 Aug 2019 13:13:36 -0700 | |
changeset 57705 | 7cf02b2c1455 |
parent 57567 | b000362a89a0 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
57567
b000362a89a0
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents:
51990
diff
changeset
|
2 |
* Copyright (c) 2015, 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 AppCDS tests for testing -Xbootclasspath/a |
|
48469
7312ae4465d6
8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents:
48397
diff
changeset
|
28 |
* @requires vm.cds & !vm.graal.enabled |
57567
b000362a89a0
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents:
51990
diff
changeset
|
29 |
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds |
57705
7cf02b2c1455
8229267: [TESTBUG] Remove unnecessary @modules dependencies in CDS tests
iklam
parents:
57567
diff
changeset
|
30 |
* @modules jdk.jartool/sun.tools.jar |
48138 | 31 |
* @compile src/jdk/test/Main.java |
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
49739
diff
changeset
|
32 |
* @compile src/com/sun/tools/javac/MyMain.jasm |
48138 | 33 |
* @compile src/sun/nio/cs/ext/MyClass.java |
34 |
* @compile src/sun/nio/cs/ext1/MyClass.java |
|
51990
6003e034cdd8
8209946: [TESTBUG] CDS tests should use "@run driver"
iklam
parents:
49894
diff
changeset
|
35 |
* @run driver BootAppendTests |
48138 | 36 |
*/ |
37 |
||
38 |
import java.io.File; |
|
39 |
import java.nio.file.Path; |
|
40 |
import java.nio.file.Paths; |
|
41 |
import jdk.test.lib.cds.CDSOptions; |
|
42 |
import jdk.test.lib.cds.CDSTestUtils; |
|
43 |
import jdk.test.lib.process.ProcessTools; |
|
44 |
import jdk.test.lib.process.OutputAnalyzer; |
|
45 |
||
46 |
public class BootAppendTests { |
|
47 |
private static final String TEST_SRC = System.getProperty("test.src"); |
|
48 |
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
|
49 |
private static final Path CLASSES_DIR = Paths.get("classes"); |
|
50 |
||
51 |
private static final String MAIN_CLASS = "jdk.test.Main"; |
|
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
49739
diff
changeset
|
52 |
private static final String APP_MODULE_CLASS = "com/sun/tools/javac/MyMain"; |
48138 | 53 |
private static final String BOOT_APPEND_MODULE_CLASS = "sun/nio/cs/ext/MyClass"; |
54 |
private static final String BOOT_APPEND_CLASS = "sun/nio/cs/ext1/MyClass"; |
|
55 |
private static final String[] ARCHIVE_CLASSES = |
|
56 |
{APP_MODULE_CLASS, BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_CLASS}; |
|
57 |
||
58 |
private static String appJar; |
|
59 |
private static String bootAppendJar; |
|
60 |
private static String testArchiveName; |
|
61 |
||
62 |
public static void main(String... args) throws Exception { |
|
63 |
dumpArchive(); |
|
64 |
||
65 |
System.out.println("TESTCASE: 1: testBootAppendModuleClassWithoutAppCDS"); |
|
66 |
testBootAppendModuleClassWithoutAppCDS(); |
|
67 |
||
68 |
System.out.println("TESTCASE: 2" ); |
|
69 |
testBootAppendModuleClassWithAppCDS(); |
|
70 |
||
71 |
System.out.println("TESTCASE: 3" ); |
|
72 |
testBootAppendExcludedModuleClassWithoutAppCDS(); |
|
73 |
||
74 |
System.out.println("TESTCASE: 4" ); |
|
75 |
testBootAppendExcludedModuleClassWithAppCDS(); |
|
76 |
||
77 |
System.out.println("TESTCASE: 5" ); |
|
78 |
testBootAppendClassWithoutAppCDS(); |
|
79 |
||
80 |
System.out.println("TESTCASE: 6" ); |
|
81 |
testBootAppendClassWithAppCDS(); |
|
82 |
||
83 |
System.out.println("TESTCASE: 7" ); |
|
84 |
testBootAppendAppModuleClassWithoutAppCDS(); |
|
85 |
||
86 |
System.out.println("TESTCASE: 9" ); |
|
87 |
testBootAppendAppModuleClassWithAppCDS(); |
|
88 |
||
89 |
System.out.println("TESTCASE: 9" ); |
|
90 |
testBootAppendAppExcludeModuleClassWithoutAppCDS(); |
|
91 |
||
92 |
System.out.println("TESTCASE: 10" ); |
|
93 |
testBootAppendAppExcludeModuleClassAppCDS(); |
|
94 |
} |
|
95 |
||
96 |
static void dumpArchive() throws Exception { |
|
97 |
JarBuilder.build("classpathtests", "jdk/test/Main"); |
|
98 |
appJar = TestCommon.getTestJar("classpathtests.jar"); |
|
99 |
||
100 |
JarBuilder.build("bootAppend", |
|
101 |
APP_MODULE_CLASS, BOOT_APPEND_MODULE_CLASS, BOOT_APPEND_CLASS); |
|
102 |
bootAppendJar = TestCommon.getTestJar("bootAppend.jar"); |
|
103 |
||
104 |
OutputAnalyzer output1 = TestCommon.dump( |
|
105 |
appJar, TestCommon.list(ARCHIVE_CLASSES), "-Xbootclasspath/a:" + bootAppendJar); |
|
106 |
TestCommon.checkDump(output1); |
|
107 |
||
108 |
if (!TestCommon.isUnableToMap(output1)) { |
|
109 |
// Make sure all the classes were successfully archived. |
|
110 |
for (String archiveClass : ARCHIVE_CLASSES) { |
|
111 |
output1.shouldNotContain("Preload Warning: Cannot find " + archiveClass); |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
testArchiveName = TestCommon.getCurrentArchiveName(); |
|
116 |
} |
|
117 |
||
118 |
// Test #1: A class in package defined in boot module |
|
119 |
// - should not be loaded from the -Xbootclasspath/a without AppCDS |
|
120 |
public static void testBootAppendModuleClassWithoutAppCDS() throws Exception { |
|
121 |
CDSOptions opts = (new CDSOptions()) |
|
122 |
.addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar) |
|
123 |
.setArchiveName(testArchiveName) |
|
124 |
.addSuffix(MAIN_CLASS, "Test #1", BOOT_APPEND_MODULE_CLASS, "false"); |
|
125 |
||
126 |
CDSTestUtils.runWithArchiveAndCheck(opts); |
|
127 |
} |
|
128 |
||
129 |
// Test #2: A shared class in package defined in boot module that's archived |
|
130 |
// from -Xbootclasspath/a |
|
131 |
// - should not be loaded by AppCDS |
|
132 |
public static void testBootAppendModuleClassWithAppCDS() throws Exception { |
|
133 |
OutputAnalyzer output = TestCommon.exec( |
|
134 |
appJar, |
|
135 |
"-Xbootclasspath/a:" + bootAppendJar, |
|
136 |
MAIN_CLASS, |
|
137 |
"Test #2", BOOT_APPEND_MODULE_CLASS, "false"); |
|
138 |
TestCommon.checkExec(output); |
|
139 |
} |
|
140 |
||
141 |
||
142 |
// Test #3: A class in excluded package defined in boot module |
|
143 |
// - should be loaded from the -Xbootclasspath/a by the boot classloader |
|
144 |
public static void testBootAppendExcludedModuleClassWithoutAppCDS() throws Exception { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
145 |
TestCommon.run( |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
146 |
"-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
147 |
"-Xlog:class+load=info", |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
148 |
"--limit-modules", "java.base", |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
149 |
MAIN_CLASS, "Test #3", BOOT_APPEND_MODULE_CLASS, "true", "BOOT") |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
150 |
.assertSilentlyDisabledCDS(out -> { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
151 |
out.shouldHaveExitValue(0) |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
152 |
.shouldMatch(".class.load. sun.nio.cs.ext.MyClass source:.*bootAppend.jar"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
153 |
}); |
48138 | 154 |
} |
155 |
||
156 |
// Test #4: A shared class in excluded package that's archived from |
|
157 |
// -Xbootclasspath/a |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
158 |
// - should be loaded from the jar since AppCDS will be disabled with |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
159 |
// the --limit-modules option |
48138 | 160 |
public static void testBootAppendExcludedModuleClassWithAppCDS() throws Exception { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
161 |
TestCommon.run( |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
162 |
"-cp", appJar, "-Xbootclasspath/a:" + bootAppendJar, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
163 |
"-Xlog:class+load=info", |
48138 | 164 |
"--limit-modules", "java.base", |
165 |
MAIN_CLASS, |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
166 |
"Test #4", BOOT_APPEND_MODULE_CLASS, "true", "BOOT") |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
167 |
.assertSilentlyDisabledCDS(out -> { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
168 |
out.shouldHaveExitValue(0) |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
169 |
.shouldMatch(".class.load. sun.nio.cs.ext.MyClass source:.*bootAppend.jar"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
170 |
}); |
48138 | 171 |
} |
172 |
||
173 |
||
174 |
// Test #5: A class not in package defined in boot module |
|
175 |
// - should be loaded from the -Xbootclasspath/a without AppCDS |
|
176 |
public static void testBootAppendClassWithoutAppCDS() throws Exception { |
|
177 |
CDSOptions opts = (new CDSOptions()) |
|
178 |
.addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar) |
|
179 |
.setArchiveName(testArchiveName) |
|
180 |
.addSuffix(MAIN_CLASS, "Test #5", BOOT_APPEND_CLASS, "true", "BOOT"); |
|
181 |
||
182 |
CDSTestUtils.runWithArchiveAndCheck(opts); |
|
183 |
} |
|
184 |
||
185 |
||
186 |
// Test #6: A shared class not in package defined in boot module that's |
|
187 |
// archived from -Xbootclasspath/a |
|
188 |
// - should be loaded from the archive by the bootstrap class loader |
|
189 |
public static void testBootAppendClassWithAppCDS() throws Exception { |
|
190 |
OutputAnalyzer output = TestCommon.exec( |
|
191 |
appJar, |
|
192 |
"-Xbootclasspath/a:" + bootAppendJar, |
|
193 |
"-XX:+TraceClassLoading", |
|
194 |
MAIN_CLASS, |
|
195 |
"Test #6", BOOT_APPEND_CLASS, "true", "BOOT"); |
|
196 |
TestCommon.checkExec(output); |
|
197 |
if (!TestCommon.isUnableToMap(output)) |
|
198 |
output.shouldContain("[class,load] sun.nio.cs.ext1.MyClass source: shared objects file"); |
|
199 |
} |
|
200 |
||
201 |
||
202 |
// Test #7: A class in package defined in jimage app module |
|
203 |
// - should not be loaded from the -Xbootclasspath/a without AppCDS |
|
204 |
public static void testBootAppendAppModuleClassWithoutAppCDS() throws Exception { |
|
205 |
CDSOptions opts = (new CDSOptions()) |
|
206 |
.addPrefix("-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar) |
|
207 |
.setArchiveName(testArchiveName) |
|
208 |
.addSuffix(MAIN_CLASS, "Test #7", APP_MODULE_CLASS, "false"); |
|
209 |
||
210 |
CDSTestUtils.runWithArchiveAndCheck(opts); |
|
211 |
} |
|
212 |
||
213 |
||
214 |
// Test #8: A shared class in package defined in jimage app module that's |
|
215 |
// archived from -Xbootclasspath/a |
|
216 |
// - should not be loaded from the archive |
|
217 |
public static void testBootAppendAppModuleClassWithAppCDS() throws Exception { |
|
218 |
OutputAnalyzer output = TestCommon.exec( |
|
219 |
appJar, |
|
220 |
"-Xbootclasspath/a:" + bootAppendJar, |
|
221 |
MAIN_CLASS, |
|
222 |
"Test #8", APP_MODULE_CLASS, "false"); |
|
223 |
TestCommon.checkExec(output); |
|
224 |
} |
|
225 |
||
226 |
||
227 |
// Test #9: A class in excluded package defined in jimage app module |
|
228 |
// - should be loaded from the -Xbootclasspath/a without AppCDS |
|
229 |
public static void testBootAppendAppExcludeModuleClassWithoutAppCDS() |
|
230 |
throws Exception { |
|
231 |
||
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
232 |
TestCommon.run( |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
233 |
"-Xbootclasspath/a:" + bootAppendJar, "-cp", appJar, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
234 |
"-Xlog:class+load=info", |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
235 |
"--limit-modules", "java.base", |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
236 |
MAIN_CLASS, "Test #9", APP_MODULE_CLASS, "true", "BOOT") |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
237 |
.assertSilentlyDisabledCDS(out -> { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
238 |
out.shouldHaveExitValue(0) |
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
49739
diff
changeset
|
239 |
.shouldMatch(".class.load. com.sun.tools.javac.MyMain source:.*bootAppend.jar"); |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
240 |
}); |
48138 | 241 |
} |
242 |
||
243 |
// Test #10: A shared class in excluded package defined in jimage app module |
|
244 |
// - should be loaded from the -Xbootclasspath/a with AppCDS |
|
245 |
public static void testBootAppendAppExcludeModuleClassAppCDS() throws Exception { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
246 |
TestCommon.run( |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
247 |
"-cp", appJar, "-Xbootclasspath/a:" + bootAppendJar, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
248 |
"-Xlog:class+load=info", |
48138 | 249 |
"--limit-modules", "java.base", |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
250 |
MAIN_CLASS, "Test #10", APP_MODULE_CLASS, "true", "BOOT") |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
251 |
.assertSilentlyDisabledCDS(out -> { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
252 |
out.shouldHaveExitValue(0) |
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
49739
diff
changeset
|
253 |
.shouldMatch(".class.load. com.sun.tools.javac.MyMain source:.*bootAppend.jar"); |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
254 |
}); |
48138 | 255 |
} |
256 |
} |