author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 55650 | 56e8c0a3fe9a |
permissions | -rw-r--r-- |
55650
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
1 |
/* |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
4 |
* |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
8 |
* |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
13 |
* accompanied this code). |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
14 |
* |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
18 |
* |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
21 |
* questions. |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
22 |
*/ |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
23 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
24 |
/** |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
25 |
* @test |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
26 |
* @bug 8209790 |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
27 |
* @summary Checks ability for connecting to debug server (jstack, jmap, jinfo, jsnap) |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
28 |
* @requires vm.hasSAandCanAttach |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
29 |
* @requires os.family != "windows" |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
30 |
* @modules java.base/jdk.internal.misc |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
31 |
* @library /test/lib |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
32 |
* |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
33 |
* @run main/othervm DebugdConnectTest |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
34 |
*/ |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
35 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
36 |
import java.io.IOException; |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
37 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
38 |
import jdk.test.lib.JDKToolLauncher; |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
39 |
import jdk.test.lib.apps.LingeredApp; |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
40 |
import jdk.test.lib.process.OutputAnalyzer; |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
41 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
42 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
43 |
public class DebugdConnectTest { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
44 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
45 |
private static OutputAnalyzer runJHSDB(String command, String id) throws IOException, InterruptedException { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
46 |
JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
47 |
jhsdbLauncher.addToolArg(command); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
48 |
jhsdbLauncher.addToolArg("--connect"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
49 |
if (id != null) { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
50 |
jhsdbLauncher.addToolArg(id + "@localhost"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
51 |
} else { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
52 |
jhsdbLauncher.addToolArg("localhost"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
53 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
54 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
55 |
Process jhsdb = (new ProcessBuilder(jhsdbLauncher.getCommand())).start(); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
56 |
OutputAnalyzer out = new OutputAnalyzer(jhsdb); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
57 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
58 |
jhsdb.waitFor(); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
59 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
60 |
System.out.println(out.getStdout()); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
61 |
System.err.println(out.getStderr()); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
62 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
63 |
return out; |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
64 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
65 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
66 |
private static void runJSTACK(String id) throws IOException, InterruptedException { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
67 |
OutputAnalyzer out = runJHSDB("jstack", id); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
68 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
69 |
out.shouldContain("LingeredApp"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
70 |
out.stderrShouldBeEmpty(); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
71 |
out.shouldHaveExitValue(0); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
72 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
73 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
74 |
private static void runJMAP(String id) throws IOException, InterruptedException { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
75 |
OutputAnalyzer out = runJHSDB("jmap", id); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
76 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
77 |
out.shouldContain("JVM version is"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
78 |
out.stderrShouldBeEmpty(); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
79 |
out.shouldHaveExitValue(0); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
80 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
81 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
82 |
private static void runJINFO(String id) throws IOException, InterruptedException { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
83 |
OutputAnalyzer out = runJHSDB("jinfo", id); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
84 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
85 |
out.shouldContain("Java System Properties:"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
86 |
out.stderrShouldBeEmpty(); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
87 |
out.shouldHaveExitValue(0); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
88 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
89 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
90 |
private static void runJSNAP(String id) throws IOException, InterruptedException { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
91 |
OutputAnalyzer out = runJHSDB("jsnap", id); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
92 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
93 |
out.shouldContain("java.vm.name="); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
94 |
out.stderrShouldBeEmpty(); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
95 |
out.shouldHaveExitValue(0); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
96 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
97 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
98 |
private static void runTests(String id, long debuggeePid) throws IOException, InterruptedException { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
99 |
DebugdUtils debugd = new DebugdUtils(id); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
100 |
debugd.attach(debuggeePid); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
101 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
102 |
try { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
103 |
runJSTACK(id); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
104 |
runJMAP(id); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
105 |
runJINFO(id); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
106 |
runJSNAP(id); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
107 |
} finally { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
108 |
debugd.detach(); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
109 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
110 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
111 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
112 |
public static void main(String[] args) throws Exception { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
113 |
LingeredApp app = null; |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
114 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
115 |
try { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
116 |
app = LingeredApp.startApp(); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
117 |
System.out.println("Started LingeredApp with pid " + app.getPid()); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
118 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
119 |
System.out.println("debugd connection test with server id:"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
120 |
runTests("test", app.getPid()); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
121 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
122 |
System.out.println("debugd connection test without server id:"); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
123 |
runTests(null, app.getPid()); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
124 |
} finally { |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
125 |
LingeredApp.stopApp(app); |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
126 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
127 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
128 |
} |
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
129 |
|
56e8c0a3fe9a
8209790: SA tools not providing option to connect to debug server
ysuenaga
parents:
diff
changeset
|
130 |
} |