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 Aleksander V. Budniy
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 14.07.2005
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.EventMod;
030: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
031: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
032: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
033: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
034: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
035:
036: /**
037: * JDWP Unit test for SINGLE_STEP event.
038: */
039: public class SingleStepTest extends JDWPEventTestCase {
040:
041: private String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/SingleStepDebuggee;";
042:
043: private String DEBUGGEE_CLASS_NAME = "org.apache.harmony.jpda.tests.jdwp.Events.SingleStepDebuggee";
044:
045: protected String getDebuggeeClassName() {
046: return DEBUGGEE_CLASS_NAME;
047: }
048:
049: /**
050: * This test case exercises SINGLE_STEP event.<BR>
051: * Runs stepFunction() function four times to checks
052: * SINGLE_STEP event with LINE and OVER steps.
053: *
054: */
055: public void testSingleStep1() {
056: stepFunction(JDWPConstants.StepSize.LINE,
057: JDWPConstants.StepDepth.OVER);
058:
059: }
060:
061: /**
062: * This test case exercises SINGLE_STEP event.<BR>
063: * Runs stepFunction() function four times to checks
064: * SINGLE_STEP event with LINE and INTO steps.
065: *
066: */
067: public void testSingleStep2() {
068: stepFunction(JDWPConstants.StepSize.LINE,
069: JDWPConstants.StepDepth.INTO);
070: }
071:
072: /**
073: * This test case exercises SINGLE_STEP event.<BR>
074: * Runs stepFunction() function four times to checks
075: * SINGLE_STEP event with MIN and OVER steps.
076: *
077: */
078: public void testSingleStep3() {
079: stepFunction(JDWPConstants.StepSize.MIN,
080: JDWPConstants.StepDepth.OVER);
081: }
082:
083: /**
084: * This test case exercises SINGLE_STEP event.<BR>
085: * Runs stepFunction() function four times to checks
086: * SINGLE_STEP event with MIN and INTO steps.
087: *
088: */
089: public void testSingleStep4() {
090: stepFunction(JDWPConstants.StepSize.MIN,
091: JDWPConstants.StepDepth.INTO);
092: }
093:
094: /**
095: * Runs SingleStepDebuggee and sets breakpoint to its
096: * breakpointTest method, sends a request for single step event, then
097: * verifies that requested SINGLE_STEP event with StepSize and StepDepth
098: * steps occurs.
099: */
100:
101: void stepFunction(byte StepSize, byte StepDepth) {
102: logWriter.println("=> testSingleStep started");
103:
104: synchronizer
105: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
106:
107: //find checked method
108: long refTypeID = getClassIDBySignature(debuggeeSignature);
109:
110: logWriter.println("=> Debuggee class = "
111: + getDebuggeeClassName());
112: logWriter.println("=> referenceTypeID for Debuggee class = "
113: + refTypeID);
114: logWriter
115: .println("=> Send ReferenceType::Methods command and get methodIDs ");
116:
117: long requestID = debuggeeWrapper.vmMirror
118: .setBreakpointAtMethodBegin(refTypeID, "breakpointTest");
119: logWriter.println("=> breakpointID = " + requestID);
120: logWriter.println("=> starting thread");
121:
122: //execute the breakpoint
123: synchronizer
124: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
125:
126: long breakpointThreadID = debuggeeWrapper.vmMirror
127: .waitForBreakpoint(requestID);
128:
129: logWriter.println("=> breakpointThreadID = "
130: + breakpointThreadID);
131:
132: // Sending a SINGLE_STEP request
133:
134: CommandPacket setRequestCommand = new CommandPacket(
135: JDWPCommands.EventRequestCommandSet.CommandSetID,
136: JDWPCommands.EventRequestCommandSet.SetCommand);
137:
138: setRequestCommand
139: .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP);
140: setRequestCommand
141: .setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
142: setRequestCommand.setNextValueAsInt(1);
143: setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step);
144: setRequestCommand.setNextValueAsThreadID(breakpointThreadID);
145: setRequestCommand.setNextValueAsInt(StepSize);
146: setRequestCommand.setNextValueAsInt(StepDepth);
147:
148: ReplyPacket setRequestReply = debuggeeWrapper.vmMirror
149: .performCommand(setRequestCommand);
150:
151: checkReplyPacket(setRequestReply, "Set SINGLE_STEP event");
152:
153: requestID = setRequestReply.getNextValueAsInt();
154:
155: logWriter.println("=> RequestID = " + requestID);
156: assertAllDataRead(setRequestReply);
157:
158: //resume debuggee
159: resumeDebuggee();
160:
161: //receive event
162: logWriter.println("==> Wait for SINGLE_STEP event");
163: CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
164: ParsedEvent[] parsedEvents = ParsedEvent
165: .parseEventPacket(event);
166:
167: //check if received event is expected
168: logWriter.println("==> Received " + parsedEvents.length
169: + " events");
170:
171: // trace events
172: for (int i = 0; i < parsedEvents.length; i++) {
173: logWriter.println("");
174: logWriter.println("==> Event #" + i + ";");
175: logWriter.println("==> EventKind: "
176: + parsedEvents[i].getEventKind()
177: + "("
178: + JDWPConstants.EventKind.getName(parsedEvents[i]
179: .getEventKind()) + ")");
180: logWriter.println("==> RequestID: "
181: + parsedEvents[i].getRequestID());
182: }
183:
184: // check all
185: assertEquals("Received wrong number of events,", 1,
186: parsedEvents.length);
187: assertEquals("Received wrong event request ID,", requestID,
188: parsedEvents[0].getRequestID());
189: assertEquals("Invalid event kind,",
190: JDWPConstants.EventKind.SINGLE_STEP, parsedEvents[0]
191: .getEventKind(), JDWPConstants.EventKind
192: .getName(JDWPConstants.EventKind.SINGLE_STEP),
193: JDWPConstants.EventKind.getName(parsedEvents[0]
194: .getEventKind()));
195:
196: // clear SINGLE_STEP event
197: logWriter.println("==> Clearing SINGLE_STEP event..");
198: //ReplyPacket reply =
199: debuggeeWrapper.vmMirror.clearEvent(
200: JDWPConstants.EventKind.SINGLE_STEP, (int) requestID);
201: checkReplyPacket(setRequestReply, "Clear SINGLE_STEP event");
202: logWriter.println("==> SINGLE_STEP event has been cleared");
203:
204: // resuming debuggee
205: logWriter.println("==> Resuming debuggee");
206: resumeDebuggee();
207: logWriter.println("==> Test PASSED!");
208: }
209:
210: public static void main(String[] args) {
211: junit.textui.TestRunner.run(SingleStepTest.class);
212: }
213: }
|