提交 e18b3df1 编写于 作者: E egahlin

8214925: JFR tool fails to execute

Reviewed-by: mgronlun, mseledtsov
上级 594d7245
...@@ -72,7 +72,7 @@ public final class Main { ...@@ -72,7 +72,7 @@ public final class Main {
System.out.println(); System.out.println();
System.out.println(" jfr summary recording.jfr"); System.out.println(" jfr summary recording.jfr");
System.out.println(); System.out.println();
System.out.println(" jfr metadata recoding.jfr"); System.out.println(" jfr metadata recording.jfr");
System.out.println(); System.out.println();
System.out.println("For more information about available commands, use 'jfr help'"); System.out.println("For more information about available commands, use 'jfr help'");
System.exit(EXIT_OK); System.exit(EXIT_OK);
......
...@@ -32,7 +32,10 @@ import java.util.regex.Pattern; ...@@ -32,7 +32,10 @@ import java.util.regex.Pattern;
import jdk.jfr.Configuration; import jdk.jfr.Configuration;
import jdk.jfr.Event; import jdk.jfr.Event;
import jdk.jfr.Recording; import jdk.jfr.Recording;
import jdk.test.lib.Utils;; import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;;
final class ExecuteHelper { final class ExecuteHelper {
...@@ -122,4 +125,12 @@ final class ExecuteHelper { ...@@ -122,4 +125,12 @@ final class ExecuteHelper {
Matcher m = p.matcher("aaaaab"); Matcher m = p.matcher("aaaaab");
m.matches(); m.matches();
} }
public static OutputAnalyzer jfr(String... args) throws Throwable {
JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jfr");
for (String arg : args) {
l.addToolArg(arg);
}
return ProcessTools.executeCommand(l.getCommand());
}
} }
...@@ -40,7 +40,6 @@ import jdk.jfr.internal.Repository; ...@@ -40,7 +40,6 @@ import jdk.jfr.internal.Repository;
import jdk.jfr.internal.SecuritySupport.SafePath; import jdk.jfr.internal.SecuritySupport.SafePath;
import jdk.test.lib.Asserts; import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/** /**
* @test * @test
...@@ -89,30 +88,30 @@ public class TestAssemble { ...@@ -89,30 +88,30 @@ public class TestAssemble {
String destination = destinationPath.toAbsolutePath().toString(); String destination = destinationPath.toAbsolutePath().toString();
// Test failure // Test failure
OutputAnalyzer output = ProcessTools.executeProcess("jfr", "assemble"); OutputAnalyzer output = ExecuteHelper.jfr("assemble");
output.shouldContain("too few arguments"); output.shouldContain("too few arguments");
output = ProcessTools.executeProcess("jfr", "assemble", directory); output = ExecuteHelper.jfr("assemble", directory);
output.shouldContain("too few arguments"); output.shouldContain("too few arguments");
output = ProcessTools.executeProcess("jfr", "assemble", "not-a-directory", destination); output = ExecuteHelper.jfr("assemble", "not-a-directory", destination);
output.shouldContain("directory does not exist, not-a-directory"); output.shouldContain("directory does not exist, not-a-directory");
output = ProcessTools.executeProcess("jfr", "assemble", directory, "not-a-destination"); output = ExecuteHelper.jfr("assemble", directory, "not-a-destination");
output.shouldContain("filename must end with '.jfr'"); output.shouldContain("filename must end with '.jfr'");
output = ProcessTools.executeProcess("jfr","assemble", "--wrongOption", directory, destination); output = ExecuteHelper.jfr("assemble", "--wrongOption", directory, destination);
output.shouldContain("too many arguments"); output.shouldContain("too many arguments");
FileWriter fw = new FileWriter(destination); FileWriter fw = new FileWriter(destination);
fw.write('d'); fw.write('d');
fw.close(); fw.close();
output = ProcessTools.executeProcess("jfr", "assemble", directory, destination); output = ExecuteHelper.jfr("assemble", directory, destination);
output.shouldContain("already exists"); output.shouldContain("already exists");
Files.delete(destinationPath); Files.delete(destinationPath);
// test success // test success
output = ProcessTools.executeProcess("jfr", "assemble", directory, destination); output = ExecuteHelper.jfr("assemble", directory, destination);
System.out.println(output.getOutput()); System.out.println(output.getOutput());
output.shouldContain("Finished."); output.shouldContain("Finished.");
......
...@@ -37,7 +37,6 @@ import jdk.jfr.Configuration; ...@@ -37,7 +37,6 @@ import jdk.jfr.Configuration;
import jdk.jfr.Recording; import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordingFile; import jdk.jfr.consumer.RecordingFile;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/** /**
* @test * @test
...@@ -63,40 +62,40 @@ public class TestDisassemble { ...@@ -63,40 +62,40 @@ public class TestDisassemble {
String fileBText = recordingFileB.toAbsolutePath().toString(); String fileBText = recordingFileB.toAbsolutePath().toString();
String fileCText = recordingFileC.toAbsolutePath().toString(); String fileCText = recordingFileC.toAbsolutePath().toString();
OutputAnalyzer output = ProcessTools.executeProcess("jfr", "disassemble"); OutputAnalyzer output = ExecuteHelper.jfr("disassemble");
output.shouldContain("missing file"); output.shouldContain("missing file");
output = ProcessTools.executeProcess("jfr","disassemble", "--wrongOption", fileAText); output = ExecuteHelper.jfr("disassemble", "--wrongOption", fileAText);
output.shouldContain("unknown option"); output.shouldContain("unknown option");
output = ProcessTools.executeProcess("jfr","disassemble", "--wrongOption", "1", fileAText); output = ExecuteHelper.jfr("disassemble", "--wrongOption", "1", fileAText);
output.shouldContain("unknown option"); output.shouldContain("unknown option");
output = ProcessTools.executeProcess("jfr","disassemble", "--max-chunks", "-3", fileAText); output = ExecuteHelper.jfr("disassemble", "--max-chunks", "-3", fileAText);
output.shouldContain("max chunks must be at least 1"); output.shouldContain("max chunks must be at least 1");
output = ProcessTools.executeProcess("jfr","disassemble", "--max-chunks", "1000", fileAText); output = ExecuteHelper.jfr("disassemble", "--max-chunks", "1000", fileAText);
output.shouldContain("number of chunks in recording"); output.shouldContain("number of chunks in recording");
output.shouldContain("doesn't exceed max chunks"); output.shouldContain("doesn't exceed max chunks");
output = ProcessTools.executeProcess("jfr", "disassemble", fileAText); // maxchunks is 5 by output = ExecuteHelper.jfr("disassemble", fileAText); // maxchunks is 5 by
// default // default
System.out.println(output.getOutput()); System.out.println(output.getOutput());
System.out.println(fileAText); System.out.println(fileAText);
verifyRecording(fileAText.substring(0, fileAText.length() - 4) + "_1.jfr"); verifyRecording(fileAText.substring(0, fileAText.length() - 4) + "_1.jfr");
verifyRecording(fileAText.substring(0, fileAText.length() - 4) + "_2.jfr"); verifyRecording(fileAText.substring(0, fileAText.length() - 4) + "_2.jfr");
output = ProcessTools.executeProcess("jfr","disassemble", "--max-chunks", "2", fileBText); output = ExecuteHelper.jfr("disassemble", "--max-chunks", "2", fileBText);
verifyRecording(fileBText.substring(0, fileBText.length() - 4) + "_1.jfr"); verifyRecording(fileBText.substring(0, fileBText.length() - 4) + "_1.jfr");
verifyRecording(fileBText.substring(0, fileBText.length() - 4) + "_2.jfr"); verifyRecording(fileBText.substring(0, fileBText.length() - 4) + "_2.jfr");
verifyRecording(fileBText.substring(0, fileBText.length() - 4) + "_3.jfr"); verifyRecording(fileBText.substring(0, fileBText.length() - 4) + "_3.jfr");
output = ProcessTools.executeProcess("jfr","disassemble", "--max-chunks", "2", fileBText); output = ExecuteHelper.jfr("disassemble", "--max-chunks", "2", fileBText);
output.shouldContain("file with that name already exist"); output.shouldContain("file with that name already exist");
// sanity check // sanity check
output = ProcessTools.executeProcess("jfr","disassemble", "--max-size", "500000", fileCText); output = ExecuteHelper.jfr("disassemble", "--max-size", "10000", fileCText);
verifyRecording(fileCText.substring(0, fileCText.length() - 4) + "_1.jfr"); verifyRecording(fileCText.substring(0, fileCText.length() - 4) + "_01.jfr");
} }
private static void verifyRecording(String name) throws IOException { private static void verifyRecording(String name) throws IOException {
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
package jdk.jfr.tool; package jdk.jfr.tool;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/** /**
* @test * @test
...@@ -38,7 +37,7 @@ import jdk.test.lib.process.ProcessTools; ...@@ -38,7 +37,7 @@ import jdk.test.lib.process.ProcessTools;
public class TestHelp { public class TestHelp {
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
OutputAnalyzer output = ProcessTools.executeProcess("jfr", "help"); OutputAnalyzer output = ExecuteHelper.jfr("help");
output.shouldContain("print"); output.shouldContain("print");
output.shouldContain("assemble"); output.shouldContain("assemble");
output.shouldContain("disassemble"); output.shouldContain("disassemble");
...@@ -46,11 +45,11 @@ public class TestHelp { ...@@ -46,11 +45,11 @@ public class TestHelp {
output.shouldContain("summary"); output.shouldContain("summary");
output.shouldContain("help"); output.shouldContain("help");
output = ProcessTools.executeProcess("jfr", "help", "version"); output = ExecuteHelper.jfr("help", "version");
output.shouldContain("Display version of the jfr tool"); output.shouldContain("Display version of the jfr tool");
output.shouldContain("jfr version"); output.shouldContain("jfr version");
output = ProcessTools.executeProcess("jfr", "help", "wrongcommand"); output = ExecuteHelper.jfr("help", "wrongcommand");
output.shouldContain("unknown command 'wrongcommand'"); output.shouldContain("unknown command 'wrongcommand'");
} }
} }
...@@ -30,7 +30,6 @@ import java.nio.file.Path; ...@@ -30,7 +30,6 @@ import java.nio.file.Path;
import jdk.jfr.EventType; import jdk.jfr.EventType;
import jdk.jfr.consumer.RecordingFile; import jdk.jfr.consumer.RecordingFile;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/** /**
* @test * @test
...@@ -45,13 +44,13 @@ public class TestMetadata { ...@@ -45,13 +44,13 @@ public class TestMetadata {
Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath(); Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath();
String file = f.toAbsolutePath().toString(); String file = f.toAbsolutePath().toString();
OutputAnalyzer output = ProcessTools.executeProcess("jfr", "metadata"); OutputAnalyzer output = ExecuteHelper.jfr("metadata");
output.shouldContain("missing file"); output.shouldContain("missing file");
output = ProcessTools.executeProcess("jfr", "metadata", "--wrongOption", file); output = ExecuteHelper.jfr("metadata", "--wrongOption", file);
output.shouldContain("unknown option --wrongOption"); output.shouldContain("unknown option --wrongOption");
output = ProcessTools.executeProcess("jfr", "metadata", file); output = ExecuteHelper.jfr("metadata", file);
try (RecordingFile rf = new RecordingFile(f)) { try (RecordingFile rf = new RecordingFile(f)) {
for (EventType t : rf.readEventTypes()) { for (EventType t : rf.readEventTypes()) {
String name = t.getName(); String name = t.getName();
......
...@@ -31,7 +31,6 @@ import java.nio.file.Path; ...@@ -31,7 +31,6 @@ import java.nio.file.Path;
import jdk.test.lib.Utils; import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/** /**
* @test * @test
...@@ -44,17 +43,17 @@ public class TestPrint { ...@@ -44,17 +43,17 @@ public class TestPrint {
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
OutputAnalyzer output = ProcessTools.executeProcess("jfr", "print"); OutputAnalyzer output = ExecuteHelper.jfr("print");
output.shouldContain("missing file"); output.shouldContain("missing file");
output = ProcessTools.executeProcess("jfr", "print", "missing.jfr"); output = ExecuteHelper.jfr("print", "missing.jfr");
output.shouldContain("could not find file "); output.shouldContain("could not find file ");
Path file = Utils.createTempFile("faked-print-file", ".jfr"); Path file = Utils.createTempFile("faked-print-file", ".jfr");
FileWriter fw = new FileWriter(file.toFile()); FileWriter fw = new FileWriter(file.toFile());
fw.write('d'); fw.write('d');
fw.close(); fw.close();
output = ProcessTools.executeProcess("jfr", "print", "--wrongOption", file.toAbsolutePath().toString()); output = ExecuteHelper.jfr("print", "--wrongOption", file.toAbsolutePath().toString());
output.shouldContain("unknown option"); output.shouldContain("unknown option");
Files.delete(file); Files.delete(file);
} }
......
...@@ -28,7 +28,6 @@ package jdk.jfr.tool; ...@@ -28,7 +28,6 @@ package jdk.jfr.tool;
import java.nio.file.Path; import java.nio.file.Path;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/** /**
* @test * @test
...@@ -47,7 +46,7 @@ public class TestPrintDefault { ...@@ -47,7 +46,7 @@ public class TestPrintDefault {
Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath(); Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();
OutputAnalyzer output = ProcessTools.executeProcess("jfr", "print", recordingFile.toString()); OutputAnalyzer output = ExecuteHelper.jfr("print", recordingFile.toString());
output.shouldContain("JVMInformation"); output.shouldContain("JVMInformation");
} }
} }
...@@ -43,7 +43,6 @@ import jdk.jfr.consumer.RecordingFile; ...@@ -43,7 +43,6 @@ import jdk.jfr.consumer.RecordingFile;
import jdk.nashorn.api.scripting.JSObject; import jdk.nashorn.api.scripting.JSObject;
import jdk.test.lib.Asserts; import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/** /**
* @test * @test
...@@ -62,7 +61,7 @@ public class TestPrintJSON { ...@@ -62,7 +61,7 @@ public class TestPrintJSON {
Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath(); Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();
OutputAnalyzer output = ProcessTools.executeProcess("jfr", "print", "--json", "--stack-depth", "999", recordingFile.toString()); OutputAnalyzer output = ExecuteHelper.jfr("print", "--json", "--stack-depth", "999", recordingFile.toString());
String json = output.getStdout(); String json = output.getStdout();
// Parse JSON using Nashorn // Parse JSON using Nashorn
......
...@@ -58,7 +58,6 @@ import jdk.jfr.consumer.RecordedEvent; ...@@ -58,7 +58,6 @@ import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.consumer.RecordedObject; import jdk.jfr.consumer.RecordedObject;
import jdk.jfr.consumer.RecordingFile; import jdk.jfr.consumer.RecordingFile;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/** /**
* @test * @test
...@@ -76,7 +75,7 @@ public class TestPrintXML { ...@@ -76,7 +75,7 @@ public class TestPrintXML {
Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath(); Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();
OutputAnalyzer output = ProcessTools.executeProcess("jfr", "print", "--xml", "--stack-depth", "9999", recordingFile.toString()); OutputAnalyzer output = ExecuteHelper.jfr("print", "--xml", "--stack-depth", "9999", recordingFile.toString());
System.out.println(recordingFile); System.out.println(recordingFile);
String xml = output.getStdout(); String xml = output.getStdout();
......
...@@ -30,7 +30,6 @@ import java.nio.file.Path; ...@@ -30,7 +30,6 @@ import java.nio.file.Path;
import jdk.jfr.EventType; import jdk.jfr.EventType;
import jdk.jfr.consumer.RecordingFile; import jdk.jfr.consumer.RecordingFile;
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/** /**
* @test * @test
...@@ -45,13 +44,13 @@ public class TestSummary { ...@@ -45,13 +44,13 @@ public class TestSummary {
Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath(); Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath();
String file = f.toAbsolutePath().toString(); String file = f.toAbsolutePath().toString();
OutputAnalyzer output = ProcessTools.executeProcess("jfr", "summary"); OutputAnalyzer output = ExecuteHelper.jfr("summary");
output.shouldContain("missing file"); output.shouldContain("missing file");
output = ProcessTools.executeProcess("jfr", "summary", "--wrongOption", file); output = ExecuteHelper.jfr("summary", "--wrongOption", file);
output.shouldContain("too many arguments"); output.shouldContain("too many arguments");
output = ProcessTools.executeProcess("jfr", "summary", file); output = ExecuteHelper.jfr("summary", file);
try (RecordingFile rf = new RecordingFile(f)) { try (RecordingFile rf = new RecordingFile(f)) {
for (EventType t : rf.readEventTypes()) { for (EventType t : rf.readEventTypes()) {
output.shouldContain(t.getName()); output.shouldContain(t.getName());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册