8348309: MultiNST tests need more debugging and timing

Reviewed-by: hchao, mullan
This commit is contained in:
Anthony Scarpino 2025-03-07 17:14:03 +00:00
parent 7c22b814d6
commit 5cd4fe6376
5 changed files with 56 additions and 49 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,10 +31,7 @@ import java.security.cert.PKIXBuilderParameters;
import java.security.cert.X509CertSelector;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
/**
* This is a base setup for creating a server and clients. All clients will
@ -84,14 +81,16 @@ abstract public class TLSBase {
byte[] read(SSLSocket sock) throws Exception {
BufferedInputStream is = new BufferedInputStream(sock.getInputStream());
byte[] b = is.readNBytes(5);
System.err.println("(read) " + Thread.currentThread().getName() + ": " + new String(b));
System.err.println("(read) " + Thread.currentThread().getName() + ": " +
new String(b));
return b;
}
// Base write operation
public void write(SSLSocket sock, byte[] data) throws Exception {
sock.getOutputStream().write(data);
System.err.println("(write)" + Thread.currentThread().getName() + ": " + new String(data));
System.err.println("(write)" + Thread.currentThread().getName() + ": " +
new String(data));
}
private static KeyManager[] getKeyManager(boolean empty) throws Exception {
@ -148,14 +147,9 @@ abstract public class TLSBase {
// Clients sockets are kept in a hash table with the port as the key.
ConcurrentHashMap<Integer, SSLSocket> clientMap =
new ConcurrentHashMap<>();
Thread t;
List<Exception> exceptionList = new ArrayList<>();
ExecutorService threadPool = Executors.newFixedThreadPool(1,
r -> {
Thread t = Executors.defaultThreadFactory().newThread(r);
return t;
});
ExecutorService threadPool = Executors.newFixedThreadPool(1);
CountDownLatch serverLatch = new CountDownLatch(1);
Server(ServerBuilder builder) {
super();
name = "server";
@ -168,27 +162,28 @@ abstract public class TLSBase {
ssock.setReuseAddress(true);
ssock.setNeedClientAuth(builder.clientauth);
serverPort = ssock.getLocalPort();
System.out.println("Server Port: " + serverPort);
System.err.println("Server Port: " + serverPort);
} catch (Exception e) {
System.err.println("Failure during server initialization");
e.printStackTrace();
}
// Thread to allow multiple clients to connect
t = new Thread(() -> {
new Thread(() -> {
try {
while (true) {
System.err.println("Server starting to accept");
serverLatch.countDown();
do {
SSLSocket sock = (SSLSocket)ssock.accept();
threadPool.submit(new ServerThread(sock));
}
} while (true);
} catch (Exception ex) {
System.err.println("Server Down");
ex.printStackTrace();
} finally {
threadPool.close();
}
});
t.start();
}).start();
}
class ServerThread extends Thread {
@ -196,7 +191,8 @@ abstract public class TLSBase {
ServerThread(SSLSocket s) {
this.sock = s;
System.err.println("ServerThread("+sock.getPort()+")");
System.err.println("(Server) client connection on port " +
sock.getPort());
clientMap.put(sock.getPort(), sock);
}
@ -204,7 +200,7 @@ abstract public class TLSBase {
try {
write(sock, read(sock));
} catch (Exception e) {
System.out.println("Caught " + e.getMessage());
System.err.println("Caught " + e.getMessage());
e.printStackTrace();
exceptionList.add(e);
}
@ -289,7 +285,8 @@ abstract public class TLSBase {
this.tm = tm;
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(TLSBase.getKeyManager(km), TLSBase.getTrustManager(tm), null);
sslContext.init(TLSBase.getKeyManager(km),
TLSBase.getTrustManager(tm), null);
socket = createSocket();
} catch (Exception ex) {
ex.printStackTrace();
@ -312,9 +309,12 @@ abstract public class TLSBase {
public SSLSocket connect() {
try {
socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), serverPort));
System.err.println("Client (" + Thread.currentThread().getName() + ") connected using port " +
socket.getLocalPort() + " to " + socket.getPort());
socket.connect(new InetSocketAddress(
InetAddress.getLoopbackAddress(), serverPort));
System.err.println("Client (" +
Thread.currentThread().getName() +
") connected using port " + socket.getLocalPort() + " to " +
socket.getPort());
writeRead();
} catch (Exception ex) {
ex.printStackTrace();

View File

@ -81,7 +81,6 @@ public class MultiNSTClient {
Utils.addTestJavaOpts("MultiNSTClient", "p"));
OutputAnalyzer output = ProcessTools.executeProcess(pb);
System.out.println("I'm here");
boolean pass = true;
try {
List<String> list = output.stderrShouldContain("MultiNST PSK").
@ -99,10 +98,12 @@ public class MultiNSTClient {
for (int i = 0; i < 2; i++) {
String svr = serverPSK.getFirst();
String cli = clientPSK.getFirst();
if (svr.regionMatches(svr.length() - 16, cli, cli.length() - 16, 16)) {
if (svr.regionMatches(svr.length() - 16, cli,
cli.length() - 16, 16)) {
System.out.println("entry " + (i + 1) + " match.");
} else {
System.out.println("entry " + (i + 1) + " server and client PSK didn't match:");
System.out.println("entry " + (i + 1) +
" server and client PSK didn't match:");
System.out.println(" server: " + svr);
System.out.println(" client: " + cli);
pass = false;
@ -127,8 +128,8 @@ public class MultiNSTClient {
}
TLSBase.Server server = new TLSBase.Server();
System.out.println("------ Start connection");
server.serverLatch.await();
System.out.println("------ Server ready, starting original client.");
TLSBase.Client initial = new TLSBase.Client();
SSLSession initialSession = initial.connect().getSession();
System.out.println("id = " + hex.formatHex(initialSession.getId()));

View File

@ -76,8 +76,8 @@ public class MultiNSTNoSessionCreation {
}
TLSBase.Server server = new TLSBase.Server();
System.out.println("------ Initial connection");
server.serverLatch.await();
System.out.println("------ Server ready, starting initial client.");
TLSBase.Client initial = new TLSBase.Client();
initial.connect();
System.out.println(

View File

@ -73,7 +73,7 @@ public class MultiNSTParallel {
public void run() {
String name = Thread.currentThread().getName();
SSLSession r;
System.err.println("waiting " + Thread.currentThread().getName());
System.err.println(name + " is ready");
try {
wait.await();
r = new TLSBase.Client(client).connect().getSession();
@ -84,6 +84,7 @@ public class MultiNSTParallel {
sb.append("(").append(name).append(") id = ");
sb.append(hex.formatHex(r.getId()));
sb.append("\n(").append(name).append(") session = ").append(r);
System.err.println(sb);
if (!client.getSession().toString().equalsIgnoreCase(r.toString())) {
throw new RuntimeException("(" + name +
") Resumed session did not match");
@ -133,7 +134,14 @@ public class MultiNSTParallel {
serverPSK.stream().forEach(s -> System.out.println("\t" + s));
System.out.println("found client: " + clientPSK.size());
clientPSK.stream().forEach(s -> System.out.println("\t" + s));
if (list.size() == 0 || serverPSK.size() == 0) {
throw new Exception("Error setting up test. No server " +
"PSKs found in debug log.");
}
if (clientPSK.size() == 0) {
throw new Exception("Error setting up test. No " +
"client PSKs found in debug log.");
}
// Must search all results as order is not guaranteed.
clientPSK.stream().forEach(cli -> {
for (int i = 0; i < serverPSK.size(); i++) {
@ -171,21 +179,20 @@ public class MultiNSTParallel {
System.getProperty("jdk.tls.server.newSessionTicketCount"));
TLSBase.Server server = new TLSBase.Server();
System.out.println("------ Start connection");
TLSBase.Client initial = new TLSBase.Client();
SSLSession initialSession = initial.getSession();
server.serverLatch.await();
System.out.println("------ Server ready, starting initial client.");
TLSBase.Client initialClient = new TLSBase.Client();
SSLSession initialSession = initialClient.connect().getSession();
System.out.println("id = " + hex.formatHex(initialSession.getId()));
System.out.println("session = " + initialSession);
System.out.println("------ getNewSession from original client");
System.out.println("------ Initial client context ready.");
ArrayList<Thread> slist = new ArrayList<>(ticketCount);
System.out.println("tx " + ticketCount);
System.out.println("Client count = " + ticketCount);
for (int i = 0; ticketCount > i; i++) {
Thread t = new ClientThread(initial);
t.setName("Iteration " + i);
Thread t = new ClientThread(initialClient);
t.setName("client " + i);
slist.add(t);
t.start();
}
@ -197,7 +204,7 @@ public class MultiNSTParallel {
}
System.out.println("------ Closing connections");
initial.close();
initialClient.close();
server.close();
System.out.println("------ End");
System.exit(0);

View File

@ -64,8 +64,7 @@ public class MultiNSTSequence {
" -Dtest.src=" + System.getProperty("test.src") +
" -Dtest.jdk=" + System.getProperty("test.jdk") +
" -Dtest.root=" + System.getProperty("test.root") +
" -Djavax.net.debug=ssl,handshake " + params
);
" -Djavax.net.debug=ssl,handshake " + params);
System.out.println("test.java.opts: " +
System.getProperty("test.java.opts"));
@ -115,8 +114,8 @@ public class MultiNSTSequence {
}
TLSBase.Server server = new TLSBase.Server();
System.out.println("------ Initial connection");
server.serverLatch.await();
System.out.println("------ Server ready, starting initial client.");
TLSBase.Client initial = new TLSBase.Client();
SSLSession initialSession = initial.connect().getSession();