001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Vitaly A. Provodin
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 28.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
027:
028: import org.apache.harmony.jpda.tests.framework.TestErrorException;
029: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
030: import org.apache.harmony.jpda.tests.framework.jdwp.EventPacket;
031: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
032: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
033: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
034: import org.apache.harmony.jpda.tests.framework.jdwp.exceptions.TimeoutException;
035: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
036: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
037:
038: /**
039: * JDWP Unit test for VirtualMachine.HoldEvents command.
040: */
041: public class HoldEventsTest extends JDWPSyncTestCase {
042:
043: protected String getDebuggeeClassName() {
044: return "org.apache.harmony.jpda.tests.jdwp.VirtualMachine.HoldEventsDebuggee";
045: }
046:
047: /**
048: * This testcase exercises VirtualMachine.HoldEvents command.
049: * <BR>At first the test starts HoldEventsDebuggee.
050: * <BR> Then the test sends request for TESTED_THREAD and
051: * performs VirtualMachine.HoldEvents command.
052: * Next, the test waits for debuggee to start the 'TESTED_THREAD'
053: * thread and checks that no any events (including requested THREAD_START event)
054: * are received during default timeout.
055: * Then the test sends VirtualMachine.ReleaseEvents command
056: * and checks that expected THREAD_START event is received.
057: */
058: public void testHoldEvents001() {
059: synchronizer
060: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
061:
062: debuggeeWrapper.vmMirror.setThreadStart();
063:
064: //send HoldEvents command
065: logWriter.println("send HoldEvents");
066: CommandPacket packet = new CommandPacket(
067: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
068: JDWPCommands.VirtualMachineCommandSet.HoldEventsCommand);
069:
070: ReplyPacket reply = debuggeeWrapper.vmMirror
071: .performCommand(packet);
072: checkReplyPacket(reply, "VirtualMachine::HoldEvents command");
073:
074: logWriter.println("allow to start thread");
075: synchronizer
076: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
077:
078: try {
079: EventPacket event = debuggeeWrapper.vmMirror
080: .receiveEvent(settings.getTimeout());
081: logWriter.printError("unexpected event received: " + event);
082: fail("unexpected event received");
083: } catch (TimeoutException e) {
084: logWriter.println("no events were received");
085: } catch (Exception e) {
086: throw new TestErrorException(e);
087: }
088:
089: logWriter.println("send ReleaseEvents");
090: packet = new CommandPacket(
091: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
092: JDWPCommands.VirtualMachineCommandSet.ReleaseEventsCommand);
093: debuggeeWrapper.vmMirror.performCommand(packet);
094:
095: EventPacket event = debuggeeWrapper.vmMirror
096: .receiveCertainEvent(JDWPConstants.EventKind.THREAD_START);
097: logWriter.println("expected event received: " + event);
098: debuggeeWrapper.vmMirror.resume();
099: }
100:
101: public static void main(String[] args) {
102: junit.textui.TestRunner.run(HoldEventsTest.class);
103: }
104: }
|