author | jiefu |
Wed, 06 Nov 2019 13:43:25 +0800 | |
changeset 58944 | bb2a436e616c |
parent 57705 | 7cf02b2c1455 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
57567
b000362a89a0
8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents:
51325
diff
changeset
|
2 |
* Copyright (c) 2016, 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 MultiReleaseJars |
|
27 |
* @summary Test multi-release jar with AppCDS. |
|
48469
7312ae4465d6
8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents:
48403
diff
changeset
|
28 |
* @requires vm.cds |
48138 | 29 |
* @library /test/lib |
57705
7cf02b2c1455
8229267: [TESTBUG] Remove unnecessary @modules dependencies in CDS tests
iklam
parents:
57567
diff
changeset
|
30 |
* @modules jdk.jartool/sun.tools.jar |
51325
52fed262f009
8208704: runtime/appcds/MultiReleaseJars.java timed out often in hs-tier7 testing
ccheung
parents:
50166
diff
changeset
|
31 |
* @run main/othervm/timeout=2400 MultiReleaseJars |
48138 | 32 |
*/ |
33 |
||
34 |
import java.io.File; |
|
35 |
import java.io.FileOutputStream; |
|
36 |
import java.io.PrintStream; |
|
37 |
import java.io.IOException; |
|
38 |
import jdk.test.lib.process.OutputAnalyzer; |
|
39 |
||
40 |
public class MultiReleaseJars { |
|
41 |
||
50166
1d683e243d8d
8196619: [TESTBUG] restore current version check in runtime/appcds/MultiReleaseJars.java
ccheung
parents:
48741
diff
changeset
|
42 |
static final int MAJOR_VERSION = Runtime.version().major(); |
48741
d682d3da7923
8196550: [Testbug] runtime/appcds/MultiReleaseJars.java fails on JDK 11
dholmes
parents:
48469
diff
changeset
|
43 |
static final String MAJOR_VERSION_STRING = String.valueOf(MAJOR_VERSION); |
48138 | 44 |
|
45 |
static String[] getMain() { |
|
46 |
String[] sts = { |
|
47 |
"package version;", |
|
48 |
"public class Main {", |
|
49 |
" public static void main(String[] args) {", |
|
50 |
" Version version = new Version();", |
|
51 |
" System.out.println(\"I am running on version \" + version.getVersion());", |
|
52 |
" }", |
|
53 |
"}" |
|
54 |
}; |
|
55 |
return sts; |
|
56 |
} |
|
57 |
||
58 |
static String[] getVersion(int version) { |
|
59 |
String[] sts = { |
|
60 |
"package version;", |
|
61 |
"public class Version {", |
|
62 |
" public int getVersion(){ return " + version + "; }", |
|
63 |
"}" |
|
64 |
}; |
|
65 |
return sts; |
|
66 |
} |
|
67 |
||
68 |
static void writeFile(File file, String... contents) throws Exception { |
|
69 |
if (contents == null) { |
|
70 |
throw new java.lang.RuntimeException("No input for writing to file" + file); |
|
71 |
} |
|
48403
6d4e1efac80a
8165603: runtime/appcds/UseAppCDS.java: failed to clean up files after test when running with agentvm
iklam
parents:
48138
diff
changeset
|
72 |
try ( |
6d4e1efac80a
8165603: runtime/appcds/UseAppCDS.java: failed to clean up files after test when running with agentvm
iklam
parents:
48138
diff
changeset
|
73 |
FileOutputStream fos = new FileOutputStream(file); |
6d4e1efac80a
8165603: runtime/appcds/UseAppCDS.java: failed to clean up files after test when running with agentvm
iklam
parents:
48138
diff
changeset
|
74 |
PrintStream ps = new PrintStream(fos) |
6d4e1efac80a
8165603: runtime/appcds/UseAppCDS.java: failed to clean up files after test when running with agentvm
iklam
parents:
48138
diff
changeset
|
75 |
) { |
6d4e1efac80a
8165603: runtime/appcds/UseAppCDS.java: failed to clean up files after test when running with agentvm
iklam
parents:
48138
diff
changeset
|
76 |
for (String str : contents) { |
6d4e1efac80a
8165603: runtime/appcds/UseAppCDS.java: failed to clean up files after test when running with agentvm
iklam
parents:
48138
diff
changeset
|
77 |
ps.println(str); |
6d4e1efac80a
8165603: runtime/appcds/UseAppCDS.java: failed to clean up files after test when running with agentvm
iklam
parents:
48138
diff
changeset
|
78 |
} |
48138 | 79 |
} |
80 |
} |
|
81 |
||
82 |
/* version.jar entries and files: |
|
83 |
* META-INF/ |
|
84 |
* META-INF/MANIFEST.MF |
|
85 |
* version/ |
|
86 |
* version/Main.class |
|
87 |
* version/Version.class |
|
88 |
* META-INF/versions/ |
|
89 |
* META-INF/versions/<major-version>/ |
|
90 |
* META-INF/versions/<major-version>/version/ |
|
91 |
* META-INF/versions/<major-version>/version/Version.class |
|
92 |
*/ |
|
93 |
static void createClassFilesAndJar() throws Exception { |
|
94 |
String tempDir = System.getProperty("test.classes"); |
|
95 |
File baseDir = new File(tempDir + File.separator + "base"); |
|
96 |
File vDir = new File(tempDir + File.separator + MAJOR_VERSION_STRING); |
|
97 |
||
98 |
baseDir.mkdirs(); |
|
99 |
vDir.mkdirs(); |
|
100 |
||
101 |
File fileMain = TestCommon.getOutputSourceFile("Main.java"); |
|
102 |
writeFile(fileMain, getMain()); |
|
103 |
||
104 |
File fileVersion = TestCommon.getOutputSourceFile("Version.java"); |
|
105 |
writeFile(fileVersion, getVersion(7)); |
|
106 |
JarBuilder.compile(baseDir.getAbsolutePath(), fileVersion.getAbsolutePath(), "--release", "7"); |
|
107 |
JarBuilder.compile(baseDir.getAbsolutePath(), fileMain.getAbsolutePath(), |
|
108 |
"-cp", baseDir.getAbsolutePath(), "--release", MAJOR_VERSION_STRING); |
|
109 |
||
110 |
String[] meta = { |
|
111 |
"Multi-Release: true", |
|
112 |
"Main-Class: version.Main" |
|
113 |
}; |
|
114 |
File metainf = new File(tempDir, "mf.txt"); |
|
115 |
writeFile(metainf, meta); |
|
116 |
||
117 |
fileVersion = TestCommon.getOutputSourceFile("Version.java"); |
|
118 |
writeFile(fileVersion, getVersion(MAJOR_VERSION)); |
|
119 |
JarBuilder.compile(vDir.getAbsolutePath(), fileVersion.getAbsolutePath(), "--release", MAJOR_VERSION_STRING); |
|
120 |
||
121 |
JarBuilder.build("version", baseDir, metainf.getAbsolutePath(), |
|
122 |
"--release", MAJOR_VERSION_STRING, "-C", vDir.getAbsolutePath(), "."); |
|
123 |
||
124 |
// the following jar file is for testing case-insensitive "Multi-Release" |
|
125 |
// attibute name |
|
126 |
String[] meta2 = { |
|
127 |
"multi-Release: true", |
|
128 |
"Main-Class: version.Main" |
|
129 |
}; |
|
130 |
metainf = new File(tempDir, "mf2.txt"); |
|
131 |
writeFile(metainf, meta2); |
|
132 |
JarBuilder.build("version2", baseDir, metainf.getAbsolutePath(), |
|
133 |
"--release", MAJOR_VERSION_STRING, "-C", vDir.getAbsolutePath(), "."); |
|
134 |
} |
|
135 |
||
136 |
static void checkExecOutput(OutputAnalyzer output, String expectedOutput) throws Exception { |
|
137 |
try { |
|
138 |
TestCommon.checkExec(output, expectedOutput); |
|
139 |
} catch (java.lang.RuntimeException re) { |
|
140 |
String cause = re.getMessage(); |
|
141 |
if (!expectedOutput.equals(cause)) { |
|
142 |
throw re; |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
146 |
||
147 |
public static void main(String... args) throws Exception { |
|
148 |
// create version.jar which contains Main.class and Version.class. |
|
149 |
// Version.class has two versions: 8 and the current version. |
|
150 |
createClassFilesAndJar(); |
|
151 |
||
152 |
String mainClass = "version.Main"; |
|
153 |
String loadInfo = "[class,load] version.Version source: shared objects file"; |
|
154 |
String appClasses[] = {"version/Main", "version/Version"}; |
|
155 |
String appJar = TestCommon.getTestJar("version.jar"); |
|
156 |
String appJar2 = TestCommon.getTestJar("version2.jar"); |
|
157 |
String enableMultiRelease = "-Djdk.util.jar.enableMultiRelease=true"; |
|
158 |
String jarVersion = null; |
|
159 |
String expectedOutput = null; |
|
160 |
||
161 |
// 1. default to highest version |
|
162 |
// if META-INF/versions exists, no other commandline options like -Djdk.util.jar.version and |
|
163 |
// -Djdk.util.jar.enableMultiRelease passed to vm |
|
164 |
OutputAnalyzer output = TestCommon.dump(appJar, appClasses); |
|
165 |
output.shouldContain("Loading classes to share: done."); |
|
166 |
output.shouldHaveExitValue(0); |
|
167 |
||
51325
52fed262f009
8208704: runtime/appcds/MultiReleaseJars.java timed out often in hs-tier7 testing
ccheung
parents:
50166
diff
changeset
|
168 |
output = TestCommon.exec(appJar, mainClass); |
48138 | 169 |
checkExecOutput(output, "I am running on version " + MAJOR_VERSION_STRING); |
170 |
||
171 |
// 2. Test versions 7 and the current major version. |
|
172 |
// -Djdk.util.jar.enableMultiRelease=true (or force), default is true. |
|
173 |
// a) -Djdk.util.jar.version=7 does not exist in jar. |
|
174 |
// It will fallback to the root version which is also 7 in this test. |
|
175 |
// b) -Djdk.util.jar.version=MAJOR_VERSION exists in the jar. |
|
176 |
for (int i : new int[] {7, MAJOR_VERSION}) { |
|
177 |
jarVersion = "-Djdk.util.jar.version=" + i; |
|
178 |
expectedOutput = "I am running on version " + i; |
|
179 |
output = TestCommon.dump(appJar, appClasses, enableMultiRelease, jarVersion); |
|
180 |
output.shouldContain("Loading classes to share: done."); |
|
181 |
output.shouldHaveExitValue(0); |
|
182 |
||
51325
52fed262f009
8208704: runtime/appcds/MultiReleaseJars.java timed out often in hs-tier7 testing
ccheung
parents:
50166
diff
changeset
|
183 |
output = TestCommon.exec(appJar, mainClass); |
48138 | 184 |
checkExecOutput(output, expectedOutput); |
185 |
} |
|
186 |
||
187 |
// 3. For unsupported version, 5 and current major version + 1, the multiversion |
|
188 |
// will be turned off, so it will use the default (root) version. |
|
189 |
for (int i : new int[] {5, MAJOR_VERSION + 1}) { |
|
190 |
jarVersion = "-Djdk.util.jar.version=" + i; |
|
191 |
output = TestCommon.dump(appJar, appClasses, enableMultiRelease, jarVersion); |
|
192 |
output.shouldHaveExitValue(0); |
|
193 |
// With the fix for 8172218, multi-release jar is being handled in |
|
194 |
// jdk corelib which doesn't emit the following warning message. |
|
195 |
//output.shouldContain("JDK" + i + " is not supported in multiple version jars"); |
|
196 |
||
51325
52fed262f009
8208704: runtime/appcds/MultiReleaseJars.java timed out often in hs-tier7 testing
ccheung
parents:
50166
diff
changeset
|
197 |
output = TestCommon.exec(appJar, mainClass); |
48138 | 198 |
if (i == 5) |
199 |
checkExecOutput(output, "I am running on version 7"); |
|
200 |
else |
|
201 |
checkExecOutput(output, "I am running on version " + MAJOR_VERSION_STRING); |
|
202 |
} |
|
203 |
||
204 |
// 4. If explicitly disabled from command line for multiversion jar, it will use default |
|
205 |
// version at root regardless multiversion versions exists. |
|
206 |
// -Djdk.util.jar.enableMultiRelease=false (not 'true' or 'force') |
|
207 |
for (int i = 6; i < MAJOR_VERSION + 1; i++) { |
|
208 |
jarVersion = "-Djdk.util.jar.version=" + i; |
|
209 |
output = TestCommon.dump(appJar, appClasses, "-Djdk.util.jar.enableMultiRelease=false", jarVersion); |
|
210 |
output.shouldHaveExitValue(0); |
|
211 |
||
51325
52fed262f009
8208704: runtime/appcds/MultiReleaseJars.java timed out often in hs-tier7 testing
ccheung
parents:
50166
diff
changeset
|
212 |
output = TestCommon.exec(appJar, mainClass); |
48138 | 213 |
expectedOutput = "I am running on version 7"; |
214 |
checkExecOutput(output, expectedOutput); |
|
215 |
} |
|
216 |
||
217 |
// 5. Sanity test with -Xbootclasspath/a |
|
218 |
// AppCDS behaves the same as the non-AppCDS case. A multi-release |
|
219 |
// jar file in the -Xbootclasspath/a will be ignored. |
|
220 |
output = TestCommon.dump(appJar, appClasses, "-Xbootclasspath/a:" + appJar, enableMultiRelease, jarVersion); |
|
221 |
output.shouldContain("Loading classes to share: done."); |
|
222 |
output.shouldHaveExitValue(0); |
|
223 |
||
51325
52fed262f009
8208704: runtime/appcds/MultiReleaseJars.java timed out often in hs-tier7 testing
ccheung
parents:
50166
diff
changeset
|
224 |
output = TestCommon.exec(appJar, "-Xbootclasspath/a:" + appJar, mainClass); |
48138 | 225 |
checkExecOutput(output, "I am running on version 7"); |
226 |
||
227 |
// 6. Sanity test case-insensitive "Multi-Release" attribute name |
|
228 |
output = TestCommon.dump(appJar2, appClasses); |
|
229 |
output.shouldContain("Loading classes to share: done."); |
|
230 |
output.shouldHaveExitValue(0); |
|
231 |
||
51325
52fed262f009
8208704: runtime/appcds/MultiReleaseJars.java timed out often in hs-tier7 testing
ccheung
parents:
50166
diff
changeset
|
232 |
output = TestCommon.exec(appJar2, mainClass); |
48138 | 233 |
checkExecOutput(output, "I am running on version " + MAJOR_VERSION_STRING); |
234 |
} |
|
235 |
} |