< prev index next >

test/jdk/sun/tools/jcmd/TestJcmdDefaults.java

Print this page
rev 48243 : 8189102: All tools should support -?, -h and --help
Reviewed-by: kvn, jjg, weijun, alanb, rfield, ksrini


  35 import jdk.testlibrary.Utils;
  36 
  37 /*
  38  * @test
  39  * @bug 7104647
  40  * @summary Unit test for jcmd utility. Tests jcmd options which do not send
  41  * requests to a specific JVM process.
  42  *
  43  * @library /lib/testlibrary
  44  *
  45  * @build jdk.testlibrary.*
  46  * @run main TestJcmdDefaults
  47  */
  48 public class TestJcmdDefaults {
  49 
  50     private static final String TEST_SRC = System.getProperty("test.src").trim();
  51     private static final String[] VM_ARGS = new String[] { "-XX:+UsePerfData" };
  52     private static final String JCMD_LIST_REGEX = "(?s)^\\d+\\s*.*";
  53 
  54     public static void main(String[] args) throws Exception {

  55         testJcmdUsage("-h");
  56         testJcmdUsage("-help");
  57         testJcmdDefaults();
  58         testJcmdDefaults("-l");
  59     }
  60 
  61     /**

  62      * jcmd -J-XX:+UsePerfData -h
  63      * jcmd -J-XX:+UsePerfData -help
  64      */
  65     private static void testJcmdUsage(String... jcmdArgs) throws Exception {
  66         OutputAnalyzer output = JcmdBase.jcmdNoPid(VM_ARGS, jcmdArgs);
  67 
  68         assertNotEquals(output.getExitValue(), 0);
  69         verifyOutputAgainstFile(output);
  70     }
  71 
  72     /**
  73      * jcmd -J-XX:+UsePerfData
  74      * jcmd -J-XX:+UsePerfData -l
  75      */
  76     private static void testJcmdDefaults(String... jcmdArgs) throws Exception {
  77         OutputAnalyzer output = JcmdBase.jcmdNoPid(VM_ARGS, jcmdArgs);
  78 
  79         output.shouldHaveExitValue(0);
  80         output.shouldContain("sun.tools.jcmd.JCmd");
  81         matchListedProcesses(output);
  82     }
  83 
  84     /**
  85      * Verifies the listed processes match a certain pattern.
  86      *
  87      * The output should look like:
  88      * 12246 sun.tools.jcmd.JCmd


  35 import jdk.testlibrary.Utils;
  36 
  37 /*
  38  * @test
  39  * @bug 7104647
  40  * @summary Unit test for jcmd utility. Tests jcmd options which do not send
  41  * requests to a specific JVM process.
  42  *
  43  * @library /lib/testlibrary
  44  *
  45  * @build jdk.testlibrary.*
  46  * @run main TestJcmdDefaults
  47  */
  48 public class TestJcmdDefaults {
  49 
  50     private static final String TEST_SRC = System.getProperty("test.src").trim();
  51     private static final String[] VM_ARGS = new String[] { "-XX:+UsePerfData" };
  52     private static final String JCMD_LIST_REGEX = "(?s)^\\d+\\s*.*";
  53 
  54     public static void main(String[] args) throws Exception {
  55         testJcmdUsage("-?");
  56         testJcmdUsage("-h");
  57         testJcmdUsage("--help");
  58         testJcmdDefaults();
  59         testJcmdDefaults("-l");
  60     }
  61 
  62     /**
  63      * jcmd -J-XX:+UsePerfData -?
  64      * jcmd -J-XX:+UsePerfData -h
  65      * jcmd -J-XX:+UsePerfData --help
  66      */
  67     private static void testJcmdUsage(String... jcmdArgs) throws Exception {
  68         OutputAnalyzer output = JcmdBase.jcmdNoPid(VM_ARGS, jcmdArgs);
  69 
  70         assertEquals(output.getExitValue(), 0);
  71         verifyOutputAgainstFile(output);
  72     }
  73 
  74     /**
  75      * jcmd -J-XX:+UsePerfData
  76      * jcmd -J-XX:+UsePerfData -l
  77      */
  78     private static void testJcmdDefaults(String... jcmdArgs) throws Exception {
  79         OutputAnalyzer output = JcmdBase.jcmdNoPid(VM_ARGS, jcmdArgs);
  80 
  81         output.shouldHaveExitValue(0);
  82         output.shouldContain("sun.tools.jcmd.JCmd");
  83         matchListedProcesses(output);
  84     }
  85 
  86     /**
  87      * Verifies the listed processes match a certain pattern.
  88      *
  89      * The output should look like:
  90      * 12246 sun.tools.jcmd.JCmd
< prev index next >