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-- |
48138 | 1 |
/* |
53636
962ed57b29c9
8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
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 |
|
48469
7312ae4465d6
8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents:
48138
diff
changeset
|
27 |
* @requires vm.cds |
57705
7cf02b2c1455
8229267: [TESTBUG] Remove unnecessary @modules dependencies in CDS tests
iklam
parents:
57567
diff
changeset
|
28 |
* @modules jdk.jartool/sun.tools.jar |
48138 | 29 |
* @library ../.. |
30 |
* @library /test/lib |
|
54927 | 31 |
* @compile ../../test-classes/Hello.java |
51990
6003e034cdd8
8209946: [TESTBUG] CDS tests should use "@run driver"
iklam
parents:
49894
diff
changeset
|
32 |
* @run driver OverrideTests |
48138 | 33 |
* @summary AppCDS tests for overriding archived classes with -p and --upgrade-module-path |
34 |
*/ |
|
35 |
||
36 |
/* |
|
37 |
* This test consists of 4 tests: |
|
38 |
* 1. Archive PLATFORM class and override with --upgrade-module-path. |
|
39 |
* 2. Archive PLATFORM class and override with -p. |
|
40 |
* 3. Archive APP class and override with --upgrade-module-path. |
|
41 |
* 4. Archive App class and override with -p. |
|
42 |
* For all 4 tests, the class is instantiatied and toString() is called |
|
43 |
* to check whether the archived version or the override version was instantiatied. |
|
44 |
* For tests 1 and 3, the overridden version should be instantiatied. |
|
45 |
* For tests 2 and 4, the archived version should be instantiated. |
|
46 |
* |
|
47 |
* This test uses the same test helper class in all 4 cases. It is located in |
|
48 |
* src/test/jdk/test/Main.java. It will be invoked once for each test cases, |
|
49 |
* with parameters to the test determining how it is run and what the |
|
50 |
* expected result is. See Main.java for a description of these 3 arguments. |
|
51 |
*/ |
|
52 |
||
53 |
import java.io.File; |
|
54 |
import java.nio.file.Files; |
|
55 |
import java.nio.file.Path; |
|
56 |
import java.nio.file.Paths; |
|
57 |
||
58 |
import jdk.test.lib.Asserts; |
|
59 |
import jdk.test.lib.cds.CDSOptions; |
|
60 |
import jdk.test.lib.cds.CDSTestUtils; |
|
61 |
import jdk.test.lib.process.OutputAnalyzer; |
|
62 |
import jdk.test.lib.process.ProcessTools; |
|
63 |
||
64 |
||
65 |
public class OverrideTests { |
|
66 |
private static final String TEST_SRC = System.getProperty("test.src"); |
|
67 |
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
|
68 |
private static final Path MODS_DIR = Paths.get("mods"); |
|
54927 | 69 |
private static String appJar; |
48138 | 70 |
// the module that is upgraded |
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
71 |
private static final String[] UPGRADED_MODULES = {"jdk.compiler", "java.net.http"}; |
48138 | 72 |
private static final Path[] UPGRADEDMODS_DIR = {Paths.get("upgradedmod1"), Paths.get("upgradedmod2")}; |
73 |
||
74 |
// the test module |
|
75 |
private static final String TEST_MODULE = "test"; |
|
76 |
private static final String MAIN_CLASS = "jdk.test.Main"; |
|
77 |
||
78 |
// test classes to archive. These are both in UPGRADED_MODULES |
|
79 |
private static final String APP_ARCHIVE_CLASS = "com/sun/tools/javac/Main"; |
|
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
80 |
private static final String PLATFORM_ARCHIVE_CLASS = "java/net/http/HttpTimeoutException"; |
48138 | 81 |
private static final String[] ARCHIVE_CLASSES = {APP_ARCHIVE_CLASS, PLATFORM_ARCHIVE_CLASS}; |
82 |
private static String testArchiveName; |
|
83 |
||
84 |
||
85 |
public static void main(String[] args) throws Exception { |
|
54927 | 86 |
appJar = JarBuilder.getOrCreateHelloJar(); |
48138 | 87 |
OverrideTests tests = new OverrideTests(); |
88 |
tests.compileModulesAndDumpArchive(); |
|
89 |
tests.testAppClassOverriding(); |
|
90 |
tests.testPlatformClassOverriding(); |
|
91 |
} |
|
92 |
||
93 |
void compileModulesAndDumpArchive() throws Exception { |
|
94 |
boolean compiled; |
|
95 |
// javac -d upgradedmods/$upgradedMod src/$upgradedMod/** |
|
96 |
int i = 0; |
|
97 |
for (String upgradedMod : UPGRADED_MODULES) { |
|
98 |
compiled = CompilerUtils.compile( |
|
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
99 |
SRC_DIR.resolve(UPGRADED_MODULES[i]), |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
100 |
UPGRADEDMODS_DIR[i].resolve(UPGRADED_MODULES[i]) |
48138 | 101 |
); |
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
102 |
Asserts.assertTrue(compiled, UPGRADED_MODULES[i] + " did not compile"); |
48138 | 103 |
i++; |
104 |
} |
|
105 |
||
106 |
// javac -d mods/test --upgrade-module-path upgradedmods ... |
|
107 |
compiled = CompilerUtils.compile( |
|
108 |
SRC_DIR.resolve(TEST_MODULE), |
|
109 |
MODS_DIR.resolve(TEST_MODULE), |
|
110 |
"--upgrade-module-path", UPGRADEDMODS_DIR[0].toString() + |
|
111 |
System.getProperty("path.separator") + UPGRADEDMODS_DIR[1].toString() |
|
112 |
); |
|
113 |
Asserts.assertTrue(compiled, TEST_MODULE + " did not compile"); |
|
114 |
||
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
115 |
// dump the archive with jdk.compiler and java.net.http classes in the class list |
54927 | 116 |
OutputAnalyzer output = TestCommon.dump(appJar, TestCommon.list(ARCHIVE_CLASSES)); |
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
117 |
TestCommon.checkDump(output); |
48138 | 118 |
// Make sure all the classes where successfully archived. |
119 |
for (String archiveClass : ARCHIVE_CLASSES) { |
|
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
120 |
output.shouldNotContain("Preload Warning: Cannot find " + archiveClass); |
48138 | 121 |
} |
122 |
||
123 |
testArchiveName = TestCommon.getCurrentArchiveName(); |
|
124 |
} |
|
125 |
||
126 |
/** |
|
127 |
* APP Class Overriding Tests |
|
128 |
* |
|
129 |
* Archive APP class com.sun.tools.javac.Main from module jdk.compiler. |
|
130 |
* -At run time, upgrade module jdk.compiler using --upgrade-module-path. |
|
131 |
* Class.forname(Main) MUST NOT load the archived Main. |
|
132 |
* -At run time, module jdk.compiler also exists in --module-path. |
|
133 |
* Class.forname(Main) MUST load the archived Main. |
|
134 |
*/ |
|
135 |
public void testAppClassOverriding() throws Exception { |
|
136 |
testClassOverriding(APP_ARCHIVE_CLASS, "app"); |
|
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* PLATFORM Class Overriding Tests |
|
141 |
* |
|
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
142 |
* Archive PLATFORM class java.net.http.HttpTimeoutException from module java.net.http. |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
143 |
* -At run time, upgrade module java.net.http using --upgrade-module-path. |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
144 |
* Class.forname(HttpTimeoutException) MUST NOT load the archived HttpTimeoutException. |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
145 |
* -At run time, module java.net.http also exists in --module-path. |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
146 |
* Class.forname(HttpTimeoutException) MUST load the archived HttpTimeoutException. |
48138 | 147 |
*/ |
148 |
public void testPlatformClassOverriding() throws Exception { |
|
149 |
testClassOverriding(PLATFORM_ARCHIVE_CLASS, "platform"); |
|
150 |
} |
|
151 |
||
152 |
/** |
|
153 |
* Run the test twice. Once with upgrade module on --upgrade-module-path and once with it on -p. |
|
154 |
* Only modules defined to the PlatformClassLoader are upgradeable. |
|
155 |
* Modules defined to the AppClassLoader are not upgradeble; we expect the |
|
156 |
* FindException to be thrown. |
|
157 |
*/ |
|
158 |
void testClassOverriding(String archiveClass, String loaderName) throws Exception { |
|
159 |
String mid = TEST_MODULE + "/" + MAIN_CLASS; |
|
160 |
OutputAnalyzer output; |
|
161 |
boolean isAppLoader = loaderName.equals("app"); |
|
162 |
int upgradeModIdx = isAppLoader ? 0 : 1; |
|
163 |
String expectedException = "java.lang.module.FindException: Unable to compute the hash"; |
|
53636
962ed57b29c9
8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents:
51990
diff
changeset
|
164 |
String prefix[] = new String[3]; |
54927 | 165 |
prefix[0] = "-Djava.class.path=" + appJar; |
53636
962ed57b29c9
8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents:
51990
diff
changeset
|
166 |
prefix[1] = "--add-modules"; |
962ed57b29c9
8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents:
51990
diff
changeset
|
167 |
prefix[2] = "java.net.http"; |
48138 | 168 |
|
169 |
// Run the test with --upgrade-module-path set to alternate location of archiveClass |
|
170 |
// The alternate version of archiveClass SHOULD be found. |
|
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
171 |
TestCommon.runWithModules(prefix, |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
172 |
UPGRADEDMODS_DIR[upgradeModIdx].toString(), |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
173 |
MODS_DIR.toString(), |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
174 |
mid, |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
175 |
archiveClass, loaderName, "true") // last 3 args passed to test |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
176 |
.ifNoMappingFailure(out -> out.shouldContain(expectedException)); |
48138 | 177 |
|
178 |
// Now run this same test again, but this time without AppCDS. Behavior should be the same. |
|
179 |
CDSOptions opts = (new CDSOptions()) |
|
180 |
.addPrefix(prefix) |
|
181 |
.setArchiveName(testArchiveName).setUseVersion(false) |
|
182 |
.addSuffix("--upgrade-module-path", UPGRADEDMODS_DIR[upgradeModIdx].toString(), |
|
183 |
"-p", MODS_DIR.toString(), "-m", mid) |
|
184 |
.addSuffix(archiveClass, loaderName, "true"); |
|
185 |
||
186 |
output = CDSTestUtils.runWithArchive(opts); |
|
187 |
||
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
188 |
try { |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
189 |
output.shouldContain(expectedException); |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
190 |
} catch (Exception e) { |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
191 |
TestCommon.checkCommonExecExceptions(output, e); |
48138 | 192 |
} |
193 |
||
194 |
// Run the test with -p set to alternate location of archiveClass. |
|
195 |
// The alternate version of archiveClass SHOULD NOT be found. |
|
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
196 |
TestCommon.runWithModules( |
48138 | 197 |
prefix, |
198 |
null, |
|
199 |
UPGRADEDMODS_DIR[upgradeModIdx].toString() + java.io.File.pathSeparator + MODS_DIR.toString(), |
|
200 |
mid, |
|
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
201 |
archiveClass, loaderName, "false") // last 3 args passed to test |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
48469
diff
changeset
|
202 |
.assertNormalExit(); |
48138 | 203 |
|
204 |
// Now run this same test again, but this time without AppCDS. Behavior should be the same. |
|
205 |
opts = (new CDSOptions()) |
|
206 |
.addPrefix(prefix) |
|
207 |
.setArchiveName(testArchiveName).setUseVersion(false) |
|
208 |
.addSuffix("-p", MODS_DIR.toString(), "-m", mid) |
|
209 |
.addSuffix(archiveClass, loaderName, "false"); // params to the test class |
|
210 |
||
211 |
OutputAnalyzer out = CDSTestUtils.runWithArchive(opts); |
|
212 |
if (!CDSTestUtils.isUnableToMap(out)) |
|
213 |
out.shouldHaveExitValue(0); |
|
214 |
} |
|
215 |
} |