harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r559093 [2/3] - in /harmony/enhanced/jdktools/trunk/modules/jpda: src/main/native/jdwp/common/agent/core/ test/common/unit/org/apache/harmony/jpda/tests/framework/jdwp/ test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/
Date Tue, 24 Jul 2007 16:20:33 GMT
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents002Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents002Test.java?view=auto&rev=559093
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents002Test.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents002Test.java
Tue Jul 24 09:20:30 2007
@@ -0,0 +1,248 @@
+/*
+ * 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.1 $
+ */
+
+/**
+ * Created on 06.10.2006
+ */
+package org.apache.harmony.jpda.tests.jdwp.Events;
+
+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.Location;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+
+/**
+ * JDWP Unit test for METHOD_ENTRY, METHOD_EXIT events for empty method.
+ */
+public class CombinedEvents002Test extends CombinedEventsTestCase {
+    static final String TESTED_CLASS_NAME = 
+        CombinedEvents002Debuggee.TESTED_CLASS_NAME; 
+    static final String TESTED_CLASS_SIGNATURE = 
+        CombinedEvents002Debuggee.TESTED_CLASS_SIGNATURE;
+    static final String TESTED_METHOD_NAME = CombinedEvents002Debuggee.TESTED_METHOD_NAME;
+
+    protected String getDebuggeeClassName() {
+        return CombinedEvents002Debuggee.class.getName();
+    }
+    
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(CombinedEvents002Test.class);
+    }
+    
+    /**
+     * This testcase is for METHOD_ENTRY, METHOD_EXIT events for empty method.
+     * <BR>It runs CombinedEvents002Debuggee that executed its own empty method 
+     * and verify that requested METHOD_ENTRY, METHOD_EXIT events occur
+     * for empty method.
+     */
+    public void testCombinedEvents002_01() {
+        logWriter.println("==> testCombinedEvents002_01: Start...");
+
+        logWriter.println("==> Wait for SGNL_READY signal from debuggee...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+        logWriter.println("==> OK - SGNL_READY signal received!");
+        
+        long testedClassID = 
+            debuggeeWrapper.vmMirror.getClassID(TESTED_CLASS_SIGNATURE);
+        if ( testedClassID == -1 ) {
+            String failureMessage = "## FAILURE: Can NOT get ClassID for '"
+                + TESTED_CLASS_SIGNATURE + "'";
+            printErrorAndFail(failureMessage);
+        }
+        logWriter.println("==> Tested Class Name = '" + TESTED_CLASS_NAME + "'");
+        logWriter.println("==> testedClassID = " + testedClassID);
+        
+        logWriter.println("==> ");
+        logWriter.println("==> Info for tested method '" + TESTED_METHOD_NAME + "':");
+        long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(testedClassID, TESTED_METHOD_NAME);
+        if (testedMethodID == -1 ) {
+            String failureMessage = "## FAILURE: Can NOT get MethodID for class '"
+                + TESTED_CLASS_NAME + "'; Method name = " + TESTED_METHOD_NAME;
+            printErrorAndFail(failureMessage);
+        }
+        logWriter.println("==> testedMethodID = " + testedMethodID);
+        printMethodLineTable(testedClassID, null, TESTED_METHOD_NAME);
+        long testedMethodStartCodeIndex = getMethodStartCodeIndex(testedClassID, TESTED_METHOD_NAME);
+        if ( testedMethodStartCodeIndex == -1 ) {
+            String failureMessage = "## FAILURE: Can NOT get MethodStartCodeIndex for method
'"
+                + TESTED_METHOD_NAME + "' ";
+            printErrorAndFail(failureMessage);
+        }
+        long testedMethodEndCodeIndex = getMethodEndCodeIndex(testedClassID, TESTED_METHOD_NAME);
+        if ( testedMethodEndCodeIndex == -1 ) {
+            String failureMessage = "## FAILURE: Can NOT get MethodEndCodeIndex for method
'"
+                + TESTED_METHOD_NAME + "' ";
+            printErrorAndFail(failureMessage);
+        }
+        boolean expectColocatedEvents = (testedMethodStartCodeIndex == testedMethodEndCodeIndex);
+
+        logWriter.println("==> ");
+        logWriter.println("==> Set request for METHOD_ENTRY event for '" + TESTED_CLASS_NAME
+ "'... ");
+        ReplyPacket reply = debuggeeWrapper.vmMirror.setMethodEntry(TESTED_CLASS_NAME);
+        checkReplyPacket(reply, "Set METHOD_ENTRY event.");  //DBG needless ?
+        logWriter.println("==> OK - request for METHOD_ENTRY event is set!");
+
+        logWriter.println("==> Set request for METHOD_EXIT event for '" + TESTED_CLASS_NAME
+ "'... ");
+        reply = debuggeeWrapper.vmMirror.setMethodExit(TESTED_CLASS_NAME);
+        checkReplyPacket(reply, "Set METHOD_EXIT event.");  //DBG needless ?
+        logWriter.println("==> OK - request for METHOD_EXIT event is set!");
+        
+        logWriter.println("==> Send SGNL_CONTINUE signal to debuggee...");
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+
+        logWriter.println("==> ");
+        logWriter.println("==> Receiving events... ");
+        CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent();
+        ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);
+        byte[] expectedEventKinds 
+            = {JDWPConstants.EventKind.METHOD_ENTRY, JDWPConstants.EventKind.METHOD_EXIT};
+        
+        int receivedEventsNumber = parsedEvents.length;
+        byte[] receivedEventKinds = new byte[(receivedEventsNumber==1)? 2 : receivedEventsNumber];
+        logWriter.println("==> Number of received events in event packet = " + receivedEventsNumber);
+        for (int i=0; i < receivedEventsNumber; i++) {
+            receivedEventKinds[i] = parsedEvents[i].getEventKind();
+            logWriter.println("==> Received event[" + i + "] kind = " 
+                +  receivedEventKinds[i]
+                + "(" + JDWPConstants.EventKind.getName(receivedEventKinds[i]) + ")");
+        }
+        if ( receivedEventsNumber > 2 ) {
+            String failureMessage = "## FAILURE: Unexpected number of received events in
packet = "
+                + receivedEventsNumber + "\n## Expected number of received events in packet
= 1 or 2";
+            printErrorAndFail(failureMessage);
+        }
+        
+        logWriter.println("==> ");
+        logWriter.println("==> Check received event #1...");
+        if ( receivedEventKinds[0] != expectedEventKinds[0] ) {
+            String failureMessage = "## FAILURE: Unexpected event is received: event kind
= "
+                + receivedEventKinds[0] + "("
+                + JDWPConstants.EventKind.getName(receivedEventKinds[0]) + ")"
+                + "\n## Expected event kind = " + expectedEventKinds[0] + "("
+                + JDWPConstants.EventKind.getName(expectedEventKinds[0]) + ")";
+            printErrorAndFail(failureMessage);
+        }
+        boolean testCaseIsOk = true;
+        Location location = ((ParsedEvent.Event_METHOD_ENTRY)parsedEvents[0]).getLocation();
+        long eventClassID = location.classID;
+        logWriter.println("==> ClassID in event = " + eventClassID);
+        if ( testedClassID != eventClassID ) {
+            logWriter.println("## FAILURE: Unexpected ClassID in event!");
+            logWriter.println("##          Expected ClassID (testedClassID) = " + testedClassID
);
+            testCaseIsOk = false;
+        } else {
+            logWriter.println("==> OK - it is expected ClassID (testedClassID)");
+        }
+        long eventMethodID = location.methodID;
+        logWriter.println("==> MethodID in event = " + eventMethodID);
+        if ( testedMethodID != eventMethodID ) {
+            logWriter.println("## FAILURE: Unexpected MethodID in event!");
+            logWriter.println("##          Expected MethodID (testedMethodID) = " + testedMethodID
);
+            testCaseIsOk = false;
+        } else {
+            logWriter.println("==> OK - it is expected MethodID (testedMethodID)");
+        }
+        long eventCodeIndex = location.index;
+        logWriter.println("==> CodeIndex in event = " + eventCodeIndex);
+        if ( testedMethodStartCodeIndex != eventCodeIndex ) {
+            logWriter.println("## FAILURE: Unexpected CodeIndex in event!");
+            logWriter.println("##          Expected CodeIndex (testedMethodStartCodeIndex)
= " 
+                + testedMethodStartCodeIndex );
+            testCaseIsOk = false;
+        } else {
+            logWriter.println("==> OK - it is expected CodeIndex (testedMethodStartCodeIndex)");
+        }
+
+        if ( receivedEventsNumber == 1 ) {
+            logWriter.println("==> ");
+            logWriter.println("==> Resume debuggee VM...");
+            debuggeeWrapper.vmMirror.resume();     
+            logWriter.println("==> Receiving events... ");
+            event = debuggeeWrapper.vmMirror.receiveEvent();
+            parsedEvents = ParsedEvent.parseEventPacket(event);
+            
+            receivedEventsNumber = parsedEvents.length;
+            logWriter.println("==> Number of received events in event packet = " + receivedEventsNumber);
+            receivedEventKinds[1] = parsedEvents[0].getEventKind();
+            for (int i=0; i < receivedEventsNumber; i++) {
+                logWriter.println("==> Received event[" + i + "] kind = " 
+                    +  parsedEvents[i].getEventKind()
+                    + "(" + JDWPConstants.EventKind.getName(parsedEvents[i].getEventKind())
+ ")");
+            }
+            if ( receivedEventsNumber != 1 ) {
+                String failureMessage = "## FAILURE: Unexpected number of received events
in packet = "
+                    + receivedEventsNumber + "\n## Expected number of received events in
packet = 1";
+                printErrorAndFail(failureMessage);
+            }
+        }
+        logWriter.println("==> ");
+        logWriter.println("==> Check received event #2...");
+        if ( receivedEventKinds[1] != expectedEventKinds[1] ) {
+            String failureMessage = "## FAILURE: Unexpected event is received: event kind
= "
+                + receivedEventKinds[1] + "("
+                + JDWPConstants.EventKind.getName(receivedEventKinds[1]) + ")"
+                + "\n## Expected event kind = " + expectedEventKinds[1] + "("
+                + JDWPConstants.EventKind.getName(expectedEventKinds[1]) + ")";
+            printErrorAndFail(failureMessage);
+        }
+        location = ((ParsedEvent.Event_METHOD_EXIT)parsedEvents[0]).getLocation();
+        eventClassID = location.classID;
+        logWriter.println("==> ClassID in event = " + eventClassID);
+        if ( testedClassID != eventClassID ) {
+            logWriter.println("## FAILURE: Unexpected ClassID in event!");
+            logWriter.println("##          Expected ClassID (testedClassID) = " + testedClassID
);
+            testCaseIsOk = false;
+        } else {
+            logWriter.println("==> OK - it is expected ClassID (testedClassID)");
+        }
+        eventMethodID = location.methodID;
+        logWriter.println("==> MethodID in event = " + eventMethodID);
+        if ( testedMethodID != eventMethodID ) {
+            logWriter.println("## FAILURE: Unexpected MethodID in event!");
+            logWriter.println("##          Expected MethodID (testedMethodID) = " + testedMethodID
);
+            testCaseIsOk = false;
+        } else {
+            logWriter.println("==> OK - it is expected MethodID (testedMethodID)");
+        }
+        eventCodeIndex = location.index;
+        logWriter.println("==> CodeIndex in event = " + eventCodeIndex);
+        if ( testedMethodEndCodeIndex != eventCodeIndex ) {
+            logWriter.println("## FAILURE: Unexpected CodeIndex in event!");
+            logWriter.println("##          Expected CodeIndex (testedMethodEndCodeIndex)
= " 
+                + testedMethodStartCodeIndex );
+            testCaseIsOk = false;
+        } else {
+            logWriter.println("==> OK - it is expected CodeIndex (testedMethodEndCodeIndex)");
+        }
+        if ( ! testCaseIsOk ) {
+            String failureMessage = "## FAILURE: Unexpected events attributes are found out!";
+            printErrorAndFail(failureMessage);
+        }
+        
+        logWriter.println("==> Resume debuggee VM...");
+        debuggeeWrapper.vmMirror.resume();     
+        logWriter.println("==> testCombinedEvents002_01: PASSED! ");
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents003Debuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents003Debuggee.java?view=auto&rev=559093
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents003Debuggee.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents003Debuggee.java
Tue Jul 24 09:20:30 2007
@@ -0,0 +1,40 @@
+/**
+ * @author Anatoly F. Bondarenko
+ * @version $Revision: 1.1 $
+ */
+
+/**
+ * Created on 26.10.2006
+ */
+package org.apache.harmony.jpda.tests.jdwp.Events;
+
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+
+
+/**
+ * Debuggee for JDWP unit tests for CombinedEvents.
+ */
+public class CombinedEvents003Debuggee extends SyncDebuggee {
+
+    public static void main(String[] args) {
+        runDebuggee(CombinedEvents003Debuggee.class);
+    }
+    
+    public void emptyMethod() {
+    }
+     
+    public void run() {
+        logWriter.println("-> CombinedEvents003Debuggee: Starting...");
+        
+        String mainThreadName = Thread.currentThread().getName();
+        synchronizer.sendMessage(mainThreadName);
+              
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        
+        emptyMethod();
+        
+        logWriter.println("-> CombinedEvents003Debuggee: Finishing...");
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents003Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents003Test.java?view=auto&rev=559093
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents003Test.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents003Test.java
Tue Jul 24 09:20:30 2007
@@ -0,0 +1,379 @@
+/**
+ * @author Anatoly F. Bondarenko
+ * @version $Revision: 1.1 $
+ */
+
+/**
+ * Created on 26.10.2006
+ */
+package org.apache.harmony.jpda.tests.jdwp.Events;
+
+import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.EventMod;
+import org.apache.harmony.jpda.tests.framework.jdwp.EventPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
+import org.apache.harmony.jpda.tests.framework.jdwp.Location;
+import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
+import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+/**
+ * JDWP Unit test for possible combined (co-located) events:
+ * METHOD_ENTRY, SINGLE_STEP, BREAKPOINT, METHOD_EXIT.
+ */
+public class CombinedEvents003Test extends CombinedEventsTestCase {
+
+    private String debuggeeSignature = 
+        "Lorg/apache/harmony/jpda/tests/jdwp/Events/CombinedEvents003Debuggee;";
+
+    private String methodForEvents = "emptyMethod";
+
+    private String methodEntryClassNameRegexp = 
+        "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEvents003Debuggee";
+    
+    private boolean eventVmDeathReceived = false;
+    private boolean eventMethodExitReceived = false;
+
+    protected String getDebuggeeClassName() {
+        return CombinedEvents003Debuggee.class.getName();
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(CombinedEvents003Test.class);
+    }
+
+    /**
+     * This test case checks events:
+     * METHOD_ENTRY, SINGLE_STEP, BREAKPOINT, METHOD_EXIT
+     * for empty method.
+     */
+
+    public void testCombinedEvents003_01() {
+        logWriter.println("==> testCombinedEvents003_01 started");
+
+        byte[] EXPECTED_EVENTS_ARRAY = { JDWPConstants.EventKind.METHOD_ENTRY,
+                JDWPConstants.EventKind.BREAKPOINT,
+                JDWPConstants.EventKind.SINGLE_STEP,
+                JDWPConstants.EventKind.METHOD_EXIT};
+        int EXPECTED_EVENTS_COUNT = EXPECTED_EVENTS_ARRAY.length;
+
+        String debuggeeMainThreadName = synchronizer.receiveMessage();
+
+        long debuggeeClassID = debuggeeWrapper.vmMirror
+                .getClassID(debuggeeSignature);
+        logWriter.println("=> debuggeeClassID = " + debuggeeClassID);
+        
+        long threadID = debuggeeWrapper.vmMirror.getThreadID(debuggeeMainThreadName);
+        logWriter.println("=> threadID = " + threadID);
+        
+        long runMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, "run");
+        logWriter.println("=> runMethodID = " + runMethodID);
+
+        long dummyMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, "dummyMethod");
+        logWriter.println("=> dummyMethodID = " + dummyMethodID);
+
+        logWriter.println("");
+        logWriter.println("=> Info for tested method '" + methodForEvents + "':");
+        long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, methodForEvents);
+        if (testedMethodID == -1 ) {
+            String failureMessage = "## FAILURE: Can NOT get MethodID for class '"
+                + getDebuggeeClassName() + "'; Method name = " + methodForEvents;
+            printErrorAndFail(failureMessage);
+        }
+        logWriter.println("=> testedMethodID = " + testedMethodID);
+        printMethodLineTable(debuggeeClassID, null, methodForEvents);
+        
+        // set requests for events that will be checked
+        logWriter.println("");
+        logWriter.println("=> Set request for BREAKPOINT event in debuggee: "
+                + getDebuggeeClassName() + ", beginning of method: "
+                + methodForEvents);
+        Location combinedEventsLocation = getMethodEntryLocation(debuggeeClassID, methodForEvents);
+        if ( combinedEventsLocation == null ) {
+            String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method
'"
+                + methodForEvents + "'";
+            printErrorAndFail(failureMessage);
+        }
+        ReplyPacket reply = debuggeeWrapper.vmMirror.setBreakpoint(combinedEventsLocation);
+        int breakpointRequestID = reply.getNextValueAsInt();
+        logWriter.println("=> Breakpoint requestID = " + breakpointRequestID);
+
+        logWriter.println("=> Set request for METHOD_ENTRY event in debuggee: "
+                + getDebuggeeClassName());
+        reply = debuggeeWrapper.vmMirror
+                .setMethodEntry(methodEntryClassNameRegexp);
+        checkReplyPacket(reply, "Set METHOD_ENTRY event");
+        int methodEntryRequestID = reply.getNextValueAsInt();
+        logWriter.println("=> METHOD_ENTRY requestID = " + methodEntryRequestID);
+        logWriter.println("=> Set request for METHOD_EXIT event in debuggee: "
+                + getDebuggeeClassName());
+        reply = debuggeeWrapper.vmMirror
+                .setMethodExit(methodEntryClassNameRegexp);
+        checkReplyPacket(reply, "Set METHOD_EXIT event");
+        int methodExitRequestID = reply.getNextValueAsInt();
+        logWriter.println("=> METHOD_EXIT requestID = " + methodExitRequestID);
+
+        logWriter.println("=> Set request for SINGLE_STEP event in class "
+                + debuggeeSignature);
+        CommandPacket setRequestCommand = new CommandPacket(
+                JDWPCommands.EventRequestCommandSet.CommandSetID,
+                JDWPCommands.EventRequestCommandSet.SetCommand);
+        setRequestCommand
+                .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP);
+        setRequestCommand.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
+        setRequestCommand.setNextValueAsInt(2);
+        setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step);
+        setRequestCommand.setNextValueAsThreadID(threadID);
+        setRequestCommand.setNextValueAsInt(JDWPConstants.StepSize.MIN);
+        setRequestCommand.setNextValueAsInt(JDWPConstants.StepDepth.INTO);
+        setRequestCommand.setNextValueAsByte(EventMod.ModKind.ClassOnly);
+        setRequestCommand.setNextValueAsReferenceTypeID(debuggeeClassID);
+
+        ReplyPacket setRequestReply = debuggeeWrapper.vmMirror
+                .performCommand(setRequestCommand);
+        checkReplyPacket(setRequestReply, "EventRequest::Set command");
+        int stepRequestID = setRequestReply.getNextValueAsInt();
+        logWriter.println("=> SINGLE_STEP requestID = " + stepRequestID);
+
+        logWriter.println("");
+        logWriter.println("=> Send SGNL_CONTINUE signal to debuggee...");
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+
+        logWriter.println("=> Try to receive and check combined events: "
+            + " METHOD_ENTRY, SINGLE_STEP, BREAKPOINT, METHOD_EXIT events; ignore single
SINGLE_STEP event");
+        receiveAndCheckEvents(EXPECTED_EVENTS_ARRAY, combinedEventsLocation);
+        if ( eventVmDeathReceived ) {
+            logWriter.println("==> testCombinedEvents001 is FINISHing as VM_DEATH is received!");
+            return;
+        }
+
+        logWriter.println("");
+        logWriter.println("=> Clean request for METHOD_ENTRY event...");
+        ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent(
+                JDWPConstants.EventKind.METHOD_ENTRY, methodEntryRequestID);
+        checkReplyPacket(clearReply, "EventRequest::Clear");
+
+        logWriter.println("");
+        logWriter.println("=> Clean request for SINGLE_STEP event...");
+        clearReply = debuggeeWrapper.vmMirror.clearEvent(
+                JDWPConstants.EventKind.SINGLE_STEP, stepRequestID);
+        checkReplyPacket(clearReply, "EventRequest::Clear");
+
+        logWriter.println("=> Resume debuggee");
+        debuggeeWrapper.vmMirror.resume();
+
+        // check that no other events, except VM_DEATH, will be received
+        checkVMDeathEvent();
+
+        logWriter.println("");
+        logWriter.println("==> testCombinedEvents003_01 PASSED");
+    }
+    
+    void receiveAndCheckEvents(byte[] EXPECTED_EVENTS_ARRAY, Location expectedLocation) {
+        int EXPECTED_EVENTS_COUNT = EXPECTED_EVENTS_ARRAY.length;
+        for (;;) {
+            logWriter.println("=>");
+            logWriter.println("=> Receiving events...");
+            EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
+            ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);
+
+            // print all received events
+            logWriter.println("=> Received event packet with events number = " + parsedEvents.length
+ " :");
+            
+            for (int i = 0; i < parsedEvents.length; i++) {
+                logWriter.println("");
+                logWriter.println("=> Event #" + (i+1) + " in packet -");
+                logWriter.println("=> EventKind: "
+                        + parsedEvents[i].getEventKind()
+                        + "["
+                        + JDWPConstants.EventKind.getName(parsedEvents[i]
+                                .getEventKind()) + "]");
+                logWriter.println("=> RequestID: "
+                        + parsedEvents[i].getRequestID());
+                if ( parsedEvents[i].getEventKind() == JDWPConstants.EventKind.VM_DEATH )
{
+                    eventVmDeathReceived = true;
+                }
+                if ( parsedEvents[i].getEventKind() == JDWPConstants.EventKind.METHOD_EXIT
) {
+                    eventMethodExitReceived = true;
+                }
+            }
+            if ( eventVmDeathReceived ) {
+                return;
+            }
+            checkEventsLocation(parsedEvents, null); // DBG__
+
+            // the following code checks received events
+            if (parsedEvents.length == 1) {
+                debuggeeWrapper.vmMirror.resume();
+                continue;
+/* DBG__                
+                if (parsedEvents[0].getEventKind() == JDWPConstants.EventKind.SINGLE_STEP)
{
+                    logWriter.println("");
+                    logWriter.println("=> Resume debuggee");
+                    logWriter.println("");
+                    debuggeeWrapper.vmMirror.resume();
+                    continue;
+                } else {
+                    logWriter.println("##FAILURE: received unexpected event: "
+                            + parsedEvents[0].getEventKind()
+                            + "["
+                            + JDWPConstants.EventKind.getName(parsedEvents[0]
+                                    .getEventKind())
+                            + "] instead of SINGLE_STEP");
+                    fail("received event is not SINGLE_STEP event: "
+                            + parsedEvents[0].getEventKind()
+                            + "["
+                            + JDWPConstants.EventKind.getName(parsedEvents[0]
+                                    .getEventKind()) + "]");
+                }
+// DBG__ */                
+            //DBG__} else if (parsedEvents.length == EXPECTED_EVENTS_COUNT) {
+            } else if (parsedEvents.length > 1) {
+                logWriter.println("");
+                logWriter
+                        .println("=> Combined events are received. Check events..");
+                boolean success = true;
+                for (int i = 0; i < parsedEvents.length; i++) {
+                    boolean isFound = false;
+                    for (int j = 0; j < EXPECTED_EVENTS_COUNT; j++) {
+                        if (parsedEvents[i].getEventKind() == EXPECTED_EVENTS_ARRAY[j]) {
+                            EXPECTED_EVENTS_ARRAY[j] = 0;
+                            isFound = true;
+                            break;
+                        }
+                    }
+                    if (!isFound) {
+                        logWriter.println("##FAILURE: received unexpected event: "
+                                        + parsedEvents[i].getEventKind()
+                                        + "["
+                                        + JDWPConstants.EventKind
+                                                .getName(parsedEvents[0]
+                                                        .getEventKind()) + "]");
+                        success = false;
+                    }
+                }
+                if (!success) {
+                    logWriter.println("");
+                    logWriter.println("##FAILURE: the following expected events were not
received: ");
+                    for (int k = 0; k < EXPECTED_EVENTS_COUNT; k++) {
+                        if (EXPECTED_EVENTS_ARRAY[k] != 0)
+                            logWriter.println("  #"
+                                    + k
+                                    + ": "
+                                    + EXPECTED_EVENTS_ARRAY[k]
+                                    + "["
+                                    + JDWPConstants.EventKind
+                                            .getName(EXPECTED_EVENTS_ARRAY[k])
+                                    + "]");
+                    }
+                    fail("not all expected events were received");
+                }
+                for (int i = 0; i < parsedEvents.length; i++) {
+                    byte eventKind = parsedEvents[i].getEventKind();
+                    long eventThreadID = ((ParsedEvent.EventThread)parsedEvents[i]).getThreadID();
+                    logWriter.println("");
+                    logWriter.println("=> Chcek location for combined event N " + (i+1)

+                        + ": Event kind = " + eventKind + "(" 
+                        + JDWPConstants.EventKind.getName(eventKind) +"); eventThreadID =
"
+                        + eventThreadID);
+                    Location eventLocation = null;
+                    switch ( eventKind ) {
+                    case JDWPConstants.EventKind.METHOD_ENTRY:
+                        eventLocation = ((ParsedEvent.Event_METHOD_ENTRY)parsedEvents[i]).getLocation();
+                        break;
+                    case JDWPConstants.EventKind.SINGLE_STEP:
+                        eventLocation = ((ParsedEvent.Event_SINGLE_STEP)parsedEvents[i]).getLocation();
+                        break;
+                    case JDWPConstants.EventKind.BREAKPOINT:
+                        eventLocation = ((ParsedEvent.Event_BREAKPOINT)parsedEvents[i]).getLocation();
+                        break;
+                    case JDWPConstants.EventKind.METHOD_EXIT:
+                        eventLocation = ((ParsedEvent.Event_METHOD_EXIT)parsedEvents[i]).getLocation();
+                        break;
+                    }
+                    long eventClassID = eventLocation.classID;
+                    logWriter.println("=> ClassID in event = " + eventClassID);
+                    if ( expectedLocation.classID != eventClassID ) {
+                        logWriter.println("## FAILURE: Unexpected ClassID in event!");
+                        logWriter.println("##          Expected ClassID  = " + expectedLocation.classID
);
+                        success = false;
+                    } else {
+                        logWriter.println("=> OK - it is expected ClassID");
+                    }
+                    long eventMethodID = eventLocation.methodID;
+                    logWriter.println("=> MethodID in event = " + eventMethodID);
+                    if ( expectedLocation.methodID != eventMethodID ) {
+                        logWriter.println("## FAILURE: Unexpected MethodID in event!");
+                        logWriter.println("##          Expected MethodID = " + expectedLocation.methodID);
+                        success = false;
+                    } else {
+                        logWriter.println("=> OK - it is expected MethodID");
+                    }
+                    long eventCodeIndex = eventLocation.index;
+                    logWriter.println("=> CodeIndex in event = " + eventCodeIndex);
+                    if ( expectedLocation.index != eventCodeIndex ) {
+                        logWriter.println("## FAILURE: Unexpected CodeIndex in event!");
+                        logWriter.println("##          Expected CodeIndex = " 
+                            + expectedLocation.index);
+                        success = false;
+                    } else {
+                        logWriter.println("=> OK - it is expected CodeIndex)");
+                    }
+                }
+                logWriter.println("");
+                if ( ! success ) {
+                    String failureMessage = "## FAILURE: Unexpected events' locations are
found out!";
+                    logWriter.println(failureMessage);
+                    //DBG__printErrorAndFail(failureMessage);
+                } else {
+                    logWriter.println("=> OK - all combined events have expected location!");
+                }
+                break;
+            } else {
+                logWriter.println("##FAILURE: received unexpected number of events: "
+                                + parsedEvents.length
+                                + " instead of 1 or "
+                                + EXPECTED_EVENTS_COUNT);
+                fail("received unexpected number of events: "
+                        + parsedEvents.length);
+            }
+        }
+    }
+
+    void checkVMDeathEvent() {
+        if ( eventVmDeathReceived ) {
+            return;
+        }
+        logWriter.println("=> Wait for VM_DEATH event...");
+        while ( true ) { //DBG_
+            logWriter.println("=> Receiving events...");
+            EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
+            ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);
+            if (parsedEvents.length != 1
+                    || parsedEvents[0].getEventKind() != JDWPConstants.EventKind.VM_DEATH)
{
+                // print all received events
+                logWriter.println("##FAILURE: Received unexpected events");
+                logWriter.println("=> Events received: " + parsedEvents.length);
+                for (int i = 0; i < parsedEvents.length; i++) {
+                    logWriter.println("");
+                    logWriter.println("=> Event #" + i + ";");
+                    logWriter.println("=> EventKind: "
+                            + parsedEvents[i].getEventKind()
+                            + "["
+                            + JDWPConstants.EventKind.getName(parsedEvents[i]
+                                    .getEventKind()) + "]");
+                    logWriter.println("=> RequestID: "
+                            + parsedEvents[i].getRequestID());
+                }
+                checkEventsLocation(parsedEvents, null); // DBG__
+                logWriter.println("=> Resume debuggee"); //DBG__
+                debuggeeWrapper.vmMirror.resume(); //DBG__
+                continue; //DBG__
+                //DBG__fail("unexpected events received");
+            }
+            logWriter.println("=> OK - VM_DEATH event was received. ");
+            break; //DBG__
+        } // DBG__
+    }
+}

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

Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEventsDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEventsDebuggee.java?view=auto&rev=559093
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEventsDebuggee.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/Events/CombinedEventsDebuggee.java
Tue Jul 24 09:20:30 2007
@@ -0,0 +1,55 @@
+/**
+ * @author Aleksander V. Budniy
+ * @version $Revision: 0.0 $
+ */
+
+/**
+ * Created on 25.05.2006
+ */
+package org.apache.harmony.jpda.tests.jdwp.Events;
+
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+
+
+/**
+ * Debuggee for JDWP unit tests for CombinedEvents.
+ * Calls it's own sampleMethod method.
+ */
+public class CombinedEventsDebuggee extends SyncDebuggee {
+    public static CombinedEventsDebuggee combinedEventsDebuggee = null;
+
+    public static void main(String[] args) {
+        runDebuggee(CombinedEventsDebuggee.class);
+    }
+    
+    public void sampleMethod() {
+        logWriter.println("-> CombinedEventsDebuggee: inside of sampleMethod()!");
+    }
+    
+       
+    public void run() {
+        logWriter.println("-> CombinedEventsDebuggee: Starting...");
+        combinedEventsDebuggee = this;
+        
+        //DBG synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+        String mainThreadName = Thread.currentThread().getName();
+        synchronizer.sendMessage(mainThreadName);
+              
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        
+        logWriter.println("-> CombinedEventsDebuggee: Before calling sampleMethod");
+        
+        sampleMethod();
+        // new CombinedEventsDebuggee_Extra().proxiMethod();
+        
+        logWriter.println("-> CombinedEventsDebuggee: Finishing...");
+    }
+}
+
+class CombinedEventsDebuggee_Extra {
+    public void proxiMethod() {
+        CombinedEventsDebuggee.combinedEventsDebuggee.sampleMethod();
+    }
+}

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



Mime
View raw message