harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r647082 - in /harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp: ReferenceType/InstancesTest.java ThreadReference/ForceEarlyReturnDebuggee.java ThreadReference/ForceEarlyReturnTest.java
Date Fri, 11 Apr 2008 08:52:12 GMT
Author: lvjing
Date: Fri Apr 11 01:52:07 2008
New Revision: 647082

URL: http://svn.apache.org/viewvc?rev=647082&view=rev
Log:
Apply patch for HARMONY-5704,[jdktools][jdwp6] Add some new tests for JDWP 6

Modified:
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnDebuggee.java
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnTest.java

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java?rev=647082&r1=647081&r2=647082&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesTest.java
Fri Apr 11 01:52:07 2008
@@ -35,11 +35,16 @@
     static int maxInstances;
 
     static final String thisCommandName = "ReferenceType.Instances command";
+    
+    static String thisTestName;
 
     static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/InstancesDebuggee;";
 
     static final String mockClassSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/MockClass;";
 
+    static final String stringSignature = "Ljava/lang/String;";
+
+    static final String intArraySignature = "[I";
     @Override
     protected String getDebuggeeClassName() {
         return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.InstancesDebuggee";
@@ -53,8 +58,6 @@
      * objects are expected ones.
      */
     private void runTestInstances() {
-        String thisTestName = "testInstances001";
-
         // check capability, relevant for this test
         logWriter.println("=> Check capability: canGetInstanceInfo");
         debuggeeWrapper.vmMirror.capabilities();
@@ -159,6 +162,7 @@
      * are returned.
      */
     public void testInstances001() {
+        thisTestName = "testInstances001";
         maxInstances = 0;
         runTestInstances();
     }
@@ -171,6 +175,7 @@
      * ILLEGAL_ARGUMENT exception are replied.
      */
     public void testInstances002() {
+        thisTestName = "testInstances002";
         maxInstances = -1;
         runTestInstances();
     }
@@ -184,6 +189,7 @@
      * objects of this reference type, so all instances are returned.
      */
     public void testInstances003() {
+        thisTestName = "testInstances003";
         maxInstances = 20;
         runTestInstances();
     }
@@ -197,9 +203,130 @@
      * objects of this reference type, so maximum number of instances are returned.
      */
     public void testInstances004() {
+        thisTestName = "testInstances004";
         maxInstances = 1;
         runTestInstances();
     }
+    
+    /**
+     * It starts InstancesDebuggee class, requests referenceTypeId for String
+     * class by VirtualMachine.ClassesBySignature command, then performs
+     * ReferenceType.Instances command and checks that returned reachable String
+     * objects are expected.
+     */
+    public void testInstances_String() {
+        String thisTestName = "testInstances_String";
+
+        // check capability, relevant for this test
+        logWriter.println("=> Check capability: canGetInstanceInfo");
+        debuggeeWrapper.vmMirror.capabilities();
+        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canGetInstanceInfo;
+        if (!isCapability) {
+            logWriter
+                    .println("##WARNING: this VM dosn't possess capability: canGetInstanceInfo");
+            return;
+        }
+
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName
+                + ": START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        long stringRefTypeID = getClassIDBySignature(stringSignature);
+        maxInstances = 10;
+
+        logWriter.println("=> CHECK: send " + thisCommandName
+                + " and check reply for ERROR...");
+
+        CommandPacket InstancesCommand = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.InstancesCommand);
+        InstancesCommand.setNextValueAsReferenceTypeID(stringRefTypeID);
+        InstancesCommand.setNextValueAsInt(maxInstances);
+
+        ReplyPacket checkedReply = debuggeeWrapper.vmMirror
+                .performCommand(InstancesCommand);
+        InstancesCommand = null;
+        checkReplyPacket(checkedReply, thisTestName);
+
+        // Get the number of instances that returned.
+        int reachableInstancesNum = checkedReply.getNextValueAsInt();
+
+        for (int i = 0; i < reachableInstancesNum; i++) {
+            // Get the tagged-objectID
+            byte tag = checkedReply.getNextValueAsByte();
+            assertEquals(thisCommandName + "returned String tag is invalid.",
+                    's', tag, null, null);
+            long objectID = checkedReply.getNextValueAsObjectID();
+            logWriter.println("=> ObjectID is: " + objectID);
+
+        }
+        logWriter.println("=> CHECK: PASSED: expected instances are returned:");
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName
+                + ": FINISH");
+        assertAllDataRead(checkedReply);
+
+    }
+
+    /**
+     * It starts InstancesDebuggee class, requests referenceTypeId for Array
+     * class by VirtualMachine.ClassesBySignature command, then performs
+     * ReferenceType.Instances command and checks that returned reachable Array
+     * objects are expected.
+     */
+    public void testInstances_Array() {
+        String thisTestName = "testInstances_Array";
+
+        // check capability, relevant for this test
+        logWriter.println("=> Check capability: canGetInstanceInfo");
+        debuggeeWrapper.vmMirror.capabilities();
+        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canGetInstanceInfo;
+        if (!isCapability) {
+            logWriter
+                    .println("##WARNING: this VM dosn't possess capability: canGetInstanceInfo");
+            return;
+        }
+
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName
+                + ": START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        long intArrayRefTypeID = getClassIDBySignature(intArraySignature);
+        maxInstances = 10;
+
+        logWriter.println("=> CHECK: send " + thisCommandName
+                + " and check reply for ERROR...");
+
+        CommandPacket InstancesCommand = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.InstancesCommand);
+        InstancesCommand.setNextValueAsReferenceTypeID(intArrayRefTypeID);
+        InstancesCommand.setNextValueAsInt(maxInstances);
+
+        ReplyPacket checkedReply = debuggeeWrapper.vmMirror
+                .performCommand(InstancesCommand);
+        InstancesCommand = null;
+        checkReplyPacket(checkedReply, thisTestName);
+
+        // Get the number of instances that returned.
+        int reachableInstancesNum = checkedReply.getNextValueAsInt();
+
+        for (int i = 0; i < reachableInstancesNum; i++) {
+            // Get the tagged-objectID
+            byte tag = checkedReply.getNextValueAsByte();
+            assertEquals(thisCommandName + "returned Array tag is invalid.",
+                    '[', tag, null, null);
+            long objectID = checkedReply.getNextValueAsObjectID();
+            logWriter.println("=> ObjectID is: " + objectID);
+
+        }
+        logWriter.println("=> CHECK: PASSED: expected instances are returned:");
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName
+                + ": FINISH");
+        assertAllDataRead(checkedReply);
+
+    }    
 
     public static void main(String[] args) {
         junit.textui.TestRunner.run(InstancesTest.class);

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnDebuggee.java?rev=647082&r1=647081&r2=647082&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnDebuggee.java
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnDebuggee.java
Fri Apr 11 01:52:07 2008
@@ -247,7 +247,7 @@
                         synchronizer.sendMessage(new Double(result).toString());
                         logWriter
                                 .println(getName() + ": func_Double returned.");
-                    } else {
+                    } else if (getName().equals(THREAD_VOID)) {
                         func_Void();
                         logWriter.println(getName() + ": " + "void");
                         if (isFuncVoidBreak) {
@@ -256,6 +256,10 @@
                             synchronizer.sendMessage("FALSE");
                         }
                         logWriter.println(getName() + ": func_Void returned.");
+                    } else {
+                        logWriter.println(getName() + ": no func is called.");
+                        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+                        synchronizer.receiveMessage("ThreadExit");
                     }
 
                     logWriter.println(getName() + ": finished");

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnTest.java?rev=647082&r1=647081&r2=647082&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnTest.java
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/ThreadReference/ForceEarlyReturnTest.java
Fri Apr 11 01:52:07 2008
@@ -24,6 +24,7 @@
 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.framework.jdwp.JDWPConstants.Tag;
 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
 
