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 /** 20 * @author Vitaly A. Provodin 21 */ 22 23 /** 24 * Created on 31.01.2005 25 */ 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 /** 34 * JDWP Unit test for VirtualMachine.Exit command. 35 */ 36 public class ExitTest extends JDWPTestCase { 37 getDebuggeeClassName()38 protected String getDebuggeeClassName() { 39 return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.SimpleHelloWorld"; 40 } 41 42 /** 43 * This testcase exercises VirtualMachine.Exit command. 44 * <BR>At first the test starts HelloWorld debuggee. 45 * <BR> Then the test performs VirtualMachine.Exit command 46 * with exit code = 99 and checks that debuggee exit code, received 47 * with help of debuggeeWrapper of test framework, is the same. 48 */ testExit001()49 public void testExit001() { 50 CommandPacket packet = new CommandPacket( 51 JDWPCommands.VirtualMachineCommandSet.CommandSetID, 52 JDWPCommands.VirtualMachineCommandSet.ExitCommand); 53 packet.setNextValueAsInt(99); 54 55 debuggeeWrapper.vmMirror.performCommand(packet); 56 57 int exitCode = 0; 58 boolean exitLoop; 59 60 long timeOut = settings.getTimeout(); 61 long startTime = System.currentTimeMillis(); 62 do { 63 try { 64 exitCode = debuggeeWrapper.process.exitValue(); 65 exitLoop = true; 66 } catch (IllegalThreadStateException e) { 67 exitLoop = false; 68 } 69 if (System.currentTimeMillis() - startTime > timeOut) { 70 printErrorAndFail("Out of time: debugger did get " 71 + "no exit codes of debuggee"); 72 break; 73 } 74 } while (!exitLoop); 75 76 logWriter.println("exitCode = " + exitCode); 77 assertEquals("Invalid exit code,", 99, exitCode); 78 } 79 } 80