Home | History | Annotate | Download | only in MultiSession
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  */
     18 
     19 /**
     20  * @author Aleksander V. Budniy
     21  */
     22 
     23 /**
     24  * Created on 8.7.2005
     25  */
     26 package org.apache.harmony.jpda.tests.jdwp.MultiSession;
     27 
     28 import org.apache.harmony.jpda.tests.framework.TestOptions;
     29 import org.apache.harmony.jpda.tests.framework.TestErrorException;
     30 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
     31 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
     32 import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
     33 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
     34 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     35 
     36 
     37 /**
     38  * JDWP Unit test for verifying canceling of some events after re-connection.
     39  */
     40 public class MethodEntryExitTest extends JDWPSyncTestCase {
     41 
     42     private String DEBUGGEE_SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/MultiSession/MultiSessionDebuggee;";
     43 
     44     private String METHOD_NAME = "printWord";
     45 
     46     String classNameRegexp = "org.apache.harmony.jpda.tests.jdwp.MultiSession.MultiSessionDebuggee";
     47 
     48     @Override
     49     protected String getDebuggeeClassName() {
     50         return "org.apache.harmony.jpda.tests.jdwp.MultiSession.MultiSessionDebuggee";
     51     }
     52 
     53     /**
     54      * This testcase verifies canceling of some events after re-connection.
     55      * <BR>It runs MultiSessionDebuggee, sets requests for BREAKPOINT, METHOD_ENTRY
     56      * and METHOD_EXIT events and then re-connects.
     57      * <BR>It is expected that no any events, including requested events, occur after re-connection
     58      * and before MultiSessionDebuggee finish.
     59      */
     60     public void testMethodEvent001() {
     61         logWriter.println("==> testMethodEvent001 started..");
     62 
     63         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     64 
     65         long classID = debuggeeWrapper.vmMirror.getClassID(DEBUGGEE_SIGNATURE);
     66 
     67         logWriter.println("=> Set breakpoint at method begin");
     68         //long requestID =
     69             debuggeeWrapper.vmMirror.setBreakpointAtMethodBegin(
     70                 classID, METHOD_NAME);
     71 
     72         logWriter.println("=> Set request for METHOD_ENTRY event");
     73         debuggeeWrapper.vmMirror
     74                 .setMethodEntry(classNameRegexp);
     75 
     76         logWriter.println("=> Set request for METHOD_EXIT event");
     77         debuggeeWrapper.vmMirror.setMethodExit(classNameRegexp);
     78 
     79         logWriter.println("");
     80         logWriter.println("=> CLOSE CONNECTION..");
     81         closeConnection();
     82         logWriter.println("=> CONNECTION CLOSED");
     83 
     84         logWriter.println("");
     85         logWriter.println("=> OPEN NEW CONNECTION..");
     86         openConnection();
     87         logWriter.println("=> CONNECTION OPENED");
     88 
     89         //resuming debuggee
     90         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     91         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     92         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     93 
     94         //      receive event
     95         logWriter.println("=> Wait for event..");
     96         CommandPacket event = null;
     97         try {
     98             event = debuggeeWrapper.vmMirror.receiveEvent();
     99         } catch (TestErrorException thrown) {
    100             logWriter.println("=> Exception while receiving event:" + thrown);
    101 
    102         }
    103         if (event == null) {
    104             logWriter.println("=> It's expected result, nothing was caught");
    105             logWriter.println("=> Resuming debuggee");
    106             //resuming debuggee
    107             synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    108             logWriter.println("==> testMethodEvent001 PASSED! ");
    109         } else {
    110 
    111             logWriter.println("##FAILURE: Event was received");
    112 
    113             try {
    114                 ParsedEvent[] parsedEvents = ParsedEvent
    115                         .parseEventPacket(event);
    116 
    117                 logWriter.println("=> Number of events = "
    118                         + parsedEvents.length);
    119                 for (int i = 0; i < parsedEvents.length; i++) {
    120                     logWriter.println("=> EventKind() = "
    121                             + parsedEvents[0].getEventKind()
    122                             + " ("
    123                             + JDWPConstants.EventKind.getName(parsedEvents[0]
    124                                     .getEventKind()) + ")");
    125                     logWriter.println("=> EventRequestID() = "
    126                             + parsedEvents[0].getRequestID());
    127 
    128                 }
    129             } catch (Throwable thrown) {
    130                 logWriter
    131                         .println("##FAILURE: Exception while analyzing received event:"
    132                                 + thrown);
    133                 fail("Exception while analyzing received event:" + thrown);
    134             }
    135 
    136             synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    137             synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    138             logWriter.println("==> testMethodEvent001 failed");
    139         }
    140     }
    141 
    142     @Override
    143     protected void beforeConnectionSetUp() {
    144         settings.setAttachConnectorKind();
    145         if(settings.getTransportAddress() == null) {
    146             settings.setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
    147         }
    148         logWriter.println("ATTACH connector kind");
    149         super.beforeConnectionSetUp();
    150     }
    151 }
    152