1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /** 19 * @author Aleksander V. Budniy 20 */ 21 22 /** 23 * Created on 26.05.2006 24 */ 25 package org.apache.harmony.jpda.tests.jdwp.Events; 26 27 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 28 import org.apache.harmony.jpda.tests.framework.jdwp.EventMod; 29 import org.apache.harmony.jpda.tests.framework.jdwp.EventPacket; 30 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 31 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 32 import org.apache.harmony.jpda.tests.framework.jdwp.Location; 33 import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent; 34 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 35 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 36 37 /** 38 * JDWP Unit test for possible combined (co-located) events: 39 * METHOD_ENTRY, SINGLE_STEP, BREAKPOINT, METHOD_EXIT. 40 */ 41 public class CombinedEventsTest extends CombinedEventsTestCase { 42 43 private String debuggeeSignature = 44 "Lorg/apache/harmony/jpda/tests/jdwp/Events/CombinedEventsDebuggee;"; 45 46 private String methodForEvents = "sampleMethod"; 47 48 private String methodEntryClassNameRegexp = 49 "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEventsDebuggee"; 50 51 private boolean eventVmDeathReceived = false; 52 private boolean eventMethodExitReceived = false; 53 getDebuggeeClassName()54 protected String getDebuggeeClassName() { 55 return CombinedEventsDebuggee.class.getName(); 56 } 57 58 /** 59 * Test starts <code>CombinedEventsDebuggee</code> class. 60 * Then sets requests for expected events at the beginning 61 * (location = 0) of debuggee's method 'sampleMethod()'. Expected events are: 62 * METHOD_ENTRY, SINGLE_STEP, BREAKPOINT. After setting requests the test starts 63 * to receive single SINGLE_STEP events, until debuggee achieves beginning 64 * of sampleMethod(). Then test checks, that three expected events were 65 * grouped on one location and sent in one event packet. At the end, test cleans 66 * request for SINGLE_STEP event, resumes debuggee and checks that only 67 * VM_DEATH event is received after that. 68 */ 69 testCombinedEvents_01()70 public void testCombinedEvents_01() { 71 logWriter.println("==> testCombinedEvents_01 started"); 72 73 byte[] EXPECTED_EVENTS_ARRAY = 74 { 75 JDWPConstants.EventKind.METHOD_ENTRY, 76 JDWPConstants.EventKind.SINGLE_STEP, 77 JDWPConstants.EventKind.BREAKPOINT, 78 }; 79 80 String debuggeeMainThreadName = synchronizer.receiveMessage(); 81 82 long debuggeeClassID = debuggeeWrapper.vmMirror 83 .getClassID(debuggeeSignature); 84 logWriter.println("=> debuggeeClassID = " + debuggeeClassID); 85 86 long threadID = debuggeeWrapper.vmMirror.getThreadID(debuggeeMainThreadName); 87 logWriter.println("=> threadID = " + threadID); 88 89 long runMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, "run"); 90 logWriter.println("=> runMethodID = " + runMethodID); 91 92 logWriter.println(""); 93 logWriter.println("=> Info for tested method '" + methodForEvents + "':"); 94 long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, methodForEvents); 95 if (testedMethodID == -1 ) { 96 String failureMessage = "## FAILURE: Can NOT get MethodID for class '" 97 + getDebuggeeClassName() + "'; Method name = " + methodForEvents; 98 printErrorAndFail(failureMessage); 99 } 100 logWriter.println("=> testedMethodID = " + testedMethodID); 101 printMethodLineTable(debuggeeClassID, null, methodForEvents); 102 103 // set requests for events that will be checked 104 logWriter.println(""); 105 logWriter.println("=> Set request for BREAKPOINT event in debuggee: " 106 + getDebuggeeClassName() + ", beginning of method: " 107 + methodForEvents); 108 Location combinedEventsLocation = getMethodEntryLocation(debuggeeClassID, methodForEvents); 109 if ( combinedEventsLocation == null ) { 110 String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '" 111 + methodForEvents + "'"; 112 printErrorAndFail(failureMessage); 113 } 114 ReplyPacket reply = debuggeeWrapper.vmMirror.setBreakpoint(combinedEventsLocation); 115 int breakpointRequestID = reply.getNextValueAsInt(); 116 logWriter.println("=> Breakpoint requestID = " + breakpointRequestID); 117 118 logWriter.println("=> Set request for METHOD_ENTRY event in debuggee: " 119 + getDebuggeeClassName() + ", method: " + methodForEvents); 120 reply = debuggeeWrapper.vmMirror 121 .setMethodEntry(methodEntryClassNameRegexp); 122 checkReplyPacket(reply, "Set METHOD_ENTRY event"); 123 int methodEntryRequestID = reply.getNextValueAsInt(); 124 logWriter.println("=> METHOD_ENTRY requestID = " + methodEntryRequestID); 125 126 logWriter.println("=> Set request for SINGLE_STEP event in class " 127 + debuggeeSignature); 128 CommandPacket setRequestCommand = new CommandPacket( 129 JDWPCommands.EventRequestCommandSet.CommandSetID, 130 JDWPCommands.EventRequestCommandSet.SetCommand); 131 setRequestCommand 132 .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP); 133 setRequestCommand.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); 134 setRequestCommand.setNextValueAsInt(2); 135 setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step); 136 setRequestCommand.setNextValueAsThreadID(threadID); 137 setRequestCommand.setNextValueAsInt(JDWPConstants.StepSize.MIN); 138 setRequestCommand.setNextValueAsInt(JDWPConstants.StepDepth.INTO); 139 setRequestCommand.setNextValueAsByte(EventMod.ModKind.ClassOnly); 140 setRequestCommand.setNextValueAsReferenceTypeID(debuggeeClassID); 141 142 ReplyPacket setRequestReply = debuggeeWrapper.vmMirror 143 .performCommand(setRequestCommand); 144 checkReplyPacket(setRequestReply, "EventRequest::Set command"); 145 int stepRequestID = setRequestReply.getNextValueAsInt(); 146 logWriter.println("=> SINGLE_STEP requestID = " + stepRequestID); 147 148 logWriter.println(""); 149 logWriter.println("=> Send SGNL_CONTINUE signal to debuggee..."); 150 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 151 152 // ignore SINGLE_STEP events until receiving combined METHOD_ENTRY, 153 // SINGLE_STEP, BREAKPOINT events 154 logWriter.println("=> Try to receive and check combined events: " 155 + " METHOD_ENTRY, SINGLE_STEP, BREAKPOINT events; ignore single SINGLE_STEP event"); 156 receiveAndCheckEvents(EXPECTED_EVENTS_ARRAY, combinedEventsLocation); 157 if ( eventVmDeathReceived ) { 158 logWriter.println("==> testCombinedEvents001 is FINISHing as VM_DEATH is received!"); 159 return; 160 } 161 162 logWriter.println(""); 163 logWriter.println("=> Clean request for METHOD_ENTRY event..."); 164 ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent( 165 JDWPConstants.EventKind.METHOD_ENTRY, methodEntryRequestID); 166 checkReplyPacket(clearReply, "EventRequest::Clear"); 167 168 logWriter.println(""); 169 logWriter.println("=> Clean request for SINGLE_STEP event..."); 170 clearReply = debuggeeWrapper.vmMirror.clearEvent( 171 JDWPConstants.EventKind.SINGLE_STEP, stepRequestID); 172 checkReplyPacket(clearReply, "EventRequest::Clear"); 173 174 logWriter.println("=> Resume debuggee"); 175 debuggeeWrapper.vmMirror.resume(); 176 177 // check that no other events, except VM_DEATH, will be received 178 checkVMDeathEvent(); 179 180 logWriter.println(""); 181 logWriter.println("==> testCombinedEvents_01 PASSED"); 182 } 183 184 /** 185 * Test starts <code>CombinedEventsDebuggee</code> class, sets a 186 * breakpoint at the beginning of method sampleMethod() of debuggee, waits 187 * for this breakpoint. Then sets requests for expected events at the end of 188 * debuggee's method sampleMethod(). Expected events are: METHOD_EXIT, 189 * SINGLE_STEP, BREAKPOINT. Then resumes debuggee and starts to receive 190 * single SINGLE_STEP events, until debuggee achieves end of sampleMethod(). 191 * Then test checks, that three expected events were grouped on one location 192 * and sent in one packet. At the end, test cleans request for SINGLE_STEP 193 * event, resumes debuggee and checks that only VM_DEATH event is received 194 * after that. 195 */ 196 testCombinedEvents_02()197 public void testCombinedEvents_02() { 198 logWriter.println("==> testCombinedEvents_02 started"); 199 200 byte[] EXPECTED_EVENTS_ARRAY = 201 { 202 JDWPConstants.EventKind.SINGLE_STEP, 203 JDWPConstants.EventKind.BREAKPOINT, 204 JDWPConstants.EventKind.METHOD_EXIT, 205 }; 206 207 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 208 209 long debuggeeClassID = debuggeeWrapper.vmMirror.getClassID(debuggeeSignature); 210 logWriter.println("=> debuggeeClassID = " + debuggeeClassID); 211 212 long runMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, "run"); 213 logWriter.println("=> runMethodID = " + runMethodID); 214 215 logWriter.println(""); 216 logWriter.println("=> Info for tested method '" + methodForEvents + "':"); 217 long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, methodForEvents); 218 if (testedMethodID == -1 ) { 219 String failureMessage = "## FAILURE: Can NOT get MethodID for class '" 220 + getDebuggeeClassName() + "'; Method name = " + methodForEvents; 221 printErrorAndFail(failureMessage); 222 } 223 logWriter.println("=> testedMethodID = " + testedMethodID); 224 printMethodLineTable(debuggeeClassID, null, methodForEvents); 225 226 logWriter.println(""); 227 logWriter.println("=> Set breakpoint at the beginning of " 228 + methodForEvents); 229 int requestID = debuggeeWrapper.vmMirror.setBreakpointAtMethodBegin( 230 debuggeeClassID, methodForEvents); 231 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 232 233 logWriter.println("=> Wait for breakpoint event.."); 234 235 long threadID = debuggeeWrapper.vmMirror.waitForBreakpoint(requestID); 236 logWriter.println("=> threadID = " + threadID); 237 238 // set requests for events that will be checked 239 logWriter.println("=> Set request for BREAKPOINT event in debuggee: " 240 + getDebuggeeClassName() + ", at end of method: " 241 + methodForEvents); 242 Location combinedEventsLocation = getMethodEndLocation(debuggeeClassID, methodForEvents); 243 if ( combinedEventsLocation == null ) { 244 String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '" 245 + methodForEvents + "'"; 246 printErrorAndFail(failureMessage); 247 } 248 249 ReplyPacket reply = debuggeeWrapper.vmMirror.setBreakpoint(combinedEventsLocation); 250 int breakpointRequestID = reply.getNextValueAsInt(); 251 logWriter.println("=> Breakpoint requestID = " + breakpointRequestID); 252 253 logWriter.println("=> Set request for METHOD_EXIT event in debuggee: " 254 + getDebuggeeClassName() + ", method: " + methodForEvents); 255 reply = debuggeeWrapper.vmMirror 256 .setMethodExit(methodEntryClassNameRegexp); 257 checkReplyPacket(reply, "EventRequest::Set command"); 258 int methodExitRequestID = reply.getNextValueAsInt(); 259 logWriter.println("=> METHOD_EXIT requestID = " + methodExitRequestID); 260 261 logWriter.println("=> Set request for SINGLE_STEP event in class " 262 + debuggeeSignature); 263 CommandPacket setRequestCommand = new CommandPacket( 264 JDWPCommands.EventRequestCommandSet.CommandSetID, 265 JDWPCommands.EventRequestCommandSet.SetCommand); 266 setRequestCommand 267 .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP); 268 setRequestCommand.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); 269 setRequestCommand.setNextValueAsInt(2); 270 setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step); 271 setRequestCommand.setNextValueAsThreadID(threadID); 272 setRequestCommand.setNextValueAsInt(JDWPConstants.StepSize.MIN); 273 setRequestCommand.setNextValueAsInt(JDWPConstants.StepDepth.INTO); 274 setRequestCommand.setNextValueAsByte(EventMod.ModKind.ClassOnly); 275 setRequestCommand.setNextValueAsReferenceTypeID(debuggeeClassID); 276 277 ReplyPacket setRequestReply = debuggeeWrapper.vmMirror 278 .performCommand(setRequestCommand); 279 checkReplyPacket(setRequestReply, "EventRequest::Set command"); 280 int stepRequestID = setRequestReply.getNextValueAsInt(); 281 logWriter.println("=> SINGLE_STEP requestID = " + stepRequestID); 282 283 logWriter.println(""); 284 logWriter.println("=> Resume debuggee"); 285 debuggeeWrapper.vmMirror.resume(); 286 287 // ignore SINGLE_STEP events until receiving combined METHOD_EXIT, 288 // SINGLE_STEP, BREAKPOINT events 289 logWriter.println("=> Try to receive and check combined events: " 290 + " METHOD_EXIT, SINGLE_STEP, BREAKPOINT events; ignore single SINGLE_STEP event"); 291 receiveAndCheckEvents(EXPECTED_EVENTS_ARRAY, combinedEventsLocation); 292 if ( eventVmDeathReceived ) { 293 logWriter.println("==> testCombinedEvents002 is FINISHing as VM_DEATH is received!"); 294 return; 295 } 296 297 if ( eventMethodExitReceived ) { 298 logWriter.println(""); 299 logWriter.println("=> Clean request for METHOD_EXIT event..."); 300 ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent( 301 JDWPConstants.EventKind.METHOD_EXIT, methodExitRequestID); 302 checkReplyPacket(clearReply, "EventRequest::Clear"); 303 } 304 305 logWriter.println(""); 306 logWriter.println("=> Clean request for SINGLE_STEP event..."); 307 ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent( 308 JDWPConstants.EventKind.SINGLE_STEP, stepRequestID); 309 checkReplyPacket(clearReply, "EventRequest::Clear"); 310 311 logWriter.println("=> Resume debuggee"); 312 debuggeeWrapper.vmMirror.resume(); 313 314 // check that no other events, except VM_DEATH, will be received 315 checkVMDeathEvent(); 316 317 logWriter.println(""); 318 logWriter.println("==> testCombinedEvents_02 PASSED"); 319 } 320 321 /** 322 * Test starts <code>CombinedEventsDebuggee</code> class. 323 * Then sets requests for expected events at the beginning 324 * (location = 0) of debuggee's method 'sampleMethod()'. Expected events are: 325 * METHOD_ENTRY, SINGLE_STEP. After setting requests the test starts 326 * to receive single SINGLE_STEP events, until debuggee achieves beginning of 327 * sampleMethod(). Then test checks, that three expected events were grouped 328 * on one location and sent in one packet. At the end, test cleans request 329 * for SINGLE_STEP event, resumes debuggee and checks that only VM_DEATH 330 * event is received after that. 331 */ 332 testCombinedEvents_03()333 public void testCombinedEvents_03() { 334 logWriter.println("==> testCombinedEvents_03 started"); 335 336 byte[] EXPECTED_EVENTS_ARRAY = 337 { 338 JDWPConstants.EventKind.METHOD_ENTRY, 339 JDWPConstants.EventKind.SINGLE_STEP, 340 }; 341 342 String debuggeeMainThreadName = synchronizer.receiveMessage(); 343 344 long debuggeeClassID = debuggeeWrapper.vmMirror 345 .getClassID(debuggeeSignature); 346 logWriter.println("=> debuggeeClassID = " + debuggeeClassID); 347 348 long threadID = debuggeeWrapper.vmMirror.getThreadID(debuggeeMainThreadName); 349 logWriter.println("=> threadID = " + threadID); 350 351 long runMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, "run"); 352 logWriter.println("=> runMethodID = " + runMethodID); 353 354 logWriter.println(""); 355 logWriter.println("=> Info for tested method '" + methodForEvents + "':"); 356 long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, methodForEvents); 357 if (testedMethodID == -1 ) { 358 String failureMessage = "## FAILURE: Can NOT get MethodID for class '" 359 + getDebuggeeClassName() + "'; Method name = " + methodForEvents; 360 printErrorAndFail(failureMessage); 361 } 362 logWriter.println("=> testedMethodID = " + testedMethodID); 363 printMethodLineTable(debuggeeClassID, null, methodForEvents); 364 365 // set requests for events that will be checked 366 367 logWriter.println("=> Set request for METHOD_ENTRY event in debuggee: " 368 + getDebuggeeClassName() + ", method: " + methodForEvents); 369 ReplyPacket reply = debuggeeWrapper.vmMirror 370 .setMethodEntry(methodEntryClassNameRegexp); 371 checkReplyPacket(reply, "Set METHOD_ENTRY event"); 372 int methodEntryRequestID = reply.getNextValueAsInt(); 373 logWriter.println("=> METHOD_ENTRY requestID = " + methodEntryRequestID); 374 375 logWriter.println("=> Set request for SINGLE_STEP event in class " 376 + debuggeeSignature); 377 CommandPacket setRequestCommand = new CommandPacket( 378 JDWPCommands.EventRequestCommandSet.CommandSetID, 379 JDWPCommands.EventRequestCommandSet.SetCommand); 380 setRequestCommand 381 .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP); 382 setRequestCommand.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); 383 setRequestCommand.setNextValueAsInt(2); 384 setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step); 385 setRequestCommand.setNextValueAsThreadID(threadID); 386 setRequestCommand.setNextValueAsInt(JDWPConstants.StepSize.MIN); 387 setRequestCommand.setNextValueAsInt(JDWPConstants.StepDepth.INTO); 388 setRequestCommand.setNextValueAsByte(EventMod.ModKind.ClassOnly); 389 setRequestCommand.setNextValueAsReferenceTypeID(debuggeeClassID); 390 391 ReplyPacket setRequestReply = debuggeeWrapper.vmMirror 392 .performCommand(setRequestCommand); 393 checkReplyPacket(setRequestReply, "EventRequest::Set command"); 394 int stepRequestID = setRequestReply.getNextValueAsInt(); 395 logWriter.println("=> SINGLE_STEP requestID = " + stepRequestID); 396 397 logWriter.println(""); 398 logWriter.println("=> Send SGNL_CONTINUE signal to debuggee..."); 399 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 400 401 Location combinedEventsLocation = getMethodEntryLocation(debuggeeClassID, methodForEvents); 402 if ( combinedEventsLocation == null ) { 403 String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '" 404 + methodForEvents + "'"; 405 printErrorAndFail(failureMessage); 406 } 407 // ignore SINGLE_STEP events until receiving combined METHOD_ENTRY, 408 // SINGLE_STEP events 409 logWriter 410 .println("=> Try to receive and check combined events: METHOD_ENTRY, SINGLE_STEP events; ignore single SINGLE_STEP event"); 411 receiveAndCheckEvents(EXPECTED_EVENTS_ARRAY, combinedEventsLocation); 412 if ( eventVmDeathReceived ) { 413 logWriter.println("==> testCombinedEvents003 is FINISHing as VM_DEATH is received!"); 414 return; 415 } 416 417 logWriter.println(""); 418 logWriter.println("=> Clean request for METHOD_ENTRY event..."); 419 ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent( 420 JDWPConstants.EventKind.METHOD_ENTRY, methodEntryRequestID); 421 checkReplyPacket(clearReply, "EventRequest::Clear"); 422 423 logWriter.println(""); 424 logWriter.println("=> Clean request for SINGLE_STEP event"); 425 clearReply = debuggeeWrapper.vmMirror.clearEvent( 426 JDWPConstants.EventKind.SINGLE_STEP, stepRequestID); 427 checkReplyPacket(clearReply, "EventRequest::Clear"); 428 429 logWriter.println("=> Resume debuggee"); 430 debuggeeWrapper.vmMirror.resume(); 431 432 // check that no other events, except VM_DEATH, will be received 433 checkVMDeathEvent(); 434 435 logWriter.println(""); 436 logWriter.println("==> testCombinedEvents_03 PASSED"); 437 } 438 439 /** 440 * Test starts <code>CombinedEventsDebuggee</code> class, sets a 441 * breakpoint at the beginning of method sampleMethod() of debuggee, waits 442 * for this breakpoint. Then sets requests for expected events at the end of 443 * debuggee's method sampleMethod(). Expected events are: METHOD_EXIT, 444 * SINGLE_STEP. Then resumes debuggee and starts to receive single 445 * SINGLE_STEP events, until debuggee achieves end of sampleMethod(). Then 446 * test checks, that three expected events were grouped on one location and 447 * sent in one packet. At the end, test cleans request for SINGLE_STEP 448 * event, resumes debuggee and checks that only VM_DEATH event is received 449 * after that. 450 */ 451 testCombinedEvents_04()452 public void testCombinedEvents_04() { 453 logWriter.println("==> testCombinedEvents004 started"); 454 455 byte[] EXPECTED_EVENTS_ARRAY = 456 { 457 JDWPConstants.EventKind.SINGLE_STEP, 458 JDWPConstants.EventKind.METHOD_EXIT, 459 }; 460 461 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 462 463 long debuggeeClassID = debuggeeWrapper.vmMirror.getClassID(debuggeeSignature); 464 logWriter.println("=> debuggeeClassID = " + debuggeeClassID); 465 466 long runMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, "run"); 467 logWriter.println("=> runMethodID = " + runMethodID); 468 469 logWriter.println(""); 470 logWriter.println("=> Info for tested method '" + methodForEvents + "':"); 471 long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, methodForEvents); 472 if (testedMethodID == -1 ) { 473 String failureMessage = "## FAILURE: Can NOT get MethodID for class '" 474 + getDebuggeeClassName() + "'; Method name = " + methodForEvents; 475 printErrorAndFail(failureMessage); 476 } 477 logWriter.println("=> testedMethodID = " + testedMethodID); 478 printMethodLineTable(debuggeeClassID, null, methodForEvents); 479 480 logWriter.println(""); 481 logWriter.println("=> Set breakpoint at the beginning of " 482 + methodForEvents); 483 int requestID = debuggeeWrapper.vmMirror.setBreakpointAtMethodBegin( 484 debuggeeClassID, methodForEvents); 485 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 486 487 logWriter.println("=> Wait for breakpoint event.."); 488 489 long threadID = debuggeeWrapper.vmMirror.waitForBreakpoint(requestID); 490 logWriter.println("=> threadID = " + threadID); 491 492 // set requests for events that will be checked 493 494 logWriter.println("=> Set request for METHOD_EXIT event in debuggee: " 495 + getDebuggeeClassName() + ", method: " + methodForEvents); 496 ReplyPacket reply = debuggeeWrapper.vmMirror 497 .setMethodExit(methodEntryClassNameRegexp); 498 checkReplyPacket(reply, "EventRequest::Set command"); 499 int methodExitRequestID = reply.getNextValueAsInt(); 500 logWriter.println("=> METHOD_EXIT requestID = " + methodExitRequestID); 501 502 logWriter.println("=> Set request for SINGLE_STEP event in class " 503 + debuggeeSignature); 504 CommandPacket setRequestCommand = new CommandPacket( 505 JDWPCommands.EventRequestCommandSet.CommandSetID, 506 JDWPCommands.EventRequestCommandSet.SetCommand); 507 setRequestCommand 508 .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP); 509 setRequestCommand.setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL); 510 setRequestCommand.setNextValueAsInt(2); 511 setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step); 512 setRequestCommand.setNextValueAsThreadID(threadID); 513 setRequestCommand.setNextValueAsInt(JDWPConstants.StepSize.MIN); 514 setRequestCommand.setNextValueAsInt(JDWPConstants.StepDepth.INTO); 515 setRequestCommand.setNextValueAsByte(EventMod.ModKind.ClassOnly); 516 setRequestCommand.setNextValueAsReferenceTypeID(debuggeeClassID); 517 518 ReplyPacket setRequestReply = debuggeeWrapper.vmMirror 519 .performCommand(setRequestCommand); 520 checkReplyPacket(setRequestReply, "EventRequest::Set command"); 521 int stepRequestID = setRequestReply.getNextValueAsInt(); 522 logWriter.println("=> SINGLE_STEP requestID = " + stepRequestID); 523 524 logWriter.println(""); 525 logWriter.println("=> Resume debuggee"); 526 debuggeeWrapper.vmMirror.resume(); 527 528 Location combinedEventsLocation = getMethodEndLocation(debuggeeClassID, methodForEvents); 529 if ( combinedEventsLocation == null ) { 530 String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '" 531 + methodForEvents + "'"; 532 printErrorAndFail(failureMessage); 533 } 534 // ignore SINGLE_STEP events until receiving combined METHOD_EXIT, 535 // SINGLE_STEP events 536 logWriter 537 .println("=> Try to receive and check combined events: METHOD_EXIT, SINGLE_STEP events; ignore single SINGLE_STEP event"); 538 539 receiveAndCheckEvents(EXPECTED_EVENTS_ARRAY, combinedEventsLocation); 540 if ( eventVmDeathReceived ) { 541 logWriter.println("==> testCombinedEvents004 is FINISHing as VM_DEATH is received!"); 542 return; 543 } 544 545 if ( eventMethodExitReceived ) { 546 logWriter.println(""); 547 logWriter.println("=> Clean request for METHOD_EXIT event..."); 548 ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent( 549 JDWPConstants.EventKind.METHOD_EXIT, methodExitRequestID); 550 checkReplyPacket(clearReply, "EventRequest::Clear"); 551 } 552 553 logWriter.println(""); 554 logWriter.println("=> Clean request for SINGLE_STEP event"); 555 ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent( 556 JDWPConstants.EventKind.SINGLE_STEP, stepRequestID); 557 checkReplyPacket(clearReply, "EventRequest::Clear"); 558 559 logWriter.println("=> Resume debuggee"); 560 debuggeeWrapper.vmMirror.resume(); 561 562 // check that no other events, except VM_DEATH, will be received 563 checkVMDeathEvent(); 564 565 logWriter.println(""); 566 logWriter.println("==> testCombinedEvents_04 PASSED"); 567 } 568 569 /** 570 * Test starts <code>CombinedEventsDebuggee</code> class, sets a 571 * breakpoint inside method run() of debuggee, waits for this breakpoint and 572 * gets threadID. Then sets requests for expected events at the beginning 573 * (location = 0) of debuggee's method sampleMethod(). Expected events are: 574 * METHOD_ENTRY, BREAKPOINT. Then resumes debuggee and starts to receive 575 * single SINGLE_STEP events, until debuggee achieves beginning of 576 * sampleMethod(). Then test checks, that three expected events were grouped 577 * on one location and sent in one packet. At the end, test resumes debuggee 578 * and checks that only VM_DEATH event is received after that. 579 */ 580 testCombinedEvents_05()581 public void testCombinedEvents_05() { 582 logWriter.println("==> testCombinedEvents_05 started"); 583 584 byte[] EXPECTED_EVENTS_ARRAY = 585 { 586 JDWPConstants.EventKind.METHOD_ENTRY, 587 JDWPConstants.EventKind.BREAKPOINT, 588 }; 589 int EXPECTED_EVENTS_COUNT = EXPECTED_EVENTS_ARRAY.length; 590 591 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 592 593 long debuggeeClassID = debuggeeWrapper.vmMirror 594 .getClassID(debuggeeSignature); 595 logWriter.println("=> debuggeeClassID = " + debuggeeClassID); 596 597 long runMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, "run"); 598 logWriter.println("=> runMethodID = " + runMethodID); 599 600 logWriter.println(""); 601 logWriter.println("=> Info for tested method '" + methodForEvents + "':"); 602 long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, methodForEvents); 603 if (testedMethodID == -1 ) { 604 String failureMessage = "## FAILURE: Can NOT get MethodID for class '" 605 + getDebuggeeClassName() + "'; Method name = " + methodForEvents; 606 printErrorAndFail(failureMessage); 607 } 608 logWriter.println("=> testedMethodID = " + testedMethodID); 609 printMethodLineTable(debuggeeClassID, null, methodForEvents); 610 611 612 // logWriter.println("=> Set breakpoint inside debuggee to get threadID"); 613 // int requestID = (int)debuggeeWrapper.vmMirror.setBreakpointInsideMethod( 614 // debuggeeClassID, "run", 2 /*lineInsideDebuggee*/); 615 // synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 616 617 // logWriter.println("=> Wait for breakpoint event.."); 618 619 // long threadID = debuggeeWrapper.vmMirror.waitForBreakpoint(requestID); 620 // logWriter.println("=> threadID = " + threadID); 621 622 // set requests for events that will be checked 623 logWriter.println(""); 624 logWriter.println("=> Set request for BREAKPOINT event in debuggee: " 625 + getDebuggeeClassName() + ", beginning of method: " 626 + methodForEvents); 627 // int breakpointRequestID = (int)debuggeeWrapper.vmMirror 628 // .setBreakpointAtMethodBegin(debuggeeClassID, methodForEvents); 629 // logWriter.println("=> Breakpoint requestID = " + breakpointRequestID); 630 Location combinedEventsLocation = getMethodEntryLocation(debuggeeClassID, methodForEvents); 631 if ( combinedEventsLocation == null ) { 632 String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '" 633 + methodForEvents + "'"; 634 printErrorAndFail(failureMessage); 635 } 636 ReplyPacket reply = debuggeeWrapper.vmMirror.setBreakpoint(combinedEventsLocation); 637 int breakpointRequestID = reply.getNextValueAsInt(); 638 logWriter.println("=> Breakpoint requestID = " + breakpointRequestID); 639 640 641 logWriter.println("=> Set request for METHOD_ENTRY event in debuggee: " 642 + getDebuggeeClassName() + ", method: " + methodForEvents); 643 reply = debuggeeWrapper.vmMirror 644 .setMethodEntry(methodEntryClassNameRegexp); 645 checkReplyPacket(reply, "Set METHOD_ENTRY event"); 646 int methodEntryRequestID = reply.getNextValueAsInt(); 647 logWriter.println("=> METHOD_ENTRY requestID = " + methodEntryRequestID); 648 649 logWriter.println(""); 650 // logWriter.println("=> Resume debuggee"); 651 // debuggeeWrapper.vmMirror.resume(); 652 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 653 654 // receive and check combined METHOD_ENTRY, BREAKPOINT events 655 logWriter 656 .println("=> Try to receive and check combined events: METHOD_ENTRY, BREAKPOINT events"); 657 EventPacket event = debuggeeWrapper.vmMirror.receiveEvent(); 658 ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event); 659 // print all received events 660 logWriter.println("=> Events received: " + parsedEvents.length); 661 for (int i = 0; i < parsedEvents.length; i++) { 662 logWriter.println(""); 663 logWriter.println("=> Event #" + i + ";"); 664 logWriter.println("=> EventKind: " 665 + parsedEvents[i].getEventKind() 666 + "[" 667 + JDWPConstants.EventKind.getName(parsedEvents[i] 668 .getEventKind()) + "]"); 669 logWriter 670 .println("=> RequestID: " + parsedEvents[i].getRequestID()); 671 } 672 boolean success = true; 673 boolean locationsOK = checkEventsLocation(parsedEvents, combinedEventsLocation); 674 if (parsedEvents.length == EXPECTED_EVENTS_COUNT) { 675 logWriter.println(""); 676 logWriter 677 .println("=> Combined events are received. Check events.."); 678 for (int i = 0; i < parsedEvents.length; i++) { 679 boolean isFound = false; 680 for (int j = 0; j < EXPECTED_EVENTS_COUNT; j++) { 681 if (parsedEvents[i].getEventKind() == EXPECTED_EVENTS_ARRAY[j]) { 682 EXPECTED_EVENTS_ARRAY[j] = 0; 683 isFound = true; 684 break; 685 } 686 } 687 if (!isFound) { 688 logWriter 689 .println("##FAILURE: received unexpected event: " 690 + parsedEvents[i].getEventKind() 691 + "[" 692 + JDWPConstants.EventKind 693 .getName(parsedEvents[0] 694 .getEventKind()) + "]"); 695 success = false; 696 } 697 } 698 if (!success) { 699 logWriter.println(""); 700 logWriter 701 .println("##FAILURE: the following events were not received: "); 702 for (int k = 0; k < EXPECTED_EVENTS_COUNT; k++) { 703 if (EXPECTED_EVENTS_ARRAY[k] != 0) 704 logWriter.println(" #" 705 + k 706 + ": " 707 + EXPECTED_EVENTS_ARRAY[k] 708 + "[" 709 + JDWPConstants.EventKind 710 .getName(EXPECTED_EVENTS_ARRAY[k]) 711 + "]"); 712 } 713 //DBG__fail("not all expected events were received"); 714 } 715 } else { 716 logWriter.println("##FAILURE: received unexpected number of events: " 717 + parsedEvents.length 718 + " instead of " 719 + EXPECTED_EVENTS_COUNT); 720 //DBG__fail("received unexpected number of events: " + parsedEvents.length); 721 722 } 723 if ( (! success) || (! locationsOK) ) { 724 logWriter.println("## FAILURE during checking events!"); 725 } 726 logWriter.println(""); 727 logWriter.println("=> Clean request for METHOD_ENTRY event..."); 728 ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent( 729 JDWPConstants.EventKind.METHOD_ENTRY, methodEntryRequestID); 730 checkReplyPacket(clearReply, "EventRequest::Clear"); 731 732 logWriter.println("=> Resume debuggee"); 733 debuggeeWrapper.vmMirror.resume(); 734 735 // check that no other events, except VM_DEATH, will be received 736 checkVMDeathEvent(); 737 738 logWriter.println(""); 739 logWriter.println("==> testCombinedEvents_05 PASSED"); 740 } 741 742 /** 743 * Test starts <code>CombinedEventsDebuggee</code> class, sets a 744 * breakpoint inside method run() of debuggee, waits for this breakpoint and 745 * gets threadID. Then sets requests for expected events at the beginning 746 * (location = 0) of debuggee's method sampleMethod(). Expected events are: 747 * METHOD_EXIT, BREAKPOINT. Then resumes debuggee and starts to receive 748 * single SINGLE_STEP events, until debuggee achieves beginning of 749 * sampleMethod(). Then test checks, that three expected events were grouped 750 * on one location and sent in one packet. At the end, test resumes debuggee 751 * and checks that only VM_DEATH event is received after that. 752 */ 753 testCombinedEvents_06()754 public void testCombinedEvents_06() { 755 logWriter.println("==> testCombinedEvents_06 started"); 756 757 byte[] EXPECTED_EVENTS_ARRAY = 758 { 759 JDWPConstants.EventKind.BREAKPOINT, 760 JDWPConstants.EventKind.METHOD_EXIT, 761 }; 762 int EXPECTED_EVENTS_COUNT = EXPECTED_EVENTS_ARRAY.length; 763 764 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 765 766 long debuggeeClassID = debuggeeWrapper.vmMirror 767 .getClassID(debuggeeSignature); 768 logWriter.println("=> debuggeeClassID = " + debuggeeClassID); 769 770 long runMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, "run"); 771 logWriter.println("=> runMethodID = " + runMethodID); 772 773 logWriter.println(""); 774 logWriter.println("=> Info for tested method '" + methodForEvents + "':"); 775 long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(debuggeeClassID, methodForEvents); 776 if (testedMethodID == -1 ) { 777 String failureMessage = "## FAILURE: Can NOT get MethodID for class '" 778 + getDebuggeeClassName() + "'; Method name = " + methodForEvents; 779 printErrorAndFail(failureMessage); 780 } 781 logWriter.println("=> testedMethodID = " + testedMethodID); 782 printMethodLineTable(debuggeeClassID, null, methodForEvents); 783 784 // set requests for events that will be checked 785 logWriter.println(""); 786 logWriter.println("=> Set request for BREAKPOINT event in debuggee: " 787 + getDebuggeeClassName() + ", at end of method: " 788 + methodForEvents); 789 Location combinedEventsLocation = getMethodEndLocation(debuggeeClassID, methodForEvents); 790 if ( combinedEventsLocation == null ) { 791 String failureMessage = "## FAILURE: Can NOT get MethodEndLocation for method '" 792 + methodForEvents + "'"; 793 printErrorAndFail(failureMessage); 794 } 795 ReplyPacket reply = debuggeeWrapper.vmMirror.setBreakpoint(combinedEventsLocation); 796 int breakpointRequestID = reply.getNextValueAsInt(); 797 logWriter.println("=> Breakpoint requestID = " + breakpointRequestID); 798 799 800 logWriter.println("=> Set request for METHOD_EXIT event in debuggee: " 801 + getDebuggeeClassName() + ", method: " + methodForEvents); 802 reply = debuggeeWrapper.vmMirror 803 .setMethodExit(methodEntryClassNameRegexp); 804 checkReplyPacket(reply, "Set METHOD_EXIT event"); 805 int methodExitRequestID = reply.getNextValueAsInt(); 806 logWriter.println("=> METHOD_EXIT requestID = " + methodExitRequestID); 807 808 logWriter.println(""); 809 logWriter.println("Send SGNL_CONTINUE signal to debuggee..."); 810 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 811 812 // receive and check combined METHOD_EXIT, BREAKPOINT events 813 logWriter 814 .println("=> Try to receive and check combined events: METHOD_EXIT, BREAKPOINT events"); 815 EventPacket event = debuggeeWrapper.vmMirror.receiveEvent(); 816 ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event); 817 // print all received events 818 logWriter.println("=> Events received: " + parsedEvents.length); 819 for (int i = 0; i < parsedEvents.length; i++) { 820 logWriter.println(""); 821 logWriter.println("=> Event #" + i + ";"); 822 logWriter.println("=> EventKind: " 823 + parsedEvents[i].getEventKind() 824 + "[" 825 + JDWPConstants.EventKind.getName(parsedEvents[i] 826 .getEventKind()) + "]"); 827 logWriter 828 .println("=> RequestID: " + parsedEvents[i].getRequestID()); 829 if ( parsedEvents[i].getEventKind() == JDWPConstants.EventKind.METHOD_EXIT ) { 830 eventMethodExitReceived = true; 831 } 832 } 833 boolean success = true; 834 boolean locationsOK = checkEventsLocation(parsedEvents, combinedEventsLocation); 835 if (parsedEvents.length == EXPECTED_EVENTS_COUNT) { 836 logWriter.println(""); 837 logWriter 838 .println("=> Combined events are received. Check events.."); 839 for (int i = 0; i < parsedEvents.length; i++) { 840 boolean isFound = false; 841 for (int j = 0; j < EXPECTED_EVENTS_COUNT; j++) { 842 if (parsedEvents[i].getEventKind() == EXPECTED_EVENTS_ARRAY[j]) { 843 EXPECTED_EVENTS_ARRAY[j] = 0; 844 isFound = true; 845 break; 846 } 847 } 848 if (!isFound) { 849 logWriter 850 .println("##FAILURE: received unexpected event: " 851 + parsedEvents[i].getEventKind() 852 + "[" 853 + JDWPConstants.EventKind 854 .getName(parsedEvents[0] 855 .getEventKind()) + "]"); 856 success = false; 857 } 858 } 859 if (!success) { 860 logWriter.println(""); 861 logWriter 862 .println("##FAILURE: the following events were not received: "); 863 for (int k = 0; k < EXPECTED_EVENTS_COUNT; k++) { 864 if (EXPECTED_EVENTS_ARRAY[k] != 0) 865 logWriter.println(" #" 866 + k 867 + ": " 868 + EXPECTED_EVENTS_ARRAY[k] 869 + "[" 870 + JDWPConstants.EventKind 871 .getName(EXPECTED_EVENTS_ARRAY[k]) 872 + "]"); 873 } 874 //DBG__fail("not all expected events were received"); 875 } 876 } else { 877 logWriter.println("##FAILURE: received unexpected number of events: " 878 + parsedEvents.length 879 + " instead of " 880 + EXPECTED_EVENTS_COUNT); 881 //DBG__fail("received unexpected number of events: " + parsedEvents.length); 882 883 } 884 if ( (! success) || (! locationsOK) ) { 885 logWriter.println("## FAILURE during checking events!"); 886 //DBG__printErrorAndFail(failureMessage); 887 } 888 if ( eventMethodExitReceived ) { 889 logWriter.println(""); 890 logWriter.println("=> Clean request for METHOD_EXIT event..."); 891 ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent( 892 JDWPConstants.EventKind.METHOD_EXIT, methodExitRequestID); 893 checkReplyPacket(clearReply, "EventRequest::Clear"); 894 } 895 896 logWriter.println("=> Resume debuggee"); 897 debuggeeWrapper.vmMirror.resume(); 898 899 // check that no other events, except VM_DEATH, will be received 900 checkVMDeathEvent(); 901 902 logWriter.println(""); 903 logWriter.println("==> testCombinedEvents_06 PASSED"); 904 } 905 receiveAndCheckEvents(byte[] EXPECTED_EVENTS_ARRAY, Location expectedLocation)906 void receiveAndCheckEvents(byte[] EXPECTED_EVENTS_ARRAY, Location expectedLocation) { 907 int EXPECTED_EVENTS_COUNT = EXPECTED_EVENTS_ARRAY.length; 908 for (;;) { 909 logWriter.println("=>"); 910 logWriter.println("=> Receiving events..."); 911 EventPacket event = debuggeeWrapper.vmMirror.receiveEvent(); 912 ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event); 913 914 // print all received events 915 logWriter.println("=> Received event packet with events number = " + parsedEvents.length + " :"); 916 917 for (int i = 0; i < parsedEvents.length; i++) { 918 logWriter.println(""); 919 logWriter.println("=> Event #" + (i+1) + " in packet -"); 920 logWriter.println("=> EventKind: " 921 + parsedEvents[i].getEventKind() 922 + "[" 923 + JDWPConstants.EventKind.getName(parsedEvents[i] 924 .getEventKind()) + "]"); 925 logWriter.println("=> RequestID: " 926 + parsedEvents[i].getRequestID()); 927 if ( parsedEvents[i].getEventKind() == JDWPConstants.EventKind.VM_DEATH ) { 928 eventVmDeathReceived = true; 929 } 930 if ( parsedEvents[i].getEventKind() == JDWPConstants.EventKind.METHOD_EXIT ) { 931 eventMethodExitReceived = true; 932 } 933 } 934 if ( eventVmDeathReceived ) { 935 return; 936 } 937 checkEventsLocation(parsedEvents, null); // DBG__ 938 939 // the following code checks received events 940 if (parsedEvents.length == 1) { 941 debuggeeWrapper.vmMirror.resume(); 942 continue; 943 /* DBG__ 944 if (parsedEvents[0].getEventKind() == JDWPConstants.EventKind.SINGLE_STEP) { 945 logWriter.println(""); 946 logWriter.println("=> Resume debuggee"); 947 logWriter.println(""); 948 debuggeeWrapper.vmMirror.resume(); 949 continue; 950 } else { 951 logWriter.println("##FAILURE: received unexpected event: " 952 + parsedEvents[0].getEventKind() 953 + "[" 954 + JDWPConstants.EventKind.getName(parsedEvents[0] 955 .getEventKind()) 956 + "] instead of SINGLE_STEP"); 957 fail("received event is not SINGLE_STEP event: " 958 + parsedEvents[0].getEventKind() 959 + "[" 960 + JDWPConstants.EventKind.getName(parsedEvents[0] 961 .getEventKind()) + "]"); 962 } 963 // DBG__ */ 964 //DBG__} else if (parsedEvents.length == EXPECTED_EVENTS_COUNT) { 965 } else if (parsedEvents.length > 1) { 966 logWriter.println(""); 967 logWriter 968 .println("=> Combined events are received. Check events.."); 969 boolean success = true; 970 for (int i = 0; i < parsedEvents.length; i++) { 971 boolean isFound = false; 972 for (int j = 0; j < EXPECTED_EVENTS_COUNT; j++) { 973 if (parsedEvents[i].getEventKind() == EXPECTED_EVENTS_ARRAY[j]) { 974 EXPECTED_EVENTS_ARRAY[j] = 0; 975 isFound = true; 976 break; 977 } 978 } 979 if (!isFound) { 980 logWriter.println("##FAILURE: received unexpected event: " 981 + parsedEvents[i].getEventKind() 982 + "[" 983 + JDWPConstants.EventKind 984 .getName(parsedEvents[0] 985 .getEventKind()) + "]"); 986 success = false; 987 } 988 } 989 if (!success) { 990 logWriter.println(""); 991 logWriter.println("##FAILURE: the following expected events were not received: "); 992 for (int k = 0; k < EXPECTED_EVENTS_COUNT; k++) { 993 if (EXPECTED_EVENTS_ARRAY[k] != 0) 994 logWriter.println(" #" 995 + k 996 + ": " 997 + EXPECTED_EVENTS_ARRAY[k] 998 + "[" 999 + JDWPConstants.EventKind 1000 .getName(EXPECTED_EVENTS_ARRAY[k]) 1001 + "]"); 1002 } 1003 fail("not all expected events were received"); 1004 } 1005 for (int i = 0; i < parsedEvents.length; i++) { 1006 byte eventKind = parsedEvents[i].getEventKind(); 1007 long eventThreadID = ((ParsedEvent.EventThread)parsedEvents[i]).getThreadID(); 1008 logWriter.println(""); 1009 logWriter.println("=> Chcek location for combined event N " + (i+1) 1010 + ": Event kind = " + eventKind + "(" 1011 + JDWPConstants.EventKind.getName(eventKind) +"); eventThreadID = " 1012 + eventThreadID); 1013 Location eventLocation = null; 1014 switch ( eventKind ) { 1015 case JDWPConstants.EventKind.METHOD_ENTRY: 1016 eventLocation = ((ParsedEvent.Event_METHOD_ENTRY)parsedEvents[i]).getLocation(); 1017 break; 1018 case JDWPConstants.EventKind.SINGLE_STEP: 1019 eventLocation = ((ParsedEvent.Event_SINGLE_STEP)parsedEvents[i]).getLocation(); 1020 break; 1021 case JDWPConstants.EventKind.BREAKPOINT: 1022 eventLocation = ((ParsedEvent.Event_BREAKPOINT)parsedEvents[i]).getLocation(); 1023 break; 1024 case JDWPConstants.EventKind.METHOD_EXIT: 1025 eventLocation = ((ParsedEvent.Event_METHOD_EXIT)parsedEvents[i]).getLocation(); 1026 break; 1027 } 1028 long eventClassID = eventLocation.classID; 1029 logWriter.println("=> ClassID in event = " + eventClassID); 1030 if ( expectedLocation.classID != eventClassID ) { 1031 logWriter.println("## FAILURE: Unexpected ClassID in event!"); 1032 logWriter.println("## Expected ClassID = " + expectedLocation.classID ); 1033 success = false; 1034 } else { 1035 logWriter.println("=> OK - it is expected ClassID"); 1036 } 1037 long eventMethodID = eventLocation.methodID; 1038 logWriter.println("=> MethodID in event = " + eventMethodID); 1039 if ( expectedLocation.methodID != eventMethodID ) { 1040 logWriter.println("## FAILURE: Unexpected MethodID in event!"); 1041 logWriter.println("## Expected MethodID = " + expectedLocation.methodID); 1042 success = false; 1043 } else { 1044 logWriter.println("=> OK - it is expected MethodID"); 1045 } 1046 long eventCodeIndex = eventLocation.index; 1047 logWriter.println("=> CodeIndex in event = " + eventCodeIndex); 1048 if ( expectedLocation.index != eventCodeIndex ) { 1049 logWriter.println("## FAILURE: Unexpected CodeIndex in event!"); 1050 logWriter.println("## Expected CodeIndex = " 1051 + expectedLocation.index); 1052 success = false; 1053 } else { 1054 logWriter.println("=> OK - it is expected CodeIndex)"); 1055 } 1056 } 1057 logWriter.println(""); 1058 if ( ! success ) { 1059 String failureMessage = "## FAILURE: Unexpected events' locations are found out!"; 1060 logWriter.println(failureMessage); 1061 //DBG__printErrorAndFail(failureMessage); 1062 } else { 1063 logWriter.println("=> OK - all combined events have expected location!"); 1064 } 1065 break; 1066 } else { 1067 logWriter.println("##FAILURE: received unexpected number of events: " 1068 + parsedEvents.length 1069 + " instead of 1 or " 1070 + EXPECTED_EVENTS_COUNT); 1071 fail("received unexpected number of events: " 1072 + parsedEvents.length); 1073 } 1074 } 1075 } 1076 checkVMDeathEvent()1077 void checkVMDeathEvent() { 1078 if ( eventVmDeathReceived ) { 1079 return; 1080 } 1081 logWriter.println("=> Wait for VM_DEATH event..."); 1082 while ( true ) { //DBG__ 1083 logWriter.println("=> Receiving events..."); 1084 EventPacket event = debuggeeWrapper.vmMirror.receiveEvent(); 1085 ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event); 1086 if (parsedEvents.length != 1 1087 || parsedEvents[0].getEventKind() != JDWPConstants.EventKind.VM_DEATH) { 1088 // print all received events 1089 logWriter.println("##FAILURE: Received unexpected events"); 1090 logWriter.println("=> Events received: " + parsedEvents.length); 1091 for (int i = 0; i < parsedEvents.length; i++) { 1092 logWriter.println(""); 1093 logWriter.println("=> Event #" + i + ";"); 1094 logWriter.println("=> EventKind: " 1095 + parsedEvents[i].getEventKind() 1096 + "[" 1097 + JDWPConstants.EventKind.getName(parsedEvents[i] 1098 .getEventKind()) + "]"); 1099 logWriter.println("=> RequestID: " 1100 + parsedEvents[i].getRequestID()); 1101 } 1102 checkEventsLocation(parsedEvents, null); // DBG__ 1103 logWriter.println("=> Resume debuggee"); //DBG__ 1104 debuggeeWrapper.vmMirror.resume(); //DBG__ 1105 continue; //DBG__ 1106 //DBG__fail("unexpected events received"); 1107 } 1108 logWriter.println("=> OK - VM_DEATH event was received. "); 1109 break; //DBG__ 1110 } // DBG__ 1111 } 1112 } 1113