Ejemplo n.º 1
0
  /**
   * This testcase exercises ObjectReference.IsCollected command. <br>
   * The test starts IsCollectedDebuggee class. Then attempts to know if an invalid objectID is
   * collected and checks no error is returned and result is true.
   */
  public void testIsCollected_invalid() {
    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

    CommandPacket command =
        new CommandPacket(
            JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
            JDWPCommands.ObjectReferenceCommandSet.IsCollectedCommand);
    command.setNextValueAsObjectID(JDWPTestConstants.INVALID_OBJECT_ID);

    ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(command);
    checkReplyPacket(reply, thisCommandName);
    boolean is_collected = reply.getNextValueAsBoolean();
    assertAllDataRead(reply);
    assertTrue("Invalid object id is assumed to be collected", is_collected);

    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
  }
Ejemplo n.º 2
0
  private void checkArrayRegion(
      ArrayRegion valuesRegion, long arrayID, int firstIndex, int length) {
    // set values
    CommandPacket packet =
        new CommandPacket(
            JDWPCommands.ArrayReferenceCommandSet.CommandSetID,
            JDWPCommands.ArrayReferenceCommandSet.SetValuesCommand);
    packet.setNextValueAsArrayID(arrayID);
    packet.setNextValueAsInt(firstIndex);
    packet.setNextValueAsInt(length);
    for (int i = 0; i < length; i++) {
      packet.setNextValueAsUntaggedValue(valuesRegion.getValue(i));
    }
    packet.setNextValueAsInt(length);

    ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
    checkReplyPacket(reply, "ArrayReference::SetValues command");

    // get values
    packet =
        new CommandPacket(
            JDWPCommands.ArrayReferenceCommandSet.CommandSetID,
            JDWPCommands.ArrayReferenceCommandSet.GetValuesCommand);
    packet.setNextValueAsArrayID(arrayID);
    packet.setNextValueAsInt(firstIndex);
    packet.setNextValueAsInt(length);
    reply = debuggeeWrapper.vmMirror.performCommand(packet);
    checkReplyPacket(reply, "ArrayReference::GetValues command");

    // do not check values for non-array fields
    ArrayRegion region = reply.getNextValueAsArrayRegion();
    assertEquals("Invalud returned array length,", length, region.getLength());
    for (int i = 0; i < region.getLength(); i++) {
      Value value = region.getValue(i);
      logWriter.println(value.toString());
      assertEquals(
          "ArrayReference::GetValues returned invalid value on index:<" + i + ">",
          value,
          valuesRegion.getValue(i));
    }
  }
Ejemplo n.º 3
0
  private void checkArrayValues(ArrayRegion valuesRegion, long classID, long fieldID) {
    CommandPacket packet =
        new CommandPacket(
            JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
            JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
    packet.setNextValueAsReferenceTypeID(classID);
    packet.setNextValueAsInt(1);
    packet.setNextValueAsFieldID(fieldID);

    ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
    checkReplyPacket(reply, "ReferenceType::GetValues command");

    assertEquals(
        "GetValuesCommand returned invalid number of values,", 1, reply.getNextValueAsInt());
    Value value = reply.getNextValueAsValue();
    // System.err.println("value="+value);
    long arrayID = value.getLongValue();
    int length = valuesRegion.getLength();

    checkArrayRegion(valuesRegion, arrayID, 0, length);
  }
Ejemplo n.º 4
0
  /**
   * This testcase exercises ArrayReference.SetValues command. <br>
   * Starts <A HREF="ArrayReferenceDebuggee.html">ArrayReferenceDebuggee</A>. <br>
   * Receives fields with ReferenceType.fields command, sets values with ArrayReference.SetValues
   * then checks changes.
   */
  public void testSetValues001() {
    logWriter.println("testLength001 started");
    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

    // obtain classID
    long classID =
        getClassIDBySignature(
            "Lorg/apache/harmony/jpda/tests/jdwp/ArrayReference/ArrayReferenceDebuggee;");

    // obtain fields
    CommandPacket packet =
        new CommandPacket(
            JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
            JDWPCommands.ReferenceTypeCommandSet.FieldsCommand);
    packet.setNextValueAsReferenceTypeID(classID);
    ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
    checkReplyPacket(reply, "ReferenceType::Fields command");

    int declared = reply.getNextValueAsInt();
    for (int i = 0; i < declared; i++) {
      long fieldID = reply.getNextValueAsFieldID();
      String name = reply.getNextValueAsString();
      reply.getNextValueAsString();
      reply.getNextValueAsInt();

      if (name.equals("intArray")) {
        ArrayRegion valuesRegion = new ArrayRegion(JDWPConstants.Tag.INT_TAG, 10);
        for (int j = 0; j < valuesRegion.getLength(); j++) {
          valuesRegion.setValue(j, new Value(-j));
        }
        checkArrayValues(valuesRegion, classID, fieldID);
      } else if (name.equals("longArray")) {
        ArrayRegion valuesRegion = new ArrayRegion(JDWPConstants.Tag.LONG_TAG, 10);
        for (int j = 0; j < valuesRegion.getLength(); j++) {
          valuesRegion.setValue(j, new Value((long) -j));
        }
        checkArrayValues(valuesRegion, classID, fieldID);
      } else if (name.equals("byteArray")) {
        ArrayRegion valuesRegion = new ArrayRegion(JDWPConstants.Tag.BYTE_TAG, 10);
        for (int j = 0; j < valuesRegion.getLength(); j++) {
          valuesRegion.setValue(j, new Value((byte) -j));
        }
        checkArrayValues(valuesRegion, classID, fieldID);
      }
    }

    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
  }
Ejemplo n.º 5
0
  /**
   * 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
    };

    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");
  }
  /**
   * This testcase exercises ThreadReference.Status command for the Thread waiting for time. <br>
   * At first the test starts Status003Debuggee which runs the tested thread and blocks it in
   * invocation of the 'Object.wait(mlsecTime)' method. <br>
   * Then the tests performs the ThreadReference.Status command for tested thread. <br>
   * It is expected that: <br>
   * &nbsp;&nbsp; - returned thread status is WAIT status; <br>
   * &nbsp;&nbsp; - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
   */
  public void testStatus004() {
    String thisTestName = "testStatus004";
    logWriter.println("==> " + thisTestName + " for ThreadReference.Status command: START...");
    logWriter.println(
        "==> This "
            + thisTestName
            + " checks command for TIMED_WAITING Thread: which is waiting in Object.wait(Time) method...");
    String checkedThreadName = synchronizer.receiveMessage();
    logWriter.println("=> checkedThreadName = " + checkedThreadName);

    long checkedThreadID = debuggeeWrapper.vmMirror.getThreadID(checkedThreadName);
    logWriter.println("=> checkedThreadID = " + checkedThreadID);

    logWriter.println(
        "=> Send ThreadReference.Status command for checked Thread and check reply...");
    CommandPacket checkedCommand =
        new CommandPacket(
            JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
            JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
    checkedCommand.setNextValueAsThreadID(checkedThreadID);

    ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
    checkReplyPacket(checkedReply, "ThreadReference.Status command");

    int threadStatus = checkedReply.getNextValueAsInt();
    int suspendStatus = checkedReply.getNextValueAsInt();

    logWriter.println(
        "\n=> Returned thread status = 0x"
            + Integer.toHexString(threadStatus)
            + "("
            + JDWPConstants.ThreadStatus.getName(threadStatus)
            + ")");
    if (threadStatus != JDWPConstants.ThreadStatus.WAIT) {
      finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
      printErrorAndFail(
          "Unexpected thread status is returned:"
              + "\nExpected thread status = 0x"
              + Integer.toHexString(JDWPConstants.ThreadStatus.WAIT)
              + "("
              + JDWPConstants.ThreadStatus.getName(JDWPConstants.ThreadStatus.WAIT)
              + ")");
    } else {
      logWriter.println("=> OK - Expected thread status is returned");
    }

    logWriter.println(
        "\n=> Returned thread suspend status = 0x"
            + Integer.toHexString(suspendStatus)
            + "("
            + getThreadSuspendStatusName(suspendStatus)
            + ")");
    if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
      finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
      printErrorAndFail(
          "Unexpected thread status is returned:"
              + "## Expected thread status = 0x"
              + Integer.toHexString(0)
              + "("
              + getThreadSuspendStatusName(0)
              + ")");
    } else {
      logWriter.println("=> OK - Expected thread suspend status is returned");
    }

    logWriter.println("=> Send to Debuggee signal to funish ...");
    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);

    logWriter.println("==> " + thisTestName + " for ThreadReference.Status command: FINISH...");
  }
