8214925: JFR tool fails to execute
authoregahlin
Thu, 06 Dec 2018 23:38:22 +0100
changeset 52888 9607fb16ccfe
parent 52887 0d89f672c62e
child 52889 4ac336352a29
8214925: JFR tool fails to execute Reviewed-by: mgronlun, mseledtsov
src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Main.java
test/jdk/jdk/jfr/tool/ExecuteHelper.java
test/jdk/jdk/jfr/tool/TestAssemble.java
test/jdk/jdk/jfr/tool/TestDisassemble.java
test/jdk/jdk/jfr/tool/TestHelp.java
test/jdk/jdk/jfr/tool/TestMetadata.java
test/jdk/jdk/jfr/tool/TestPrint.java
test/jdk/jdk/jfr/tool/TestPrintDefault.java
test/jdk/jdk/jfr/tool/TestPrintJSON.java
test/jdk/jdk/jfr/tool/TestPrintXML.java
test/jdk/jdk/jfr/tool/TestSummary.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Main.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Main.java	Thu Dec 06 23:38:22 2018 +0100
@@ -72,7 +72,7 @@
             System.out.println();
             System.out.println(" jfr summary recording.jfr");
             System.out.println();
-            System.out.println(" jfr metadata recoding.jfr");
+            System.out.println(" jfr metadata recording.jfr");
             System.out.println();
             System.out.println("For more information about available commands, use 'jfr help'");
             System.exit(EXIT_OK);
--- a/test/jdk/jdk/jfr/tool/ExecuteHelper.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/ExecuteHelper.java	Thu Dec 06 23:38:22 2018 +0100
@@ -32,7 +32,10 @@
 import jdk.jfr.Configuration;
 import jdk.jfr.Event;
 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 {
 
@@ -122,4 +125,12 @@
        Matcher m = p.matcher("aaaaab");
        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());
+    }
 }
