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 |
/* |
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 Test combinations of jigsaw options that affect the use of AppCDS |
|
28 |
* |
|
48469
7312ae4465d6
8193672: [test] Enhance vm.cds property to check for all conditions required to run CDS tests
iklam
parents:
48397
diff
changeset
|
29 |
* @requires vm.cds & !vm.graal.enabled |
48138 | 30 |
* @library /test/lib .. |
57705
7cf02b2c1455
8229267: [TESTBUG] Remove unnecessary @modules dependencies in CDS tests
iklam
parents:
57567
diff
changeset
|
31 |
* @modules jdk.jartool/sun.tools.jar |
48138 | 32 |
* @compile ../test-classes/Hello.java ../test-classes/HelloMore.java |
51990
6003e034cdd8
8209946: [TESTBUG] CDS tests should use "@run driver"
iklam
parents:
49739
diff
changeset
|
33 |
* @run driver JigsawOptionsCombo |
48138 | 34 |
*/ |
35 |
import jdk.test.lib.compiler.InMemoryJavaCompiler; |
|
36 |
import jdk.test.lib.process.OutputAnalyzer; |
|
37 |
import java.util.ArrayList; |
|
38 |
||
39 |
||
40 |
// Remaining WORK: TODO: |
|
41 |
// 1. test with -m initial-module; waiting for changes from Chris will provide |
|
42 |
// utils to build modules |
|
43 |
// 2. Loading classes from Jmod files - waiting on utils |
|
44 |
// 3. Loading classes from exploded module dir" |
|
45 |
||
46 |
public class JigsawOptionsCombo { |
|
47 |
||
48 |
public static void main(String[] args) throws Exception { |
|
49 |
String source = "package javax.naming.spi; " + |
|
50 |
"public class NamingManager { " + |
|
51 |
" static { " + |
|
52 |
" System.out.println(\"I pass!\"); " + |
|
53 |
" } " + |
|
54 |
"}"; |
|
55 |
ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager", |
|
56 |
InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "--patch-module=java.naming"), |
|
57 |
"mods/java.naming"); |
|
58 |
||
59 |
JarBuilder.build("hello", "Hello"); |
|
60 |
JarBuilder.build("hello_more", "HelloMore"); |
|
61 |
||
62 |
(new JigsawOptionsCombo()).runTests(); |
|
63 |
} |
|
64 |
||
65 |
||
66 |
private ArrayList<TestCase> testCaseTable = new ArrayList<TestCase>(); |
|
67 |
||
68 |
public static String infoDuringDump(String option) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
69 |
return "Cannot use the following option when dumping the shared archive: " + option; |
48138 | 70 |
} |
71 |
||
72 |
public void runTests() throws Exception { |
|
73 |
||
74 |
testCaseTable.add(new TestCase( |
|
75 |
"basic: Basic dump and execute, to verify the test plumbing works", |
|
76 |
"", "", 0, |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
77 |
"", "", 0, true) ); |
48138 | 78 |
|
79 |
String bcpArg = "-Xbootclasspath/a:" + |
|
80 |
TestCommon.getTestJar("hello_more.jar"); |
|
81 |
||
82 |
testCaseTable.add(new TestCase( |
|
83 |
"Xbootclasspath/a: is OK for both dump and run time", |
|
84 |
bcpArg, "", 0, |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
85 |
bcpArg, "", 0, true) ); |
48138 | 86 |
|
87 |
testCaseTable.add(new TestCase( |
|
88 |
"module-path-01: --module-path is ignored for dump time", |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
89 |
"--module-path mods", "", 0, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
90 |
null, null, 0, true) ); |
48138 | 91 |
|
92 |
testCaseTable.add(new TestCase( |
|
93 |
"module-path-02: --module-path is ok for run time", |
|
94 |
"", "", 0, |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
95 |
"--module-path mods", "", 0, true) ); |
48138 | 96 |
|
97 |
testCaseTable.add(new TestCase( |
|
98 |
"add-modules-01: --add-modules is ok at dump time", |
|
99 |
"--add-modules java.management", |
|
100 |
"", 0, |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
101 |
null, null, 0, true) ); |
48138 | 102 |
|
103 |
testCaseTable.add(new TestCase( |
|
104 |
"add-modules-02: --add-modules is ok at run time", |
|
105 |
"", "", 0, |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
106 |
"--add-modules java.management", "", 0, true) ); |
48138 | 107 |
|
108 |
testCaseTable.add(new TestCase( |
|
109 |
"limit-modules-01: --limit-modules is ignored at dump time", |
|
110 |
"--limit-modules java.base", |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
111 |
infoDuringDump("--limit-modules"), 1, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
112 |
null, null, 0, true) ); |
48138 | 113 |
|
114 |
testCaseTable.add(new TestCase( |
|
115 |
"limit-modules-02: --limit-modules is ok at run time", |
|
116 |
"", "", 0, |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
117 |
"--limit-modules java.base", "", 0, false) ); |
48138 | 118 |
|
119 |
testCaseTable.add(new TestCase( |
|
120 |
"upgrade-module-path-01: --upgrade-module-path is ignored at dump time", |
|
121 |
"--upgrade-module-path mods", |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
122 |
infoDuringDump("--upgrade-module-path"), 1, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
123 |
null, null, 0, true) ); |
48138 | 124 |
|
125 |
testCaseTable.add(new TestCase( |
|
126 |
"-upgrade-module-path-module-path-02: --upgrade-module-path is ok at run time", |
|
127 |
"", "", 0, |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
128 |
"--upgrade-module-path mods", "", 0, false) ); |
48138 | 129 |
|
130 |
for (TestCase tc : testCaseTable) tc.execute(); |
|
131 |
} |
|
132 |
||
133 |
||
134 |
// class representing a singe test case |
|
135 |
public class TestCase { |
|
136 |
String description; |
|
137 |
String dumpTimeArgs; |
|
138 |
String dumpTimeExpectedOutput; |
|
139 |
int dumpTimeExpectedExitValue; |
|
140 |
String runTimeArgs; |
|
141 |
String runTimeExpectedOutput; |
|
142 |
int runTimeExpectedExitValue; |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
143 |
boolean sharingOn; |
48138 | 144 |
|
145 |
private String appJar = TestCommon.getTestJar("hello.jar"); |
|
146 |
private String appClasses[] = {"Hello"}; |
|
147 |
||
148 |
||
149 |
public TestCase(String description, |
|
150 |
String dumpTimeArgs, String dumpTimeExpectedOutput, int dumpTimeExpectedExitValue, |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
151 |
String runTimeArgs, String runTimeExpectedOutput, int runTimeExpectedExitValue, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
152 |
boolean sharingOn) { |
48138 | 153 |
|
154 |
this.description = description; |
|
155 |
this.dumpTimeArgs = dumpTimeArgs; |
|
156 |
this.dumpTimeExpectedOutput = dumpTimeExpectedOutput; |
|
157 |
this.dumpTimeExpectedExitValue = dumpTimeExpectedExitValue; |
|
158 |
this.runTimeArgs = runTimeArgs; |
|
159 |
this.runTimeExpectedOutput = runTimeExpectedOutput; |
|
160 |
this.runTimeExpectedExitValue = runTimeExpectedExitValue; |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
161 |
this.sharingOn = sharingOn; |
48138 | 162 |
} |
163 |
||
164 |
||
165 |
public void execute() throws Exception { |
|
166 |
System.out.println("Description: " + description); |
|
167 |
||
168 |
// ===== dump step - create the archive |
|
169 |
OutputAnalyzer dumpOutput = TestCommon.dump( |
|
170 |
appJar, appClasses, getDumpOptions()); |
|
171 |
||
172 |
if (dumpTimeExpectedExitValue == 0) { |
|
173 |
TestCommon.checkDump(dumpOutput, dumpTimeExpectedOutput); |
|
174 |
} else { |
|
175 |
dumpOutput.shouldMatch(dumpTimeExpectedOutput); |
|
176 |
dumpOutput.shouldHaveExitValue(dumpTimeExpectedExitValue); |
|
177 |
} |
|
178 |
||
179 |
// ===== exec step - use the archive |
|
180 |
if (runTimeArgs != null) { |
|
181 |
OutputAnalyzer execOutput = TestCommon.exec(appJar, getRunOptions()); |
|
182 |
||
183 |
if (runTimeExpectedExitValue == 0) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
184 |
if (sharingOn) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
185 |
TestCommon.checkExec(execOutput, runTimeExpectedOutput, "Hello World"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
186 |
} else { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
187 |
execOutput.shouldHaveExitValue(0) |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
188 |
.shouldContain(runTimeExpectedOutput) |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
189 |
.shouldContain("Hello World"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48469
diff
changeset
|
190 |
} |
48138 | 191 |
} else { |
192 |
execOutput.shouldMatch(dumpTimeExpectedOutput); |
|
193 |
execOutput.shouldHaveExitValue(dumpTimeExpectedExitValue); |
|
194 |
} |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
||
199 |
// dump command line options can be separated by a space |
|
200 |
private String[] getDumpOptions() { |
|
201 |
return dumpTimeArgs.split(" "); |
|
202 |
} |
|
203 |
||
204 |
||
205 |
// run command line options can be separated by a space |
|
206 |
private String[] getRunOptions() { |
|
207 |
ArrayList<String> result = new ArrayList<>(); |
|
208 |
||
209 |
if (runTimeArgs != "") { |
|
210 |
String splitArgs[] = runTimeArgs.split(" "); |
|
211 |
for (String arg : splitArgs) |
|
212 |
result.add(arg); |
|
213 |
} |
|
214 |
||
215 |
result.add("Hello"); |
|
216 |
return result.toArray(new String[1]); |
|
217 |
} |
|
218 |
} |
|
219 |
} |