Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/compatibility/Compatibility.java
38854 views
1
/*
2
* Copyright (c) 2017, 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
* @test
26
* @summary This test is used to check the interop compatibility on JSSE among
27
* different JDK releases.
28
* Note that, this is a manual test. For more details about the test and
29
* its usages, please look through README.
30
*
31
* @library /test/lib ../TLSCommon
32
* @compile -source 1.6 -target 1.6 JdkUtils.java Server.java Client.java
33
* @run main/manual Compatibility
34
*/
35
36
import java.io.File;
37
import java.io.FileOutputStream;
38
import java.io.FileWriter;
39
import java.io.IOException;
40
import java.io.PrintStream;
41
import java.nio.file.Files;
42
import java.nio.file.Paths;
43
import java.util.ArrayList;
44
import java.util.LinkedHashMap;
45
import java.util.LinkedHashSet;
46
import java.util.List;
47
import java.util.Map;
48
import java.util.Set;
49
import java.util.concurrent.ExecutorService;
50
import java.util.concurrent.Executors;
51
import java.util.concurrent.Future;
52
import java.util.concurrent.TimeUnit;
53
import java.util.stream.Collectors;
54
import java.util.stream.Stream;
55
56
import jdk.test.lib.process.OutputAnalyzer;
57
58
public class Compatibility {
59
60
protected List<UseCase> getUseCases() {
61
return UseCase.getAllUseCases();
62
}
63
64
protected Set<JdkInfo> getJdkInfos() {
65
return jdkInfoList();
66
}
67
68
protected List<TestCase> runTest() throws Exception {
69
Set<JdkInfo> jdkInfos = getJdkInfos();
70
71
List<TestCase> testCases = new ArrayList<>();
72
ExecutorService executor = Executors.newCachedThreadPool();
73
PrintStream origStdOut = System.out;
74
PrintStream origStdErr = System.err;
75
76
boolean debug = Boolean.getBoolean("debug");
77
78
String securityPropertiesFile = System.getProperty(
79
"test.security.properties",
80
System.getProperty("test.src") + "/java.security");
81
System.out.println("security properties: " + securityPropertiesFile);
82
83
// If true, server and client CANNOT be a same JDK
84
boolean disallowSameEndpoint = Boolean.getBoolean("disallowSameEndpoint");
85
System.out.println("disallowSameEndpoint: " + disallowSameEndpoint);
86
87
try (PrintStream printStream = new PrintStream(
88
new FileOutputStream(Utils.TEST_LOG, true))) {
89
System.setOut(printStream);
90
System.setErr(printStream);
91
92
System.out.println(Utils.startHtml());
93
System.out.println(Utils.startPre());
94
95
for (UseCase useCase : getUseCases()) {
96
for (JdkInfo serverJdk : jdkInfos) {
97
Map<String, String> props = new LinkedHashMap<>();
98
if (debug) {
99
props.put("javax.net.debug", "all");
100
}
101
props.put("java.security.properties", securityPropertiesFile);
102
103
props.put(Utils.PROP_PROTOCOL, useCase.protocol.name);
104
props.put(Utils.PROP_CIPHER_SUITE, useCase.cipherSuite.name());
105
props.put(Utils.PROP_CLIENT_AUTH, String.valueOf(useCase.clientAuth));
106
if (useCase.appProtocol != UseCase.AppProtocol.NONE) {
107
props.put(Utils.PROP_APP_PROTOCOLS,
108
Utils.join(Utils.VALUE_DELIMITER,
109
useCase.appProtocol.appProtocols));
110
props.put(Utils.PROP_NEGO_APP_PROTOCOL,
111
useCase.appProtocol.negoAppProtocol);
112
}
113
props.put(Utils.PROP_SERVER_JDK, serverJdk.version);
114
115
props.put(Utils.PROP_SUPPORTS_SNI_ON_SERVER,
116
serverJdk.supportsSNI + "");
117
props.put(Utils.PROP_SUPPORTS_ALPN_ON_SERVER,
118
serverJdk.supportsALPN + "");
119
120
for (JdkInfo clientJdk : jdkInfos) {
121
if (disallowSameEndpoint && clientJdk == serverJdk) {
122
continue;
123
}
124
125
TestCase testCase = new TestCase(serverJdk, clientJdk,
126
useCase);
127
System.out.println(Utils.anchorName(testCase.toString(),
128
"===== Case start ====="));
129
System.out.println(testCase.toString());
130
131
props.put(Utils.PROP_NEGATIVE_CASE_ON_SERVER,
132
testCase.negativeCaseOnServer + "");
133
props.put(Utils.PROP_NEGATIVE_CASE_ON_CLIENT,
134
testCase.negativeCaseOnClient + "");
135
136
Future<OutputAnalyzer> serverFuture = executor.submit(() -> {
137
return runServer(serverJdk.jdkPath, props);
138
});
139
int port = waitForServerStarted();
140
System.out.println("port=" + port);
141
142
props.put(Utils.PROP_PORT, port + "");
143
144
props.put(Utils.PROP_CLIENT_JDK, clientJdk.version);
145
146
props.put(Utils.PROP_SUPPORTS_SNI_ON_CLIENT,
147
clientJdk.supportsSNI + "");
148
props.put(Utils.PROP_SUPPORTS_ALPN_ON_CLIENT,
149
clientJdk.supportsALPN + "");
150
if (useCase.serverName != UseCase.ServerName.NONE) {
151
props.put(Utils.PROP_SERVER_NAME,
152
useCase.serverName.name);
153
}
154
155
Status clientStatus = null;
156
if (port != -1) {
157
String clientOutput = runClient(clientJdk.jdkPath,
158
props).getOutput();
159
clientStatus = getStatus(clientOutput);
160
}
161
162
String serverOutput = serverFuture.get().getOutput();
163
Status serverStatus = getStatus(serverOutput);
164
testCase.setStatus(caseStatus(serverStatus, clientStatus));
165
testCases.add(testCase);
166
System.out.printf(
167
"ServerStatus=%s, ClientStatus=%s, CaseStatus=%s%n",
168
serverStatus, clientStatus, testCase.getStatus());
169
170
System.out.println("===== Case end =====");
171
}
172
}
173
}
174
175
System.out.println(Utils.endPre());
176
System.out.println(Utils.endHtml());
177
}
178
System.setOut(origStdOut);
179
System.setErr(origStdErr);
180
executor.shutdown();
181
182
return testCases;
183
}
184
185
// Generates the test result report.
186
protected boolean generateReport(List<TestCase> testCases)
187
throws IOException {
188
boolean failed = false;
189
StringBuilder report = new StringBuilder();
190
report.append(Utils.startHtml());
191
report.append(Utils.tableStyle());
192
report.append(Utils.startTable());
193
report.append(Utils.row(
194
"No.",
195
"ServerJDK",
196
"ClientJDK",
197
"Protocol",
198
"CipherSuite",
199
"ClientAuth",
200
"SNI",
201
"ALPN",
202
"Status"));
203
for (int i = 0, size = testCases.size(); i < size; i++) {
204
TestCase testCase = testCases.get(i);
205
206
report.append(Utils.row(
207
Utils.anchorLink(
208
Utils.TEST_LOG,
209
testCase.toString(),
210
i + ""),
211
testCase.serverJdk.version,
212
testCase.clientJdk.version,
213
testCase.useCase.protocol.name,
214
testCase.useCase.cipherSuite,
215
Utils.boolToStr(
216
testCase.useCase.clientAuth),
217
Utils.boolToStr(
218
testCase.useCase.serverName == UseCase.ServerName.EXAMPLE),
219
Utils.boolToStr(
220
testCase.useCase.appProtocol == UseCase.AppProtocol.EXAMPLE),
221
testCase.getStatus()));
222
failed = failed
223
|| testCase.getStatus() == Status.FAIL
224
|| testCase.getStatus() == Status.UNEXPECTED_SUCCESS;
225
}
226
report.append(Utils.endTable());
227
report.append(Utils.endHtml());
228
229
generateFile("report.html", report.toString());
230
return failed;
231
}
232
233
protected void run() throws Exception {
234
System.out.println("Test start");
235
List<TestCase> testCases= runTest();
236
System.out.println("Test end");
237
238
boolean failed = generateReport(testCases);
239
System.out.println("Report was generated.");
240
241
if (failed) {
242
throw new RuntimeException("At least one case failed. "
243
+ "Please check logs for more details.");
244
}
245
}
246
247
public static void main(String[] args) throws Throwable {
248
new Compatibility().run();;
249
}
250
251
private static Status getStatus(String log) {
252
if (log.contains(Status.UNEXPECTED_SUCCESS.name())) {
253
return Status.UNEXPECTED_SUCCESS;
254
} else if (log.contains(Status.SUCCESS.name())) {
255
return Status.SUCCESS;
256
} else if (log.contains(Status.EXPECTED_FAIL.name())) {
257
return Status.EXPECTED_FAIL;
258
} else if (log.contains(Status.TIMEOUT.name())) {
259
return Status.TIMEOUT;
260
} else {
261
return Status.FAIL;
262
}
263
}
264
265
private static Status caseStatus(Status serverStatus, Status clientStatus) {
266
if (clientStatus == null || clientStatus == Status.TIMEOUT) {
267
return serverStatus == Status.EXPECTED_FAIL
268
? Status.EXPECTED_FAIL
269
: Status.FAIL;
270
} else if (serverStatus == Status.TIMEOUT) {
271
return clientStatus == Status.EXPECTED_FAIL
272
? Status.EXPECTED_FAIL
273
: Status.FAIL;
274
} else {
275
return serverStatus == clientStatus
276
? serverStatus
277
: Status.FAIL;
278
}
279
}
280
281
// Retrieves JDK info from the file which is specified by jdkListFile.
282
// And the current testing JDK, which is specified by test.jdk, always be used.
283
private static Set<JdkInfo> jdkInfoList() {
284
List<String> jdkList = jdkList();
285
jdkList.add(System.getProperty("test.jdk"));
286
287
Set<JdkInfo> jdkInfoList = new LinkedHashSet<>();
288
for (String jdkPath : jdkList) {
289
JdkInfo jdkInfo = new JdkInfo(jdkPath);
290
// JDK version must be unique.
291
if (!jdkInfoList.add(jdkInfo)) {
292
System.out.println("The JDK version is duplicate: " + jdkPath);
293
}
294
}
295
return jdkInfoList;
296
}
297
298
private static List<String> jdkList() {
299
String listFile = System.getProperty("jdkListFile");
300
System.out.println("jdk list file: " + listFile);
301
if (listFile != null && Files.exists(Paths.get(listFile))) {
302
try (Stream<String> lines = Files.lines(Paths.get(listFile))) {
303
return lines.filter(line -> {
304
return !line.trim().isEmpty();
305
}).collect(Collectors.toList());
306
} catch (IOException e) {
307
throw new RuntimeException("Cannot get jdk list", e);
308
}
309
} else {
310
return new ArrayList<>();
311
}
312
}
313
314
// Checks if server is already launched, and returns server port.
315
private static int waitForServerStarted()
316
throws IOException, InterruptedException {
317
System.out.print("Waiting for server");
318
long deadline = System.currentTimeMillis() + Utils.TIMEOUT;
319
int port;
320
while ((port = getServerPort()) == -1
321
&& System.currentTimeMillis() < deadline) {
322
System.out.print(".");
323
TimeUnit.SECONDS.sleep(1);
324
}
325
System.out.println();
326
327
return port;
328
}
329
330
// Retrieves the latest server port from port.log.
331
private static int getServerPort() throws IOException {
332
if (!Files.exists(Paths.get(Utils.PORT_LOG))) {
333
return -1;
334
}
335
336
try (Stream<String> lines = Files.lines(Paths.get(Utils.PORT_LOG))) {
337
return Integer.valueOf(lines.findFirst().get());
338
}
339
}
340
341
private static OutputAnalyzer runServer(String jdkPath,
342
Map<String, String> props) {
343
return ProcessUtils.java(jdkPath, props, Server.class);
344
}
345
346
private static OutputAnalyzer runClient(String jdkPath,
347
Map<String, String> props) {
348
return ProcessUtils.java(jdkPath, props, Client.class);
349
}
350
351
private static void generateFile(String path, String content)
352
throws IOException {
353
try(FileWriter writer = new FileWriter(new File(path))) {
354
writer.write(content);
355
}
356
}
357
}
358
359