Home | History | Annotate | Download | only in VirtualMachine
      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     /**
     38      * The exit code for this test.
     39      */
     40     private static final int EXIT_CODE = 99;
     41 
     42     @Override
     43     protected String getDebuggeeClassName() {
     44         return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.SimpleHelloWorld";
     45     }
     46 
     47     @Override
     48     protected void beforeDebuggeeStart() {
     49         // Indicate that we expect the debuggee to exit with a particular code.
     50         debuggeeWrapper.setExpectedExitCode(EXIT_CODE);
     51         super.beforeDebuggeeStart();
     52     }
     53 
     54     /**
     55      * This testcase exercises VirtualMachine.Exit command.
     56      * <BR>At first the test starts HelloWorld debuggee.
     57      * <BR> Then the test performs VirtualMachine.Exit command
     58      * with exit code = 99 and checks that debuggee exit code, received
     59      * with help of debuggeeWrapper of test framework, is the same.
     60      */
     61     public void testExit001() {
     62         CommandPacket packet = new CommandPacket(
     63                 JDWPCommands.VirtualMachineCommandSet.CommandSetID,
     64                 JDWPCommands.VirtualMachineCommandSet.ExitCommand);
     65         packet.setNextValueAsInt(EXIT_CODE);
     66 
     67         debuggeeWrapper.vmMirror.performCommand(packet);
     68 
     69         int exitCode = 0;
     70         boolean exitLoop;
     71 
     72         long timeOut = settings.getTimeout();
     73         long startTime = System.currentTimeMillis();
     74         do {
     75             try {
     76                 exitCode = debuggeeWrapper.process.exitValue();
     77                 exitLoop = true;
     78             } catch (IllegalThreadStateException e) {
     79                 exitLoop = false;
     80             }
     81             if (System.currentTimeMillis() - startTime > timeOut) {
     82                 printErrorAndFail("Out of time: debugger did get "
     83                         + "no exit codes of debuggee");
     84                 break;
     85             }
     86         } while (!exitLoop);
     87 
     88         logWriter.println("exitCode = " + exitCode);
     89         assertEquals("Invalid exit code,", 99, exitCode);
     90     }
     91 }
     92