< prev index next >

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

Print this page
rev 51638 : [mq]: 8210112
rev 51639 : [mq]: 8210112-1


  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 static jdk.testlibrary.Asserts.*;
  25 
  26 import java.io.File;
  27 import java.io.IOException;
  28 import java.nio.file.Files;
  29 import java.nio.file.Path;
  30 import java.nio.file.Paths;
  31 import java.util.List;
  32 
  33 import jdk.testlibrary.OutputAnalyzer;
  34 import jdk.testlibrary.ProcessTools;
  35 import jdk.testlibrary.Utils;
  36 
  37 /*
  38  * @test
  39  * @bug 7104647 7154822
  40  * @summary Unit test for jcmd utility. The test will send different diagnostic
  41  * command requests to the current java process.
  42  *
  43  * @library /lib/testlibrary

  44  *
  45  * @build jdk.testlibrary.*
  46  * @run main/othervm -XX:+UsePerfData TestJcmdSanity
  47  */
  48 public class TestJcmdSanity {
  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_COMMAND_REGEX = "(\\w|\\.)*";
  53     private static final String PERF_COUNTER_REGEX = "(\\w|\\.)*\\=.*";
  54 
  55     public static void main(String[] args) throws Exception {
  56         testJcmdPidHelp();
  57         testJcmdPidHelpHelp();
  58         testJcmdPid_f();
  59         testJcmdPidPerfCounterPrint();
  60         testJcmdPidBigScript();
  61     }
  62 
  63     /**


 117         File scrpitFile = new File(TEST_SRC, "dcmd-big-script.txt");
 118         OutputAnalyzer output = JcmdBase.jcmd(VM_ARGS,
 119                 new String[] {"-f", scrpitFile.getAbsolutePath()});
 120 
 121         output.shouldHaveExitValue(0);
 122         output.shouldNotContain("Exception");
 123         output.shouldContain(System.getProperty("java.vm.name").trim());
 124     }
 125 
 126     /**
 127      * Verifies the listed jcmd commands match a certain pattern.
 128      *
 129      * The output of the jcmd commands should look like:
 130      * VM.uptime
 131      * VM.flags
 132      * VM.system_properties
 133      *
 134      * @param output The generated output from the jcmd.
 135      * @throws Exception
 136      */
 137     private static void matchJcmdCommands(OutputAnalyzer output) throws Exception {
 138         int matchedCount = output.shouldMatchByLine(JCMD_COMMAND_REGEX,
 139                 "help",
 140                 JCMD_COMMAND_REGEX);
 141         assertGreaterThan(matchedCount , 0,
 142                 "Found no lines matching pattern: " + JCMD_COMMAND_REGEX);
 143     }
 144 
 145     /**
 146      * Verifies the generated output from the PerfCounter.print command
 147      * matches a certain pattern.
 148      *
 149      * The output of perf counters should look like:
 150      * java.property.java.vm.name="Java HotSpot(TM) 64-Bit Server VM"
 151      * java.threads.daemon=7
 152      * sun.rt.javaCommand="com.sun.javatest.regtest.MainWrapper /tmp/jtreg/jtreg-workdir/classes/sun/tools/jcmd/TestJcmdSanity.jta"
 153      *
 154      * @param output The generated output from the PerfCounter.print command.
 155      * @throws Exception
 156      */
 157     private static void matchPerfCounters(OutputAnalyzer output) throws Exception {
 158         int matchedCount = output.shouldMatchByLineFrom(PERF_COUNTER_REGEX,
 159                 PERF_COUNTER_REGEX);
 160         assertGreaterThan(matchedCount , 0,
 161                 "Found no lines matching pattern: " + PERF_COUNTER_REGEX);
 162     }
 163 
 164     private static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {
 165         Path path = Paths.get(TEST_SRC, "help_help.out");
 166         List<String> fileOutput = Files.readAllLines(path);
 167         List<String> outputAsLines = output.asLines();
 168         assertTrue(outputAsLines.containsAll(fileOutput),
 169                 "The ouput should contain all content of " + path.toAbsolutePath());
 170     }
 171 
 172 }


  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 static jdk.testlibrary.Asserts.*;
  25 
  26 import java.io.File;
  27 import java.io.IOException;
  28 import java.nio.file.Files;
  29 import java.nio.file.Path;
  30 import java.nio.file.Paths;
  31 import java.util.List;
  32 
  33 import jdk.test.lib.process.OutputAnalyzer;
  34 import jdk.test.lib.process.ProcessTools;
  35 import jdk.testlibrary.Utils;
  36 
  37 /*
  38  * @test
  39  * @bug 7104647 7154822
  40  * @summary Unit test for jcmd utility. The test will send different diagnostic
  41  * command requests to the current java process.
  42  *
  43  * @library /lib/testlibrary
  44  * @library /test/lib
  45  *
  46  * @build jdk.testlibrary.*
  47  * @run main/othervm -XX:+UsePerfData TestJcmdSanity
  48  */
  49 public class TestJcmdSanity {
  50 
  51     private static final String TEST_SRC = System.getProperty("test.src").trim();
  52     private static final String[] VM_ARGS = new String[] { "-XX:+UsePerfData" };
  53     private static final String JCMD_COMMAND_REGEX = "(\\w|\\.)*";
  54     private static final String PERF_COUNTER_REGEX = "(\\w|\\.)*\\=.*";
  55 
  56     public static void main(String[] args) throws Exception {
  57         testJcmdPidHelp();
  58         testJcmdPidHelpHelp();
  59         testJcmdPid_f();
  60         testJcmdPidPerfCounterPrint();
  61         testJcmdPidBigScript();
  62     }
  63 
  64     /**


 118         File scrpitFile = new File(TEST_SRC, "dcmd-big-script.txt");
 119         OutputAnalyzer output = JcmdBase.jcmd(VM_ARGS,
 120                 new String[] {"-f", scrpitFile.getAbsolutePath()});
 121 
 122         output.shouldHaveExitValue(0);
 123         output.shouldNotContain("Exception");
 124         output.shouldContain(System.getProperty("java.vm.name").trim());
 125     }
 126 
 127     /**
 128      * Verifies the listed jcmd commands match a certain pattern.
 129      *
 130      * The output of the jcmd commands should look like:
 131      * VM.uptime
 132      * VM.flags
 133      * VM.system_properties
 134      *
 135      * @param output The generated output from the jcmd.
 136      * @throws Exception
 137      */
 138     private static void matchJcmdCommands(OutputAnalyzer output) {
 139         output.shouldMatchByLine(JCMD_COMMAND_REGEX,
 140                 "help",
 141                 JCMD_COMMAND_REGEX);


 142     }
 143 
 144     /**
 145      * Verifies the generated output from the PerfCounter.print command
 146      * matches a certain pattern.
 147      *
 148      * The output of perf counters should look like:
 149      * java.property.java.vm.name="Java HotSpot(TM) 64-Bit Server VM"
 150      * java.threads.daemon=7
 151      * sun.rt.javaCommand="com.sun.javatest.regtest.MainWrapper /tmp/jtreg/jtreg-workdir/classes/sun/tools/jcmd/TestJcmdSanity.jta"
 152      *
 153      * @param output The generated output from the PerfCounter.print command.
 154      * @throws Exception
 155      */
 156     private static void matchPerfCounters(OutputAnalyzer output) {
 157         output.shouldMatchByLineFrom(PERF_COUNTER_REGEX,
 158                 PERF_COUNTER_REGEX);


 159     }
 160 
 161     private static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {
 162         Path path = Paths.get(TEST_SRC, "help_help.out");
 163         List<String> fileOutput = Files.readAllLines(path);
 164         List<String> outputAsLines = output.asLines();
 165         assertTrue(outputAsLines.containsAll(fileOutput),
 166                 "The ouput should contain all content of " + path.toAbsolutePath());
 167     }
 168 
 169 }
< prev index next >