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 Anton V. Karnachuk, Aleksander V. Budniy
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 16.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.StackFrame;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
031: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
032:
033: /**
034: * JDWP Unit test for StackFrame.PopFrames command.
035: */
036: public class PopFramesTest extends JDWPStackFrameTestCase {
037:
038: private String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/StackFrame/PopFramesDebuggee;";
039:
040: private String breakpointMethodName = "nestledMethod4";
041:
042: private String methodToPop = "nestledMethod4";
043:
044: protected String getDebuggeeClassName() {
045: return PopFramesDebuggee.class.getName();
046: }
047:
048: /**
049: * This testcase exercises StackFrame.PopFrames command to discard one top frame.
050: * <BR>The test starts PopFramesDebuggee class, sets a breakpoint
051: * in 'nestledMethod4', stops at breakpoint and prints stack.
052: * <BR>Then the test performs StackFrame.PopFrame command for one top frame,
053: * prints stack and checks that discarded frame is not returned
054: * by ThreadReference.Frames command.
055: * <BR>Then the test resumes debuggee and checks stop on the same breakpoint.
056: */
057: public void testPopFramesTest001() {
058: logWriter.println("==> testPopFramesTest001 started");
059:
060: //check capability, relevant for this test
061: logWriter.println("=> Check capability: canPopFrames");
062: debuggeeWrapper.vmMirror.capabilities();
063: boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canPopFrames;
064: if (!isCapability) {
065: logWriter
066: .println("##WARNING: this VM doesn't possess capability: canPopFrames");
067: return;
068: }
069:
070: synchronizer
071: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
072:
073: // find checked method
074: long refTypeID = getClassIDBySignature(debuggeeSignature);
075:
076: logWriter.println("=> Debuggee class = "
077: + getDebuggeeClassName());
078:
079: logWriter.println("=> Set breakpoint at the beginning of "
080: + breakpointMethodName);
081: long requestID = debuggeeWrapper.vmMirror
082: .setBreakpointAtMethodBegin(refTypeID,
083: breakpointMethodName);
084:
085: synchronizer
086: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
087:
088: // receive event
089: logWriter.println("=> Wait for breakpoint in "
090: + breakpointMethodName);
091: long breakpointThreadID = debuggeeWrapper.vmMirror
092: .waitForBreakpoint(requestID);
093:
094: logWriter.println("=> breakpointThreadID = "
095: + breakpointThreadID);
096:
097: // print stack frames
098: logWriter.println("");
099: logWriter
100: .println("=> Get frames before PopFrames command, thread = "
101: + breakpointThreadID);
102: FrameInfo[] frameInfos = jdwpGetFrames(breakpointThreadID, 0,
103: -1);
104: logWriter.println("=> Frames before popFrame");
105: printStackFrame(frameInfos.length, frameInfos);
106: logWriter.println("=> Number of frames before command: "
107: + frameInfos.length);
108:
109: // find stack frame for popped method
110: logWriter.println("");
111: logWriter.println("=> Find frameID of method = " + methodToPop
112: + " for PopFrames command");
113: long frameID = 0;
114: long methodID = getMethodID(refTypeID, methodToPop);
115: if (methodID == -1) {
116: logWriter
117: .println("##FAILURE: error during getting methodID of "
118: + methodToPop);
119: }
120: boolean isMethodFound = false;
121: for (int i = 0; i < frameInfos.length; i++) {
122: if (frameInfos[i].location.methodID == methodID) {
123: frameID = frameInfos[i].getFrameID();
124: isMethodFound = true;
125: break;
126: }
127: }
128: if (!isMethodFound) {
129: logWriter
130: .println("##FAILURE: there is no frame for checked method");
131: fail("There is no frame for checked method");
132: }
133:
134: logWriter.println("=> frameID for PopFrames command = "
135: + frameID);
136:
137: logWriter.println("");
138: logWriter.println("=> Perform PopFrames command for method = "
139: + methodToPop + " with frameID = " + frameID);
140: // pop stack frame
141: CommandPacket popFramesCommand = new CommandPacket(
142: JDWPCommands.StackFrameCommandSet.CommandSetID,
143: JDWPCommands.StackFrameCommandSet.PopFramesCommand);
144: popFramesCommand.setNextValueAsThreadID(breakpointThreadID);
145: popFramesCommand.setNextValueAsFrameID(frameID);
146:
147: ReplyPacket err = debuggeeWrapper.vmMirror
148: .performCommand(popFramesCommand);
149: checkReplyPacket(err, "StackFrame::PopFrames command");
150:
151: logWriter
152: .println("=> Get frames after PopFrames command, thread = "
153: + breakpointThreadID);
154: FrameInfo[] newFrameInfos = jdwpGetFrames(breakpointThreadID,
155: 0, -1);
156:
157: logWriter.println("");
158: logWriter.println("=> Frames after popFrame");
159: logWriter.println("=> newNumberOfFrames = "
160: + newFrameInfos.length);
161:
162: printStackFrame(newFrameInfos.length, newFrameInfos);
163:
164: // check if expected frames are popped
165: logWriter
166: .println("=> Check that only one frame was discarded: frameID = "
167: + frameID + ", method = " + methodToPop);
168: int numberOfPoppedFrames = frameInfos.length
169: - newFrameInfos.length;
170: assertEquals("frame is not discarded", numberOfPoppedFrames, 1);
171:
172: for (int i = numberOfPoppedFrames; i < (frameInfos.length); i++) {
173: if (frameInfos[i].location.methodID != newFrameInfos[i
174: - numberOfPoppedFrames].location.methodID) {
175: logWriter.println("## FAILURE: frames number " + i
176: + " and " + (i - numberOfPoppedFrames)
177: + " are not equal");
178: fail("frames number are not equal");
179: }
180: }
181: logWriter.println("=> Ckeck PASSED");
182: logWriter.println("=> Resume debuggee");
183: debuggeeWrapper.vmMirror.resume();
184:
185: logWriter.println("=> Wait for breakpoint in "
186: + breakpointMethodName);
187: breakpointThreadID = debuggeeWrapper.vmMirror
188: .waitForBreakpoint(requestID);
189:
190: logWriter.println("=> Resume debuggee");
191: debuggeeWrapper.vmMirror.resume();
192:
193: synchronizer
194: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
195: synchronizer
196: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
197:
198: logWriter.println("==> TEST PASSED");
199:
200: }
201:
202: void printStackFrame(int NumberOfFrames, FrameInfo[] frameInfos) {
203: for (int i = 0; i < NumberOfFrames; i++) {
204: logWriter.println(" ");
205: logWriter.println("=> #" + i + " frameID="
206: + frameInfos[i].frameID);
207: String methodName = getMethodName(
208: frameInfos[i].location.classID,
209: frameInfos[i].location.methodID);
210: logWriter.println("=> method name=" + methodName);
211: }
212: logWriter.println(" ");
213: }
214:
215: public static void main(String[] args) {
216: junit.textui.TestRunner.run(PopFramesTest.class);
217: }
218: }
|