• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 15.02.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.ReplyPacket;
31 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
32 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
33 
34 
35 /**
36  * JDWP Unit test for ThreadReference.ThreadGroup command.
37  */
38 public class ThreadGroupTest extends JDWPSyncTestCase {
39 
40     @Override
getDebuggeeClassName()41     protected String getDebuggeeClassName() {
42         return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.ThreadGroupDebuggee";
43     }
44 
45     /**
46      * This testcase exercises ThreadReference.ThreadGroup command.
47      * <BR>At first the test starts ThreadGroupDebuggee which creates
48      * 'TESTED_GROUP' ThreadGroup and starts the 'TESTED_THREAD' thread which
49      * belongs to that thread group.
50      * <BR>After the tested thread starts but does not finish, test requests all
51      * debuggee threads by VirtualMachine.AllThreads command and looks for tested thread.
52      * <BR>If the tested thread is not found the test fails.
53      * <BR>If the tested thread is found the test checks that
54      * ThreadReference.ThreadGroup command for tested thread returns 'TESTED_GROUP' thread group.
55      */
testThreadGroup001()56     public void testThreadGroup001() {
57         logWriter.println("wait for SGNL_READY");
58         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
59 
60         // getting ID of the tested thread
61         CommandPacket packet;
62         logWriter.println("get all threads");
63         ReplyPacket replyThread, reply = debuggeeWrapper.vmMirror.getAllThreadID();
64         int threads = reply.getNextValueAsInt();
65         logWriter.println("exercise threads = " + threads);
66 
67         long threadID, groupID;
68         String groupName, threadName;
69         int count = 0;
70 
71         for (int i = 0; i < threads; i++) {
72             threadID = reply.getNextValueAsThreadID();
73 
74             // getting the thread group ID
75             packet = new CommandPacket(
76                     JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
77                     JDWPCommands.ThreadReferenceCommandSet.ThreadGroupCommand);
78             packet.setNextValueAsThreadID(threadID);
79 
80             replyThread = debuggeeWrapper.vmMirror.performCommand(packet);
81             checkReplyPacket(replyThread, "ThreadReference::ThreadGroup command");
82 
83             groupID = replyThread.getNextValueAsThreadGroupID();
84 
85             groupName = debuggeeWrapper.vmMirror.getThreadGroupName(groupID);
86             threadName = debuggeeWrapper.vmMirror.getThreadName(threadID);
87 
88             logWriter.println("\tthreadID=" + threadID
89                     + "; threadName=" + threadName
90                     + "; groupID=" + groupID
91                     + "; groupName=" + groupName);
92 
93             if (threadName.equals(ThreadGroupDebuggee.TESTED_THREAD)) {
94                 if (!groupName.equals(ThreadGroupDebuggee.TESTED_GROUP)) {
95                     printErrorAndFail("unexpected group name, it is expected: "
96                             + ThreadGroupDebuggee.TESTED_GROUP);
97                 }
98                 count++;
99             }
100         }
101         if (count == 0) {
102             printErrorAndFail("Tested thread is not found in all_threads list.");
103         }
104 
105         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
106         logWriter.println("waiting for finishing thread");
107         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
108         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
109     }
110 }
111