001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Anatoly F. Bondarenko
021: * @version $Revision: 1.1 $
022: */
023:
024: /**
025: * Created on 06.10.2006
026: */package org.apache.harmony.jpda.tests.jdwp.Events;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
030: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032: import org.apache.harmony.jpda.tests.framework.jdwp.Location;
033: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for METHOD_ENTRY, METHOD_EXIT events for empty method.
037: */
038: public class CombinedEvents002Test extends CombinedEventsTestCase {
039: static final String TESTED_CLASS_NAME = CombinedEvents002Debuggee.TESTED_CLASS_NAME;
040: static final String TESTED_CLASS_SIGNATURE = CombinedEvents002Debuggee.TESTED_CLASS_SIGNATURE;
041: static final String TESTED_METHOD_NAME = CombinedEvents002Debuggee.TESTED_METHOD_NAME;
042:
043: protected String getDebuggeeClassName() {
044: return CombinedEvents002Debuggee.class.getName();
045: }
046:
047: public static void main(String[] args) {
048: junit.textui.TestRunner.run(CombinedEvents002Test.class);
049: }
050:
051: /**
052: * This testcase is for METHOD_ENTRY, METHOD_EXIT events for empty method.
053: * <BR>It runs CombinedEvents002Debuggee that executed its own empty method
054: * and verify that requested METHOD_ENTRY, METHOD_EXIT events occur
055: * for empty method.
056: */
057: public void testCombinedEvents002_01() {
058: logWriter.println("==> testCombinedEvents002_01: Start...");
059:
060: logWriter
061: .println("==> Wait for SGNL_READY signal from debuggee...");
062: synchronizer
063: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
064: logWriter.println("==> OK - SGNL_READY signal received!");
065:
066: long testedClassID = debuggeeWrapper.vmMirror
067: .getClassID(TESTED_CLASS_SIGNATURE);
068: if (testedClassID == -1) {
069: String failureMessage = "## FAILURE: Can NOT get ClassID for '"
070: + TESTED_CLASS_SIGNATURE + "'";
071: printErrorAndFail(failureMessage);
072: }
073: logWriter.println("==> Tested Class Name = '"
074: + TESTED_CLASS_NAME + "'");
075: logWriter.println("==> testedClassID = " + testedClassID);
076:
077: logWriter.println("==> ");
078: logWriter.println("==> Info for tested method '"
079: + TESTED_METHOD_NAME + "':");
080: long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(
081: testedClassID, TESTED_METHOD_NAME);
082: if (testedMethodID == -1) {
083: String failureMessage = "## FAILURE: Can NOT get MethodID for class '"
084: + TESTED_CLASS_NAME
085: + "'; Method name = "
086: + TESTED_METHOD_NAME;
087: printErrorAndFail(failureMessage);
088: }
089: logWriter.println("==> testedMethodID = " + testedMethodID);
090: printMethodLineTable(testedClassID, null, TESTED_METHOD_NAME);
091: long testedMethodStartCodeIndex = getMethodStartCodeIndex(
092: testedClassID, TESTED_METHOD_NAME);
093: if (testedMethodStartCodeIndex == -1) {
094: String failureMessage = "## FAILURE: Can NOT get MethodStartCodeIndex for method '"
095: + TESTED_METHOD_NAME + "' ";
096: printErrorAndFail(failureMessage);
097: }
098: long testedMethodEndCodeIndex = getMethodEndCodeIndex(
099: testedClassID, TESTED_METHOD_NAME);
100: if (testedMethodEndCodeIndex == -1) {
101: String failureMessage = "## FAILURE: Can NOT get MethodEndCodeIndex for method '"
102: + TESTED_METHOD_NAME + "' ";
103: printErrorAndFail(failureMessage);
104: }
105:
106: logWriter.println("==> ");
107: logWriter
108: .println("==> Set request for METHOD_ENTRY event for '"
109: + TESTED_CLASS_NAME + "'... ");
110: ReplyPacket reply = debuggeeWrapper.vmMirror
111: .setMethodEntry(TESTED_CLASS_NAME);
112: checkReplyPacket(reply, "Set METHOD_ENTRY event."); //DBG needless ?
113: logWriter
114: .println("==> OK - request for METHOD_ENTRY event is set!");
115:
116: logWriter.println("==> Set request for METHOD_EXIT event for '"
117: + TESTED_CLASS_NAME + "'... ");
118: reply = debuggeeWrapper.vmMirror
119: .setMethodExit(TESTED_CLASS_NAME);
120: checkReplyPacket(reply, "Set METHOD_EXIT event."); //DBG needless ?
121: logWriter
122: .println("==> OK - request for METHOD_EXIT event is set!");
123:
124: logWriter
125: .println("==> Send SGNL_CONTINUE signal to debuggee...");
126: synchronizer
127: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
128:
129: logWriter.println("==> ");
130: logWriter.println("==> Receiving events... ");
131: CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
132: ParsedEvent[] parsedEvents = ParsedEvent
133: .parseEventPacket(event);
134: byte[] expectedEventKinds = {
135: JDWPConstants.EventKind.METHOD_ENTRY,
136: JDWPConstants.EventKind.METHOD_EXIT };
137:
138: int receivedEventsNumber = parsedEvents.length;
139: byte[] receivedEventKinds = new byte[(receivedEventsNumber == 1) ? 2
140: : receivedEventsNumber];
141: logWriter
142: .println("==> Number of received events in event packet = "
143: + receivedEventsNumber);
144: for (int i = 0; i < receivedEventsNumber; i++) {
145: receivedEventKinds[i] = parsedEvents[i].getEventKind();
146: logWriter.println("==> Received event["
147: + i
148: + "] kind = "
149: + receivedEventKinds[i]
150: + "("
151: + JDWPConstants.EventKind
152: .getName(receivedEventKinds[i]) + ")");
153: }
154: if (receivedEventsNumber > 2) {
155: String failureMessage = "## FAILURE: Unexpected number of received events in packet = "
156: + receivedEventsNumber
157: + "\n## Expected number of received events in packet = 1 or 2";
158: printErrorAndFail(failureMessage);
159: }
160:
161: logWriter.println("==> ");
162: logWriter.println("==> Check received event #1...");
163: if (receivedEventKinds[0] != expectedEventKinds[0]) {
164: String failureMessage = "## FAILURE: Unexpected event is received: event kind = "
165: + receivedEventKinds[0]
166: + "("
167: + JDWPConstants.EventKind
168: .getName(receivedEventKinds[0])
169: + ")"
170: + "\n## Expected event kind = "
171: + expectedEventKinds[0]
172: + "("
173: + JDWPConstants.EventKind
174: .getName(expectedEventKinds[0]) + ")";
175: printErrorAndFail(failureMessage);
176: }
177: boolean testCaseIsOk = true;
178: Location location = ((ParsedEvent.Event_METHOD_ENTRY) parsedEvents[0])
179: .getLocation();
180: long eventClassID = location.classID;
181: logWriter.println("==> ClassID in event = " + eventClassID);
182: if (testedClassID != eventClassID) {
183: logWriter
184: .println("## FAILURE: Unexpected ClassID in event!");
185: logWriter
186: .println("## Expected ClassID (testedClassID) = "
187: + testedClassID);
188: testCaseIsOk = false;
189: } else {
190: logWriter
191: .println("==> OK - it is expected ClassID (testedClassID)");
192: }
193: long eventMethodID = location.methodID;
194: logWriter.println("==> MethodID in event = " + eventMethodID);
195: if (testedMethodID != eventMethodID) {
196: logWriter
197: .println("## FAILURE: Unexpected MethodID in event!");
198: logWriter
199: .println("## Expected MethodID (testedMethodID) = "
200: + testedMethodID);
201: testCaseIsOk = false;
202: } else {
203: logWriter
204: .println("==> OK - it is expected MethodID (testedMethodID)");
205: }
206: long eventCodeIndex = location.index;
207: logWriter.println("==> CodeIndex in event = " + eventCodeIndex);
208: if (testedMethodStartCodeIndex != eventCodeIndex) {
209: logWriter
210: .println("## FAILURE: Unexpected CodeIndex in event!");
211: logWriter
212: .println("## Expected CodeIndex (testedMethodStartCodeIndex) = "
213: + testedMethodStartCodeIndex);
214: testCaseIsOk = false;
215: } else {
216: logWriter
217: .println("==> OK - it is expected CodeIndex (testedMethodStartCodeIndex)");
218: }
219:
220: if (receivedEventsNumber == 1) {
221: logWriter.println("==> ");
222: logWriter.println("==> Resume debuggee VM...");
223: debuggeeWrapper.vmMirror.resume();
224: logWriter.println("==> Receiving events... ");
225: event = debuggeeWrapper.vmMirror.receiveEvent();
226: parsedEvents = ParsedEvent.parseEventPacket(event);
227:
228: receivedEventsNumber = parsedEvents.length;
229: logWriter
230: .println("==> Number of received events in event packet = "
231: + receivedEventsNumber);
232: receivedEventKinds[1] = parsedEvents[0].getEventKind();
233: for (int i = 0; i < receivedEventsNumber; i++) {
234: logWriter
235: .println("==> Received event["
236: + i
237: + "] kind = "
238: + parsedEvents[i].getEventKind()
239: + "("
240: + JDWPConstants.EventKind
241: .getName(parsedEvents[i]
242: .getEventKind()) + ")");
243: }
244: if (receivedEventsNumber != 1) {
245: String failureMessage = "## FAILURE: Unexpected number of received events in packet = "
246: + receivedEventsNumber
247: + "\n## Expected number of received events in packet = 1";
248: printErrorAndFail(failureMessage);
249: }
250: }
251: logWriter.println("==> ");
252: logWriter.println("==> Check received event #2...");
253: if (receivedEventKinds[1] != expectedEventKinds[1]) {
254: String failureMessage = "## FAILURE: Unexpected event is received: event kind = "
255: + receivedEventKinds[1]
256: + "("
257: + JDWPConstants.EventKind
258: .getName(receivedEventKinds[1])
259: + ")"
260: + "\n## Expected event kind = "
261: + expectedEventKinds[1]
262: + "("
263: + JDWPConstants.EventKind
264: .getName(expectedEventKinds[1]) + ")";
265: printErrorAndFail(failureMessage);
266: }
267: location = ((ParsedEvent.Event_METHOD_EXIT) parsedEvents[0])
268: .getLocation();
269: eventClassID = location.classID;
270: logWriter.println("==> ClassID in event = " + eventClassID);
271: if (testedClassID != eventClassID) {
272: logWriter
273: .println("## FAILURE: Unexpected ClassID in event!");
274: logWriter
275: .println("## Expected ClassID (testedClassID) = "
276: + testedClassID);
277: testCaseIsOk = false;
278: } else {
279: logWriter
280: .println("==> OK - it is expected ClassID (testedClassID)");
281: }
282: eventMethodID = location.methodID;
283: logWriter.println("==> MethodID in event = " + eventMethodID);
284: if (testedMethodID != eventMethodID) {
285: logWriter
286: .println("## FAILURE: Unexpected MethodID in event!");
287: logWriter
288: .println("## Expected MethodID (testedMethodID) = "
289: + testedMethodID);
290: testCaseIsOk = false;
291: } else {
292: logWriter
293: .println("==> OK - it is expected MethodID (testedMethodID)");
294: }
295: eventCodeIndex = location.index;
296: logWriter.println("==> CodeIndex in event = " + eventCodeIndex);
297: if (testedMethodEndCodeIndex != eventCodeIndex) {
298: logWriter
299: .println("## FAILURE: Unexpected CodeIndex in event!");
300: logWriter
301: .println("## Expected CodeIndex (testedMethodEndCodeIndex) = "
302: + testedMethodStartCodeIndex);
303: testCaseIsOk = false;
304: } else {
305: logWriter
306: .println("==> OK - it is expected CodeIndex (testedMethodEndCodeIndex)");
307: }
308: if (!testCaseIsOk) {
309: String failureMessage = "## FAILURE: Unexpected events attributes are found out!";
310: printErrorAndFail(failureMessage);
311: }
312:
313: logWriter.println("==> Resume debuggee VM...");
314: debuggeeWrapper.vmMirror.resume();
315: logWriter.println("==> testCombinedEvents002_01: PASSED! ");
316: }
317: }
|