/** * This testcase exercises ObjectReference.IsCollected command. <br> * The test starts IsCollectedDebuggee class. Then attempts to know if "null" object (id=0) is * collected and checks INVALID_OBJECT is returned. */ public void testIsCollected_null() { synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); CommandPacket command = new CommandPacket( JDWPCommands.ObjectReferenceCommandSet.CommandSetID, JDWPCommands.ObjectReferenceCommandSet.IsCollectedCommand); command.setNextValueAsObjectID(JDWPTestConstants.NULL_OBJECT_ID); ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(command); checkReplyPacket(reply, thisCommandName, JDWPConstants.Error.INVALID_OBJECT); synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); }
/** * This testcase exercises ObjectReference.IsCollected command. <br> * The test starts IsCollectedDebuggee class. Then attempts to know if an invalid objectID is * collected and checks no error is returned and result is true. */ public void testIsCollected_invalid() { synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); CommandPacket command = new CommandPacket( JDWPCommands.ObjectReferenceCommandSet.CommandSetID, JDWPCommands.ObjectReferenceCommandSet.IsCollectedCommand); command.setNextValueAsObjectID(JDWPTestConstants.INVALID_OBJECT_ID); ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(command); checkReplyPacket(reply, thisCommandName); boolean is_collected = reply.getNextValueAsBoolean(); assertAllDataRead(reply); assertTrue("Invalid object id is assumed to be collected", is_collected); synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); }
/** * This testcase exercises VirtualMachine.DisposeObjects command. <br> * At first the test starts HelloWorld debuggee. <br> * Then the test performs VirtualMachine.CreateString command for some string and checks that * VirtualMachine.DisposeObjects command for returned by CreateString command stringID with * refCount = 0 does not dispose that stringID - ObjectReference::ReferenceType command should * return some referenceTypeID without any error. <br> * Then the test check that repeated VirtualMachine.DisposeObjects command with refCount = 1 * disposes that stringID - ObjectReference::ReferenceType command should return INVALID_OBJECT * error. */ public void testDisposeObjects001() { synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); CommandPacket packet = new CommandPacket( JDWPCommands.VirtualMachineCommandSet.CommandSetID, JDWPCommands.VirtualMachineCommandSet.CreateStringCommand); packet.setNextValueAsString(CHECKED_STRING); logWriter.println("\tcreate string: " + CHECKED_STRING); ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); long stringID = reply.getNextValueAsStringID(); logWriter.println("\tstring creared: stringID = " + stringID); logWriter.println( "\tsend DisposeObjects for created string with refCount = 0" + " - string should not be disposed..."); packet = new CommandPacket( JDWPCommands.VirtualMachineCommandSet.CommandSetID, JDWPCommands.VirtualMachineCommandSet.DisposeObjectsCommand); packet.setNextValueAsInt(1); packet.setNextValueAsObjectID(stringID); packet.setNextValueAsInt(0); reply = debuggeeWrapper.vmMirror.performCommand(packet); checkReplyPacket(reply, "VirtualMachine::DisposeObjects command"); logWriter.println( "\tsend ObjectReference::ReferenceType command for created string" + " to make sure that string is not disposed..."); packet = new CommandPacket( JDWPCommands.ObjectReferenceCommandSet.CommandSetID, JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand); packet.setNextValueAsObjectID(stringID); reply = debuggeeWrapper.vmMirror.performCommand(packet); checkReplyPacket(reply, "ObjectReference::ReferenceType command"); byte refTypeTag = reply.getNextValueAsByte(); long refTypeID = reply.getNextValueAsReferenceTypeID(); logWriter.println( "\tReturned refTypeTag = " + refTypeTag + "(" + JDWPConstants.TypeTag.getName(refTypeTag) + ")"); logWriter.println("\tReturned ReferenceTypeID for string = " + refTypeID); logWriter.println( "\tsend DisposeObjects for created string with refCount = 1" + " - string should be disposed..."); packet = new CommandPacket( JDWPCommands.VirtualMachineCommandSet.CommandSetID, JDWPCommands.VirtualMachineCommandSet.DisposeObjectsCommand); packet.setNextValueAsInt(1); packet.setNextValueAsObjectID(stringID); packet.setNextValueAsInt(1); reply = debuggeeWrapper.vmMirror.performCommand(packet); checkReplyPacket(reply, "VirtualMachine::DisposeObjects command"); logWriter.println( "\tsend ObjectReference::ReferenceType command for disposed string" + " - INVALID_OBJECT should be..."); packet = new CommandPacket( JDWPCommands.ObjectReferenceCommandSet.CommandSetID, JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand); packet.setNextValueAsObjectID(stringID); reply = debuggeeWrapper.vmMirror.performCommand(packet); checkReplyPacket( reply, "ObjectReference::ReferenceType command", JDWPConstants.Error.INVALID_OBJECT); synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); }
/** * The test checks ClassType.SetValues command for field of Debuggee class with value which has * other referenceType than field to set. The test expects the field should not be set. */ public void testSetValues002() { String thisTestName = "testSetValues002"; logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); CommandPacket classesBySignatureCommand = new CommandPacket( JDWPCommands.VirtualMachineCommandSet.CommandSetID, JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand); classesBySignatureCommand.setNextValueAsString(debuggeeSignature); ReplyPacket classesBySignatureReply = debuggeeWrapper.vmMirror.performCommand(classesBySignatureCommand); classesBySignatureCommand = null; checkReplyPacket(classesBySignatureReply, "VirtualMachine::ClassesBySignature command"); classesBySignatureReply.getNextValueAsInt(); // Number of returned reference types - is NOt used here classesBySignatureReply.getNextValueAsByte(); // refTypeTag of class - is NOt used here long refTypeID = classesBySignatureReply.getNextValueAsReferenceTypeID(); classesBySignatureReply = null; logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); String checkedFieldNames[] = { "SetValues002DebuggeeObject", "objectField", }; long checkedFieldIDs[] = checkFields(refTypeID, checkedFieldNames); int checkedFieldsNumber = checkedFieldNames.length; logWriter.println( "=> Send ReferenceType::GetValues command and get ObjectID for value to set..."); CommandPacket getValuesCommand = new CommandPacket( JDWPCommands.ReferenceTypeCommandSet.CommandSetID, JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); getValuesCommand.setNextValueAsReferenceTypeID(refTypeID); getValuesCommand.setNextValueAsInt(1); getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]); ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand); getValuesCommand = null; checkReplyPacket(getValuesReply, "ReferenceType::GetValues command"); int returnedValuesNumber = getValuesReply.getNextValueAsInt(); logWriter.println("=> Returned values number = " + returnedValuesNumber); assertEquals( "ReferenceType::GetValues returned invalid values number,", 1, returnedValuesNumber); Value objectFieldValueToSet = getValuesReply.getNextValueAsValue(); byte objectFieldValueToSetTag = objectFieldValueToSet.getTag(); logWriter.println( "=> Returned field value tag for checked object= " + objectFieldValueToSetTag + "(" + JDWPConstants.Tag.getName(objectFieldValueToSetTag) + ")"); assertEquals( "ReferenceType::GetValues returned invalid value tag,", JDWPConstants.Tag.OBJECT_TAG, objectFieldValueToSetTag, JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG), JDWPConstants.Tag.getName(objectFieldValueToSetTag)); long objectFieldID = objectFieldValueToSet.getLongValue(); logWriter.println("=> Returned ObjectID = " + objectFieldID); logWriter.println( "=> CHECK: send " + thisCommandName + " for Debuggee class with value which has other referenceType than field to set..."); CommandPacket checkedCommand = new CommandPacket( JDWPCommands.ClassTypeCommandSet.CommandSetID, JDWPCommands.ClassTypeCommandSet.SetValuesCommand); checkedCommand.setNextValueAsClassID(refTypeID); checkedCommand.setNextValueAsInt(checkedFieldsNumber - 1); int fieldIndex = 1; for (; fieldIndex < checkedFieldsNumber; fieldIndex++) { checkedCommand.setNextValueAsFieldID(checkedFieldIDs[fieldIndex]); switch (fieldIndex) { case 1: // objectField checkedCommand.setNextValueAsObjectID(objectFieldID); break; } } ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand); checkedCommand = null; short errorCode = checkedReply.getErrorCode(); if (errorCode == JDWPConstants.Error.NONE) { logWriter.println("=> " + thisCommandName + " run without any ERROR!"); } else { logWriter.println( "=> " + thisCommandName + " returns ERROR = " + errorCode + "(" + JDWPConstants.Error.getName(errorCode) + ")"); } logWriter.println("=> Wait for Debuggee's status about check for set field..."); synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); boolean debuggeeStatus = synchronizer.receiveMessage("PASSED"); if (!debuggeeStatus) { logWriter.println("## " + thisTestName + ": Debuggee returned status FAILED"); fail("Debuggee returned status FAILED"); } else { logWriter.println("=> " + thisTestName + ": Debuggee returned status PASSED"); } logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": OK"); }
/** * This test exercises ObjectReference.IsCollected command. <br> * The test starts IsCollectedDebuggee class, gets two objectIDs as value of static fields of this * class which (fields) represent two checked objects. Then for the first objectID test executes * ObjectReference.DisableCollection command. After that Debuggee tries to unload checked objects. * Then the test executes ObjectReference.IsCollected commands for both checked objects and checks * replies. */ public void testIsCollected001() { String thisTestName = "testIsCollected001"; logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); String failMessage = ""; synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); finalSyncMessage = "TO_FINISH"; long refTypeID = getClassIDBySignature(debuggeeSignature); logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); String checkedFieldNames[] = { "checkedObject_01", "checkedObject_02", }; long checkedFieldIDs[] = checkFields(refTypeID, checkedFieldNames); long checkedField_01ID = checkedFieldIDs[0]; long checkedField_02ID = checkedFieldIDs[1]; logWriter.println( "=> Send ReferenceType::GetValues command for received fieldIDs and get ObjectIDs to check..."); CommandPacket getValuesCommand = new CommandPacket( JDWPCommands.ReferenceTypeCommandSet.CommandSetID, JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand); getValuesCommand.setNextValueAsReferenceTypeID(refTypeID); getValuesCommand.setNextValueAsInt(2); getValuesCommand.setNextValueAsFieldID(checkedField_01ID); getValuesCommand.setNextValueAsFieldID(checkedField_02ID); ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand); getValuesCommand = null; checkReplyPacket(getValuesReply, "ReferenceType::GetValues command"); int returnedValuesNumber = getValuesReply.getNextValueAsInt(); logWriter.println("=> Returned values number = " + returnedValuesNumber); assertEquals("Invalid number of values,", 2, returnedValuesNumber); Value checkedObjectFieldValue = getValuesReply.getNextValueAsValue(); byte checkedObjectFieldTag = checkedObjectFieldValue.getTag(); logWriter.println( "=> Returned field value tag for checkedObject_01 = " + checkedObjectFieldTag + "(" + JDWPConstants.Tag.getName(checkedObjectFieldTag) + ")"); assertEquals( "Invalid value tag for checkedObject_01", JDWPConstants.Tag.OBJECT_TAG, checkedObjectFieldTag, JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG), JDWPConstants.Tag.getName(checkedObjectFieldTag)); long checkedObject_01ID = checkedObjectFieldValue.getLongValue(); logWriter.println("=> Returned ObjectID for checkedObject_01 = " + checkedObject_01ID); checkedObjectFieldValue = getValuesReply.getNextValueAsValue(); checkedObjectFieldTag = checkedObjectFieldValue.getTag(); logWriter.println( "=> Returned field value tag for checkedObject_02 = " + checkedObjectFieldTag + "(" + JDWPConstants.Tag.getName(checkedObjectFieldTag) + ")"); assertEquals( "Invalid value tag for checkedObject_02", JDWPConstants.Tag.OBJECT_TAG, checkedObjectFieldTag, JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG), JDWPConstants.Tag.getName(checkedObjectFieldTag)); long checkedObject_02ID = checkedObjectFieldValue.getLongValue(); logWriter.println("=> Returned ObjectID for checkedObject_02 = " + checkedObject_02ID); logWriter.println( "\n=> Send ObjectReference::DisableCollection command for checkedObject_01..."); CommandPacket disableCollectionCommand = new CommandPacket( JDWPCommands.ObjectReferenceCommandSet.CommandSetID, JDWPCommands.ObjectReferenceCommandSet.DisableCollectionCommand); disableCollectionCommand.setNextValueAsObjectID(checkedObject_01ID); ReplyPacket disableCollectionReply = debuggeeWrapper.vmMirror.performCommand(disableCollectionCommand); disableCollectionCommand = null; checkReplyPacket(disableCollectionReply, "ObjectReference::DisableCollection command"); logWriter.println( "=> Send to Debuggee signal to continue and try to unload checked objects..."); finalSyncMessage = null; synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); String messageFromDebuggee = synchronizer.receiveMessage(); logWriter.println("\n=> Received message from Debuggee = \"" + messageFromDebuggee + "\""); logWriter.println("\n=> Send " + thisCommandName + " for checkedObject_01 and check reply..."); CommandPacket checkedCommand = new CommandPacket( JDWPCommands.ObjectReferenceCommandSet.CommandSetID, JDWPCommands.ObjectReferenceCommandSet.IsCollectedCommand); checkedCommand.setNextValueAsObjectID(checkedObject_01ID); ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand); checkedCommand = null; checkReplyPacket(checkedReply, thisCommandName); boolean checkedObject_01_IsCollected = checkedReply.getNextValueAsBoolean(); logWriter.println("=> IsCollected for checkedObject_01 = " + checkedObject_01_IsCollected); if (messageFromDebuggee.indexOf("checkedObject_01 is UNLOADed;") != -1) { if (!checkedObject_01_IsCollected) { logWriter.println( "## FAILURE: Unexpected result for checkedObject_01 of " + thisCommandName + ":"); logWriter.println("## checkedObject_01 is UNLOADed so IsCollected must be 'true'"); failMessage = failMessage + "Unexpected result for checkedObject_01 of " + thisCommandName + "\n"; } } else { if (checkedObject_01_IsCollected) { logWriter.println( "## FAILURE: Unexpected result for checkedObject_01 of " + thisCommandName + ":"); logWriter.println("## checkedObject_01 is NOT UNLOADed so IsCollected must be 'false'"); failMessage = failMessage + "Unexpected result for checkedObject_01 of " + thisCommandName + "\n"; } } logWriter.println("=> PASSED for checkedObject_01"); logWriter.println("\n=> Send " + thisCommandName + " for checkedObject_02 and check reply..."); checkedCommand = new CommandPacket( JDWPCommands.ObjectReferenceCommandSet.CommandSetID, JDWPCommands.ObjectReferenceCommandSet.IsCollectedCommand); checkedCommand.setNextValueAsObjectID(checkedObject_02ID); checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand); checkedCommand = null; checkReplyPacket(checkedReply, thisCommandName); boolean checkedObject_02_IsCollected = checkedReply.getNextValueAsBoolean(); logWriter.println("=> IsCollected for checkedObject_02 = " + checkedObject_02_IsCollected); if (messageFromDebuggee.indexOf("checkedObject_02 is UNLOADed;") != -1) { if (!checkedObject_02_IsCollected) { logWriter.println( "## FAILURE: Unexpected result for checkedObject_02 of " + thisCommandName + ":"); logWriter.println("## checkedObject_02 is UNLOADed so IsCollected must be 'true'"); failMessage = failMessage + "Unexpected result for checkedObject_02 of " + thisCommandName + "\n"; } } else { if (checkedObject_02_IsCollected) { logWriter.println( "## FAILURE: Unexpected result for checkedObject_02 of " + thisCommandName + ":"); logWriter.println("## checkedObject_02 is NOT UNLOADed so IsCollected must be 'false'"); failMessage = failMessage + "Unexpected result for checkedObject_02 of " + thisCommandName + "\n"; } } logWriter.println("=> PASSED for checkedObject_02"); logWriter.println("=> Send to Debuggee signal to funish ..."); synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); if (failMessage.length() > 0) { fail(failMessage); } assertAllDataRead(checkedReply); }