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 22.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.Status command.
037: */
038: public class StatusTest extends JDWPSyncTestCase {
039:
040: protected String getDebuggeeClassName() {
041: return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.StatusDebuggee";
042: }
043:
044: /**
045: * This testcase exercises ThreadReference.Status command for suspended Thread.
046: * <BR>At first the test starts StatusDebuggee which runs
047: * the tested thread.
048: * <BR> At first the test suspends tested thread by ThreadReference.Suspend command.
049: * <BR> Then the tests performs the ThreadReference.Status command
050: * for tested thread.
051: * <BR>It is expected that:
052: * <BR> - returned thread status is RUNNING status;
053: * <BR> - returned suspend status is SUSPEND_STATUS_SUSPENDED status;
054: */
055: public void testStatus002() {
056: synchronizer
057: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
058:
059: // getting ID of the tested thread
060: logWriter.println("get thread ID");
061: long threadID = debuggeeWrapper.vmMirror
062: .getThreadID(StatusDebuggee.TESTED_THREAD);
063: logWriter.println("suspend thread");
064: debuggeeWrapper.vmMirror.suspendThread(threadID);
065:
066: // getting the thread group ID
067: CommandPacket packet = new CommandPacket(
068: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
069: JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
070: packet.setNextValueAsThreadID(threadID);
071:
072: ReplyPacket reply = debuggeeWrapper.vmMirror
073: .performCommand(packet);
074: checkReplyPacket(reply, "ThreadReference::Status command");
075:
076: int threadStatus = reply.getNextValueAsInt();
077: int suspendStatus = reply.getNextValueAsInt();
078:
079: logWriter.println("\t" + threadID + " " + "\""
080: + StatusDebuggee.TESTED_THREAD + "\" "
081: + JDWPConstants.ThreadStatus.getName(threadStatus)
082: + " "
083: + JDWPConstants.SuspendStatus.getName(suspendStatus));
084:
085: if (threadStatus != JDWPConstants.ThreadStatus.RUNNING) {
086: printErrorAndFail("Unexpected thread status: "
087: + JDWPConstants.ThreadStatus.getName(threadStatus));
088: } else {
089: logWriter.println("Expected thread status "
090: + JDWPConstants.ThreadStatus.getName(threadStatus));
091: }
092:
093: if (suspendStatus != JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
094: printErrorAndFail("Unexpected suspend status: "
095: + JDWPConstants.ThreadStatus.getName(suspendStatus));
096: } else {
097: logWriter.println("Expected suspend status "
098: + JDWPConstants.SuspendStatus
099: .getName(suspendStatus));
100: }
101:
102: logWriter.println("resume thread");
103: debuggeeWrapper.vmMirror.resumeThread(threadID);
104:
105: synchronizer
106: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
107: }
108:
109: /**
110: * This testcase exercises ThreadReference.Status command.
111: * <BR>At first the test starts StatusDebuggee which runs
112: * the tested thread.
113: * <BR> Then the tests performs the ThreadReference.Status command
114: * for tested thread.
115: * <BR>It is expected that:
116: * <BR> - returned thread status is RUNNING status;
117: * <BR> - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
118: */
119: public void testStatus001() {
120: synchronizer
121: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
122:
123: // getting ID of the tested thread
124: logWriter.println("get thread ID");
125: long threadID = debuggeeWrapper.vmMirror
126: .getThreadID(StatusDebuggee.TESTED_THREAD);
127:
128: // getting the thread group ID
129: CommandPacket packet = new CommandPacket(
130: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
131: JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
132: packet.setNextValueAsThreadID(threadID);
133:
134: ReplyPacket reply = debuggeeWrapper.vmMirror
135: .performCommand(packet);
136: checkReplyPacket(reply, "ThreadReference::Status command");
137:
138: int threadStatus = reply.getNextValueAsInt();
139: int suspendStatus = reply.getNextValueAsInt();
140:
141: logWriter.println("\t" + threadID + " " + "\""
142: + StatusDebuggee.TESTED_THREAD + "\" "
143: + JDWPConstants.ThreadStatus.getName(threadStatus)
144: + " "
145: + JDWPConstants.SuspendStatus.getName(suspendStatus));
146:
147: if (threadStatus != JDWPConstants.ThreadStatus.RUNNING) {
148: printErrorAndFail("Unexpected thread status: "
149: + JDWPConstants.ThreadStatus.getName(threadStatus));
150: } else {
151: logWriter.println("Expected thread status "
152: + JDWPConstants.ThreadStatus.getName(threadStatus));
153: }
154:
155: if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
156: printErrorAndFail("Unexpected suspend status: "
157: + JDWPConstants.ThreadStatus.getName(suspendStatus));
158: } else {
159: logWriter.println("Expected suspend status "
160: + JDWPConstants.SuspendStatus
161: .getName(suspendStatus));
162: }
163:
164: synchronizer
165: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
166: }
167:
168: public static void main(String[] args) {
169: junit.textui.TestRunner.run(StatusTest.class);
170: }
171: }
|