--- a/test/jdk/jdk/jfr/tool/TestAssemble.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/TestAssemble.java	Thu Dec 06 23:38:22 2018 +0100
@@ -40,7 +40,6 @@
 import jdk.jfr.internal.SecuritySupport.SafePath;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 
 /**
  * @test
@@ -90,30 +89,30 @@
         String destination = destinationPath.toAbsolutePath().toString();
 
         // Test failure
-        OutputAnalyzer output = ProcessTools.executeProcess("jfr", "assemble");
+        OutputAnalyzer output = ExecuteHelper.jfr("assemble");
         output.shouldContain("too few arguments");
 
-        output = ProcessTools.executeProcess("jfr", "assemble", directory);
+        output = ExecuteHelper.jfr("assemble", directory);
         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 = ProcessTools.executeProcess("jfr", "assemble", directory, "not-a-destination");
+        output = ExecuteHelper.jfr("assemble", directory, "not-a-destination");
         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");
 
         FileWriter fw = new FileWriter(destination);
         fw.write('d');
         fw.close();
-        output = ProcessTools.executeProcess("jfr", "assemble", directory, destination);
+        output = ExecuteHelper.jfr("assemble", directory, destination);
         output.shouldContain("already exists");
         Files.delete(destinationPath);
 
         // test success
-        output = ProcessTools.executeProcess("jfr", "assemble", directory, destination);
+        output = ExecuteHelper.jfr("assemble", directory, destination);
         System.out.println(output.getOutput());
         output.shouldContain("Finished.");
 
--- a/test/jdk/jdk/jfr/tool/TestDisassemble.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/TestDisassemble.java	Thu Dec 06 23:38:22 2018 +0100
@@ -37,7 +37,6 @@
 import jdk.jfr.Recording;
 import jdk.jfr.consumer.RecordingFile;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 
 /**
  * @test
@@ -64,40 +63,40 @@
         String fileBText = recordingFileB.toAbsolutePath().toString();
         String fileCText = recordingFileC.toAbsolutePath().toString();
 
-        OutputAnalyzer output = ProcessTools.executeProcess("jfr", "disassemble");
+        OutputAnalyzer output = ExecuteHelper.jfr("disassemble");
         output.shouldContain("missing file");
 
-        output =  ProcessTools.executeProcess("jfr","disassemble", "--wrongOption", fileAText);
+        output = ExecuteHelper.jfr("disassemble", "--wrongOption", fileAText);
         output.shouldContain("unknown option");
 
-        output = ProcessTools.executeProcess("jfr","disassemble", "--wrongOption", "1", fileAText);
+        output = ExecuteHelper.jfr("disassemble", "--wrongOption", "1", fileAText);
         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 =  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("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
         System.out.println(output.getOutput());
         System.out.println(fileAText);
         verifyRecording(fileAText.substring(0, fileAText.length() - 4) + "_1.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) + "_2.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");
 
         // sanity check
-        output =  ProcessTools.executeProcess("jfr","disassemble", "--max-size", "500000", fileCText);
-        verifyRecording(fileCText.substring(0, fileCText.length() - 4) + "_1.jfr");
+        output = ExecuteHelper.jfr("disassemble", "--max-size", "10000", fileCText);
+        verifyRecording(fileCText.substring(0, fileCText.length() - 4) + "_01.jfr");
     }
 
     private static void verifyRecording(String name) throws IOException {
--- a/test/jdk/jdk/jfr/tool/TestHelp.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/TestHelp.java	Thu Dec 06 23:38:22 2018 +0100
@@ -26,7 +26,6 @@
 package jdk.jfr.tool;
 
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 
 /**
  * @test
@@ -39,7 +38,7 @@
 public class TestHelp {
 
     public static void main(String[] args) throws Throwable {
-        OutputAnalyzer output = ProcessTools.executeProcess("jfr", "help");
+        OutputAnalyzer output = ExecuteHelper.jfr("help");
         output.shouldContain("print");
         output.shouldContain("assemble");
         output.shouldContain("disassemble");
@@ -47,11 +46,11 @@
         output.shouldContain("summary");
         output.shouldContain("help");
 
-        output = ProcessTools.executeProcess("jfr", "help", "version");
+        output = ExecuteHelper.jfr("help", "version");
         output.shouldContain("Display version of the jfr tool");
         output.shouldContain("jfr version");
 
-        output = ProcessTools.executeProcess("jfr", "help", "wrongcommand");
+        output = ExecuteHelper.jfr("help", "wrongcommand");
         output.shouldContain("unknown command 'wrongcommand'");
     }
 }
--- a/test/jdk/jdk/jfr/tool/TestMetadata.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/TestMetadata.java	Thu Dec 06 23:38:22 2018 +0100
@@ -30,7 +30,6 @@
 import jdk.jfr.EventType;
 import jdk.jfr.consumer.RecordingFile;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 
 /**
  * @test
@@ -46,13 +45,13 @@
         Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath();
         String file = f.toAbsolutePath().toString();
 
-        OutputAnalyzer output = ProcessTools.executeProcess("jfr", "metadata");
+        OutputAnalyzer output = ExecuteHelper.jfr("metadata");
         output.shouldContain("missing file");
 
-        output = ProcessTools.executeProcess("jfr", "metadata", "--wrongOption", file);
+        output = ExecuteHelper.jfr("metadata", "--wrongOption", file);
         output.shouldContain("unknown option --wrongOption");
 
-        output = ProcessTools.executeProcess("jfr", "metadata", file);
+        output = ExecuteHelper.jfr("metadata", file);
         try (RecordingFile rf = new RecordingFile(f)) {
             for (EventType t : rf.readEventTypes()) {
                 String name = t.getName();
--- a/test/jdk/jdk/jfr/tool/TestPrint.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/TestPrint.java	Thu Dec 06 23:38:22 2018 +0100
@@ -31,7 +31,6 @@
 
 import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 
 /**
  * @test
@@ -45,17 +44,17 @@
 
     public static void main(String[] args) throws Throwable {
 
-        OutputAnalyzer output = ProcessTools.executeProcess("jfr", "print");
+        OutputAnalyzer output = ExecuteHelper.jfr("print");
         output.shouldContain("missing file");
 
-        output = ProcessTools.executeProcess("jfr", "print", "missing.jfr");
+        output = ExecuteHelper.jfr("print", "missing.jfr");
         output.shouldContain("could not find file ");
 
         Path file = Utils.createTempFile("faked-print-file",  ".jfr");
         FileWriter fw = new FileWriter(file.toFile());
         fw.write('d');
         fw.close();
-        output = ProcessTools.executeProcess("jfr", "print", "--wrongOption", file.toAbsolutePath().toString());
+        output = ExecuteHelper.jfr("print", "--wrongOption", file.toAbsolutePath().toString());
         output.shouldContain("unknown option");
         Files.delete(file);
     }
--- a/test/jdk/jdk/jfr/tool/TestPrintDefault.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/TestPrintDefault.java	Thu Dec 06 23:38:22 2018 +0100
@@ -28,7 +28,6 @@
 import java.nio.file.Path;
 
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 
 /**
  * @test
@@ -48,7 +47,7 @@
 
         Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();
 
-        OutputAnalyzer output = ProcessTools.executeProcess("jfr", "print", recordingFile.toString());
+        OutputAnalyzer output = ExecuteHelper.jfr("print", recordingFile.toString());
         output.shouldContain("JVMInformation");
     }
 }
--- a/test/jdk/jdk/jfr/tool/TestPrintJSON.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/TestPrintJSON.java	Thu Dec 06 23:38:22 2018 +0100
@@ -43,7 +43,6 @@
 import jdk.nashorn.api.scripting.JSObject;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 
 /**
  * @test
@@ -63,7 +62,7 @@
 
         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();
 
         // Parse JSON using Nashorn
--- a/test/jdk/jdk/jfr/tool/TestPrintXML.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/TestPrintXML.java	Thu Dec 06 23:38:22 2018 +0100
@@ -58,7 +58,6 @@
 import jdk.jfr.consumer.RecordedObject;
 import jdk.jfr.consumer.RecordingFile;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 
 /**
  * @test
@@ -77,7 +76,7 @@
 
         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);
         String xml = output.getStdout();
 
--- a/test/jdk/jdk/jfr/tool/TestSummary.java	Thu Dec 06 14:34:11 2018 -0800
+++ b/test/jdk/jdk/jfr/tool/TestSummary.java	Thu Dec 06 23:38:22 2018 +0100
@@ -30,7 +30,6 @@
 import jdk.jfr.EventType;
 import jdk.jfr.consumer.RecordingFile;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 
 /**
  * @test
@@ -46,13 +45,13 @@
         Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath();
         String file = f.toAbsolutePath().toString();
 
-        OutputAnalyzer output = ProcessTools.executeProcess("jfr", "summary");
+        OutputAnalyzer output = ExecuteHelper.jfr("summary");
         output.shouldContain("missing file");
 
-        output = ProcessTools.executeProcess("jfr", "summary", "--wrongOption", file);
+        output = ExecuteHelper.jfr("summary", "--wrongOption", file);
         output.shouldContain("too many arguments");
 
-        output = ProcessTools.executeProcess("jfr", "summary", file);
+        output = ExecuteHelper.jfr("summary", file);
         try (RecordingFile rf = new RecordingFile(f)) {
             for (EventType t : rf.readEventTypes()) {
                 output.shouldContain(t.getName());