Home | History | Annotate | Download | only in ThreadReference
      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 Anatoly F. Bondarenko
     21  */
     22 
     23 /**
     24  * Created on 31.03.2005
     25  */
     26 package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
     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.framework.jdwp.JDWPConstants;
     31 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
     32 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
     33 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     34 
     35 
     36 /**
     37  * JDWP Unit test for ThreadReference.Status command for the Thread waiting for time.
     38  */
     39 public class Status003Test extends JDWPSyncTestCase {
     40 
     41     static final int testStatusPassed = 0;
     42     static final int testStatusFailed = -1;
     43 
     44     protected String getDebuggeeClassName() {
     45         return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.Status003Debuggee";
     46     }
     47 
     48     String getThreadSuspendStatusName(int suspendStatus) {
     49 
     50         String result = JDWPConstants.SuspendStatus.getName(suspendStatus);
     51         if ( result.equals("") ) {
     52             result = "NOT_SUSPENDED";
     53         }
     54         return result;
     55     }
     56 
     57     /**
     58      * This testcase exercises ThreadReference.Status command for the Thread waiting for time.
     59      * <BR>At first the test starts Status003Debuggee which runs
     60      * the tested thread and blocks it in invocation of
     61      * the 'Object.wait(mlsecTime)' method.
     62      * <BR> Then the tests performs the ThreadReference.Status command
     63      * for tested thread.
     64      * <BR>It is expected that:
     65      * <BR>&nbsp;&nbsp; - returned thread status is WAIT status;
     66      * <BR>&nbsp;&nbsp; - returned suspend status is not SUSPEND_STATUS_SUSPENDED status;
     67      */
     68     public void testStatus004() {
     69         String thisTestName = "testStatus004";
     70         logWriter.println("==> " + thisTestName + " for ThreadReference.Status command: START...");
     71         logWriter.println("==> This " + thisTestName
     72             + " checks command for TIMED_WAITING Thread: which is waiting in Object.wait(Time) method...");
     73         String checkedThreadName = synchronizer.receiveMessage();
     74         logWriter.println("=> checkedThreadName = " + checkedThreadName);
     75 
     76         long checkedThreadID = debuggeeWrapper.vmMirror.getThreadID(checkedThreadName);
     77         logWriter.println("=> checkedThreadID = " + checkedThreadID);
     78 
     79         logWriter.println
     80         ("=> Send ThreadReference.Status command for checked Thread and check reply...");
     81         CommandPacket checkedCommand = new CommandPacket(
     82                 JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
     83                 JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
     84         checkedCommand.setNextValueAsThreadID(checkedThreadID);
     85 
     86         ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
     87         checkReplyPacket(checkedReply, "ThreadReference.Status command");
     88 
     89         int threadStatus = checkedReply.getNextValueAsInt();
     90         int suspendStatus = checkedReply.getNextValueAsInt();
     91 
     92         logWriter.println("\n=> Returned thread status = 0x" + Integer.toHexString(threadStatus)
     93                 + "(" + JDWPConstants.ThreadStatus.getName(threadStatus) + ")");
     94         if (threadStatus != JDWPConstants.ThreadStatus.WAIT) {
     95             finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
     96             printErrorAndFail("Unexpected thread status is returned:"
     97                 + "\nExpected thread status = 0x"
     98                 + Integer.toHexString(JDWPConstants.ThreadStatus.WAIT)
     99                 + "(" + JDWPConstants.ThreadStatus.getName(JDWPConstants.ThreadStatus.WAIT) + ")");
    100         } else {
    101             logWriter.println("=> OK - Expected thread status is returned");
    102         }
    103 
    104         logWriter.println
    105             ("\n=> Returned thread suspend status = 0x" + Integer.toHexString(suspendStatus)
    106             + "(" + getThreadSuspendStatusName(suspendStatus) + ")");
    107         if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
    108             finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
    109             printErrorAndFail("Unexpected thread status is returned:"
    110                 + "## Expected thread status = 0x"
    111                 + Integer.toHexString(0)
    112                 + "(" + getThreadSuspendStatusName(0) + ")");
    113         } else {
    114             logWriter.println("=> OK - Expected thread suspend status is returned");
    115         }
    116 
    117         logWriter.println("=> Send to Debuggee signal to funish ...");
    118         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    119 
    120         logWriter.println("==> " + thisTestName + " for ThreadReference.Status command: FINISH...");
    121     }
    122 }
    123