@@ -226,6 +227,69 @@
         RunTestForceEarlyReturn();
     }
 
+    /**
+     * This testcase exercises ThreadReference.ForceEarlyReturn command. <BR>
+     * At first the test starts ForceEarlyReturnDebuggee and send it the thread
+     * name through which to start a specific thread. Then the test performs the
+     * ThreadReference.ForceEarlyReturn command for the tested thread without
+     * suspending the VM. In this testcase, THREAD_NOT_SUSPENDED exception is returned.
+     */
+    public void testForceEarlyReturn_NotSuspended() {
+        thisTestName = "testForceEarlyReturn_NotSuspended";
+        testThreadName = "test";
+        expectedValue = new Value(Tag.VOID_TAG, 0);
+
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName
+                + ": START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        if (!isCapability()) {
+            logWriter
+                    .println("##WARNING: this VM dosn't possess capability: canForceEarlyReturn");
+            return;
+        }
+        // Tell debuggee to start a thread
+        synchronizer.sendMessage(testThreadName);
+
+        // Wait thread signal.
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        // Getting ID of the tested thread
+        logWriter.println("==> testedThreadName = " + testThreadName);
+        logWriter.println("==> Get testedThreadID...");
+        long testedThreadID = debuggeeWrapper.vmMirror
+                .getThreadID(testThreadName);
+        logWriter.println("==> Get testedThreadID is" + testedThreadID);
+
+        // Compose the ForceEarlyReturn command
+        CommandPacket forceEarlyReturnPacket = new CommandPacket(
+                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadReferenceCommandSet.ForceEarlyReturnCommand);
+        forceEarlyReturnPacket.setNextValueAsThreadID(testedThreadID);
+        forceEarlyReturnPacket.setNextValueAsValue(expectedValue);
+
+        // Perform the command
+        logWriter.println("==> Perform " + thisCommandName);
+        ReplyPacket forceEarlyReturnReply = debuggeeWrapper.vmMirror
+                .performCommand(forceEarlyReturnPacket);
+        forceEarlyReturnPacket = null;
+
+        short errorCode = forceEarlyReturnReply.getErrorCode();
+        if (errorCode != JDWPConstants.Error.NONE) {
+            if (errorCode == JDWPConstants.Error.THREAD_NOT_SUSPENDED) {
+                logWriter
+                        .println("=> CHECK PASSED: Expected error (THREAD_NOT_SUSPENDED)
is returned");
+                synchronizer.sendMessage("ThreadExit");
+                synchronizer
+                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+                return;
+            }
+        }
+        printErrorAndFail(thisCommandName
+                + " should throw exception when VM is not suspended.");
+
+    }
+    
     public static void main(String[] args) {
         junit.textui.TestRunner.run(ForceEarlyReturnTest.class);
 



Mime
View raw message