|
1 /* |
|
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
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.util.ArrayList; |
|
25 import java.util.List; |
|
26 import java.io.IOException; |
|
27 import java.util.stream.Collectors; |
|
28 import java.io.OutputStream; |
|
29 import jdk.test.lib.apps.LingeredApp; |
|
30 import jdk.test.lib.JDKToolLauncher; |
|
31 import jdk.test.lib.Platform; |
|
32 import jdk.test.lib.process.OutputAnalyzer; |
|
33 import jdk.test.lib.Utils; |
|
34 |
|
35 /* |
|
36 * @test |
|
37 * @summary Test the 'intConstant' command of jhsdb clhsdb. |
|
38 * @bug 8190307 |
|
39 * @library /test/lib |
|
40 * @build jdk.test.lib.apps.* |
|
41 * @run main/othervm TestIntConstant |
|
42 */ |
|
43 |
|
44 public class TestIntConstant { |
|
45 |
|
46 private static void testClhsdbForIntConstant( |
|
47 long lingeredAppPid, |
|
48 String commandString, |
|
49 String[] expectedOutputStrings) throws Exception { |
|
50 |
|
51 Process p; |
|
52 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); |
|
53 launcher.addToolArg("clhsdb"); |
|
54 launcher.addToolArg("--pid"); |
|
55 launcher.addToolArg(Long.toString(lingeredAppPid)); |
|
56 |
|
57 ProcessBuilder pb = new ProcessBuilder(); |
|
58 pb.command(launcher.getCommand()); |
|
59 pb.redirectError(ProcessBuilder.Redirect.INHERIT); |
|
60 System.out.println( |
|
61 pb.command().stream().collect(Collectors.joining(" "))); |
|
62 |
|
63 try { |
|
64 p = pb.start(); |
|
65 } catch (Exception attachE) { |
|
66 throw new Error("Couldn't start jhsdb or attach to LingeredApp : " + attachE); |
|
67 } |
|
68 |
|
69 // Issue the 'intConstant' inputs at the clhsdb prompt. |
|
70 OutputStream input = p.getOutputStream(); |
|
71 try { |
|
72 input.write((commandString + "\n").getBytes()); |
|
73 input.write("quit\n".getBytes()); |
|
74 input.flush(); |
|
75 } catch (IOException ioe) { |
|
76 throw new Error("Problem issuing the intConstant command: " + |
|
77 commandString + ioe); |
|
78 } |
|
79 |
|
80 OutputAnalyzer output = new OutputAnalyzer(p); |
|
81 |
|
82 System.out.println("Awaiting process completion"); |
|
83 try { |
|
84 p.waitFor(); |
|
85 } catch (InterruptedException ie) { |
|
86 p.destroyForcibly(); |
|
87 throw new Error("Problem awaiting the child process: " + ie); |
|
88 } |
|
89 |
|
90 output.shouldHaveExitValue(0); |
|
91 System.out.println(output.getOutput()); |
|
92 for (String expectedOutputString: expectedOutputStrings) { |
|
93 output.shouldContain(expectedOutputString); |
|
94 } |
|
95 } |
|
96 |
|
97 public static void testIntConstant() throws Exception { |
|
98 LingeredApp app = null; |
|
99 |
|
100 try { |
|
101 List<String> vmArgs = new ArrayList<String>(); |
|
102 vmArgs.addAll(Utils.getVmOptions()); |
|
103 |
|
104 app = LingeredApp.startApp(vmArgs); |
|
105 System.out.println ("Started LingeredApp with pid " + app.getPid()); |
|
106 |
|
107 // Strings to check for in the output of 'intConstant'. The |
|
108 // 'intConstant' command prints out entries from the |
|
109 // 'gHotSpotVMIntConstants', which is a table of integer constants, |
|
110 // with names and the values derived from enums and #define preprocessor |
|
111 // macros in hotspot. |
|
112 String[] defaultOutputStrings = |
|
113 {"CollectedHeap::G1CollectedHeap 2", |
|
114 "RUNNABLE 2", |
|
115 "Deoptimization::Reason_class_check 4", |
|
116 "InstanceKlass::_misc_is_anonymous 32", |
|
117 "Generation::ParNew 1", |
|
118 "_thread_uninitialized 0"}; |
|
119 String[] tempConstantString = {"intConstant _temp_constant 45"}; |
|
120 testClhsdbForIntConstant(app.getPid(), "intConstant", defaultOutputStrings); |
|
121 testClhsdbForIntConstant( |
|
122 app.getPid(), |
|
123 "intConstant _temp_constant 45\nintConstant _temp_constant", |
|
124 tempConstantString); |
|
125 } finally { |
|
126 LingeredApp.stopApp(app); |
|
127 } |
|
128 } |
|
129 |
|
130 public static void main (String... args) throws Exception { |
|
131 |
|
132 if (!Platform.shouldSAAttach()) { |
|
133 System.out.println( |
|
134 "SA attach not expected to work - test skipped."); |
|
135 return; |
|
136 } |
|
137 |
|
138 try { |
|
139 testIntConstant(); |
|
140 } catch (Exception e) { |
|
141 throw new Error("Test failed with " + e); |
|
142 } |
|
143 } |
|
144 } |