You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/11/28 18:49:31 UTC

svn commit: r480141 [37/38] - in /harmony/enhanced/jdktools/trunk/modules/jpda: ./ doc/ doc/images/ make/ src/ src/common/ src/common/other/ src/common/other/jpda/ src/common/other/jpda/jdwp/ src/common/other/jpda/jdwp/agent/ src/common/other/jpda/jdwp...

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/ResumeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/ResumeTest.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/ResumeTest.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/ResumeTest.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,260 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin, Anatoly F. Bondarenko
+ * @version $Revision: 1.6 $
+ */
+
+/**
+ * Created on 10.02.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
+
+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.exceptions.ReplyErrorCodeException;
+import org.apache.harmony.jpda.tests.jdwp.ThreadReference.ResumeDebuggee;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
+
+
+/**
+ * JDWP Unit test for VirtualMachine.Resume command.
+ */
+public class ResumeTest extends JDWPSyncTestCase {
+
+    static final String debuggeeSignature = 
+        "Lorg/apache/harmony/jpda/tests/jdwp/VirtualMachine/ResumeDebuggee;";
+
+   protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.VirtualMachine.ResumeDebuggee";
+    }
+
+    /**
+     * This testcase exercises VirtualMachine.Resume command.
+     * <BR>At first the test starts ResumeDebuggee which starts and runs some tested threads. 
+     * <BR> Then the test performs VirtualMachine.Suspend command and checks with help of 
+     * ThreadReference.Status command that all debuggee tested threads are suspended. 
+     * <BR> Then the test performs VirtualMachine.Resume command and checks with help of 
+     * ThreadReference.Status command that all debuggee tested threads are resumed. 
+     */
+    public void testResume001() {
+        logWriter.println("==> testResume001: START...");
+        String debuggeeMessage = synchronizer.receiveMessage();
+        int testedThreadsNumber = 0;
+        try {
+            testedThreadsNumber = Integer.valueOf(debuggeeMessage).intValue();
+        } catch (NumberFormatException exception) {
+            logWriter.println
+                ("## FAILURE: Exception while getting number of started threads from debuggee = " + exception);
+            setStaticIntField(debuggeeSignature, ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+            printErrorAndFail("\n## Can NOT get number of started threads from debuggee! ");
+        }
+        testedThreadsNumber++; // to add debuggee main thread
+        logWriter.println("==>  Number of threads in debuggee to test = " + testedThreadsNumber);
+        String[] testedThreadsNames = new String[testedThreadsNumber];
+        long[] testedThreadsIDs = new long[testedThreadsNumber];
+        String debuggeeMainThreadName = synchronizer.receiveMessage();
+        for (int i = 0; i < testedThreadsNumber; i++) {
+            if ( i < (testedThreadsNumber-1) ) {
+                testedThreadsNames[i] = ResumeDebuggee.THREAD_NAME_PATTERN + i;
+            } else {
+                testedThreadsNames[i] = debuggeeMainThreadName;
+            }
+            testedThreadsIDs[i] = 0;
+        }
+
+        // getting ID of the tested thread
+        ReplyPacket allThreadIDReply = null;
+        try {
+            allThreadIDReply = debuggeeWrapper.vmMirror.getAllThreadID();
+        } catch (ReplyErrorCodeException exception) {
+            logWriter.println
+                ("## FAILURE: Exception in vmMirror.getAllThreadID() = " + exception);
+            setStaticIntField(debuggeeSignature, ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+            printErrorAndFail("\n## Can NOT get all ThreadID in debuggee! ");
+        }
+        int threads = allThreadIDReply.getNextValueAsInt();
+        logWriter.println("==>  Number of all threads in debuggee = " + threads);
+        for (int i = 0; i < threads; i++) {
+            long threadID = allThreadIDReply.getNextValueAsThreadID();
+            String threadName = null;
+            try {
+                threadName = debuggeeWrapper.vmMirror.getThreadName(threadID); 
+            } catch (ReplyErrorCodeException exception) {
+                logWriter.println
+                    ("==> WARNING: Can NOT get thread name for threadID = " + threadID);
+                continue;
+            }
+            int k = 0;
+            for (; k < testedThreadsNumber; k++) {
+                if ( threadName.equals(testedThreadsNames[k]) ) {
+                    testedThreadsIDs[k] = threadID;
+                    break;
+                }
+            }
+        }
+            
+        boolean testedThreadNotFound = false;
+        for (int i = 0; i < testedThreadsNumber; i++) {
+            if ( testedThreadsIDs[i] == 0 ) {
+                logWriter.println("## FAILURE: Tested thread is not found out among debuggee threads!");
+                logWriter.println("##          Thread name = " + testedThreadsNames[i]);
+                testedThreadNotFound = true;
+            }
+        }
+        if ( testedThreadNotFound ) {
+            setStaticIntField(debuggeeSignature, ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+            printErrorAndFail("\n## Some of tested threads are not found!");
+        }
+
+        logWriter.println("\n==> Send VirtualMachine.Suspend command..."); 
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.SuspendCommand);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        int errorCode = reply.getErrorCode();
+        if ( errorCode !=  JDWPConstants.Error.NONE ) {
+            setStaticIntField(debuggeeSignature, ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+            logWriter.println("## FAILURE: VirtualMachine.Suspend command returns error = " + errorCode 
+                    + "(" + JDWPConstants.Error.getName(errorCode) + ")");
+            printErrorAndFail("\nVirtualMachine.Suspend command FAILED!");
+        } else {
+            logWriter.println("==> VirtualMachine.Suspend command - OK.");
+        }
+        
+        logWriter.println
+        ("\n==> Check that all tested threads are suspended after VirtualMachine.Suspend command...");
+
+        boolean statusCommandFailed = false;
+        boolean suspendStatusFailed = false;
+        for (int i = 0; i < testedThreadsNumber; i++) {
+            logWriter.println("\n==> Check for Thread: threadID = " + testedThreadsIDs[i] 
+                + "; threadName = " + testedThreadsNames[i]);
+
+            logWriter.println("==> Send ThreadReference.Status command..."); 
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
+            packet.setNextValueAsReferenceTypeID(testedThreadsIDs[i]);
+            reply = debuggeeWrapper.vmMirror.performCommand(packet);
+            if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.Status command") ) {
+                statusCommandFailed = true;
+                continue;
+            }
+
+            int threadStatus = reply.getNextValueAsInt();
+            int suspendStatus = reply.getNextValueAsInt();
+
+            logWriter.println("==> threadStatus = " + threadStatus + "("
+                    + JDWPConstants.ThreadStatus.getName(threadStatus) + ")");
+            logWriter.println("==> suspendStatus = " + suspendStatus + "("
+                    + JDWPConstants.SuspendStatus.getName(suspendStatus) + ")");
+            if (suspendStatus
+                    != JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
+                logWriter.println("## FAILURE: Unexpected suspendStatus for checked thread!");
+                logWriter.println("##          Expected suspendStatus  = "  
+                    + JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED
+                    + "(" + JDWPConstants.SuspendStatus.getName
+                    (JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) +")");
+                suspendStatusFailed = true;
+                continue;
+            }
+        }
+            
+        String errorMessage = "";
+        if ( statusCommandFailed ) {
+            errorMessage = errorMessage + "## Error found out while ThreadReference.Status command performing!\n";
+        }
+        if ( suspendStatusFailed ) {
+            errorMessage = errorMessage + "## Unexpected suspendStatus found out!\n";
+        }
+
+        logWriter.println("\n==> Send VirtualMachine.Resume command..."); 
+        packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.ResumeCommand);
+        reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        errorCode = reply.getErrorCode();
+        if ( errorCode !=  JDWPConstants.Error.NONE ) {
+            setStaticIntField(debuggeeSignature, ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+            logWriter.println("## FAILURE: VirtualMachine.Resume command returns error = " + errorCode 
+                    + "(" + JDWPConstants.Error.getName(errorCode) + ")");
+            printErrorAndFail("\nVirtualMachine.Resume command FAILED!");
+        } else {
+            logWriter.println("==> VirtualMachine.Resume command - OK.");
+        }
+        
+        if ( ! errorMessage.equals("") ) {
+            setStaticIntField(debuggeeSignature, ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+            printErrorAndFail("\ntestResume001 FAILED:\n" + errorMessage);
+        }
+
+        logWriter.println
+        ("\n==> Check that all tested threads are resumed after VirtualMachine.Resume command...");
+
+        for (int i = 0; i < testedThreadsNumber; i++) {
+            logWriter.println("\n==> Check for Thread: threadID = " + testedThreadsIDs[i] 
+                + "; threadName = " + testedThreadsNames[i]);
+
+            logWriter.println("==> Send ThreadReference.Status command..."); 
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
+            packet.setNextValueAsReferenceTypeID(testedThreadsIDs[i]);
+            reply = debuggeeWrapper.vmMirror.performCommand(packet);
+            if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.Status command") ) {
+                statusCommandFailed = true;
+                continue;
+            }
+
+            int threadStatus = reply.getNextValueAsInt();
+            int suspendStatus = reply.getNextValueAsInt();
+
+            logWriter.println("==> threadStatus = " + threadStatus + "("
+                    + JDWPConstants.ThreadStatus.getName(threadStatus) + ")");
+            logWriter.println("==> suspendStatus = " + suspendStatus + "("
+                    + JDWPConstants.SuspendStatus.getName(suspendStatus) + ")");
+            if (suspendStatus
+                    == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
+                logWriter.println
+                    ("## FAILURE: Thread still is suspended after VirtualMachine.Resume commands!");
+                suspendStatusFailed = true;
+            }
+        }
+            
+        if ( statusCommandFailed ) {
+            errorMessage = errorMessage + "## Error found out while ThreadReference.Status command performing!\n";
+        }
+        if ( suspendStatusFailed ) {
+            errorMessage = errorMessage + "## Unexpected suspendStatus found out!\n";
+        }
+        
+        setStaticIntField(debuggeeSignature, ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+        if ( ! errorMessage.equals("") ) {
+            printErrorAndFail("\ntestResume001 FAILED:\n" + errorMessage);
+        }
+
+        logWriter.println("\n==> testResume001 - OK!");
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(ResumeTest.class);
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/ResumeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SetDefaultStratumTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SetDefaultStratumTest.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SetDefaultStratumTest.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SetDefaultStratumTest.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+ * @author Anatoly F. Bondarenko
+ * @version $Revision: 1.5 $
+ */
+
+/**
+ * Created on 24.03.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
+
+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.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+
+/**
+ * JDWP Unit test for VirtualMachine.SetDefaultStratum command.
+ */
+public class SetDefaultStratumTest extends JDWPSyncTestCase {
+
+    static final int testStatusPassed = 0;
+    static final int testStatusFailed = -1;
+    static final String thisCommandName = "VirtualMachine::SetDefaultStratum command";
+    static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld;";
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
+    }
+
+    /**
+     * This testcase exercises VirtualMachine.SetDefaultStratum command.
+     * <BR>At first the test starts HelloWorld debuggee.
+     * <BR>Then the test checks that VirtualMachine.SetDefaultStratum command runs
+     * without any error or returns NOT_IMPLEMENTED error.
+     * Any other error is considered as test' failure.
+     */
+    public void testSetDefaultStratum001() {
+        String thisTestName = "testSetDefaultStratum001";
+        
+        //check capability, relevant for this test
+        logWriter.println("=> Check capability: canSetDefaultStratum");
+        debuggeeWrapper.vmMirror.capabilities();
+        boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canSetDefaultStratum;
+        if (!isCapability) {
+            logWriter.println("##WARNING: this VM dosn't possess capability: canSetDefaultStratum");
+            return;
+        }
+        
+        logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        logWriter.println("=> CHECK1: send " + thisCommandName + " and check reply for ERROR...");
+        String stratumID = "C++";
+        CommandPacket checkedCommand = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.SetDefaultStratumCommand);
+        checkedCommand.setNextValueAsString(stratumID);
+        
+        ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
+        checkedCommand = null;
+
+        short errorCode = checkedReply.getErrorCode();
+        if ( errorCode != JDWPConstants.Error.NONE ) {
+            if ( errorCode != JDWPConstants.Error.NOT_IMPLEMENTED ) {
+                printErrorAndFail(thisCommandName 
+                    + " returns unexpected ERROR = " + errorCode 
+                    + "(" + JDWPConstants.Error.getName(errorCode) + ")");
+            } else { 
+                logWriter.println("=> CHECK PASSED: Expected error (NOT_IMPLEMENTED) is returned");
+            }
+        } else {
+            logWriter.println
+            ("=> CHECK PASSED: No any error is received");
+        }
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(SetDefaultStratumTest.class);
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SetDefaultStratumTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SuspendTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SuspendTest.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SuspendTest.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SuspendTest.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.4 $
+ */
+
+/**
+ * Created on 09.02.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
+
+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.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+
+/**
+ * JDWP Unit test for VirtualMachine.Suspend command.
+ */
+public class SuspendTest extends JDWPSyncTestCase {
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
+    }
+
+    /**
+     * This testcase exercises VirtualMachine.Suspend command.
+     * <BR>At first the test starts HelloWorld debuggee.
+     * <BR> Then the test performs VirtualMachine.Suspend commands 
+     * and checks with help of ThreadReference.Status command that all threads in debuggee 
+     * have suspend status = SUSPEND_STATUS_SUSPENDED, i.e. all
+     * debuggee threads are suspended.
+     */
+    public void testSuspend001() {
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.SuspendCommand);
+        
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "VirtualMachine::Suspend command");
+
+        reply = debuggeeWrapper.vmMirror.getAllThreadID(); 
+        
+        long threadID;
+        int threadStatus, suspendStatus;
+        String threadName;
+        ReplyPacket replyName;
+
+        int threads = reply.getNextValueAsInt();
+        logWriter.println("Number of threads = " + threads);
+        assertTrue("Invalid number of threads: " + threads, threads > 0);
+
+        for (int i = 0; i < threads; i++) {
+
+            threadID = reply.getNextValueAsThreadID() ;
+            threadName = debuggeeWrapper.vmMirror.getThreadName(threadID); 
+
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
+            packet.setNextValueAsReferenceTypeID(threadID);
+            
+            replyName = debuggeeWrapper.vmMirror.performCommand(packet);
+            checkReplyPacket(reply, "ThreadReference::Status command");
+
+            threadStatus = replyName.getNextValueAsInt();
+            suspendStatus = replyName.getNextValueAsInt();
+
+            logWriter.println("\t" + threadID + " "
+                    + "\"" + threadName + "\" "
+                    + JDWPConstants.ThreadStatus.getName(threadStatus) + " "
+                    + JDWPConstants.SuspendStatus.getName(suspendStatus));
+            if (suspendStatus
+                    != JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
+                printErrorAndFail("thread ID=" + threadID + "; name=\""
+                        + threadName + "\"" + " is not in suspended state");
+            }
+        }
+
+        resumeDebuggee();
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(SuspendTest.class);
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/SuspendTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/TopLevelThreadGroupsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/TopLevelThreadGroupsTest.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/TopLevelThreadGroupsTest.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/TopLevelThreadGroupsTest.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.5 $
+ */
+
+/**
+ * Created on 09.02.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
+
+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.ReplyPacket;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+
+/**
+ * JDWP Unit test for VirtualMachine.TopLevelThreadGroups command.
+ */
+public class TopLevelThreadGroupsTest extends JDWPSyncTestCase {
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
+    }
+
+    /**
+     * This testcase exercises VirtualMachine.TopLevelThreadGroups command.
+     * <BR>At first the test starts HelloWorld debuggee.
+     * <BR> Then the test performs VirtualMachine.TopLevelThreadGroups command 
+     * and checks that:
+     * <BR>&nbsp;&nbsp; - number of returned thread groups is equal to 1;
+     * <BR>&nbsp;&nbsp; - there are no extra data in the reply packet;
+     * <BR>Also the test prints information about returned thread groups.
+     */
+    public void testTopLevelThreadGroups001() {
+        logWriter.println("\n==> testTopLevelThreadGroups001: START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        logWriter.println("==> Send VirtualMachine::TopLevelThreadGroups command...");
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.TopLevelThreadGroupsCommand);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "VirtualMachine::TopLevelThreadGroups command");
+
+        int groups = reply.getNextValueAsInt();
+        logWriter.println("==> Returned number of groups = " + groups);
+        assertEquals(1, groups);
+
+        for (int i = 0; i < groups; i++) {
+
+            long threadGroupID = reply.getNextValueAsThreadGroupID() ;
+            logWriter.println("\n==> Print info about ThreadGroup[" + i + "]... ");
+            printThreadGroup(threadGroupID);
+
+        }
+        assertAllDataRead(reply);
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+    }
+
+    private void printThreadGroup(long rootID) {
+        logWriter.println("==> ThreadGroupID = " + rootID);
+        
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.ThreadGroupReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadGroupReferenceCommandSet.NameCommand);
+        packet.setNextValueAsThreadGroupID(rootID);
+        ReplyPacket replyParent = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(replyParent, "ThreadGroupReference::Name command");
+
+        String threadGroupIDName = replyParent.getNextValueAsString();
+        logWriter.println("==> threadGroupIDName = |" + threadGroupIDName +"|");
+
+        logWriter.println("==> Send ThreadGroupReference::Children command...");
+        packet = new CommandPacket(
+                JDWPCommands.ThreadGroupReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadGroupReferenceCommandSet.ChildrenCommand);
+        packet.setNextValueAsThreadGroupID(rootID);
+        ReplyPacket replyChilds = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(replyChilds, "ThreadGroupReference::Children command");
+        
+        int childThreads = replyChilds.getNextValueAsInt();
+        logWriter.println("==> Returned child threads: " + childThreads);
+
+        for (int j = 0; j < childThreads; j++) {
+            long id = replyChilds.getNextValueAsThreadID();
+            logWriter.println("\n==> childThreadID[" + j + "] = " + id);
+
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.NameCommand);
+            packet.setNextValueAsThreadID(id);
+            replyParent = debuggeeWrapper.vmMirror.performCommand(packet);
+            checkReplyPacket(replyParent, "ThreadReference::Name command");
+            
+            String name = replyParent.getNextValueAsString();
+            logWriter.println("==> childThreadName[" + j + "] = " + name);
+        }
+
+        int childGroups = replyChilds.getNextValueAsInt();
+        logWriter.println("\n==> Returned child groups: " + childGroups);
+
+        for (int j = 0; j < childGroups; j++) {
+            long id = replyChilds.getNextValueAsThreadGroupID();
+            logWriter.println("\n==> childGroupID[" + j + "] = " + id);
+
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadGroupReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadGroupReferenceCommandSet.NameCommand);
+            packet.setNextValueAsThreadGroupID(id);
+            replyParent = debuggeeWrapper.vmMirror.performCommand(packet);
+            checkReplyPacket(replyParent, "ThreadGroupReference::Name command");
+            
+            String name = replyParent.getNextValueAsString();
+            logWriter.println("==> childGroupName[" + j + "] = " + name);
+            
+            logWriter.println("\n==> Print info about child ThreadGroup \"main\"... ");
+            if ("main".equals(name)) {
+                printThreadGroup(id);
+            }
+        }
+    }
+    
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(TopLevelThreadGroupsTest.class);
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/TopLevelThreadGroupsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/VersionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/VersionTest.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/VersionTest.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/VersionTest.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.4 $
+ */
+
+/**
+ * Created on 29.01.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
+
+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.ReplyPacket;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+
+/**
+ * JDWP Unit test for VirtualMachine.Version command.
+ */
+public class VersionTest extends JDWPSyncTestCase {
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
+    }
+
+    /**
+     * This testcase exercises VirtualMachine.Version command.
+     * <BR>At first the test starts HelloWorld debuggee.
+     * <BR> Then the test performs VirtualMachine.Version command 
+     * and checks that:
+     * <BR>&nbsp;&nbsp; - length of returned description is greater than 0;
+     * <BR>&nbsp;&nbsp; - length of returned vmVersion is greater than 0;
+     * <BR>&nbsp;&nbsp; - length of returned vmName is greater than 0;
+     */
+    public void testVersion001() {
+
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+        
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.VersionCommand);
+        
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet); 
+
+        String description = reply.getNextValueAsString();
+        int    jdwpMajor   = reply.getNextValueAsInt();
+        int    jdwpMinor   = reply.getNextValueAsInt();
+        String vmVersion   = reply.getNextValueAsString();
+        String vmName      = reply.getNextValueAsString();
+
+        logWriter.println("description\t= " + description);
+        logWriter.println("jdwpMajor\t= " + jdwpMajor);
+        logWriter.println("jdwpMinor\t= " + jdwpMinor);
+        logWriter.println("vmVersion\t= " + vmVersion);
+        logWriter.println("vmName\t\t= " + vmName);
+
+        if (!(description.length() > 0)) {
+            printErrorAndFail("description.length = 0");
+        }
+
+        if (!(vmVersion.length() > 0)) {
+            printErrorAndFail("vmVersion.length = 0");
+        }
+
+        if (!(vmName.length() > 0)) {
+            printErrorAndFail("vmName.length = 0");
+        }
+
+        logWriter.println("CHECK PASSED");
+
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(VersionTest.class);
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/VersionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPManualDebuggeeWrapper.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPManualDebuggeeWrapper.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPManualDebuggeeWrapper.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPManualDebuggeeWrapper.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+ * @author Ivan G. Popov
+ * @version $Revision: 1.6 $
+ */
+
+/**
+ * Created on 29.01.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.share;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import org.apache.harmony.jpda.tests.framework.LogWriter;
+import org.apache.harmony.jpda.tests.framework.TestErrorException;
+import org.apache.harmony.jpda.tests.share.JPDATestOptions;
+
+/**
+ * This class provides DebuggeeWrapper implementation based on JUnit framework.
+ * Debuggee is always launched on local machine and attaches to debugger.
+ */
+public class JDWPManualDebuggeeWrapper extends JDWPUnitDebuggeeWrapper {
+
+    private BufferedReader reader = null;
+
+    /**
+     * A constructor that creates new instance with given data.
+     * 
+     * @param settings
+     *            test run options
+     * @param logWriter
+     *            where to print log messages
+     */
+    public JDWPManualDebuggeeWrapper(JPDATestOptions settings,
+            LogWriter logWriter) {
+        super(settings, logWriter);
+        reader = new BufferedReader(new InputStreamReader(System.in));
+    }
+
+    /**
+     * Get response from user and check if it is as expected.
+     */
+    private void checkUserResponse(String expected) throws IOException {
+        String response = reader.readLine();
+        if (!expected.equals(response)) {
+            throw new TestErrorException("Unexpected user response: "
+                    + response + " (expected: " + expected + ")");
+        }
+    }
+
+    /**
+     * Asks user to launch process with given command line and waits for
+     * confirmation.
+     * 
+     * @param cmdLine
+     *            command line
+     * @return null instead of associated Process object
+     * @throws IOException
+     *             if user does not confirm process launching
+     */
+    protected Process launchProcess(String cmdLine) throws IOException {
+        getLogWriter().println(
+                "\n>>> Start debuggee VM with this command line:\n" + cmdLine);
+        getLogWriter().println(
+                "\n>>> Confirm that debuggee VM has started [yes/no]:");
+        checkUserResponse("yes");
+        return null;
+    }
+
+    /**
+     * Waits for user to confirm that launched process has exited.
+     * 
+     * @param process
+     *            should be null instead of associated Process object
+     * @throws IOException
+     *             if user does not confirm process exit
+     */
+    protected void WaitForProcessExit(Process process) throws IOException {
+        getLogWriter().println(
+                "\n>>> Confirm that debuggee VM has exited [yes/no]:");
+        checkUserResponse("yes");
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPManualDebuggeeWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPRawTestCase.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPRawTestCase.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPRawTestCase.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPRawTestCase.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.5 $
+ */
+
+/**
+ * Created on 01.02.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.share;
+
+import org.apache.harmony.jpda.tests.framework.TestErrorException;
+import org.apache.harmony.jpda.tests.share.JPDALogWriter;
+import org.apache.harmony.jpda.tests.share.JPDATestOptions;
+
+import junit.framework.TestCase;
+
+/**
+ * Basic class for all JDWP unit tests based on <code>JUnit</code> framework.
+ * <p>
+ * This class extends JUnit interface <code>TestCase</code> and implements
+ * <code>setUp()</code> and <code>tearDown()</code> being common for all
+ * JDWP tests.
+ * <p>
+ * It also introduces <code>internalSetUp()</code> and
+ * <code>internalTearDown()</code> that can be implemented to supply safe
+ * start up and shut down of debuggee.
+ */
+public abstract class JDWPRawTestCase extends TestCase {
+
+    /** Where to print log messages. */
+    protected JPDALogWriter logWriter;
+
+    /** Test run options. */
+    protected JPDATestOptions settings;
+
+    /**
+     * This method should be overridden in derived classes to return full name
+     * for debuggee class.
+     * 
+     * @return full debuggee class name
+     */
+    protected abstract String getDebuggeeClassName();
+
+    /**
+     * This method will be invoked before starting each test.
+     * 
+     * @throws Exception
+     *             if any error occurs
+     */
+    protected void internalSetUp() throws Exception {
+    }
+
+    /**
+     * This method will be invoked after each test completed or any error
+     * occurred.
+     */
+    protected void internalTearDown() {
+    }
+
+    /**
+     * Overrides inherited JUnit method to provide initialization and invocation
+     * of internalSetUp() and internalTearDown() methods.
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        settings = new JPDATestOptions();
+        settings.setDebuggeeClassName(getDebuggeeClassName());
+
+        logWriter = new JPDALogWriter(System.out, null, settings.isVerbose());
+
+        logWriter.println("\n=====================================>>>");
+        logWriter.println("Run: " + getClass().getName() + "." + getName());
+        logWriter.println("----------------------------------------");
+
+        try {
+            internalSetUp();
+            logWriter.println("----------------------------------------");
+        } catch (Throwable e) {
+            logWriter.printError(e);
+            logWriter.println("----------------------------------------");
+            internalTearDown();
+            throw new TestErrorException(e);
+        }
+    }
+
+    /**
+     * Overrides inherited JUnit method to provide cleanup and invocation of
+     * internalTearDown() method.
+     */
+    protected void tearDown() throws Exception {
+        logWriter.println("----------------------------------------");
+        internalTearDown();
+        logWriter.println("<<<=====================================\n");
+
+        super.tearDown();
+    }
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPRawTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPSyncTestCase.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPSyncTestCase.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPSyncTestCase.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPSyncTestCase.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.5 $
+ */
+
+/**
+ * Created on 29.01.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.share;
+
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+/**
+ * Base class for unit tests which use one debuggee VM with synchronization
+ * channel.
+ */
+public abstract class JDWPSyncTestCase extends JDWPTestCase {
+
+    protected JPDADebuggeeSynchronizer synchronizer;
+
+    protected String finalSyncMessage;
+
+    /**
+     * This method is invoked right before starting debuggee VM.
+     */
+    protected void beforeDebuggeeStart(JDWPUnitDebuggeeWrapper debuggeeWrapper) {
+        synchronizer = new JPDADebuggeeSynchronizer(logWriter, settings);
+        int port = synchronizer.bindServer();
+        debuggeeWrapper.savedVMOptions = "-Djpda.settings.syncPort=" + port;
+        super.beforeDebuggeeStart(debuggeeWrapper);
+    }
+
+    /**
+     * Overrides inherited method to resume debuggee VM and then to establish
+     * sync connection.
+     */
+    protected void internalSetUp() throws Exception {
+        super.internalSetUp();
+
+        debuggeeWrapper.resume();
+        logWriter.println("Resumed debuggee VM");
+
+        synchronizer.startServer();
+        logWriter.println("Established sync connection");
+    }
+
+    /**
+     * Overrides inherited method to close sync connection upon exit.
+     */
+    protected void internalTearDown() {
+        if (synchronizer != null) {
+            if (null != finalSyncMessage) {
+                synchronizer.sendMessage(finalSyncMessage);
+            }
+            synchronizer.stop();
+            logWriter.println("Completed sync connection");
+        }
+        super.internalTearDown();
+    }
+
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPSyncTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPTestCase.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPTestCase.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPTestCase.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPTestCase.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,813 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.7 $
+ */
+
+/**
+ * Created on 29.01.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.share;
+
+import org.apache.harmony.jpda.tests.framework.TestErrorException;
+import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.EventPacket;
+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.Packet;
+import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
+
+/**
+ * Basic class for unit tests which use only one debuggee VM.
+ */
+public abstract class JDWPTestCase extends JDWPRawTestCase {
+
+    /**
+     * DebuggeeWrapper instance for launched debuggee VM.
+     */
+    protected JDWPUnitDebuggeeWrapper debuggeeWrapper;
+
+    /**
+     * EventPacket instance with received VM_START event.
+     */
+    protected EventPacket vmStartEvent;
+
+    /**
+     * Overrides inherited method to launch one debuggee VM, establish JDWP
+     * connection, and wait for VM_START event.
+     */
+    protected void internalSetUp() throws Exception {
+        super.internalSetUp();
+
+        if (settings.getDebuggeeLaunchKind().equals("manual")) {
+            debuggeeWrapper = new JDWPManualDebuggeeWrapper(settings, logWriter);
+        } else {
+            debuggeeWrapper = new JDWPUnitDebuggeeWrapper(settings, logWriter);
+        }
+
+        beforeDebuggeeStart(debuggeeWrapper);
+        logWriter.println("TEST NAME: " + getName());
+        debuggeeWrapper.start();
+
+        logWriter
+                .println("Launched debuggee VM process and established connection");
+        vmStartEvent = debuggeeWrapper.vmMirror
+                .receiveCertainEvent(JDWPConstants.EventKind.VM_INIT);
+        logWriter.println("Received VM_START event");
+
+        debuggeeWrapper.vmMirror.adjustTypeLength();
+        logWriter.println("Adjusted VM-dependent type lengths");
+    }
+
+    /**
+     * Overrides inherited method to stop started debuggee VM and close all
+     * connections.
+     */
+    protected void internalTearDown() {
+        if (debuggeeWrapper != null) {
+            debuggeeWrapper.stop();
+            logWriter
+                    .println("Finished debuggee VM process and closed connection");
+        }
+        super.internalTearDown();
+    }
+
+    /**
+     * This method is invoked right before starting debuggee VM.
+     */
+    protected void beforeDebuggeeStart(JDWPUnitDebuggeeWrapper debuggeeWrapper) {
+
+    }
+
+    /**
+     * Opens JDWP connection with debuggee (doesn't run debuggee and doesn't
+     * establish synchronize connection).
+     */
+    public void openConnection() {
+        debuggeeWrapper.openConnection();
+        debuggeeWrapper.vmMirror.adjustTypeLength();
+        logWriter.println("Adjusted VM-dependent type lengths");
+        logWriter.println("Opened connection");
+    }
+
+    /**
+     * Closes JDWP connection with debuggee (doesn't terminate debuggee and
+     * doesn't stop synchronize connection).
+     */
+    public void closeConnection() {
+        if (debuggeeWrapper != null) {
+            debuggeeWrapper.disposeConnection();
+            try {
+                debuggeeWrapper.vmMirror.closeConnection();
+            } catch (Exception e) {
+                throw new TestErrorException(e);
+            }
+            logWriter.println("Closed connection");
+        }
+    }
+
+    /**
+     * Helper that returns reference type signature of input object ID.
+     * 
+     * @param objectID -
+     *            debuggee object ID
+     * @return object signature of reference type
+     */
+    protected String getObjectSignature(long objectID) {
+        long classID = getObjectReferenceType(objectID);
+        return getClassSignature(classID);
+    }
+
+    /**
+     * Helper that returns reference type ID for input object ID.
+     * 
+     * @param objectID -
+     *            debuggee object ID
+     * @return reference type ID
+     */
+    protected long getObjectReferenceType(long objectID) {
+        CommandPacket command = new CommandPacket(
+                JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
+                JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand);
+        command.setNextValueAsReferenceTypeID(objectID);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(command);
+        checkReplyPacket(reply, "ObjectReference::ReferenceType command");
+        // byte refTypeTag =
+        reply.getNextValueAsByte();
+        long objectRefTypeID = reply.getNextValueAsReferenceTypeID();
+        return objectRefTypeID;
+    }
+
+    /**
+     * Helper for getting method ID of corresponding class and method name.
+     * 
+     * @param classID -
+     *            class ID
+     * @param methodName -
+     *            method name
+     * @return method ID
+     */
+    protected long getMethodID(long classID, String methodName) {
+        CommandPacket command = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.MethodsCommand);
+        command.setNextValueAsClassID(classID);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(command);
+        checkReplyPacket(reply, "ReferenceType::Methods command");
+        int methods = reply.getNextValueAsInt();
+        for (int i = 0; i < methods; i++) {
+            long methodID = reply.getNextValueAsMethodID();
+            String name = reply.getNextValueAsString(); // method name
+            reply.getNextValueAsString(); // method signature
+            reply.getNextValueAsInt(); // method modifiers
+            if (name.equals(methodName)) {
+                return methodID;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * Issues LineTable command.
+     * 
+     * @param classID -
+     *            class ID
+     * @param methodID -
+     *            method ID
+     * @return reply packet
+     */
+    protected ReplyPacket getLineTable(long classID, long methodID) {
+        CommandPacket lineTableCommand = new CommandPacket(
+                JDWPCommands.MethodCommandSet.CommandSetID,
+                JDWPCommands.MethodCommandSet.LineTableCommand);
+        lineTableCommand.setNextValueAsReferenceTypeID(classID);
+        lineTableCommand.setNextValueAsMethodID(methodID);
+        ReplyPacket lineTableReply = debuggeeWrapper.vmMirror
+                .performCommand(lineTableCommand);
+        checkReplyPacket(lineTableReply, "Method::LineTable command");
+        return lineTableReply;
+    }
+
+    /**
+     * Helper for getting method name of corresponding class and method ID.
+     * 
+     * @param classID class id
+     * @param methodID method id
+     * @return String
+     */
+    protected String getMethodName(long classID, long methodID) {
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.MethodsCommand);
+        packet.setNextValueAsClassID(classID);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "ReferenceType::Methods command");
+        int methods = reply.getNextValueAsInt();
+        for (int i = 0; i < methods; i++) {
+            long mid = reply.getNextValueAsMethodID();
+            String name = reply.getNextValueAsString();
+            reply.getNextValueAsString();
+            reply.getNextValueAsInt();
+            if (mid == methodID) {
+                return name;
+            }
+        }
+        return "unknown";
+    }
+
+    /**
+     * Returns jni signature for selected classID
+     * 
+     * @param classID
+     * @return jni signature for selected classID
+     */
+    protected String getClassSignature(long classID) {
+        CommandPacket command = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.SignatureCommand);
+        command.setNextValueAsReferenceTypeID(classID);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(command);
+        checkReplyPacket(reply, "ReferenceType::Signature command");
+        String signature = reply.getNextValueAsString();
+        return signature;
+    }
+
+    /**
+     * Returns classID for the selected jni signature
+     * 
+     * @param signature
+     * @return classID for the selected jni signature
+     */
+    protected long getClassIDBySignature(String signature) {
+        logWriter.println("=> Getting reference type ID for class: "
+                + signature);
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
+        packet.setNextValueAsString(signature);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "VirtualMachine::ClassesBySignature command");
+        int classes = reply.getNextValueAsInt();
+        logWriter.println("=> Returned number of classes: " + classes);
+        long classID = 0;
+        for (int i = 0; i < classes; i++) {
+            reply.getNextValueAsByte();
+            classID = reply.getNextValueAsReferenceTypeID();
+            reply.getNextValueAsInt();
+            // we need the only class, even if there were multiply ones
+            break;
+        }
+        assertTrue(
+                "VirtualMachine::ClassesBySignature command returned invalid classID:<"
+                        + classID + "> for signature " + signature, classID > 0);
+        return classID;
+    }
+
+    /**
+     * Returns reference type ID.
+     * 
+     * @param signature
+     * @return type ID for the selected jni signature
+     */
+    protected long getReferenceTypeID(String signature) {
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
+        packet.setNextValueAsString(signature);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "VirtualMachine::ClassesBySignature command");
+        int classes = reply.getNextValueAsInt();
+        // this class may be loaded only once
+        assertEquals("Invalid number of classes for reference type: "
+                + signature + ",", 1, classes);
+        byte refTypeTag = reply.getNextValueAsByte();
+        long classID = reply.getNextValueAsReferenceTypeID();
+        int status = reply.getNextValueAsInt();
+        logWriter.println("VirtualMachine.ClassesBySignature: classes="
+                + classes + " refTypeTag=" + refTypeTag + " typeID= " + classID
+                + " status=" + status);
+        assertAllDataRead(reply);
+        assertEquals("", JDWPConstants.TypeTag.CLASS, refTypeTag);
+        return classID;
+    }
+
+    /**
+     * Helper function for resuming debuggee.
+     */
+    protected void resumeDebuggee() {
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.ResumeCommand);
+        logWriter.println("Sending VirtualMachine::Resume command...");
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "VirtualMachine::Resume command");
+        assertAllDataRead(reply);
+    }
+
+    /**
+     * Performs string creation in debuggee.
+     * 
+     * @param value -
+     *            content for new string
+     * @return StringID of new created string
+     */
+    protected long createString(String value) {
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.CreateStringCommand);
+        packet.setNextValueAsString(value);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "VirtualMachine::CreateString command");
+        long stringID = reply.getNextValueAsStringID();
+        return stringID;
+    }
+
+    /**
+     * Returns corresponding string from string ID.
+     * 
+     * @param stringID -
+     *            string ID
+     * @return string value
+     */
+    protected String getStringValue(long stringID) {
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.StringReferenceCommandSet.CommandSetID,
+                JDWPCommands.StringReferenceCommandSet.ValueCommand);
+        packet.setNextValueAsObjectID(stringID);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "StringReference::Value command");
+        String returnedTestString = reply.getNextValueAsString();
+        return returnedTestString;
+    }
+
+    /**
+     * Multiple field verification routine.
+     * 
+     * @param refTypeID -
+     *            reference type ID
+     * @param checkedFieldNames -
+     *            list of field names to be checked
+     * @return list of field IDs
+     */
+    protected long[] checkFields(long refTypeID, String checkedFieldNames[]) {
+        return checkFields(refTypeID, checkedFieldNames, null, null);
+    }
+
+    /**
+     * Single field verification routine.
+     * 
+     * @param refTypeID -
+     *            reference type ID
+     * @param fieldName -
+     *            name of single field
+     * @return filed ID
+     */
+    protected long checkField(long refTypeID, String fieldName) {
+        return checkFields(refTypeID, new String[] { fieldName }, null, null)[0];
+    }
+
+    /**
+     * Multiple field verification routine.
+     * 
+     * @param refTypeID -
+     *            reference type ID
+     * @param checkedFieldNames -
+     *            list of field names to be checked
+     * @param expectedSignatures -
+     *            list of expected field signatures
+     * @param expectedModifiers -
+     *            list of expected field modifiers
+     * @return list of field IDs
+     */
+    protected long[] checkFields(long refTypeID, String checkedFieldNames[],
+            String expectedSignatures[], int expectedModifiers[]) {
+
+        boolean checkedFieldFound[] = new boolean[checkedFieldNames.length];
+        long checkedFieldIDs[] = new long[checkedFieldNames.length];
+
+        logWriter
+                .println("=> Send ReferenceType::Fields command and get field ID(s)");
+
+        CommandPacket fieldsCommand = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.FieldsCommand);
+        fieldsCommand.setNextValueAsReferenceTypeID(refTypeID);
+        ReplyPacket fieldsReply = debuggeeWrapper.vmMirror
+                .performCommand(fieldsCommand);
+        fieldsCommand = null;
+        checkReplyPacket(fieldsReply, "ReferenceType::Fields command");
+
+        int returnedFieldsNumber = fieldsReply.getNextValueAsInt();
+        logWriter
+                .println("=> Returned fields number = " + returnedFieldsNumber);
+
+        int checkedFieldsNumber = checkedFieldNames.length;
+        final int fieldSyntheticFlag = 0xf0000000;
+
+        int nameDuplicated = 0;
+        String fieldNameDuplicated = null; // <= collects all duplicated fields
+        int nameMissing = 0;
+        String fieldNameMissing = null; // <= collects all missed fields
+
+        for (int i = 0; i < returnedFieldsNumber; i++) {
+            long returnedFieldID = fieldsReply.getNextValueAsFieldID();
+            String returnedFieldName = fieldsReply.getNextValueAsString();
+            String returnedFieldSignature = fieldsReply.getNextValueAsString();
+            int returnedFieldModifiers = fieldsReply.getNextValueAsInt();
+            logWriter.println("");
+            logWriter.println("=> Field ID: " + returnedFieldID);
+            logWriter.println("=> Field name: " + returnedFieldName);
+            logWriter.println("=> Field signature: " + returnedFieldSignature);
+            logWriter.println("=> Field modifiers: 0x"
+                    + Integer.toHexString(returnedFieldModifiers));
+            if ((returnedFieldModifiers & fieldSyntheticFlag) == fieldSyntheticFlag) {
+                continue; // do not check synthetic fields
+            }
+            for (int k = 0; k < checkedFieldsNumber; k++) {
+                if (!checkedFieldNames[k].equals(returnedFieldName)) {
+                    continue;
+                }
+                if (checkedFieldFound[k]) {
+                    logWriter.println("");
+                    logWriter
+                            .println("## FAILURE: The field is found repeatedly in the list");
+                    logWriter.println("## Field Name: " + returnedFieldName);
+                    logWriter.println("## Field ID: " + returnedFieldID);
+                    logWriter.println("## Field Signature: "
+                            + returnedFieldSignature);
+                    logWriter.println("## Field Modifiers: 0x"
+                            + Integer.toHexString(returnedFieldModifiers));
+                    fieldNameDuplicated = (0 == nameDuplicated ? returnedFieldName
+                            : fieldNameDuplicated + "," + returnedFieldName);
+                    nameDuplicated++;
+                    break;
+                }
+                checkedFieldFound[k] = true;
+                checkedFieldIDs[k] = returnedFieldID;
+                if (null != expectedSignatures) {
+                    assertString(
+                            "Invalid field signature is returned for field:"
+                                    + returnedFieldName + ",",
+                            expectedSignatures[k], returnedFieldSignature);
+                }
+                if (null != expectedModifiers) {
+                    assertEquals(
+                            "Invalid field modifiers are returned for field:"
+                                    + returnedFieldName + ",",
+                            expectedModifiers[k], returnedFieldModifiers);
+                }
+                break;
+            }
+        }
+
+        for (int k = 0; k < checkedFieldsNumber; k++) {
+            if (!checkedFieldFound[k]) {
+                logWriter.println("");
+                logWriter
+                        .println("\n## FAILURE: Expected field is NOT found in the list of retuned fields:");
+                logWriter.println("## Field name = " + checkedFieldNames[k]);
+                fieldNameMissing = 0 == nameMissing ? checkedFieldNames[k]
+                        : fieldNameMissing + "," + checkedFieldNames[k];
+                nameMissing++;
+                // break;
+            }
+        }
+
+        // String thisTestName = this.getClass().getName();
+        // logWriter.println("==> " + thisTestName + " for " + thisCommandName +
+        // ": FAILED");
+
+        if (nameDuplicated > 1) {
+            fail("Duplicated fields are found in the retuned by FieldsCommand list: "
+                    + fieldNameDuplicated);
+        }
+        if (nameDuplicated > 0) {
+            fail("Duplicated field is found in the retuned by FieldsCommand list: "
+                    + fieldNameDuplicated);
+        }
+        if (nameMissing > 1) {
+            fail("Expected fields are NOT found in the retuned by FieldsCommand list: "
+                    + fieldNameMissing);
+        }
+        if (nameMissing > 0) {
+            fail("Expected field is NOT found in the retuned by FieldsCommand list: "
+                    + fieldNameMissing);
+        }
+
+        logWriter.println("");
+        if (1 == checkedFieldsNumber) {
+            logWriter
+                    .println("=> Expected field was found and field ID was got");
+        } else {
+            logWriter
+                    .println("=> Expected fields were found and field IDs were got");
+        }
+
+        assertAllDataRead(fieldsReply);
+        return checkedFieldIDs;
+    }
+
+    /**
+     * Helper for checking reply packet error code. Calls junit fail if packet
+     * error code does not equal to expected error code.
+     * 
+     * @param reply -
+     *            returned from debuggee packet
+     * @param message -
+     *            additional message
+     * @param errorCodeExpected -
+     *            array of expected error codes
+     */
+    protected void checkReplyPacket(ReplyPacket reply, String message,
+            int errorCodeExpected) {
+        checkReplyPacket(reply, message, new int[] { errorCodeExpected });
+    }
+
+    /**
+     * Helper for checking reply packet error code. Calls junit fail if packet
+     * error code does not equal NONE.
+     * 
+     * @param reply -
+     *            returned from debuggee packet
+     * @param message -
+     *            additional message
+     */
+    protected void checkReplyPacket(ReplyPacket reply, String message) {
+        checkReplyPacket(reply, message, JDWPConstants.Error.NONE);
+    }
+
+    /**
+     * Helper for checking reply packet error code. Calls junit fail if packet
+     * error code does not equal to expected error code.
+     * 
+     * @param reply -
+     *            returned from debuggee packet
+     * @param message -
+     *            additional message
+     * @param expected -
+     *            array of expected error codes
+     */
+    protected void checkReplyPacket(ReplyPacket reply, String message,
+            int[] expected) {
+        checkReplyPacket(reply, message, expected, true /* failSign */);
+    }
+
+    /**
+     * Helper for checking reply packet error code. If reply packet does not
+     * have error - returns true. Otherwise does not call junit fail - simply
+     * prints error message and returns false. if packet error code does not
+     * equal NONE.
+     * 
+     * @param reply -
+     *            returned from debuggee packet
+     * @param message -
+     *            additional message
+     * @return true if error is not found, or false otherwise
+     */
+    protected boolean checkReplyPacketWithoutFail(ReplyPacket reply,
+            String message) {
+        return checkReplyPacket(reply, message,
+                new int[] { JDWPConstants.Error.NONE }, false /* failSign */);
+    }
+
+    /**
+     * Helper for checking reply packet error code. If reply packet does not
+     * have unexpected error - returns true. If reply packet has got unexpected
+     * error: If failSign param = true - calls junit fail. Otherwise prints
+     * message about error and returns false.
+     * 
+     * @param reply -
+     *            returned from debuggee packet
+     * @param message -
+     *            additional message
+     * @param expected -
+     *            array of expected error codes
+     * @param failSign -
+     *            defines to call junit fail or not
+     * @return true if unexpected errors are not found, or false otherwise
+     */
+    protected boolean checkReplyPacket(ReplyPacket reply, String message,
+            int[] expected, boolean failSign) {
+        // check reply code against expected
+        int errorCode = reply.getErrorCode();
+        for (int i = 0; i < expected.length; i++) {
+            if (reply.getErrorCode() == expected[i]) {
+                return true; // OK
+            }
+        }
+
+        // replay code validation failed
+        // start error message composition
+        if (null == message) {
+            message = "";
+        } else {
+            message = message + ", ";
+        }
+
+        // format error message
+        if (expected.length == 1 && JDWPConstants.Error.NONE == expected[0]) {
+            message = message + "Error Code:<" + errorCode + "("
+                    + JDWPConstants.Error.getName(errorCode) + ")>";
+        } else {
+            message = message + "Unexpected error code:<" + errorCode + "("
+                    + JDWPConstants.Error.getName(errorCode) + ")>"
+                    + ", Expected error code"
+                    + (expected.length == 1 ? ":" : "s:");
+            for (int i = 0; i < expected.length; i++) {
+                message = message + (i > 0 ? ",<" : "<") + expected[i] + "("
+                        + JDWPConstants.Error.getName(expected[i]) + ")>";
+            }
+        }
+
+        if (failSign) {
+            printErrorAndFail(message);
+        }
+        logWriter.printError(message);
+        return false;
+    }
+
+    /**
+     * Helper for comparison numbers and printing string equivalents.
+     * 
+     * @param message -
+     *            user message
+     * @param expected -
+     *            expected value
+     * @param actual -
+     *            actual value
+     * @param strExpected -
+     *            string equivalent of expected value
+     * @param strActual -
+     *            string equivalent of actual value
+     */
+    protected void assertEquals(String message, long expected, long actual,
+            String strExpected, String strActual) {
+        if (expected == actual) {
+            return; // OK
+        }
+
+        if (null == message) {
+            message = "";
+        }
+
+        if (null == strExpected) {
+            strExpected = expected + "";
+        } else {
+            strExpected = expected + "(" + strExpected + ")";
+        }
+
+        if (null == strActual) {
+            strActual = actual + "";
+        } else {
+            strActual = actual + "(" + strActual + ")";
+        }
+
+        printErrorAndFail(message + " expected:<" + strExpected + "> but was:<"
+                + strActual + ">");
+    }
+
+    /**
+     * Asserts that two strings are equal.
+     * 
+     * @param message -
+     *            user message
+     * @param expected -
+     *            expected string
+     * @param actual -
+     *            actual string
+     */
+    protected void assertString(String message, String expected, String actual) {
+        if (null == expected) {
+            expected = "";
+        }
+        if (null == actual) {
+            actual = "";
+        }
+        if (expected.equals(actual)) {
+            return; // OK
+        }
+        printErrorAndFail(message + " expected:<" + expected + "> but was:<"
+                + actual + ">");
+    }
+
+    /**
+     * Helper for checking reply packet data has been read.
+     * 
+     * @param reply -
+     *            reply packet from debuggee
+     */
+    protected void assertAllDataRead(Packet reply) {
+        if (reply.isAllDataRead()) {
+            return; // OK
+        }
+        printErrorAndFail("Not all data has been read");
+    }
+
+    /**
+     * Prints error message in log writer and in junit fail.
+     * 
+     * @param message -
+     *            error message
+     */
+    protected void printErrorAndFail(String message) {
+        logWriter.printError(message);
+        fail(message);
+    }
+
+    /**
+     * Helper for setting static int field in class with new value.
+     * 
+     * @param classSignature -
+     *            String defining signature of class
+     * @param fieldName -
+     *            String defining field name in specified class
+     * @param newValue -
+     *            int value to set for specified field
+     * @return true, if setting is successfully, or false otherwise
+     */
+    protected boolean setStaticIntField(String classSignature,
+            String fieldName, int newValue) {
+
+        long classID = debuggeeWrapper.vmMirror.getClassID(classSignature);
+        if (classID == -1) {
+            logWriter
+                    .println("## setStaticIntField(): Can NOT get classID for class signature = '"
+                            + classSignature + "'");
+            return false;
+        }
+
+        long fieldID = debuggeeWrapper.vmMirror.getFieldID(classID, fieldName);
+        if (fieldID == -1) {
+            logWriter
+                    .println("## setStaticIntField(): Can NOT get fieldID for field = '"
+                            + fieldName + "'");
+            return false;
+        }
+
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.ClassTypeCommandSet.CommandSetID,
+                JDWPCommands.ClassTypeCommandSet.SetValuesCommand);
+        packet.setNextValueAsReferenceTypeID(classID);
+        packet.setNextValueAsInt(1);
+        packet.setNextValueAsFieldID(fieldID);
+        packet.setNextValueAsInt(newValue);
+
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        int errorCode = reply.getErrorCode();
+        if (errorCode != JDWPConstants.Error.NONE) {
+            logWriter
+                    .println("## setStaticIntField(): Can NOT set value for field = '"
+                            + fieldName
+                            + "' in class = '"
+                            + classSignature
+                            + "'; ClassType.SetValues command reurns error = "
+                            + errorCode);
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Removes breakpoint of the given event kind corresponding to the given
+     * request id.
+     * 
+     * @param eventKind
+     *            request event kind
+     * @param requestID
+     *            request id
+     * @param verbose
+     *            print or don't extra log info
+     */
+    protected void clearEvent(byte eventKind, int requestID, boolean verbose) {
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.EventRequestCommandSet.CommandSetID,
+                JDWPCommands.EventRequestCommandSet.ClearCommand);
+        packet.setNextValueAsByte(eventKind);
+        packet.setNextValueAsInt(requestID);
+        if (verbose) {
+            logWriter.println("Clearing event: "
+                    + JDWPConstants.EventKind.getName(eventKind) + ", id: "
+                    + requestID);
+        }
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "EventRequest::Clear command");
+        assertAllDataRead(reply);
+    }
+
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native