Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 15950 invoked from network); 8 Apr 2008 09:51:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Apr 2008 09:51:49 -0000 Received: (qmail 31276 invoked by uid 500); 8 Apr 2008 09:51:48 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 31256 invoked by uid 500); 8 Apr 2008 09:51:48 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 31247 invoked by uid 99); 8 Apr 2008 09:51:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Apr 2008 02:51:48 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Apr 2008 09:51:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A7DA11A983A; Tue, 8 Apr 2008 02:51:26 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r645814 [2/2] - in /harmony/enhanced/jdktools/branches/java6/modules/jpda: ./ src/main/native/jdwp/common/agent/commands/ src/main/native/jdwp/common/agent/core/ src/main/native/jdwp/common/generic/ src/test/java/org/apache/harmony/jpda/tes... Date: Tue, 08 Apr 2008 09:51:21 -0000 To: commits@harmony.apache.org From: lvjing@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080408095126.A7DA11A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MethodExitWithReturnValueTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MethodExitWithReturnValueTest.java?rev=645814&view=auto ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MethodExitWithReturnValueTest.java (added) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MethodExitWithReturnValueTest.java Tue Apr 8 02:51:16 2008 @@ -0,0 +1,219 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.Events; + +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.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent; +import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; +import org.apache.harmony.jpda.tests.framework.jdwp.Value; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.Event_METHOD_EXIT; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.Event_METHOD_EXIT_WITH_RETURN_VALUE; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + +public class MethodExitWithReturnValueTest extends JDWPEventTestCase { + + protected String getDebuggeeClassName() { + return MethodExitWithReturnValueDebuggee.class.getName(); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(MethodExitWithReturnValueTest.class); + } + + /** + * This testcase is for METHOD_EXIT_WITH_RETURN_VALUE event.
+ * It runs MethodExitWithReturnValueDebuggee that executed own exceptionMethod. + * It then verify that requested METHOD_EXIT_WITH_RETURN_VALUE event occurs + */ + public void testMethodExitWithReturnValueException() { + logWriter.println("==> Start testMethodExitWithReturnValue which method will throw IOException."); + String methodExitClassNameRegexp = "org.apache.harmony.jpda.tests.jdwp.Events.MethodExitWithReturnValueDebuggee"; + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Set event request for MethodExitWithReturnValue + ReplyPacket reply = debuggeeWrapper.vmMirror + .setMethodExit(methodExitClassNameRegexp); + checkReplyPacket(reply, "Set METHOD_EXIT_WITH_RETURN_VALUE event"); + + // Inform debuggee desired return method + synchronizer.sendMessage(MethodExitWithReturnValueDebuggee.EXCEPTION_TYPE); + + // Receive MethodExitWithReturnValue event + CommandPacket receiveEvent = null; + try { + receiveEvent = debuggeeWrapper.vmMirror.receiveEvent(); + } catch (TestErrorException e) { + printErrorAndFail("There is no event received."); + } + ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(receiveEvent); + Event_METHOD_EXIT event = (Event_METHOD_EXIT)parsedEvents[0]; + + assertEquals("Invalid number of events,", 1, parsedEvents.length); + assertEquals("Invalid event kind,", + JDWPConstants.EventKind.METHOD_EXIT, + event.getEventKind(), + JDWPConstants.EventKind.getName(JDWPConstants.EventKind.METHOD_EXIT), + JDWPConstants.EventKind.getName(event.getEventKind())); + + long refID = event.getLocation().classID; + String expectedSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/MethodExitWithReturnValueDebuggee;"; + String actualSignature = debuggeeWrapper.vmMirror.getReferenceTypeSignature(refID); + assertEquals("Invalid class signature of method caller,",expectedSignature,actualSignature); + } + + /** + * This testcase is for METHOD_EXIT_WITH_RETURN_VALUE event.
+ * It runs MethodExitWithReturnValueDebuggee that executed own booleanMethod. + * It then verify that requested METHOD_EXIT_WITH_RETURN_VALUE event occurs + * and the returned value is as expected boolean value. + */ + public void testMethodExitWithReturnValueOfBoolean() { + runMethodExitWithReturn(MethodExitWithReturnValueDebuggee.BOOLEAN_TYPE); + } + + /** + * This testcase is for METHOD_EXIT_WITH_RETURN_VALUE event.
+ * It runs MethodExitWithReturnValueDebuggee that executed own shortMethod. + * It then verify that requested METHOD_EXIT_WITH_RETURN_VALUE event occurs + * and the returned value is as expected short value. + */ + public void testMethodExitWithReturnValueOfShort() { + runMethodExitWithReturn(MethodExitWithReturnValueDebuggee.SHORT_TYPE); + } + + /** + * This testcase is for METHOD_EXIT_WITH_RETURN_VALUE event.
+ * It runs MethodExitWithReturnValueDebuggee that executed own charMethod. + * It then verify that requested METHOD_EXIT_WITH_RETURN_VALUE event occurs + * and the returned value is as expected char value. + */ + public void testMethodExitWithReturnValueOfChar() { + runMethodExitWithReturn(MethodExitWithReturnValueDebuggee.CHAR_TYPE); + } + + /** + * This testcase is for METHOD_EXIT_WITH_RETURN_VALUE event.
+ * It runs MethodExitWithReturnValueDebuggee that executed own intMethod. + * It then verify that requested METHOD_EXIT_WITH_RETURN_VALUE event occurs + * and the returned value is as expected integer value. + */ + public void testMethodExitWithReturnValueOfInt() { + runMethodExitWithReturn(MethodExitWithReturnValueDebuggee.INT_TYPE); + } + + /** + * This testcase is for METHOD_EXIT_WITH_RETURN_VALUE event.
+ * It runs MethodExitWithReturnValueDebuggee that executed own longMethod. + * It then verify that requested METHOD_EXIT_WITH_RETURN_VALUE event occurs + * and the returned value is as expected long value. + */ + public void testMethodExitWithReturnValueOfLong() { + runMethodExitWithReturn(MethodExitWithReturnValueDebuggee.LONG_TYPE); + } + + /** + * This testcase is for METHOD_EXIT_WITH_RETURN_VALUE event.
+ * It runs MethodExitWithReturnValueDebuggee that executed own doubleMethod. + * It then verify that requested METHOD_EXIT_WITH_RETURN_VALUE event occurs + * and the returned value is as expected double value. + */ + public void testMethodExitWithReturnValueOfDouble() { + runMethodExitWithReturn(MethodExitWithReturnValueDebuggee.DOUBLE_TYPE); + } + + + /* + * Internal function used to receive MethodExitWithReturnValue event. + * Test the returned value according to the parameter's value + */ + private void runMethodExitWithReturn(String type){ + logWriter.println("==> Start testMethodExitWithReturnValue with return type of " + type); + String methodExitClassNameRegexp = "org.apache.harmony.jpda.tests.jdwp.Events.MethodExitWithReturnValueDebuggee"; + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Set event request for MethodExitWithReturnValue + ReplyPacket reply = debuggeeWrapper.vmMirror + .setMethodExitWithReturnValue(methodExitClassNameRegexp); + checkReplyPacket(reply, "Set METHOD_EXIT_WITH_RETURN_VALUE event"); + + // Inform debuggee desired return method + synchronizer.sendMessage(type.toString()); + + // Receive MethodExitWithReturnValue event + + CommandPacket receiveEvent = null; + try { + receiveEvent = debuggeeWrapper.vmMirror.receiveEvent(); + } catch (TestErrorException e) { + printErrorAndFail("There is no event received."); + } + ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(receiveEvent); + + // Check received event's basic information + assertEquals("Invalid number of events,", 1, parsedEvents.length); + logWriter.println("==> CHECK: receive 1 event"); + + assertEquals( + "Invalid event kind,", + JDWPConstants.EventKind.METHOD_EXIT_WITH_RETURN_VALUE, + parsedEvents[0].getEventKind(), + JDWPConstants.EventKind + .getName(JDWPConstants.EventKind.METHOD_EXIT_WITH_RETURN_VALUE), + JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind())); + logWriter.println("==> CHECK: received event's type is " + JDWPConstants.EventKind.METHOD_EXIT_WITH_RETURN_VALUE); + + // Check return value according to it's type + Value value = ((Event_METHOD_EXIT_WITH_RETURN_VALUE) parsedEvents[0]) + .getReturnValue(); + + if(type.equals(MethodExitWithReturnValueDebuggee.BOOLEAN_TYPE)){ + boolean b = value.getBooleanValue(); + logWriter.println("==> CHECK: booleanMethod() is invoked, return value:" + b); + assertEquals("Invalid return value,", + MethodExitWithReturnValueDebuggee.EXPECTED_BOOLEAN, b); + }else if(type.equals(MethodExitWithReturnValueDebuggee.SHORT_TYPE)){ + short s = value.getShortValue(); + logWriter.println("==> CHECK: shortMethod() is invoked, return value:" + s); + assertEquals("Invalid return value,", + MethodExitWithReturnValueDebuggee.EXPECTED_SHORT, s); + }else if(type.equals(MethodExitWithReturnValueDebuggee.CHAR_TYPE)){ + char c = value.getCharValue(); + logWriter.println("==> CHECK: charMethod() is invoked, return value:" + c); + assertEquals("Invalid return value,", + MethodExitWithReturnValueDebuggee.EXPECTED_CHAR, c); + }else if(type.equals(MethodExitWithReturnValueDebuggee.INT_TYPE)){ + int i = value.getIntValue(); + logWriter.println("==> CHECK: intMethod() is invoked, return value:" + i); + assertEquals("Invalid return value,", + MethodExitWithReturnValueDebuggee.EXPECTED_INT, i); + }else if(type.equals(MethodExitWithReturnValueDebuggee.LONG_TYPE)){ + long l = value.getLongValue(); + logWriter.println("==> CHECK: longMethod() is invoked, return value:" + l); + assertEquals("Invalid return value,", + MethodExitWithReturnValueDebuggee.EXPECTED_LONG, l); + }else if(type.equals(MethodExitWithReturnValueDebuggee.DOUBLE_TYPE)){ + double d = value.getDoubleValue(); + logWriter.println("==> CHECK: doubleMethod() is invoked, return value:" + d); + assertEquals("Invalid return value,", + MethodExitWithReturnValueDebuggee.EXPECTED_DOUBLE, d); + } + } +} Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MethodExitWithReturnValueTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java?rev=645814&view=auto ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java (added) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java Tue Apr 8 02:51:16 2008 @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.Events; + +import org.apache.harmony.jpda.tests.framework.LogWriter; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; +import org.apache.harmony.jpda.tests.share.SyncDebuggee; + +public class MonitorContendedEnterAndEnteredDebuggee extends SyncDebuggee { + + static final String TESTED_THREAD = "BLOCKED_THREAD"; + + static Object lock = new MonitorWaitMockMonitor(); + + BlockedThread thread; + + public void run() { + thread = new BlockedThread(logWriter,TESTED_THREAD); + + // Inform debugger test is ready for testing + logWriter.println("--> Main thread : started"); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + synchronized (lock) { + // Request has been set by Debugger + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + logWriter.println("main thread: start tested thread"); + thread.start(); + + // wait and hold the lock until the second thread blocks + while (!thread.getState().equals(Thread.State.valueOf("BLOCKED"))){ + Thread.yield(); + logWriter.println("main thread: Waiting for second thread to attempt to lock a monitor"); + } + + logWriter.println("--> main thread: finish test"); + } + } + + class BlockedThread extends Thread { + private LogWriter logWriter; + + public BlockedThread(LogWriter writer, String name){ + logWriter = writer; + this.setName(name); + } + + public void run() { + logWriter.println("--> BlockedThread: start to run"); + + synchronized (lock) { + this.getName().trim(); + logWriter.println("--> BlockedThread: get lock"); + } + } + } + + public static void main(String[] args) { + runDebuggee(MonitorContendedEnterAndEnteredDebuggee.class); + } + +} + Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterTest.java?rev=645814&view=auto ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterTest.java (added) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterTest.java Tue Apr 8 02:51:16 2008 @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.Events; + +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.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.Event_MONITOR_CONTENDED_ENTER; +import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + +public class MonitorContendedEnterTest extends JDWPSyncTestCase { + String monitorSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitMockMonitor;"; + + protected String getDebuggeeClassName() { + return "org.apache.harmony.jpda.tests.jdwp.Events.MonitorContendedEnterAndEnteredDebuggee"; + } + + public void testMonitorContendedEnterForClassOnly() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Attain Object class id + long monitorRefTypeID = getClassIDBySignature(monitorSignature); + logWriter.println("==> Object ReferenceType ID = " + monitorRefTypeID); + + // Set MONITOR_CONTENDED_ENTER request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorContendedEnterForClassOnly(monitorRefTypeID); + + // Verify received event + verifyEvent(); + } + + private void verifyEvent(){ + // Inform debuggee that the request has been set + logWriter.println("==> Request has been set."); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + // Receive event of MONITOR_CONTENDED_ENTER + logWriter.println("==> Receive Event."); + CommandPacket receiveEvent = null; + try { + receiveEvent = debuggeeWrapper.vmMirror.receiveEvent(); + } catch (TestErrorException e) { + printErrorAndFail("There is no event received."); + } + ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(receiveEvent); + Event_MONITOR_CONTENDED_ENTER event = (ParsedEvent.Event_MONITOR_CONTENDED_ENTER)parsedEvents[0]; + + assertEquals("Invalid number of events,", 1, parsedEvents.length); + assertEquals("Invalid event kind,", JDWPConstants.EventKind.MONITOR_CONTENDED_ENTER, event.getEventKind() + , JDWPConstants.EventKind.getName(JDWPConstants.EventKind.MONITOR_CONTENDED_ENTER) + , JDWPConstants.EventKind.getName(event.getEventKind())); + logWriter.println("==> CHECK: Event Kind: " + JDWPConstants.EventKind.getName(JDWPConstants.EventKind.MONITOR_CONTENDED_ENTER)); + + // Getting ID of the tested thread + logWriter.println("==> Get testedThreadID..."); + long testedThreadID = debuggeeWrapper.vmMirror + .getThreadID(MonitorContendedEnterAndEnteredDebuggee.TESTED_THREAD); + assertEquals("Invalid tested thread id: ", testedThreadID + , event.getThreadID()); + logWriter.println("==> CHECK: tested blocked thread id: " + testedThreadID ); + + // Get monitor object from event packet + long objID = event.getTaggedObject().objectID; + // Check the ReferenceType of monitor object + long refID = debuggeeWrapper.vmMirror.getReferenceType(objID); + String actualSignature = debuggeeWrapper.vmMirror.getReferenceTypeSignature(refID); + assertEquals("Invalid monitor class signature: ", monitorSignature + , actualSignature); + logWriter.println("==> CHECK: monitor class signature: " + actualSignature); + } + +} Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnteredTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnteredTest.java?rev=645814&view=auto ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnteredTest.java (added) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnteredTest.java Tue Apr 8 02:51:16 2008 @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.Events; + +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.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.Event_MONITOR_CONTENDED_ENTERED; +import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + +public class MonitorContendedEnteredTest extends JDWPSyncTestCase { + String monitorSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitMockMonitor;"; + + protected String getDebuggeeClassName() { + return "org.apache.harmony.jpda.tests.jdwp.Events.MonitorContendedEnterAndEnteredDebuggee"; + } + + public void testMonitorContendedEntteredForClassOnly() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Attain Object class id + long monitorRefTypeID = getClassIDBySignature(monitorSignature); + logWriter.println("==> Object ReferenceType ID = " + monitorRefTypeID); + + // Set MONITOR_CONTENDED_ENTERED request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorContendedEnteredForClassOnly(monitorRefTypeID); + + // Verify received event + verifyEvent(); + } + + private void verifyEvent(){ + // Inform debuggee that the request has been set + logWriter.println("==> Request has been set."); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + // Receive event of MONITOR_CONTENDED_ENTERED + logWriter.println("==> Receive Event."); + CommandPacket receiveEvent = null; + try { + receiveEvent = debuggeeWrapper.vmMirror.receiveEvent(); + } catch (TestErrorException e) { + printErrorAndFail("There is no event received."); + } + ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(receiveEvent); + Event_MONITOR_CONTENDED_ENTERED event = (ParsedEvent.Event_MONITOR_CONTENDED_ENTERED)parsedEvents[0]; + + assertEquals("Invalid number of events,", 1, parsedEvents.length); + assertEquals("Invalid event kind,", JDWPConstants.EventKind.MONITOR_CONTENDED_ENTERED, event.getEventKind() + , JDWPConstants.EventKind.getName(JDWPConstants.EventKind.MONITOR_CONTENDED_ENTERED) + , JDWPConstants.EventKind.getName(event.getEventKind())); + logWriter.println("==> CHECK: Event Kind: " + JDWPConstants.EventKind.getName(JDWPConstants.EventKind.MONITOR_CONTENDED_ENTERED)); + + // Getting ID of the tested thread + logWriter.println("==> Get testedThreadID..."); + long testedThreadID = debuggeeWrapper.vmMirror + .getThreadID(MonitorContendedEnterAndEnteredDebuggee.TESTED_THREAD); + assertEquals("Invalid tested thread id: ", testedThreadID + , event.getThreadID()); + logWriter.println("==> CHECK: tested blocked thread id: " + testedThreadID ); + + // Get monitor object from event packet + long objID = event.getTaggedObject().objectID; + // Check the ReferenceType of monitor object + long refID = debuggeeWrapper.vmMirror.getReferenceType(objID); + String actualSignature = debuggeeWrapper.vmMirror.getReferenceTypeSignature(refID); + assertEquals("Invalid monitor class signature: ", monitorSignature + , actualSignature); + logWriter.println("==> CHECK: monitor class signature: " + actualSignature); + } + +} Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnteredTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitAndWaitedDebuggee.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitAndWaitedDebuggee.java?rev=645814&view=auto ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitAndWaitedDebuggee.java (added) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitAndWaitedDebuggee.java Tue Apr 8 02:51:16 2008 @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.Events; + +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; +import org.apache.harmony.jpda.tests.share.SyncDebuggee; + +public class MonitorWaitAndWaitedDebuggee extends SyncDebuggee { + + public static long TIMEOUT = 500; + + public void run() { + MonitorWaitMockMonitor monitor = new MonitorWaitMockMonitor(); + + // Inform debugger to prepare for testing + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Wait until debugger complete the event request + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + try { + synchronized (monitor) { + logWriter.println("--> Tested Thread invoke wait"); + monitor.wait(TIMEOUT); + logWriter.println("--> Tested Thread invoked wait"); + } + } catch (Throwable e) { + e.printStackTrace(); + } + + logWriter.println("--> Tested Thread finished"); + } + + public static void main(String[] args) { + runDebuggee(MonitorWaitAndWaitedDebuggee.class); + } +} + +class MonitorWaitMockMonitor {} \ No newline at end of file Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitAndWaitedDebuggee.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitTest.java?rev=645814&view=auto ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitTest.java (added) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitTest.java Tue Apr 8 02:51:16 2008 @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.Events; + +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.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.Event_MONITOR_WAIT; +import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + +public class MonitorWaitTest extends JDWPSyncTestCase { + String monitorSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitMockMonitor;"; + + protected String getDebuggeeClassName() { + return "org.apache.harmony.jpda.tests.jdwp.Events.MonitorWaitAndWaitedDebuggee"; + } + + public void testMonitorWaitForClassOnly() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Attain Object class id + long monitorRefTypeID = getClassIDBySignature(monitorSignature); + logWriter.println("==> Object ReferenceType ID = " + monitorRefTypeID); + + // Set MonitorWait request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitForClassOnly(monitorRefTypeID); + + // Verify received event + verifyEvent(); + } + + public void testMonitorWaitForClassMatchExact() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + String classPattern = "org.apache.harmony.jpda.tests.jdwp.Events.MonitorWaitMockMonitor"; + logWriter.println("==> tested class match pattern: " + classPattern); + + // Set MonitorWait request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitForClassMatch(classPattern); + + // Verify received event + verifyEvent(); + } + + public void testMonitorWaitForClassMatchFirst() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + String classPattern = "org.apache.harmony.jpda.tests.jdwp.Events.*"; + logWriter.println("==> tested class match pattern: " + classPattern); + + // Set MonitorWait request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitForClassMatch(classPattern); + + // Verify received event + verifyEvent(); + } + + public void testMonitorWaitForClassMatchSecond() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + String classPattern = "*MonitorWaitMockMonitor"; + logWriter.println("==> tested class match pattern: " + classPattern); + + // Set MonitorWait request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitForClassMatch(classPattern); + + // Verify received event + verifyEvent(); + } + + public void testMonitorWaitForClassExclude() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + String classPattern = "MockPatter*"; + logWriter.println("==> tested class exclude pattern: " + classPattern); + + // Set MonitorWait request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitForClassExclude(classPattern); + + // Verify received event + verifyEvent(); + } + + private void verifyEvent(){ + // Inform debuggee that the request has been set + logWriter.println("==> Request has been set."); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + // Receive event of MonitorWait + logWriter.println("==> Receive Event."); + CommandPacket receiveEvent = null; + try { + receiveEvent = debuggeeWrapper.vmMirror.receiveEvent(); + } catch (TestErrorException e) { + printErrorAndFail("There is no event received."); + } + ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(receiveEvent); + Event_MONITOR_WAIT event = (ParsedEvent.Event_MONITOR_WAIT)parsedEvents[0]; + + // Check event basic message + assertEquals("Invalid number of events,", 1, parsedEvents.length); + assertEquals("Invalid event kind,", JDWPConstants.EventKind.MONITOR_WAIT, parsedEvents[0].getEventKind() + , JDWPConstants.EventKind.getName(JDWPConstants.EventKind.MONITOR_WAIT) + , JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind())); + logWriter.println("==> CHECK: Event Kind: " + JDWPConstants.EventKind.getName(JDWPConstants.EventKind.MONITOR_WAIT)); + + // Check tested thread message + logWriter.println("==> Get testedThreadID..."); + long testedThreadID = debuggeeWrapper.vmMirror.getThreadID("main"); + assertEquals("Invalid tested thread id: ", testedThreadID, event.getThreadID()); + logWriter.println("==> CHECK: tested blocked thread id: " + testedThreadID ); + + // Check the ReferenceType of monitor object + long objID = event.getTaggedObject().objectID; + long refID = debuggeeWrapper.vmMirror.getReferenceType(objID); + String actualSignature = debuggeeWrapper.vmMirror.getReferenceTypeSignature(refID); + assertEquals("Invalid monitor class signature: ", monitorSignature + , actualSignature); + logWriter.println("==> CHECK: monitor class signature: " + actualSignature); + + // Check wait's timeout + assertEquals("Invalid reference type of prepared class,", MonitorWaitAndWaitedDebuggee.TIMEOUT + , ((ParsedEvent.Event_MONITOR_WAIT)parsedEvents[0]).getTimeout()); + logWriter.println("==> CHECK: Wait time out: " + MonitorWaitAndWaitedDebuggee.TIMEOUT); + } + +} Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitedTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitedTest.java?rev=645814&view=auto ============================================================================== --- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitedTest.java (added) +++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitedTest.java Tue Apr 8 02:51:16 2008 @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.jpda.tests.jdwp.Events; + +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.JDWPConstants; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent; +import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent.Event_MONITOR_WAITED; +import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; +import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; + +public class MonitorWaitedTest extends JDWPSyncTestCase { + String monitorSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitMockMonitor;"; + + protected String getDebuggeeClassName() { + return "org.apache.harmony.jpda.tests.jdwp.Events.MonitorWaitAndWaitedDebuggee"; + } + + public void testMonitorWaitedForClassOnly() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + // Attain Object class id + long monitorRefTypeID = getClassIDBySignature(monitorSignature); + logWriter.println("==> Object ReferenceType ID = " + monitorRefTypeID); + + // Set MonitorWaited request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitedForClassOnly(monitorRefTypeID); + + // Verify received event + verifyEvent(); + } + + public void testMonitorWaitedForClassMatchExact() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + String classPattern = "org.apache.harmony.jpda.tests.jdwp.Events.MonitorWaitMockMonitor"; + logWriter.println("==> tested class match pattern: " + classPattern); + + // Set MonitorWaited request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitedForClassMatch(classPattern); + + // Verify received event + verifyEvent(); + } + + public void testMonitorWaitedForClassMatchFirst() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + String classPattern = "org.apache.harmony.jpda.tests.jdwp.Events.*"; + logWriter.println("==> tested class match pattern: " + classPattern); + + // Set MonitorWaited request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitedForClassMatch(classPattern); + + // Verify received event + verifyEvent(); + } + + public void testMonitorWaitedForClassMatchSecond() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + String classPattern = "*MonitorWaitMockMonitor"; + logWriter.println("==> tested class match pattern: " + classPattern); + + // Set MonitorWaited request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitedForClassMatch(classPattern); + + // Verify received event + verifyEvent(); + } + + public void testMonitorWaitedForClassExclude() { + synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); + + String classPattern = "MockPatter*"; + logWriter.println("==> tested class exclude pattern: " + classPattern); + + // Set MonitorWaited request for MockMonitorClass + debuggeeWrapper.vmMirror.setMonitorWaitedForClassExclude(classPattern); + + // Verify received event + verifyEvent(); + } + + private void verifyEvent(){ + // Inform debuggee that the request has been set + logWriter.println("==> Request has been set."); + synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); + + // Receive event of MonitorWaited + logWriter.println("==> Receive Event."); + CommandPacket receiveEvent = null; + try { + receiveEvent = debuggeeWrapper.vmMirror.receiveEvent(); + } catch (TestErrorException e) { + printErrorAndFail("There is no event received."); + } + ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(receiveEvent); + Event_MONITOR_WAITED event = (ParsedEvent.Event_MONITOR_WAITED)parsedEvents[0]; + + // Check event basic message + assertEquals("Invalid number of events,", 1, parsedEvents.length); + assertEquals("Invalid event kind,", JDWPConstants.EventKind.MONITOR_WAITED, parsedEvents[0].getEventKind() + , JDWPConstants.EventKind.getName(JDWPConstants.EventKind.MONITOR_WAITED) + , JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind())); + logWriter.println("==> CHECK: Event Kind: " + JDWPConstants.EventKind.getName(JDWPConstants.EventKind.MONITOR_WAITED)); + + // Check tested thread message + logWriter.println("==> Get testedThreadID..."); + long testedThreadID = debuggeeWrapper.vmMirror.getThreadID("main"); + assertEquals("Invalid tested thread id: ", testedThreadID, event.getThreadID()); + logWriter.println("==> CHECK: tested blocked thread id: " + testedThreadID ); + + // Check the ReferenceType of monitor object + long objID = event.getTaggedObject().objectID; + long refID = debuggeeWrapper.vmMirror.getReferenceType(objID); + String actualSignature = debuggeeWrapper.vmMirror.getReferenceTypeSignature(refID); + assertEquals("Invalid monitor class signature: ", monitorSignature + , actualSignature); + logWriter.println("==> CHECK: monitor class signature: " + actualSignature); + + // Check wait's timeout + assertEquals("Invalid reference type of prepared class,", true + , event.getTimedout()); + logWriter.println("==> CHECK: Wait time out: " + MonitorWaitAndWaitedDebuggee.TIMEOUT); + } + +} Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorWaitedTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/resources/org/apache/harmony/jpda/tests/jdwp/Events/SourceDebugExtensionMockClass.class URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/resources/org/apache/harmony/jpda/tests/jdwp/Events/SourceDebugExtensionMockClass.class?rev=645814&view=auto ============================================================================== Binary file - no diff available. Propchange: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/test/resources/org/apache/harmony/jpda/tests/jdwp/Events/SourceDebugExtensionMockClass.class ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream