Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Children/children001.java
41161 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdwp.ThreadGroupReference.Children;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class children001 {33static final int JCK_STATUS_BASE = 95;34static final int PASSED = 0;35static final int FAILED = 2;36static final String PACKAGE_NAME = "nsk.jdwp.ThreadGroupReference.Children";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "children001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "ThreadGroupReference.Children";41static final int JDWP_COMMAND_ID = JDWP.Command.ThreadGroupReference.Children;4243public static void main (String argv[]) {44System.exit(run(argv,System.out) + JCK_STATUS_BASE);45}4647public static int run(String argv[], PrintStream out) {48return new children001().runIt(argv, out);49}5051public int runIt(String argv[], PrintStream out) {5253boolean success = true;5455try {56ArgumentHandler argumentHandler = new ArgumentHandler(argv);57Log log = new Log(out, argumentHandler);5859try {6061Binder binder = new Binder(argumentHandler, log);62log.display("Start debugee VM");63Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);64Transport transport = debugee.getTransport();65IOPipe pipe = debugee.createIOPipe();6667log.display("Waiting for VM_INIT event");68debugee.waitForVMInit();6970log.display("Querying for IDSizes");71debugee.queryForIDSizes();7273log.display("Resume debugee VM");74debugee.resume();7576log.display("Waiting for command: " + "ready");77String cmd = pipe.readln();78log.display("Received command: " + cmd);798081try {8283// get top level thread groups8485log.display("Getting IDs for top level thread groups");8687long[] threadGroupIDs = null;88int groups = 0;8990{91log.display("Create command packet " + "TopLevelThreadGroups");92CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.TopLevelThreadGroups);9394log.display("Waiting for reply to command");95ReplyPacket reply = debugee.receiveReplyFor(command);96log.display("Valid reply packet received");9798log.display("Parsing reply packet:");99reply.resetPosition();100101groups = reply.getInt();102log.display(" groups: " + groups);103104threadGroupIDs = new long[groups];105106for (int i = 0; i < groups; i++) {107long threadGroupID = reply.getObjectID();108log.display(" " + i + " threadGroupID: " + threadGroupID);109threadGroupIDs[i] = threadGroupID;110}111112if (groups < 0) {113log.complain("Negative number of thread groups returned while getting top level thread groups IDs: " + groups);114success = false;115}116117if (groups == 0) {118log.complain("No thread groups IDs returned while getting top level thread groups IDs: " + groups);119success = false;120}121122}123124// begin test of JDWP command125126for (int i = 0; i < groups; i++) {127128long threadGroupID = threadGroupIDs[i];129130log.display("Getting name for " + i + " group ID: "131+ threadGroupID);132133log.display("Create command " + JDWP_COMMAND_NAME134+ " with thread group ID: " + threadGroupID);135CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);136command.addObjectID(threadGroupID);137command.setLength();138139log.display("Sending command packet:\n" + command);140transport.write(command);141142log.display("Waiting for reply packet");143ReplyPacket reply = new ReplyPacket();144transport.read(reply);145log.display("Reply packet received:\n" + reply);146147log.display("Checking reply packet header");148reply.checkHeader(command.getPacketID());149150log.display("Parsing reply packet:");151reply.resetPosition();152153int childThreads = reply.getInt();154log.display(" childThreads: " + childThreads);155156for (int j = 0; j < childThreads; j++) {157long childThread = reply.getObjectID();158log.display(" " + j + " childThread: " + childThread);159}160161int childGroups = reply.getInt();162log.display(" childGroups: " + childGroups);163164for (int j = 0; j < childGroups; j++) {165long childGroup = reply.getObjectID();166log.display(" " + j + " childGroup: " + childGroup);167}168169if (! reply.isParsed()) {170log.complain("Extra trailing bytes found in reply packet at: " + reply.currentPosition());171success = false;172} else {173log.display("Reply packet parsed successfully");174}175}176177// end test of JDWP command178179} catch (Exception e) {180log.complain("Caught exception while testing JDWP command: " + e);181success = false;182} finally {183log.display("Sending command: " + "quit");184pipe.println("quit");185186log.display("Waiting for debugee exits");187int code = debugee.waitFor();188if (code == JCK_STATUS_BASE + PASSED) {189log.display("Debugee PASSED with exit code: " + code);190} else {191log.complain("Debugee FAILED with exit code: " + code);192success = false;193}194}195196} catch (Exception e) {197log.complain("Caught unexpected exception while communicating with debugee: " + e);198e.printStackTrace(out);199success = false;200}201202if (!success) {203log.complain("TEST FAILED");204return FAILED;205}206207} catch (Exception e) {208out.println("Caught unexpected exception while starting the test: " + e);209e.printStackTrace(out);210out.println("TEST FAILED");211return FAILED;212}213214out.println("TEST PASSED");215return PASSED;216217}218219}220221222