Source Code Cross Referenced for CombinedEventsTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » jdwp » Events » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.jpda.tests.jdwp.Events 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:
0018:        /**
0019:         * @author Aleksander V. Budniy
0020:         * @version $Revision: 0.0 $
0021:         */
0022:
0023:        /**
0024:         * Created on 26.05.2006
0025:         */package org.apache.harmony.jpda.tests.jdwp.Events;
0026:
0027:        import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
0028:        import org.apache.harmony.jpda.tests.framework.jdwp.EventMod;
0029:        import org.apache.harmony.jpda.tests.framework.jdwp.EventPacket;
0030:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
0031:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
0032:        import org.apache.harmony.jpda.tests.framework.jdwp.Location;
0033:        import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
0034:        import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
0035:        import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
0036:
0037:        /**
0038:         * JDWP Unit test for possible combined (co-located) events:
0039:         * METHOD_ENTRY, SINGLE_STEP, BREAKPOINT, METHOD_EXIT.
0040:         */
0041:        public class CombinedEventsTest extends CombinedEventsTestCase {
0042:
0043:            private String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/Events/CombinedEventsDebuggee;";
0044:
0045:            private String methodForEvents = "sampleMethod";
0046:
0047:            private String methodEntryClassNameRegexp = "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEventsDebuggee";
0048:
0049:            private boolean eventVmDeathReceived = false;
0050:            private boolean eventMethodExitReceived = false;
0051:
0052:            protected String getDebuggeeClassName() {
0053:                return CombinedEventsDebuggee.class.getName();
0054:            }
0055:
0056:            public static void main(String[] args) {
0057:                junit.textui.TestRunner.run(CombinedEventsTest.class);
0058:            }
0059:
0060:            /**
0061:             * Test starts <code>CombinedEventsDebuggee</code> class.
0062:             * Then sets requests for expected events at the beginning
0063:             * (location = 0) of debuggee's method 'sampleMethod()'. Expected events are:
0064:             * METHOD_ENTRY, SINGLE_STEP, BREAKPOINT. After setting requests the test starts
0065:             * to receive single SINGLE_STEP events, until debuggee achieves beginning
0066:             * of sampleMethod(). Then test checks, that three expected events were
0067:             * grouped on one location and sent in one event packet. At the end, test cleans
0068:             * request for SINGLE_STEP event, resumes debuggee and checks that only
0069:             * VM_DEATH event is received after that.
0070:             */
0071:
0072:            public void testCombinedEvents_01() {
0073:                logWriter.println("==> testCombinedEvents_01 started");
0074:
0075:                byte[] EXPECTED_EVENTS_ARRAY = {
0076:                        JDWPConstants.EventKind.METHOD_ENTRY,
0077:                        JDWPConstants.EventKind.SINGLE_STEP,
0078:                        JDWPConstants.EventKind.BREAKPOINT, };
0079:
0080:                String debuggeeMainThreadName = synchronizer.receiveMessage();
0081:
0082:                long debuggeeClassID = debuggeeWrapper.vmMirror
0083:                        .getClassID(debuggeeSignature);
0084:                logWriter.println("=> debuggeeClassID = " + debuggeeClassID);
0085:
0086:                long threadID = debuggeeWrapper.vmMirror
0087:                        .getThreadID(debuggeeMainThreadName);
0088:                logWriter.println("=> threadID = " + threadID);
0089:
0090:                long runMethodID = debuggeeWrapper.vmMirror.getMethodID(
0091:                        debuggeeClassID, "run");
0092:                logWriter.println("=> runMethodID = " + runMethodID);
0093:
0094:                logWriter.println("");
0095:                logWriter.println("=> Info for tested method '"
0096:                        + methodForEvents + "':");
0097:                long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(
0098:                        debuggeeClassID, methodForEvents);
0099:                if (testedMethodID == -1) {
0100:                    String failureMessage = "## FAILURE: Can NOT get MethodID for class '"
0101:                            + getDebuggeeClassName()
0102:                            + "'; Method name = "
0103:                            + methodForEvents;
0104:                    printErrorAndFail(failureMessage);
0105:                }
0106:                logWriter.println("=> testedMethodID = " + testedMethodID);
0107:                printMethodLineTable(debuggeeClassID, null, methodForEvents);
0108:
0109:                // set requests for events that will be checked
0110:                logWriter.println("");
0111:                logWriter
0112:                        .println("=> Set request for BREAKPOINT event in debuggee: "
0113:                                + getDebuggeeClassName()
0114:                                + ", beginning of method: " + methodForEvents);
0115:                Location combinedEventsLocation = getMethodEntryLocation(
0116:                        debuggeeClassID, methodForEvents);
0117:                if (combinedEventsLocation == null) {
0118:                    String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '"
0119:                            + methodForEvents + "'";
0120:                    printErrorAndFail(failureMessage);
0121:                }
0122:                ReplyPacket reply = debuggeeWrapper.vmMirror
0123:                        .setBreakpoint(combinedEventsLocation);
0124:                int breakpointRequestID = reply.getNextValueAsInt();
0125:                logWriter.println("=> Breakpoint requestID = "
0126:                        + breakpointRequestID);
0127:
0128:                logWriter
0129:                        .println("=> Set request for METHOD_ENTRY event in debuggee: "
0130:                                + getDebuggeeClassName()
0131:                                + ", method: "
0132:                                + methodForEvents);
0133:                reply = debuggeeWrapper.vmMirror
0134:                        .setMethodEntry(methodEntryClassNameRegexp);
0135:                checkReplyPacket(reply, "Set METHOD_ENTRY event");
0136:                int methodEntryRequestID = reply.getNextValueAsInt();
0137:                logWriter.println("=> METHOD_ENTRY requestID = "
0138:                        + methodEntryRequestID);
0139:
0140:                logWriter
0141:                        .println("=> Set request for SINGLE_STEP event in class "
0142:                                + debuggeeSignature);
0143:                CommandPacket setRequestCommand = new CommandPacket(
0144:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
0145:                        JDWPCommands.EventRequestCommandSet.SetCommand);
0146:                setRequestCommand
0147:                        .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP);
0148:                setRequestCommand
0149:                        .setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
0150:                setRequestCommand.setNextValueAsInt(2);
0151:                setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step);
0152:                setRequestCommand.setNextValueAsThreadID(threadID);
0153:                setRequestCommand.setNextValueAsInt(JDWPConstants.StepSize.MIN);
0154:                setRequestCommand
0155:                        .setNextValueAsInt(JDWPConstants.StepDepth.INTO);
0156:                setRequestCommand
0157:                        .setNextValueAsByte(EventMod.ModKind.ClassOnly);
0158:                setRequestCommand
0159:                        .setNextValueAsReferenceTypeID(debuggeeClassID);
0160:
0161:                ReplyPacket setRequestReply = debuggeeWrapper.vmMirror
0162:                        .performCommand(setRequestCommand);
0163:                checkReplyPacket(setRequestReply, "EventRequest::Set command");
0164:                int stepRequestID = setRequestReply.getNextValueAsInt();
0165:                logWriter
0166:                        .println("=> SINGLE_STEP requestID = " + stepRequestID);
0167:
0168:                logWriter.println("");
0169:                logWriter
0170:                        .println("=> Send SGNL_CONTINUE signal to debuggee...");
0171:                synchronizer
0172:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
0173:
0174:                // ignore SINGLE_STEP events until receiving combined METHOD_ENTRY,
0175:                // SINGLE_STEP, BREAKPOINT events
0176:                logWriter
0177:                        .println("=> Try to receive and check combined events: "
0178:                                + " METHOD_ENTRY, SINGLE_STEP, BREAKPOINT events; ignore single SINGLE_STEP event");
0179:                receiveAndCheckEvents(EXPECTED_EVENTS_ARRAY,
0180:                        combinedEventsLocation);
0181:                if (eventVmDeathReceived) {
0182:                    logWriter
0183:                            .println("==> testCombinedEvents001 is FINISHing as VM_DEATH is received!");
0184:                    return;
0185:                }
0186:
0187:                logWriter.println("");
0188:                logWriter.println("=> Clean request for METHOD_ENTRY event...");
0189:                ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent(
0190:                        JDWPConstants.EventKind.METHOD_ENTRY,
0191:                        methodEntryRequestID);
0192:                checkReplyPacket(clearReply, "EventRequest::Clear");
0193:
0194:                logWriter.println("");
0195:                logWriter.println("=> Clean request for SINGLE_STEP event...");
0196:                clearReply = debuggeeWrapper.vmMirror.clearEvent(
0197:                        JDWPConstants.EventKind.SINGLE_STEP, stepRequestID);
0198:                checkReplyPacket(clearReply, "EventRequest::Clear");
0199:
0200:                logWriter.println("=> Resume debuggee");
0201:                debuggeeWrapper.vmMirror.resume();
0202:
0203:                // check that no other events, except VM_DEATH, will be received
0204:                checkVMDeathEvent();
0205:
0206:                logWriter.println("");
0207:                logWriter.println("==> testCombinedEvents_01 PASSED");
0208:            }
0209:
0210:            /**
0211:             * Test starts <code>CombinedEventsDebuggee</code> class, sets a
0212:             * breakpoint at the beginning of method sampleMethod() of debuggee, waits
0213:             * for this breakpoint. Then sets requests for expected events at the end of
0214:             * debuggee's method sampleMethod(). Expected events are: METHOD_EXIT,
0215:             * SINGLE_STEP, BREAKPOINT. Then resumes debuggee and starts to receive
0216:             * single SINGLE_STEP events, until debuggee achieves end of sampleMethod().
0217:             * Then test checks, that three expected events were grouped on one location
0218:             * and sent in one packet. At the end, test cleans request for SINGLE_STEP
0219:             * event, resumes debuggee and checks that only VM_DEATH event is received
0220:             * after that.
0221:             */
0222:
0223:            public void testCombinedEvents_02() {
0224:                logWriter.println("==> testCombinedEvents_02 started");
0225:
0226:                byte[] EXPECTED_EVENTS_ARRAY = {
0227:                        JDWPConstants.EventKind.SINGLE_STEP,
0228:                        JDWPConstants.EventKind.BREAKPOINT,
0229:                        JDWPConstants.EventKind.METHOD_EXIT, };
0230:
0231:                synchronizer
0232:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
0233:
0234:                long debuggeeClassID = debuggeeWrapper.vmMirror
0235:                        .getClassID(debuggeeSignature);
0236:                logWriter.println("=> debuggeeClassID = " + debuggeeClassID);
0237:
0238:                long runMethodID = debuggeeWrapper.vmMirror.getMethodID(
0239:                        debuggeeClassID, "run");
0240:                logWriter.println("=> runMethodID = " + runMethodID);
0241:
0242:                logWriter.println("");
0243:                logWriter.println("=> Info for tested method '"
0244:                        + methodForEvents + "':");
0245:                long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(
0246:                        debuggeeClassID, methodForEvents);
0247:                if (testedMethodID == -1) {
0248:                    String failureMessage = "## FAILURE: Can NOT get MethodID for class '"
0249:                            + getDebuggeeClassName()
0250:                            + "'; Method name = "
0251:                            + methodForEvents;
0252:                    printErrorAndFail(failureMessage);
0253:                }
0254:                logWriter.println("=> testedMethodID = " + testedMethodID);
0255:                printMethodLineTable(debuggeeClassID, null, methodForEvents);
0256:
0257:                logWriter.println("");
0258:                logWriter.println("=> Set breakpoint at the beginning of "
0259:                        + methodForEvents);
0260:                long requestID = debuggeeWrapper.vmMirror
0261:                        .setBreakpointAtMethodBegin(debuggeeClassID,
0262:                                methodForEvents);
0263:                synchronizer
0264:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
0265:
0266:                logWriter.println("=> Wait for breakpoint event..");
0267:
0268:                long threadID = debuggeeWrapper.vmMirror
0269:                        .waitForBreakpoint(requestID);
0270:                logWriter.println("=> threadID = " + threadID);
0271:
0272:                // set requests for events that will be checked
0273:                logWriter
0274:                        .println("=> Set request for BREAKPOINT event in debuggee: "
0275:                                + getDebuggeeClassName()
0276:                                + ", at end of method: " + methodForEvents);
0277:                Location combinedEventsLocation = getMethodEndLocation(
0278:                        debuggeeClassID, methodForEvents);
0279:                if (combinedEventsLocation == null) {
0280:                    String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '"
0281:                            + methodForEvents + "'";
0282:                    printErrorAndFail(failureMessage);
0283:                }
0284:
0285:                ReplyPacket reply = debuggeeWrapper.vmMirror
0286:                        .setBreakpoint(combinedEventsLocation);
0287:                int breakpointRequestID = reply.getNextValueAsInt();
0288:                logWriter.println("=> Breakpoint requestID = "
0289:                        + breakpointRequestID);
0290:
0291:                logWriter
0292:                        .println("=> Set request for METHOD_EXIT event in debuggee: "
0293:                                + getDebuggeeClassName()
0294:                                + ", method: "
0295:                                + methodForEvents);
0296:                reply = debuggeeWrapper.vmMirror
0297:                        .setMethodExit(methodEntryClassNameRegexp);
0298:                checkReplyPacket(reply, "EventRequest::Set command");
0299:                int methodExitRequestID = reply.getNextValueAsInt();
0300:                logWriter.println("=> METHOD_EXIT requestID = "
0301:                        + methodExitRequestID);
0302:
0303:                logWriter
0304:                        .println("=> Set request for SINGLE_STEP event in class "
0305:                                + debuggeeSignature);
0306:                CommandPacket setRequestCommand = new CommandPacket(
0307:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
0308:                        JDWPCommands.EventRequestCommandSet.SetCommand);
0309:                setRequestCommand
0310:                        .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP);
0311:                setRequestCommand
0312:                        .setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
0313:                setRequestCommand.setNextValueAsInt(2);
0314:                setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step);
0315:                setRequestCommand.setNextValueAsThreadID(threadID);
0316:                setRequestCommand.setNextValueAsInt(JDWPConstants.StepSize.MIN);
0317:                setRequestCommand
0318:                        .setNextValueAsInt(JDWPConstants.StepDepth.INTO);
0319:                setRequestCommand
0320:                        .setNextValueAsByte(EventMod.ModKind.ClassOnly);
0321:                setRequestCommand
0322:                        .setNextValueAsReferenceTypeID(debuggeeClassID);
0323:
0324:                ReplyPacket setRequestReply = debuggeeWrapper.vmMirror
0325:                        .performCommand(setRequestCommand);
0326:                checkReplyPacket(setRequestReply, "EventRequest::Set command");
0327:                int stepRequestID = setRequestReply.getNextValueAsInt();
0328:                logWriter
0329:                        .println("=> SINGLE_STEP requestID = " + stepRequestID);
0330:
0331:                logWriter.println("");
0332:                logWriter.println("=> Resume debuggee");
0333:                debuggeeWrapper.vmMirror.resume();
0334:
0335:                // ignore SINGLE_STEP events until receiving combined METHOD_EXIT,
0336:                // SINGLE_STEP, BREAKPOINT events
0337:                logWriter
0338:                        .println("=> Try to receive and check combined events: "
0339:                                + " METHOD_EXIT, SINGLE_STEP, BREAKPOINT events; ignore single SINGLE_STEP event");
0340:                receiveAndCheckEvents(EXPECTED_EVENTS_ARRAY,
0341:                        combinedEventsLocation);
0342:                if (eventVmDeathReceived) {
0343:                    logWriter
0344:                            .println("==> testCombinedEvents002 is FINISHing as VM_DEATH is received!");
0345:                    return;
0346:                }
0347:
0348:                if (eventMethodExitReceived) {
0349:                    logWriter.println("");
0350:                    logWriter
0351:                            .println("=> Clean request for METHOD_EXIT event...");
0352:                    ReplyPacket clearReply = debuggeeWrapper.vmMirror
0353:                            .clearEvent(JDWPConstants.EventKind.METHOD_EXIT,
0354:                                    methodExitRequestID);
0355:                    checkReplyPacket(clearReply, "EventRequest::Clear");
0356:                }
0357:
0358:                logWriter.println("");
0359:                logWriter.println("=> Clean request for SINGLE_STEP event...");
0360:                ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent(
0361:                        JDWPConstants.EventKind.SINGLE_STEP, stepRequestID);
0362:                checkReplyPacket(clearReply, "EventRequest::Clear");
0363:
0364:                logWriter.println("=> Resume debuggee");
0365:                debuggeeWrapper.vmMirror.resume();
0366:
0367:                // check that no other events, except VM_DEATH, will be received
0368:                checkVMDeathEvent();
0369:
0370:                logWriter.println("");
0371:                logWriter.println("==> testCombinedEvents_02 PASSED");
0372:            }
0373:
0374:            /**
0375:             * Test starts <code>CombinedEventsDebuggee</code> class.
0376:             * Then sets requests for expected events at the beginning
0377:             * (location = 0) of debuggee's method 'sampleMethod()'. Expected events are:
0378:             * METHOD_ENTRY, SINGLE_STEP. After setting requests the test starts
0379:             * to receive single SINGLE_STEP events, until debuggee achieves beginning of
0380:             * sampleMethod(). Then test checks, that three expected events were grouped
0381:             * on one location and sent in one packet. At the end, test cleans request
0382:             * for SINGLE_STEP event, resumes debuggee and checks that only VM_DEATH
0383:             * event is received after that.
0384:             */
0385:
0386:            public void testCombinedEvents_03() {
0387:                logWriter.println("==> testCombinedEvents_03 started");
0388:
0389:                byte[] EXPECTED_EVENTS_ARRAY = {
0390:                        JDWPConstants.EventKind.METHOD_ENTRY,
0391:                        JDWPConstants.EventKind.SINGLE_STEP, };
0392:
0393:                String debuggeeMainThreadName = synchronizer.receiveMessage();
0394:
0395:                long debuggeeClassID = debuggeeWrapper.vmMirror
0396:                        .getClassID(debuggeeSignature);
0397:                logWriter.println("=> debuggeeClassID = " + debuggeeClassID);
0398:
0399:                long threadID = debuggeeWrapper.vmMirror
0400:                        .getThreadID(debuggeeMainThreadName);
0401:                logWriter.println("=> threadID = " + threadID);
0402:
0403:                long runMethodID = debuggeeWrapper.vmMirror.getMethodID(
0404:                        debuggeeClassID, "run");
0405:                logWriter.println("=> runMethodID = " + runMethodID);
0406:
0407:                logWriter.println("");
0408:                logWriter.println("=> Info for tested method '"
0409:                        + methodForEvents + "':");
0410:                long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(
0411:                        debuggeeClassID, methodForEvents);
0412:                if (testedMethodID == -1) {
0413:                    String failureMessage = "## FAILURE: Can NOT get MethodID for class '"
0414:                            + getDebuggeeClassName()
0415:                            + "'; Method name = "
0416:                            + methodForEvents;
0417:                    printErrorAndFail(failureMessage);
0418:                }
0419:                logWriter.println("=> testedMethodID = " + testedMethodID);
0420:                printMethodLineTable(debuggeeClassID, null, methodForEvents);
0421:
0422:                // set requests for events that will be checked
0423:
0424:                logWriter
0425:                        .println("=> Set request for METHOD_ENTRY event in debuggee: "
0426:                                + getDebuggeeClassName()
0427:                                + ", method: "
0428:                                + methodForEvents);
0429:                ReplyPacket reply = debuggeeWrapper.vmMirror
0430:                        .setMethodEntry(methodEntryClassNameRegexp);
0431:                checkReplyPacket(reply, "Set METHOD_ENTRY event");
0432:                int methodEntryRequestID = reply.getNextValueAsInt();
0433:                logWriter.println("=> METHOD_ENTRY requestID = "
0434:                        + methodEntryRequestID);
0435:
0436:                logWriter
0437:                        .println("=> Set request for SINGLE_STEP event in class "
0438:                                + debuggeeSignature);
0439:                CommandPacket setRequestCommand = new CommandPacket(
0440:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
0441:                        JDWPCommands.EventRequestCommandSet.SetCommand);
0442:                setRequestCommand
0443:                        .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP);
0444:                setRequestCommand
0445:                        .setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
0446:                setRequestCommand.setNextValueAsInt(2);
0447:                setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step);
0448:                setRequestCommand.setNextValueAsThreadID(threadID);
0449:                setRequestCommand.setNextValueAsInt(JDWPConstants.StepSize.MIN);
0450:                setRequestCommand
0451:                        .setNextValueAsInt(JDWPConstants.StepDepth.INTO);
0452:                setRequestCommand
0453:                        .setNextValueAsByte(EventMod.ModKind.ClassOnly);
0454:                setRequestCommand
0455:                        .setNextValueAsReferenceTypeID(debuggeeClassID);
0456:
0457:                ReplyPacket setRequestReply = debuggeeWrapper.vmMirror
0458:                        .performCommand(setRequestCommand);
0459:                checkReplyPacket(setRequestReply, "EventRequest::Set command");
0460:                int stepRequestID = setRequestReply.getNextValueAsInt();
0461:                logWriter
0462:                        .println("=> SINGLE_STEP requestID = " + stepRequestID);
0463:
0464:                logWriter.println("");
0465:                logWriter
0466:                        .println("=> Send SGNL_CONTINUE signal to debuggee...");
0467:                synchronizer
0468:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
0469:
0470:                Location combinedEventsLocation = getMethodEntryLocation(
0471:                        debuggeeClassID, methodForEvents);
0472:                if (combinedEventsLocation == null) {
0473:                    String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '"
0474:                            + methodForEvents + "'";
0475:                    printErrorAndFail(failureMessage);
0476:                }
0477:                // ignore SINGLE_STEP events until receiving combined METHOD_ENTRY,
0478:                // SINGLE_STEP events
0479:                logWriter
0480:                        .println("=> Try to receive and check combined events: METHOD_ENTRY, SINGLE_STEP events; ignore single SINGLE_STEP event");
0481:                receiveAndCheckEvents(EXPECTED_EVENTS_ARRAY,
0482:                        combinedEventsLocation);
0483:                if (eventVmDeathReceived) {
0484:                    logWriter
0485:                            .println("==> testCombinedEvents003 is FINISHing as VM_DEATH is received!");
0486:                    return;
0487:                }
0488:
0489:                logWriter.println("");
0490:                logWriter.println("=> Clean request for METHOD_ENTRY event...");
0491:                ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent(
0492:                        JDWPConstants.EventKind.METHOD_ENTRY,
0493:                        methodEntryRequestID);
0494:                checkReplyPacket(clearReply, "EventRequest::Clear");
0495:
0496:                logWriter.println("");
0497:                logWriter.println("=> Clean request for SINGLE_STEP event");
0498:                clearReply = debuggeeWrapper.vmMirror.clearEvent(
0499:                        JDWPConstants.EventKind.SINGLE_STEP, stepRequestID);
0500:                checkReplyPacket(clearReply, "EventRequest::Clear");
0501:
0502:                logWriter.println("=> Resume debuggee");
0503:                debuggeeWrapper.vmMirror.resume();
0504:
0505:                // check that no other events, except VM_DEATH, will be received
0506:                checkVMDeathEvent();
0507:
0508:                logWriter.println("");
0509:                logWriter.println("==> testCombinedEvents_03 PASSED");
0510:            }
0511:
0512:            /**
0513:             * Test starts <code>CombinedEventsDebuggee</code> class, sets a
0514:             * breakpoint at the beginning of method sampleMethod() of debuggee, waits
0515:             * for this breakpoint. Then sets requests for expected events at the end of
0516:             * debuggee's method sampleMethod(). Expected events are: METHOD_EXIT,
0517:             * SINGLE_STEP. Then resumes debuggee and starts to receive single
0518:             * SINGLE_STEP events, until debuggee achieves end of sampleMethod(). Then
0519:             * test checks, that three expected events were grouped on one location and
0520:             * sent in one packet. At the end, test cleans request for SINGLE_STEP
0521:             * event, resumes debuggee and checks that only VM_DEATH event is received
0522:             * after that.
0523:             */
0524:
0525:            public void testCombinedEvents_04() {
0526:                logWriter.println("==> testCombinedEvents004 started");
0527:
0528:                byte[] EXPECTED_EVENTS_ARRAY = {
0529:                        JDWPConstants.EventKind.SINGLE_STEP,
0530:                        JDWPConstants.EventKind.METHOD_EXIT, };
0531:
0532:                synchronizer
0533:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
0534:
0535:                long debuggeeClassID = debuggeeWrapper.vmMirror
0536:                        .getClassID(debuggeeSignature);
0537:                logWriter.println("=> debuggeeClassID = " + debuggeeClassID);
0538:
0539:                long runMethodID = debuggeeWrapper.vmMirror.getMethodID(
0540:                        debuggeeClassID, "run");
0541:                logWriter.println("=> runMethodID = " + runMethodID);
0542:
0543:                logWriter.println("");
0544:                logWriter.println("=> Info for tested method '"
0545:                        + methodForEvents + "':");
0546:                long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(
0547:                        debuggeeClassID, methodForEvents);
0548:                if (testedMethodID == -1) {
0549:                    String failureMessage = "## FAILURE: Can NOT get MethodID for class '"
0550:                            + getDebuggeeClassName()
0551:                            + "'; Method name = "
0552:                            + methodForEvents;
0553:                    printErrorAndFail(failureMessage);
0554:                }
0555:                logWriter.println("=> testedMethodID = " + testedMethodID);
0556:                printMethodLineTable(debuggeeClassID, null, methodForEvents);
0557:
0558:                logWriter.println("");
0559:                logWriter.println("=> Set breakpoint at the beginning of "
0560:                        + methodForEvents);
0561:                long requestID = debuggeeWrapper.vmMirror
0562:                        .setBreakpointAtMethodBegin(debuggeeClassID,
0563:                                methodForEvents);
0564:                synchronizer
0565:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
0566:
0567:                logWriter.println("=> Wait for breakpoint event..");
0568:
0569:                long threadID = debuggeeWrapper.vmMirror
0570:                        .waitForBreakpoint(requestID);
0571:                logWriter.println("=> threadID = " + threadID);
0572:
0573:                // set requests for events that will be checked
0574:
0575:                logWriter
0576:                        .println("=> Set request for METHOD_EXIT event in debuggee: "
0577:                                + getDebuggeeClassName()
0578:                                + ", method: "
0579:                                + methodForEvents);
0580:                ReplyPacket reply = debuggeeWrapper.vmMirror
0581:                        .setMethodExit(methodEntryClassNameRegexp);
0582:                checkReplyPacket(reply, "EventRequest::Set command");
0583:                int methodExitRequestID = reply.getNextValueAsInt();
0584:                logWriter.println("=> METHOD_EXIT requestID = "
0585:                        + methodExitRequestID);
0586:
0587:                logWriter
0588:                        .println("=> Set request for SINGLE_STEP event in class "
0589:                                + debuggeeSignature);
0590:                CommandPacket setRequestCommand = new CommandPacket(
0591:                        JDWPCommands.EventRequestCommandSet.CommandSetID,
0592:                        JDWPCommands.EventRequestCommandSet.SetCommand);
0593:                setRequestCommand
0594:                        .setNextValueAsByte(JDWPConstants.EventKind.SINGLE_STEP);
0595:                setRequestCommand
0596:                        .setNextValueAsByte(JDWPConstants.SuspendPolicy.ALL);
0597:                setRequestCommand.setNextValueAsInt(2);
0598:                setRequestCommand.setNextValueAsByte(EventMod.ModKind.Step);
0599:                setRequestCommand.setNextValueAsThreadID(threadID);
0600:                setRequestCommand.setNextValueAsInt(JDWPConstants.StepSize.MIN);
0601:                setRequestCommand
0602:                        .setNextValueAsInt(JDWPConstants.StepDepth.INTO);
0603:                setRequestCommand
0604:                        .setNextValueAsByte(EventMod.ModKind.ClassOnly);
0605:                setRequestCommand
0606:                        .setNextValueAsReferenceTypeID(debuggeeClassID);
0607:
0608:                ReplyPacket setRequestReply = debuggeeWrapper.vmMirror
0609:                        .performCommand(setRequestCommand);
0610:                checkReplyPacket(setRequestReply, "EventRequest::Set command");
0611:                int stepRequestID = setRequestReply.getNextValueAsInt();
0612:                logWriter
0613:                        .println("=> SINGLE_STEP requestID = " + stepRequestID);
0614:
0615:                logWriter.println("");
0616:                logWriter.println("=> Resume debuggee");
0617:                debuggeeWrapper.vmMirror.resume();
0618:
0619:                Location combinedEventsLocation = getMethodEndLocation(
0620:                        debuggeeClassID, methodForEvents);
0621:                if (combinedEventsLocation == null) {
0622:                    String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '"
0623:                            + methodForEvents + "'";
0624:                    printErrorAndFail(failureMessage);
0625:                }
0626:                // ignore SINGLE_STEP events until receiving combined METHOD_EXIT,
0627:                // SINGLE_STEP events
0628:                logWriter
0629:                        .println("=> Try to receive and check combined events: METHOD_EXIT, SINGLE_STEP events; ignore single SINGLE_STEP event");
0630:
0631:                receiveAndCheckEvents(EXPECTED_EVENTS_ARRAY,
0632:                        combinedEventsLocation);
0633:                if (eventVmDeathReceived) {
0634:                    logWriter
0635:                            .println("==> testCombinedEvents004 is FINISHing as VM_DEATH is received!");
0636:                    return;
0637:                }
0638:
0639:                if (eventMethodExitReceived) {
0640:                    logWriter.println("");
0641:                    logWriter
0642:                            .println("=> Clean request for METHOD_EXIT event...");
0643:                    ReplyPacket clearReply = debuggeeWrapper.vmMirror
0644:                            .clearEvent(JDWPConstants.EventKind.METHOD_EXIT,
0645:                                    methodExitRequestID);
0646:                    checkReplyPacket(clearReply, "EventRequest::Clear");
0647:                }
0648:
0649:                logWriter.println("");
0650:                logWriter.println("=> Clean request for SINGLE_STEP event");
0651:                ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent(
0652:                        JDWPConstants.EventKind.SINGLE_STEP, stepRequestID);
0653:                checkReplyPacket(clearReply, "EventRequest::Clear");
0654:
0655:                logWriter.println("=> Resume debuggee");
0656:                debuggeeWrapper.vmMirror.resume();
0657:
0658:                // check that no other events, except VM_DEATH, will be received
0659:                checkVMDeathEvent();
0660:
0661:                logWriter.println("");
0662:                logWriter.println("==> testCombinedEvents_04 PASSED");
0663:            }
0664:
0665:            /**
0666:             * Test starts <code>CombinedEventsDebuggee</code> class, sets a
0667:             * breakpoint inside method run() of debuggee, waits for this breakpoint and
0668:             * gets threadID. Then sets requests for expected events at the beginning
0669:             * (location = 0) of debuggee's method sampleMethod(). Expected events are:
0670:             * METHOD_ENTRY, BREAKPOINT. Then resumes debuggee and starts to receive
0671:             * single SINGLE_STEP events, until debuggee achieves beginning of
0672:             * sampleMethod(). Then test checks, that three expected events were grouped
0673:             * on one location and sent in one packet. At the end, test resumes debuggee
0674:             * and checks that only VM_DEATH event is received after that.
0675:             */
0676:
0677:            public void testCombinedEvents_05() {
0678:                logWriter.println("==> testCombinedEvents_05 started");
0679:
0680:                byte[] EXPECTED_EVENTS_ARRAY = {
0681:                        JDWPConstants.EventKind.METHOD_ENTRY,
0682:                        JDWPConstants.EventKind.BREAKPOINT, };
0683:                int EXPECTED_EVENTS_COUNT = EXPECTED_EVENTS_ARRAY.length;
0684:
0685:                synchronizer
0686:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
0687:
0688:                long debuggeeClassID = debuggeeWrapper.vmMirror
0689:                        .getClassID(debuggeeSignature);
0690:                logWriter.println("=> debuggeeClassID = " + debuggeeClassID);
0691:
0692:                long runMethodID = debuggeeWrapper.vmMirror.getMethodID(
0693:                        debuggeeClassID, "run");
0694:                logWriter.println("=> runMethodID = " + runMethodID);
0695:
0696:                logWriter.println("");
0697:                logWriter.println("=> Info for tested method '"
0698:                        + methodForEvents + "':");
0699:                long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(
0700:                        debuggeeClassID, methodForEvents);
0701:                if (testedMethodID == -1) {
0702:                    String failureMessage = "## FAILURE: Can NOT get MethodID for class '"
0703:                            + getDebuggeeClassName()
0704:                            + "'; Method name = "
0705:                            + methodForEvents;
0706:                    printErrorAndFail(failureMessage);
0707:                }
0708:                logWriter.println("=> testedMethodID = " + testedMethodID);
0709:                printMethodLineTable(debuggeeClassID, null, methodForEvents);
0710:
0711:                //        logWriter.println("=> Set breakpoint inside debuggee to get threadID");
0712:                //        int requestID = (int)debuggeeWrapper.vmMirror.setBreakpointInsideMethod(
0713:                //                debuggeeClassID, "run", 2 /*lineInsideDebuggee*/);
0714:                //        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
0715:
0716:                //        logWriter.println("=> Wait for breakpoint event..");
0717:
0718:                //        long threadID = debuggeeWrapper.vmMirror.waitForBreakpoint(requestID);
0719:                //        logWriter.println("=> threadID = " + threadID);
0720:
0721:                // set requests for events that will be checked
0722:                logWriter.println("");
0723:                logWriter
0724:                        .println("=> Set request for BREAKPOINT event in debuggee: "
0725:                                + getDebuggeeClassName()
0726:                                + ", beginning of method: " + methodForEvents);
0727:                //        int breakpointRequestID = (int)debuggeeWrapper.vmMirror
0728:                //                .setBreakpointAtMethodBegin(debuggeeClassID, methodForEvents);
0729:                //        logWriter.println("=> Breakpoint requestID = " + breakpointRequestID);
0730:                Location combinedEventsLocation = getMethodEntryLocation(
0731:                        debuggeeClassID, methodForEvents);
0732:                if (combinedEventsLocation == null) {
0733:                    String failureMessage = "## FAILURE: Can NOT get MethodEntryLocation for method '"
0734:                            + methodForEvents + "'";
0735:                    printErrorAndFail(failureMessage);
0736:                }
0737:                ReplyPacket reply = debuggeeWrapper.vmMirror
0738:                        .setBreakpoint(combinedEventsLocation);
0739:                int breakpointRequestID = reply.getNextValueAsInt();
0740:                logWriter.println("=> Breakpoint requestID = "
0741:                        + breakpointRequestID);
0742:
0743:                logWriter
0744:                        .println("=> Set request for METHOD_ENTRY event in debuggee: "
0745:                                + getDebuggeeClassName()
0746:                                + ", method: "
0747:                                + methodForEvents);
0748:                reply = debuggeeWrapper.vmMirror
0749:                        .setMethodEntry(methodEntryClassNameRegexp);
0750:                checkReplyPacket(reply, "Set METHOD_ENTRY event");
0751:                int methodEntryRequestID = reply.getNextValueAsInt();
0752:                logWriter.println("=> METHOD_ENTRY requestID = "
0753:                        + methodEntryRequestID);
0754:
0755:                logWriter.println("");
0756:                //        logWriter.println("=> Resume debuggee");
0757:                //        debuggeeWrapper.vmMirror.resume();
0758:                synchronizer
0759:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
0760:
0761:                // receive and check combined METHOD_ENTRY, BREAKPOINT events
0762:                logWriter
0763:                        .println("=> Try to receive and check combined events: METHOD_ENTRY, BREAKPOINT events");
0764:                EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
0765:                ParsedEvent[] parsedEvents = ParsedEvent
0766:                        .parseEventPacket(event);
0767:                // print all received events
0768:                logWriter.println("=> Events received: " + parsedEvents.length);
0769:                for (int i = 0; i < parsedEvents.length; i++) {
0770:                    logWriter.println("");
0771:                    logWriter.println("=> Event #" + i + ";");
0772:                    logWriter.println("=> EventKind: "
0773:                            + parsedEvents[i].getEventKind()
0774:                            + "["
0775:                            + JDWPConstants.EventKind.getName(parsedEvents[i]
0776:                                    .getEventKind()) + "]");
0777:                    logWriter.println("=> RequestID: "
0778:                            + parsedEvents[i].getRequestID());
0779:                }
0780:                boolean success = true;
0781:                boolean locationsOK = checkEventsLocation(parsedEvents,
0782:                        combinedEventsLocation);
0783:                if (parsedEvents.length == EXPECTED_EVENTS_COUNT) {
0784:                    logWriter.println("");
0785:                    logWriter
0786:                            .println("=> Combined events are received. Check events..");
0787:                    for (int i = 0; i < parsedEvents.length; i++) {
0788:                        boolean isFound = false;
0789:                        for (int j = 0; j < EXPECTED_EVENTS_COUNT; j++) {
0790:                            if (parsedEvents[i].getEventKind() == EXPECTED_EVENTS_ARRAY[j]) {
0791:                                EXPECTED_EVENTS_ARRAY[j] = 0;
0792:                                isFound = true;
0793:                                break;
0794:                            }
0795:                        }
0796:                        if (!isFound) {
0797:                            logWriter
0798:                                    .println("##FAILURE: received unexpected event: "
0799:                                            + parsedEvents[i].getEventKind()
0800:                                            + "["
0801:                                            + JDWPConstants.EventKind
0802:                                                    .getName(parsedEvents[0]
0803:                                                            .getEventKind())
0804:                                            + "]");
0805:                            success = false;
0806:                        }
0807:                    }
0808:                    if (!success) {
0809:                        logWriter.println("");
0810:                        logWriter
0811:                                .println("##FAILURE: the following events were not received: ");
0812:                        for (int k = 0; k < EXPECTED_EVENTS_COUNT; k++) {
0813:                            if (EXPECTED_EVENTS_ARRAY[k] != 0)
0814:                                logWriter
0815:                                        .println("  #"
0816:                                                + k
0817:                                                + ": "
0818:                                                + EXPECTED_EVENTS_ARRAY[k]
0819:                                                + "["
0820:                                                + JDWPConstants.EventKind
0821:                                                        .getName(EXPECTED_EVENTS_ARRAY[k])
0822:                                                + "]");
0823:                        }
0824:                        //DBG__fail("not all expected events were received");
0825:                    }
0826:                } else {
0827:                    logWriter
0828:                            .println("##FAILURE: received unexpected number of events: "
0829:                                    + parsedEvents.length
0830:                                    + " instead of "
0831:                                    + EXPECTED_EVENTS_COUNT);
0832:                    //DBG__fail("received unexpected number of events: " + parsedEvents.length);
0833:
0834:                }
0835:                if ((!success) || (!locationsOK)) {
0836:                    logWriter.println("## FAILURE during checking events!");
0837:                }
0838:                logWriter.println("");
0839:                logWriter.println("=> Clean request for METHOD_ENTRY event...");
0840:                ReplyPacket clearReply = debuggeeWrapper.vmMirror.clearEvent(
0841:                        JDWPConstants.EventKind.METHOD_ENTRY,
0842:                        methodEntryRequestID);
0843:                checkReplyPacket(clearReply, "EventRequest::Clear");
0844:
0845:                logWriter.println("=> Resume debuggee");
0846:                debuggeeWrapper.vmMirror.resume();
0847:
0848:                // check that no other events, except VM_DEATH, will be received
0849:                checkVMDeathEvent();
0850:
0851:                logWriter.println("");
0852:                logWriter.println("==> testCombinedEvents_05 PASSED");
0853:            }
0854:
0855:            /**
0856:             * Test starts <code>CombinedEventsDebuggee</code> class, sets a
0857:             * breakpoint inside method run() of debuggee, waits for this breakpoint and
0858:             * gets threadID. Then sets requests for expected events at the beginning
0859:             * (location = 0) of debuggee's method sampleMethod(). Expected events are:
0860:             * METHOD_EXIT, BREAKPOINT. Then resumes debuggee and starts to receive
0861:             * single SINGLE_STEP events, until debuggee achieves beginning of
0862:             * sampleMethod(). Then test checks, that three expected events were grouped
0863:             * on one location and sent in one packet. At the end, test resumes debuggee
0864:             * and checks that only VM_DEATH event is received after that.
0865:             */
0866:
0867:            public void testCombinedEvents_06() {
0868:                logWriter.println("==> testCombinedEvents_06 started");
0869:
0870:                byte[] EXPECTED_EVENTS_ARRAY = {
0871:                        JDWPConstants.EventKind.BREAKPOINT,
0872:                        JDWPConstants.EventKind.METHOD_EXIT, };
0873:                int EXPECTED_EVENTS_COUNT = EXPECTED_EVENTS_ARRAY.length;
0874:
0875:                synchronizer
0876:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
0877:
0878:                long debuggeeClassID = debuggeeWrapper.vmMirror
0879:                        .getClassID(debuggeeSignature);
0880:                logWriter.println("=> debuggeeClassID = " + debuggeeClassID);
0881:
0882:                long runMethodID = debuggeeWrapper.vmMirror.getMethodID(
0883:                        debuggeeClassID, "run");
0884:                logWriter.println("=> runMethodID = " + runMethodID);
0885:
0886:                logWriter.println("");
0887:                logWriter.println("=> Info for tested method '"
0888:                        + methodForEvents + "':");
0889:                long testedMethodID = debuggeeWrapper.vmMirror.getMethodID(
0890:                        debuggeeClassID, methodForEvents);
0891:                if (testedMethodID == -1) {
0892:                    String failureMessage = "## FAILURE: Can NOT get MethodID for class '"
0893:                            + getDebuggeeClassName()
0894:                            + "'; Method name = "
0895:                            + methodForEvents;
0896:                    printErrorAndFail(failureMessage);
0897:                }
0898:                logWriter.println("=> testedMethodID = " + testedMethodID);
0899:                printMethodLineTable(debuggeeClassID, null, methodForEvents);
0900:
0901:                // set requests for events that will be checked
0902:                logWriter.println("");
0903:                logWriter
0904:                        .println("=> Set request for BREAKPOINT event in debuggee: "
0905:                                + getDebuggeeClassName()
0906:                                + ", at end of method: " + methodForEvents);
0907:                Location combinedEventsLocation = getMethodEndLocation(
0908:                        debuggeeClassID, methodForEvents);
0909:                if (combinedEventsLocation == null) {
0910:                    String failureMessage = "## FAILURE: Can NOT get MethodEndLocation for method '"
0911:                            + methodForEvents + "'";
0912:                    printErrorAndFail(failureMessage);
0913:                }
0914:                ReplyPacket reply = debuggeeWrapper.vmMirror
0915:                        .setBreakpoint(combinedEventsLocation);
0916:                int breakpointRequestID = reply.getNextValueAsInt();
0917:                logWriter.println("=> Breakpoint requestID = "
0918:                        + breakpointRequestID);
0919:
0920:                logWriter
0921:                        .println("=> Set request for METHOD_EXIT event in debuggee: "
0922:                                + getDebuggeeClassName()
0923:                                + ", method: "
0924:                                + methodForEvents);
0925:                reply = debuggeeWrapper.vmMirror
0926:                        .setMethodExit(methodEntryClassNameRegexp);
0927:                checkReplyPacket(reply, "Set METHOD_EXIT event");
0928:                int methodExitRequestID = reply.getNextValueAsInt();
0929:                logWriter.println("=> METHOD_EXIT requestID = "
0930:                        + methodExitRequestID);
0931:
0932:                logWriter.println("");
0933:                logWriter.println("Send SGNL_CONTINUE signal to debuggee...");
0934:                synchronizer
0935:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
0936:
0937:                // receive and check combined METHOD_EXIT, BREAKPOINT events
0938:                logWriter
0939:                        .println("=> Try to receive and check combined events: METHOD_EXIT, BREAKPOINT events");
0940:                EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
0941:                ParsedEvent[] parsedEvents = ParsedEvent
0942:                        .parseEventPacket(event);
0943:                // print all received events
0944:                logWriter.println("=> Events received: " + parsedEvents.length);
0945:                for (int i = 0; i < parsedEvents.length; i++) {
0946:                    logWriter.println("");
0947:                    logWriter.println("=> Event #" + i + ";");
0948:                    logWriter.println("=> EventKind: "
0949:                            + parsedEvents[i].getEventKind()
0950:                            + "["
0951:                            + JDWPConstants.EventKind.getName(parsedEvents[i]
0952:                                    .getEventKind()) + "]");
0953:                    logWriter.println("=> RequestID: "
0954:                            + parsedEvents[i].getRequestID());
0955:                    if (parsedEvents[i].getEventKind() == JDWPConstants.EventKind.METHOD_EXIT) {
0956:                        eventMethodExitReceived = true;
0957:                    }
0958:                }
0959:                boolean success = true;
0960:                boolean locationsOK = checkEventsLocation(parsedEvents,
0961:                        combinedEventsLocation);
0962:                if (parsedEvents.length == EXPECTED_EVENTS_COUNT) {
0963:                    logWriter.println("");
0964:                    logWriter
0965:                            .println("=> Combined events are received. Check events..");
0966:                    for (int i = 0; i < parsedEvents.length; i++) {
0967:                        boolean isFound = false;
0968:                        for (int j = 0; j < EXPECTED_EVENTS_COUNT; j++) {
0969:                            if (parsedEvents[i].getEventKind() == EXPECTED_EVENTS_ARRAY[j]) {
0970:                                EXPECTED_EVENTS_ARRAY[j] = 0;
0971:                                isFound = true;
0972:                                break;
0973:                            }
0974:                        }
0975:                        if (!isFound) {
0976:                            logWriter
0977:                                    .println("##FAILURE: received unexpected event: "
0978:                                            + parsedEvents[i].getEventKind()
0979:                                            + "["
0980:                                            + JDWPConstants.EventKind
0981:                                                    .getName(parsedEvents[0]
0982:                                                            .getEventKind())
0983:                                            + "]");
0984:                            success = false;
0985:                        }
0986:                    }
0987:                    if (!success) {
0988:                        logWriter.println("");
0989:                        logWriter
0990:                                .println("##FAILURE: the following events were not received: ");
0991:                        for (int k = 0; k < EXPECTED_EVENTS_COUNT; k++) {
0992:                            if (EXPECTED_EVENTS_ARRAY[k] != 0)
0993:                                logWriter
0994:                                        .println("  #"
0995:                                                + k
0996:                                                + ": "
0997:                                                + EXPECTED_EVENTS_ARRAY[k]
0998:                                                + "["
0999:                                                + JDWPConstants.EventKind
1000:                                                        .getName(EXPECTED_EVENTS_ARRAY[k])
1001:                                                + "]");
1002:                        }
1003:                        //DBG__fail("not all expected events were received");
1004:                    }
1005:                } else {
1006:                    logWriter
1007:                            .println("##FAILURE: received unexpected number of events: "
1008:                                    + parsedEvents.length
1009:                                    + " instead of "
1010:                                    + EXPECTED_EVENTS_COUNT);
1011:                    //DBG__fail("received unexpected number of events: " + parsedEvents.length);
1012:
1013:                }
1014:                if ((!success) || (!locationsOK)) {
1015:                    logWriter.println("## FAILURE during checking events!");
1016:                    //DBG__printErrorAndFail(failureMessage);
1017:                }
1018:                if (eventMethodExitReceived) {
1019:                    logWriter.println("");
1020:                    logWriter
1021:                            .println("=> Clean request for METHOD_EXIT event...");
1022:                    ReplyPacket clearReply = debuggeeWrapper.vmMirror
1023:                            .clearEvent(JDWPConstants.EventKind.METHOD_EXIT,
1024:                                    methodExitRequestID);
1025:                    checkReplyPacket(clearReply, "EventRequest::Clear");
1026:                }
1027:
1028:                logWriter.println("=> Resume debuggee");
1029:                debuggeeWrapper.vmMirror.resume();
1030:
1031:                // check that no other events, except VM_DEATH, will be received
1032:                checkVMDeathEvent();
1033:
1034:                logWriter.println("");
1035:                logWriter.println("==> testCombinedEvents_06 PASSED");
1036:            }
1037:
1038:            void receiveAndCheckEvents(byte[] EXPECTED_EVENTS_ARRAY,
1039:                    Location expectedLocation) {
1040:                int EXPECTED_EVENTS_COUNT = EXPECTED_EVENTS_ARRAY.length;
1041:                for (;;) {
1042:                    logWriter.println("=>");
1043:                    logWriter.println("=> Receiving events...");
1044:                    EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
1045:                    ParsedEvent[] parsedEvents = ParsedEvent
1046:                            .parseEventPacket(event);
1047:
1048:                    // print all received events
1049:                    logWriter
1050:                            .println("=> Received event packet with events number = "
1051:                                    + parsedEvents.length + " :");
1052:
1053:                    for (int i = 0; i < parsedEvents.length; i++) {
1054:                        logWriter.println("");
1055:                        logWriter.println("=> Event #" + (i + 1)
1056:                                + " in packet -");
1057:                        logWriter
1058:                                .println("=> EventKind: "
1059:                                        + parsedEvents[i].getEventKind()
1060:                                        + "["
1061:                                        + JDWPConstants.EventKind
1062:                                                .getName(parsedEvents[i]
1063:                                                        .getEventKind()) + "]");
1064:                        logWriter.println("=> RequestID: "
1065:                                + parsedEvents[i].getRequestID());
1066:                        if (parsedEvents[i].getEventKind() == JDWPConstants.EventKind.VM_DEATH) {
1067:                            eventVmDeathReceived = true;
1068:                        }
1069:                        if (parsedEvents[i].getEventKind() == JDWPConstants.EventKind.METHOD_EXIT) {
1070:                            eventMethodExitReceived = true;
1071:                        }
1072:                    }
1073:                    if (eventVmDeathReceived) {
1074:                        return;
1075:                    }
1076:                    checkEventsLocation(parsedEvents, null); // DBG__
1077:
1078:                    // the following code checks received events
1079:                    if (parsedEvents.length == 1) {
1080:                        debuggeeWrapper.vmMirror.resume();
1081:                        continue;
1082:                        /* DBG__                
1083:                         if (parsedEvents[0].getEventKind() == JDWPConstants.EventKind.SINGLE_STEP) {
1084:                         logWriter.println("");
1085:                         logWriter.println("=> Resume debuggee");
1086:                         logWriter.println("");
1087:                         debuggeeWrapper.vmMirror.resume();
1088:                         continue;
1089:                         } else {
1090:                         logWriter.println("##FAILURE: received unexpected event: "
1091:                         + parsedEvents[0].getEventKind()
1092:                         + "["
1093:                         + JDWPConstants.EventKind.getName(parsedEvents[0]
1094:                         .getEventKind())
1095:                         + "] instead of SINGLE_STEP");
1096:                         fail("received event is not SINGLE_STEP event: "
1097:                         + parsedEvents[0].getEventKind()
1098:                         + "["
1099:                         + JDWPConstants.EventKind.getName(parsedEvents[0]
1100:                         .getEventKind()) + "]");
1101:                         }
1102:                         // DBG__ */
1103:                        //DBG__} else if (parsedEvents.length == EXPECTED_EVENTS_COUNT) {
1104:                    } else if (parsedEvents.length > 1) {
1105:                        logWriter.println("");
1106:                        logWriter
1107:                                .println("=> Combined events are received. Check events..");
1108:                        boolean success = true;
1109:                        for (int i = 0; i < parsedEvents.length; i++) {
1110:                            boolean isFound = false;
1111:                            for (int j = 0; j < EXPECTED_EVENTS_COUNT; j++) {
1112:                                if (parsedEvents[i].getEventKind() == EXPECTED_EVENTS_ARRAY[j]) {
1113:                                    EXPECTED_EVENTS_ARRAY[j] = 0;
1114:                                    isFound = true;
1115:                                    break;
1116:                                }
1117:                            }
1118:                            if (!isFound) {
1119:                                logWriter
1120:                                        .println("##FAILURE: received unexpected event: "
1121:                                                + parsedEvents[i]
1122:                                                        .getEventKind()
1123:                                                + "["
1124:                                                + JDWPConstants.EventKind
1125:                                                        .getName(parsedEvents[0]
1126:                                                                .getEventKind())
1127:                                                + "]");
1128:                                success = false;
1129:                            }
1130:                        }
1131:                        if (!success) {
1132:                            logWriter.println("");
1133:                            logWriter
1134:                                    .println("##FAILURE: the following expected events were not received: ");
1135:                            for (int k = 0; k < EXPECTED_EVENTS_COUNT; k++) {
1136:                                if (EXPECTED_EVENTS_ARRAY[k] != 0)
1137:                                    logWriter
1138:                                            .println("  #"
1139:                                                    + k
1140:                                                    + ": "
1141:                                                    + EXPECTED_EVENTS_ARRAY[k]
1142:                                                    + "["
1143:                                                    + JDWPConstants.EventKind
1144:                                                            .getName(EXPECTED_EVENTS_ARRAY[k])
1145:                                                    + "]");
1146:                            }
1147:                            fail("not all expected events were received");
1148:                        }
1149:                        for (int i = 0; i < parsedEvents.length; i++) {
1150:                            byte eventKind = parsedEvents[i].getEventKind();
1151:                            long eventThreadID = ((ParsedEvent.EventThread) parsedEvents[i])
1152:                                    .getThreadID();
1153:                            logWriter.println("");
1154:                            logWriter
1155:                                    .println("=> Chcek location for combined event N "
1156:                                            + (i + 1)
1157:                                            + ": Event kind = "
1158:                                            + eventKind
1159:                                            + "("
1160:                                            + JDWPConstants.EventKind
1161:                                                    .getName(eventKind)
1162:                                            + "); eventThreadID = "
1163:                                            + eventThreadID);
1164:                            Location eventLocation = null;
1165:                            switch (eventKind) {
1166:                            case JDWPConstants.EventKind.METHOD_ENTRY:
1167:                                eventLocation = ((ParsedEvent.Event_METHOD_ENTRY) parsedEvents[i])
1168:                                        .getLocation();
1169:                                break;
1170:                            case JDWPConstants.EventKind.SINGLE_STEP:
1171:                                eventLocation = ((ParsedEvent.Event_SINGLE_STEP) parsedEvents[i])
1172:                                        .getLocation();
1173:                                break;
1174:                            case JDWPConstants.EventKind.BREAKPOINT:
1175:                                eventLocation = ((ParsedEvent.Event_BREAKPOINT) parsedEvents[i])
1176:                                        .getLocation();
1177:                                break;
1178:                            case JDWPConstants.EventKind.METHOD_EXIT:
1179:                                eventLocation = ((ParsedEvent.Event_METHOD_EXIT) parsedEvents[i])
1180:                                        .getLocation();
1181:                                break;
1182:                            }
1183:                            long eventClassID = eventLocation.classID;
1184:                            logWriter.println("=> ClassID in event = "
1185:                                    + eventClassID);
1186:                            if (expectedLocation.classID != eventClassID) {
1187:                                logWriter
1188:                                        .println("## FAILURE: Unexpected ClassID in event!");
1189:                                logWriter
1190:                                        .println("##          Expected ClassID  = "
1191:                                                + expectedLocation.classID);
1192:                                success = false;
1193:                            } else {
1194:                                logWriter
1195:                                        .println("=> OK - it is expected ClassID");
1196:                            }
1197:                            long eventMethodID = eventLocation.methodID;
1198:                            logWriter.println("=> MethodID in event = "
1199:                                    + eventMethodID);
1200:                            if (expectedLocation.methodID != eventMethodID) {
1201:                                logWriter
1202:                                        .println("## FAILURE: Unexpected MethodID in event!");
1203:                                logWriter
1204:                                        .println("##          Expected MethodID = "
1205:                                                + expectedLocation.methodID);
1206:                                success = false;
1207:                            } else {
1208:                                logWriter
1209:                                        .println("=> OK - it is expected MethodID");
1210:                            }
1211:                            long eventCodeIndex = eventLocation.index;
1212:                            logWriter.println("=> CodeIndex in event = "
1213:                                    + eventCodeIndex);
1214:                            if (expectedLocation.index != eventCodeIndex) {
1215:                                logWriter
1216:                                        .println("## FAILURE: Unexpected CodeIndex in event!");
1217:                                logWriter
1218:                                        .println("##          Expected CodeIndex = "
1219:                                                + expectedLocation.index);
1220:                                success = false;
1221:                            } else {
1222:                                logWriter
1223:                                        .println("=> OK - it is expected CodeIndex)");
1224:                            }
1225:                        }
1226:                        logWriter.println("");
1227:                        if (!success) {
1228:                            String failureMessage = "## FAILURE: Unexpected events' locations are found out!";
1229:                            logWriter.println(failureMessage);
1230:                            //DBG__printErrorAndFail(failureMessage);
1231:                        } else {
1232:                            logWriter
1233:                                    .println("=> OK - all combined events have expected location!");
1234:                        }
1235:                        break;
1236:                    } else {
1237:                        logWriter
1238:                                .println("##FAILURE: received unexpected number of events: "
1239:                                        + parsedEvents.length
1240:                                        + " instead of 1 or "
1241:                                        + EXPECTED_EVENTS_COUNT);
1242:                        fail("received unexpected number of events: "
1243:                                + parsedEvents.length);
1244:                    }
1245:                }
1246:            }
1247:
1248:            void checkVMDeathEvent() {
1249:                if (eventVmDeathReceived) {
1250:                    return;
1251:                }
1252:                logWriter.println("=> Wait for VM_DEATH event...");
1253:                while (true) { //DBG__
1254:                    logWriter.println("=> Receiving events...");
1255:                    EventPacket event = debuggeeWrapper.vmMirror.receiveEvent();
1256:                    ParsedEvent[] parsedEvents = ParsedEvent
1257:                            .parseEventPacket(event);
1258:                    if (parsedEvents.length != 1
1259:                            || parsedEvents[0].getEventKind() != JDWPConstants.EventKind.VM_DEATH) {
1260:                        // print all received events
1261:                        logWriter
1262:                                .println("##FAILURE: Received unexpected events");
1263:                        logWriter.println("=> Events received: "
1264:                                + parsedEvents.length);
1265:                        for (int i = 0; i < parsedEvents.length; i++) {
1266:                            logWriter.println("");
1267:                            logWriter.println("=> Event #" + i + ";");
1268:                            logWriter.println("=> EventKind: "
1269:                                    + parsedEvents[i].getEventKind()
1270:                                    + "["
1271:                                    + JDWPConstants.EventKind
1272:                                            .getName(parsedEvents[i]
1273:                                                    .getEventKind()) + "]");
1274:                            logWriter.println("=> RequestID: "
1275:                                    + parsedEvents[i].getRequestID());
1276:                        }
1277:                        checkEventsLocation(parsedEvents, null); // DBG__
1278:                        logWriter.println("=> Resume debuggee"); //DBG__
1279:                        debuggeeWrapper.vmMirror.resume(); //DBG__
1280:                        continue; //DBG__
1281:                        //DBG__fail("unexpected events received");
1282:                    }
1283:                    logWriter.println("=> OK - VM_DEATH event was received. ");
1284:                    break; //DBG__
1285:                } // DBG__
1286:            }
1287:        }
ww_w__._ja__v__a___2___s.c__o__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.