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.6 $
022: */
023:
024: /**
025: * Created on 8.7.2005
026: */package org.apache.harmony.jpda.tests.jdwp.MultiSession;
027:
028: import org.apache.harmony.jpda.tests.framework.TestOptions;
029: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
030: import org.apache.harmony.jpda.tests.framework.jdwp.EventMod;
031: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
032: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
033: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
034: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
035: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
036: import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper;
037: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
038:
039: /**
040: * JDWP Unit test for verifying canceling of SINGLE_STEP event after re-connection.
041: */
042: public class SingleStepTest extends JDWPSyncTestCase {
043:
044: private String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/MultiSession/SingleStepDebuggee;";
045:
046: private String DEBUGGEE_CLASS_NAME = "org.apache.harmony.jpda.tests.jdwp.MultiSession.SingleStepDebuggee";
047:
048: protected String getDebuggeeClassName() {
049: return DEBUGGEE_CLASS_NAME;
050: }
051:
052: /**
053: * This testcase verifies canceling of SINGLE_STEP event after re-connection.
054: * <BR>It runs SingleStepDebuggee and sets request for BREAKPOINT event.
055: * After BREAKPOINT event occurs the testcase sets request for SINGLE_STEP event
056: * and re-connects.
057: * <BR>It is expected that only auto VM_DEATH event occurs after re-connection,
058: * but no any other event, including SINGLE_STEP event.
059: */
060: public void testSingleStep001() {
061: stepFunction(JDWPConstants.StepSize.LINE,
062: JDWPConstants.StepDepth.OVER);
063: }
064:
065: void stepFunction(byte StepSize, byte StepDepth) {
066: logWriter.println("=> testSingleStep started");
067:
068: synchronizer
069: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
070:
071: //find checked method
072: long refTypeID = debuggeeWrapper.vmMirror
073: .getClassID(debuggeeSignature);
074:
075: logWriter.println("=> Debuggee class = "
076: + getDebuggeeClassName());
077: logWriter.println("=> referenceTypeID for Debuggee class = "
078: + refTypeID);
079: logWriter
080: .println("=> Send ReferenceType::Methods command and get methodIDs ");
081:
082: long requestID = debuggeeWrapper.vmMirror
083: .setBreakpointAtMethodBegin(refTypeID, "breakpointTest");
084: logWriter.println("=> breakpointID = " + requestID);
085: logWriter.println("=> starting thread");
086:
087: //execute the breakpoint
088: synchronizer
089: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
090:
091: long breakpointThreadID = debuggeeWrapper.vmMirror
092: .waitForBreakpoint(requestID);
093:
094: logWriter.println("=> breakpointThreadID = "
095: + breakpointThreadID);
096:
097: // Sending a SINGLE_STEP request
098:
099: CommandPacket setRequestCommand = new CommandPacket(
100: JDWPCommands.EventRequestCommandSet.CommandSetID,
101: JDWPCommands.EventRequestCommandSet.SetCommand);
102:
103: setRequestCommand
104: .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP);
105: setRequestCommand
106: .setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
107: setRequestCommand.setNextValueAsInt(1);
108: setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step);
109: setRequestCommand.setNextValueAsThreadID(breakpointThreadID);
110: setRequestCommand.setNextValueAsInt(StepSize);
111: setRequestCommand.setNextValueAsInt(StepDepth);
112:
113: ReplyPacket setRequestReply = debuggeeWrapper.vmMirror
114: .performCommand(setRequestCommand);
115:
116: checkReplyPacket(setRequestReply, "Set SINGLE_STEP event");
117:
118: requestID = setRequestReply.getNextValueAsInt();
119: logWriter.println("=> RequestID = " + requestID);
120:
121: assertAllDataRead(setRequestReply);
122:
123: logWriter.println("");
124: logWriter.println("=> CLOSE CONNECTION..");
125: closeConnection();
126: logWriter.println("=> CONNECTION IS CLOSED");
127:
128: logWriter.println("");
129: logWriter.println("=> OPEN NEW CONNECTION..");
130: openConnection();
131: logWriter.println("=> CONNECTION IS OPENED");
132:
133: //resume debuggee
134: //ReplyPacket reply = debuggeeWrapper.vmMirror.resume();
135: synchronizer
136: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
137:
138: // receive event
139: logWriter.println("=> Wait for event..");
140: CommandPacket eventPacket = debuggeeWrapper.vmMirror
141: .receiveEvent();
142: ParsedEvent[] parsedEvents = ParsedEvent
143: .parseEventPacket(eventPacket);
144: int eventsCount = parsedEvents.length;
145: logWriter
146: .println("=> Received event set: count=" + eventsCount);
147:
148: //ckeck if received events are expected
149: int result = 0;
150: int autoEvents = 0;
151: int wrongEvents = 0;
152: for (int i = 0; i < eventsCount; i++) {
153: ParsedEvent event = parsedEvents[i];
154: logWriter.println("=> Event #" + i + ";");
155:
156: // print event info
157: byte eventSuspendPolicy = event.getSuspendPolicy();
158: logWriter.println("=> SuspendPolicy="
159: + eventSuspendPolicy
160: + "/"
161: + JDWPConstants.SuspendPolicy
162: .getName(eventSuspendPolicy));
163: byte eventKind = event.getEventKind();
164: logWriter.println("=> EventKind=" + eventKind + "/"
165: + JDWPConstants.EventKind.getName(eventKind));
166: int eventRequestID = event.getRequestID();
167: logWriter.println("=> RequestID=" + eventRequestID);
168:
169: // check if event is expected
170: if (eventKind == JDWPConstants.EventKind.VM_DEATH) {
171: if (parsedEvents[i].getRequestID() == 0) {
172: autoEvents++;
173: logWriter.println("=> found auto VM_DEATH event!");
174: // for automatical event suspend policy can be changed
175: } else {
176: logWriter.println("## FAILURE: VM_DEATH event "
177: + "with unexpected RequestID: "
178: + eventRequestID);
179: result = 1;
180: }
181: } else {
182: wrongEvents++;
183: logWriter.println("## FAILURE: unexpected event kind: "
184: + eventKind);
185: result = 2;
186: }
187: }
188:
189: if (1 == result)
190: fail("VM_DEATH event with unexpected RequestID");
191: else if (2 == result)
192: fail("Unexpected event kind");
193:
194: logWriter.println("==> testSingleStep001 PASSED!");
195: }
196:
197: protected void beforeDebuggeeStart(
198: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
199: settings.setAttachConnectorKind();
200: if (settings.getTransportAddress() == null) {
201: settings
202: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
203: }
204: logWriter.println("ATTACH connector kind");
205: super .beforeDebuggeeStart(debuggeeWrapper);
206: }
207:
208: public static void main(String[] args) {
209: junit.textui.TestRunner.run(SingleStepTest.class);
210: }
211: }
|