1 /* 2 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package nsk.jdwp.Event.FIELD_ACCESS; 25 26 import java.io.*; 27 28 import nsk.share.*; 29 import nsk.share.jpda.*; 30 import nsk.share.jdwp.*; 31 32 /** 33 * Test for JDWP event: FIELD_ACCESS. 34 * 35 * See fldaccess001.README for description of test execution. 36 * 37 * This class represents debugger part of the test. 38 * Test is executed by invoking method runIt(). 39 * JDWP event is tested in the method waitForTestedEvent(). 40 * 41 * @see #runIt() 42 * @see #waitForTestedEvent() 43 */ 44 public class fldaccess001 { 45 46 // exit status constants 47 static final int JCK_STATUS_BASE = 95; 48 static final int PASSED = 0; 49 static final int FAILED = 2; 50 51 // VM capability constatnts 52 static final int VM_CAPABILITY_NUMBER = JDWP.Capability.CAN_WATCH_FIELD_ACCESS; 53 static final String VM_CAPABILITY_NAME = "canWatchFieldAccess"; 54 55 // package and classes names constants 56 static final String PACKAGE_NAME = "nsk.jdwp.Event.FIELD_ACCESS"; 57 static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "fldaccess001"; 58 static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a"; 59 60 // tested JDWP event constants 61 static final byte TESTED_EVENT_KIND = JDWP.EventKind.FIELD_ACCESS; 62 static final byte TESTED_EVENT_SUSPEND_POLICY = JDWP.SuspendPolicy.ALL; 63 64 // name and signature of the tested class 65 static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedObjectClass"; 66 static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";"; 67 static final String TESTED_THREAD_NAME = "TestedThread"; 68 69 // name of field and method of tested class 70 static final String OBJECT_FIELD_NAME = "object"; 71 static final String VALUE_FIELD_NAME = "value"; 72 static final String TESTED_METHOD_NAME = "methodForAccess"; 73 static final String BREAKPOINT_METHOD_NAME = "run"; 74 static final int BREAKPOINT_LINE = fldaccess001a.BREAKPOINT_LINE; 75 static final int FIELD_ACCESS_LINE = fldaccess001a.FIELD_ACCESS_LINE; 76 77 // usual scaffold objects 78 ArgumentHandler argumentHandler = null; 79 Log log = null; 80 Binder binder = null; 81 Debugee debugee = null; 82 Transport transport = null; 83 int waitTime = 0; // minutes 84 long timeout = 0; // milliseconds 85 boolean dead = false; 86 boolean success = true; 87 88 // obtained data 89 long testedClassID = 0; 90 long testedThreadID = 0; 91 long testedMethodID = 0; 92 long testedFieldID = 0; 93 long testedObjectID = 0; 94 JDWP.Location testedLocation = null; 95 int eventRequestID = 0; 96 97 // ------------------------------------------------------------------- 98 99 /** 100 * Start test from command line. 101 */ main(String argv[])102 public static void main(String argv[]) { 103 System.exit(run(argv,System.out) + JCK_STATUS_BASE); 104 } 105 106 /** 107 * Start test from JCK-compilant environment. 108 */ run(String argv[], PrintStream out)109 public static int run(String argv[], PrintStream out) { 110 return new fldaccess001().runIt(argv, out); 111 } 112 113 // ------------------------------------------------------------------- 114 115 /** 116 * Perform test execution. 117 */ runIt(String argv[], PrintStream out)118 public int runIt(String argv[], PrintStream out) { 119 120 // make log for debugger messages 121 argumentHandler = new ArgumentHandler(argv); 122 log = new Log(out, argumentHandler); 123 waitTime = argumentHandler.getWaitTime(); 124 timeout = waitTime * 60 * 1000; 125 126 // execute test and display results 127 try { 128 log.display("\n>>> Starting debugee \n"); 129 130 // launch debuggee 131 binder = new Binder(argumentHandler, log); 132 log.display("Launching debugee"); 133 debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME); 134 transport = debugee.getTransport(); 135 log.display(" ... debugee launched"); 136 log.display(""); 137 138 // set timeout for debuggee responces 139 log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)"); 140 transport.setReadTimeout(timeout); 141 log.display(" ... timeout set"); 142 143 // wait for debuggee started 144 log.display("Waiting for VM_INIT event"); 145 debugee.waitForVMInit(); 146 log.display(" ... VM_INIT event received"); 147 148 // query debugee for VM-dependent ID sizes 149 log.display("Querying for IDSizes"); 150 debugee.queryForIDSizes(); 151 log.display(" ... size of VM-dependent types adjusted"); 152 153 // check for VM capability 154 log.display("\n>>> Checking VM capability \n"); 155 log.display("Getting VM capability: " + VM_CAPABILITY_NAME); 156 boolean capable = debugee.getCapability(VM_CAPABILITY_NUMBER, VM_CAPABILITY_NAME); 157 log.display(" ... got VM capability: " + capable); 158 159 // exit as PASSED if this capability is not supported 160 if (!capable) { 161 out.println("TEST PASSED: unsupported VM capability: " 162 + VM_CAPABILITY_NAME); 163 return PASSED; 164 } 165 166 // prepare debuggee 167 log.display("\n>>> Getting prepared for testing \n"); 168 prepareForTest(); 169 170 // test JDWP event 171 log.display("\n>>> Testing JDWP event \n"); 172 log.display("Making request for FIELD_ACCESS event for field: " 173 + VALUE_FIELD_NAME); 174 requestTestedEvent(); 175 log.display(" ... got requestID: " + eventRequestID); 176 log.display(""); 177 178 // resume debuggee 179 log.display("Resumindg debuggee"); 180 debugee.resume(); 181 log.display(" ... debuggee resumed"); 182 log.display(""); 183 184 // wait for tested FIELD_ACCESS event 185 log.display("Waiting for FIELD_ACCESS event received"); 186 waitForTestedEvent(); 187 log.display(" ... event received"); 188 log.display(""); 189 190 // clear tested request for FIELD_ACCESS event 191 log.display("Clearing request for tested event"); 192 clearTestedRequest(); 193 log.display(" ... request removed"); 194 195 // finish debuggee after testing 196 log.display("\n>>> Finishing debuggee \n"); 197 198 // resume debuggee 199 log.display("Resuming debuggee"); 200 debugee.resume(); 201 log.display(" ... debuggee resumed"); 202 203 // wait for debuggee exited 204 log.display("Waiting for VM_DEATH event"); 205 debugee.waitForVMDeath(); 206 dead = true; 207 log.display(" ... VM_DEATH event received"); 208 209 } catch (Failure e) { 210 log.complain("TEST FAILED: " + e.getMessage()); 211 success = false; 212 } catch (Exception e) { 213 e.printStackTrace(out); 214 log.complain("Caught unexpected exception while running the test:\n\t" + e); 215 success = false; 216 } finally { 217 // quit debugee 218 log.display("\n>>> Finishing test \n"); 219 quitDebugee(); 220 } 221 222 // check test results 223 if (!success) { 224 log.complain("TEST FAILED"); 225 return FAILED; 226 } 227 228 out.println("TEST PASSED"); 229 return PASSED; 230 231 } 232 233 /** 234 * Get debuggee prepared for testing and obtain required data. 235 */ prepareForTest()236 void prepareForTest() { 237 // wait for tested class loaded 238 log.display("Waiting for tested class loaded:\n\t" + TESTED_CLASS_NAME); 239 testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL); 240 log.display(" ... class loaded with classID: " + testedClassID); 241 log.display(""); 242 243 // get fieldID for the tested field 244 log.display("Getting tested fieldID for field name: " + VALUE_FIELD_NAME); 245 testedFieldID = debugee.getClassFieldID(testedClassID, VALUE_FIELD_NAME, true); 246 log.display(" ... got fieldID: " + testedFieldID); 247 248 // get methodID for the tested method 249 log.display("Getting tested methodID for method name: " + TESTED_METHOD_NAME); 250 testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true); 251 log.display(" ... got methodID: " + testedMethodID); 252 253 // get codeIndex for field access line 254 log.display("Getting codeIndex for field acccess line: " + FIELD_ACCESS_LINE); 255 long codeIndex = debugee.getCodeIndex(testedClassID, testedMethodID, FIELD_ACCESS_LINE); 256 log.display(" ... got index: " + codeIndex); 257 258 // create location for method entry line 259 log.display("Creating location for field access line"); 260 testedLocation = new JDWP.Location(JDWP.TypeTag.CLASS, testedClassID, 261 testedMethodID, codeIndex); 262 log.display(" ... got location: " + testedLocation); 263 log.display(""); 264 265 // wait for breakpoint reached 266 log.display("Waiting for breakpoint reached at: " 267 + BREAKPOINT_METHOD_NAME + ":" + BREAKPOINT_LINE); 268 testedThreadID = debugee.waitForBreakpointReached(testedClassID, 269 BREAKPOINT_METHOD_NAME, 270 BREAKPOINT_LINE, 271 JDWP.SuspendPolicy.ALL); 272 log.display(" ... breakpoint reached with threadID: " + testedThreadID); 273 log.display(""); 274 275 // get objectID of the tested object from static field 276 log.display("Getting tested objectID from static field: " + OBJECT_FIELD_NAME); 277 JDWP.Value value = debugee.getStaticFieldValue(testedClassID, OBJECT_FIELD_NAME, JDWP.Tag.OBJECT); 278 testedObjectID = ((Long)value.getValue()).longValue(); 279 log.display(" ... got objectID: " + testedObjectID); 280 } 281 282 /** 283 * Make request for tested FIELD_ACCESS event. 284 */ requestTestedEvent()285 void requestTestedEvent() { 286 Failure failure = new Failure("Error occured while makind request for tested event"); 287 288 // create command packet and fill requred out data 289 log.display("Create command packet: " + "EventRequest.Set"); 290 CommandPacket command = new CommandPacket(JDWP.Command.EventRequest.Set); 291 log.display(" eventKind: " + TESTED_EVENT_KIND); 292 command.addByte(TESTED_EVENT_KIND); 293 log.display(" eventPolicy: " + TESTED_EVENT_SUSPEND_POLICY); 294 command.addByte(TESTED_EVENT_SUSPEND_POLICY); 295 log.display(" modifiers: " + 1); 296 command.addInt(1); 297 log.display(" modKind: " + JDWP.EventModifierKind.FIELD_ONLY + " (FIELD_ONLY)"); 298 command.addByte(JDWP.EventModifierKind.FIELD_ONLY); 299 log.display(" classID: " + testedClassID); 300 command.addReferenceTypeID(testedClassID); 301 log.display(" fieldID: " + testedFieldID); 302 command.addFieldID(testedFieldID); 303 /* 304 log.display(" modifiers: " + 1); 305 command.addInt(1); 306 log.display(" modKind: " + JDWP.EventModifierKind.CLASS_ONLY + " (CLASS_ONLY)"); 307 command.addByte(JDWP.EventModifierKind.CLASS_ONLY); 308 log.display(" classID: " + testedClassID); 309 command.addReferenceTypeID(testedClassID); 310 */ 311 command.setLength(); 312 log.display(" ... command packet composed"); 313 log.display(""); 314 315 // send command packet to debugee 316 try { 317 log.display("Sending command packet:\n" + command); 318 transport.write(command); 319 log.display(" ... command packet sent"); 320 } catch (IOException e) { 321 log.complain("Unable to send command packet:\n\t" + e); 322 success = false; 323 throw failure; 324 } 325 log.display(""); 326 327 // receive reply packet from debugee 328 ReplyPacket reply = new ReplyPacket(); 329 try { 330 log.display("Waiting for reply packet"); 331 transport.read(reply); 332 log.display(" ... packet received:\n" + reply); 333 } catch (IOException e) { 334 log.complain("Unable to read reply packet:\n\t" + e); 335 success = false; 336 throw failure; 337 } 338 log.display(""); 339 340 // check reply packet header 341 try{ 342 log.display("Checking header of reply packet"); 343 reply.checkHeader(command.getPacketID()); 344 log.display(" ... packet header is correct"); 345 } catch (BoundException e) { 346 log.complain("Bad header of reply packet:\n\t" + e.getMessage()); 347 success = false; 348 throw failure; 349 } 350 351 // start parsing reply packet data 352 log.display("Parsing reply packet:"); 353 reply.resetPosition(); 354 355 // extract requestID 356 int requestID = 0; 357 try { 358 requestID = reply.getInt(); 359 log.display(" requestID: " + requestID); 360 } catch (BoundException e) { 361 log.complain("Unable to extract requestID from request reply packet:\n\t" 362 + e.getMessage()); 363 success = false; 364 throw failure; 365 } 366 367 // check requestID 368 if (requestID == 0) { 369 log.complain("Unexpected null requestID returned: " + requestID); 370 success = false; 371 throw failure; 372 } 373 374 eventRequestID = requestID; 375 376 // check for extra data in reply packet 377 if (!reply.isParsed()) { 378 log.complain("Extra trailing bytes found in request reply packet at: " 379 + reply.offsetString()); 380 success = false; 381 } 382 383 log.display(" ... reply packet parsed"); 384 } 385 386 /** 387 * Clear request for tested FIELD_ACCESS event. 388 */ clearTestedRequest()389 void clearTestedRequest() { 390 Failure failure = new Failure("Error occured while clearing request for tested event"); 391 392 // create command packet and fill requred out data 393 log.display("Create command packet: " + "EventRequest.Clear"); 394 CommandPacket command = new CommandPacket(JDWP.Command.EventRequest.Clear); 395 log.display(" event: " + TESTED_EVENT_KIND); 396 command.addByte(TESTED_EVENT_KIND); 397 log.display(" requestID: " + eventRequestID); 398 command.addInt(eventRequestID); 399 log.display(" ... command packet composed"); 400 log.display(""); 401 402 // send command packet to debugee 403 try { 404 log.display("Sending command packet:\n" + command); 405 transport.write(command); 406 log.display(" ... command packet sent"); 407 } catch (IOException e) { 408 log.complain("Unable to send command packet:\n\t" + e); 409 success = false; 410 throw failure; 411 } 412 log.display(""); 413 414 ReplyPacket reply = new ReplyPacket(); 415 416 // receive reply packet from debugee 417 try { 418 log.display("Waiting for reply packet"); 419 transport.read(reply); 420 log.display(" ... packet received:\n" + reply); 421 } catch (IOException e) { 422 log.complain("Unable to read reply packet:\n\t" + e); 423 success = false; 424 throw failure; 425 } 426 427 // check reply packet header 428 try{ 429 log.display("Checking header of reply packet"); 430 reply.checkHeader(command.getPacketID()); 431 log.display(" ... packet header is correct"); 432 } catch (BoundException e) { 433 log.complain("Bad header of reply packet:\n\t" + e.getMessage()); 434 success = false; 435 throw failure; 436 } 437 438 // start parsing reply packet data 439 log.display("Parsing reply packet:"); 440 reply.resetPosition(); 441 442 log.display(" no data"); 443 444 // check for extra data in reply packet 445 if (!reply.isParsed()) { 446 log.complain("Extra trailing bytes found in request reply packet at: " 447 + reply.offsetString()); 448 success = false; 449 } 450 451 log.display(" ... reply packet parsed"); 452 } 453 454 /** 455 * Wait for tested FIELD_ACCESS event. 456 */ waitForTestedEvent()457 void waitForTestedEvent() { 458 459 EventPacket eventPacket = null; 460 461 // receive reply packet from debugee 462 try { 463 log.display("Waiting for event packet"); 464 eventPacket = debugee.getEventPacket(timeout); 465 log.display(" ... event packet received:\n" + eventPacket); 466 } catch (IOException e) { 467 log.complain("Unable to read tested event packet:\n\t" + e); 468 success = false; 469 return; 470 } 471 log.display(""); 472 473 // check reply packet header 474 try{ 475 log.display("Checking header of event packet"); 476 eventPacket.checkHeader(); 477 log.display(" ... packet header is correct"); 478 } catch (BoundException e) { 479 log.complain("Bad header of tested event packet:\n\t" 480 + e.getMessage()); 481 success = false; 482 return; 483 } 484 485 // start parsing reply packet data 486 log.display("Parsing event packet:"); 487 eventPacket.resetPosition(); 488 489 // get suspendPolicy value 490 byte suspendPolicy = 0; 491 try { 492 suspendPolicy = eventPacket.getByte(); 493 log.display(" suspendPolicy: " + suspendPolicy); 494 } catch (BoundException e) { 495 log.complain("Unable to get suspendPolicy value from tested event packet:\n\t" 496 + e.getMessage()); 497 success = false; 498 return; 499 } 500 501 // check suspendPolicy value 502 if (suspendPolicy != TESTED_EVENT_SUSPEND_POLICY) { 503 log.complain("Unexpected SuspendPolicy in tested event packet: " + 504 suspendPolicy + " (expected: " + TESTED_EVENT_SUSPEND_POLICY + ")"); 505 success = false; 506 } 507 508 // get events count 509 int events = 0; 510 try { 511 events = eventPacket.getInt(); 512 log.display(" events: " + events); 513 } catch (BoundException e) { 514 log.complain("Unable to get events count from tested event packet:\n\t" 515 + e.getMessage()); 516 success = false; 517 return; 518 } 519 520 // check events count 521 if (events < 0) { 522 log.complain("Negative value of events number in tested event packet: " + 523 events + " (expected: " + 1 + ")"); 524 success = false; 525 } else if (events != 1) { 526 log.complain("Invalid number of events in tested event packet: " + 527 events + " (expected: " + 1 + ")"); 528 success = false; 529 } 530 531 // extract each event 532 long eventThreadID = 0; 533 for (int i = 0; i < events; i++) { 534 log.display(" event #" + i + ":"); 535 536 // get eventKind 537 byte eventKind = 0; 538 try { 539 eventKind = eventPacket.getByte(); 540 log.display(" eventKind: " + eventKind); 541 } catch (BoundException e) { 542 log.complain("Unable to get eventKind of event #" + i + " from tested event packet:\n\t" 543 + e.getMessage()); 544 success = false; 545 return; 546 } 547 548 // check eventKind 549 if (eventKind == JDWP.EventKind.VM_DEATH) { 550 log.complain("Unexpected VM_DEATH event received: " + 551 eventKind + " (expected: " + JDWP.EventKind.FIELD_ACCESS + ")"); 552 dead = true; 553 success = false; 554 return; 555 } else if (eventKind != JDWP.EventKind.FIELD_ACCESS) { 556 log.complain("Unexpected eventKind of event " + i + " in tested event packet: " + 557 eventKind + " (expected: " + JDWP.EventKind.FIELD_ACCESS + ")"); 558 success = false; 559 return; 560 } 561 562 // get requestID 563 int requestID = 0; 564 try { 565 requestID = eventPacket.getInt(); 566 log.display(" requestID: " + requestID); 567 } catch (BoundException e) { 568 log.complain("Unable to get requestID of event #" + i + " from tested event packet:\n\t" 569 + e.getMessage()); 570 success = false; 571 return; 572 } 573 574 // check requestID 575 if (requestID != eventRequestID) { 576 log.complain("Unexpected requestID of event " + i + " in tested event packet: " + 577 requestID + " (expected: " + eventRequestID + ")"); 578 success = false; 579 } 580 581 // get threadID 582 long threadID = 0; 583 try { 584 threadID = eventPacket.getObjectID(); 585 log.display(" threadID: " + threadID); 586 } catch (BoundException e) { 587 log.complain("Unable to get threadID of event #" + i + " from tested event packet:\n\t" 588 + e.getMessage()); 589 success = false; 590 return; 591 } 592 593 // check threadID 594 if (threadID != testedThreadID) { 595 log.complain("Unexpected threadID of event " + i + " in tested event packet: " + 596 threadID + " (expected: " + testedThreadID + ")"); 597 success = false; 598 } 599 600 // get location 601 JDWP.Location location = null; 602 try { 603 location = eventPacket.getLocation(); 604 log.display(" location: " + location); 605 } catch (BoundException e) { 606 log.complain("Unable to get location of event #" + i + " from tested event packet:\n\t" 607 + e.getMessage()); 608 success = false; 609 return; 610 } 611 612 // check location 613 checkLocation(location, testedLocation, i, FIELD_ACCESS_LINE); 614 615 // get type tag 616 byte refTypeTag = 0; 617 try { 618 refTypeTag = eventPacket.getByte(); 619 log.display(" refTypeTag: " + refTypeTag); 620 } catch (BoundException e) { 621 log.complain("Unable to get reftypetag of event #" + i + " from tested event packet:\n\t" 622 + e.getMessage()); 623 success = false; 624 return; 625 } 626 627 // check type tag 628 if (refTypeTag != JDWP.TypeTag.CLASS) { 629 log.complain("Unexpected refTypeTag of event " + i + " in tested event packet: " + 630 refTypeTag + " (expected: " + JDWP.TypeTag.CLASS + ")"); 631 success = false; 632 } 633 634 // get typeID 635 long typeID = 0; 636 try { 637 typeID = eventPacket.getReferenceTypeID(); 638 log.display(" typeID: " + typeID); 639 } catch (BoundException e) { 640 log.complain("Unable to get typeID of event #" + i + " from tested event packet:\n\t" 641 + e.getMessage()); 642 success = false; 643 return; 644 } 645 646 // check typeID 647 if (typeID != testedClassID) { 648 log.complain("Unexpected typeID of event " + i + " in tested event packet: " + 649 typeID + " (expected: " + testedClassID + ")"); 650 success = false; 651 } 652 653 // get fieldID 654 long fieldID = 0; 655 try { 656 fieldID = eventPacket.getFieldID(); 657 log.display(" fieldID: " + fieldID); 658 } catch (BoundException e) { 659 log.complain("Unable to get fieldID of event #" + i + " from tested event packet:\n\t" 660 + e.getMessage()); 661 success = false; 662 return; 663 } 664 665 // check fieldID 666 if (fieldID != testedFieldID) { 667 log.complain("Unexpected fieldID of event " + i + " in tested event packet: " + 668 fieldID + " (expected: " + testedFieldID + ")"); 669 success = false; 670 } 671 672 // get object tag 673 byte objectTag = 0; 674 try { 675 objectTag = eventPacket.getByte(); 676 log.display(" objectTag: " + objectTag); 677 } catch (BoundException e) { 678 log.complain("Unable to get object tag of event #" + i + " from tested event packet:\n\t" 679 + e.getMessage()); 680 success = false; 681 return; 682 } 683 684 // check object tag 685 if (objectTag != JDWP.Tag.OBJECT) { 686 log.complain("Unexpected object tag of event " + i + " in tested event packet: " + 687 objectTag + " (expected: " + JDWP.Tag.OBJECT + ")"); 688 success = false; 689 } 690 691 // get objectID 692 long objectID = 0; 693 try { 694 objectID = eventPacket.getObjectID(); 695 log.display(" objectID: " + objectID); 696 } catch (BoundException e) { 697 log.complain("Unable to get objectID of event #" + i + " from tested event packet:\n\t" 698 + e.getMessage()); 699 success = false; 700 return; 701 } 702 703 // check objectID 704 if (objectID != 0) { 705 log.complain("Unexpected objectID of event " + i + " in tested event packet: " + 706 objectID + " (expected: " + 0 + ")"); 707 success = false; 708 } 709 } 710 711 // check for extra data in event packet 712 if (!eventPacket.isParsed()) { 713 log.complain("Extra trailing bytes found in event packet at: " 714 + eventPacket.offsetString()); 715 success = false; 716 } 717 718 log.display(" ... event packet parsed"); 719 } 720 721 /** 722 * Check if given location is equal to the expected one. 723 */ checkLocation(JDWP.Location location, JDWP.Location expectedLocation, int eventNumber, int expectedLine)724 void checkLocation(JDWP.Location location, JDWP.Location expectedLocation, 725 int eventNumber, int expectedLine) { 726 if (location.getTag() != expectedLocation.getTag()) { 727 log.complain("Unexpected class tag of location of event " 728 + eventNumber + " in tested event packet: " + location.getTag() 729 + " (expected: " + expectedLocation.getTag() + ")"); 730 success = false; 731 } 732 if (location.getClassID() != expectedLocation.getClassID()) { 733 log.complain("Unexpected classID of location of event " 734 + eventNumber + " in tested event packet: " + location.getClassID() 735 + " (expected: " + expectedLocation.getClassID() + ")"); 736 success = false; 737 } 738 if (location.getMethodID() != expectedLocation.getMethodID()) { 739 log.complain("Unexpected methodID of location of event " 740 + eventNumber + " in tested event packet: " + location.getMethodID() 741 + " (expected: " + expectedLocation.getMethodID() + ")"); 742 success = false; 743 } 744 if (location.getIndex() != expectedLocation.getIndex()) { 745 /* 746 log.complain("Unexpected codeIndex of location of event " + i 747 + " in tested event packet: " + location.getIndex() 748 + " (expected: " + expectedLocation.getIndex() + ")"); 749 success = false; 750 */ 751 try { 752 // find approximate line number for location 753 int lineNumber = debugee.getLineNumber(location, true); 754 if (lineNumber != expectedLine) { 755 log.complain("Unexpected line number of location of event " 756 + eventNumber + " in tested event packet: " + lineNumber 757 + " (expected: " + expectedLine + ")"); 758 success = false; 759 } else { 760 log.display("Unexpected codeIndex of location: " + location.getIndex() 761 + " (expected: " + expectedLocation.getIndex() + ")"); 762 log.display("Though line number of catch location is as expected: " 763 + expectedLine); 764 } 765 } catch (Failure e) { 766 log.complain("Unable to get line number for location of event " 767 + eventNumber + " in tested event packet:\n\t" + e.getMessage()); 768 success = false; 769 } 770 } 771 } 772 773 /** 774 * Disconnect debuggee and wait for it exited. 775 */ quitDebugee()776 void quitDebugee() { 777 if (debugee == null) 778 return; 779 780 // disconnect debugee 781 if (!dead) { 782 try { 783 log.display("Disconnecting debuggee"); 784 debugee.dispose(); 785 log.display(" ... debuggee disconnected"); 786 } catch (Failure e) { 787 log.display("Failed to finally disconnect debuggee:\n\t" 788 + e.getMessage()); 789 } 790 } 791 792 // wait for debugee exited 793 log.display("Waiting for debuggee exit"); 794 int code = debugee.waitFor(); 795 log.display(" ... debuggee exited with exit code: " + code); 796 797 // analize debugee exit status code 798 if (code != JCK_STATUS_BASE + PASSED) { 799 log.complain("Debuggee FAILED with exit code: " + code); 800 success = false; 801 } 802 } 803 804 } 805