Home | History | Annotate | Download | only in VMDebug
      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.VMDebug;
     20 
     21 import org.apache.harmony.jpda.tests.framework.TestOptions;
     22 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
     23 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
     24 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
     25 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
     26 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
     27 import org.apache.harmony.jpda.tests.jdwp.share.JDWPTestConstants;
     28 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     29 
     30 /**
     31  * JDWP Unit test for VMDebug functions command
     32  */
     33 public class VMDebugTest002 extends JDWPSyncTestCase {
     34     @Override
     35     protected String getDebuggeeClassName() {
     36         return "org.apache.harmony.jpda.tests.jdwp.VMDebug.VMDebugDebuggee";
     37     }
     38 
     39     // We will need to disconnect once to clear out the VM_INIT resume that we get on startup.
     40     @Override
     41     protected void beforeConnectionSetUp() {
     42         settings.setAttachConnectorKind();
     43         if (settings.getTransportAddress() == null) {
     44             settings.setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
     45         }
     46         logWriter.println("ATTACH connector kind");
     47         super.beforeConnectionSetUp();
     48     }
     49 
     50     /**
     51      * JDWP DDM Command Set constants
     52      *
     53      * TODO It would be good to get these out of the DDMTest class but that class won't be there in
     54      * all configurations.
     55      */
     56     public static class DDMCommandSet {
     57         public static final byte CommandSetID = -57; // uint8_t value is 199
     58 
     59         public static final byte ChunkCommand = 1;
     60     }
     61 
     62     private void sendDdmDebuggerActivity() {
     63         int type = 0xABCDEF01;
     64         logWriter.println("Send DDM.Chunk command with type " + type + " and no data");
     65         CommandPacket packet = new CommandPacket(
     66                 DDMCommandSet.CommandSetID,
     67                 DDMCommandSet.ChunkCommand);
     68         packet.setNextValueAsInt(type);
     69         packet.setNextValueAsInt(0x0);
     70         ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
     71 
     72         checkReplyPacket(reply, "DDM::Chunk command");
     73         // Shouldn't have any data.
     74         assertAllDataRead(reply);
     75     }
     76 
     77     public void testVMDebug() {
     78         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     79         // Close and reopen connection to clear out any activity from VM_INIT or other places.
     80         logWriter.println("=> CLOSE CONNECTION");
     81         closeConnection();
     82         logWriter.println("=> CONNECTION CLOSED");
     83         logWriter.println("=> OPEN NEW CONNECTION");
     84         // Don't use the openConnection helper since that will call JDWP functions to figure out the
     85         // type-lengths.
     86         openConnectionWithoutTypeLength();
     87         logWriter.println("=> CONNECTION OPENED");
     88         // Do something that resets the debugger activity count.
     89         sendDdmDebuggerActivity();
     90         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     91         // Get the results.
     92         VMDebugDebuggee.DebugResult res = VMDebugDebuggee.readResult(synchronizer.receiveMessage());
     93         if (res == null) {
     94             fail("unable to deserialize result data");
     95         } else {
     96             logWriter.println("Received results: " + res);
     97             assertFalse("no error expected", res.error_occured);
     98             assertTrue("expected debugger to be enabled!", res.is_debugging_enabled);
     99             assertFalse(
    100                 "expected no active debugger connection since no non-ddms commands were sent!",
    101                 res.is_debugger_connected);
    102             assertEquals("Expected no last-debugger-activity", -1L, res.last_debugger_activity);
    103         }
    104         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    105     }
    106 }
    107