1 /* |
1 /* |
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
65 private static final String TEST_SRC = System.getProperty("test.src"); |
65 private static final String TEST_SRC = System.getProperty("test.src"); |
66 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
66 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
67 private static final Path MODS_DIR = Paths.get("mods"); |
67 private static final Path MODS_DIR = Paths.get("mods"); |
68 |
68 |
69 // the module that is upgraded |
69 // the module that is upgraded |
70 private static final String[] UPGRADED_MODULES = {"jdk.compiler", "java.activation"}; |
70 private static final String[] UPGRADED_MODULES = {"jdk.compiler", "java.net.http"}; |
71 private static final Path[] UPGRADEDMODS_DIR = {Paths.get("upgradedmod1"), Paths.get("upgradedmod2")}; |
71 private static final Path[] UPGRADEDMODS_DIR = {Paths.get("upgradedmod1"), Paths.get("upgradedmod2")}; |
72 |
72 |
73 // the test module |
73 // the test module |
74 private static final String TEST_MODULE = "test"; |
74 private static final String TEST_MODULE = "test"; |
75 private static final String MAIN_CLASS = "jdk.test.Main"; |
75 private static final String MAIN_CLASS = "jdk.test.Main"; |
76 |
76 |
77 // test classes to archive. These are both in UPGRADED_MODULES |
77 // test classes to archive. These are both in UPGRADED_MODULES |
78 private static final String APP_ARCHIVE_CLASS = "com/sun/tools/javac/Main"; |
78 private static final String APP_ARCHIVE_CLASS = "com/sun/tools/javac/Main"; |
79 private static final String PLATFORM_ARCHIVE_CLASS = "javax/activation/UnsupportedDataTypeException"; |
79 private static final String PLATFORM_ARCHIVE_CLASS = "java/net/http/HttpTimeoutException"; |
80 private static final String[] ARCHIVE_CLASSES = {APP_ARCHIVE_CLASS, PLATFORM_ARCHIVE_CLASS}; |
80 private static final String[] ARCHIVE_CLASSES = {APP_ARCHIVE_CLASS, PLATFORM_ARCHIVE_CLASS}; |
81 private static String testArchiveName; |
81 private static String testArchiveName; |
82 |
82 |
83 |
83 |
84 public static void main(String[] args) throws Exception { |
84 public static void main(String[] args) throws Exception { |
92 boolean compiled; |
92 boolean compiled; |
93 // javac -d upgradedmods/$upgradedMod src/$upgradedMod/** |
93 // javac -d upgradedmods/$upgradedMod src/$upgradedMod/** |
94 int i = 0; |
94 int i = 0; |
95 for (String upgradedMod : UPGRADED_MODULES) { |
95 for (String upgradedMod : UPGRADED_MODULES) { |
96 compiled = CompilerUtils.compile( |
96 compiled = CompilerUtils.compile( |
97 SRC_DIR.resolve(upgradedMod), |
97 SRC_DIR.resolve(UPGRADED_MODULES[i]), |
98 UPGRADEDMODS_DIR[i].resolve(upgradedMod) |
98 UPGRADEDMODS_DIR[i].resolve(UPGRADED_MODULES[i]) |
99 ); |
99 ); |
100 Asserts.assertTrue(compiled, upgradedMod + " did not compile"); |
100 Asserts.assertTrue(compiled, UPGRADED_MODULES[i] + " did not compile"); |
101 i++; |
101 i++; |
102 } |
102 } |
103 |
103 |
104 // javac -d mods/test --upgrade-module-path upgradedmods ... |
104 // javac -d mods/test --upgrade-module-path upgradedmods ... |
105 compiled = CompilerUtils.compile( |
105 compiled = CompilerUtils.compile( |
108 "--upgrade-module-path", UPGRADEDMODS_DIR[0].toString() + |
108 "--upgrade-module-path", UPGRADEDMODS_DIR[0].toString() + |
109 System.getProperty("path.separator") + UPGRADEDMODS_DIR[1].toString() |
109 System.getProperty("path.separator") + UPGRADEDMODS_DIR[1].toString() |
110 ); |
110 ); |
111 Asserts.assertTrue(compiled, TEST_MODULE + " did not compile"); |
111 Asserts.assertTrue(compiled, TEST_MODULE + " did not compile"); |
112 |
112 |
113 // the java.activation module is not defined by default; --add-modules is required. |
113 // dump the archive with jdk.compiler and java.net.http classes in the class list |
114 // dumping without "--add-modules java.activation" |
114 OutputAnalyzer output = TestCommon.dump(null /* appJar*/, TestCommon.list(ARCHIVE_CLASSES)); |
115 // the class in the javax.activation package cannot be found |
115 TestCommon.checkDump(output); |
116 OutputAnalyzer output1 = TestCommon.dump(null /* appJar*/, TestCommon.list(ARCHIVE_CLASSES)); |
|
117 TestCommon.checkDump(output1); |
|
118 output1.shouldContain( |
|
119 "Preload Warning: Cannot find javax/activation/UnsupportedDataTypeException"); |
|
120 |
|
121 // dump the archive with jdk.comiler and java.activation classes in the class list |
|
122 // with "--add-modules java.activation" |
|
123 output1 = TestCommon.dump(null /* appJar*/, TestCommon.list(ARCHIVE_CLASSES), |
|
124 "--add-modules", "java.activation"); |
|
125 TestCommon.checkDump(output1); |
|
126 // Make sure all the classes where successfully archived. |
116 // Make sure all the classes where successfully archived. |
127 for (String archiveClass : ARCHIVE_CLASSES) { |
117 for (String archiveClass : ARCHIVE_CLASSES) { |
128 output1.shouldNotContain("Preload Warning: Cannot find " + archiveClass); |
118 output.shouldNotContain("Preload Warning: Cannot find " + archiveClass); |
129 } |
119 } |
130 |
120 |
131 testArchiveName = TestCommon.getCurrentArchiveName(); |
121 testArchiveName = TestCommon.getCurrentArchiveName(); |
132 } |
122 } |
133 |
123 |
145 } |
135 } |
146 |
136 |
147 /** |
137 /** |
148 * PLATFORM Class Overriding Tests |
138 * PLATFORM Class Overriding Tests |
149 * |
139 * |
150 * Archive PLATFORM class javax.activation.UnsupportedDataTypeException from module jdk.activation. |
140 * Archive PLATFORM class java.net.http.HttpTimeoutException from module java.net.http. |
151 * -At run time, upgrade module jdk.activation using --upgrade-module-path. |
141 * -At run time, upgrade module java.net.http using --upgrade-module-path. |
152 * Class.forname(UnsupportedDataTypeException) MUST NOT load the archived UnsupportedDataTypeException. |
142 * Class.forname(HttpTimeoutException) MUST NOT load the archived HttpTimeoutException. |
153 * -At run time, module jdk.activation also exists in --module-path. |
143 * -At run time, module java.net.http also exists in --module-path. |
154 * Class.forname(UnsupportedDataTypeException) MUST load the archived UnsupportedDataTypeException. |
144 * Class.forname(HttpTimeoutException) MUST load the archived HttpTimeoutException. |
155 */ |
145 */ |
156 public void testPlatformClassOverriding() throws Exception { |
146 public void testPlatformClassOverriding() throws Exception { |
157 testClassOverriding(PLATFORM_ARCHIVE_CLASS, "platform"); |
147 testClassOverriding(PLATFORM_ARCHIVE_CLASS, "platform"); |
158 } |
148 } |
159 |
149 |
171 String expectedException = "java.lang.module.FindException: Unable to compute the hash"; |
161 String expectedException = "java.lang.module.FindException: Unable to compute the hash"; |
172 String prefix[] = new String[4]; |
162 String prefix[] = new String[4]; |
173 prefix[0] = "-cp"; |
163 prefix[0] = "-cp"; |
174 prefix[1] = "\"\""; |
164 prefix[1] = "\"\""; |
175 prefix[2] = "--add-modules"; |
165 prefix[2] = "--add-modules"; |
176 prefix[3] = "java.activation"; |
166 prefix[3] = "java.net.http"; |
177 |
167 |
178 // Run the test with --upgrade-module-path set to alternate location of archiveClass |
168 // Run the test with --upgrade-module-path set to alternate location of archiveClass |
179 // The alternate version of archiveClass SHOULD be found. |
169 // The alternate version of archiveClass SHOULD be found. |
180 output = TestCommon.execModule( |
170 TestCommon.runWithModules(prefix, |
181 prefix, |
171 UPGRADEDMODS_DIR[upgradeModIdx].toString(), |
182 UPGRADEDMODS_DIR[upgradeModIdx].toString(), |
172 MODS_DIR.toString(), |
183 MODS_DIR.toString(), |
173 mid, |
184 mid, |
174 archiveClass, loaderName, "true") // last 3 args passed to test |
185 archiveClass, loaderName, "true"); // last 3 args passed to test |
175 .ifNoMappingFailure(out -> out.shouldContain(expectedException)); |
186 if (isAppLoader) { |
|
187 try { |
|
188 output.shouldContain(expectedException); |
|
189 } catch (Exception e) { |
|
190 TestCommon.checkCommonExecExceptions(output, e); |
|
191 } |
|
192 } else { |
|
193 TestCommon.checkExec(output); |
|
194 } |
|
195 |
176 |
196 // Now run this same test again, but this time without AppCDS. Behavior should be the same. |
177 // Now run this same test again, but this time without AppCDS. Behavior should be the same. |
197 CDSOptions opts = (new CDSOptions()) |
178 CDSOptions opts = (new CDSOptions()) |
198 .addPrefix(prefix) |
179 .addPrefix(prefix) |
199 .setArchiveName(testArchiveName).setUseVersion(false) |
180 .setArchiveName(testArchiveName).setUseVersion(false) |
201 "-p", MODS_DIR.toString(), "-m", mid) |
182 "-p", MODS_DIR.toString(), "-m", mid) |
202 .addSuffix(archiveClass, loaderName, "true"); |
183 .addSuffix(archiveClass, loaderName, "true"); |
203 |
184 |
204 output = CDSTestUtils.runWithArchive(opts); |
185 output = CDSTestUtils.runWithArchive(opts); |
205 |
186 |
206 if (isAppLoader) { |
187 try { |
207 try { |
188 output.shouldContain(expectedException); |
208 output.shouldContain(expectedException); |
189 } catch (Exception e) { |
209 } catch (Exception e) { |
190 TestCommon.checkCommonExecExceptions(output, e); |
210 TestCommon.checkCommonExecExceptions(output, e); |
|
211 } |
|
212 } else { |
|
213 if (!CDSTestUtils.isUnableToMap(output)) |
|
214 output.shouldHaveExitValue(0); |
|
215 } |
191 } |
216 |
192 |
217 // Run the test with -p set to alternate location of archiveClass. |
193 // Run the test with -p set to alternate location of archiveClass. |
218 // The alternate version of archiveClass SHOULD NOT be found. |
194 // The alternate version of archiveClass SHOULD NOT be found. |
219 output = TestCommon.execModule( |
195 TestCommon.runWithModules( |
220 prefix, |
196 prefix, |
221 null, |
197 null, |
222 UPGRADEDMODS_DIR[upgradeModIdx].toString() + java.io.File.pathSeparator + MODS_DIR.toString(), |
198 UPGRADEDMODS_DIR[upgradeModIdx].toString() + java.io.File.pathSeparator + MODS_DIR.toString(), |
223 mid, |
199 mid, |
224 archiveClass, loaderName, "false"); // last 3 args passed to test |
200 archiveClass, loaderName, "false") // last 3 args passed to test |
225 TestCommon.checkExec(output); |
201 .assertNormalExit(); |
226 |
202 |
227 // Now run this same test again, but this time without AppCDS. Behavior should be the same. |
203 // Now run this same test again, but this time without AppCDS. Behavior should be the same. |
228 opts = (new CDSOptions()) |
204 opts = (new CDSOptions()) |
229 .addPrefix(prefix) |
205 .addPrefix(prefix) |
230 .setArchiveName(testArchiveName).setUseVersion(false) |
206 .setArchiveName(testArchiveName).setUseVersion(false) |