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 sleeping Thread.
037: */
038: public class Status002Test 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.Status002Debuggee";
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 sleeping Thread.
059: * <BR>At first the test starts Status002Debuggee which runs
060: * the tested thread and blocks it in invocation of
061: * the 'Thread.sleep()' method.
062: * <BR> Then the tests performs the ThreadReference.Status command
063: * for tested thread.
064: * <BR>It is expected that:
065: * <BR> - returned thread status is SLEEPING status;
066: * <BR> - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
067: */
068: public void testStatus003() {
069: String this TestName = "testStatus003";
070: logWriter.println("==> " + this TestName
071: + " for ThreadReference.Status command: START...");
072: logWriter
073: .println("==> This "
074: + this TestName
075: + " checks command for SLEEPING Thread: which is sleeping in Thread.sleep(Time) method...");
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.SLEEPING) {
103: finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
104: printErrorAndFail("Unexpected thread status is returned: "
105: + Integer.toHexString(threadStatus)
106: + "("
107: + JDWPConstants.ThreadStatus.getName(threadStatus)
108: + ")"
109: + "\nExpected thread status: 0x"
110: + Integer
111: .toHexString(JDWPConstants.ThreadStatus.SLEEPING)
112: + "("
113: + JDWPConstants.ThreadStatus
114: .getName(JDWPConstants.ThreadStatus.SLEEPING)
115: + ")");
116: } else {
117: logWriter
118: .println("=> OK - Expected thread status is returned");
119: }
120:
121: logWriter.println("\n=> Returned thread suspend status = 0x"
122: + Integer.toHexString(suspendStatus) + "("
123: + getThreadSuspendStatusName(suspendStatus) + ")");
124: if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
125: finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
126: printErrorAndFail("Unexpected thread status is returned:"
127: + Integer.toHexString(0) + "("
128: + getThreadSuspendStatusName(0) + ")");
129: } else {
130: logWriter
131: .println("=> OK - Expected thread suspend status is returned");
132: }
133:
134: logWriter.println("=> Send to Debuggee signal to funish ...");
135: synchronizer
136: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
137:
138: logWriter.println("==> " + this TestName
139: + " for ThreadReference.Status command: FINISH...");
140: }
141:
142: public static void main(String[] args) {
143: junit.textui.TestRunner.run(Status002Test.class);
144: }
145: }
|