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 Vitaly A. Provodin
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 18.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
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.JDWPConstants;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
033: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for ThreadReference.FrameCount command.
037: */
038: public class FrameCountTest extends JDWPSyncTestCase {
039:
040: protected String getDebuggeeClassName() {
041: return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.FramesDebuggee";
042: }
043:
044: /**
045: * This testcase exercises ThreadReference.CurrentContendedMonitor command.
046: * <BR>At first the test starts FramesDebuggee which recursively invokes
047: * the method 'FramesDebuggee.recursiveMethod' thereby the specified depth
048: * 'FramesDebuggee.DEPTH' of recursion is reached.
049: * <BR> Then the tests requests list of frames for main thread by invoking
050: * the JDWP command ThreadReference.Frames and compares size of
051: * this list with the value got via invoking ThreadReference.FrameCount command.
052: * <BR>The test expects that these values are equal, otherwise the test fail.
053: *
054: */
055: public void testFrameCount001() {
056: logWriter.println("==> testFrameCount001 START ");
057: String testedThreadName = synchronizer.receiveMessage();
058:
059: logWriter.println("==> testedThreadName = |" + testedThreadName
060: + "|");
061: long threadID = debuggeeWrapper.vmMirror
062: .getThreadID(testedThreadName);
063: logWriter.println("==> threadID = " + threadID);
064: debuggeeWrapper.vmMirror.suspendThread(threadID);
065:
066: int expectedCount = getFramesCount(threadID);
067: logWriter.println("\texpected count = " + expectedCount);
068:
069: CommandPacket packet = new CommandPacket(
070: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
071: JDWPCommands.ThreadReferenceCommandSet.FrameCountCommand);
072: packet.setNextValueAsThreadID(threadID);
073: ReplyPacket reply = debuggeeWrapper.vmMirror
074: .performCommand(packet);
075: checkReplyPacket(reply, "ThreadReference::FrameCount command");
076:
077: int frameCount = reply.getNextValueAsInt();
078: logWriter.println("\tframe count = " + frameCount);
079:
080: if (frameCount != expectedCount) {
081: printErrorAndFail("Unexpected frame count = " + frameCount
082: + ", expected value " + expectedCount);
083: }
084: debuggeeWrapper.vmMirror.resumeThread(threadID);
085: synchronizer
086: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
087: }
088:
089: private int getFramesCount(long threadID) {
090:
091: logWriter.println("getting frames of the thread");
092:
093: short err;
094:
095: // getting frames of the thread
096: CommandPacket packet = new CommandPacket(
097: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
098: JDWPCommands.ThreadReferenceCommandSet.FramesCommand);
099: packet.setNextValueAsThreadID(threadID);
100: packet.setNextValueAsInt(0);
101: packet.setNextValueAsInt(-1);
102: ReplyPacket reply = debuggeeWrapper.vmMirror
103: .performCommand(packet);
104: err = reply.getErrorCode();
105: if (err != JDWPConstants.Error.NONE) {
106: logWriter.println("\tthreadID=" + threadID + " - "
107: + JDWPConstants.Error.getName(err));
108: return 0;
109: }
110: int framesCount = reply.getNextValueAsInt();
111: return framesCount;
112: }
113:
114: public static void main(String[] args) {
115: junit.textui.TestRunner.run(FrameCountTest.class);
116: }
117: }
|