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 [34/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/ThreadReference/Status005Debuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status005Debuggee.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status005Debuggee.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status005Debuggee.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,109 @@
+/*
+ * 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.3 $
+ */
+
+/**
+ * Created on 31.03.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+// import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+/**
+ * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.Status005Test</code>.
+ */
+public class Status005Debuggee extends SyncDebuggee {
+
+    static Status005Debuggee status005DebuggeeThis;
+    static volatile boolean status005DebuggeeThreadStarted = false;
+
+    static Object lockObject = new Object();
+
+    static Object waitTimeObject = new Object();
+    static void waitMlsecsTime(long mlsecsTime) { 
+        synchronized(waitTimeObject) {
+            try {
+                waitTimeObject.wait(mlsecsTime);
+            } catch (Throwable throwable) {
+                 // ignore
+            }
+        }
+    }
+    
+    public void run() {
+        logWriter.println("--> Debuggee: Status005Debuggee: START");
+        status005DebuggeeThis = this;
+        
+        String status005DebuggeeThreadName = "Status005DebuggeeThread";
+        Status005Debuggee_Thread status005DebuggeeThread
+            = new Status005Debuggee_Thread(status005DebuggeeThreadName); 
+
+        synchronized(lockObject) {
+            logWriter.println
+            ("--> Debuggee: Status005Debuggee: has entered in synchronized(lockObject) block");
+            status005DebuggeeThread.start();
+
+            while ( ! status005DebuggeeThreadStarted ) {
+                waitMlsecsTime(1000);
+            }
+            logWriter.println("--> Debuggee: Status005Debuggee: will sleep for 10 seconds");
+            waitMlsecsTime(10000); // to make sure that status005DebuggeeThread is sleeping
+
+            synchronizer.sendMessage(status005DebuggeeThreadName);
+            synchronizer.receiveMessage(); // signal to finish
+        }
+        logWriter.println
+        ("--> Debuggee: Status005Debuggee: has exited from synchronized(lockObject) block");
+        
+        while ( status005DebuggeeThread.isAlive() ) {
+            waitMlsecsTime(100);
+        }
+
+       logWriter.println("--> Debuggee: Status005Debuggee: FINISH");
+        System.exit(0);
+    }
+
+    public static void main(String [] args) {
+        runDebuggee(Status005Debuggee.class);
+    }
+}
+
+class Status005Debuggee_Thread extends Thread {
+
+    public Status005Debuggee_Thread(String name) {
+        super(name);
+    }
+
+    public void run() {
+        Status005Debuggee parent = Status005Debuggee.status005DebuggeeThis;
+        parent.logWriter.println("--> Thread: " + getName() +  ": started...");
+        parent.logWriter.println
+        ("--> Thread: " + getName() +  ": will try to enter in synchronized(lockObject) block");
+        Status005Debuggee.status005DebuggeeThreadStarted = true;
+        synchronized(Status005Debuggee.lockObject) {
+            parent.logWriter.println
+            ("--> Thread: " + getName() +  ": has entered in synchronized(lockObject) block");
+        }
+        parent.logWriter.println("--> Thread: " + getName() +  ": is finishibg...");
+    }
+}
+

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status005Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status005Test.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status005Test.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status005Test.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,126 @@
+/*
+ * 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.6 $
+ */
+
+/**
+ * Created on 31.03.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+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 ThreadReference.Status command for the Thread waiting to enter in locked Monitor.
+ */
+public class Status005Test extends JDWPSyncTestCase {
+
+    static final int testStatusPassed = 0;
+    static final int testStatusFailed = -1;
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.Status005Debuggee";
+    }
+
+    String getThreadSuspendStatusName(int suspendStatus) {
+    
+        String result = JDWPConstants.SuspendStatus.getName(suspendStatus);
+        if ( result.equals("") ) {
+            result = "NOT_SUSPENDED";
+        }
+        return result;
+    }
+    
+    /**
+     * This testcase exercises ThreadReference.Status command for the Thread waiting to enter in locked Monitor.
+     * <BR>At first the test starts Status005Debuggee which runs
+     * the tested thread and blocks it in entering in synchronized block. 
+     * <BR> Then the tests performs the ThreadReference.Status command 
+     * for tested thread. 
+     * <BR>It is expected that:
+     * <BR>&nbsp;&nbsp; - returned thread status is MONITOR status;
+     * <BR>&nbsp;&nbsp; - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
+     */
+    public void testStatus006() {
+        String thisTestName = "testStatus006";
+        logWriter.println("==> " + thisTestName + " for ThreadReference.Status command: START...");
+        logWriter.println("==> This " + thisTestName
+                + " checks command for BLOCKED Thread: which is waiting to enter in locked Monitor...");
+        //int testStatus = testStatusPassed;
+        String checkedThreadName = synchronizer.receiveMessage();
+        logWriter.println("=> checkedThreadName = " + checkedThreadName);
+
+        long checkedThreadID = debuggeeWrapper.vmMirror.getThreadID(checkedThreadName);
+        logWriter.println("=> checkedThreadID = " + checkedThreadID);
+
+        logWriter.println
+        ("=> Send ThreadReference.Status command for checked Thread and check reply...");
+        CommandPacket checkedCommand = new CommandPacket(
+                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
+        checkedCommand.setNextValueAsThreadID(checkedThreadID);
+        
+        ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
+        checkReplyPacket(checkedReply, "ThreadReference.Status command");
+        
+        int threadStatus = checkedReply.getNextValueAsInt();
+        int suspendStatus = checkedReply.getNextValueAsInt();
+
+        logWriter.println("\n=> Returned thread status = 0x" + Integer.toHexString(threadStatus)
+                + "(" + JDWPConstants.ThreadStatus.getName(threadStatus) + ")");
+        if (threadStatus != JDWPConstants.ThreadStatus.MONITOR) {
+            finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
+            printErrorAndFail("Unexpected thread status is returned:"
+                + "\n Expected thread status = 0x"
+                + Integer.toHexString(JDWPConstants.ThreadStatus.MONITOR)
+                + "(" + JDWPConstants.ThreadStatus.getName(JDWPConstants.ThreadStatus.MONITOR) + ")");
+        } else {
+            logWriter.println("=> OK - Expected thread status is returned");
+        }
+
+        logWriter.println
+            ("\n=> Returned thread suspend status = 0x" + Integer.toHexString(suspendStatus)
+            + "(" + getThreadSuspendStatusName(suspendStatus) + ")");
+        if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
+            finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
+            printErrorAndFail("Unexpected thread status is returned:"
+                + "\n Expected thread status = 0x"
+                + Integer.toHexString(0)
+                + "(" + getThreadSuspendStatusName(0) + ")");
+        } else {
+            logWriter.println("=> OK - Expected thread suspend status is returned");
+        }
+
+        logWriter.println("=> Send to Debuggee signal to funish ...");
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+
+        logWriter.println("==> " + thisTestName + " for ThreadReference.Status command: FINISH...");
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(Status005Test.class);
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status006Debuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status006Debuggee.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status006Debuggee.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status006Debuggee.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,96 @@
+/*
+ * 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.2 $
+ */
+
+/**
+ * Created on 31.03.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+/**
+ * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.Status006Test</code>.
+ */
+public class Status006Debuggee extends SyncDebuggee {
+
+    static Status006Debuggee status006DebuggeeThis;
+    static volatile boolean status006DebuggeeThreadStarted = false;
+
+    static Object waitTimeObject = new Object();
+    static void waitMlsecsTime(long mlsecsTime) { 
+        synchronized(waitTimeObject) {
+            try {
+                waitTimeObject.wait(mlsecsTime);
+            } catch (Throwable throwable) {
+                 // ignore
+            }
+        }
+    }
+    
+    public void run() {
+        logWriter.println("--> Debuggee: Status006Debuggee: START");
+        status006DebuggeeThis = this;
+        
+        String status006DebuggeeThreadName = "Status006DebuggeeThread";
+        Status006Debuggee_Thread status006DebuggeeThread
+            = new Status006Debuggee_Thread(status006DebuggeeThreadName); 
+
+        status006DebuggeeThread.start();
+
+        while ( ! status006DebuggeeThreadStarted ) {
+            waitMlsecsTime(1000);
+        }
+        logWriter.println
+        ("--> Debuggee: Status006Debuggee: is waiting for Status006DebuggeeThread to finish...");
+        while ( status006DebuggeeThread.isAlive() ) {
+            waitMlsecsTime(1000);
+        }
+        logWriter.println
+        ("--> Debuggee: Status006Debuggee: Status006DebuggeeThread has finished");
+
+        synchronizer.sendMessage("READY");
+        synchronizer.receiveMessageWithoutException("Status006Debuggee(#1)");
+
+        logWriter.println("--> Debuggee: Status006Debuggee: FINISH");
+    }
+
+    public static void main(String [] args) {
+        runDebuggee(Status006Debuggee.class);
+    }
+}
+
+class Status006Debuggee_Thread extends Thread {
+
+    public Status006Debuggee_Thread(String name) {
+        super(name);
+    }
+
+    public void run() {
+        Status006Debuggee parent = Status006Debuggee.status006DebuggeeThis;
+        parent.logWriter.println("--> Thread: " + getName() +  ": started...");
+        Status006Debuggee.status006DebuggeeThreadStarted = true;
+        parent.synchronizer.sendMessage(getName());
+        parent.synchronizer.receiveMessageWithoutException("Status006Debuggee_Thread(#1)");
+        parent.logWriter.println("--> Thread: " + getName() +  ": is finishibg...");
+    }
+}
+

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status006Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status006Test.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status006Test.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/Status006Test.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,137 @@
+/*
+ * 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 31.03.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+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 ThreadReference.Status command for the Thread which has started and finished.
+ */
+public class Status006Test extends JDWPSyncTestCase {
+
+    static final int testStatusPassed = 0;
+    static final int testStatusFailed = -1;
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.Status006Debuggee";
+    }
+
+    String getThreadSuspendStatusName(int suspendStatus) {
+        String result = JDWPConstants.SuspendStatus.getName(suspendStatus);
+        if ( result.equals("") ) {
+            result = "NOT_SUSPENDED";
+        }
+        return result;
+    }
+    
+
+    /**
+     * This testcase exercises ThreadReference.Status command for the Thread which has started and finished.
+     * <BR>At first the test starts Status006Debuggee which runs
+     * the tested thread which starts and finishes. 
+     * <BR> Then the tests performs the ThreadReference.Status command 
+     * for tested thread. 
+     * <BR>It is expected that:
+     * <BR>&nbsp;&nbsp; - returned thread status is ZOMBIE status;
+     * <BR>&nbsp;&nbsp; - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
+     */
+    public void testStatus007() {
+        String thisTestName = "testStatus007";
+        logWriter.println("==> " + thisTestName + " for ThreadReference.Status command: START...");
+        logWriter.println("==> This " + thisTestName
+                + " checks command for TERMINATED Thread: which has started and finished...");
+//        String checkedThreadName = synchronizer.receiveMessage();
+        String checkedThreadName = synchronizer.receiveMessageWithoutException
+        ("ThreadReference.Status006Test: testStatus007(#1)");
+        logWriter.println("=> checkedThreadName = " + checkedThreadName);
+        if ( checkedThreadName.startsWith("Exception:") ) {
+            logWriter.println("=> Can NOT get checkedThreadName => test con NOT be executed!");
+            return;
+        }
+
+        long checkedThreadID = debuggeeWrapper.vmMirror.getThreadID(checkedThreadName);
+        logWriter.println("=> checkedThreadID = " + checkedThreadID);
+
+        logWriter.println("=> Send to Debuggee signal to continue ...");
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+//        synchronizer.receiveMessage();
+        synchronizer.receiveMessageWithoutException
+        ("ThreadReference.Status006Test: testStatus007(#2)");
+
+        logWriter.println
+        ("=> Send ThreadReference.Status command for checked Thread and check reply...");
+        CommandPacket checkedCommand = new CommandPacket(
+                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
+        checkedCommand.setNextValueAsThreadID(checkedThreadID);
+        
+        ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
+        checkReplyPacket(checkedReply, "ThreadReference.Status command");
+        
+        int threadStatus = checkedReply.getNextValueAsInt();
+        int suspendStatus = checkedReply.getNextValueAsInt();
+
+        logWriter.println("\n=> Returned thread status = 0x" + Integer.toHexString(threadStatus)
+                + "(" + JDWPConstants.ThreadStatus.getName(threadStatus) + ")");
+        if (threadStatus != JDWPConstants.ThreadStatus.ZOMBIE) {
+            finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
+            printErrorAndFail("Unexpected thread status is returned:"
+                + "\n Expected thread status = 0x"
+                + Integer.toHexString(JDWPConstants.ThreadStatus.ZOMBIE)
+                + "(" + JDWPConstants.ThreadStatus.getName(JDWPConstants.ThreadStatus.ZOMBIE) + ")");
+        } else {
+            logWriter.println("=> OK - Expected thread status is returned");
+        }
+
+        logWriter.println
+            ("\n=> Returned thread suspend status = 0x" + Integer.toHexString(suspendStatus)
+            + "(" + getThreadSuspendStatusName(suspendStatus) + ")");
+        if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
+            finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
+            printErrorAndFail("Unexpected thread status is returned:"
+                + "\n Expected thread status = 0x"
+                + Integer.toHexString(0)
+                + "(" + getThreadSuspendStatusName(0) + ")");
+        } else {
+            logWriter.println("=> OK - Expected thread suspend status is returned");
+        }
+
+        logWriter.println("=> Send to Debuggee signal to funish ...");
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+
+        logWriter.println("==> " + thisTestName + " for ThreadReference.Status command: FINISH...");
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(Status006Test.class);
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StatusDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StatusDebuggee.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StatusDebuggee.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StatusDebuggee.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,97 @@
+/*
+ * 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.2 $
+ */
+
+/**
+ * Created on 22.02.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.framework.LogWriter;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+
+/**
+ * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.StatusTest</code>.
+ * This debuggee starts the tested thread <code>TESTED_THREAD</code>.
+ */
+public class StatusDebuggee extends SyncDebuggee {
+
+    public static final String TESTED_THREAD = "TestedThread";
+    
+    static Object waitForStart = new Object();
+    static Object waitForFinish = new Object();
+    
+    public void run() {
+        DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
+                logWriter, synchronizer); 
+        
+        synchronized(waitForStart){
+            thrd.start();
+            try {
+                waitForStart.wait();
+            } catch (InterruptedException e) {
+
+            }
+        }
+
+        synchronized(waitForFinish){
+            logWriter.println("thread is finished");
+        }
+    }
+
+    class DebuggeeThread extends Thread {
+
+        LogWriter logWriter;
+        DebuggeeSynchronizer synchronizer;
+
+        public DebuggeeThread(String name, LogWriter logWriter,
+                DebuggeeSynchronizer synchronizer) {
+            super(name);
+            this.logWriter = logWriter;
+            this.synchronizer = synchronizer;
+        }
+
+        public void run() {
+
+            synchronized(StatusDebuggee.waitForFinish){
+
+                synchronized(StatusDebuggee.waitForStart){
+
+                    StatusDebuggee.waitForStart.notifyAll();
+
+                    logWriter.println(getName() +  ": started");
+                    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+                    logWriter.println(getName() +  ": wait for SGNL_CONTINUE");
+                    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+                    logWriter.println(getName() +  ": finished");
+                }
+            }
+        }
+    }
+
+    public static void main(String [] args) {
+        runDebuggee(StatusDebuggee.class);
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StatusTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StatusTest.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StatusTest.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StatusTest.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,162 @@
+/*
+ * 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 22.02.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+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 ThreadReference.Status command.
+ */
+public class StatusTest extends JDWPSyncTestCase {
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.StatusDebuggee";
+    }
+
+    /**
+     * This testcase exercises ThreadReference.Status command for suspended Thread.
+     * <BR>At first the test starts StatusDebuggee which runs
+     * the tested thread.
+     * <BR> At first the test suspends tested thread by ThreadReference.Suspend command. 
+     * <BR> Then the tests performs the ThreadReference.Status command 
+     * for tested thread. 
+     * <BR>It is expected that:
+     * <BR>&nbsp;&nbsp; - returned thread status is RUNNING status;
+     * <BR>&nbsp;&nbsp; - returned suspend status is SUSPEND_STATUS_SUSPENDED status;
+     */
+    public void testStatus002() {
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        // getting ID of the tested thread
+        logWriter.println("get thread ID");
+        long threadID = 
+            debuggeeWrapper.vmMirror.getThreadID(StatusDebuggee.TESTED_THREAD);
+        logWriter.println("suspend thread");
+        debuggeeWrapper.vmMirror.suspendThread(threadID);
+
+        // getting the thread group ID
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
+        packet.setNextValueAsThreadID(threadID);
+        
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "ThreadReference::Status command");
+
+        int threadStatus = reply.getNextValueAsInt();
+        int suspendStatus = reply.getNextValueAsInt();
+
+        logWriter.println("\t" + threadID + " "
+                + "\"" + StatusDebuggee.TESTED_THREAD + "\" "
+                + JDWPConstants.ThreadStatus.getName(threadStatus) + " "
+                + JDWPConstants.SuspendStatus.getName(suspendStatus));
+
+        if (threadStatus != JDWPConstants.ThreadStatus.RUNNING) {
+            printErrorAndFail("Unexpected thread status: "
+                    + JDWPConstants.ThreadStatus.getName(threadStatus));
+        } else {
+            logWriter.println("Expected thread status "
+                    + JDWPConstants.ThreadStatus.getName(threadStatus));
+        }
+
+        if (suspendStatus != JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
+            printErrorAndFail("Unexpected suspend status: "
+                    + JDWPConstants.ThreadStatus.getName(suspendStatus));
+        } else {
+            logWriter.println("Expected suspend status "
+                    + JDWPConstants.SuspendStatus.getName(suspendStatus));
+        }
+
+        logWriter.println("resume thread");
+        debuggeeWrapper.vmMirror.resumeThread(threadID);
+
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+    }
+
+    /**
+     * This testcase exercises ThreadReference.Status command.
+     * <BR>At first the test starts StatusDebuggee which runs
+     * the tested thread.
+     * <BR> Then the tests performs the ThreadReference.Status command 
+     * for tested thread. 
+     * <BR>It is expected that:
+     * <BR>&nbsp;&nbsp; - returned thread status is RUNNING status;
+     * <BR>&nbsp;&nbsp; - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
+     */
+    public void testStatus001() {
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        // getting ID of the tested thread
+        logWriter.println("get thread ID");
+        long threadID = 
+            debuggeeWrapper.vmMirror.getThreadID(StatusDebuggee.TESTED_THREAD);
+
+        // getting the thread group ID
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
+        packet.setNextValueAsThreadID(threadID);
+        
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "ThreadReference::Status command");
+
+        int threadStatus = reply.getNextValueAsInt();
+        int suspendStatus = reply.getNextValueAsInt();
+
+        logWriter.println("\t" + threadID + " "
+                + "\"" + StatusDebuggee.TESTED_THREAD + "\" "
+                + JDWPConstants.ThreadStatus.getName(threadStatus) + " "
+                + JDWPConstants.SuspendStatus.getName(suspendStatus));
+
+        if (threadStatus != JDWPConstants.ThreadStatus.RUNNING) {
+            printErrorAndFail("Unexpected thread status: "
+                    + JDWPConstants.ThreadStatus.getName(threadStatus));
+        } else {
+            logWriter.println("Expected thread status "
+                    + JDWPConstants.ThreadStatus.getName(threadStatus));
+        }
+
+        if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
+            printErrorAndFail("Unexpected suspend status: "
+                    + JDWPConstants.ThreadStatus.getName(suspendStatus));
+        } else {
+            logWriter.println("Expected suspend status "
+                    + JDWPConstants.SuspendStatus.getName(suspendStatus));
+        }
+
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(StatusTest.class);
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StopDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StopDebuggee.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StopDebuggee.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StopDebuggee.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,135 @@
+/*
+ * 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.2 $
+ */
+
+/**
+ * Created on 22.02.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.framework.LogWriter;
+import org.apache.harmony.jpda.tests.framework.TestOptions;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+
+/**
+ * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.StopTest</code>.
+ * This debuggee starts the tested thread <code>TESTED_THREAD</code> which waits for 
+ * 'Stop' command with NullPointerException exception.
+ */
+public class StopDebuggee extends SyncDebuggee {
+
+    static Object waitTimeObject = new Object();
+    static void waitMlsecsTime(long mlsecsTime) { 
+        synchronized(waitTimeObject) {
+            try {
+                waitTimeObject.wait(mlsecsTime);
+            } catch (Throwable throwable) {
+                 // ignore
+            }
+        }
+    }
+
+    static Object waitTimeObjectWithException = new Object();
+    static void waitMlsecsTimeWithException(long mlsecsTime) throws Throwable { 
+        synchronized(waitTimeObject) {
+            try {
+                waitTimeObject.wait(mlsecsTime);
+            } catch (Throwable throwable) {
+                 throw throwable;
+            }
+        }
+    }
+
+    public static String testStatus = "PASSED";
+    public static final String TESTED_THREAD = "TestedThread";
+    public static final String FIELD_NAME = "exception";
+//    public static final String EXCEPTION_SIGNATURE = "Ljava/lang/NullPointerException;";
+    public static NullPointerException exception = new NullPointerException(); 
+    
+    static Object waitForStart = new Object();
+    
+    public void run() {
+        logWriter.println("StopDebuggee: started");
+        DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
+                logWriter, synchronizer); 
+        
+        synchronized(waitForStart){
+            thrd.start();
+            try {
+                waitForStart.wait();
+            } catch (InterruptedException e) {
+                logWriter.println("StopDebuggee:" + e + " is cought while waitForStart.wait()");
+            }
+        }
+
+        logWriter.println("StopDebuggee: Wait for TestedThread to finish...");
+        while ( thrd.isAlive() ) {
+            waitMlsecsTime(1000);
+        }
+        logWriter.println("StopDebuggee: TestedThread finished");
+
+        synchronizer.sendMessage(testStatus);
+        logWriter.println("StopDebuggee: finishing...");
+    }
+
+    class DebuggeeThread extends Thread {
+
+        LogWriter logWriter;
+        DebuggeeSynchronizer synchronizer;
+
+        public DebuggeeThread(String name, LogWriter logWriter,
+                DebuggeeSynchronizer synchronizer) {
+            super(name);
+            this.logWriter = logWriter;
+            this.synchronizer = synchronizer;
+        }
+
+        public void run() {
+            logWriter.println(getName() +  ": started");
+            synchronized(waitForStart){
+                waitForStart.notifyAll();
+            }
+
+            logWriter.println(getName() +  ": Wait for 'Stop' command with NullPointerException...");
+            try {
+                synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+                waitMlsecsTimeWithException(TestOptions.DEFAULT_TIMEOUT);
+                logWriter.println(getName() +  ": FAILED: TIMEOUT is run out - No any exception is caught");
+                testStatus = "FAILED";
+            } catch (Throwable thrown) {
+                logWriter.println(getName() +  ": Exception is caught: " + thrown);
+                if ( thrown.equals(exception) ) {
+                    logWriter.println(getName() +  ": PASSED: It is expected Exception");
+                } else {
+                    logWriter.println(getName() +  ": FAILED: It is unexpected Exception");
+                    testStatus = "FAILED";
+                }
+            }
+        }
+    }
+
+    public static void main(String [] args) {
+        runDebuggee(StopDebuggee.class);
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StopTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StopTest.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StopTest.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/StopTest.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 22.02.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+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.framework.jdwp.Value;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+
+/**
+ * JDWP Unit test for ThreadReference.Stop command.
+ */
+public class StopTest extends JDWPSyncTestCase {
+
+    static String SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/ThreadReference/StopDebuggee;";
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.StopDebuggee";
+    }
+
+    /**
+     * This testcase exercises ThreadReference.Stop command.
+     * <BR>At first the test starts StopDebuggee which runs
+     * the tested thread 'TESTED_THREAD'.
+     * <BR>After the tested thread starts, the test performs ThreadReference.Stop command 
+     * for the tested thread and waits for Debuggee message if the tested thread
+     * is interrupted with NullPointerException. 
+     * <BR>If so the test PASSED, otherwise FAILED. 
+     */
+    public void testStop001() {
+        logWriter.println("testStop001: STARTED...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        // getting ID of the tested thread
+        logWriter.println("testStop001: get threadID to Stop...");
+        long threadID = 
+            debuggeeWrapper.vmMirror.getThreadID(StopDebuggee.TESTED_THREAD);
+        logWriter.println("testStop001: ID of the tested thread to Stop = " + threadID);
+
+        long classID = 
+            debuggeeWrapper.vmMirror.getClassID(SIGNATURE);
+
+        long fieldID = 
+            debuggeeWrapper.vmMirror.getFieldID(classID, StopDebuggee.FIELD_NAME);
+
+        // getting throwable 
+        logWriter.println("testStop001: get throwable for Stop command...");
+        CommandPacket packet = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
+        packet.setNextValueAsReferenceTypeID(classID);
+        packet.setNextValueAsInt(1);
+        packet.setNextValueAsFieldID(fieldID);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "ReferenceType::GetValues command");
+        
+        int values = reply.getNextValueAsInt();
+        if (values != 1) {
+            logWriter.println("## testStop001: Unexpected number of values = " + values);
+            logWriter.println("## Expected number of values = 1");
+            fail("Unexpected number of values: " + values + ", expected: 1");
+        }
+        Value fieldValue = reply.getNextValueAsValue();
+        logWriter.println("testStop001: throwable = " + fieldValue);
+
+        packet = new CommandPacket(
+                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                JDWPCommands.ThreadReferenceCommandSet.StopCommand);
+        packet.setNextValueAsThreadID(threadID);
+        packet.setNextValueAsObjectID(fieldValue.getLongValue());
+        logWriter.println("testStop001: send \"Stop\" command");
+        reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        checkReplyPacket(reply, "ThreadReference::Stop command");
+
+        logWriter.println("testStop001: wait for Debuggee message about test status...");
+        String testStatus = synchronizer.receiveMessage();
+        logWriter.println("testStop001: Received from Debuggee test status = " + testStatus);
+        if ( ! testStatus.equals("PASSED") ) {
+            logWriter.println("## testStop001: FAILED");
+            fail("Bad message received from debuggee: " + testStatus);
+        } else {
+            logWriter.println("testStop001: PASSED");
+        }
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(StopTest.class);
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendCountDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendCountDebuggee.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendCountDebuggee.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendCountDebuggee.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,154 @@
+/*
+ * 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.3 $
+ */
+
+/**
+ * Created on 07.06.2006 
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+public class SuspendCountDebuggee extends SyncDebuggee {
+    public static final int THREAD_NUMBER_LIMIT = 6; 
+    public static final String THREAD_NAME_PATTERN = "SuspendCountDebuggee_Thread_"; 
+    public static final String TO_FINISH_DEBUGGEE_FIELD_NAME = "debuggeToFinish"; 
+
+    static SuspendCountDebuggee suspendCountDebuggeeThis;
+
+    static volatile boolean allThreadsToFinish = false;
+    static int debuggeToFinish = 0;
+    static int createdThreadsNumber = 0;
+    static volatile int startedThreadsNumber = 0;
+
+    static SuspendCountDebuggee_Thread[] suspendCountDebuggeeThreads = null;
+
+    static Object waitTimeObject = new Object();
+    static void waitMlsecsTime(long mlsecsTime) { 
+        synchronized(waitTimeObject) {
+            try {
+                waitTimeObject.wait(mlsecsTime);
+            } catch (Throwable throwable) {
+                 // ignore
+            }
+        }
+    }
+    
+    static void sleepMlsecsTime(long mlsecsTime) { 
+        try {
+            Thread.sleep(mlsecsTime);
+        } catch (Throwable throwable) {
+             // ignore
+        }
+    }
+    
+    public void run() {
+        
+        logWriter.println("--> SuspendCountDebuggee: START...");
+        suspendCountDebuggeeThis = this;
+
+        logWriter.println("--> SuspendCountDebuggee: Create and start tested threads...");
+        try {
+            suspendCountDebuggeeThreads = new SuspendCountDebuggee_Thread[THREAD_NUMBER_LIMIT]; 
+            for (int i=0; i < THREAD_NUMBER_LIMIT; i++) {
+                suspendCountDebuggeeThreads[i]= new SuspendCountDebuggee_Thread(i);
+                suspendCountDebuggeeThreads[i].start();
+                createdThreadsNumber++;
+            }
+        } catch ( Throwable thrown) {
+            logWriter.println
+            ("--> SuspendCountDebuggee: Exception while creating threads: " + thrown);
+        }
+        logWriter.println
+        ("--> SuspendCountDebuggee: Created threads number = " + createdThreadsNumber);
+        
+        while ( startedThreadsNumber != createdThreadsNumber ) {
+            waitMlsecsTime(100);
+        }
+        if ( createdThreadsNumber != 0 ) {
+            logWriter.println("--> SuspendCountDebuggee: All created threads are started!");
+        }
+
+        synchronizer.sendMessage(Integer.toString(createdThreadsNumber));
+        if ( createdThreadsNumber == 0 ) {
+            logWriter.println("--> SuspendCountDebuggee: FINISH...");
+            System.exit(0);
+        }
+        String messageFromTest = synchronizer.receiveMessage();  // signal to continue or to finish
+        
+        if ( ! messageFromTest.equals("FINISH") ) {
+            String mainThreadName = Thread.currentThread().getName();
+            synchronizer.sendMessage(mainThreadName);
+            while ( debuggeToFinish != 99 ) { // is set up by debugger - SuspendCountTest
+                waitMlsecsTime(100);
+            }
+        }
+
+        logWriter.println
+        ("--> SuspendCountDebuggee: Send signal to all threads to finish and wait...");
+        allThreadsToFinish = true;
+
+        for (int i=0; i < createdThreadsNumber; i++) {
+            while ( suspendCountDebuggeeThreads[i].isAlive() ) {
+                waitMlsecsTime(10);
+            }
+        }
+        logWriter.println
+        ("--> SuspendCountDebuggee: All threads finished!");
+
+        logWriter.println("--> SuspendCountDebuggee: FINISH...");
+
+    }
+
+    public static void main(String [] args) {
+        runDebuggee(SuspendCountDebuggee.class);
+    }
+
+}
+
+class SuspendCountDebuggee_Thread extends Thread {
+    
+    int threadKind;
+    
+    public SuspendCountDebuggee_Thread(int threadNumber) {
+        super(SuspendCountDebuggee.THREAD_NAME_PATTERN + threadNumber);
+        threadKind = threadNumber % 3;
+    }
+
+    public void run() {
+        SuspendCountDebuggee parent = SuspendCountDebuggee.suspendCountDebuggeeThis;
+        synchronized (parent) { 
+            SuspendCountDebuggee.startedThreadsNumber++;
+        }
+        while ( ! SuspendCountDebuggee.allThreadsToFinish ) {
+            switch ( threadKind ) {
+            case 0:
+                SuspendCountDebuggee.waitMlsecsTime(100);
+                break;
+            case 1:
+                SuspendCountDebuggee.sleepMlsecsTime(100);
+            }
+        }
+    }
+}
+
+

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendCountTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendCountTest.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendCountTest.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendCountTest.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,430 @@
+/*
+ * 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 15.02.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+import org.apache.harmony.jpda.tests.framework.jdwp.exceptions.*;
+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 ThreadReference.SuspendCount command.
+ */
+public class SuspendCountTest extends JDWPSyncTestCase {
+
+    static final int testStatusPassed = 0;
+    static final int testStatusFailed = -1;
+    static final String debuggeeSignature = 
+            "Lorg/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendCountDebuggee;";
+
+    protected String getDebuggeeClassName() {
+        return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.SuspendCountDebuggee";
+    }
+
+    /**
+     * This testcase exercises ThreadReference.SuspendCount command.
+     * <BR>At first the test starts SuspendCountDebuggee which starts and runs some tested threads.
+     * <BR>After the tested threads starts, the test suspends every 
+     * tested thread in debuggee some times and 
+     * check that ThreadReference.SuspendCount command returns 
+     * expected number of times thread was suspended.
+     * <BR>Then the test suspends all debuggee by VirtualMachine.Suspend command
+     * and check that ThreadReference.SuspendCount command returns 1 value
+     * for all tested threads and main thread.
+     * <BR>Then the test resumes all debuggee by VirtualMachine.Resume command
+     * and check that ThreadReference.SuspendCount command returns 0 value
+     * for all tested threads and main thread. 
+     */
+    public void testSuspendCount001() {
+        logWriter.println("==> testSuspendCount001: 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);
+            synchronizer.sendMessage("FINISH");
+            printErrorAndFail("Can NOT get number of started threads from debuggee! ");
+        }
+        if ( testedThreadsNumber == 0 ) {
+            logWriter.println("==>  There are no started threads in debuggee to test" 
+                    + " - testSuspendCount001 finishes!");
+            synchronizer.sendMessage("FINISH");
+            return;
+        }
+        logWriter.println("==>  Number of started threads in debuggee to test = " + testedThreadsNumber);
+        String[] testedThreadsNames = new String[testedThreadsNumber+1]; // +1 is for main debuggee thread
+        long[] testedThreadsIDs = new long[testedThreadsNumber+1];
+        for (int i = 0; i < testedThreadsNumber; i++) {
+            testedThreadsNames[i] = SuspendCountDebuggee.THREAD_NAME_PATTERN + i;
+            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);
+            synchronizer.sendMessage("FINISH");
+            printErrorAndFail("Can NOT get all ThreadID in debuggee! ");
+        }
+        int threads = allThreadIDReply.getNextValueAsInt();
+        logWriter.println("==>  Number of all threads in debuggee = " + threads);
+        String[] allThreadsNames = new String[threads];
+        long[] allThreadsIDs = new long[threads];
+        boolean suspendCommandFailed = false;
+        boolean suspendCountCommandFailed = false;
+        boolean resumeCommandFailed = false;
+        
+        int suspendNumber = 0;
+        for (int i = 0; i < threads; i++) {
+            long threadID = allThreadIDReply.getNextValueAsThreadID();
+            allThreadsIDs[i] = threadID;
+            String threadName = null;
+            try {
+                threadName = debuggeeWrapper.vmMirror.getThreadName(threadID); 
+            } catch (ReplyErrorCodeException exception) {
+                logWriter.println
+                    ("==> WARNING: Can NOT get thread name for threadID = " + threadID);
+                continue;
+            }
+            allThreadsNames[i] = threadName;
+            int k = 0;
+            for (; k < testedThreadsNumber; k++) {
+                if ( threadName.equals(testedThreadsNames[k]) ) {
+                    testedThreadsIDs[k] = threadID;
+                    break;
+                }
+            }
+            if ( k == testedThreadsNumber ) {
+                // it is not thread to test
+                continue;
+            }
+            
+            logWriter.println("\n==> Check for Thread: threadID = " + threadID 
+                    + "; threadName = " + threadName);
+
+            logWriter.println("==> Send ThreadReference.SuspendCount command..."); 
+            CommandPacket packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
+            packet.setNextValueAsThreadID(threadID);
+            ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+            if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command") ) {
+                suspendCountCommandFailed = true;
+            } else {
+                int suspendCount = reply.getNextValueAsInt();
+                logWriter.println("==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount); 
+                if ( suspendCount != 0 ) {
+                    logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + threadName);
+                    logWriter.println("##          Expected suspendCount  = 0");  
+                    suspendCountCommandFailed = true;
+                }
+            }
+
+            suspendNumber++;
+            logWriter.println("==> Send ThreadReference.Suspend command number of times = " 
+                    + suspendNumber + "..."); 
+            int j = 0;
+            for (; j < suspendNumber; j++) {
+                packet = new CommandPacket(
+                        JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                        JDWPCommands.ThreadReferenceCommandSet.SuspendCommand);
+                packet.setNextValueAsThreadID(threadID);
+                reply = debuggeeWrapper.vmMirror.performCommand(packet);
+                if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.Suspend command") ) {
+                    break;
+                }
+            }
+            if ( j < suspendNumber ) {
+                suspendCommandFailed = true;
+                continue;
+            }
+
+            logWriter.println("==> Send ThreadReference.SuspendCount command..."); 
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
+            packet.setNextValueAsThreadID(threadID);
+            reply = debuggeeWrapper.vmMirror.performCommand(packet);
+            if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command") ) {
+                suspendCountCommandFailed = true;
+            } else {
+                int suspendCount = reply.getNextValueAsInt();
+                logWriter.println("==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount); 
+                if ( suspendCount != suspendNumber ) {
+                    logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + threadName);
+                    logWriter.println("##          Expected suspendCount  = " + suspendNumber);  
+                    suspendCountCommandFailed = true;
+                }
+            }
+
+            logWriter.println("==> Send ThreadReference.Resume command..."); 
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.ResumeCommand);
+            packet.setNextValueAsThreadID(threadID);
+            reply = debuggeeWrapper.vmMirror.performCommand(packet);
+            if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.Resume command") ) {
+                resumeCommandFailed = true;
+            }
+
+            logWriter.println("==> Send ThreadReference.SuspendCount command..."); 
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
+            packet.setNextValueAsThreadID(threadID);
+            reply = debuggeeWrapper.vmMirror.performCommand(packet);
+            if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command") ) {
+                suspendCountCommandFailed = true;
+            } else {
+                int suspendCount = reply.getNextValueAsInt();
+                logWriter.println("==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount); 
+                if ( suspendCount != (suspendNumber -1) ) {
+                    logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + threadName);
+                    logWriter.println("##          Expected suspendCount  = " + (suspendNumber-1));  
+                    suspendCountCommandFailed = true;
+                }
+            }
+            
+            if ( suspendNumber == 1 ) {
+                continue;
+            }
+
+            logWriter.println("==> Send ThreadReference.Resume command number of times = " 
+                    + (suspendNumber - 1) + "..."); 
+            j = 0;
+            for (; j < (suspendNumber-1); j++) {
+                packet = new CommandPacket(
+                        JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                        JDWPCommands.ThreadReferenceCommandSet.ResumeCommand);
+                packet.setNextValueAsThreadID(threadID);
+                reply = debuggeeWrapper.vmMirror.performCommand(packet);
+                if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.Resume command") ) {
+                    break;
+                }
+            }
+            if ( j < (suspendNumber-1) ) {
+                resumeCommandFailed = true;
+                continue;
+            }
+
+            logWriter.println("==> Send ThreadReference.SuspendCount command..."); 
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
+            packet.setNextValueAsThreadID(threadID);
+            reply = debuggeeWrapper.vmMirror.performCommand(packet);
+            if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command") ) {
+                suspendCountCommandFailed = true;
+                continue;
+            }
+            int suspendCount = reply.getNextValueAsInt();
+            logWriter.println("==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount); 
+            if ( suspendCount != 0 ) {
+                logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + threadName);
+                logWriter.println("##          Expected suspendCount  = 0");  
+                suspendCountCommandFailed = true;
+            }
+        }
+
+        String errorMessage = "";
+        if ( suspendCountCommandFailed ) {
+            errorMessage = errorMessage + "## Error found out while ThreadReference.SuspendCount command performing!\n";
+        }
+        if ( suspendCommandFailed ) {
+            errorMessage = errorMessage + "## Error found out while ThreadReference.Suspend command performing!\n";
+        }
+        if ( resumeCommandFailed ) {
+            errorMessage = errorMessage + "## Error found out while ThreadReference.Resume command performing!\n";
+        }
+
+        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 ) {
+            errorMessage = errorMessage + "## Some of tested threads are not found!\n";
+        }
+        if ( ! errorMessage.equals("") ) {
+            synchronizer.sendMessage("FINISH");
+            printErrorAndFail("\ntestSuspendCount001 FAILED:\n" + errorMessage);
+        }
+        
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        logWriter.println("\n==> Check ThreadReference.SuspendCount command when all debuggee is suspended...");
+        testedThreadsNames[testedThreadsNumber] = synchronizer.receiveMessage(); // debuggee main thread name
+        
+        testedThreadsIDs[testedThreadsNumber] = 0; // debuggee main thread ID
+        for (int i = 0; i < threads; i++) {
+            if ( testedThreadsNames[testedThreadsNumber].equals(allThreadsNames[i]) ) {
+                testedThreadsIDs[testedThreadsNumber] = allThreadsIDs[i];
+                break;
+            }
+        }
+        if ( testedThreadsIDs[testedThreadsNumber] == 0 ) {
+            setStaticIntField(debuggeeSignature, SuspendCountDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+            logWriter.println("## FAILURE: Debuggee main thread is not found out among debuggee threads!");
+            logWriter.println("##          Thread name = " + testedThreadsNames[testedThreadsNumber]);
+            printErrorAndFail("\nCan NOT found out debuggee main thread!");
+        }
+        
+        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, SuspendCountDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+            logWriter.println("## FAILURE: VirtualMachine.Suspend command returns error = " + errorCode 
+                    + "(" + JDWPConstants.Error.getName(errorCode) + ")");
+            printErrorAndFail("\nVirtualMachine.Suspend command FAILED!");
+        }
+        
+        for (int i = 0; i < (testedThreadsNumber+1); i++) {
+            logWriter.println("==> Send ThreadReference.SuspendCount command for thread = " 
+                    + testedThreadsNames[i] + " ..."); 
+            packet = new CommandPacket(
+                    JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                    JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
+            packet.setNextValueAsThreadID(testedThreadsIDs[i]);
+            reply = debuggeeWrapper.vmMirror.performCommand(packet);
+            if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command") ) {
+                suspendCountCommandFailed = true;
+                continue;
+            }
+            int suspendCount = reply.getNextValueAsInt();
+            logWriter.println("==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount); 
+            if ( suspendCount != 1 ) {
+                logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + testedThreadsNames[i]);
+                logWriter.println("##          Expected suspendCount  = 1");  
+                suspendCountCommandFailed = true;
+            }
+        }
+
+        logWriter.println("\n==> Send VirtualMachine.Resume command ..."); 
+        packet = new CommandPacket(
+                JDWPCommands.VirtualMachineCommandSet.CommandSetID,
+                JDWPCommands.VirtualMachineCommandSet.ResumeCommand);
+        reply = debuggeeWrapper.vmMirror.performCommand(packet);
+        if ( ! checkReplyPacketWithoutFail(reply, "VirtualMachine.Resume command") ) {
+            resumeCommandFailed = true;
+        } else {
+            logWriter.println("\n==> Check ThreadReference.SuspendCount command after debuggee is resumed..."); 
+            for (int i = 0; i < (testedThreadsNumber+1); i++) {
+                logWriter.println("==> Send ThreadReference.SuspendCount command for thread = " 
+                        + testedThreadsNames[i] + " ..."); 
+                packet = new CommandPacket(
+                        JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
+                        JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
+                packet.setNextValueAsThreadID(testedThreadsIDs[i]);
+                reply = debuggeeWrapper.vmMirror.performCommand(packet);
+                if ( ! checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command") ) {
+                    suspendCountCommandFailed = true;
+                    continue;
+                }
+                int suspendCount = reply.getNextValueAsInt();
+                logWriter.println("==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount); 
+                if ( suspendCount != 0 ) {
+                    logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + testedThreadsNames[i]);
+                    logWriter.println("##          Expected suspendCount  = 0");  
+                    suspendCountCommandFailed = true;
+                }
+            }
+        }
+
+        setStaticIntField(debuggeeSignature, SuspendCountDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
+
+        if ( suspendCountCommandFailed ) {
+            errorMessage = "## Error found out while ThreadReference.SuspendCount command performing!\n";
+        }
+
+        if ( resumeCommandFailed ) {
+            errorMessage = "## Error found out while VirtualMachine.Resume command performing!\n";
+        }
+
+        if ( ! errorMessage.equals("") ) {
+            printErrorAndFail("\ntestSuspendCount001 FAILED:\n" + errorMessage);
+        }
+        logWriter.println("\n==> testSuspendCount001 - OK!");
+    }
+/*
+    protected int 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 -1;
+        }
+
+        long fieldID = 
+            debuggeeWrapper.vmMirror.getFieldID(classID, fieldName);
+        if ( fieldID == -1 ) {
+            logWriter.println
+            ("## setStaticIntField(): Can NOT get fieldID for field = '" 
+                    + fieldName + "'");
+            return -1;
+        }
+        
+        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 -1;
+        }
+        return 0;
+    }
+*/
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(SuspendCountTest.class);
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendDebuggee.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendDebuggee.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/ThreadReference/SuspendDebuggee.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,144 @@
+/*
+ * 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.2 $
+ */
+
+/**
+ * Created on 06.06.2006 
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
+
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+public class SuspendDebuggee extends SyncDebuggee {
+    public static final int THREAD_NUMBER_LIMIT = 9; 
+    public static final String THREAD_NAME_PATTERN = "SuspendDebuggee_Thread_"; 
+
+    static SuspendDebuggee suspendDebuggeeThis;
+
+    static volatile boolean allThreadsToFinish = false;
+    static int createdThreadsNumber = 0;
+    static volatile int startedThreadsNumber = 0;
+
+    static SuspendDebuggee_Thread[] suspendDebuggeeThreads = null;
+
+    static Object waitTimeObject = new Object();
+    static void waitMlsecsTime(long mlsecsTime) { 
+        synchronized(waitTimeObject) {
+            try {
+                waitTimeObject.wait(mlsecsTime);
+            } catch (Throwable throwable) {
+                 // ignore
+            }
+        }
+    }
+    
+    static void sleepMlsecsTime(long mlsecsTime) { 
+        try {
+            Thread.sleep(mlsecsTime);
+        } catch (Throwable throwable) {
+             // ignore
+        }
+    }
+    
+    public void run() {
+        
+        logWriter.println("--> SuspendDebuggee: START...");
+        suspendDebuggeeThis = this;
+
+        logWriter.println("--> SuspendDebuggee: Create and start tested threads...");
+        try {
+            suspendDebuggeeThreads = new SuspendDebuggee_Thread[THREAD_NUMBER_LIMIT]; 
+            for (int i=0; i < THREAD_NUMBER_LIMIT; i++) {
+                suspendDebuggeeThreads[i]= new SuspendDebuggee_Thread(i);
+                suspendDebuggeeThreads[i].start();
+                createdThreadsNumber++;
+            }
+        } catch ( Throwable thrown) {
+            logWriter.println
+            ("--> SuspendDebuggee: Exception while creating threads: " + thrown);
+        }
+        logWriter.println
+        ("--> SuspendDebuggee: Created threads number = " + createdThreadsNumber);
+        
+        while ( startedThreadsNumber != createdThreadsNumber ) {
+            waitMlsecsTime(100);
+        }
+        if ( createdThreadsNumber != 0 ) {
+            logWriter.println("--> SuspendDebuggee: All created threads are started!");
+        }
+
+        synchronizer.sendMessage(Integer.toString(createdThreadsNumber));
+        if ( createdThreadsNumber == 0 ) {
+            logWriter.println("--> SuspendDebuggee: FINISH...");
+            return;
+        }
+        synchronizer.receiveMessage(); // signal to finish
+
+        logWriter.println
+        ("--> SuspendDebuggee: Send signal to all threads to finish and wait...");
+        allThreadsToFinish = true;
+
+        for (int i=0; i < createdThreadsNumber; i++) {
+            while ( suspendDebuggeeThreads[i].isAlive() ) {
+                waitMlsecsTime(10);
+            }
+        }
+        logWriter.println
+        ("--> SuspendDebuggee: All threads finished!");
+
+        logWriter.println("--> SuspendDebuggee: FINISH...");
+
+    }
+
+    public static void main(String [] args) {
+        runDebuggee(SuspendDebuggee.class);
+    }
+
+}
+
+class SuspendDebuggee_Thread extends Thread {
+    
+    int threadKind;
+    
+    public SuspendDebuggee_Thread(int threadNumber) {
+        super(SuspendDebuggee.THREAD_NAME_PATTERN + threadNumber);
+        threadKind = threadNumber % 3;
+    }
+
+    public void run() {
+        SuspendDebuggee parent = SuspendDebuggee.suspendDebuggeeThis;
+        synchronized (parent) { 
+            SuspendDebuggee.startedThreadsNumber++;
+        }
+        while ( ! SuspendDebuggee.allThreadsToFinish ) {
+            switch ( threadKind ) {
+            case 0:
+                SuspendDebuggee.waitMlsecsTime(100);
+                break;
+            case 1:
+                SuspendDebuggee.sleepMlsecsTime(100);
+            }
+        }
+    }
+}
+
+

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