001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Vitaly A. Provodin
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 09.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
031: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
032: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
033:
034: /**
035: * JDWP Unit test for VirtualMachine.TopLevelThreadGroups command.
036: */
037: public class TopLevelThreadGroupsTest extends JDWPSyncTestCase {
038:
039: protected String getDebuggeeClassName() {
040: return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
041: }
042:
043: /**
044: * This testcase exercises VirtualMachine.TopLevelThreadGroups command.
045: * <BR>At first the test starts HelloWorld debuggee.
046: * <BR> Then the test performs VirtualMachine.TopLevelThreadGroups command
047: * and checks that:
048: * <BR> - number of returned thread groups is equal to 1;
049: * <BR> - there are no extra data in the reply packet;
050: * <BR>Also the test prints information about returned thread groups.
051: */
052: public void testTopLevelThreadGroups001() {
053: logWriter
054: .println("\n==> testTopLevelThreadGroups001: START...");
055: synchronizer
056: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
057:
058: logWriter
059: .println("==> Send VirtualMachine::TopLevelThreadGroups command...");
060: CommandPacket packet = new CommandPacket(
061: JDWPCommands.VirtualMachineCommandSet.CommandSetID,
062: JDWPCommands.VirtualMachineCommandSet.TopLevelThreadGroupsCommand);
063: ReplyPacket reply = debuggeeWrapper.vmMirror
064: .performCommand(packet);
065: checkReplyPacket(reply,
066: "VirtualMachine::TopLevelThreadGroups command");
067:
068: int groups = reply.getNextValueAsInt();
069: logWriter.println("==> Returned number of groups = " + groups);
070: assertEquals(1, groups);
071:
072: for (int i = 0; i < groups; i++) {
073:
074: long threadGroupID = reply.getNextValueAsThreadGroupID();
075: logWriter.println("\n==> Print info about ThreadGroup[" + i
076: + "]... ");
077: printThreadGroup(threadGroupID);
078:
079: }
080: assertAllDataRead(reply);
081: synchronizer
082: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
083: }
084:
085: private void printThreadGroup(long rootID) {
086: logWriter.println("==> ThreadGroupID = " + rootID);
087:
088: CommandPacket packet = new CommandPacket(
089: JDWPCommands.ThreadGroupReferenceCommandSet.CommandSetID,
090: JDWPCommands.ThreadGroupReferenceCommandSet.NameCommand);
091: packet.setNextValueAsThreadGroupID(rootID);
092: ReplyPacket replyParent = debuggeeWrapper.vmMirror
093: .performCommand(packet);
094: checkReplyPacket(replyParent,
095: "ThreadGroupReference::Name command");
096:
097: String threadGroupIDName = replyParent.getNextValueAsString();
098: logWriter.println("==> threadGroupIDName = |"
099: + threadGroupIDName + "|");
100:
101: logWriter
102: .println("==> Send ThreadGroupReference::Children command...");
103: packet = new CommandPacket(
104: JDWPCommands.ThreadGroupReferenceCommandSet.CommandSetID,
105: JDWPCommands.ThreadGroupReferenceCommandSet.ChildrenCommand);
106: packet.setNextValueAsThreadGroupID(rootID);
107: ReplyPacket replyChilds = debuggeeWrapper.vmMirror
108: .performCommand(packet);
109: checkReplyPacket(replyChilds,
110: "ThreadGroupReference::Children command");
111:
112: int childThreads = replyChilds.getNextValueAsInt();
113: logWriter
114: .println("==> Returned child threads: " + childThreads);
115:
116: for (int j = 0; j < childThreads; j++) {
117: long id = replyChilds.getNextValueAsThreadID();
118: logWriter.println("\n==> childThreadID[" + j + "] = " + id);
119:
120: packet = new CommandPacket(
121: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
122: JDWPCommands.ThreadReferenceCommandSet.NameCommand);
123: packet.setNextValueAsThreadID(id);
124: replyParent = debuggeeWrapper.vmMirror
125: .performCommand(packet);
126: checkReplyPacket(replyParent,
127: "ThreadReference::Name command");
128:
129: String name = replyParent.getNextValueAsString();
130: logWriter.println("==> childThreadName[" + j + "] = "
131: + name);
132: }
133:
134: int childGroups = replyChilds.getNextValueAsInt();
135: logWriter
136: .println("\n==> Returned child groups: " + childGroups);
137:
138: for (int j = 0; j < childGroups; j++) {
139: long id = replyChilds.getNextValueAsThreadGroupID();
140: logWriter.println("\n==> childGroupID[" + j + "] = " + id);
141:
142: packet = new CommandPacket(
143: JDWPCommands.ThreadGroupReferenceCommandSet.CommandSetID,
144: JDWPCommands.ThreadGroupReferenceCommandSet.NameCommand);
145: packet.setNextValueAsThreadGroupID(id);
146: replyParent = debuggeeWrapper.vmMirror
147: .performCommand(packet);
148: checkReplyPacket(replyParent,
149: "ThreadGroupReference::Name command");
150:
151: String name = replyParent.getNextValueAsString();
152: logWriter
153: .println("==> childGroupName[" + j + "] = " + name);
154:
155: logWriter
156: .println("\n==> Print info about child ThreadGroup \"main\"... ");
157: if ("main".equals(name)) {
158: printThreadGroup(id);
159: }
160: }
161: }
162:
163: public static void main(String[] args) {
164: junit.textui.TestRunner.run(TopLevelThreadGroupsTest.class);
165: }
166: }
|