1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @author Vitaly A. Provodin 21 */ 22 23 /** 24 * Created on 18.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ThreadReference; 27 28 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 29 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 30 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 31 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 32 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 33 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 34 35 36 /** 37 * JDWP Unit test for ThreadReference.FrameCount command. 38 */ 39 public class FrameCountTest extends JDWPSyncTestCase { 40 41 @Override 42 protected String getDebuggeeClassName() { 43 return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.FramesDebuggee"; 44 } 45 46 /** 47 * This testcase exercises ThreadReference.CurrentContendedMonitor command. 48 * <BR>At first the test starts FramesDebuggee which recursively invokes 49 * the method 'FramesDebuggee.recursiveMethod' thereby the specified depth 50 * 'FramesDebuggee.DEPTH' of recursion is reached. 51 * <BR> Then the tests requests list of frames for main thread by invoking 52 * the JDWP command ThreadReference.Frames and compares size of 53 * this list with the value got via invoking ThreadReference.FrameCount command. 54 * <BR>The test expects that these values are equal, otherwise the test fail. 55 * 56 */ 57 public void testFrameCount001() { 58 logWriter.println("==> testFrameCount001 START "); 59 String testedThreadName = synchronizer.receiveMessage(); 60 61 logWriter.println 62 ("==> testedThreadName = |" + testedThreadName +"|"); 63 long threadID = debuggeeWrapper.vmMirror.getThreadID(testedThreadName); 64 logWriter.println("==> threadID = " + threadID); 65 debuggeeWrapper.vmMirror.suspendThread(threadID); 66 67 int expectedCount = getFramesCount(threadID); 68 logWriter.println("\texpected count = " + expectedCount); 69 70 CommandPacket packet = new CommandPacket( 71 JDWPCommands.ThreadReferenceCommandSet.CommandSetID, 72 JDWPCommands.ThreadReferenceCommandSet.FrameCountCommand); 73 packet.setNextValueAsThreadID(threadID); 74 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 75 checkReplyPacket(reply, "ThreadReference::FrameCount command"); 76 77 int frameCount = reply.getNextValueAsInt(); 78 logWriter.println("\tframe count = " + frameCount); 79 80 if (frameCount != expectedCount) { 81 printErrorAndFail("Unexpected frame count = " + frameCount 82 + ", expected value " + expectedCount); 83 } 84 debuggeeWrapper.vmMirror.resumeThread(threadID); 85 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 86 } 87 88 private int getFramesCount(long threadID) { 89 90 logWriter.println("getting frames of the thread"); 91 92 short err; 93 94 // getting frames of the thread 95 CommandPacket packet = new CommandPacket( 96 JDWPCommands.ThreadReferenceCommandSet.CommandSetID, 97 JDWPCommands.ThreadReferenceCommandSet.FramesCommand); 98 packet.setNextValueAsThreadID(threadID); 99 packet.setNextValueAsInt(0); 100 packet.setNextValueAsInt(-1); 101 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 102 err = reply.getErrorCode(); 103 if ( err != JDWPConstants.Error.NONE) { 104 logWriter.println("\tthreadID=" + threadID 105 + " - " + JDWPConstants.Error.getName(err)); 106 return 0; 107 } 108 int framesCount = reply.getNextValueAsInt(); 109 return framesCount; 110 } 111 } 112