001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Aleksander V. Budniy
021: * @version $Revision: 1.7 $
022: */
023:
024: /**
025: * Created on 8.7.2005
026: */package org.apache.harmony.jpda.tests.jdwp.MultiSession;
027:
028: import org.apache.harmony.jpda.tests.framework.TestOptions;
029: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
030: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
032: import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper;
033: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for verifying canceling of FIELD_MODIFICATION event after re-connection.
037: */
038: public class FieldModificationTest extends JDWPEventTestCase {
039:
040: protected String getDebuggeeClassName() {
041: return FieldDebuggee.class.getName();
042: }
043:
044: /**
045: * This testcase verifies canceling of FIELD_MODIFICATION event after re-connection.
046: * <BR>It runs FieldDebuggee, sets request for FIELD_MODIFICATION event
047: * and re-connects.
048: * <BR>It is expected that only auto VM_DEATH event occurs after re-connection,
049: * but no any other event, including FIELD_MODIFICATION.
050: */
051: public void testFieldModification001() {
052:
053: logWriter.println("==> testFieldModification001 started");
054:
055: //check capability, relevant for this test
056: logWriter
057: .println("=> Check capability: canWatchFieldModification");
058: debuggeeWrapper.vmMirror.capabilities();
059: boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canWatchFieldModification;
060: if (!isCapability) {
061: logWriter
062: .println("##WARNING: this VM doesn't possess capability: canWatchFieldModification");
063: return;
064: }
065:
066: synchronizer
067: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
068:
069: String classSignature = "Lorg/apache/harmony/jpda/tests/jdwp/MultiSession/FieldDebuggee;";
070: debuggeeWrapper.vmMirror.setFieldModification(classSignature,
071: JDWPConstants.TypeTag.CLASS, "testIntField");
072:
073: logWriter.println("");
074: logWriter.println("=> CLOSE CONNECTION..");
075: closeConnection();
076: logWriter.println("=> CONNECTION CLOSED");
077:
078: logWriter.println("");
079: logWriter.println("=> OPEN NEW CONNECTION..");
080: openConnection();
081: logWriter.println("=> CONNECTION OPENED");
082:
083: logWriter.println("=> Resuming debuggee");
084:
085: // start the thread
086: synchronizer
087: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
088: synchronizer
089: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
090:
091: // receive event
092: logWriter.println("=> Wait for event..");
093: CommandPacket eventPacket = debuggeeWrapper.vmMirror
094: .receiveEvent();
095: ParsedEvent[] parsedEvents = ParsedEvent
096: .parseEventPacket(eventPacket);
097: int eventsCount = parsedEvents.length;
098: logWriter
099: .println("=> Received event set: count=" + eventsCount);
100:
101: //ckeck if received events are expected
102: int result = 0;
103: int autoEvents = 0;
104: int wrongEvents = 0;
105: for (int i = 0; i < eventsCount; i++) {
106: ParsedEvent event = parsedEvents[i];
107: logWriter.println("=> Event #" + i + ";");
108:
109: // print event info
110: byte eventSuspendPolicy = event.getSuspendPolicy();
111: logWriter.println("=> SuspendPolicy="
112: + eventSuspendPolicy
113: + "/"
114: + JDWPConstants.SuspendPolicy
115: .getName(eventSuspendPolicy));
116: byte eventKind = event.getEventKind();
117: logWriter.println("=> EventKind=" + eventKind + "/"
118: + JDWPConstants.EventKind.getName(eventKind));
119: int eventRequestID = event.getRequestID();
120: logWriter.println("=> RequestID=" + eventRequestID);
121:
122: // check if event is expected
123: if (eventKind == JDWPConstants.EventKind.VM_DEATH) {
124: if (parsedEvents[i].getRequestID() == 0) {
125: autoEvents++;
126: logWriter.println("=> found auto VM_DEATH event!");
127: // for automatical event suspend policy can be changed
128: } else {
129: logWriter.println("## FAILURE: VM_DEATH event "
130: + "with unexpected RequestID: "
131: + eventRequestID);
132: result = 1;
133: }
134: } else {
135: wrongEvents++;
136: logWriter.println("## FAILURE: unexpected event kind: "
137: + eventKind);
138: result = 2;
139: }
140: }
141:
142: if (1 == result)
143: fail("VM_DEATH event with unexpected RequestID");
144: else if (2 == result)
145: fail("Unexpected event kind");
146:
147: logWriter.println("==> testFieldModification001 PASSED!");
148: }
149:
150: protected void beforeDebuggeeStart(
151: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
152: settings.setAttachConnectorKind();
153: if (settings.getTransportAddress() == null) {
154: settings
155: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
156: }
157: logWriter.println("ATTACH connector kind");
158: super .beforeDebuggeeStart(debuggeeWrapper);
159: }
160:
161: public static void main(String[] args) {
162: junit.textui.TestRunner.run(FieldModificationTest.class);
163: }
164: }
|