Ejemplo n.º 7
0
  /**
   * This testcase exercises ThreadReference.SuspendCount command. <br>
   * At first the test starts SuspendCountDebuggee which starts and runs some tested threads. <br>
   * After the tested threads starts, the test suspends every tested thread in debuggee some times
   * and check that ThreadReference.SuspendCount command returns expected number of times thread was
   * suspended. <br>
   * Then the test suspends all debuggee by VirtualMachine.Suspend command and check that
   * ThreadReference.SuspendCount command returns 1 value for all tested threads and main thread.
   * <br>
   * Then the test resumes all debuggee by VirtualMachine.Resume command and check that
   * ThreadReference.SuspendCount command returns 0 value for all tested threads and main thread.
   */
  public void testSuspendCount001() {
    logWriter.println("==> testSuspendCount001: START...");
    String debuggeeMessage = synchronizer.receiveMessage();
    int testedThreadsNumber = 0;
    try {
      testedThreadsNumber = Integer.valueOf(debuggeeMessage).intValue();
    } catch (NumberFormatException exception) {
      logWriter.println(
          "## FAILURE: Exception while getting number of started threads from debuggee = "
              + exception);
      synchronizer.sendMessage("FINISH");
      printErrorAndFail("Can NOT get number of started threads from debuggee! ");
    }
    if (testedThreadsNumber == 0) {
      logWriter.println(
          "==>  There are no started threads in debuggee to test"
              + " - testSuspendCount001 finishes!");
      synchronizer.sendMessage("FINISH");
      return;
    }
    logWriter.println(
        "==>  Number of started threads in debuggee to test = " + testedThreadsNumber);
    String[] testedThreadsNames =
        new String[testedThreadsNumber + 1]; // +1 is for main debuggee thread
    long[] testedThreadsIDs = new long[testedThreadsNumber + 1];
    for (int i = 0; i < testedThreadsNumber; i++) {
      testedThreadsNames[i] = SuspendCountDebuggee.THREAD_NAME_PATTERN + i;
      testedThreadsIDs[i] = 0;
    }

    // getting ID of the tested thread
    ReplyPacket allThreadIDReply = null;
    try {
      allThreadIDReply = debuggeeWrapper.vmMirror.getAllThreadID();
    } catch (ReplyErrorCodeException exception) {
      logWriter.println("## FAILURE: Exception in vmMirror.getAllThreadID() = " + exception);
      synchronizer.sendMessage("FINISH");
      printErrorAndFail("Can NOT get all ThreadID in debuggee! ");
    }
    int threads = allThreadIDReply.getNextValueAsInt();
    logWriter.println("==>  Number of all threads in debuggee = " + threads);
    String[] allThreadsNames = new String[threads];
    long[] allThreadsIDs = new long[threads];
    boolean suspendCommandFailed = false;
    boolean suspendCountCommandFailed = false;
    boolean resumeCommandFailed = false;

    int suspendNumber = 0;
    for (int i = 0; i < threads; i++) {
      long threadID = allThreadIDReply.getNextValueAsThreadID();
      allThreadsIDs[i] = threadID;
      String threadName = null;
      try {
        threadName = debuggeeWrapper.vmMirror.getThreadName(threadID);
      } catch (ReplyErrorCodeException exception) {
        logWriter.println("==> WARNING: Can NOT get thread name for threadID = " + threadID);
        continue;
      }
      allThreadsNames[i] = threadName;
      int k = 0;
      for (; k < testedThreadsNumber; k++) {
        if (threadName.equals(testedThreadsNames[k])) {
          testedThreadsIDs[k] = threadID;
          break;
        }
      }
      if (k == testedThreadsNumber) {
        // it is not thread to test
        continue;
      }

      logWriter.println(
          "\n==> Check for Thread: threadID = " + threadID + "; threadName = " + threadName);

      logWriter.println("==> Send ThreadReference.SuspendCount command...");
      CommandPacket packet =
          new CommandPacket(
              JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
              JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
      packet.setNextValueAsThreadID(threadID);
      ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
      if (!checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command")) {
        suspendCountCommandFailed = true;
      } else {
        int suspendCount = reply.getNextValueAsInt();
        logWriter.println(
            "==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount);
        if (suspendCount != 0) {
          logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + threadName);
          logWriter.println("##          Expected suspendCount  = 0");
          suspendCountCommandFailed = true;
        }
      }

      suspendNumber++;
      logWriter.println(
          "==> Send ThreadReference.Suspend command number of times = " + suspendNumber + "...");
      int j = 0;
      for (; j < suspendNumber; j++) {
        packet =
            new CommandPacket(
                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
                JDWPCommands.ThreadReferenceCommandSet.SuspendCommand);
        packet.setNextValueAsThreadID(threadID);
        reply = debuggeeWrapper.vmMirror.performCommand(packet);
        if (!checkReplyPacketWithoutFail(reply, "ThreadReference.Suspend command")) {
          break;
        }
      }
      if (j < suspendNumber) {
        suspendCommandFailed = true;
        continue;
      }

      logWriter.println("==> Send ThreadReference.SuspendCount command...");
      packet =
          new CommandPacket(
              JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
              JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
      packet.setNextValueAsThreadID(threadID);
      reply = debuggeeWrapper.vmMirror.performCommand(packet);
      if (!checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command")) {
        suspendCountCommandFailed = true;
      } else {
        int suspendCount = reply.getNextValueAsInt();
        logWriter.println(
            "==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount);
        if (suspendCount != suspendNumber) {
          logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + threadName);
          logWriter.println("##          Expected suspendCount  = " + suspendNumber);
          suspendCountCommandFailed = true;
        }
      }

      logWriter.println("==> Send ThreadReference.Resume command...");
      packet =
          new CommandPacket(
              JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
              JDWPCommands.ThreadReferenceCommandSet.ResumeCommand);
      packet.setNextValueAsThreadID(threadID);
      reply = debuggeeWrapper.vmMirror.performCommand(packet);
      if (!checkReplyPacketWithoutFail(reply, "ThreadReference.Resume command")) {
        resumeCommandFailed = true;
      }

      logWriter.println("==> Send ThreadReference.SuspendCount command...");
      packet =
          new CommandPacket(
              JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
              JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
      packet.setNextValueAsThreadID(threadID);
      reply = debuggeeWrapper.vmMirror.performCommand(packet);
      if (!checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command")) {
        suspendCountCommandFailed = true;
      } else {
        int suspendCount = reply.getNextValueAsInt();
        logWriter.println(
            "==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount);
        if (suspendCount != (suspendNumber - 1)) {
          logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + threadName);
          logWriter.println("##          Expected suspendCount  = " + (suspendNumber - 1));
          suspendCountCommandFailed = true;
        }
      }

      if (suspendNumber == 1) {
        continue;
      }

      logWriter.println(
          "==> Send ThreadReference.Resume command number of times = "
              + (suspendNumber - 1)
              + "...");
      j = 0;
      for (; j < (suspendNumber - 1); j++) {
        packet =
            new CommandPacket(
                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
                JDWPCommands.ThreadReferenceCommandSet.ResumeCommand);
        packet.setNextValueAsThreadID(threadID);
        reply = debuggeeWrapper.vmMirror.performCommand(packet);
        if (!checkReplyPacketWithoutFail(reply, "ThreadReference.Resume command")) {
          break;
        }
      }
      if (j < (suspendNumber - 1)) {
        resumeCommandFailed = true;
        continue;
      }

      logWriter.println("==> Send ThreadReference.SuspendCount command...");
      packet =
          new CommandPacket(
              JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
              JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
      packet.setNextValueAsThreadID(threadID);
      reply = debuggeeWrapper.vmMirror.performCommand(packet);
      if (!checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command")) {
        suspendCountCommandFailed = true;
        continue;
      }
      int suspendCount = reply.getNextValueAsInt();
      logWriter.println(
          "==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount);
      if (suspendCount != 0) {
        logWriter.println("## FAILURE: Unexpected suspendCount for thread = " + threadName);
        logWriter.println("##          Expected suspendCount  = 0");
        suspendCountCommandFailed = true;
      }
    }

    String errorMessage = "";
    if (suspendCountCommandFailed) {
      errorMessage =
          errorMessage
              + "## Error found out while ThreadReference.SuspendCount command performing!\n";
    }
    if (suspendCommandFailed) {
      errorMessage =
          errorMessage + "## Error found out while ThreadReference.Suspend command performing!\n";
    }
    if (resumeCommandFailed) {
      errorMessage =
          errorMessage + "## Error found out while ThreadReference.Resume command performing!\n";
    }

    boolean testedThreadNotFound = false;
    for (int i = 0; i < testedThreadsNumber; i++) {
      if (testedThreadsIDs[i] == 0) {
        logWriter.println("## FAILURE: Tested thread is not found out among debuggee threads!");
        logWriter.println("##          Thread name = " + testedThreadsNames[i]);
        testedThreadNotFound = true;
      }
    }

    if (testedThreadNotFound) {
      errorMessage = errorMessage + "## Some of tested threads are not found!\n";
    }
    if (!errorMessage.equals("")) {
      synchronizer.sendMessage("FINISH");
      printErrorAndFail("\ntestSuspendCount001 FAILED:\n" + errorMessage);
    }

    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    logWriter.println(
        "\n==> Check ThreadReference.SuspendCount command when all debuggee is suspended...");
    testedThreadsNames[testedThreadsNumber] =
        synchronizer.receiveMessage(); // debuggee main thread name

    testedThreadsIDs[testedThreadsNumber] = 0; // debuggee main thread ID
    for (int i = 0; i < threads; i++) {
      if (testedThreadsNames[testedThreadsNumber].equals(allThreadsNames[i])) {
        testedThreadsIDs[testedThreadsNumber] = allThreadsIDs[i];
        break;
      }
    }
    if (testedThreadsIDs[testedThreadsNumber] == 0) {
      setStaticIntField(debuggeeSignature, SuspendCountDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
      logWriter.println(
          "## FAILURE: Debuggee main thread is not found out among debuggee threads!");
      logWriter.println("##          Thread name = " + testedThreadsNames[testedThreadsNumber]);
      printErrorAndFail("\nCan NOT found out debuggee main thread!");
    }

    logWriter.println("\n==> Send VirtualMachine.Suspend command...");
    CommandPacket packet =
        new CommandPacket(
            JDWPCommands.VirtualMachineCommandSet.CommandSetID,
            JDWPCommands.VirtualMachineCommandSet.SuspendCommand);
    ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
    int errorCode = reply.getErrorCode();
    if (errorCode != JDWPConstants.Error.NONE) {
      setStaticIntField(debuggeeSignature, SuspendCountDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
      logWriter.println(
          "## FAILURE: VirtualMachine.Suspend command returns error = "
              + errorCode
              + "("
              + JDWPConstants.Error.getName(errorCode)
              + ")");
      printErrorAndFail("\nVirtualMachine.Suspend command FAILED!");
    }

    for (int i = 0; i < (testedThreadsNumber + 1); i++) {
      logWriter.println(
          "==> Send ThreadReference.SuspendCount command for thread = "
              + testedThreadsNames[i]
              + " ...");
      packet =
          new CommandPacket(
              JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
              JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
      packet.setNextValueAsThreadID(testedThreadsIDs[i]);
      reply = debuggeeWrapper.vmMirror.performCommand(packet);
      if (!checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command")) {
        suspendCountCommandFailed = true;
        continue;
      }
      int suspendCount = reply.getNextValueAsInt();
      logWriter.println(
          "==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount);
      if (suspendCount != 1) {
        logWriter.println(
            "## FAILURE: Unexpected suspendCount for thread = " + testedThreadsNames[i]);
        logWriter.println("##          Expected suspendCount  = 1");
        suspendCountCommandFailed = true;
      }
    }

    logWriter.println("\n==> Send VirtualMachine.Resume command ...");
    packet =
        new CommandPacket(
            JDWPCommands.VirtualMachineCommandSet.CommandSetID,
            JDWPCommands.VirtualMachineCommandSet.ResumeCommand);
    reply = debuggeeWrapper.vmMirror.performCommand(packet);
    if (!checkReplyPacketWithoutFail(reply, "VirtualMachine.Resume command")) {
      resumeCommandFailed = true;
    } else {
      logWriter.println(
          "\n==> Check ThreadReference.SuspendCount command after debuggee is resumed...");
      for (int i = 0; i < (testedThreadsNumber + 1); i++) {
        logWriter.println(
            "==> Send ThreadReference.SuspendCount command for thread = "
                + testedThreadsNames[i]
                + " ...");
        packet =
            new CommandPacket(
                JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
                JDWPCommands.ThreadReferenceCommandSet.SuspendCountCommand);
        packet.setNextValueAsThreadID(testedThreadsIDs[i]);
        reply = debuggeeWrapper.vmMirror.performCommand(packet);
        if (!checkReplyPacketWithoutFail(reply, "ThreadReference.SuspendCount command")) {
          suspendCountCommandFailed = true;
          continue;
        }
        int suspendCount = reply.getNextValueAsInt();
        logWriter.println(
            "==> ThreadReference.SuspendCount command returns suspendCount = " + suspendCount);
        if (suspendCount != 0) {
          logWriter.println(
              "## FAILURE: Unexpected suspendCount for thread = " + testedThreadsNames[i]);
          logWriter.println("##          Expected suspendCount  = 0");
          suspendCountCommandFailed = true;
        }
      }
    }

    setStaticIntField(debuggeeSignature, SuspendCountDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);

    if (suspendCountCommandFailed) {
      errorMessage = "## Error found out while ThreadReference.SuspendCount command performing!\n";
    }

    if (resumeCommandFailed) {
      errorMessage = "## Error found out while VirtualMachine.Resume command performing!\n";
    }

    if (!errorMessage.equals("")) {
      printErrorAndFail("\ntestSuspendCount001 FAILED:\n" + errorMessage);
    }
    logWriter.println("\n==> testSuspendCount001 - OK!");
  }
Ejemplo n.º 8
0
  /**
   * This testcase exercises VirtualMachine.DisposeObjects command. <br>
   * At first the test starts HelloWorld debuggee. <br>
   * Then the test performs VirtualMachine.CreateString command for some string and checks that
   * VirtualMachine.DisposeObjects command for returned by CreateString command stringID with
   * refCount = 0 does not dispose that stringID - ObjectReference::ReferenceType command should
   * return some referenceTypeID without any error. <br>
   * Then the test check that repeated VirtualMachine.DisposeObjects command with refCount = 1
   * disposes that stringID - ObjectReference::ReferenceType command should return INVALID_OBJECT
   * error.
   */
  public void testDisposeObjects001() {
    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

    CommandPacket packet =
        new CommandPacket(
            JDWPCommands.VirtualMachineCommandSet.CommandSetID,
            JDWPCommands.VirtualMachineCommandSet.CreateStringCommand);
    packet.setNextValueAsString(CHECKED_STRING);
    logWriter.println("\tcreate string: " + CHECKED_STRING);
    ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);

    long stringID = reply.getNextValueAsStringID();
    logWriter.println("\tstring creared: stringID = " + stringID);

    logWriter.println(
        "\tsend DisposeObjects for created string with refCount = 0"
            + " - string should not be disposed...");
    packet =
        new CommandPacket(
            JDWPCommands.VirtualMachineCommandSet.CommandSetID,
            JDWPCommands.VirtualMachineCommandSet.DisposeObjectsCommand);
    packet.setNextValueAsInt(1);
    packet.setNextValueAsObjectID(stringID);
    packet.setNextValueAsInt(0);
    reply = debuggeeWrapper.vmMirror.performCommand(packet);
    checkReplyPacket(reply, "VirtualMachine::DisposeObjects command");

    logWriter.println(
        "\tsend ObjectReference::ReferenceType command for created string"
            + " to make sure that string is not disposed...");
    packet =
        new CommandPacket(
            JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
            JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand);
    packet.setNextValueAsObjectID(stringID);
    reply = debuggeeWrapper.vmMirror.performCommand(packet);
    checkReplyPacket(reply, "ObjectReference::ReferenceType command");

    byte refTypeTag = reply.getNextValueAsByte();
    long refTypeID = reply.getNextValueAsReferenceTypeID();
    logWriter.println(
        "\tReturned refTypeTag = "
            + refTypeTag
            + "("
            + JDWPConstants.TypeTag.getName(refTypeTag)
            + ")");
    logWriter.println("\tReturned ReferenceTypeID for string = " + refTypeID);

    logWriter.println(
        "\tsend DisposeObjects for created string with refCount = 1"
            + " - string should be disposed...");
    packet =
        new CommandPacket(
            JDWPCommands.VirtualMachineCommandSet.CommandSetID,
            JDWPCommands.VirtualMachineCommandSet.DisposeObjectsCommand);
    packet.setNextValueAsInt(1);
    packet.setNextValueAsObjectID(stringID);
    packet.setNextValueAsInt(1);
    reply = debuggeeWrapper.vmMirror.performCommand(packet);
    checkReplyPacket(reply, "VirtualMachine::DisposeObjects command");

    logWriter.println(
        "\tsend ObjectReference::ReferenceType command for disposed string"
            + " - INVALID_OBJECT should be...");
    packet =
        new CommandPacket(
            JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
            JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand);
    packet.setNextValueAsObjectID(stringID);
    reply = debuggeeWrapper.vmMirror.performCommand(packet);

    checkReplyPacket(
        reply, "ObjectReference::ReferenceType command", JDWPConstants.Error.INVALID_OBJECT);

    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
  }
Ejemplo n.º 9
0
  /**
   * The test checks ClassType.SetValues command for field of Debuggee class with value which has
   * other referenceType than field to set. The test expects the field should not be set.
   */
  public void testSetValues002() {
    String thisTestName = "testSetValues002";
    logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

    CommandPacket classesBySignatureCommand =
        new CommandPacket(
            JDWPCommands.VirtualMachineCommandSet.CommandSetID,
            JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
    classesBySignatureCommand.setNextValueAsString(debuggeeSignature);
    ReplyPacket classesBySignatureReply =
        debuggeeWrapper.vmMirror.performCommand(classesBySignatureCommand);
    classesBySignatureCommand = null;
    checkReplyPacket(classesBySignatureReply, "VirtualMachine::ClassesBySignature command");

    classesBySignatureReply.getNextValueAsInt();
    // Number of returned reference types - is NOt used here

    classesBySignatureReply.getNextValueAsByte();
    // refTypeTag of class - is NOt used here

    long refTypeID = classesBySignatureReply.getNextValueAsReferenceTypeID();
    classesBySignatureReply = null;

    logWriter.println("=> Debuggee class = " + getDebuggeeClassName());
    logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID);

    String checkedFieldNames[] = {
      "SetValues002DebuggeeObject", "objectField",
    };
    long checkedFieldIDs[] = checkFields(refTypeID, checkedFieldNames);
    int checkedFieldsNumber = checkedFieldNames.length;

    logWriter.println(
        "=> Send ReferenceType::GetValues command and get ObjectID for value to set...");

    CommandPacket getValuesCommand =
        new CommandPacket(
            JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
            JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
    getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
    getValuesCommand.setNextValueAsInt(1);
    getValuesCommand.setNextValueAsFieldID(checkedFieldIDs[0]);
    ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand);
    getValuesCommand = null;
    checkReplyPacket(getValuesReply, "ReferenceType::GetValues command");

    int returnedValuesNumber = getValuesReply.getNextValueAsInt();
    logWriter.println("=> Returned values number = " + returnedValuesNumber);
    assertEquals(
        "ReferenceType::GetValues returned invalid values number,", 1, returnedValuesNumber);

    Value objectFieldValueToSet = getValuesReply.getNextValueAsValue();
    byte objectFieldValueToSetTag = objectFieldValueToSet.getTag();
    logWriter.println(
        "=> Returned field value tag for checked object= "
            + objectFieldValueToSetTag
            + "("
            + JDWPConstants.Tag.getName(objectFieldValueToSetTag)
            + ")");
    assertEquals(
        "ReferenceType::GetValues returned invalid value tag,",
        JDWPConstants.Tag.OBJECT_TAG,
        objectFieldValueToSetTag,
        JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
        JDWPConstants.Tag.getName(objectFieldValueToSetTag));

    long objectFieldID = objectFieldValueToSet.getLongValue();
    logWriter.println("=> Returned ObjectID = " + objectFieldID);
    logWriter.println(
        "=> CHECK: send "
            + thisCommandName
            + " for Debuggee class with value which has other referenceType than field to set...");

    CommandPacket checkedCommand =
        new CommandPacket(
            JDWPCommands.ClassTypeCommandSet.CommandSetID,
            JDWPCommands.ClassTypeCommandSet.SetValuesCommand);
    checkedCommand.setNextValueAsClassID(refTypeID);
    checkedCommand.setNextValueAsInt(checkedFieldsNumber - 1);
    int fieldIndex = 1;
    for (; fieldIndex < checkedFieldsNumber; fieldIndex++) {
      checkedCommand.setNextValueAsFieldID(checkedFieldIDs[fieldIndex]);
      switch (fieldIndex) {
        case 1: // objectField
          checkedCommand.setNextValueAsObjectID(objectFieldID);
          break;
      }
    }
    ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
    checkedCommand = null;

    short errorCode = checkedReply.getErrorCode();
    if (errorCode == JDWPConstants.Error.NONE) {
      logWriter.println("=> " + thisCommandName + " run without any ERROR!");
    } else {
      logWriter.println(
          "=> "
              + thisCommandName
              + " returns ERROR = "
              + errorCode
              + "("
              + JDWPConstants.Error.getName(errorCode)
              + ")");
    }

    logWriter.println("=> Wait for Debuggee's status about check for set field...");
    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    boolean debuggeeStatus = synchronizer.receiveMessage("PASSED");
    if (!debuggeeStatus) {
      logWriter.println("## " + thisTestName + ": Debuggee returned status FAILED");
      fail("Debuggee returned status FAILED");
    } else {
      logWriter.println("=> " + thisTestName + ": Debuggee returned status PASSED");
    }

    logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": OK");
  }
  /**
   * This testcase exercises StackFrame.PopFrames command when thread is not suspended. <br>
   * The test starts PopFramesDebuggee class, sets a breakpoint in 'nestledMethod4', stops at
   * breakpoint and prints stack. <br>
   * Then the test performs ClassType.InvokeMethodCommand without waiting reply, and waits to ensure
   * that method was started. <br>
   * During working of method the test performs StackFrame.PopFrames command. Then the test checks
   * that StackFrame.PopFrames command returns error: THREAD_NOT_SUSPENDED or INVALID_FRAMEID. <br>
   * Next, the test receives reply from invoked method and resumes debuggee..
   */
  public void testPopFramesWithInvokeMethods() {
    logWriter.println("==> testPopFramesWithInvokeMethods started");

    // check capability, relevant for this test
    logWriter.println("=> Check capability: canPopFrames");
    debuggeeWrapper.vmMirror.capabilities();
    boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canPopFrames;
    if (!isCapability) {
      logWriter.println("##WARNING: this VM doesn't possess capability: canPopFrames");
      return;
    }
    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

    // find checked method
    long refTypeID = getClassIDBySignature(debuggeeSignature);

    logWriter.println("=> Debuggee class = " + getDebuggeeClassName());

    logWriter.println("=> Set breakpoint at the beginning of " + breakpointMethodName);
    long requestID =
        debuggeeWrapper.vmMirror.setBreakpointAtMethodBegin(refTypeID, breakpointMethodName);

    // release debuggee
    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);

    // receive event
    logWriter.println("=> Wait for breakpoint in " + breakpointMethodName);
    long breakpointThreadID = debuggeeWrapper.vmMirror.waitForBreakpoint(requestID);

    logWriter.println("=> breakpointThreadID = " + breakpointThreadID);

    // print stack frames
    logWriter.println("");
    logWriter.println("=> Get frames before PopFrames command, thread = " + breakpointThreadID);
    FrameInfo[] frameInfos = jdwpGetFrames(breakpointThreadID, 0, -1);
    printStackFrame(frameInfos.length, frameInfos);
    logWriter.println("=> Number of frames before command: " + frameInfos.length);

    // find frameID to pop
    logWriter.println("");
    logWriter.println("=> Find frameID of method = " + methodToPop + " for PopFrames command");
    long frameID = 0;
    long methodID = getMethodID(refTypeID, methodToPop);
    boolean isMethodFound = false;
    for (int j = 0; j < frameInfos.length; j++) {
      if (frameInfos[j].location.methodID == methodID) {
        frameID = frameInfos[j].getFrameID();
        isMethodFound = true;
        break;
      }
    }
    if (!isMethodFound) {
      logWriter.println("##FAILURE: there is no frame for checked method");
      fail("There is no frame for checked method");
    }

    logWriter.println("=> frameID for PopFrames command = " + frameID);

    // create JDWP command for MethodInvoke with a long running method
    long debuggeeRefTypeID = debuggeeWrapper.vmMirror.getClassID(debuggeeSignature);
    logWriter.println(
        "=> Find toInvokeMethodID for method: " + PopFramesDebuggee.METHOD_TO_INVOKE_NAME);
    long toInvokeMethodID =
        debuggeeWrapper.vmMirror.getMethodID(
            debuggeeRefTypeID, PopFramesDebuggee.METHOD_TO_INVOKE_NAME);
    if (toInvokeMethodID == -1) {
      logWriter.println(
          "## FAILURE: Can NOT get toInvokeMethodID for method: "
              + PopFramesDebuggee.METHOD_TO_INVOKE_NAME);
      fail("## Can NOT get toInvokeMethodID");
    }
    logWriter.println("=> toInvokeMethodID = " + toInvokeMethodID);

    int invokeCommandID = 0;
    CommandPacket invokeCommand =
        new CommandPacket(
            JDWPCommands.ClassTypeCommandSet.CommandSetID,
            JDWPCommands.ClassTypeCommandSet.InvokeMethodCommand);
    invokeCommand.setNextValueAsClassID(debuggeeRefTypeID);
    invokeCommand.setNextValueAsThreadID(breakpointThreadID);
    invokeCommand.setNextValueAsMethodID(toInvokeMethodID);
    invokeCommand.setNextValueAsInt(1); // args number
    invokeCommand.setNextValueAsValue(new Value(timeOfMethodInvocation));
    invokeCommand.setNextValueAsInt(JDWPConstants.InvokeOptions.INVOKE_SINGLE_THREADED);

    // send MethodInvoke command, but not wait for reply
    try {
      logWriter.println(
          "=> Send InvokeMethod command for method: " + PopFramesDebuggee.METHOD_TO_INVOKE_NAME);
      invokeCommandID = debuggeeWrapper.vmMirror.sendCommand(invokeCommand);
    } catch (Exception e) {
      logWriter.println("Exception during invokeCommand: " + e);
      throw new TestErrorException(e);
    }

    // wait to ensure that method invocation started
    logWriter.println("=> Wait " + timeoutToWait + " mls to ensure that method invocation started");
    Object waitObj = new Object();
    synchronized (waitObj) {
      try {
        waitObj.wait(timeoutToWait);
      } catch (InterruptedException e) {
        logWriter.println("##Exception while waiting on object: " + e);
        throw new TestErrorException(e);
      }
    }

    // perform PopFrame command
    logWriter.println(
        "=> Perform PopFrames command for method = "
            + methodToPop
            + " with frameID = "
            + frameID
            + " and expect errors");
    CommandPacket popFramesCommand =
        new CommandPacket(
            JDWPCommands.StackFrameCommandSet.CommandSetID,
            JDWPCommands.StackFrameCommandSet.PopFramesCommand);
    popFramesCommand.setNextValueAsThreadID(breakpointThreadID);
    popFramesCommand.setNextValueAsFrameID(frameID);

    ReplyPacket popFrameReply = debuggeeWrapper.vmMirror.performCommand(popFramesCommand);
    int res = popFrameReply.getErrorCode();
    logWriter.println(
        "=> Returned error code: " + res + " (" + JDWPConstants.Error.getName(res) + ")");

    // check that PopFrames returns error, because thread is resumed by
    // InvokeMethod
    if (res == JDWPConstants.Error.NONE) {
      logWriter.println("##PopFrames command returned no error for thread resumed by InvokeMethod");
      fail("##PopFrames command returned no error for thread resumed by InvokeMethod");
    }

    logWriter.println(
        "=> Receive reply of invoked method: " + PopFramesDebuggee.METHOD_TO_INVOKE_NAME);
    try {
      ReplyPacket reply = debuggeeWrapper.vmMirror.receiveReply(invokeCommandID);
      checkReplyPacket(reply, "ClassType::InvokeMethod command");
    } catch (Exception e) {
      logWriter.println("##Exception while receiving reply for invoke command: " + e);
      throw new TestErrorException(e);
    }

    logWriter.println("=> Resume debuggee");
    debuggeeWrapper.vmMirror.resume();

    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    logWriter.println("==> TEST testPopFramesWithInvokeMethods PASSED");
  }
Ejemplo n.º 11
0
  /**
   * This testcase exercises ReferenceType.Modifiers command. <br>
   * The test starts HelloWorld debuggee, requests referenceTypeId for it by
   * VirtualMachine.ClassesBySignature command, then performs ReferenceType.Modifiers command and
   * checks that returned Modifiers contain expected flags: ACC_PUBLIC, ACC_SUPER; but do NOT
   * contain flags: ACC_FINAL, ACC_INTERFACE, ACC_ABSTRACT
   */
  public void testModifiers001() {
    String thisTestName = "testModifiers001";
    logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
    String failMessage = "";
    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);

    long refTypeID = getClassIDBySignature(debuggeeSignature);

    logWriter.println("=> Debuggee class = " + getDebuggeeClassName());
    logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID);
    logWriter.println("=> CHECK1: send " + thisCommandName + " and check reply...");

    CommandPacket modifiersCommand =
        new CommandPacket(
            JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
            JDWPCommands.ReferenceTypeCommandSet.ModifiersCommand);
    modifiersCommand.setNextValueAsReferenceTypeID(refTypeID);

    ReplyPacket modifiersReply = debuggeeWrapper.vmMirror.performCommand(modifiersCommand);
    modifiersCommand = null;
    checkReplyPacket(modifiersReply, thisCommandName);

    int returnedModifiers = modifiersReply.getNextValueAsInt();
    /*
     * The value of the access_flags item is a mask of modifiers used with class and
     * interface declarations. The access_flags modifiers are:
     * Flag Name      Value   Meaning                                               Used By
     * ACC_PUBLIC     0x0001  Is public; may be accessed from outside its package.  Class, interface
     * ACC_FINAL      0x0010  Is final; no subclasses allowed.                      Class
     * ACC_SUPER      0x0020  Treat superclass methods specially in invokespecial.  Class, interface
     * ACC_INTERFACE  0x0200  Is an interface.                                      Interface
     * ACC_ABSTRACT   0x0400  Is abstract; may not be instantiated.                 Class, interface
     */
    logWriter.println("=> Returned modifiers = 0x" + Integer.toHexString(returnedModifiers));

    int publicFlag = 0x0001; // expected
    int finalFlag = 0x0010; // unexpected
    int superFlag = 0x0020; // expected
    int interfaceFlag = 0x0200; // unexpected
    int abstractFlag = 0x0400; // unexpected

    if ((returnedModifiers & publicFlag) == 0) {
      logWriter.println(
          "## CHECK1: FAILURE: Returned modifiers do NOT contain expected ACC_PUBLIC flag(0x0001)");
      failMessage =
          failMessage + "Returned modifiers do NOT contain expected ACC_PUBLIC flag(0x0001);\n";
    }
    if ((returnedModifiers & superFlag) == 0) {
      logWriter.println(
          "## CHECK1: FAILURE: Returned modifiers do NOT contain expected ACC_SUPER flag(0x0020)");
      failMessage =
          failMessage + "Returned modifiers do NOT contain expected ACC_SUPER flag(0x0020);\n";
    }
    if ((returnedModifiers & finalFlag) != 0) {
      logWriter.println(
          "## CHECK1: FAILURE: Returned modifiers contain unexpected ACC_FINAL flag(0x0010)");
      failMessage = failMessage + "Returned modifiers contain unexpected ACC_FINAL flag(0x0010);\n";
    }
    if ((returnedModifiers & interfaceFlag) != 0) {
      logWriter.println(
          "## CHECK1: FAILURE: Returned modifiers contain unexpected ACC_INTERFACE flag(0x0200)");
      failMessage =
          failMessage + "Returned modifiers contain unexpected ACC_INTERFACE flag(0x0200);\n";
    }
    if ((returnedModifiers & abstractFlag) != 0) {
      logWriter.println(
          "## CHECK1: FAILURE: Returned modifiers contain unexpected ACC_ABSTRACT flag(0x0400)");
      failMessage =
          failMessage + "Returned modifiers contain unexpected ACC_ABSTRACT flag(0x0400);\n";
    }

    logWriter.println(
        "=> CHECK1: PASSED: expected modifiers are returned: ACC_PUBLIC flag(0x0001), ACC_SUPER flag(0x0020)");
    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH");

    if (failMessage.length() > 0) {
      fail(failMessage);
    }

    assertAllDataRead(modifiersReply);
  }
Ejemplo n.º 12
0
  /**
   * This test exercises ObjectReference.IsCollected command. <br>
   * The test starts IsCollectedDebuggee class, gets two objectIDs as value of static fields of this
   * class which (fields) represent two checked objects. Then for the first objectID test executes
   * ObjectReference.DisableCollection command. After that Debuggee tries to unload checked objects.
   * Then the test executes ObjectReference.IsCollected commands for both checked objects and checks
   * replies.
   */
  public void testIsCollected001() {
    String thisTestName = "testIsCollected001";
    logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
    String failMessage = "";
    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
    finalSyncMessage = "TO_FINISH";

    long refTypeID = getClassIDBySignature(debuggeeSignature);

    logWriter.println("=> Debuggee class = " + getDebuggeeClassName());
    logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID);

    String checkedFieldNames[] = {
      "checkedObject_01", "checkedObject_02",
    };
    long checkedFieldIDs[] = checkFields(refTypeID, checkedFieldNames);
    long checkedField_01ID = checkedFieldIDs[0];
    long checkedField_02ID = checkedFieldIDs[1];

    logWriter.println(
        "=> Send ReferenceType::GetValues command for received fieldIDs and get ObjectIDs to check...");

    CommandPacket getValuesCommand =
        new CommandPacket(
            JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
            JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
    getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
    getValuesCommand.setNextValueAsInt(2);
    getValuesCommand.setNextValueAsFieldID(checkedField_01ID);
    getValuesCommand.setNextValueAsFieldID(checkedField_02ID);

    ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand);
    getValuesCommand = null;
    checkReplyPacket(getValuesReply, "ReferenceType::GetValues command");

    int returnedValuesNumber = getValuesReply.getNextValueAsInt();
    logWriter.println("=> Returned values number = " + returnedValuesNumber);
    assertEquals("Invalid number of values,", 2, returnedValuesNumber);

    Value checkedObjectFieldValue = getValuesReply.getNextValueAsValue();
    byte checkedObjectFieldTag = checkedObjectFieldValue.getTag();
    logWriter.println(
        "=> Returned field value tag for checkedObject_01 = "
            + checkedObjectFieldTag
            + "("
            + JDWPConstants.Tag.getName(checkedObjectFieldTag)
            + ")");
    assertEquals(
        "Invalid value tag for checkedObject_01",
        JDWPConstants.Tag.OBJECT_TAG,
        checkedObjectFieldTag,
        JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
        JDWPConstants.Tag.getName(checkedObjectFieldTag));

    long checkedObject_01ID = checkedObjectFieldValue.getLongValue();
    logWriter.println("=> Returned ObjectID for checkedObject_01 = " + checkedObject_01ID);

    checkedObjectFieldValue = getValuesReply.getNextValueAsValue();
    checkedObjectFieldTag = checkedObjectFieldValue.getTag();
    logWriter.println(
        "=> Returned field value tag for checkedObject_02 = "
            + checkedObjectFieldTag
            + "("
            + JDWPConstants.Tag.getName(checkedObjectFieldTag)
            + ")");
    assertEquals(
        "Invalid value tag for checkedObject_02",
        JDWPConstants.Tag.OBJECT_TAG,
        checkedObjectFieldTag,
        JDWPConstants.Tag.getName(JDWPConstants.Tag.OBJECT_TAG),
        JDWPConstants.Tag.getName(checkedObjectFieldTag));

    long checkedObject_02ID = checkedObjectFieldValue.getLongValue();
    logWriter.println("=> Returned ObjectID for checkedObject_02 = " + checkedObject_02ID);

    logWriter.println(
        "\n=> Send ObjectReference::DisableCollection command for checkedObject_01...");

    CommandPacket disableCollectionCommand =
        new CommandPacket(
            JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
            JDWPCommands.ObjectReferenceCommandSet.DisableCollectionCommand);
    disableCollectionCommand.setNextValueAsObjectID(checkedObject_01ID);

    ReplyPacket disableCollectionReply =
        debuggeeWrapper.vmMirror.performCommand(disableCollectionCommand);
    disableCollectionCommand = null;
    checkReplyPacket(disableCollectionReply, "ObjectReference::DisableCollection command");

    logWriter.println(
        "=> Send to Debuggee signal to continue and try to unload checked objects...");
    finalSyncMessage = null;
    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    String messageFromDebuggee = synchronizer.receiveMessage();
    logWriter.println("\n=> Received message from Debuggee = \"" + messageFromDebuggee + "\"");

    logWriter.println("\n=> Send " + thisCommandName + " for checkedObject_01 and check reply...");

    CommandPacket checkedCommand =
        new CommandPacket(
            JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
            JDWPCommands.ObjectReferenceCommandSet.IsCollectedCommand);
    checkedCommand.setNextValueAsObjectID(checkedObject_01ID);

    ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
    checkedCommand = null;
    checkReplyPacket(checkedReply, thisCommandName);

    boolean checkedObject_01_IsCollected = checkedReply.getNextValueAsBoolean();
    logWriter.println("=> IsCollected for checkedObject_01 = " + checkedObject_01_IsCollected);

    if (messageFromDebuggee.indexOf("checkedObject_01 is UNLOADed;") != -1) {
      if (!checkedObject_01_IsCollected) {
        logWriter.println(
            "## FAILURE: Unexpected result for checkedObject_01 of " + thisCommandName + ":");
        logWriter.println("## checkedObject_01 is UNLOADed so IsCollected must be 'true'");
        failMessage =
            failMessage + "Unexpected result for checkedObject_01 of " + thisCommandName + "\n";
      }
    } else {
      if (checkedObject_01_IsCollected) {
        logWriter.println(
            "## FAILURE: Unexpected result for checkedObject_01 of " + thisCommandName + ":");
        logWriter.println("## checkedObject_01 is NOT UNLOADed so IsCollected must be 'false'");
        failMessage =
            failMessage + "Unexpected result for checkedObject_01 of " + thisCommandName + "\n";
      }
    }

    logWriter.println("=> PASSED for checkedObject_01");

    logWriter.println("\n=> Send " + thisCommandName + " for checkedObject_02 and check reply...");

    checkedCommand =
        new CommandPacket(
            JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
            JDWPCommands.ObjectReferenceCommandSet.IsCollectedCommand);
    checkedCommand.setNextValueAsObjectID(checkedObject_02ID);

    checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
    checkedCommand = null;
    checkReplyPacket(checkedReply, thisCommandName);

    boolean checkedObject_02_IsCollected = checkedReply.getNextValueAsBoolean();
    logWriter.println("=> IsCollected for checkedObject_02 = " + checkedObject_02_IsCollected);

    if (messageFromDebuggee.indexOf("checkedObject_02 is UNLOADed;") != -1) {
      if (!checkedObject_02_IsCollected) {
        logWriter.println(
            "## FAILURE: Unexpected result for checkedObject_02 of " + thisCommandName + ":");
        logWriter.println("## checkedObject_02 is UNLOADed so IsCollected must be 'true'");
        failMessage =
            failMessage + "Unexpected result for checkedObject_02 of " + thisCommandName + "\n";
      }
    } else {
      if (checkedObject_02_IsCollected) {
        logWriter.println(
            "## FAILURE: Unexpected result for checkedObject_02 of " + thisCommandName + ":");
        logWriter.println("## checkedObject_02 is NOT UNLOADed so IsCollected must be 'false'");
        failMessage =
            failMessage + "Unexpected result for checkedObject_02 of " + thisCommandName + "\n";
      }
    }

    logWriter.println("=> PASSED for checkedObject_02");
    logWriter.println("=> Send to Debuggee signal to funish ...");
    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH");

    if (failMessage.length() > 0) {
      fail(failMessage);
    }

    assertAllDataRead(checkedReply);
  }