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 Anatoly F. Bondarenko
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 31.03.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.Status command for the Thread waiting to enter in locked Monitor.
037: */
038: public class Status005Test extends JDWPSyncTestCase {
039:
040: static final int testStatusPassed = 0;
041: static final int testStatusFailed = -1;
042:
043: protected String getDebuggeeClassName() {
044: return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.Status005Debuggee";
045: }
046:
047: String getThreadSuspendStatusName(int suspendStatus) {
048:
049: String result = JDWPConstants.SuspendStatus
050: .getName(suspendStatus);
051: if (result.equals("")) {
052: result = "NOT_SUSPENDED";
053: }
054: return result;
055: }
056:
057: /**
058: * This testcase exercises ThreadReference.Status command for the Thread waiting to enter in locked Monitor.
059: * <BR>At first the test starts Status005Debuggee which runs
060: * the tested thread and blocks it in entering in synchronized block.
061: * <BR> Then the tests performs the ThreadReference.Status command
062: * for tested thread.
063: * <BR>It is expected that:
064: * <BR> - returned thread status is MONITOR status;
065: * <BR> - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
066: */
067: public void testStatus006() {
068: String this TestName = "testStatus006";
069: logWriter.println("==> " + this TestName
070: + " for ThreadReference.Status command: START...");
071: logWriter
072: .println("==> This "
073: + this TestName
074: + " checks command for BLOCKED Thread: which is waiting to enter in locked Monitor...");
075: //int testStatus = testStatusPassed;
076: String checkedThreadName = synchronizer.receiveMessage();
077: logWriter
078: .println("=> checkedThreadName = " + checkedThreadName);
079:
080: long checkedThreadID = debuggeeWrapper.vmMirror
081: .getThreadID(checkedThreadName);
082: logWriter.println("=> checkedThreadID = " + checkedThreadID);
083:
084: logWriter
085: .println("=> Send ThreadReference.Status command for checked Thread and check reply...");
086: CommandPacket checkedCommand = new CommandPacket(
087: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
088: JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
089: checkedCommand.setNextValueAsThreadID(checkedThreadID);
090:
091: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
092: .performCommand(checkedCommand);
093: checkReplyPacket(checkedReply, "ThreadReference.Status command");
094:
095: int threadStatus = checkedReply.getNextValueAsInt();
096: int suspendStatus = checkedReply.getNextValueAsInt();
097:
098: logWriter.println("\n=> Returned thread status = 0x"
099: + Integer.toHexString(threadStatus) + "("
100: + JDWPConstants.ThreadStatus.getName(threadStatus)
101: + ")");
102: if (threadStatus != JDWPConstants.ThreadStatus.MONITOR) {
103: finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
104: printErrorAndFail("Unexpected thread status is returned:"
105: + "\n Expected thread status = 0x"
106: + Integer
107: .toHexString(JDWPConstants.ThreadStatus.MONITOR)
108: + "("
109: + JDWPConstants.ThreadStatus
110: .getName(JDWPConstants.ThreadStatus.MONITOR)
111: + ")");
112: } else {
113: logWriter
114: .println("=> OK - Expected thread status is returned");
115: }
116:
117: logWriter.println("\n=> Returned thread suspend status = 0x"
118: + Integer.toHexString(suspendStatus) + "("
119: + getThreadSuspendStatusName(suspendStatus) + ")");
120: if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
121: finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
122: printErrorAndFail("Unexpected thread status is returned:"
123: + "\n Expected thread status = 0x"
124: + Integer.toHexString(0) + "("
125: + getThreadSuspendStatusName(0) + ")");
126: } else {
127: logWriter
128: .println("=> OK - Expected thread suspend status is returned");
129: }
130:
131: logWriter.println("=> Send to Debuggee signal to funish ...");
132: synchronizer
133: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
134:
135: logWriter.println("==> " + this TestName
136: + " for ThreadReference.Status command: FINISH...");
137: }
138:
139: public static void main(String[] args) {
140: junit.textui.TestRunner.run(Status005Test.class);
141: }
142: }
|