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.5 $
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 which has started and finished.
037: */
038: public class Status006Test 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.Status006Debuggee";
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 which has started and finished.
058: * <BR>At first the test starts Status006Debuggee which runs
059: * the tested thread which starts and finishes.
060: * <BR> Then the tests performs the ThreadReference.Status command
061: * for tested thread.
062: * <BR>It is expected that:
063: * <BR> - returned thread status is ZOMBIE status;
064: * <BR> - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
065: */
066: public void testStatus007() {
067: String this TestName = "testStatus007";
068: logWriter.println("==> " + this TestName
069: + " for ThreadReference.Status command: START...");
070: logWriter
071: .println("==> This "
072: + this TestName
073: + " checks command for TERMINATED Thread: which has started and finished...");
074: // String checkedThreadName = synchronizer.receiveMessage();
075: String checkedThreadName = synchronizer
076: .receiveMessageWithoutException("ThreadReference.Status006Test: testStatus007(#1)");
077: logWriter
078: .println("=> checkedThreadName = " + checkedThreadName);
079: if (checkedThreadName.startsWith("Exception:")) {
080: logWriter
081: .println("=> Can NOT get checkedThreadName => test con NOT be executed!");
082: return;
083: }
084:
085: long checkedThreadID = debuggeeWrapper.vmMirror
086: .getThreadID(checkedThreadName);
087: logWriter.println("=> checkedThreadID = " + checkedThreadID);
088:
089: logWriter.println("=> Send to Debuggee signal to continue ...");
090: synchronizer
091: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
092: // synchronizer.receiveMessage();
093: synchronizer
094: .receiveMessageWithoutException("ThreadReference.Status006Test: testStatus007(#2)");
095:
096: logWriter
097: .println("=> Send ThreadReference.Status command for checked Thread and check reply...");
098: CommandPacket checkedCommand = new CommandPacket(
099: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
100: JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
101: checkedCommand.setNextValueAsThreadID(checkedThreadID);
102:
103: ReplyPacket checkedReply = debuggeeWrapper.vmMirror
104: .performCommand(checkedCommand);
105: checkReplyPacket(checkedReply, "ThreadReference.Status command");
106:
107: int threadStatus = checkedReply.getNextValueAsInt();
108: int suspendStatus = checkedReply.getNextValueAsInt();
109:
110: logWriter.println("\n=> Returned thread status = 0x"
111: + Integer.toHexString(threadStatus) + "("
112: + JDWPConstants.ThreadStatus.getName(threadStatus)
113: + ")");
114: if (threadStatus != JDWPConstants.ThreadStatus.ZOMBIE) {
115: finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
116: printErrorAndFail("Unexpected thread status is returned:"
117: + "\n Expected thread status = 0x"
118: + Integer
119: .toHexString(JDWPConstants.ThreadStatus.ZOMBIE)
120: + "("
121: + JDWPConstants.ThreadStatus
122: .getName(JDWPConstants.ThreadStatus.ZOMBIE)
123: + ")");
124: } else {
125: logWriter
126: .println("=> OK - Expected thread status is returned");
127: }
128:
129: logWriter.println("\n=> Returned thread suspend status = 0x"
130: + Integer.toHexString(suspendStatus) + "("
131: + getThreadSuspendStatusName(suspendStatus) + ")");
132: if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
133: finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
134: printErrorAndFail("Unexpected thread status is returned:"
135: + "\n Expected thread status = 0x"
136: + Integer.toHexString(0) + "("
137: + getThreadSuspendStatusName(0) + ")");
138: } else {
139: logWriter
140: .println("=> OK - Expected thread suspend status is returned");
141: }
142:
143: logWriter.println("=> Send to Debuggee signal to funish ...");
144: synchronizer
145: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
146:
147: logWriter.println("==> " + this TestName
148: + " for ThreadReference.Status command: FINISH...");
149: }
150:
151: public static void main(String[] args) {
152: junit.textui.TestRunner.run(Status006Test.class);
153: }
154: }
|