8315406: [REDO] serviceability/jdwp/AllModulesCommandTest.java ignores VM flags
Reviewed-by: cjplummer, dcubed
This commit is contained in:
parent
7a08e6bdd6
commit
5cbff24608
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2023, 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
|
||||
@ -72,12 +72,6 @@ public class AllModulesCommandTest implements DebuggeeLauncher.Listener {
|
||||
jdwpLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDebuggeeError(String message) {
|
||||
System.err.println("Debuggee error: '" + message + "'");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
private void doJdwp() throws Exception {
|
||||
try {
|
||||
// Establish JDWP socket connection
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2023, 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
|
||||
@ -22,9 +22,9 @@
|
||||
*/
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
import jdk.test.lib.JDKToolFinder;
|
||||
import jdk.test.lib.JDWP;
|
||||
import static jdk.test.lib.Asserts.assertFalse;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
/**
|
||||
* Launches the debuggee with the necessary JDWP options and handles the output
|
||||
@ -45,21 +45,14 @@ public class DebuggeeLauncher implements StreamHandler.Listener {
|
||||
*/
|
||||
void onDebuggeeSendingCompleted();
|
||||
|
||||
/**
|
||||
* Callback to handle any debuggee error
|
||||
*
|
||||
* @param line line from the debuggee's stderr
|
||||
*/
|
||||
void onDebuggeeError(String line);
|
||||
}
|
||||
|
||||
private int jdwpPort = -1;
|
||||
private static final String CLS_DIR = System.getProperty("test.classes", "").trim();
|
||||
private static final String DEBUGGEE = "AllModulesCommandTestDebuggee";
|
||||
private static final String JDWP_OPT = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0";
|
||||
|
||||
private Process p;
|
||||
private final Listener listener;
|
||||
private StreamHandler inputHandler;
|
||||
private StreamHandler errorHandler;
|
||||
|
||||
/**
|
||||
* @param listener the listener we report the debuggee events to
|
||||
@ -70,36 +63,20 @@ public class DebuggeeLauncher implements StreamHandler.Listener {
|
||||
|
||||
/**
|
||||
* Starts the debuggee with the necessary JDWP options and handles the
|
||||
* debuggee's stdout and stderr outputs
|
||||
* debuggee's stdout output. stderr might contain jvm output, which is just printed to the log.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public void launchDebuggee() throws Throwable {
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(getCommand());
|
||||
ProcessBuilder pb = ProcessTools.createTestJvm(JDWP_OPT, DEBUGGEE);
|
||||
p = pb.start();
|
||||
inputHandler = new StreamHandler(p.getInputStream(), this);
|
||||
errorHandler = new StreamHandler(p.getErrorStream(), this);
|
||||
StreamHandler inputHandler = new StreamHandler(p.getInputStream(), this);
|
||||
StreamHandler errorHandler = new StreamHandler(p.getErrorStream(), l -> System.out.println("[stderr]: " + l));
|
||||
inputHandler.start();
|
||||
errorHandler.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Command to start the debuggee with the JDWP options and using the JDK
|
||||
* under test
|
||||
*
|
||||
* @return the command
|
||||
*/
|
||||
private String[] getCommand() {
|
||||
return new String[]{
|
||||
JDKToolFinder.getTestJDKTool("java"),
|
||||
getJdwpOptions(),
|
||||
"-cp",
|
||||
CLS_DIR,
|
||||
DEBUGGEE
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminates the debuggee
|
||||
*/
|
||||
@ -109,15 +86,6 @@ public class DebuggeeLauncher implements StreamHandler.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debuggee JDWP options
|
||||
*
|
||||
* @return the JDWP options to start the debuggee with
|
||||
*/
|
||||
private static String getJdwpOptions() {
|
||||
return "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets JDWP port debuggee is listening on.
|
||||
*
|
||||
@ -129,16 +97,8 @@ public class DebuggeeLauncher implements StreamHandler.Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStringRead(StreamHandler handler, String line) {
|
||||
if (handler.equals(errorHandler)) {
|
||||
terminateDebuggee();
|
||||
listener.onDebuggeeError(line);
|
||||
} else {
|
||||
processDebuggeeOutput(line);
|
||||
}
|
||||
}
|
||||
|
||||
private void processDebuggeeOutput(String line) {
|
||||
public void onStringRead(String line) {
|
||||
System.out.println("[stdout]: " + line);
|
||||
if (jdwpPort == -1) {
|
||||
JDWP.ListenAddress addr = JDWP.parseListenAddress(line);
|
||||
if (addr != null) {
|
||||
|
@ -37,10 +37,9 @@ public class StreamHandler implements Runnable {
|
||||
public interface Listener {
|
||||
/**
|
||||
* Called when a line has been read from the process output stream
|
||||
* @param handler this StreamHandler
|
||||
* @param s the line
|
||||
*/
|
||||
void onStringRead(StreamHandler handler, String s);
|
||||
void onStringRead(String s);
|
||||
}
|
||||
|
||||
private final ExecutorService executor;
|
||||
@ -71,7 +70,7 @@ public class StreamHandler implements Runnable {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
listener.onStringRead(this, line);
|
||||
listener.onStringRead(line);
|
||||
}
|
||||
} catch (Exception x) {
|
||||
throw new RuntimeException(x);
|
||||
|
Loading…
Reference in New Issue
Block a user