1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @author Vitaly A. Provodin 21 */ 22 23 /** 24 * Created on 22.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ThreadReference; 27 28 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 29 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 30 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 31 import org.apache.harmony.jpda.tests.framework.jdwp.Value; 32 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 33 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 34 35 36 /** 37 * JDWP Unit test for ThreadReference.Stop command. 38 */ 39 public class StopTest extends JDWPSyncTestCase { 40 41 static String SIGNATURE = getClassSignature(StopDebuggee.class); 42 43 @Override getDebuggeeClassName()44 protected String getDebuggeeClassName() { 45 return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.StopDebuggee"; 46 } 47 48 /** 49 * This testcase exercises ThreadReference.Stop command. 50 * <BR>At first the test starts StopDebuggee which runs 51 * the tested thread 'TESTED_THREAD'. 52 * <BR>After the tested thread starts, the test performs ThreadReference.Stop command 53 * for the tested thread and waits for Debuggee message if the tested thread 54 * is interrupted with NullPointerException. 55 * <BR>If so the test PASSED, otherwise FAILED. 56 */ testStop001()57 public void testStop001() { 58 logWriter.println("testStop001: STARTED..."); 59 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 60 61 // getting ID of the tested thread 62 logWriter.println("testStop001: get threadID to Stop..."); 63 long threadID = 64 debuggeeWrapper.vmMirror.getThreadID(StopDebuggee.TESTED_THREAD); 65 logWriter.println("testStop001: ID of the tested thread to Stop = " + threadID); 66 67 long classID = 68 debuggeeWrapper.vmMirror.getClassID(SIGNATURE); 69 70 long fieldID = 71 debuggeeWrapper.vmMirror.getFieldID(classID, StopDebuggee.FIELD_NAME); 72 73 // getting throwable 74 logWriter.println("testStop001: get throwable for Stop command..."); 75 CommandPacket packet = new CommandPacket( 76 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 77 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); 78 packet.setNextValueAsReferenceTypeID(classID); 79 packet.setNextValueAsInt(1); 80 packet.setNextValueAsFieldID(fieldID); 81 ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 82 checkReplyPacket(reply, "ReferenceType::GetValues command"); 83 84 int values = reply.getNextValueAsInt(); 85 if (values != 1) { 86 logWriter.println("## testStop001: Unexpected number of values = " + values); 87 logWriter.println("## Expected number of values = 1"); 88 fail("Unexpected number of values: " + values + ", expected: 1"); 89 } 90 Value fieldValue = reply.getNextValueAsValue(); 91 logWriter.println("testStop001: throwable = " + fieldValue); 92 93 packet = new CommandPacket( 94 JDWPCommands.ThreadReferenceCommandSet.CommandSetID, 95 JDWPCommands.ThreadReferenceCommandSet.StopCommand); 96 packet.setNextValueAsThreadID(threadID); 97 packet.setNextValueAsObjectID(fieldValue.getLongValue()); 98 logWriter.println("testStop001: send \"Stop\" command"); 99 reply = debuggeeWrapper.vmMirror.performCommand(packet); 100 checkReplyPacket(reply, "ThreadReference::Stop command"); 101 102 logWriter.println("testStop001: wait for Debuggee message about test status..."); 103 String testStatus = synchronizer.receiveMessage(); 104 logWriter.println("testStop001: Received from Debuggee test status = " + testStatus); 105 if ( ! testStatus.equals("PASSED") ) { 106 logWriter.println("## testStop001: FAILED"); 107 fail("Bad message received from debuggee: " + testStatus); 108 } else { 109 logWriter.println("testStop001: PASSED"); 110 } 111 } 112 } 113