|
1 /* |
|
2 * Copyright (c) 2001, 2018, 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 package nsk.jdwp.VirtualMachine.ClassesBySignature; |
|
25 |
|
26 import java.io.*; |
|
27 import java.util.*; |
|
28 |
|
29 import nsk.share.*; |
|
30 import nsk.share.jpda.*; |
|
31 import nsk.share.jdwp.*; |
|
32 |
|
33 public class classbysig001 { |
|
34 static final int JCK_STATUS_BASE = 95; |
|
35 static final int PASSED = 0; |
|
36 static final int FAILED = 2; |
|
37 static final String PACKAGE_NAME = "nsk.jdwp.VirtualMachine.ClassesBySignature"; |
|
38 static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "classbysig001"; |
|
39 static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; |
|
40 |
|
41 static final String JDWP_COMMAND_NAME = "VirtualMachine.ClassesBySignature"; |
|
42 static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.ClassesBySignature; |
|
43 |
|
44 static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME; |
|
45 // static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME + ";"; |
|
46 |
|
47 public static void main (String argv[]) { |
|
48 System.exit(run(argv,System.out) + JCK_STATUS_BASE); |
|
49 } |
|
50 |
|
51 public static int run(String argv[], PrintStream out) { |
|
52 return new classbysig001().runIt(argv, out); |
|
53 } |
|
54 |
|
55 public int runIt(String argv[], PrintStream out) { |
|
56 |
|
57 boolean success = true; |
|
58 |
|
59 try { |
|
60 ArgumentHandler argumentHandler = new ArgumentHandler(argv); |
|
61 Log log = new Log(out, argumentHandler); |
|
62 |
|
63 try { |
|
64 |
|
65 Binder binder = new Binder(argumentHandler, log); |
|
66 log.display("Start debugee VM"); |
|
67 Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); |
|
68 Transport transport = debugee.getTransport(); |
|
69 IOPipe pipe = debugee.createIOPipe(); |
|
70 |
|
71 log.display("Waiting for VM_INIT event"); |
|
72 debugee.waitForVMInit(); |
|
73 |
|
74 log.display("Querying for IDSizes"); |
|
75 debugee.queryForIDSizes(); |
|
76 |
|
77 log.display("Resume debugee VM"); |
|
78 debugee.resume(); |
|
79 |
|
80 log.display("Waiting for command: " + "ready"); |
|
81 String cmd = pipe.readln(); |
|
82 log.display("Received command: " + cmd); |
|
83 |
|
84 String classSignature = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; |
|
85 |
|
86 // begin test of JDWP command |
|
87 |
|
88 try { |
|
89 log.display("Create command " + JDWP_COMMAND_NAME |
|
90 + " with class signature: " + classSignature); |
|
91 CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); |
|
92 command.addString(classSignature); |
|
93 command.setLength(); |
|
94 |
|
95 log.display("Sending command packet:\n" + command); |
|
96 transport.write(command); |
|
97 |
|
98 log.display("Waiting for reply packet"); |
|
99 ReplyPacket reply = new ReplyPacket(); |
|
100 transport.read(reply); |
|
101 log.display("Reply packet received:\n" + reply); |
|
102 |
|
103 log.display("Checking reply packet header"); |
|
104 reply.checkHeader(command.getPacketID()); |
|
105 |
|
106 log.display("Parsing reply packet:"); |
|
107 reply.resetPosition(); |
|
108 |
|
109 int classes = reply.getInt(); |
|
110 log.display(" classes: " + classes); |
|
111 |
|
112 for (int i = 0; i < classes; i++) { |
|
113 |
|
114 byte refTypeTag = reply.getByte(); |
|
115 log.display(" " + i + " refTypeTag: " + refTypeTag); |
|
116 |
|
117 long typeID = reply.getReferenceTypeID(); |
|
118 log.display(" " + i + " typeID: " + typeID); |
|
119 |
|
120 int status = reply.getInt(); |
|
121 log.display(" " + i + " status: " + status); |
|
122 } |
|
123 |
|
124 if (! reply.isParsed()) { |
|
125 log.complain("Extra bytes in reply packet at: " + reply.currentPosition()); |
|
126 success = false; |
|
127 } |
|
128 |
|
129 if (classes < 0) { |
|
130 log.complain("Negative number of returned classes: " + classes); |
|
131 success = false; |
|
132 } |
|
133 |
|
134 if (classes == 0) { |
|
135 log.complain("No class returned for signature: " + classSignature); |
|
136 success = false; |
|
137 } |
|
138 |
|
139 if (classes > 1) { |
|
140 log.complain("Too many classes returned for signature: " + classSignature); |
|
141 success = false; |
|
142 } |
|
143 |
|
144 } catch (Exception e) { |
|
145 log.complain("Exception catched: " + e); |
|
146 success = false; |
|
147 } |
|
148 |
|
149 // end test of JDWP command |
|
150 |
|
151 log.display("Sending command: " + "quit"); |
|
152 pipe.println("quit"); |
|
153 |
|
154 log.display("Waiting for debugee exits"); |
|
155 int code = debugee.waitFor(); |
|
156 if (code == JCK_STATUS_BASE + PASSED) { |
|
157 log.display("Debugee PASSED: " + code); |
|
158 } else { |
|
159 log.complain("Debugee FAILED: " + code); |
|
160 success = false; |
|
161 } |
|
162 |
|
163 } catch (Exception e) { |
|
164 log.complain("Unexpected exception: " + e); |
|
165 e.printStackTrace(out); |
|
166 success = false; |
|
167 } |
|
168 |
|
169 if (!success) { |
|
170 log.complain("TEST FAILED"); |
|
171 return FAILED; |
|
172 } |
|
173 |
|
174 } catch (Exception e) { |
|
175 out.println("Unexpected exception: " + e); |
|
176 e.printStackTrace(out); |
|
177 out.println("TEST FAILED"); |
|
178 return FAILED; |
|
179 } |
|
180 |
|
181 out.println("TEST PASSED"); |
|
182 return PASSED; |
|
183 |
|
184 } |
|
185 |
|
186 } |