1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.harmony.jpda.tests.jdwp.Events; 20 21 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 22 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 23 import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent; 24 import org.apache.harmony.jpda.tests.framework.jdwp.VmMirror; 25 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 26 27 import java.util.HashSet; 28 import java.util.Set; 29 30 /** 31 * JDWP Unit test for multiple BREAKPOINT events. 32 */ 33 public class BreakpointMultipleTest extends JDWPEventTestCase { getDebuggeeClassName()34 protected String getDebuggeeClassName() { 35 return BreakpointDebuggee.class.getName(); 36 } 37 38 /** 39 * This testcase is for BREAKPOINT event. It checks we can set 40 * multiple breakpoints at the same location. 41 * <BR>It runs BreakpointDebuggee and sets two breakpoints in the 42 * breakpointTest method, then clears both breakpoints. 43 */ testSetAndClearMultipleBreakpoint()44 public void testSetAndClearMultipleBreakpoint() { 45 logWriter.println("testSetAndClearMultipleBreakpoint started"); 46 47 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 48 49 // Set breakpoints. 50 long classID = getClassIDBySignature(getDebuggeeClassSignature()); 51 int breakpoint1 = setBreakpoint(classID); 52 int breakpoint2 = setBreakpoint(classID); 53 54 // Clear breakpoints 55 debuggeeWrapper.vmMirror.clearBreakpoint(breakpoint1); 56 debuggeeWrapper.vmMirror.clearBreakpoint(breakpoint2); 57 58 // Set breakpoint again to be sure we cleared breakpoints correctly in the runtime. 59 int breakpoint3 = setBreakpoint(classID); 60 debuggeeWrapper.vmMirror.clearBreakpoint(breakpoint3); 61 62 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 63 64 logWriter.println("testSetAndClearMultipleBreakpoint done"); 65 } 66 67 /** 68 * This testcase is for BREAKPOINT event. It checks we can set 69 * multiple breakpoints at the same location. 70 * <BR>It runs BreakpointDebuggee and sets two breakpoints in the 71 * breakpointTest method, then checks we receive both events at 72 * the same time. 73 */ testSetMultipleBreakpoint()74 public void testSetMultipleBreakpoint() { 75 logWriter.println("testSetMultipleBreakpoint started"); 76 77 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 78 79 // Set breakpoints. 80 long classID = getClassIDBySignature(getDebuggeeClassSignature()); 81 int breakpoint1 = setBreakpoint(classID); 82 int breakpoint2 = setBreakpoint(classID); 83 84 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 85 86 // Wait for event. 87 CommandPacket event = debuggeeWrapper.vmMirror.receiveEvent(); 88 89 // Check we received all our BREAKPOINT events at the same time. 90 ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event); 91 assertEquals("Invalid number of events,", 2, parsedEvents.length); 92 Set<Integer> request_ids = new HashSet<Integer>(); 93 checkBreakpointEvent(parsedEvents[0], request_ids); 94 checkBreakpointEvent(parsedEvents[1], request_ids); 95 assertTrue("Breakpoint 1 is missing", request_ids.contains(breakpoint1)); 96 assertTrue("Breakpoint 2 is missing", request_ids.contains(breakpoint2)); 97 98 // Clear breakpoints. 99 debuggeeWrapper.vmMirror.clearBreakpoint(breakpoint1); 100 debuggeeWrapper.vmMirror.clearBreakpoint(breakpoint2); 101 102 // Resume debuggee so the test ends cleanly. 103 resumeDebuggee(); 104 105 logWriter.println("testSetMultipleBreakpoint done"); 106 } 107 108 /** 109 * Sets a breakpoint at the start of the "breakpointTest" 110 * method and returns its request ID. 111 */ setBreakpoint(long classID)112 private int setBreakpoint(long classID) { 113 VmMirror mirror = debuggeeWrapper.vmMirror; 114 return mirror.setBreakpointAtMethodBegin(classID, "breakpointTest"); 115 } 116 117 /** 118 * Checks the given event is a BREAKPOINT event and adds its request 119 * ID to the given request set. 120 */ checkBreakpointEvent(ParsedEvent parsedEvent, Set<Integer> request_ids)121 private void checkBreakpointEvent(ParsedEvent parsedEvent, Set<Integer> request_ids) { 122 byte eventKind = parsedEvent.getEventKind(); 123 assertEquals("Invalid event kind,", 124 JDWPConstants.EventKind.BREAKPOINT, 125 eventKind, 126 JDWPConstants.EventKind.getName(JDWPConstants.EventKind.BREAKPOINT), 127 JDWPConstants.EventKind.getName(eventKind)); 128 request_ids.add(parsedEvent.getRequestID()); 129 } 130 } 131