author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57705 | 7cf02b2c1455 |
permissions | -rw-r--r-- |
54927 | 1 |
/* |
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
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 |
* @requires vm.cds |
|
57567
b000362a89a0
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents:
54927
diff
changeset
|
28 |
* @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
|
29 |
* @modules jdk.jartool/sun.tools.jar |
54927 | 30 |
* @run driver MainModuleOnly |
31 |
* @summary Test some scenarios with a main modular jar specified in the --module-path and -cp options in the command line. |
|
32 |
*/ |
|
33 |
||
34 |
import java.io.File; |
|
35 |
import java.nio.file.Files; |
|
36 |
import java.nio.file.Path; |
|
37 |
import java.nio.file.Paths; |
|
38 |
import java.util.Arrays; |
|
39 |
||
40 |
import jdk.test.lib.process.OutputAnalyzer; |
|
41 |
import jdk.test.lib.Platform; |
|
42 |
||
43 |
public class MainModuleOnly extends DynamicArchiveTestBase { |
|
44 |
||
45 |
private static final Path USER_DIR = Paths.get(System.getProperty("user.dir")); |
|
46 |
||
47 |
private static final String FS = File.separator; |
|
48 |
private static final String TEST_SRC = System.getProperty("test.src") + |
|
49 |
FS + ".." + FS + "jigsaw" + FS + "modulepath"; |
|
50 |
||
51 |
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
|
52 |
private static final Path MODS_DIR = Paths.get("mods"); |
|
53 |
||
54 |
// the module name of the test module |
|
55 |
private static final String TEST_MODULE1 = "com.simple"; |
|
56 |
||
57 |
// the module main class |
|
58 |
private static final String MAIN_CLASS = "com.simple.Main"; |
|
59 |
||
60 |
private static Path moduleDir = null; |
|
61 |
private static Path moduleDir2 = null; |
|
62 |
private static Path destJar = null; |
|
63 |
||
64 |
public static void buildTestModule() throws Exception { |
|
65 |
||
66 |
// javac -d mods/$TESTMODULE --module-path MOD_DIR src/$TESTMODULE/** |
|
67 |
JarBuilder.compileModule(SRC_DIR.resolve(TEST_MODULE1), |
|
68 |
MODS_DIR.resolve(TEST_MODULE1), |
|
69 |
MODS_DIR.toString()); |
|
70 |
||
71 |
||
72 |
moduleDir = Files.createTempDirectory(USER_DIR, "mlib"); |
|
73 |
moduleDir2 = Files.createTempDirectory(USER_DIR, "mlib2"); |
|
74 |
||
75 |
Path srcJar = moduleDir.resolve(TEST_MODULE1 + ".jar"); |
|
76 |
destJar = moduleDir2.resolve(TEST_MODULE1 + ".jar"); |
|
77 |
String classes = MODS_DIR.resolve(TEST_MODULE1).toString(); |
|
78 |
JarBuilder.createModularJar(srcJar.toString(), classes, MAIN_CLASS); |
|
79 |
Files.copy(srcJar, destJar); |
|
80 |
||
81 |
} |
|
82 |
||
83 |
static void testDefaultBase() throws Exception { |
|
84 |
String topArchiveName = getNewArchiveName("top"); |
|
85 |
doTest(topArchiveName); |
|
86 |
} |
|
87 |
||
88 |
public static void main(String... args) throws Exception { |
|
89 |
runTest(MainModuleOnly::testDefaultBase); |
|
90 |
} |
|
91 |
||
92 |
public static void doTest(String topArchiveName) throws Exception { |
|
93 |
// compile the modules and create the modular jar files |
|
94 |
buildTestModule(); |
|
95 |
// create an archive with both -cp and --module-path in the command line. |
|
96 |
// Only the class in the modular jar in the --module-path will be archived; |
|
97 |
// the class in the modular jar in the -cp won't be archived. |
|
98 |
dump2(null, topArchiveName, |
|
99 |
"-Xlog:cds+dynamic=debug,cds=debug", |
|
100 |
"-cp", destJar.toString(), |
|
101 |
"--module-path", moduleDir.toString(), |
|
102 |
"-m", TEST_MODULE1) |
|
103 |
.assertNormalExit(output -> { |
|
104 |
output.shouldContain("Buffer-space to target-space delta") |
|
105 |
.shouldContain("Written dynamic archive 0x"); |
|
106 |
}); |
|
107 |
||
108 |
// run with the archive using the same command line as in dump time. |
|
109 |
// The main class should be loaded from the archive. |
|
110 |
run2(null, topArchiveName, |
|
111 |
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace", |
|
112 |
"-cp", destJar.toString(), |
|
113 |
"--module-path", moduleDir.toString(), |
|
114 |
"-m", TEST_MODULE1) |
|
115 |
.assertNormalExit(output -> { |
|
116 |
output.shouldContain("[class,load] com.simple.Main source: shared objects file") |
|
117 |
.shouldHaveExitValue(0); |
|
118 |
}); |
|
119 |
||
120 |
// run with the archive with the main class name inserted before the -m. |
|
121 |
// The main class name will be picked up before the module name. So the |
|
122 |
// main class should be loaded from the jar in the -cp. |
|
123 |
run2(null, topArchiveName, |
|
124 |
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace", |
|
125 |
"-cp", destJar.toString(), |
|
126 |
"--module-path", moduleDir.toString(), |
|
127 |
MAIN_CLASS, "-m", TEST_MODULE1) |
|
128 |
.assertNormalExit(out -> |
|
129 |
out.shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar")); |
|
130 |
||
131 |
// run with the archive with exploded module. Since during dump time, we |
|
132 |
// only archive classes from the modular jar in the --module-path, the |
|
133 |
// main class should be loaded from the exploded module directory. |
|
134 |
run2(null, topArchiveName, |
|
135 |
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace", |
|
136 |
"-cp", destJar.toString(), |
|
137 |
"--module-path", MODS_DIR.toString(), |
|
138 |
"-m", TEST_MODULE1 + "/" + MAIN_CLASS) |
|
139 |
.assertNormalExit(out -> { |
|
140 |
out.shouldMatch(".class.load. com.simple.Main source:.*com.simple") |
|
141 |
.shouldContain(MODS_DIR.toString()); |
|
142 |
}); |
|
143 |
||
144 |
// run with the archive with the --upgrade-module-path option. |
|
145 |
// CDS will be disabled with this options and the main class will be |
|
146 |
// loaded from the modular jar. |
|
147 |
run2(null, topArchiveName, |
|
148 |
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace", |
|
149 |
"-cp", destJar.toString(), |
|
150 |
"--upgrade-module-path", moduleDir.toString(), |
|
151 |
"--module-path", moduleDir.toString(), |
|
152 |
"-m", TEST_MODULE1) |
|
153 |
.assertSilentlyDisabledCDS(out -> { |
|
154 |
out.shouldHaveExitValue(0) |
|
155 |
.shouldMatch("CDS is disabled when the.*option is specified") |
|
156 |
.shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); |
|
157 |
}); |
|
158 |
// run with the archive with the --limit-modules option. |
|
159 |
// CDS will be disabled with this options and the main class will be |
|
160 |
// loaded from the modular jar. |
|
161 |
run2(null, topArchiveName, |
|
162 |
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace", |
|
163 |
"-cp", destJar.toString(), |
|
164 |
"--limit-modules", "java.base," + TEST_MODULE1, |
|
165 |
"--module-path", moduleDir.toString(), |
|
166 |
"-m", TEST_MODULE1) |
|
167 |
.assertSilentlyDisabledCDS(out -> { |
|
168 |
out.shouldHaveExitValue(0) |
|
169 |
.shouldMatch("CDS is disabled when the.*option is specified") |
|
170 |
.shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); |
|
171 |
}); |
|
172 |
// run with the archive with the --patch-module option. |
|
173 |
// CDS will be disabled with this options and the main class will be |
|
174 |
// loaded from the modular jar. |
|
175 |
run2(null, topArchiveName, |
|
176 |
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace", |
|
177 |
"-cp", destJar.toString(), |
|
178 |
"--patch-module", TEST_MODULE1 + "=" + MODS_DIR.toString(), |
|
179 |
"--module-path", moduleDir.toString(), |
|
180 |
"-m", TEST_MODULE1) |
|
181 |
.assertSilentlyDisabledCDS(out -> { |
|
182 |
out.shouldHaveExitValue(0) |
|
183 |
.shouldMatch("CDS is disabled when the.*option is specified") |
|
184 |
.shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); |
|
185 |
}); |
|
186 |
// modify the timestamp of the jar file |
|
187 |
(new File(destJar.toString())).setLastModified(System.currentTimeMillis() + 2000); |
|
188 |
// run with the archive and the jar with modified timestamp. |
|
189 |
// It should fail due to timestamp of the jar doesn't match the one |
|
190 |
// used during dump time. |
|
191 |
run2(null, topArchiveName, |
|
192 |
"-Xlog:cds+dynamic=debug,cds=debug,class+load=trace", |
|
193 |
"-cp", destJar.toString(), |
|
194 |
"--module-path", moduleDir.toString(), |
|
195 |
"-m", TEST_MODULE1) |
|
196 |
.assertAbnormalExit( |
|
197 |
"A jar file is not the one used while building the shared archive file:"); |
|
198 |
// create an archive with a non-empty directory in the --module-path. |
|
199 |
// The dumping process will exit with an error due to non-empty directory |
|
200 |
// in the --module-path. |
|
201 |
dump2(null, topArchiveName, |
|
202 |
"-Xlog:cds+dynamic=debug,cds=debug", |
|
203 |
"-cp", destJar.toString(), |
|
204 |
"--module-path", MODS_DIR.toString(), |
|
205 |
"-m", TEST_MODULE1 + "/" + MAIN_CLASS) |
|
206 |
.assertAbnormalExit(output -> { |
|
207 |
output.shouldMatch("Error: non-empty directory.*com.simple"); |
|
208 |
}); |
|
209 |
||
210 |
// test module path with very long length |
|
211 |
// |
|
212 |
// This test can't be run on the windows platform due to an existing |
|
213 |
// issue in ClassLoader::get_canonical_path() (JDK-8190737). |
|
214 |
if (Platform.isWindows()) { |
|
215 |
System.out.println("Long module path test cannot be tested on the Windows platform."); |
|
216 |
return; |
|
217 |
} |
|
218 |
Path longDir = USER_DIR; |
|
219 |
int pathLen = longDir.toString().length(); |
|
220 |
int PATH_LEN = 2034; |
|
221 |
int MAX_DIR_LEN = 250; |
|
222 |
while (pathLen < PATH_LEN) { |
|
223 |
int remaining = PATH_LEN - pathLen; |
|
224 |
int subPathLen = remaining > MAX_DIR_LEN ? MAX_DIR_LEN : remaining; |
|
225 |
char[] chars = new char[subPathLen]; |
|
226 |
Arrays.fill(chars, 'x'); |
|
227 |
String subPath = new String(chars); |
|
228 |
longDir = Paths.get(longDir.toString(), subPath); |
|
229 |
pathLen = longDir.toString().length(); |
|
230 |
} |
|
231 |
File longDirFile = new File(longDir.toString()); |
|
232 |
try { |
|
233 |
longDirFile.mkdirs(); |
|
234 |
} catch (Exception e) { |
|
235 |
throw e; |
|
236 |
} |
|
237 |
Path longDirJar = longDir.resolve(TEST_MODULE1 + ".jar"); |
|
238 |
// IOException results from the Files.copy() call on platform |
|
239 |
// such as MacOS X. Test can't be proceeded further with the |
|
240 |
// exception. |
|
241 |
try { |
|
242 |
Files.copy(destJar, longDirJar); |
|
243 |
} catch (java.io.IOException ioe) { |
|
244 |
System.out.println("Caught IOException from Files.copy(). Cannot continue."); |
|
245 |
return; |
|
246 |
} |
|
247 |
dump2(null, topArchiveName, |
|
248 |
"-Xlog:cds+dynamic=debug,cds=debug", |
|
249 |
"-cp", destJar.toString(), |
|
250 |
"-Xlog:exceptions=trace", |
|
251 |
"--module-path", longDirJar.toString(), |
|
252 |
"-m", TEST_MODULE1) |
|
253 |
.ifAbnormalExit(output -> { |
|
254 |
output.shouldMatch("os::stat error.*CDS dump aborted"); |
|
255 |
}); |
|
256 |
} |
|
257 |
} |