173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz/* 273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * Licensed to the Apache Software Foundation (ASF) under one or more 373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * contributor license agreements. See the NOTICE file distributed with 473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * this work for additional information regarding copyright ownership. 573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * The ASF licenses this file to You under the Apache License, Version 2.0 673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * (the "License"); you may not use this file except in compliance with 773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * the License. You may obtain a copy of the License at 873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * 973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * http://www.apache.org/licenses/LICENSE-2.0 1073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * 1173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * Unless required by applicable law or agreed to in writing, software 1273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * distributed under the License is distributed on an "AS IS" BASIS, 1373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * 1573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * See the License for the specific language governing permissions and 1673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * limitations under the License. 1773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz */ 1873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 1973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzpackage org.apache.harmony.jpda.tests.jdwp.ClassType; 2073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 2173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 2273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 2373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 2473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 2573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.TaggedObject; 2673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzimport org.apache.harmony.jpda.tests.framework.jdwp.Value; 2773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzimport org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 2873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzimport org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 2973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 3073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 3173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz/** 3273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * JDWP unit test for ClassType.InvokeMethod command. 3373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz */ 3473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertzpublic class InvokeMethod003Test extends JDWPSyncTestCase { 35e1833aa2673d4f975ad35e7a39317feeea922fe1Sebastien Hertz @Override 3673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz protected String getDebuggeeClassName() { 3773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz return "org.apache.harmony.jpda.tests.jdwp.ClassType.InvokeMethod003Debuggee"; 3873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz } 3973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 4073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz /** 4173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * This testcase exercises ClassType.InvokeMethod command. 4273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * <BR>The test first starts the debuggee, request METHOD_ENTRY event so the 4373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * application suspends on first invoke. 4473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * <BR>Then sends ClassType.InvokeMethod command for method with null 4573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * argument. Checks that returned value is expected int value and returned 4673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * exception object is null. 4773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz * <BR>Finally resume the application. 4873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz */ 4973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz public void testInvokeMethod_null_argument() { 5073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 5173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 5273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz // Get debuggee class ID. 5373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz String debuggeeClassSig = "Lorg/apache/harmony/jpda/tests/jdwp/ClassType/InvokeMethod003Debuggee;"; 5473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz long debuggeeTypeID = debuggeeWrapper.vmMirror.getClassID(debuggeeClassSig); 5573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertTrue("Failed to find debuggee class", debuggeeTypeID != 0); 5673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 5773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz // Set METHOD_ENTRY event request so application is suspended. 5873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz CommandPacket packet = new CommandPacket( 5973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz JDWPCommands.EventRequestCommandSet.CommandSetID, 6073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz JDWPCommands.EventRequestCommandSet.SetCommand); 6173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); 6273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); 6373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsInt(1); 6473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsByte((byte) 4); // class-only modifier. 6573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsReferenceTypeID(debuggeeTypeID); 6673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 6773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz checkReplyPacket(reply, "EventRequest::Set command"); 6873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 6973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz int requestID = reply.getNextValueAsInt(); 7073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz logWriter.println(" EventRequest.Set: requestID=" + requestID); 7173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertAllDataRead(reply); 7273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 7373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 7473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz long targetThreadID = 0; 7573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz // Wait for METHOD_ENTRY event and collect event thread. 7673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent(); 7773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz byte suspendPolicy = event.getNextValueAsByte(); 7873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz int events = event.getNextValueAsInt(); 7973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz logWriter.println(" EVENT_THREAD event: suspendPolicy=" + suspendPolicy + " events=" + events); 8073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz for (int i = 0; i < events; i++) { 8173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz byte eventKind = event.getNextValueAsByte(); 8273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz int newRequestID = event.getNextValueAsInt(); 8373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz long threadID = event.getNextValueAsThreadID(); 8473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz //Location location = 8573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz event.getNextValueAsLocation(); 8673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz logWriter.println(" EVENT_THREAD event " + i + ": eventKind=" 8773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz + eventKind + " requestID=" + newRequestID + " threadID=" 8873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz + threadID); 8973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz if (newRequestID == requestID) { 9073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz targetThreadID = threadID; 9173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz } 9273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz } 9373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertAllDataRead(event); 9473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertTrue("Invalid targetThreadID, must be != 0", targetThreadID != 0); 9573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 9673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz // Now we're suspended, clear event request. 9773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet = new CommandPacket( 9873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz JDWPCommands.EventRequestCommandSet.CommandSetID, 9973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz JDWPCommands.EventRequestCommandSet.ClearCommand); 10073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsByte(JDWPConstants.EventKind.METHOD_ENTRY); 10173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsInt(requestID); 10273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz reply = debuggeeWrapper.vmMirror.performCommand(packet); 10373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz checkReplyPacket(reply, "EventRequest::Clear command"); 10473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertAllDataRead(reply); 10573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 10673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz // Get test method ID. 10773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz long targetMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeTypeID, "testMethod"); 10873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertTrue("Failed to find method", targetMethodID != 0); 10973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 11073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz // Invoke test method with null argument. 111e9e1750a916cf602df722515736d21af63de1defSebastien Hertz Value nullObjectValue = Value.createObjectValue(JDWPConstants.Tag.OBJECT_TAG, 0); 11273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet = new CommandPacket( 11373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz JDWPCommands.ClassTypeCommandSet.CommandSetID, 11473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand); 11573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsClassID(debuggeeTypeID); 11673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsThreadID(targetThreadID); 11773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsMethodID(targetMethodID); 11873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsInt(1); 11973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsValue(nullObjectValue); 12073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz packet.setNextValueAsInt(0); 12173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz logWriter.println(" Send ClassType.InvokeMethod without Exception"); 12273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz reply = debuggeeWrapper.vmMirror.performCommand(packet); 12373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz checkReplyPacket(reply, "ClassType::InvokeMethod command"); 12473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 12573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz Value returnValue = reply.getNextValueAsValue(); 12673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertNotNull("Returned value is null", returnValue); 12773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertEquals("Invalid returned value,", 123, returnValue.getIntValue()); 12873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz logWriter.println(" ClassType.InvokeMethod: returnValue.getIntValue()=" 12973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz + returnValue.getIntValue()); 13073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 13173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz TaggedObject exception = reply.getNextValueAsTaggedObject(); 13273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertNotNull("Returned exception is null", exception); 13373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertTrue("Invalid exception object ID:<" + exception.objectID + ">", exception.objectID == 0); 13473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertEquals("Invalid exception tag,", JDWPConstants.Tag.OBJECT_TAG, exception.tag 13573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz , JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG) 13673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz , JDWPConstants.Tag.getName(exception.tag)); 13773a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz logWriter.println(" ClassType.InvokeMethod: exception.tag=" 13873a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz + exception.tag + " exception.objectID=" + exception.objectID); 13973a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz assertAllDataRead(reply); 14073a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 14173a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz // Let's resume application 14273a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz debuggeeWrapper.vmMirror.resume(); 14373a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz 14473a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 14573a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz } 14673a9bfc045ae62ef74fcbdce45eb0a19d120eb94Sebastien Hertz} 147