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 UNDEFINITELY.
037: */
038: public class Status004Test 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.Status004Debuggee";
045: }
046:
047: String getThreadSuspendStatusName(int suspendStatus) {
048: String result = JDWPConstants.SuspendStatus
049: .getName(suspendStatus);
050: if (result.equals("")) {
051: result = "NOT_SUSPENDED";
052: }
053: return result;
054: }
055:
056: /**
057: * This testcase exercises ThreadReference.Status command for the Thread waiting UNDEFINITELY.
058: * <BR>At first the test starts Status004Debuggee which runs
059: * the tested thread and blocks it in invocation of
060: * the 'Object.wait()' method.
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 WAIT status;
065: * <BR> - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
066: */
067: public void testStatus005() {
068: String this TestName = "testStatus005";
069: logWriter.println("==> " + this TestName
070: + " for ThreadReference.Status command: START...");
071: logWriter
072: .println("==> This "
073: + this TestName
074: + " checks command for WAITING Thread: which is waiting UNDEFINITELY in Object.wait() method...");
075: String checkedThreadName = synchronizer.receiveMessage();
076: logWriter
077: .println("=> checkedThreadName = " + checkedThreadName);
078:
079: long checkedThreadID = debuggeeWrapper.vmMirror
080: .getThreadID(checkedThreadName);
081: logWriter.println("=> checkedThreadID = " + checkedThreadID);
082:
083: logWriter
084: .println("=> Send ThreadReference.Status command for checked Thread and check reply...");
085: CommandPacket checkedCommand = new CommandPacket(
086: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
087: JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
088: checkedCommand.setNextValueAsThreadID(checkedThreadID);
089:
090: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
091: .performCommand(checkedCommand);
092: checkReplyPacket(checkedReply, "ThreadReference.Status command");
093:
094: int threadStatus = checkedReply.getNextValueAsInt();
095: int suspendStatus = checkedReply.getNextValueAsInt();
096:
097: logWriter.println("\n=> Returned thread status = 0x"
098: + Integer.toHexString(threadStatus) + "("
099: + JDWPConstants.ThreadStatus.getName(threadStatus)
100: + ")");
101: if (threadStatus != JDWPConstants.ThreadStatus.WAIT) {
102: finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
103: printErrorAndFail("Unexpected thread status is returned:"
104: + "\n Expected thread status = 0x"
105: + Integer
106: .toHexString(JDWPConstants.ThreadStatus.WAIT)
107: + "("
108: + JDWPConstants.ThreadStatus
109: .getName(JDWPConstants.ThreadStatus.WAIT)
110: + ")");
111: } else {
112: logWriter
113: .println("=> OK - Expected thread status is returned");
114: }
115:
116: logWriter.println("\n=> Returned thread suspend status = 0x"
117: + Integer.toHexString(suspendStatus) + "("
118: + getThreadSuspendStatusName(suspendStatus) + ")");
119: if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
120: finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
121: printErrorAndFail("Unexpected thread status is returned:"
122: + "\n Expected thread status = 0x"
123: + Integer.toHexString(0) + "("
124: + getThreadSuspendStatusName(0) + ")");
125: } else {
126: logWriter
127: .println("=> OK - Expected thread suspend status is returned");
128: }
129:
130: logWriter.println("=> Send to Debuggee signal to funish ...");
131: synchronizer
132: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
133:
134: logWriter.println("==> " + this TestName
135: + " for ThreadReference.Status command: FINISH...");
136: }
137:
138: public static void main(String[] args) {
139: junit.textui.TestRunner.run(Status004Test.class);
140: }
141: }
|