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.3 $
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.JDWPCommands;
031: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
032: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
033: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
034: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
035: import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper;
036: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
037:
038: /**
039: * JDWP Unit test for verifying canceling of requested VM_DEATH event after re-connection.
040: */
041: public class VMDeathTest extends JDWPSyncTestCase {
042:
043: int requestID = 0;
044:
045: static final String DEBUGGEE_CLASS_NAME = "org.apache.harmony.jpda.tests.jdwp.Events.EventDebuggee";
046:
047: protected String getDebuggeeClassName() {
048: return DEBUGGEE_CLASS_NAME;
049: }
050:
051: /**
052: * This testcase verifies canceling of requested VM_DEATH event after re-connection.
053: * <BR>It runs EventDebuggee, sets request for VM_DEATH event
054: * and re-connects.
055: * <BR>It is expected that only auto VM_DEATH event occurs after re-connection,
056: * but no any other event, including requested VM_DEATH event.
057: */
058: public void testVMDeathRequest() {
059: logWriter.println("==> testVMDeathRequest started");
060: synchronizer
061: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
062:
063: //set request for VM_DEATH event with suspend policy SUSPEND_ALL
064: byte suspendPolicy = JDWPConstants.SuspendPolicy.ALL;
065: logWriter
066: .println("=> Create request for VM_DEATH event with suspend policy: "
067: + suspendPolicy
068: + "/"
069: + JDWPConstants.SuspendPolicy
070: .getName(suspendPolicy));
071: CommandPacket setRequestCommand = new CommandPacket(
072: JDWPCommands.EventRequestCommandSet.CommandSetID,
073: JDWPCommands.EventRequestCommandSet.SetCommand);
074:
075: setRequestCommand
076: .setNextValueAsByte(JDWPConstants.EventKind.VM_DEATH);
077: setRequestCommand
078: .setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
079: setRequestCommand.setNextValueAsInt(0);
080:
081: ReplyPacket setRequestReply = debuggeeWrapper.vmMirror
082: .performCommand(setRequestCommand);
083:
084: checkReplyPacket(setRequestReply, "Set VM_DEATH event");
085:
086: requestID = setRequestReply.getNextValueAsInt();
087: logWriter.println("=> RequestID = " + requestID);
088:
089: assertAllDataRead(setRequestReply);
090:
091: logWriter.println("");
092: logWriter.println("=> CLOSE CONNECTION");
093: closeConnection();
094: logWriter.println("=> CONNECTION IS CLOSED");
095:
096: logWriter.println("");
097: logWriter.println("=> OPEN NEW CONNECTION");
098: openConnection();
099: logWriter.println("=> CONNECTION IS OPENED");
100:
101: //release debuggee
102: synchronizer
103: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
104: synchronizer
105: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
106: //receive and parse event set
107: logWriter.println("=> Wait for event..");
108: CommandPacket eventPacket = debuggeeWrapper.vmMirror
109: .receiveEvent();
110: ParsedEvent[] parsedEvents = ParsedEvent
111: .parseEventPacket(eventPacket);
112: int eventsCount = parsedEvents.length;
113: logWriter
114: .println("=> Received event set: count=" + eventsCount);
115:
116: //ckeck if received events are expected
117: int result = 0;
118: int autoEvents = 0;
119: int wrongEvents = 0;
120: for (int i = 0; i < eventsCount; i++) {
121: ParsedEvent event = parsedEvents[i];
122: logWriter.println("=> Event #" + i + ";");
123:
124: // print event info
125: byte eventSuspendPolicy = event.getSuspendPolicy();
126: logWriter.println("=> SuspendPolicy="
127: + eventSuspendPolicy
128: + "/"
129: + JDWPConstants.SuspendPolicy
130: .getName(eventSuspendPolicy));
131: byte eventKind = event.getEventKind();
132: logWriter.println("=> EventKind=" + eventKind + "/"
133: + JDWPConstants.EventKind.getName(eventKind));
134: int eventRequestID = event.getRequestID();
135: logWriter.println("=> RequestID=" + eventRequestID);
136:
137: // check if event is expected
138: if (eventKind == JDWPConstants.EventKind.VM_DEATH) {
139: if (parsedEvents[i].getRequestID() == 0) {
140: autoEvents++;
141: logWriter.println("=> found auto VM_DEATH event!");
142: // for automatical event suspend policy can be changed
143: } else {
144: logWriter.println("## FAILURE: VM_DEATH event "
145: + "with unexpected RequestID: "
146: + eventRequestID);
147: result = 1;
148: }
149: } else {
150: wrongEvents++;
151: logWriter.println("## FAILURE: unexpected event kind: "
152: + eventKind);
153: result = 2;
154: }
155: }
156:
157: if (1 == result)
158: fail("VM_DEATH event with unexpected RequestID");
159: else if (2 == result)
160: fail("Unexpected event kind");
161:
162: logWriter.println("==> test PASSED!");
163: }
164:
165: protected void beforeDebuggeeStart(
166: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
167: settings.setAttachConnectorKind();
168: if (settings.getTransportAddress() == null) {
169: settings
170: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
171: }
172: logWriter.println("ATTACH connector kind");
173: super .beforeDebuggeeStart(debuggeeWrapper);
174: }
175:
176: public static void main(String[] args) {
177: junit.textui.TestRunner.run(VMDeathTest.class);
178:
179: }
180: }
|