8190307: SA tests for the clhsdb commands: universe, intconstant, type
authorjgeorge
Thu, 16 Nov 2017 11:58:20 +0530
changeset 47900 75d365bfc2e6
parent 47899 f113d1ef7bed
child 47901 4c42aa431f40
8190307: SA tests for the clhsdb commands: universe, intconstant, type Summary: SA Test cases for the clhsdb commands: universe, intconstant, type Reviewed-by: dholmes, sballal
test/hotspot/jtreg/serviceability/sa/TestIntConstant.java
test/hotspot/jtreg/serviceability/sa/TestType.java
test/hotspot/jtreg/serviceability/sa/TestUniverse.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/serviceability/sa/TestIntConstant.java	Thu Nov 16 11:58:20 2017 +0530
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.io.IOException;
+import java.util.stream.Collectors;
+import java.io.OutputStream;
+import jdk.test.lib.apps.LingeredApp;
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Platform;
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.Utils;
+
+/*
+ * @test
+ * @summary Test the 'intConstant' command of jhsdb clhsdb.
+ * @bug 8190307
+ * @library /test/lib
+ * @build jdk.test.lib.apps.*
+ * @run main/othervm TestIntConstant
+ */
+
+public class TestIntConstant {
+
+    private static void testClhsdbForIntConstant(
+                        long lingeredAppPid,
+                        String commandString,
+                        String[] expectedOutputStrings) throws Exception {
+
+        Process p;
+        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addToolArg("clhsdb");
+        launcher.addToolArg("--pid");
+        launcher.addToolArg(Long.toString(lingeredAppPid));
+
+        ProcessBuilder pb = new ProcessBuilder();
+        pb.command(launcher.getCommand());
+        pb.redirectError(ProcessBuilder.Redirect.INHERIT);
+        System.out.println(
+            pb.command().stream().collect(Collectors.joining(" ")));
+
+        try {
+            p = pb.start();
+        } catch (Exception attachE) {
+            throw new Error("Couldn't start jhsdb or attach to LingeredApp : " + attachE);
+        }
+
+        // Issue the 'intConstant' inputs at the clhsdb prompt.
+        OutputStream input = p.getOutputStream();
+        try {
+            input.write((commandString + "\n").getBytes());
+            input.write("quit\n".getBytes());
+            input.flush();
+        } catch (IOException ioe) {
+            throw new Error("Problem issuing the intConstant command: " +
+                            commandString + ioe);
+        }
+
+        OutputAnalyzer output = new OutputAnalyzer(p);
+
+        System.out.println("Awaiting process completion");
+        try {
+            p.waitFor();
+        } catch (InterruptedException ie) {
+            p.destroyForcibly();
+            throw new Error("Problem awaiting the child process: " + ie);
+        }
+
+        output.shouldHaveExitValue(0);
+        System.out.println(output.getOutput());
+        for (String expectedOutputString: expectedOutputStrings) {
+            output.shouldContain(expectedOutputString);
+        }
+    }
+
+    public static void testIntConstant() throws Exception {
+        LingeredApp app = null;
+
+        try {
+            List<String> vmArgs = new ArrayList<String>();
+            vmArgs.addAll(Utils.getVmOptions());
+
+            app = LingeredApp.startApp(vmArgs);
+            System.out.println ("Started LingeredApp with pid " + app.getPid());
+
+            // Strings to check for in the output of 'intConstant'. The
+            // 'intConstant' command prints out entries from the
+            // 'gHotSpotVMIntConstants', which is a table of integer constants,
+            // with names and the values derived from enums and #define preprocessor
+            // macros in hotspot.
+            String[] defaultOutputStrings =
+                {"CollectedHeap::G1CollectedHeap 2",
+                 "RUNNABLE 2",
+                 "Deoptimization::Reason_class_check 4",
+                 "InstanceKlass::_misc_is_anonymous 32",
+                 "Generation::ParNew 1",
+                 "_thread_uninitialized 0"};
+            String[] tempConstantString = {"intConstant _temp_constant 45"};
+            testClhsdbForIntConstant(app.getPid(), "intConstant", defaultOutputStrings);
+            testClhsdbForIntConstant(
+                app.getPid(),
+                "intConstant _temp_constant 45\nintConstant _temp_constant",
+                tempConstantString);
+          } finally {
+              LingeredApp.stopApp(app);
+          }
+    }
+
+    public static void main (String... args) throws Exception {
+
+        if (!Platform.shouldSAAttach()) {
+            System.out.println(
+               "SA attach not expected to work - test skipped.");
+            return;
+        }
+
+        try {
+            testIntConstant();
+        } catch (Exception e) {
+            throw new Error("Test failed with " + e);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/serviceability/sa/TestType.java	Thu Nov 16 11:58:20 2017 +0530
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.io.IOException;
+import java.util.stream.Collectors;
+import java.io.OutputStream;
+import jdk.test.lib.apps.LingeredApp;
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Platform;
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.Utils;
+
+/*
+ * @test
+ * @summary Test the 'type' command of jhsdb clhsdb.
+ * @bug 8190307
+ * @library /test/lib
+ * @build jdk.test.lib.apps.*
+ * @run main/othervm TestType
+ */
+
+public class TestType {
+
+    private static void testClhsdbForType(
+                        long lingeredAppPid,
+                        String commandString,
+                        String[] expectedOutputStrings) throws Exception {
+
+        Process p;
+        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addToolArg("clhsdb");
+        launcher.addToolArg("--pid");
+        launcher.addToolArg(Long.toString(lingeredAppPid));
+
+        ProcessBuilder pb = new ProcessBuilder();
+        pb.command(launcher.getCommand());
+        System.out.println(
+            pb.command().stream().collect(Collectors.joining(" ")));
+
+        try {
+            p = pb.start();
+        } catch (Exception attachE) {
+            throw new Error("Couldn't start jhsdb or attach to LingeredApp : " + attachE);
+        }
+
+        // Issue the 'type' commands at the clhsdb prompt.
+        OutputStream input = p.getOutputStream();
+        try {
+            input.write((commandString + "\n").getBytes());
+            input.write("quit\n".getBytes());
+            input.flush();
+        } catch (IOException ioe) {
+            throw new Error("Problem issuing the 'type' command ", ioe);
+        }
+
+        OutputAnalyzer output = new OutputAnalyzer(p);
+
+        try {
+            p.waitFor();
+        } catch (InterruptedException ie) {
+            p.destroyForcibly();
+            throw new Error("Problem awaiting the child process: " + ie);
+        }
+
+        output.shouldHaveExitValue(0);
+        System.out.println(output.getOutput());
+
+        for (String expectedOutputString: expectedOutputStrings) {
+            output.shouldContain(expectedOutputString);
+        }
+    }
+
+    public static void main (String... args) throws Exception {
+        LingeredApp app = null;
+
+        if (!Platform.shouldSAAttach()) {
+            System.out.println(
+               "SA attach not expected to work - test skipped.");
+            return;
+        }
+
+        try {
+            List<String> vmArgs = new ArrayList<String>();
+            vmArgs.addAll(Utils.getVmOptions());
+            // Strings to check for in the output of 'type'. The 'type'
+            // command prints out entries from 'gHotSpotVMTypes', which
+            // is a table containing the hotspot types, their supertypes,
+            // sizes, etc, which are of interest to the SA.
+            String[] defaultOutputStrings =
+                {"type G1CollectedHeap CollectedHeap",
+                 "type ConstantPoolCache MetaspaceObj",
+                 "type ConstantPool Metadata",
+                 "type CompilerThread JavaThread",
+                 "type CardGeneration Generation",
+                 "type ArrayKlass Klass",
+                 "type InstanceKlass Klass"};
+            // String to check for in the output of "type InstanceKlass"
+            String[] instanceKlassOutputString = {"type InstanceKlass Klass"};
+
+            app = LingeredApp.startApp(vmArgs);
+            System.out.println ("Started LingeredApp with pid " + app.getPid());
+            testClhsdbForType(app.getPid(), "type", defaultOutputStrings);
+            testClhsdbForType(app.getPid(),
+                              "type InstanceKlass",
+                              instanceKlassOutputString);
+        } finally {
+            LingeredApp.stopApp(app);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/serviceability/sa/TestUniverse.java	Thu Nov 16 11:58:20 2017 +0530
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.io.IOException;
+import java.util.stream.Collectors;
+import java.io.OutputStream;
+import jdk.test.lib.apps.LingeredApp;
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Platform;
+import jdk.test.lib.process.OutputAnalyzer;
+
+/*
+ * @test
+ * @summary Test the 'universe' command of jhsdb clhsdb.
+ * @bug 8190307
+ * @library /test/lib
+ * @build jdk.test.lib.apps.*
+ * @run main/othervm TestUniverse
+ */
+
+public class TestUniverse {
+
+    private static void testClhsdbForUniverse(long lingeredAppPid,
+                                              String gc) throws Exception {
+
+        Process p;
+        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addToolArg("clhsdb");
+        launcher.addToolArg("--pid");
+        launcher.addToolArg(Long.toString(lingeredAppPid));
+
+        ProcessBuilder pb = new ProcessBuilder();
+        pb.command(launcher.getCommand());
+        System.out.println(
+            pb.command().stream().collect(Collectors.joining(" ")));
+
+        try {
+            p = pb.start();
+        } catch (Exception attachE) {
+            throw new Error("Couldn't start jhsdb or attach to LingeredApp : " + attachE);
+        }
+
+        // Issue the 'universe' command at the clhsdb prompt.
+        OutputStream input = p.getOutputStream();
+        try {
+            input.write("universe\n".getBytes());
+            input.write("quit\n".getBytes());
+            input.flush();
+        } catch (IOException ioe) {
+            throw new Error("Problem issuing the 'universe' command ", ioe);
+        }
+
+        OutputAnalyzer output = new OutputAnalyzer(p);
+
+        try {
+            p.waitFor();
+        } catch (InterruptedException ie) {
+            p.destroyForcibly();
+            throw new Error("Problem awaiting the child process: " + ie, ie);
+        }
+
+        output.shouldHaveExitValue(0);
+        System.out.println(output.getOutput());
+
+        output.shouldContain("Heap Parameters");
+        if (gc.contains("G1GC")) {
+            output.shouldContain("garbage-first heap");
+        }
+        if (gc.contains("UseConcMarkSweepGC")) {
+            output.shouldContain("Gen 1: concurrent mark-sweep generation");
+        }
+        if (gc.contains("UseSerialGC")) {
+            output.shouldContain("Gen 1:   old");
+        }
+        if (gc.contains("UseParallelGC")) {
+            output.shouldContain("ParallelScavengeHeap");
+            output.shouldContain("PSYoungGen");
+            output.shouldContain("eden");
+        }
+
+    }
+
+    public static void test(String gc) throws Exception {
+        LingeredApp app = null;
+        try {
+            List<String> vmArgs = new ArrayList<String>();
+            vmArgs.add(gc);
+            app = LingeredApp.startApp(vmArgs);
+            System.out.println ("Started LingeredApp with the GC option " + gc +
+                                " and pid " + app.getPid());
+            testClhsdbForUniverse(app.getPid(), gc);
+        } finally {
+            LingeredApp.stopApp(app);
+        }
+    }
+
+
+    public static void main (String... args) throws Exception {
+
+        if (!Platform.shouldSAAttach()) {
+            System.out.println(
+               "SA attach not expected to work - test skipped.");
+            return;
+        }
+
+        try {
+            test("-XX:+UseG1GC");
+            test("-XX:+UseParallelGC");
+            test("-XX:+UseSerialGC");
+            test("-XX:+UseConcMarkSweepGC");
+        } catch (Exception e) {
+            throw new Error("Test failed with " + e);
+        }
+    }
+}