< prev index next >

test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java

Print this page




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.IOException;
  25 import java.io.OutputStream;
  26 import java.util.List;
  27 import java.util.Map;
  28 
  29 import jdk.test.lib.apps.LingeredApp;
  30 import jdk.test.lib.Platform;
  31 import jdk.test.lib.JDKToolLauncher;

  32 import jdk.test.lib.process.OutputAnalyzer;
  33 
  34 /**
  35  * This is a framework to run 'jhsdb clhsdb' commands.
  36  * See open/test/hotspot/jtreg/serviceability/sa/ClhsdbLongConstant.java for
  37  * an example of how to write a test.
  38  */
  39 
  40 public class ClhsdbLauncher {
  41 
  42     private Process toolProcess;
  43 
  44     public ClhsdbLauncher() {
  45         toolProcess = null;
  46     }
  47 
  48     /**
  49      *
  50      * Launches 'jhsdb clhsdb' and attaches to the Lingered App process.
  51      * @param lingeredAppPid  - pid of the Lingered App or one its sub-classes.
  52      */
  53     private void attach(long lingeredAppPid)
  54         throws IOException {
  55 
  56         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
  57         launcher.addToolArg("clhsdb");
  58         if (lingeredAppPid != -1) {
  59             launcher.addToolArg("--pid=" + Long.toString(lingeredAppPid));
  60             System.out.println("Starting clhsdb against " + lingeredAppPid);
  61         }
  62 
  63         ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
  64         processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
  65 
  66         toolProcess = processBuilder.start();
  67     }
  68 
  69     /**
  70      *





















  71      * Runs 'jhsdb clhsdb' commands and checks for expected and unexpected strings.
  72      * @param commands  - clhsdb commands to execute.
  73      * @param expectedStrMap - Map of expected strings per command which need to
  74      *                         be checked in the output of the command.
  75      * @param unExpectedStrMap - Map of unexpected strings per command which should
  76      *                           not be present in the output of the command.
  77      * @return Output of the commands as a String.
  78      */
  79     private String runCmd(List<String> commands,
  80                           Map<String, List<String>> expectedStrMap,
  81                           Map<String, List<String>> unExpectedStrMap)
  82         throws IOException, InterruptedException {
  83         String output;
  84 
  85         if (commands == null) {
  86             throw new RuntimeException("CLHSDB command must be provided\n");
  87         }
  88 
  89         try (OutputStream out = toolProcess.getOutputStream()) {
  90             for (String cmd : commands) {


 140      * @param commands  - clhsdb commands to execute.
 141      * @param expectedStrMap - Map of expected strings per command which need to
 142      *                         be checked in the output of the command.
 143      * @param unExpectedStrMap - Map of unexpected strings per command which should
 144      *                           not be present in the output of the command.
 145      * @return Output of the commands as a String.
 146      */
 147     public String run(long lingeredAppPid,
 148                       List<String> commands,
 149                       Map<String, List<String>> expectedStrMap,
 150                       Map<String, List<String>> unExpectedStrMap)
 151         throws IOException, InterruptedException {
 152 
 153         if (!Platform.shouldSAAttach()) {
 154             // Silently skip the test if we don't have enough permissions to attach
 155             System.out.println("SA attach not expected to work - test skipped.");
 156             return null;
 157         }
 158 
 159         attach(lingeredAppPid);




























 160         return runCmd(commands, expectedStrMap, unExpectedStrMap);
 161     }
 162 }


  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.IOException;
  25 import java.io.OutputStream;
  26 import java.util.List;
  27 import java.util.Map;
  28 
  29 import jdk.test.lib.apps.LingeredApp;
  30 import jdk.test.lib.Platform;
  31 import jdk.test.lib.JDKToolLauncher;
  32 import jdk.test.lib.JDKToolFinder;
  33 import jdk.test.lib.process.OutputAnalyzer;
  34 
  35 /**
  36  * This is a framework to run 'jhsdb clhsdb' commands.
  37  * See open/test/hotspot/jtreg/serviceability/sa/ClhsdbLongConstant.java for
  38  * an example of how to write a test.
  39  */
  40 
  41 public class ClhsdbLauncher {
  42 
  43     private Process toolProcess;
  44 
  45     public ClhsdbLauncher() {
  46         toolProcess = null;
  47     }
  48 
  49     /**
  50      *
  51      * Launches 'jhsdb clhsdb' and attaches to the Lingered App process.
  52      * @param lingeredAppPid  - pid of the Lingered App or one its sub-classes.
  53      */
  54     private void attach(long lingeredAppPid)
  55         throws IOException {
  56 
  57         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
  58         launcher.addToolArg("clhsdb");
  59         if (lingeredAppPid != -1) {
  60             launcher.addToolArg("--pid=" + Long.toString(lingeredAppPid));
  61             System.out.println("Starting clhsdb against " + lingeredAppPid);
  62         }
  63 
  64         ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
  65         processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
  66 
  67         toolProcess = processBuilder.start();
  68     }
  69 
  70     /**
  71      *
  72      * Launches 'jhsdb clhsdb' and loads a core file.
  73      * @param coreFileName - Name of the corefile to be loaded.
  74      */
  75     private void loadCore(String coreFileName)
  76         throws IOException {
  77 
  78         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
  79         launcher.addToolArg("clhsdb");
  80         launcher.addToolArg("--core=" + coreFileName);
  81         launcher.addToolArg("--exe=" + JDKToolFinder.getTestJDKTool("java"));
  82         System.out.println("Starting clhsdb against corefile " + coreFileName +
  83                            " and exe " + JDKToolFinder.getTestJDKTool("java"));
  84 
  85         ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
  86         processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
  87 
  88         toolProcess = processBuilder.start();
  89     }
  90 
  91     /**
  92      *
  93      * Runs 'jhsdb clhsdb' commands and checks for expected and unexpected strings.
  94      * @param commands  - clhsdb commands to execute.
  95      * @param expectedStrMap - Map of expected strings per command which need to
  96      *                         be checked in the output of the command.
  97      * @param unExpectedStrMap - Map of unexpected strings per command which should
  98      *                           not be present in the output of the command.
  99      * @return Output of the commands as a String.
 100      */
 101     private String runCmd(List<String> commands,
 102                           Map<String, List<String>> expectedStrMap,
 103                           Map<String, List<String>> unExpectedStrMap)
 104         throws IOException, InterruptedException {
 105         String output;
 106 
 107         if (commands == null) {
 108             throw new RuntimeException("CLHSDB command must be provided\n");
 109         }
 110 
 111         try (OutputStream out = toolProcess.getOutputStream()) {
 112             for (String cmd : commands) {


 162      * @param commands  - clhsdb commands to execute.
 163      * @param expectedStrMap - Map of expected strings per command which need to
 164      *                         be checked in the output of the command.
 165      * @param unExpectedStrMap - Map of unexpected strings per command which should
 166      *                           not be present in the output of the command.
 167      * @return Output of the commands as a String.
 168      */
 169     public String run(long lingeredAppPid,
 170                       List<String> commands,
 171                       Map<String, List<String>> expectedStrMap,
 172                       Map<String, List<String>> unExpectedStrMap)
 173         throws IOException, InterruptedException {
 174 
 175         if (!Platform.shouldSAAttach()) {
 176             // Silently skip the test if we don't have enough permissions to attach
 177             System.out.println("SA attach not expected to work - test skipped.");
 178             return null;
 179         }
 180 
 181         attach(lingeredAppPid);
 182         return runCmd(commands, expectedStrMap, unExpectedStrMap);
 183     }
 184 
 185     /**
 186      *
 187      * Launches 'jhsdb clhsdb', loads a core file, executes the commands,
 188      * checks for expected and unexpected strings.
 189      * @param coreFileName - Name of the core file to be debugged.
 190      * @param commands  - clhsdb commands to execute.
 191      * @param expectedStrMap - Map of expected strings per command which need to
 192      *                         be checked in the output of the command.
 193      * @param unExpectedStrMap - Map of unexpected strings per command which should
 194      *                           not be present in the output of the command.
 195      * @return Output of the commands as a String.
 196      */
 197     public String runOnCore(String coreFileName,
 198                             List<String> commands,
 199                             Map<String, List<String>> expectedStrMap,
 200                             Map<String, List<String>> unExpectedStrMap)
 201         throws IOException, InterruptedException {
 202 
 203         if (!Platform.shouldSAAttach()) {
 204             // Silently skip the test if we don't have enough permissions to attach
 205             System.out.println("SA attach not expected to work - test skipped.");
 206             return null;
 207         }
 208 
 209         loadCore(coreFileName);
 210         return runCmd(commands, expectedStrMap, unExpectedStrMap);
 211     }
 212 }
< prev index next >