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.ReplyPacket;
031: import org.apache.harmony.jpda.tests.framework.jdwp.Value;
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.Stop command.
037: */
038: public class StopTest extends JDWPSyncTestCase {
039:
040: static String SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/ThreadReference/StopDebuggee;";
041:
042: protected String getDebuggeeClassName() {
043: return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.StopDebuggee";
044: }
045:
046: /**
047: * This testcase exercises ThreadReference.Stop command.
048: * <BR>At first the test starts StopDebuggee which runs
049: * the tested thread 'TESTED_THREAD'.
050: * <BR>After the tested thread starts, the test performs ThreadReference.Stop command
051: * for the tested thread and waits for Debuggee message if the tested thread
052: * is interrupted with NullPointerException.
053: * <BR>If so the test PASSED, otherwise FAILED.
054: */
055: public void testStop001() {
056: logWriter.println("testStop001: STARTED...");
057: synchronizer
058: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
059:
060: // getting ID of the tested thread
061: logWriter.println("testStop001: get threadID to Stop...");
062: long threadID = debuggeeWrapper.vmMirror
063: .getThreadID(StopDebuggee.TESTED_THREAD);
064: logWriter
065: .println("testStop001: ID of the tested thread to Stop = "
066: + threadID);
067:
068: long classID = debuggeeWrapper.vmMirror.getClassID(SIGNATURE);
069:
070: long fieldID = debuggeeWrapper.vmMirror.getFieldID(classID,
071: StopDebuggee.FIELD_NAME);
072:
073: // getting throwable
074: logWriter
075: .println("testStop001: get throwable for Stop command...");
076: CommandPacket packet = new CommandPacket(
077: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
078: JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
079: packet.setNextValueAsReferenceTypeID(classID);
080: packet.setNextValueAsInt(1);
081: packet.setNextValueAsFieldID(fieldID);
082: ReplyPacket reply = debuggeeWrapper.vmMirror
083: .performCommand(packet);
084: checkReplyPacket(reply, "ReferenceType::GetValues command");
085:
086: int values = reply.getNextValueAsInt();
087: if (values != 1) {
088: logWriter
089: .println("## testStop001: Unexpected number of values = "
090: + values);
091: logWriter.println("## Expected number of values = 1");
092: fail("Unexpected number of values: " + values
093: + ", expected: 1");
094: }
095: Value fieldValue = reply.getNextValueAsValue();
096: logWriter.println("testStop001: throwable = " + fieldValue);
097:
098: packet = new CommandPacket(
099: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
100: JDWPCommands.ThreadReferenceCommandSet.StopCommand);
101: packet.setNextValueAsThreadID(threadID);
102: packet.setNextValueAsObjectID(fieldValue.getLongValue());
103: logWriter.println("testStop001: send \"Stop\" command");
104: reply = debuggeeWrapper.vmMirror.performCommand(packet);
105: checkReplyPacket(reply, "ThreadReference::Stop command");
106:
107: logWriter
108: .println("testStop001: wait for Debuggee message about test status...");
109: String testStatus = synchronizer.receiveMessage();
110: logWriter
111: .println("testStop001: Received from Debuggee test status = "
112: + testStatus);
113: if (!testStatus.equals("PASSED")) {
114: logWriter.println("## testStop001: FAILED");
115: fail("Bad message received from debuggee: " + testStatus);
116: } else {
117: logWriter.println("testStop001: PASSED");
118: }
119: }
120:
121: public static void main(String[] args) {
122: junit.textui.TestRunner.run(StopTest.class);
123: }
124: }
|