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.4 $
022: */
023:
024: /**
025: * Created on 14.07.2005
026: */package org.apache.harmony.jpda.tests.jdwp.Events;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
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.framework.jdwp.ReplyPacket;
033: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
034: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
035:
036: /**
037: * JDWP Unit test for requested VM_DEATH event.
038: */
039:
040: public class VMDeath002Test extends JDWPSyncTestCase {
041:
042: int requestID = 0;
043:
044: static String DEBUGGEE_CLASS_NAME = "org.apache.harmony.jpda.tests.jdwp.Events.EventDebuggee";
045:
046: protected String getDebuggeeClassName() {
047: return DEBUGGEE_CLASS_NAME;
048: }
049:
050: /**
051: * This testcase is for requested VM_DEATH event.<BR>
052: * It starts EventDebuggee class, send request for
053: * VM_DEATH event, receives events and verifies that:
054: * <BR> - requested VM_DEATH event
055: * is received with the expected RequestID, returned by EventRequest.Set command;
056: * <BR> - automatic VM_DEATH event
057: * is received with the RequestID = 0;
058: */
059: public void testVMDeathRequest() {
060: logWriter.println("==> testVMDeathRequest started");
061:
062: //check capability, relevant for this test
063: logWriter
064: .println("=> Check capability: canRequestVMDeathEvent");
065: debuggeeWrapper.vmMirror.capabilities();
066: boolean isCapability = debuggeeWrapper.vmMirror.targetVMCapabilities.canRequestVMDeathEvent;
067: if (!isCapability) {
068: logWriter
069: .println("##WARNING: this VM doesn't possess capability: canRequestVMDeathEvent");
070: return;
071: }
072: boolean success = true;
073:
074: synchronizer
075: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
076:
077: //set request for VM_DEATH event with suspend policy SUSPEND_ALL
078: byte suspendPolicy = JDWPConstants.SuspendPolicy.ALL;
079: logWriter
080: .println("=> Create request for VM_DEATH event with suspend policy: "
081: + suspendPolicy
082: + "/"
083: + JDWPConstants.SuspendPolicy
084: .getName(suspendPolicy));
085: CommandPacket setRequestCommand = new CommandPacket(
086: JDWPCommands.EventRequestCommandSet.CommandSetID,
087: JDWPCommands.EventRequestCommandSet.SetCommand);
088:
089: setRequestCommand
090: .setNextValueAsByte(JDWPConstants.EventKind.VM_DEATH);
091: setRequestCommand
092: .setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
093: setRequestCommand.setNextValueAsInt(0);
094:
095: ReplyPacket setRequestReply = debuggeeWrapper.vmMirror
096: .performCommand(setRequestCommand);
097: checkReplyPacket(setRequestReply, "Set VM_DEATH event");
098:
099: requestID = setRequestReply.getNextValueAsInt();
100: logWriter.println("==> RequestID = " + requestID);
101:
102: assertAllDataRead(setRequestReply);
103:
104: //release debuggee
105: synchronizer
106: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
107: synchronizer
108: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
109:
110: //receive and parse event set
111: logWriter.println("=> Wait for VM_DEATH event");
112: CommandPacket eventPacket = debuggeeWrapper.vmMirror
113: .receiveEvent();
114: ParsedEvent[] parsedEvents = ParsedEvent
115: .parseEventPacket(eventPacket);
116: int eventsCount = parsedEvents.length;
117: logWriter.println("==> Received event set: count="
118: + eventsCount);
119:
120: //ckeck if received events are expected
121: int requestedEvents = 0;
122: int autoEvents = 0;
123: int wrongEvents = 0;
124: for (int i = 0; i < eventsCount; i++) {
125: ParsedEvent event = parsedEvents[i];
126: logWriter.println("=> Event #" + i + ";");
127:
128: // print event info
129: byte eventSuspendPolicy = event.getSuspendPolicy();
130: logWriter.println("===> SuspendPolicy="
131: + eventSuspendPolicy
132: + "/"
133: + JDWPConstants.SuspendPolicy
134: .getName(eventSuspendPolicy));
135: byte eventKind = event.getEventKind();
136: logWriter.println("===> EventKind=" + eventKind + "/"
137: + JDWPConstants.EventKind.getName(eventKind));
138: int eventRequestID = event.getRequestID();
139: logWriter.println("===> RequestID=" + eventRequestID);
140:
141: // check if event is expected
142: if (eventKind == JDWPConstants.EventKind.VM_DEATH) {
143: if (eventRequestID == requestID) {
144: requestedEvents++;
145: logWriter
146: .println("===> found requested VM_DEATH event!");
147:
148: // check suspend p[olicy for requested event
149: if (eventSuspendPolicy != suspendPolicy) {
150: logWriter
151: .println("## FAILURE: requested VM_DEATH event "
152: + "with unexpected SuspendPolicy: "
153: + eventSuspendPolicy);
154: success = false;
155: }
156: } else if (parsedEvents[i].getRequestID() == 0) {
157: autoEvents++;
158: logWriter
159: .println("===> found auto VM_DEATH event!");
160: // for automatical event suspend policy can be changed
161: } else {
162: logWriter.println("## FAILURE: VM_DEATH event "
163: + "with unexpected RequestID: "
164: + eventRequestID);
165: success = false;
166: }
167: } else {
168: wrongEvents++;
169: logWriter.println("## FAILURE: unexpected event kind: "
170: + eventKind);
171: success = false;
172: }
173: }
174:
175: // check number of found events
176: {
177: if (eventsCount != 2) {
178: logWriter
179: .println("## FAILURE: received wrong number of events: "
180: + eventsCount);
181: success = false;
182: }
183:
184: if (requestedEvents > 1) {
185: logWriter
186: .println("## FAILURE: too many requested VM_DEATH events: "
187: + requestedEvents);
188: success = false;
189: } else if (requestedEvents < 1) {
190: logWriter
191: .println("## FAILURE: received no requested VM_DEATH events: "
192: + requestedEvents);
193: success = false;
194: }
195:
196: if (autoEvents > 1) {
197: logWriter
198: .println("## FAILURE: too many auto VM_DEATH events: "
199: + autoEvents);
200: success = false;
201: } else if (autoEvents < 1) {
202: logWriter
203: .println("## FAILURE: received no auto VM_DEATH events: "
204: + autoEvents);
205: success = false;
206: }
207:
208: if (wrongEvents > 0) {
209: logWriter
210: .println("## FAILURE: Received unexpected events: "
211: + wrongEvents);
212: success = false;
213: }
214:
215: assertTrue("Failure in processing VM_DEATH event", success);
216: }
217:
218: logWriter.println("=> Resume debuggee");
219: resumeDebuggee();
220:
221: logWriter.println("==> test PASSED!");
222: }
223:
224: public static void main(String[] args) {
225: junit.textui.TestRunner.run(VMDeath002Test.class);
226: }
227: }
|