01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: /**
20: * @author Vitaly A. Provodin
21: * @version $Revision: 1.3 $
22: */
23:
24: /**
25: * Created on 31.01.2005
26: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
27:
28: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
29: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
30: import org.apache.harmony.jpda.tests.jdwp.share.JDWPTestCase;
31:
32: /**
33: * JDWP Unit test for VirtualMachine.Exit command.
34: */
35: public class ExitTest extends JDWPTestCase {
36:
37: protected String getDebuggeeClassName() {
38: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.SimpleHelloWorld";
39: }
40:
41: /**
42: * This testcase exercises VirtualMachine.Exit command.
43: * <BR>At first the test starts HelloWorld debuggee.
44: * <BR> Then the test performs VirtualMachine.Exit command
45: * with exit code = 99 and checks that debuggee exit code, received
46: * with help of debuggeeWrapper of test framework, is the same.
47: */
48: public void testExit001() {
49: CommandPacket packet = new CommandPacket(
50: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
51: JDWPCommands.VirtualMachineCommandSet.ExitCommand);
52: packet.setNextValueAsInt(99);
53:
54: debuggeeWrapper.vmMirror.performCommand(packet);
55:
56: int exitCode = 0;
57: boolean exitLoop;
58:
59: long timeOut = settings.getTimeout();
60: long startTime = System.currentTimeMillis();
61: do {
62: try {
63: exitCode = debuggeeWrapper.process.exitValue();
64: exitLoop = true;
65: } catch (IllegalThreadStateException e) {
66: exitLoop = false;
67: }
68: if (System.currentTimeMillis() - startTime > timeOut) {
69: printErrorAndFail("Out of time: debugger did get "
70: + "no exit codes of debuggee");
71: break;
72: }
73: } while (!exitLoop);
74:
75: logWriter.println("exitCode = " + exitCode);
76: assertEquals("Invalid exit code,", 99, exitCode);
77: }
78:
79: public static void main(String[] args) {
80: junit.textui.TestRunner.run(ExitTest.class);
81: }
82: }
|