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.4 $
022: */
023:
024: /**
025: * Created on 09.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
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 VirtualMachine.Suspend command.
037: */
038: public class SuspendTest extends JDWPSyncTestCase {
039:
040: protected String getDebuggeeClassName() {
041: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
042: }
043:
044: /**
045: * This testcase exercises VirtualMachine.Suspend command.
046: * <BR>At first the test starts HelloWorld debuggee.
047: * <BR> Then the test performs VirtualMachine.Suspend commands
048: * and checks with help of ThreadReference.Status command that all threads in debuggee
049: * have suspend status = SUSPEND_STATUS_SUSPENDED, i.e. all
050: * debuggee threads are suspended.
051: */
052: public void testSuspend001() {
053: synchronizer
054: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
055:
056: CommandPacket packet = new CommandPacket(
057: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
058: JDWPCommands.VirtualMachineCommandSet.SuspendCommand);
059:
060: ReplyPacket reply = debuggeeWrapper.vmMirror
061: .performCommand(packet);
062: checkReplyPacket(reply, "VirtualMachine::Suspend command");
063:
064: reply = debuggeeWrapper.vmMirror.getAllThreadID();
065:
066: long threadID;
067: int threadStatus, suspendStatus;
068: String threadName;
069: ReplyPacket replyName;
070:
071: int threads = reply.getNextValueAsInt();
072: logWriter.println("Number of threads = " + threads);
073: assertTrue("Invalid number of threads: " + threads, threads > 0);
074:
075: for (int i = 0; i < threads; i++) {
076:
077: threadID = reply.getNextValueAsThreadID();
078: threadName = debuggeeWrapper.vmMirror
079: .getThreadName(threadID);
080:
081: packet = new CommandPacket(
082: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
083: JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
084: packet.setNextValueAsReferenceTypeID(threadID);
085:
086: replyName = debuggeeWrapper.vmMirror.performCommand(packet);
087: checkReplyPacket(reply, "ThreadReference::Status command");
088:
089: threadStatus = replyName.getNextValueAsInt();
090: suspendStatus = replyName.getNextValueAsInt();
091:
092: logWriter.println("\t"
093: + threadID
094: + " "
095: + "\""
096: + threadName
097: + "\" "
098: + JDWPConstants.ThreadStatus.getName(threadStatus)
099: + " "
100: + JDWPConstants.SuspendStatus
101: .getName(suspendStatus));
102: if (suspendStatus != JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
103: printErrorAndFail("thread ID=" + threadID + "; name=\""
104: + threadName + "\""
105: + " is not in suspended state");
106: }
107: }
108:
109: resumeDebuggee();
110: synchronizer
111: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
112: }
113:
114: public static void main(String[] args) {
115: junit.textui.TestRunner.run(SuspendTest.class);
116: }
117: }
|