Skip to content

Commit

Permalink
8260431: com/sun/jdi/JdbOptions.java failed with "RuntimeException: '…
Browse files Browse the repository at this point in the history
…prop[boo] = >foo<' missing from stdout/stderr"

Reviewed-by: sspitsyn, cjplummer
  • Loading branch information
Alex Menkov committed Feb 11, 2021
1 parent bf47a47 commit 60a2072
Showing 1 changed file with 50 additions and 21 deletions.
71 changes: 50 additions & 21 deletions test/jdk/com/sun/jdi/JdbOptions.java
Expand Up @@ -34,9 +34,17 @@
import lib.jdb.JdbCommand;
import jdk.test.lib.process.OutputAnalyzer;

import java.io.IOException;
import java.io.PrintStream;
import java.lang.management.ManagementFactory;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

class JbdOptionsTarg {
static final String OK_MSG = "JbdOptionsTarg: OK";
Expand All @@ -49,47 +57,62 @@ static String propString(String name, String value) {
return "prop[" + name + "] = >" + value + "<";
}

public static void main(String[] args) {
System.out.println(OK_MSG);
// print all args
List<String> vmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
for (String s: vmArgs) {
System.out.println(argString(s));
}
// print requested sys.props
for (String p: args) {
System.out.println(propString(p, System.getProperty(p)));
/**
* 1st argument is a filename to redirect application output,
* the rest are names of the properties to dump.
*/
public static void main(String[] args) throws IOException {
String outFile = args[0];
try (PrintStream out = new PrintStream(outFile, StandardCharsets.UTF_8)) {
out.println(OK_MSG);
// print all args
List<String> vmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
for (String s : vmArgs) {
out.println(argString(s));
}
// print requested sys.props (skip 1st arg which is output filename)
for (int i=1; i < args.length; i++) {
String p = args[i];
out.println(propString(p, System.getProperty(p)));
}
}
}
}

public class JdbOptions {
private static final String outFilename = UUID.randomUUID().toString() + ".out";
private static final Path outPath = Paths.get(outFilename);
private static final String targ = JbdOptionsTarg.class.getName();

public static void main(String[] args) throws Exception {
// the simplest case
test("-connect",
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=-client -XX:+PrintVMOptions,main=" + targ)
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=-client -XX:+PrintVMOptions"
+ ",main=" + targ + " " + outFilename)
.expectedArg("-XX:+PrintVMOptions");

// pass property through 'options'
test("-connect",
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-Dboo=foo',main=" + targ + " boo")
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-Dboo=foo'"
+ ",main=" + targ + " " + outFilename + " boo")
.expectedProp("boo", "foo");

// property with spaces
test("-connect",
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=\"-Dboo=foo 2\",main=" + targ + " boo")
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=\"-Dboo=foo 2\""
+ ",main=" + targ + " " + outFilename + " boo")
.expectedProp("boo", "foo 2");

// property with spaces (with single quotes)
test("-connect",
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-Dboo=foo 2',main=" + targ + " boo")
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-Dboo=foo 2'"
+ ",main=" + targ + " " + outFilename + " boo")
.expectedProp("boo", "foo 2");

// properties with spaces (with single quotes)
test("-connect",
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=-Dboo=foo '-Dboo2=foo 2',main=" + targ + " boo boo2")
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=-Dboo=foo '-Dboo2=foo 2'"
+ ",main=" + targ + " " + outFilename + " boo boo2")
.expectedProp("boo", "foo")
.expectedProp("boo2", "foo 2");

Expand All @@ -98,7 +121,7 @@ public static void main(String[] args) throws Exception {
"com.sun.jdi.CommandLineLaunch:vmexec=java,options=\"-client\" \"-XX:+PrintVMOptions\""
+ " -XX:+IgnoreUnrecognizedVMOptions"
+ " \"-XX:StartFlightRecording=dumponexit=true,maxsize=500M\" \"-XX:FlightRecorderOptions=repository=jfrrep\""
+ ",main=" + targ)
+ ",main=" + targ + " " + outFilename)
.expectedArg("-XX:StartFlightRecording=dumponexit=true,maxsize=500M")
.expectedArg("-XX:FlightRecorderOptions=repository=jfrrep");

Expand All @@ -107,7 +130,7 @@ public static void main(String[] args) throws Exception {
"com.sun.jdi.CommandLineLaunch:vmexec=java,options='-client' '-XX:+PrintVMOptions'"
+ " -XX:+IgnoreUnrecognizedVMOptions"
+ " '-XX:StartFlightRecording=dumponexit=true,maxsize=500M' '-XX:FlightRecorderOptions=repository=jfrrep'"
+ ",main=" + targ)
+ ",main=" + targ + " " + outFilename)
.expectedArg("-XX:StartFlightRecording=dumponexit=true,maxsize=500M")
.expectedArg("-XX:FlightRecorderOptions=repository=jfrrep");

Expand All @@ -120,7 +143,7 @@ public static void main(String[] args) throws Exception {
+ " -XX:+IgnoreUnrecognizedVMOptions"
+ " \"-XX:StartFlightRecording=dumponexit=true,maxsize=500M\""
+ " '-XX:FlightRecorderOptions=repository=jfrrep'"
+ ",main=" + targ + " prop1 prop2 prop3 prop4")
+ ",main=" + targ + " " + outFilename + " prop1 prop2 prop3 prop4")
.expectedProp("prop1", "val1")
.expectedProp("prop2", "val 2")
.expectedProp("prop3", "val3")
Expand Down Expand Up @@ -154,12 +177,18 @@ private static TestResult test(String... args) throws Exception {
.map(s -> s.replace("\"", "\\\""))
.toArray(String[]::new);
}

try (Jdb jdb = new Jdb(args)) {
jdb.waitForSimplePrompt(1024, true); // 1024 lines should be enough
jdb.command(JdbCommand.run().allowExit());
OutputAnalyzer out = new OutputAnalyzer(jdb.getJdbOutput());
out.shouldContain(JbdOptionsTarg.OK_MSG);
return new TestResult(out);
}
String output = Files.readAllLines(outPath, StandardCharsets.UTF_8).stream()
.collect(Collectors.joining(System.getProperty("line.separator")));
Files.deleteIfExists(outPath);
System.out.println("Debuggee output: [");
System.out.println(output);
System.out.println("]");
OutputAnalyzer out = new OutputAnalyzer(output);
return new TestResult(out);
}
}

0 comments on commit 60a2072

Please sign in to comment.