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 Aleksander V. Budniy 21 */ 22 23 /** 24 * Created on 8.7.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.MultiSession; 27 28 import org.apache.harmony.jpda.tests.framework.TestOptions; 29 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 30 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 31 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 32 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 33 import org.apache.harmony.jpda.tests.framework.jdwp.Value; 34 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 35 import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper; 36 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 37 38 39 /** 40 * JDWP Unit test for verifying re-enabling of garbage collecting after re-connection. 41 */ 42 public class EnableCollectionTest extends JDWPSyncTestCase { 43 44 String checkedFieldName = "checkedObject"; 45 static final int testStatusPassed = 0; 46 static final int testStatusFailed = -1; 47 static final String thisCommandName = "MultiSession::EnableCollection command"; 48 49 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/MultiSession/EnableCollectionDebuggee;"; 50 51 protected String getDebuggeeClassName() { 52 return "org.apache.harmony.jpda.tests.jdwp.MultiSession.EnableCollectionDebuggee"; 53 } 54 55 /** 56 * This testcase verifies re-enabling of garbage collecting after re-connection. 57 * <BR>It runs EnableCollectionDebuggee, disables garbage collecting for checked object 58 * with ObjectReference.DisableCollection command and re-connects. 59 * <BR>It is expected that checked object is garbage collected after re-connection. 60 */ 61 public void testEnableCollection001() { 62 String thisTestName = "testEnableCollection001"; 63 logWriter.println("==> testEnableCollection001 started.."); 64 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 65 finalSyncMessage = "TO_FINISH"; 66 67 long refTypeID = getClassIDBySignature(debuggeeSignature); 68 69 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 70 logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); 71 72 long checkedFieldID = debuggeeWrapper.vmMirror.getFieldID(refTypeID, checkedFieldName); 73 74 logWriter.println 75 ("=> Send ReferenceType::GetValues command for received fieldID and get ObjectID to check..."); 76 77 CommandPacket getValuesCommand = new CommandPacket( 78 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 79 JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); 80 getValuesCommand.setNextValueAsReferenceTypeID(refTypeID); 81 getValuesCommand.setNextValueAsInt(1); 82 getValuesCommand.setNextValueAsFieldID(checkedFieldID); 83 84 ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand); 85 getValuesCommand = null; 86 checkReplyPacket(getValuesReply, "ReferenceType::GetValues command"); 87 88 int returnedValuesNumber = getValuesReply.getNextValueAsInt(); 89 logWriter.println("=> Returned values number = " + returnedValuesNumber); 90 assertEquals("Invalid returned number of values,", 1, returnedValuesNumber); 91 92 Value checkedObjectFieldValue = getValuesReply.getNextValueAsValue(); 93 byte checkedObjectFieldTag = checkedObjectFieldValue.getTag(); 94 logWriter.println("=> Returned field value tag for checked object= " + checkedObjectFieldTag 95 + "(" + JDWPConstants.Tag.getName(checkedObjectFieldTag) + ")"); 96 assertEquals("Invalid object tag,", JDWPConstants.Tag.OBJECT_TAG, checkedObjectFieldTag); 97 98 long checkedObjectID = checkedObjectFieldValue.getLongValue(); 99 logWriter.println("=> Returned checked ObjectID = " + checkedObjectID); 100 101 logWriter.println 102 ("\n=> CHECK: send " + thisCommandName + " for checked ObjectID..."); 103 104 CommandPacket checkedCommand = new CommandPacket( 105 JDWPCommands.ObjectReferenceCommandSet.CommandSetID, 106 JDWPCommands.ObjectReferenceCommandSet.DisableCollectionCommand); 107 checkedCommand.setNextValueAsObjectID(checkedObjectID); 108 109 ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand); 110 checkedCommand = null; 111 checkReplyPacket(checkedReply, "ObjectReference::DisableCollection command"); 112 113 logWriter.println("=> CHECK: Reply is received without any error"); 114 115 logWriter.println(""); 116 logWriter.println("=> CLOSE CONNECTION.."); 117 closeConnection(); 118 logWriter.println("=> CONNECTION CLOSED"); 119 logWriter.println(""); 120 logWriter.println("=> OPEN NEW CONNECTION.."); 121 openConnection(); 122 logWriter.println("=> CONNECTION OPENED"); 123 124 logWriter.println("=> Resuming debuggee"); 125 126 // start the thread 127 finalSyncMessage = null; 128 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 129 130 String messageFromDebuggee = synchronizer.receiveMessage(); 131 logWriter.println 132 ("\n=> Received message from Debuggee = \"" + messageFromDebuggee + "\"" ); 133 if ( messageFromDebuggee.equals 134 ("Checked Object is NOT UNLOADed; Pattern Object is UNLOADed;") ) { 135 logWriter.println 136 ("## FAILURE: Checked Object is NOT UNLOADed after " + thisCommandName); 137 fail("Invalid message from debuggee."); 138 } else { 139 logWriter.println("=> PASSED: It is expected result" ); 140 } 141 142 assertAllDataRead(checkedReply); 143 144 logWriter.println("=> Send to Debuggee signal to finish ..."); 145 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 146 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 147 logWriter.println("==> testEnableCollection001 PASSED!"); 148 } 149 150 protected void beforeDebuggeeStart(JDWPUnitDebuggeeWrapper debuggeeWrapper) { 151 settings.setAttachConnectorKind(); 152 if (settings.getTransportAddress() == null) { 153 settings.setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS); 154 } 155 logWriter.println("ATTACH connector kind"); 156 super.beforeDebuggeeStart(debuggeeWrapper); 157 } 158 } 159