diff --git a/test/jdk/javax/net/ssl/compatibility/Client.java b/test/jdk/javax/net/ssl/compatibility/Client.java index adf6b4b657f..8109f6aa132 100644 --- a/test/jdk/javax/net/ssl/compatibility/Client.java +++ b/test/jdk/javax/net/ssl/compatibility/Client.java @@ -118,15 +118,15 @@ public class Client { String serverName = System.getProperty(Utils.PROP_SERVER_NAME); String appProtocols = System.getProperty(Utils.PROP_APP_PROTOCOLS); boolean supportsSNIOnServer - = Utils.getBoolProperty(Utils.PROP_SUPPORTS_SNI_ON_SERVER); + = Boolean.getBoolean(Utils.PROP_SUPPORTS_SNI_ON_SERVER); boolean supportsSNIOnClient - = Utils.getBoolProperty(Utils.PROP_SUPPORTS_SNI_ON_CLIENT); + = Boolean.getBoolean(Utils.PROP_SUPPORTS_SNI_ON_CLIENT); boolean supportsALPNOnServer - = Utils.getBoolProperty(Utils.PROP_SUPPORTS_ALPN_ON_SERVER); + = Boolean.getBoolean(Utils.PROP_SUPPORTS_ALPN_ON_SERVER); boolean supportsALPNOnClient - = Utils.getBoolProperty(Utils.PROP_SUPPORTS_ALPN_ON_CLIENT); + = Boolean.getBoolean(Utils.PROP_SUPPORTS_ALPN_ON_CLIENT); boolean negativeCase - = Utils.getBoolProperty(Utils.PROP_NEGATIVE_CASE_ON_CLIENT); + = Boolean.getBoolean(Utils.PROP_NEGATIVE_CASE_ON_CLIENT); System.out.println(Utils.join(Utils.PARAM_DELIMITER, "ClientJDK=" + System.getProperty(Utils.PROP_CLIENT_JDK), "Protocol=" + protocol, diff --git a/test/jdk/javax/net/ssl/compatibility/Compatibility.java b/test/jdk/javax/net/ssl/compatibility/Compatibility.java index 60a256861d5..fe1b3f595e4 100644 --- a/test/jdk/javax/net/ssl/compatibility/Compatibility.java +++ b/test/jdk/javax/net/ssl/compatibility/Compatibility.java @@ -57,20 +57,33 @@ import jdk.test.lib.process.OutputAnalyzer; public class Compatibility { - public static void main(String[] args) throws Throwable { - String javaSecurityFile - = System.getProperty("test.src") + "/java.security"; - boolean debug = Utils.getBoolProperty("debug"); + protected List getUseCases() { + return UseCase.getAllUseCases(); + } - Set jdkInfos = jdkInfoList(); + protected Set getJdkInfos() { + return jdkInfoList(); + } - System.out.println("Test start"); + protected List runTest() throws Exception { + Set jdkInfos = getJdkInfos(); List testCases = new ArrayList<>(); ExecutorService executor = Executors.newCachedThreadPool(); PrintStream origStdOut = System.out; PrintStream origStdErr = System.err; + boolean debug = Boolean.getBoolean("debug"); + + String securityPropertiesFile = System.getProperty( + "test.security.properties", + System.getProperty("test.src") + "/java.security"); + System.out.println("security properties: " + securityPropertiesFile); + + // If true, server and client CANNOT be a same JDK + boolean disallowSameEndpoint = Boolean.getBoolean("disallowSameEndpoint"); + System.out.println("disallowSameEndpoint: " + disallowSameEndpoint); + try (PrintStream printStream = new PrintStream( new FileOutputStream(Utils.TEST_LOG, true))) { System.setOut(printStream); @@ -79,13 +92,13 @@ public class Compatibility { System.out.println(Utils.startHtml()); System.out.println(Utils.startPre()); - for (UseCase useCase : UseCase.getAllUseCases()) { + for (UseCase useCase : getUseCases()) { for (JdkInfo serverJdk : jdkInfos) { Map props = new LinkedHashMap<>(); if (debug) { props.put("javax.net.debug", "all"); } - props.put("java.security.properties", javaSecurityFile); + props.put("java.security.properties", securityPropertiesFile); props.put(Utils.PROP_PROTOCOL, useCase.protocol.name); props.put(Utils.PROP_CIPHER_SUITE, useCase.cipherSuite.name()); @@ -105,6 +118,10 @@ public class Compatibility { serverJdk.supportsALPN + ""); for (JdkInfo clientJdk : jdkInfos) { + if (disallowSameEndpoint && clientJdk == serverJdk) { + continue; + } + TestCase testCase = new TestCase(serverJdk, clientJdk, useCase); System.out.println(Utils.anchorName(testCase.toString(), @@ -162,119 +179,11 @@ public class Compatibility { System.setErr(origStdErr); executor.shutdown(); - System.out.println("Test end"); - System.out.println("Report is being generated..."); - boolean failed = generateReport(testCases); - System.out.println("Report is generated."); - if (failed) { - throw new RuntimeException("At least one case failed. " - + "Please check logs for more details."); - } - } - - private static Status getStatus(String log) { - if (log.contains(Status.UNEXPECTED_SUCCESS.name())) { - return Status.UNEXPECTED_SUCCESS; - } else if (log.contains(Status.SUCCESS.name())) { - return Status.SUCCESS; - } else if (log.contains(Status.EXPECTED_FAIL.name())) { - return Status.EXPECTED_FAIL; - } else if (log.contains(Status.TIMEOUT.name())) { - return Status.TIMEOUT; - } else { - return Status.FAIL; - } - } - - private static Status caseStatus(Status serverStatus, Status clientStatus) { - if (clientStatus == null || clientStatus == Status.TIMEOUT) { - return serverStatus == Status.EXPECTED_FAIL - ? Status.EXPECTED_FAIL - : Status.FAIL; - } else if (serverStatus == Status.TIMEOUT) { - return clientStatus == Status.EXPECTED_FAIL - ? Status.EXPECTED_FAIL - : Status.FAIL; - } else { - return serverStatus == clientStatus - ? serverStatus - : Status.FAIL; - } - } - - // Retrieves JDK info from the file which is specified by jdkListFile. - // If no such file or no JDK is specified by the file, the current testing - // JDK will be used. - private static Set jdkInfoList() throws Throwable { - List jdkList = jdkList("jdkListFile"); - if (jdkList.size() == 0) { - jdkList.add(System.getProperty("test.jdk")); - } - - Set jdkInfoList = new LinkedHashSet<>(); - for (String jdkPath : jdkList) { - JdkInfo jdkInfo = new JdkInfo(jdkPath); - // JDK version must be unique. - if (!jdkInfoList.add(jdkInfo)) { - System.out.println("The JDK version is duplicate: " + jdkPath); - } - } - return jdkInfoList; - } - - private static List jdkList(String listFileProp) throws IOException { - String listFile = System.getProperty(listFileProp); - System.out.println(listFileProp + "=" + listFile); - if (listFile != null && Files.exists(Paths.get(listFile))) { - try (Stream lines = Files.lines(Paths.get(listFile))) { - return lines.filter(line -> { - return !line.trim().isEmpty(); - }).collect(Collectors.toList()); - } - } else { - return new ArrayList<>(); - } - } - - // Checks if server is already launched, and returns server port. - private static int waitForServerStarted() - throws IOException, InterruptedException { - System.out.print("Waiting for server"); - long deadline = System.currentTimeMillis() + Utils.TIMEOUT; - int port; - while ((port = getServerPort()) == -1 - && System.currentTimeMillis() < deadline) { - System.out.print("."); - TimeUnit.SECONDS.sleep(1); - } - System.out.println(); - - return port; - } - - // Retrieves the latest server port from port.log. - private static int getServerPort() throws IOException { - if (!Files.exists(Paths.get(Utils.PORT_LOG))) { - return -1; - } - - try (Stream lines = Files.lines(Paths.get(Utils.PORT_LOG))) { - return Integer.valueOf(lines.findFirst().get()); - } - } - - private static OutputAnalyzer runServer(String jdkPath, - Map props) { - return ProcessUtils.java(jdkPath, props, Server.class); - } - - private static OutputAnalyzer runClient(String jdkPath, - Map props) { - return ProcessUtils.java(jdkPath, props, Client.class); + return testCases; } // Generates the test result report. - private static boolean generateReport(List testCases) + protected boolean generateReport(List testCases) throws IOException { boolean failed = false; StringBuilder report = new StringBuilder(); @@ -321,6 +230,124 @@ public class Compatibility { return failed; } + protected void run() throws Exception { + System.out.println("Test start"); + List testCases= runTest(); + System.out.println("Test end"); + + boolean failed = generateReport(testCases); + System.out.println("Report was generated."); + + if (failed) { + throw new RuntimeException("At least one case failed. " + + "Please check logs for more details."); + } + } + + public static void main(String[] args) throws Throwable { + new Compatibility().run();; + } + + private static Status getStatus(String log) { + if (log.contains(Status.UNEXPECTED_SUCCESS.name())) { + return Status.UNEXPECTED_SUCCESS; + } else if (log.contains(Status.SUCCESS.name())) { + return Status.SUCCESS; + } else if (log.contains(Status.EXPECTED_FAIL.name())) { + return Status.EXPECTED_FAIL; + } else if (log.contains(Status.TIMEOUT.name())) { + return Status.TIMEOUT; + } else { + return Status.FAIL; + } + } + + private static Status caseStatus(Status serverStatus, Status clientStatus) { + if (clientStatus == null || clientStatus == Status.TIMEOUT) { + return serverStatus == Status.EXPECTED_FAIL + ? Status.EXPECTED_FAIL + : Status.FAIL; + } else if (serverStatus == Status.TIMEOUT) { + return clientStatus == Status.EXPECTED_FAIL + ? Status.EXPECTED_FAIL + : Status.FAIL; + } else { + return serverStatus == clientStatus + ? serverStatus + : Status.FAIL; + } + } + + // Retrieves JDK info from the file which is specified by jdkListFile. + // And the current testing JDK, which is specified by test.jdk, always be used. + private static Set jdkInfoList() { + List jdkList = jdkList(); + jdkList.add(System.getProperty("test.jdk")); + + Set jdkInfoList = new LinkedHashSet<>(); + for (String jdkPath : jdkList) { + JdkInfo jdkInfo = new JdkInfo(jdkPath); + // JDK version must be unique. + if (!jdkInfoList.add(jdkInfo)) { + System.out.println("The JDK version is duplicate: " + jdkPath); + } + } + return jdkInfoList; + } + + private static List jdkList() { + String listFile = System.getProperty("jdkListFile"); + System.out.println("jdk list file: " + listFile); + if (listFile != null && Files.exists(Paths.get(listFile))) { + try (Stream lines = Files.lines(Paths.get(listFile))) { + return lines.filter(line -> { + return !line.trim().isEmpty(); + }).collect(Collectors.toList()); + } catch (IOException e) { + throw new RuntimeException("Cannot get jdk list", e); + } + } else { + return new ArrayList<>(); + } + } + + // Checks if server is already launched, and returns server port. + private static int waitForServerStarted() + throws IOException, InterruptedException { + System.out.print("Waiting for server"); + long deadline = System.currentTimeMillis() + Utils.TIMEOUT; + int port; + while ((port = getServerPort()) == -1 + && System.currentTimeMillis() < deadline) { + System.out.print("."); + TimeUnit.SECONDS.sleep(1); + } + System.out.println(); + + return port; + } + + // Retrieves the latest server port from port.log. + private static int getServerPort() throws IOException { + if (!Files.exists(Paths.get(Utils.PORT_LOG))) { + return -1; + } + + try (Stream lines = Files.lines(Paths.get(Utils.PORT_LOG))) { + return Integer.valueOf(lines.findFirst().get()); + } + } + + private static OutputAnalyzer runServer(String jdkPath, + Map props) { + return ProcessUtils.java(jdkPath, props, Server.class); + } + + private static OutputAnalyzer runClient(String jdkPath, + Map props) { + return ProcessUtils.java(jdkPath, props, Client.class); + } + private static void generateFile(String path, String content) throws IOException { try(FileWriter writer = new FileWriter(new File(path))) { diff --git a/test/jdk/javax/net/ssl/compatibility/JdkInfo.java b/test/jdk/javax/net/ssl/compatibility/JdkInfo.java index 87ba0f90d9f..1b6fa1e7bcc 100644 --- a/test/jdk/javax/net/ssl/compatibility/JdkInfo.java +++ b/test/jdk/javax/net/ssl/compatibility/JdkInfo.java @@ -36,7 +36,7 @@ public class JdkInfo { public final boolean supportsSNI; public final boolean supportsALPN; - public JdkInfo(String jdkPath) throws Throwable { + public JdkInfo(String jdkPath) { this.jdkPath = jdkPath; String output = jdkAttributes(jdkPath); @@ -54,7 +54,7 @@ public class JdkInfo { } // Determines the specific attributes for the specified JDK. - private static String jdkAttributes(String jdkPath) throws Throwable { + private static String jdkAttributes(String jdkPath) { return ProcessUtils.java(jdkPath, null, JdkUtils.class).getOutput(); } diff --git a/test/jdk/javax/net/ssl/compatibility/Server.java b/test/jdk/javax/net/ssl/compatibility/Server.java index 444982ec936..da2820c79aa 100644 --- a/test/jdk/javax/net/ssl/compatibility/Server.java +++ b/test/jdk/javax/net/ssl/compatibility/Server.java @@ -103,12 +103,12 @@ public class Server { String protocol = System.getProperty(Utils.PROP_PROTOCOL); String cipherSuite = System.getProperty(Utils.PROP_CIPHER_SUITE); boolean clientAuth - = Utils.getBoolProperty(Utils.PROP_CLIENT_AUTH); + = Boolean.getBoolean(Utils.PROP_CLIENT_AUTH); String appProtocols = System.getProperty(Utils.PROP_APP_PROTOCOLS); boolean supportsALPN - = Utils.getBoolProperty(Utils.PROP_SUPPORTS_ALPN_ON_SERVER); + = Boolean.getBoolean(Utils.PROP_SUPPORTS_ALPN_ON_SERVER); boolean negativeCase - = Utils.getBoolProperty(Utils.PROP_NEGATIVE_CASE_ON_SERVER); + = Boolean.getBoolean(Utils.PROP_NEGATIVE_CASE_ON_SERVER); System.out.println(Utils.join(Utils.PARAM_DELIMITER, "ServerJDK=" + System.getProperty(Utils.PROP_SERVER_JDK), diff --git a/test/jdk/javax/net/ssl/compatibility/UseCase.java b/test/jdk/javax/net/ssl/compatibility/UseCase.java index ec4f2764d25..7bb06128017 100644 --- a/test/jdk/javax/net/ssl/compatibility/UseCase.java +++ b/test/jdk/javax/net/ssl/compatibility/UseCase.java @@ -30,10 +30,10 @@ import java.util.List; public class UseCase { private static final boolean FULL_CASES - = Utils.getBoolProperty("fullCases"); + = Boolean.getBoolean("fullCases"); public static final boolean FULL_CIPHER_SUITES - = Utils.getBoolProperty("fullCipherSuites"); + = Boolean.getBoolean("fullCipherSuites"); public static final Protocol[] PROTOCOLS = new Protocol[] { Protocol.TLSV1, @@ -129,7 +129,7 @@ public class UseCase { } private static final Object[][] PARAMS = new Object[][] { - FULL_CASES ? PROTOCOLS : PROTOCOLS, + PROTOCOLS, FULL_CASES ? CIPHER_SUITES : MANDATORY_CIPHER_SUITES, FULL_CASES ? new Boolean[] { false, true } : new Boolean[] { true }, FULL_CASES diff --git a/test/jdk/javax/net/ssl/compatibility/Utils.java b/test/jdk/javax/net/ssl/compatibility/Utils.java index 75ba3ba461e..fa12c075ad0 100644 --- a/test/jdk/javax/net/ssl/compatibility/Utils.java +++ b/test/jdk/javax/net/ssl/compatibility/Utils.java @@ -166,10 +166,6 @@ public class Utils { return bool ? "Y" : "N"; } - public static boolean getBoolProperty(String prop) { - return Boolean.valueOf(System.getProperty(prop)); - } - public static Status handleException(Exception exception, boolean negativeCase) { Status status;