diff options
author | Sebastien Hertz <shertz@google.com> | 2015-03-30 08:00:40 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-30 08:00:40 +0000 |
commit | 1c2daca2396044248d98ac832802b155cf0bf52e (patch) | |
tree | a0ae4aef1944e5218fb6077233bdb808f8d38333 | |
parent | fa919870a6531dab8411a03ed9f176f8df42d714 (diff) | |
parent | 02f1951ff89c7531cd007ec9991cae9325391b67 (diff) | |
download | apache-harmony-1c2daca2396044248d98ac832802b155cf0bf52e.tar.gz |
am 02f1951f: Merge "JDWP: add more stack frame tests"
* commit '02f1951ff89c7531cd007ec9991cae9325391b67':
JDWP: add more stack frame tests
8 files changed, 2138 insertions, 362 deletions
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/GetValues002Test.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/GetValues002Test.java new file mode 100644 index 0000000..e6eeb42 --- /dev/null +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/GetValues002Test.java @@ -0,0 +1,397 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.StackFrame; + +import org.apache.harmony.jpda.tests.framework.jdwp.Value; + +/** + * JDWP Unit test for StackFrame.GetValues command. + */ +public class GetValues002Test extends JDWPStackFrameAccessTest { + /** + * Tests we correctly read value of boolean variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues001_Boolean() { + StackFrameTester tester = new StackFrameTester("breakpointBoolean", + StackTrace002Debuggee.BOOLEAN_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointBoolean"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.BOOLEAN_PARAM_VALUE)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of byte variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues002_Byte() { + StackFrameTester tester = new StackFrameTester("breakpointByte", + StackTrace002Debuggee.BYTE_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointByte"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.BYTE_PARAM_VALUE)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of char variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues003_Char() { + StackFrameTester tester = new StackFrameTester("breakpointChar", + StackTrace002Debuggee.CHAR_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointChar"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.CHAR_PARAM_VALUE)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of short variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues004_Short() { + StackFrameTester tester = new StackFrameTester("breakpointShort", + StackTrace002Debuggee.SHORT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointShort"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.SHORT_PARAM_VALUE)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of int variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues005_Int() { + StackFrameTester tester = new StackFrameTester("breakpointInt", + StackTrace002Debuggee.INT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointInt"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.INT_PARAM_VALUE)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of int variables in the stack: one param and one local. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues005_Int2() { + StackFrameTester tester = new StackFrameTester("breakpointInt2", + StackTrace002Debuggee.INT_METHOD2_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointInt2"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.INT_PARAM_VALUE)); + methodInfo.addVariable("local", new Value(StackTrace002Debuggee.INT_PARAM_VALUE)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of long variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues006_Long() { + StackFrameTester tester = new StackFrameTester("breakpointLong", + StackTrace002Debuggee.LONG_METHOD_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointLong"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.LONG_PARAM_VALUE)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of float variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues007_Float() { + StackFrameTester tester = new StackFrameTester("breakpointFloat", + StackTrace002Debuggee.FLOAT_METHOD); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointFloat"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.FLOAT_PARAM_VALUE)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of double variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues008_Double() { + StackFrameTester tester = new StackFrameTester("breakpointDouble", + StackTrace002Debuggee.DOUBLE_METHOD); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointDouble"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.DOUBLE_PARAM_VALUE)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Object variable 'this' in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues009_ThisObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value thisValue = getStaticFieldValue(classID, "THIS_OBJECT"); + + StackFrameTester tester = new StackFrameTester("breakpointObject", + StackTrace002Debuggee.OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("this", thisValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Object variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues009_Object() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "OBJECT_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointObject", + StackTrace002Debuggee.OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of Array variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues010_Array() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "ARRAY_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointArray", + StackTrace002Debuggee.ARRAY_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointArray"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Object variable containing + * Array in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues010_ArrayAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "ARRAY_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointObject", + StackTrace002Debuggee.ARRAY_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Class variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues011_Class() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "CLASS_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointClass", + StackTrace002Debuggee.CLASS_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointClass"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Object variable containing + * java.lang.Class in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues011_ClassAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "CLASS_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointObject", + StackTrace002Debuggee.CLASS_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.ClassLoader variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues012_ClassLoader() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "CLASS_LOADER_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointClassLoader", + StackTrace002Debuggee.CLASS_LOADER_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointClassLoader"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Object variable containing + * java.lang.ClassLoader in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues012_ClassLoaderAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "CLASS_LOADER_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointObject", + StackTrace002Debuggee.CLASS_LOADER_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.String variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues013_String() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "STRING_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointString", + StackTrace002Debuggee.STRING_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointString"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Object variable containing + * java.lang.String in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues013_StringAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "STRING_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointObject", + StackTrace002Debuggee.STRING_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Thread variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues014_Thread() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "THREAD_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointThread", + StackTrace002Debuggee.THREAD_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointThread"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Object variable containing + * java.lang.Thread in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues014_ThreadAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "THREAD_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointObject", + StackTrace002Debuggee.THREAD_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.ThreadGroup variable in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues015_ThreadGroup() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "THREAD_GROUP_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointThreadGroup", + StackTrace002Debuggee.THREAD_GROUP_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointThreadGroup"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly read value of java.lang.Object variable containing + * java.lang.ThreadGroup in the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testGetValues015_ThreadGroupAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value expectedValue = getStaticFieldValue(classID, "THREAD_GROUP_PARAM_VALUE"); + + StackFrameTester tester = new StackFrameTester("breakpointObject", + StackTrace002Debuggee.THREAD_GROUP_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", expectedValue); + runStackFrameTest(tester); + } +} diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/GetValuesTest.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/GetValuesTest.java index 88783a3..924e3d6 100644 --- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/GetValuesTest.java +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/GetValuesTest.java @@ -24,37 +24,19 @@ */ package org.apache.harmony.jpda.tests.jdwp.StackFrame; -import java.util.ArrayList; -import java.util.Arrays; -import org.apache.harmony.jpda.tests.framework.LogWriter; import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands.StackFrameCommandSet; import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; import org.apache.harmony.jpda.tests.framework.jdwp.Value; -import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + +import java.util.Arrays; /** * JDWP Unit test for StackFrame.GetValues command. */ -public class GetValuesTest extends JDWPStackFrameTestCase { - - String testedMethodName = "nestledMethod3"; - String testedThreadName = ""; - - VarInfo[] varInfos; - - String varSignatures[] = { "Lorg/apache/harmony/jpda/tests/jdwp/StackFrame/StackTraceDebuggee;", "Z", - "I", "Ljava/lang/String;" }; - - String varNames[] = { "this", "boolLocalVariable", "intLocalVariable", - "strLocalVariable" }; - - byte varTags[] = { JDWPConstants.Tag.OBJECT_TAG, JDWPConstants.Tag.BOOLEAN_TAG, - JDWPConstants.Tag.INT_TAG, JDWPConstants.Tag.STRING_TAG }; - - private String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/StackFrame/StackTraceDebuggee;"; - +public class GetValuesTest extends JDWPStackTraceBaseTest { /** * This testcase exercises StackFrame.GetValues command. * <BR>The test starts StackTraceDebuggee, sets breakpoint at the beginning of @@ -66,34 +48,120 @@ public class GetValuesTest extends JDWPStackFrameTestCase { * */ public void testGetValues001() { - logWriter.println("==> testGetValues001 started..."); - testedThreadName = synchronizer.receiveMessage(); - // release on run() - synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + //gets and checks local variables of tested method + examineGetValues(); + } - // pass nestledMethod1() - synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); - synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + /** + * This testcase exercises StackFrame.GetValues command. + * <BR>The test starts StackTraceDebuggee and waits for it to reach the + * tested method - 'nestledMethod3'. + * <BR> Then it performs StackFrame.GetValues command with an invalid + * thread ID and checks the command returns error INVALID_OBJECT. + */ + public void testGetValues002_InvalidObjectError() { + long invalidThreadID = -1; + logWriter.println("Send StackFrame.GetValues with invalid thread " + invalidThreadID); + CommandPacket packet = new CommandPacket(StackFrameCommandSet.CommandSetID, + StackFrameCommandSet.GetValuesCommand); + packet.setNextValueAsThreadID(invalidThreadID); + packet.setNextValueAsFrameID(0); + packet.setNextValueAsInt(0); + ReplyPacket replyPacket = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(replyPacket, "StackFrame.GetValues", + JDWPConstants.Error.INVALID_OBJECT); + } - // enter nestledMethod2() - synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + /** + * This testcase exercises StackFrame.GetValues command. + * <BR>The test starts StackTraceDebuggee and waits for it to reach the + * tested method - 'nestledMethod3'. + * <BR> Then it performs StackFrame.GetValues command to a non-suspended + * thread and checks the command returns error THREAD_NOT_SUSPENDED. + */ + public void testGetValues003_ThreadNotSuspendedError() { + long threadID = getThreadID(); - //release debuggee - synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); - synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + CommandPacket packet = new CommandPacket(StackFrameCommandSet.CommandSetID, + StackFrameCommandSet.GetValuesCommand); + packet.setNextValueAsThreadID(threadID); + packet.setNextValueAsFrameID(0); + packet.setNextValueAsInt(0); + ReplyPacket replyPacket = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(replyPacket, "StackFrame.GetValues", + JDWPConstants.Error.THREAD_NOT_SUSPENDED); + } - //gets and checks local variables of tested method - examineGetValues(); + /** + * This testcase exercises StackFrame.GetValues command. + * <BR>The test starts StackTraceDebuggee and waits for it to reach the + * tested method - 'nestledMethod3'. + * <BR> Then it performs StackFrame.GetValues command to an invalid + * frame ID and checks the command returns error INVALID_FRAMEID. + */ + public void testGetValues004_InvalidFrameIDError() { + long threadID = getThreadID(); - // signal to finish debuggee - synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); - logWriter.println("==> testGetValues001 - OK."); + // suspend thread + jdwpSuspendThread(threadID); + long invalidFrameID = -1; + logWriter.println("Send StackFrame.GetValues with invalid frameID " + invalidFrameID); + CommandPacket packet = new CommandPacket(StackFrameCommandSet.CommandSetID, + StackFrameCommandSet.GetValuesCommand); + packet.setNextValueAsThreadID(threadID); + packet.setNextValueAsFrameID(invalidFrameID); + packet.setNextValueAsInt(0); + ReplyPacket replyPacket = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(replyPacket, "StackFrame.GetValues", + JDWPConstants.Error.INVALID_FRAMEID); } - private void examineGetValues() { + /** + * This testcase exercises StackFrame.GetValues command. + * <BR>The test starts StackTraceDebuggee and waits for it to reach the + * tested method - 'nestledMethod3'. + * <BR> Then it performs StackFrame.GetValues command to an invalid + * slot ID and checks the command returns error INVALID_SLOT. + */ + public void testGetValues005_InvalidSlotError() { + long threadID = getThreadID(); + + // suspend thread + jdwpSuspendThread(threadID); - long refTypeID = getClassIDBySignature(debuggeeSignature); + FrameInfo frameInfo = findFrameInfo(threadID); + + // getting Variable Table + logWriter.println(""); + logWriter.println("=> Getting Variable Table..."); + long refTypeID = getClassIDBySignature(getDebuggeeClassSignature()); + logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); + logWriter.println("=> referenceTypeID for Debuggee class = " + + refTypeID); + varInfos = jdwpGetVariableTable(refTypeID, frameInfo.location.methodID); + if (GetValuesTest.checkVarTable(logWriter, varInfos, varTags, varSignatures, varNames)) { + logWriter.println("=> Variable table check passed."); + } else { + printErrorAndFail("Variable table check failed."); + } + + int invalidSlotId = -1; + logWriter.println("Send StackFrame.GetValues with invalid slot " + invalidSlotId); + CommandPacket packet = new CommandPacket(StackFrameCommandSet.CommandSetID, + StackFrameCommandSet.GetValuesCommand); + packet.setNextValueAsThreadID(threadID); + packet.setNextValueAsFrameID(frameInfo.frameID); + packet.setNextValueAsInt(1); + packet.setNextValueAsInt(invalidSlotId); + packet.setNextValueAsByte(JDWPConstants.Tag.OBJECT_TAG); + ReplyPacket replyPacket = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(replyPacket, "StackFrame.GetValues", + JDWPConstants.Error.INVALID_SLOT); + } + + private void examineGetValues() { + long refTypeID = getClassIDBySignature(getDebuggeeClassSignature()); logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); @@ -107,53 +175,13 @@ public class GetValuesTest extends JDWPStackFrameTestCase { // suspend thread jdwpSuspendThread(threadID); - //get number of frames - int frameCount = jdwpGetFrameCount(threadID); - logWriter.println("=> frames count = " + frameCount); - - //get frames info - FrameInfo[] frameIDs = jdwpGetFrames(threadID, 0, frameCount); - if (frameIDs.length != frameCount) { - printErrorAndFail("Received number of frames = " - + frameIDs.length + " differ from expected number = " - + frameCount); - } - - //check and print methods info - long methodID = 0; - long frameID = 0; - String methodName = ""; - boolean testedMethodChecked = false; - for (int i = 0; i < frameCount; i++) { - logWriter.println("\n"); - methodName = getMethodName(frameIDs[i].location.classID, - frameIDs[i].location.methodID); - logWriter.println("=> method name = " + methodName); - logWriter.println("=> methodID = " + frameIDs[i].location.methodID); - logWriter.println("=> frameID = " + frameIDs[i].frameID); - logWriter.println("\n"); - if (methodName.equals(testedMethodName)) { - methodID = frameIDs[i].location.methodID; - frameID = frameIDs[i].frameID; - methodName = getMethodName(frameIDs[i].location.classID, - frameIDs[i].location.methodID); - testedMethodChecked = true; - } - } - if (testedMethodChecked) { - logWriter.println("=> Tested method is found"); - logWriter.println("=> method name = " + testedMethodName); - logWriter.println("=> methodID = " + methodID); - logWriter.println("=> frameID = " + frameID); - - } else { - printErrorAndFail("Tested method is not found"); - } + // find frame for the tested method + FrameInfo frameInfo = findFrameInfo(threadID); //getting Variable Table logWriter.println(""); logWriter.println("=> Getting Variable Table..."); - varInfos = jdwpGetVariableTable(refTypeID, methodID); + varInfos = jdwpGetVariableTable(refTypeID, frameInfo.location.methodID); if (checkVarTable(logWriter, varInfos, varTags, varSignatures, varNames)) { logWriter.println("=> Variable table check passed."); } else { @@ -167,10 +195,10 @@ public class GetValuesTest extends JDWPStackFrameTestCase { JDWPCommands.StackFrameCommandSet.CommandSetID, JDWPCommands.StackFrameCommandSet.GetValuesCommand); packet.setNextValueAsThreadID(threadID); - packet.setNextValueAsFrameID(frameID); + packet.setNextValueAsFrameID(frameInfo.frameID); logWriter.println("=> Thread: " + threadID); - logWriter.println("=> Frame: " + frameID); + logWriter.println("=> Frame: " + frameInfo.frameID); packet.setNextValueAsInt(varTags.length); for (int i = 0; i < varTags.length; i++) { logWriter.println(""); @@ -198,135 +226,75 @@ public class GetValuesTest extends JDWPStackFrameTestCase { boolean success = true; //print and check values of variables logWriter.println("=> Values of variables: "); - Value val; - val = reply.getNextValueAsValue(); - if (val.getTag() == JDWPConstants.Tag.BOOLEAN_TAG) { - logWriter.println("=>Tag is correct"); - boolean boolValue = val.getBooleanValue(); - if (boolValue) { - logWriter.println("=> "+varInfos[1].getName() + " = " + boolValue); - logWriter.println(""); - } else { - logWriter - .printError("Unexpected value of boolean variable: " + // TODO check that we find every variable + for (int i = 0; i < numberOfValues; ++i) { + Value val = reply.getNextValueAsValue(); + switch (val.getTag()) { + case JDWPConstants.Tag.BOOLEAN_TAG: { + boolean boolValue = val.getBooleanValue(); + if (boolValue) { + logWriter.println("=> "+varInfos[1].getName() + " = " + boolValue); + logWriter.println(""); + } else { + logWriter.printError("Unexpected value of boolean variable: " + boolValue + " instead of: true"); - logWriter.printError(""); - success = false; - } - } else { - logWriter.printError("Unexpected tag of variable: " - + JDWPConstants.Tag.getName(val.getTag()) + " instead of: boolean"); - logWriter.printError(""); - success = false; - } - - val = reply.getNextValueAsValue(); - if (val.getTag() == JDWPConstants.Tag.INT_TAG) { - logWriter.println("=>Tag is correct"); - int intValue = val.getIntValue(); - if (intValue == -512) { - logWriter.println("=> "+varInfos[2].getName() + " = " + intValue); - logWriter.println(""); - } else { - logWriter + logWriter.printError(""); + success = false; + } + break; + } + + case JDWPConstants.Tag.INT_TAG: { + logWriter.println("=>Tag is correct"); + int intValue = val.getIntValue(); + if (intValue == -512) { + logWriter.println("=> "+varInfos[2].getName() + " = " + intValue); + logWriter.println(""); + } else { + logWriter .printError("unexpected value of int variable: " + intValue + " instead of: -512"); - logWriter.printError(""); - success = false; - } - } else { - logWriter.printError("Unexpected tag of variable: " - + JDWPConstants.Tag.getName(val.getTag()) + " instead of: integer"); - logWriter.printError(""); - success = false; - } - - val = reply.getNextValueAsValue(); - if (val.getTag() == JDWPConstants.Tag.STRING_TAG) { - logWriter.println("=>Tag is correct"); - long strLocalVariableID = val.getLongValue(); - String strLocalVariable = getStringValue(strLocalVariableID); - if (strLocalVariable.equals("test string")) { - logWriter.println("=> "+varInfos[2].getName() + " = " - + strLocalVariable); - logWriter.println(""); - } else { - logWriter + logWriter.printError(""); + success = false; + } + break; + } + + case JDWPConstants.Tag.STRING_TAG: { + logWriter.println("=>Tag is correct"); + long strLocalVariableID = val.getLongValue(); + String strLocalVariable = getStringValue(strLocalVariableID); + if (strLocalVariable.equals("test string")) { + logWriter.println("=> "+varInfos[2].getName() + " = " + + strLocalVariable); + logWriter.println(""); + } else { + logWriter .printError("Unexpected value of string variable: " + strLocalVariable + " instead of: " + "test string"); - logWriter.printError(""); - success = false; - } - } else { - logWriter.printError("Unexpected tag of variable: " - + JDWPConstants.Tag.getName(val.getTag()) + " instead of: string"); - logWriter.printError(""); - success = false; - } - - val = reply.getNextValueAsValue(); - if (val.getTag() == JDWPConstants.Tag.OBJECT_TAG) { - logWriter.println("=> Tag is correct"); - logWriter.println(""); - - } else { - logWriter.printError("Unexpected tag of variable: " - + JDWPConstants.Tag.getName(val.getTag()) + " instead of: CLASS_OBJECT_TAG"); - logWriter.printError(""); - success = false; - } + logWriter.printError(""); + success = false; + } + break; + } + + case JDWPConstants.Tag.OBJECT_TAG: { + logWriter.println("=> Tag is correct"); + logWriter.println(""); + break; + } + default: + logWriter.printError("Unexpected tag of variable: " + + JDWPConstants.Tag.getName(val.getTag())); + logWriter.printError(""); + success = false; + break; + } // switch + } // for assertTrue(logWriter.getErrorMessage(), success); } - - //prints variables info, checks signatures - public static boolean checkVarTable(LogWriter logWriter, VarInfo[] varInfos, byte[] varTags, String[] varSignatures, String[] varNames) { - logWriter.println("==> Number of variables = " + varInfos.length); - if (varInfos.length != varTags.length) { - - logWriter.printError("Unexpected number of variables: " - + varInfos.length + " instead of " + varTags.length); - return false; - } - boolean success = true; - ArrayList<String> remaining = new ArrayList(Arrays.asList(varNames)); - for (int i = 0; i < varInfos.length; i++) { - logWriter.println(""); - logWriter.println("=> Name = " + varInfos[i].getName()); - logWriter.println("=> Slot = " + varInfos[i].getSlot()); - logWriter.println("=> Signature = " + varInfos[i].getSignature()); - // TODO: check codeIndex and length too - - int index = remaining.indexOf(varInfos[i].getName()); - if (index == -1) { - logWriter.printError("unknown variable: " + varInfos[i].getName()); - } - remaining.set(index, null); - - if (!(varSignatures[index].equals(varInfos[i].getSignature()))) { - logWriter - .printError("Unexpected signature of variable = " - + varInfos[i].getName() - + ", on slot = " - + varInfos[i].getSlot() - + ", with unexpected signature = " - + varInfos[i].getSignature() - + " instead of signature = " + varSignatures[index]); - success = false; - } - if (!(varNames[index].equals(varInfos[i].getName()))) { - logWriter.printError("Unexpected name of variable " - + varInfos[i].getName() + ", on slot = " - + varInfos[i].getSlot() + " instead of name = " - + varNames[index]); - success = false; - } - - logWriter.println(""); - } - return success; - } } diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/JDWPStackFrameAccessTest.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/JDWPStackFrameAccessTest.java new file mode 100644 index 0000000..2a58508 --- /dev/null +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/JDWPStackFrameAccessTest.java @@ -0,0 +1,454 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.StackFrame; + +import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.Value; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + +import java.util.ArrayList; +import java.util.List; + +/** + * Base class for testing StackFrame.GetValues and StackFrame.SetValues commands. + */ +public class JDWPStackFrameAccessTest extends JDWPStackFrameTestCase { + @Override + protected final String getDebuggeeClassName() { + return StackTrace002Debuggee.class.getName(); + } + + static class VariableInfo { + private final String variableName; + private final Value initialValue; + private final Value newValue; + + VariableInfo(String variableName, Value initialValue, Value newValue) { + this.variableName = variableName; + this.initialValue = initialValue; + this.newValue = newValue; + } + + public String getVariableName() { + return variableName; + } + + public Value getInitialValue() { + return initialValue; + } + + public Value getNewValue() { + return newValue; + } + } + + static class MethodInfo { + private final String methodName; + private final List<VariableInfo> variables = new ArrayList<VariableInfo>(); + + MethodInfo(String methodName) { + this.methodName = methodName; + } + + public String getMethodName() { + return methodName; + } + + public List<? extends VariableInfo> getVariables() { + return variables; + } + + public void addVariable(String variableName, Value initialValue, Value newValue) { + variables.add(new VariableInfo(variableName, initialValue, newValue)); + } + + public void addVariable(String variableName, Value initialValue) { + addVariable(variableName, initialValue, null); + } + } + + static class StackFrameTester { + // TODO remove when we no longer need breakpoint to suspend. + private final String breakpointMethodName; + private final String signalValue; + private final List<MethodInfo> testedMethods = new ArrayList<MethodInfo>(); + + public StackFrameTester(String breakpointMethodName, String signalValue) { + this.breakpointMethodName = breakpointMethodName; + this.signalValue = signalValue; + } + + public String getBreakpointMethodName() { + return breakpointMethodName; + } + + public String getSignalValue() { + return signalValue; + } + + public List<? extends MethodInfo> getTestedMethods() { + return testedMethods; + } + + public MethodInfo addTestMethod(String methodName) { + MethodInfo methodInfo = new MethodInfo(methodName); + testedMethods.add(methodInfo); + return methodInfo; + } + } + + protected void runStackFrameTest(StackFrameTester tester) { + printTestLog("STARTED"); + + // Wait for debuggee to start. + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Get variable information. + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + + // Install breakpoint. + int breakpointRequestID = debuggeeWrapper.vmMirror.setBreakpointAtMethodBegin(classID, + tester.getBreakpointMethodName()); + + // Signal debuggee with a custom message to execute the right method. + synchronizer.sendMessage(tester.getSignalValue()); + + // Wait for 1st breakpoint hit. + long eventThreadID = debuggeeWrapper.vmMirror.waitForBreakpoint(breakpointRequestID); + + // Check every local variable of every method. + checkStackFrame(classID, eventThreadID, tester, true); + + // Resume debuggee. + debuggeeWrapper.vmMirror.resume(); + + // Wait for 2nd breakpoint hit. + eventThreadID = debuggeeWrapper.vmMirror.waitForBreakpoint(breakpointRequestID); + + // Remove the breakpoint. + debuggeeWrapper.vmMirror.clearBreakpoint(breakpointRequestID); + + // Check every local variable of every method. + checkStackFrame(classID, eventThreadID, tester, false); + + // Resume debuggee. + // TODO we should let the test disconnects from debuggee. + debuggeeWrapper.vmMirror.resume(); + + printTestLog("FINISHED"); + } + + /** + * Checks the stack frame contains the values we expect during the test. + * + * @param classID + * the debuggee class ID + * @param eventThreadID + * the thread ID of the event thread + * @param tester + * an instance holding test logic + * @param firstSuspension + * true if the execution is suspended by the first breakpoint, false otherwise. + */ + private void checkStackFrame(long classID, long eventThreadID, StackFrameTester tester, + boolean firstSuspension) { + for (MethodInfo methodInfo : tester.getTestedMethods()) { + String testMethodName = methodInfo.getMethodName(); + long testMethodID = getMethodID(classID, testMethodName); + + VarInfo[] variables = jdwpGetVariableTable(classID, testMethodID); + assertNotNull("No variable table for method " + testMethodName, variables); + + // Find the frame for the tested method. + FrameInfo testMethodFrame = getFrameInfo(eventThreadID, classID, testMethodID); + assertNotNull("Cannot find frame for method " + testMethodName, testMethodFrame); + logWriter.println("Found frame for " + testMethodName + ": " + testMethodFrame.frameID); + + // Test all variables. + List<? extends VariableInfo> testedVariables = methodInfo.getVariables(); + assertTrue("Not enough variables in variable table", + variables.length >= testedVariables.size()); + for (VariableInfo variableInfo : testedVariables) { + String variableName = variableInfo.getVariableName(); + + VarInfo testVarInfo = getVariableInfo(variables, variableName); + assertNotNull("No variable info for \"" + variableName + "\"", testVarInfo); + + logWriter.println("Checking value for variable \"" + variableName + "\""); + + Value initialValue = variableInfo.getInitialValue(); + Value newValue = variableInfo.getNewValue(); + + // TODO specialize between GetValues and SetValues tests. + if (firstSuspension) { + if (newValue != null) { + // Sets the new value in the tested variable. + setVariableValue(eventThreadID, testMethodFrame.frameID, + testVarInfo.getSlot(), newValue); + } else { + // Check the value is the expected one. + Value expected = initialValue; + Value actual = getVariableValue(eventThreadID, testMethodFrame.frameID, + testVarInfo.getSlot(), expected.getTag()); + assertNotNull("No value for variable \"" + variableName + "\"", actual); + assertEquals("Incorrect value variable \"" + variableName + "\"", + expected, actual); + } + } else { + if (newValue != null) { + // Check the value is the expected one. + Value expected = newValue; + Value actual = getVariableValue(eventThreadID, testMethodFrame.frameID, + testVarInfo.getSlot(), expected.getTag()); + assertNotNull("No value for variable \"" + variableName + "\"", actual); + assertEquals("Incorrect value variable \"" + variableName + "\"", + expected, actual); + } else { + // Nothing to do. + } + } + } + } + } + + /** + * Base class for checking stack frame operations. + */ + static abstract class StackFrameChecker { + static class VariableNameAndTag { + public VariableNameAndTag(String testVariableName, byte testVariableJdwpTag) { + this.testVariableName = testVariableName; + this.testVariableJdwpTag = testVariableJdwpTag; + } + + /** + * Returns the name of the variable (in the tested method) for which + * we want to check the value. + */ + public String getTestVariableName() { + return testVariableName; + } + + /** + * Returns the JDWP tag of the tested variable. This matches the + * declared type of the variable in the tested method. + * + * Note: it can be different from the value's tag we retrieve from + * the stack in the case of Object variable (like String). + */ + public byte getTestVariableJdwpTag() { + return testVariableJdwpTag; + } + + private final String testVariableName; + private final byte testVariableJdwpTag; + + } + + protected StackFrameChecker(String breakpointMethodName, String testMethodName, + String testVariableName, byte testVariableJdwpTag) { + this(breakpointMethodName, testMethodName); + addTestedVariable(testVariableName, testVariableJdwpTag); + } + + protected StackFrameChecker(String breakpointMethodName, String testMethodName) { + this.breakpointMethodName = breakpointMethodName; + this.testMethodName = testMethodName; + this.testedVariables = new ArrayList<VariableNameAndTag>(); + } + + /** + * Returns the name of the method where a breakpoint is installed + * to suspend the debuggee. + */ + public String getBreakpointMethodName() { + return breakpointMethodName; + } + + /** + * Returns the name of the method calling the "breakpoint" method. + */ + public String getTestMethodName() { + return testMethodName; + } + + public int addTestedVariable(String name, byte tag) { + testedVariables.add(new VariableNameAndTag(name, tag)); + return testedVariables.size() - 1; + } + + public List<? extends VariableNameAndTag> getTestedVariables() { + return testedVariables; + } + + protected String getTestVariableName(int idx) { + return getTestedVariables().get(idx).getTestVariableName(); + } + + private final String breakpointMethodName; + private final String testMethodName; + private final List<VariableNameAndTag> testedVariables; + } + + /** + * Returns the {@link VarInfo} of the given variable in the given method. + * + * @param classID + * the ID of the declaring class of the method + * @param methodID + * the ID of the method + * @param variableName + * the name of the variable we look for + */ + protected VarInfo getVariableInfo(long classID, long methodID, String variableName) { + VarInfo[] variables = jdwpGetVariableTable(classID, methodID); + return getVariableInfo(variables, variableName); + } + + protected VarInfo getVariableInfo(VarInfo[] variables, String variableName) { + for (VarInfo variable : variables) { + if (variable.name.equals(variableName)) { + return variable; + } + } + return null; + } + + /** + * Returns the {@link FrameInfo} of the most recent frame matching the given method. + * + * @param threadID + * the ID of the thread where to look for the frame + * @param classID + * the ID of the declaring class of the method + * @param methodID + * the ID of the method + */ + protected FrameInfo getFrameInfo(long threadID, long classID, long methodID) { + int frameCount = jdwpGetFrameCount(threadID); + + // There should be at least 2 frames: the breakpoint method and its caller. + assertTrue("Not enough frames", frameCount > 2); + + FrameInfo[] frames = jdwpGetFrames(threadID, 0, frameCount); + for (FrameInfo frameInfo : frames) { + if (frameInfo.location.classID == classID && + frameInfo.location.methodID == methodID) { + return frameInfo; + } + } + return null; + } + + /** + * Returns the value of a local variable in the stack. + * + * @param threadID + * the ID of the thread of the stack + * @param frameID + * the ID of the frame of the stack + * @param slot + * the slot of the variable in the stack + * @param tag + * the type of the value + */ + protected Value getVariableValue(long threadID, long frameID, int slot, byte tag) { + logWriter.println(" Send StackFrame::GetValues: threadID=" + threadID + + ", frameID=" + frameID + ", slot=" + slot + + ", tag=" + JDWPConstants.Tag.getName(tag)); + + // Send StackFrame::GetValues command. + CommandPacket packet = new CommandPacket( + JDWPCommands.StackFrameCommandSet.CommandSetID, + JDWPCommands.StackFrameCommandSet.GetValuesCommand); + packet.setNextValueAsThreadID(threadID); + packet.setNextValueAsFrameID(frameID); + packet.setNextValueAsInt(1); + packet.setNextValueAsInt(slot); + packet.setNextValueAsByte(tag); + + // Check reply has no error. + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "StackFrame::GetValues command"); + + // Check we have 1 value. + int numberOfValues = reply.getNextValueAsInt(); + assertEquals("Incorrect number of values", 1, numberOfValues); + + // Check the value tag is correct. + Value value = reply.getNextValueAsValue(); + logWriter.println(" Received value " + value); + assertEquals("Invalid value tag", tag, value.getTag()); + + assertAllDataRead(reply); + return value; + } + + /** + * Sets the value of a local variable in the stack. + * + * @param threadID + * the ID of the thread of the stack + * @param frameID + * the ID of the frame of the stack + * @param slot + * the slot of the variable in the stack + * @param newValue + * the new value to set + */ + protected void setVariableValue(long threadID, long frameID, int slot, Value newValue) { + logWriter.println(" Send StackFrame::SetValues: threadID=" + threadID + + ", frameID=" + frameID + ", slot=" + slot + + ", value=" + newValue); + + // Send StackFrame::SetValues command. + CommandPacket packet = new CommandPacket(JDWPCommands.StackFrameCommandSet.CommandSetID, + JDWPCommands.StackFrameCommandSet.SetValuesCommand); + packet.setNextValueAsThreadID(threadID); + packet.setNextValueAsFrameID(frameID); + packet.setNextValueAsInt(1); + packet.setNextValueAsInt(slot); + packet.setNextValueAsValue(newValue); + + // Check reply has no error. + ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(reply, "StackFrame::SetValues command"); + } + + /** + * Returns the value of the static field identified by the given name in + * the given class. + * + * @param classID + * the ID of the declaring class of the static field + * @param fieldName + * the name of the static field in the class. + */ + protected Value getStaticFieldValue(long classID, String fieldName) { + long fieldID = debuggeeWrapper.vmMirror.getFieldID(classID, fieldName); + long[] fieldIDs = new long[]{ fieldID }; + Value[] fieldValues = debuggeeWrapper.vmMirror.getReferenceTypeValues(classID, fieldIDs); + assertNotNull("No field values", fieldValues); + assertEquals("Invalid field values count", fieldValues.length, 1); + return fieldValues[0]; + } +} diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/JDWPStackTraceBaseTest.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/JDWPStackTraceBaseTest.java new file mode 100644 index 0000000..824fb71 --- /dev/null +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/JDWPStackTraceBaseTest.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.StackFrame; + +import org.apache.harmony.jpda.tests.framework.LogWriter; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + +import java.util.ArrayList; +import java.util.Arrays; + +/** + * Base class for GetValuesTest and SetValuesTest classes. + */ +public class JDWPStackTraceBaseTest extends JDWPStackFrameTestCase { + String testedMethodName = "nestledMethod3"; + String testedThreadName = ""; + + VarInfo[] varInfos; + + String varSignatures[] = { + "Lorg/apache/harmony/jpda/tests/jdwp/StackFrame/StackTraceDebuggee;", + "Z", + "I", + "Ljava/lang/String;" + }; + + String varNames[] = { + "this", + "boolLocalVariable", + "intLocalVariable", + "strLocalVariable" + }; + + byte varTags[] = { + JDWPConstants.Tag.OBJECT_TAG, + JDWPConstants.Tag.BOOLEAN_TAG, + JDWPConstants.Tag.INT_TAG, + JDWPConstants.Tag.STRING_TAG + }; + + @Override + protected void internalSetUp() throws Exception { + super.internalSetUp(); + + logWriter.println("==> " + getName() + " started..."); + testedThreadName = synchronizer.receiveMessage(); + // release on run() + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + // pass nestledMethod1() + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + // enter nestledMethod2() + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // release debuggee + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + } + + @Override + protected void internalTearDown() { + // signal to finish debuggee + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + logWriter.println("==> " + getName() + " - OK."); + + super.internalTearDown(); + } + + protected long getThreadID() { + long threadID = debuggeeWrapper.vmMirror.getThreadID(testedThreadName); + logWriter.println("=> testedThreadID = " + threadID); + if (threadID == -1) { + printErrorAndFail("testedThread is not found!"); + } + return threadID; + } + + protected FrameInfo findFrameInfo(long threadID) { + // get number of frames + int frameCount = jdwpGetFrameCount(threadID); + logWriter.println("=> frames count = " + frameCount); + + // get frames info + FrameInfo[] frameIDs = jdwpGetFrames(threadID, 0, frameCount); + if (frameIDs.length != frameCount) { + printErrorAndFail("Received number of frames = " + + frameIDs.length + " differ from expected number = " + + frameCount); + } + + // check and print methods info + FrameInfo frameInfo = null; + for (int i = 0; i < frameCount; i++) { + logWriter.println("\n"); + String methodName = getMethodName(frameIDs[i].location.classID, + frameIDs[i].location.methodID); + logWriter.println("=> method name = " + methodName); + logWriter.println("=> methodID = " + frameIDs[i].location.methodID); + logWriter.println("=> frameID = " + frameIDs[i].frameID); + logWriter.println("\n"); + if (methodName.equals(testedMethodName)) { + frameInfo = frameIDs[i]; + } + } + if (frameInfo != null) { + logWriter.println("=> Tested method is found"); + logWriter.println("=> method name = " + testedMethodName); + logWriter.println("=> methodID = " + frameInfo.location.methodID); + logWriter.println("=> frameID = " + frameInfo.frameID); + } else { + printErrorAndFail("Tested method is not found"); + } + return frameInfo; + } + + // prints variables info, checks signatures + protected static boolean checkVarTable(LogWriter logWriter, VarInfo[] varInfos, + byte[] varTags, String[] varSignatures, String[] varNames) { + logWriter.println("==> Number of variables = " + varInfos.length); + if (varInfos.length != varTags.length) { + logWriter.printError("Unexpected number of variables: " + + varInfos.length + " instead of " + varTags.length); + return false; + } + boolean success = true; + ArrayList<String> remaining = new ArrayList<String>(Arrays.asList(varNames)); + for (int i = 0; i < varInfos.length; i++) { + logWriter.println(""); + logWriter.println("=> Name = " + varInfos[i].getName()); + logWriter.println("=> Slot = " + varInfos[i].getSlot()); + logWriter.println("=> Signature = " + varInfos[i].getSignature()); + // TODO: check codeIndex and length too + + int index = remaining.indexOf(varInfos[i].getName()); + if (index == -1) { + logWriter.printError("unknown variable: " + varInfos[i].getName()); + } + remaining.set(index, null); + + if (!varSignatures[index].equals(varInfos[i].getSignature())) { + logWriter + .printError("Unexpected signature of variable = " + + varInfos[i].getName() + + ", on slot = " + + varInfos[i].getSlot() + + ", with unexpected signature = " + + varInfos[i].getSignature() + + " instead of signature = " + varSignatures[index]); + success = false; + } + if (!varNames[index].equals(varInfos[i].getName())) { + logWriter.printError("Unexpected name of variable " + + varInfos[i].getName() + ", on slot = " + + varInfos[i].getSlot() + " instead of name = " + + varNames[index]); + success = false; + } + + logWriter.println(""); + } + return success; + } +} diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/SetValues002Test.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/SetValues002Test.java new file mode 100644 index 0000000..89faea4 --- /dev/null +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/SetValues002Test.java @@ -0,0 +1,412 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.StackFrame; + +import org.apache.harmony.jpda.tests.framework.jdwp.Value; + +/** + * JDWP Unit test for StackFrame.SetValues command. + */ +public class SetValues002Test extends JDWPStackFrameAccessTest { + /** + * Tests we correctly write value of boolean variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues001_Boolean() { + StackFrameTester tester = new StackFrameTester("breakpointBoolean", + StackTrace002Debuggee.BOOLEAN_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointBoolean"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.BOOLEAN_PARAM_VALUE), + new Value(StackTrace002Debuggee.BOOLEAN_PARAM_VALUE_TO_SET)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of byte variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues002_Byte() { + StackFrameTester tester = new StackFrameTester("breakpointByte", + StackTrace002Debuggee.BYTE_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointByte"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.BYTE_PARAM_VALUE), + new Value(StackTrace002Debuggee.BYTE_PARAM_VALUE_TO_SET)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of char variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues003_Char() { + StackFrameTester tester = new StackFrameTester("breakpointChar", + StackTrace002Debuggee.CHAR_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointChar"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.CHAR_PARAM_VALUE), + new Value(StackTrace002Debuggee.CHAR_PARAM_VALUE_TO_SET)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of short variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues004_Short() { + StackFrameTester tester = new StackFrameTester("breakpointShort", + StackTrace002Debuggee.SHORT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointShort"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.SHORT_PARAM_VALUE), + new Value(StackTrace002Debuggee.SHORT_PARAM_VALUE_TO_SET)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of int variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues005_Int() { + StackFrameTester tester = new StackFrameTester("breakpointInt", + StackTrace002Debuggee.INT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointInt"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.INT_PARAM_VALUE), + new Value(StackTrace002Debuggee.INT_PARAM_VALUE_TO_SET)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of long variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues006_Long() { + StackFrameTester tester = new StackFrameTester("breakpointLong", + StackTrace002Debuggee.LONG_METHOD_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointLong"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.LONG_PARAM_VALUE), + new Value(StackTrace002Debuggee.LONG_PARAM_VALUE_TO_SET)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of float variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues007_Float() { + StackFrameTester tester = new StackFrameTester("breakpointFloat", + StackTrace002Debuggee.FLOAT_METHOD); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointFloat"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.FLOAT_PARAM_VALUE), + new Value(StackTrace002Debuggee.FLOAT_PARAM_VALUE_TO_SET)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of double variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues008_Double() { + StackFrameTester tester = new StackFrameTester("breakpointDouble", + StackTrace002Debuggee.DOUBLE_METHOD); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointDouble"); + methodInfo.addVariable("param", new Value(StackTrace002Debuggee.DOUBLE_PARAM_VALUE), + new Value(StackTrace002Debuggee.DOUBLE_PARAM_VALUE_TO_SET)); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.Object variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues009_Object() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "OBJECT_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "OBJECT_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointObject", StackTrace002Debuggee.OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of Array variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues010_Array() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "ARRAY_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "ARRAY_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointArray", StackTrace002Debuggee.ARRAY_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointArray"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of Array into a local variable declared as + * java.lang.Object. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues010_ArrayAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "ARRAY_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "ARRAY_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointObject", StackTrace002Debuggee.ARRAY_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.Class variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues011_Class() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "CLASS_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "CLASS_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointClass", StackTrace002Debuggee.CLASS_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointClass"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.Class into a local variable declared as + * java.lang.Object. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues011_ClassAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "CLASS_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "CLASS_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointObject", StackTrace002Debuggee.CLASS_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.ClassLoader variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues012_ClassLoader() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "CLASS_LOADER_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "CLASS_LOADER_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointClassLoader", StackTrace002Debuggee.CLASS_LOADER_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointClassLoader"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.ClassLoader into a local variable declared as + * java.lang.Object. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues012_ClassLoaderAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "CLASS_LOADER_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "CLASS_LOADER_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointObject", StackTrace002Debuggee.CLASS_LOADER_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.String variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues013_String() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "STRING_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "STRING_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointString", StackTrace002Debuggee.STRING_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointString"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.String into a local variable declared as + * java.lang.Object. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues013_StringAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "STRING_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "STRING_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointObject", StackTrace002Debuggee.STRING_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.Thread variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues014_Thread() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "THREAD_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "THREAD_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointThread", StackTrace002Debuggee.THREAD_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointThread"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.Thread into a local variable declared as + * java.lang.Object. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues014_ThreadAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "THREAD_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "THREAD_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointObject", StackTrace002Debuggee.THREAD_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.ThreadGroup variable into the stack. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues015_ThreadGroup() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "THREAD_GROUP_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "THREAD_GROUP_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointThreadGroup", StackTrace002Debuggee.THREAD_GROUP_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointThreadGroup"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } + + /** + * Tests we correctly write value of java.lang.ThreadGroup into a local variable declared as + * java.lang.Object. + * + * Refer to {@link JDWPStackFrameAccessTest#runStackFrameTest(StackFrameTester)} + * method for the sequence of the test. + */ + public void testSetValues015_ThreadGroupAsObject() { + long classID = getClassIDBySignature(getDebuggeeClassSignature()); + Value actualValue = getStaticFieldValue(classID, + "THREAD_GROUP_PARAM_VALUE"); + Value expectedValue = getStaticFieldValue(classID, + "THREAD_GROUP_PARAM_VALUE_TO_SET"); + + StackFrameTester tester = new StackFrameTester( + "breakpointObject", StackTrace002Debuggee.THREAD_GROUP_AS_OBJECT_SIGNAL); + MethodInfo methodInfo = tester.addTestMethod("runBreakpointObject"); + methodInfo.addVariable("param", actualValue, expectedValue); + runStackFrameTest(tester); + } +} diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/SetValuesTest.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/SetValuesTest.java index 3a7038d..39763d0 100644 --- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/SetValuesTest.java +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/SetValuesTest.java @@ -24,35 +24,19 @@ */ package org.apache.harmony.jpda.tests.jdwp.StackFrame; -import java.util.Arrays; import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; +import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands.StackFrameCommandSet; import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; import org.apache.harmony.jpda.tests.framework.jdwp.Value; -import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + +import java.util.Arrays; /** * JDWP Unit test for StackFrame.SetValues command. */ -public class SetValuesTest extends JDWPStackFrameTestCase { - - String testedMethodName = "nestledMethod3"; - String testedThreadName = ""; - - VarInfo[] varInfos; - - String varSignatures[] = { "Lorg/apache/harmony/jpda/tests/jdwp/StackFrame/StackTraceDebuggee;", "Z", - "I", "Ljava/lang/String;" }; - - String varNames[] = { "this", "boolLocalVariable", "intLocalVariable", - "strLocalVariable" }; - - byte varTags[] = { JDWPConstants.Tag.OBJECT_TAG, JDWPConstants.Tag.BOOLEAN_TAG, - JDWPConstants.Tag.INT_TAG, JDWPConstants.Tag.STRING_TAG }; - - private String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/StackFrame/StackTraceDebuggee;"; - +public class SetValuesTest extends JDWPStackTraceBaseTest { /** * This testcase exercises StackFrame.SetValues command. * <BR>The test starts StackTraceDebuggee, sets breakpoint at the beginning of @@ -65,34 +49,123 @@ public class SetValuesTest extends JDWPStackFrameTestCase { * */ public void testSetValues001() { - logWriter.println("==> testSetValues001 started..."); - testedThreadName = synchronizer.receiveMessage(); - // release on run() - synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + // Sets and checks local variables of tested method + examineGetValues(); + } - // pass nestledMethod1() - synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); - synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + /** + * This testcase exercises StackFrame.SetValues command. + * <BR>The test starts StackTraceDebuggee and waits for it to reach the + * tested method - 'nestledMethod3'. + * <BR> Then it performs StackFrame.SetValues command with an invalid + * thread ID and checks the command returns error INVALID_OBJECT. + */ + public void testSetValues002_InvalidObjectError() { + long invalidThreadID = -1; + logWriter.println("Send StackFrame.SetValues with invalid thread " + invalidThreadID); + CommandPacket packet = new CommandPacket(StackFrameCommandSet.CommandSetID, + StackFrameCommandSet.SetValuesCommand); + packet.setNextValueAsThreadID(invalidThreadID); + packet.setNextValueAsFrameID(0); + packet.setNextValueAsInt(0); + ReplyPacket replyPacket = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(replyPacket, "StackFrame.SetValues", + JDWPConstants.Error.INVALID_OBJECT); + } - // enter nestledMethod2() - synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + /** + * This testcase exercises StackFrame.SetValues command. + * <BR>The test starts StackTraceDebuggee and waits for it to reach the + * tested method - 'nestledMethod3'. + * <BR> Then it performs StackFrame.SetValues command to a non-suspended + * thread and checks the command returns error THREAD_NOT_SUSPENDED. + */ + public void testSetValues003_ThreadNotSuspendedError() { + long threadID = getThreadID(); - //release debuggee - synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); - synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + CommandPacket packet = new CommandPacket(StackFrameCommandSet.CommandSetID, + StackFrameCommandSet.SetValuesCommand); + packet.setNextValueAsThreadID(threadID); + packet.setNextValueAsFrameID(0); + packet.setNextValueAsInt(0); + ReplyPacket replyPacket = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(replyPacket, "StackFrame.SetValues", + JDWPConstants.Error.THREAD_NOT_SUSPENDED); + } + + /** + * This testcase exercises StackFrame.SetValues command. + * <BR>The test starts StackTraceDebuggee and waits for it to reach the + * tested method - 'nestledMethod3'. + * <BR> Then it performs StackFrame.SetValues command to an invalid + * frame ID and checks the command returns error INVALID_FRAMEID. + */ + public void testSetValues004_InvalidFrameIDError() { + long threadID = getThreadID(); + + // suspend thread + jdwpSuspendThread(threadID); + long invalidFrameID = -1; + logWriter.println("Send StackFrame.SetValues with invalid frameID " + invalidFrameID); + CommandPacket packet = new CommandPacket(StackFrameCommandSet.CommandSetID, + StackFrameCommandSet.SetValuesCommand); + packet.setNextValueAsThreadID(threadID); + packet.setNextValueAsFrameID(invalidFrameID); + packet.setNextValueAsInt(0); + ReplyPacket replyPacket = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(replyPacket, "StackFrame.SetValues", + JDWPConstants.Error.INVALID_FRAMEID); + } + + /** + * This testcase exercises StackFrame.SetValues command. + * <BR>The test starts StackTraceDebuggee and waits for it to reach the + * tested method - 'nestledMethod3'. + * <BR> Then it performs StackFrame.SetValues command to an invalid + * slot ID and checks the command returns error INVALID_SLOT. + */ + public void testSetValues005_InvalidSlotError() { //sets and checks local variables of tested method - examineGetValues(); - // signal to finish debuggee - synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); - logWriter.println("==> testSetValues001 - OK."); + long threadID = getThreadID(); + // suspend thread + jdwpSuspendThread(threadID); + + FrameInfo frameInfo = findFrameInfo(threadID); + + //getting Variable Table + logWriter.println(""); + logWriter.println("=> Getting Variable Table..."); + long refTypeID = getClassIDBySignature(getDebuggeeClassSignature()); + logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); + logWriter.println("=> referenceTypeID for Debuggee class = " + + refTypeID); + varInfos = jdwpGetVariableTable(refTypeID, frameInfo.location.methodID); + if (GetValuesTest.checkVarTable(logWriter, varInfos, varTags, varSignatures, varNames)) { + logWriter.println("=> Variable table check passed."); + } else { + printErrorAndFail("Variable table check failed."); + } + + int invalidSlotId = -1; + logWriter.println("Send StackFrame.SetValues with invalid slot " + invalidSlotId); + CommandPacket packet = new CommandPacket(StackFrameCommandSet.CommandSetID, + StackFrameCommandSet.SetValuesCommand); + packet.setNextValueAsThreadID(threadID); + packet.setNextValueAsFrameID(frameInfo.frameID); + packet.setNextValueAsInt(1); + packet.setNextValueAsInt(invalidSlotId); + packet.setNextValueAsByte(JDWPConstants.Tag.OBJECT_TAG); + packet.setNextValueAsObjectID(0 /* null */); + ReplyPacket replyPacket = debuggeeWrapper.vmMirror.performCommand(packet); + checkReplyPacket(replyPacket, "StackFrame.SetValues", + JDWPConstants.Error.INVALID_SLOT); } private void examineGetValues() { - - long refTypeID = getClassIDBySignature(debuggeeSignature); + long refTypeID = getClassIDBySignature(getDebuggeeClassSignature()); logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); @@ -106,54 +179,14 @@ public class SetValuesTest extends JDWPStackFrameTestCase { // suspend thread jdwpSuspendThread(threadID); - //get number of frames - int frameCount = jdwpGetFrameCount(threadID); - logWriter.println("=> frames count = " + frameCount); - - //get frames info - FrameInfo[] frameIDs = jdwpGetFrames(threadID, 0, frameCount); - if (frameIDs.length != frameCount) { - printErrorAndFail("Received number of frames = " - + frameIDs.length + " differ from expected number = " - + frameCount); - } - - //check and print methods info - long methodID = 0; - long frameID = 0; - String methodName = ""; - boolean testedMethodChecked = false; - for (int i = 0; i < frameCount; i++) { - logWriter.println("\n"); - methodName = getMethodName(frameIDs[i].location.classID, - frameIDs[i].location.methodID); - logWriter.println("=> method name = " + methodName); - logWriter.println("=> methodID = " + frameIDs[i].location.methodID); - logWriter.println("=> frameID = " + frameIDs[i].frameID); - logWriter.println("\n"); - if (methodName.equals(testedMethodName)) { - methodID = frameIDs[i].location.methodID; - frameID = frameIDs[i].frameID; - methodName = getMethodName(frameIDs[i].location.classID, - frameIDs[i].location.methodID); - testedMethodChecked = true; - } - } - if (testedMethodChecked) { - logWriter.println("=> Tested method is found"); - logWriter.println("=> method name = " + testedMethodName); - logWriter.println("=> methodID = " + methodID); - logWriter.println("=> frameID = " + frameID); - - } else { - printErrorAndFail("Tested method is not found"); - } + // find frame for the tested method + FrameInfo frameInfo = findFrameInfo(threadID); //getting Variable Table logWriter.println(""); logWriter.println("=> Getting Variable Table..."); - varInfos = jdwpGetVariableTable(refTypeID, methodID); - if (GetValuesTest.checkVarTable(logWriter, varInfos, varTags, varSignatures, varNames)) { + varInfos = jdwpGetVariableTable(refTypeID, frameInfo.location.methodID); + if (checkVarTable(logWriter, varInfos, varTags, varSignatures, varNames)) { logWriter.println("=> Variable table check passed."); } else { printErrorAndFail("Variable table check failed."); @@ -166,7 +199,7 @@ public class SetValuesTest extends JDWPStackFrameTestCase { JDWPCommands.StackFrameCommandSet.CommandSetID, JDWPCommands.StackFrameCommandSet.SetValuesCommand); packet.setNextValueAsThreadID(threadID); - packet.setNextValueAsLong(frameID); + packet.setNextValueAsFrameID(frameInfo.frameID); packet.setNextValueAsInt(varTags.length-2); packet.setNextValueAsInt(varInfoByName("boolLocalVariable").getSlot()); @@ -184,10 +217,10 @@ public class SetValuesTest extends JDWPStackFrameTestCase { JDWPCommands.StackFrameCommandSet.CommandSetID, JDWPCommands.StackFrameCommandSet.GetValuesCommand); packet.setNextValueAsThreadID(threadID); - packet.setNextValueAsFrameID(frameID); + packet.setNextValueAsFrameID(frameInfo.frameID); logWriter.println("=> Thread: " + threadID); - logWriter.println("=> Frame: " + frameID); + logWriter.println("=> Frame: " + frameInfo.frameID); packet.setNextValueAsInt(varTags.length); for (int i = 0; i < varTags.length; i++) { logWriter.println(""); @@ -217,85 +250,74 @@ public class SetValuesTest extends JDWPStackFrameTestCase { //print and check values of variables logWriter.println("=> Values of variables: "); - Value val; - - val = reply.getNextValueAsValue(); - if (val.getTag() == JDWPConstants.Tag.BOOLEAN_TAG) { - logWriter.println("=>Tag is correct"); - boolean boolValue = val.getBooleanValue(); - if (!boolValue) { - logWriter.println("=> "+varInfos[1].getName() + " = " + boolValue); - logWriter.println(""); - } else { - logWriter + for (int i = 0; i < numberOfValues; ++i ) { + Value val = reply.getNextValueAsValue(); + switch (val.getTag()) { + case JDWPConstants.Tag.BOOLEAN_TAG: { + logWriter.println("=>Tag is correct"); + boolean boolValue = val.getBooleanValue(); + if (!boolValue) { + logWriter.println("=> "+varInfos[1].getName() + " = " + boolValue); + logWriter.println(""); + } else { + logWriter .printError("Unexpected value of boolean variable: " + boolValue + " instead of: false"); - logWriter.printError(""); - success = false; - } - } else { - logWriter.printError("Unexpected tag of variable: " - + JDWPConstants.Tag.getName(val.getTag()) + " instead of: boolean"); - logWriter.printError(""); - success = false; - } - - val = reply.getNextValueAsValue(); - if (val.getTag() == JDWPConstants.Tag.INT_TAG) { - logWriter.println("=>Tag is correct"); - int intValue = val.getIntValue(); - if (intValue == 12345) { - logWriter.println("=> "+varInfos[2].getName() + " = " + intValue); - logWriter.println(""); - } else { - logWriter + logWriter.printError(""); + success = false; + } + break; + } + + case JDWPConstants.Tag.INT_TAG: { + logWriter.println("=>Tag is correct"); + int intValue = val.getIntValue(); + if (intValue == 12345) { + logWriter.println("=> "+varInfos[2].getName() + " = " + intValue); + logWriter.println(""); + } else { + logWriter .printError("Unexpected value of int variable: " + intValue + " instead of: 12345"); - logWriter.printError(""); - success = false; - } - } else { - logWriter.printError("Unexpected tag of variable: " - + JDWPConstants.Tag.getName(val.getTag()) + " instead of: integer"); - logWriter.printError(""); - success = false; - } - - val = reply.getNextValueAsValue(); - if (val.getTag() == JDWPConstants.Tag.STRING_TAG) { - logWriter.println("=>Tag is correct"); - long strLocalVariableID = val.getLongValue(); - String strLocalVariable = getStringValue(strLocalVariableID); - if (strLocalVariable.equals("test string")) { - logWriter.println("=> "+varInfos[2].getName() + " = " - + strLocalVariable); - logWriter.println(""); - } else { - logWriter + logWriter.printError(""); + success = false; + } + break; + } + + case JDWPConstants.Tag.STRING_TAG: { + logWriter.println("=>Tag is correct"); + long strLocalVariableID = val.getLongValue(); + String strLocalVariable = getStringValue(strLocalVariableID); + if (strLocalVariable.equals("test string")) { + logWriter.println("=> "+varInfos[2].getName() + " = " + + strLocalVariable); + logWriter.println(""); + } else { + logWriter .printError("Unexpected value of string variable: " + strLocalVariable + " instead of: " + "test string"); - logWriter.printError(""); - success = false; - } - } else { - logWriter.printError("Unexpected tag of variable: " - + JDWPConstants.Tag.getName(val.getTag()) + " instead of: string"); - logWriter.printError(""); - success = false; - } - - val = reply.getNextValueAsValue(); - if (val.getTag() == JDWPConstants.Tag.OBJECT_TAG) { - logWriter.println("=> Tag is correct"); - logWriter.println(""); - } else { - logWriter.printError("Unexpected tag of variable: " - + JDWPConstants.Tag.getName(val.getTag()) + " instead of: CLASS_OBJECT_TAG"); - logWriter.printError(""); - success = false; - } + logWriter.printError(""); + success = false; + } + break; + } + + case JDWPConstants.Tag.OBJECT_TAG: { + logWriter.println("=> Tag is correct"); + logWriter.println(""); + break; + } + default: + logWriter.printError("Unexpected tag of variable: " + + JDWPConstants.Tag.getName(val.getTag())); + logWriter.printError(""); + success = false; + break; + } // switch + } // for assertTrue(logWriter.getErrorMessage(), success); } diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/StackTrace002Debuggee.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/StackTrace002Debuggee.java new file mode 100644 index 0000000..52b0123 --- /dev/null +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/StackFrame/StackTrace002Debuggee.java @@ -0,0 +1,339 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.StackFrame; + +import org.apache.harmony.jpda.tests.framework.TestErrorException; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; +import org.apache.harmony.jpda.tests.share.SyncDebuggee; + +/** + * Debuggee for GetValues002Test and SetValues002Test. + */ +public class StackTrace002Debuggee extends SyncDebuggee { + // Signals to select which method the debuggee needs to call. + static final String BOOLEAN_SIGNAL = "runBreakpointBoolean"; + static final String BYTE_SIGNAL = "runBreakpointByte"; + static final String CHAR_SIGNAL = "runBreakpointChar"; + static final String SHORT_SIGNAL = "runBreakpointShort"; + static final String INT_SIGNAL = "runBreakpointInt"; + static final String INT_METHOD2_SIGNAL = "runBreakpointInt2"; + static final String LONG_METHOD_SIGNAL = "runBreakpointLong"; + static final String FLOAT_METHOD = "runBreakpointFloat"; + static final String DOUBLE_METHOD = "runBreakpointDouble"; + static final String OBJECT_SIGNAL = "runBreakpointObject"; + static final String ARRAY_SIGNAL = "runBreakpointArray"; + static final String CLASS_SIGNAL = "runBreakpointClass"; + static final String CLASS_LOADER_SIGNAL = "runBreakpointClassLoader"; + static final String STRING_SIGNAL = "runBreakpointString"; + static final String THREAD_SIGNAL = "runBreakpointThread"; + static final String THREAD_GROUP_SIGNAL = "runBreakpointThreadGroup"; + static final String ARRAY_AS_OBJECT_SIGNAL = "runBreakpointArrayAsObject"; + static final String CLASS_AS_OBJECT_SIGNAL = "runBreakpointClassAsObject"; + static final String CLASS_LOADER_AS_OBJECT_SIGNAL = "runBreakpointClassLoaderAsObject"; + static final String STRING_AS_OBJECT_SIGNAL = "runBreakpointStringAsObject"; + static final String THREAD_AS_OBJECT_SIGNAL = "runBreakpointThreadAsObject"; + static final String THREAD_GROUP_AS_OBJECT_SIGNAL = "runBreakpointThreadGroupAsObject"; + + // Values used to check StackFrame.GetValues. + static final boolean BOOLEAN_PARAM_VALUE = true; + static final byte BYTE_PARAM_VALUE = 123; + static final char CHAR_PARAM_VALUE = '@'; + static final short SHORT_PARAM_VALUE = 12345; + static final int INT_PARAM_VALUE = 123456789; + static final long LONG_PARAM_VALUE = 102030405060708090L; + static final float FLOAT_PARAM_VALUE = 123.456f; + static final double DOUBLE_PARAM_VALUE = 0.123456789; + static final Object OBJECT_PARAM_VALUE = new Object(); + static final int[] ARRAY_PARAM_VALUE = new int[]{1, 2, 3, 4, 5}; + static final Class<?> CLASS_PARAM_VALUE = StackTrace002Debuggee.class; + static final ClassLoader CLASS_LOADER_PARAM_VALUE = CLASS_PARAM_VALUE.getClassLoader(); + static final String STRING_PARAM_VALUE = "this is a string object"; + static final Thread THREAD_PARAM_VALUE = new Thread("this is a thread"); + static final ThreadGroup THREAD_GROUP_PARAM_VALUE = THREAD_PARAM_VALUE.getThreadGroup(); + + // Values used to check StackFrame.SetValues. + static final boolean BOOLEAN_PARAM_VALUE_TO_SET = !BOOLEAN_PARAM_VALUE; + static final byte BYTE_PARAM_VALUE_TO_SET = -BYTE_PARAM_VALUE; + static final char CHAR_PARAM_VALUE_TO_SET = '%'; + static final short SHORT_PARAM_VALUE_TO_SET = -SHORT_PARAM_VALUE; + static final int INT_PARAM_VALUE_TO_SET = -INT_PARAM_VALUE; + static final long LONG_PARAM_VALUE_TO_SET = -LONG_PARAM_VALUE; + static final float FLOAT_PARAM_VALUE_TO_SET = -FLOAT_PARAM_VALUE; + static final double DOUBLE_PARAM_VALUE_TO_SET = -DOUBLE_PARAM_VALUE; + static final Object OBJECT_PARAM_VALUE_TO_SET = new Object(); + static final int[] ARRAY_PARAM_VALUE_TO_SET = new int[]{5, 4, 3, 2, 1}; + static final Class<?> CLASS_PARAM_VALUE_TO_SET = Object.class; + static final ClassLoader CLASS_LOADER_PARAM_VALUE_TO_SET = + CLASS_PARAM_VALUE_TO_SET.getClassLoader(); + static final String STRING_PARAM_VALUE_TO_SET = "this is another string object"; + static final Thread THREAD_PARAM_VALUE_TO_SET = new Thread("this is another thread"); + static final ThreadGroup THREAD_GROUP_PARAM_VALUE_TO_SET = + THREAD_PARAM_VALUE_TO_SET.getThreadGroup(); + + // A reference to 'this' debuggee. + static Object THIS_OBJECT; + + public static void main(String[] args) { + runDebuggee(StackTrace002Debuggee.class); + } + + @Override + public void run() { + THIS_OBJECT = this; + + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Wait for test setup. + String signal = synchronizer.receiveMessage(); + + // Invoke the method requested by the test. + switch (signal) { + case BOOLEAN_SIGNAL: + runBreakpointBoolean(BOOLEAN_PARAM_VALUE); + break; + case BYTE_SIGNAL: + runBreakpointByte(BYTE_PARAM_VALUE); + break; + case CHAR_SIGNAL: + runBreakpointChar(CHAR_PARAM_VALUE); + break; + case SHORT_SIGNAL: + runBreakpointShort(SHORT_PARAM_VALUE); + break; + case INT_SIGNAL: + runBreakpointInt(INT_PARAM_VALUE); + break; + case INT_METHOD2_SIGNAL: + runBreakpointInt2(INT_PARAM_VALUE); + break; + case LONG_METHOD_SIGNAL: + runBreakpointLong(LONG_PARAM_VALUE); + break; + case FLOAT_METHOD: + runBreakpointFloat(FLOAT_PARAM_VALUE); + break; + case DOUBLE_METHOD: + runBreakpointDouble(DOUBLE_PARAM_VALUE); + break; + case OBJECT_SIGNAL: + runBreakpointObject(OBJECT_PARAM_VALUE); + break; + case ARRAY_SIGNAL: + runBreakpointArray(ARRAY_PARAM_VALUE); + break; + case CLASS_SIGNAL: + runBreakpointClass(CLASS_PARAM_VALUE); + break; + case CLASS_LOADER_SIGNAL: + runBreakpointClassLoader(CLASS_LOADER_PARAM_VALUE); + break; + case STRING_SIGNAL: + runBreakpointString(STRING_PARAM_VALUE); + break; + case THREAD_SIGNAL: + runBreakpointThread(THREAD_PARAM_VALUE); + break; + case THREAD_GROUP_SIGNAL: + runBreakpointThreadGroup(THREAD_GROUP_PARAM_VALUE); + break; + case ARRAY_AS_OBJECT_SIGNAL: + runBreakpointObject(ARRAY_PARAM_VALUE); + break; + case CLASS_AS_OBJECT_SIGNAL: + runBreakpointObject(CLASS_PARAM_VALUE); + break; + case CLASS_LOADER_AS_OBJECT_SIGNAL: + runBreakpointObject(CLASS_LOADER_PARAM_VALUE); + break; + case STRING_AS_OBJECT_SIGNAL: + runBreakpointObject(STRING_PARAM_VALUE); + break; + case THREAD_AS_OBJECT_SIGNAL: + runBreakpointObject(THREAD_PARAM_VALUE); + break; + case THREAD_GROUP_AS_OBJECT_SIGNAL: + runBreakpointObject(THREAD_GROUP_PARAM_VALUE); + break; + default: + throw new TestErrorException("Unexpected signal \"" + signal + "\""); + } + + } + + // Test boolean type. + public void runBreakpointBoolean(boolean param) { + breakpointBoolean(param); + breakpointBoolean(param); + } + + public void breakpointBoolean(boolean param) { + logWriter.println("breakpointBoolean(param=" + param + ")"); + } + + // Test byte type. + public void runBreakpointByte(byte param) { + breakpointByte(param); + breakpointByte(param); + } + + public void breakpointByte(byte param) { + logWriter.println("breakpointByte(param=" + param + ")"); + } + + // Test char type. + public void runBreakpointChar(char param) { + breakpointChar(param); + breakpointChar(param); + } + + public void breakpointChar(char param) { + logWriter.println("breakpointChar(param=" + param + ")"); + } + + // Test short type. + public void runBreakpointShort(short param) { + breakpointShort(param); + breakpointShort(param); + } + + public void breakpointShort(short param) { + logWriter.println("breakpointShort(param=" + param + ")"); + } + + // Test int type. + public void runBreakpointInt(int param) { + breakpointInt(param); + breakpointInt(param); + } + + public void breakpointInt(int param) { + logWriter.println("breakpointInt(param=" + param + ")"); + } + + public void runBreakpointInt2(int param) { + int local = param; + breakpointInt2(local); + local = local + param; + breakpointInt2(local); + } + + public void breakpointInt2(int param) { + logWriter.println("breakpointInt2(param=" + param + ")"); + } + + // Test long type. + public void runBreakpointLong(long param) { + breakpointLong(param); + breakpointLong(param); + } + + public void breakpointLong(long param) { + logWriter.println("breakpointLong(param=" + param + ")"); + } + + // Test float type. + public void runBreakpointFloat(float param) { + breakpointFloat(param); + breakpointFloat(param); + } + + public void breakpointFloat(float param) { + logWriter.println("breakpointFloat(param=" + param + ")"); + } + + // Test double type. + public void runBreakpointDouble(double param) { + breakpointDouble(param); + breakpointDouble(param); + } + + public void breakpointDouble(double param) { + logWriter.println("breakpointDouble(param=" + param + ")"); + } + + // Test java.lang.Object type. + public void runBreakpointObject(Object param) { + breakpointObject(param); + breakpointObject(param); + } + + public void breakpointObject(Object param) { + logWriter.println("breakpointObject(param=\"" + param + "\")"); + } + + // Test array type. + public void runBreakpointArray(int[] param) { + breakpointArray(param); + breakpointArray(param); + } + + public void breakpointArray(int[] param) { + logWriter.println("breakpointArray(param=\"" + param + "\")"); + } + + // Test java.lang.Class type. + public void runBreakpointClass(Class<?> param) { + breakpointClass(param); + breakpointClass(param); + } + + public void breakpointClass(Class<?> param) { + logWriter.println("breakpointClass(param=\"" + param + "\")"); + } + + // Test java.lang.ClassLoader type. + public void runBreakpointClassLoader(ClassLoader param) { + breakpointClassLoader(param); + breakpointClassLoader(param); + } + + public void breakpointClassLoader(ClassLoader param) { + logWriter.println("breakpointClassLoader(param=\"" + param + "\")"); + } + + // Test java.lang.String type. + public void runBreakpointString(String param) { + breakpointString(param); + breakpointString(param); + } + + public void breakpointString(String param) { + logWriter.println("breakpointString(param=\"" + param + "\")"); + } + + // Test java.lang.Thread type. + public void runBreakpointThread(Thread param) { + breakpointThread(param); + breakpointThread(param); + } + + public void breakpointThread(Thread param) { + logWriter.println("breakpointThread(param=\"" + param + "\")"); + } + + // Test java.lang.ThreadGroup type. + public void runBreakpointThreadGroup(ThreadGroup param) { + breakpointThreadGroup(param); + breakpointThreadGroup(param); + } + + public void breakpointThreadGroup(ThreadGroup param) { + logWriter.println("breakpointThreadGroup(param=\"" + param + "\")"); + } +}
\ No newline at end of file diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java index 75f0a92..bcb1864 100644 --- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java @@ -154,10 +154,12 @@ public class AllTests { suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceDebugExtensionTest.class); suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceFileTest.class); suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.StatusTest.class); + suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.StackFrame.GetValues002Test.class); suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.StackFrame.GetValuesTest.class); suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.StackFrame.PopFrames002Test.class); suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.StackFrame.PopFramesTest.class); suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.StackFrame.ProxyThisObjectTest.class); + suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.StackFrame.SetValues002Test.class); suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.StackFrame.SetValuesTest.class); suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.StackFrame.ThisObjectTest.class); suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.StringReference.ValueTest.class); |