Пример #1
0
 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__
 }
Пример #2
0
  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 (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);
      }
    }
  }
Пример #3
0
  /**
   * This testcase verifies canceling of THREAD_END event after re-connection. <br>
   * It runs EventDebuggee, sets request for THREAD_END event and re-connects. <br>
   * It is expected that no any events, including THREAD_END, occur after re-connection and before
   * EventDebuggee finish.
   */
  public void testThreadEnd001() {
    logWriter.println("==> testThreadEnd001 - STARTED...");

    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

    logWriter.println("=> set ThreadEndEvent...");
    ReplyPacket reply;
    byte eventKind = JDWPConstants.EventKind.THREAD_END;
    byte suspendPolicy = JDWPConstants.SuspendPolicy.NONE;
    EventMod[] mods = new EventMod[0];
    Event eventToSet = new Event(eventKind, suspendPolicy, mods);

    reply = debuggeeWrapper.vmMirror.setEvent(eventToSet);
    checkReplyPacket(reply, "Set THREAD_END event");

    logWriter.println("=> set ThreadEndEvent - DONE");

    logWriter.println("");
    logWriter.println("=> CLOSE CONNECTION");
    closeConnection();
    logWriter.println("=> CONNECTION CLOSED");

    logWriter.println("");
    logWriter.println("=> OPEN NEW CONNECTION");
    openConnection();
    logWriter.println("=> CONNECTION OPENED");

    logWriter.println("=> Resuming debuggee");

    // start the thread
    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    // wait for thread start and finish
    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

    logWriter.println("=> vmMirror.receiveEvent()...");
    CommandPacket event = null;
    try {
      event = debuggeeWrapper.vmMirror.receiveEvent();
    } catch (TestErrorException thrown) {
      logWriter.println("=> Exception while receiving event:" + thrown);
    }
    if (event == null) {
      logWriter.println("=> It's expected result, nothing was caught");
      logWriter.println("=> Resuming debuggee");
      // resuming debuggee
      synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
      logWriter.println("==> testThreadStart001 PASSED! ");
    } else {
      logWriter.println("##FAILURE: Event was received");
      try {
        ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event);
        logWriter.println("=> Number of events = " + parsedEvents.length);
        for (int i = 0; i < parsedEvents.length; i++) {
          logWriter.println(
              "=> EventKind() = "
                  + parsedEvents[0].getEventKind()
                  + " ("
                  + JDWPConstants.EventKind.getName(parsedEvents[0].getEventKind())
                  + ")");
          logWriter.println("=> EventRequestID() = " + parsedEvents[0].getRequestID());
        }
      } catch (Throwable thrown) {
        logWriter.println("##FAILURE: Exception while analyzing received event:" + thrown);
        fail("##FAILURE: Exception while analyzing received event:" + thrown);
      }

      synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
      logWriter.println("==> testThreadEnd001 PASSED");
    }
  }