Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Name/name001.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.Name;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class name001 {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.Name";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "name001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "ThreadGroupReference.Name";41static final int JDWP_COMMAND_ID = JDWP.Command.ThreadGroupReference.Name;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 name001().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();152153String groupName = reply.getString();154log.display(" groupName: " + groupName);155156if (! reply.isParsed()) {157log.complain("Extra trailing bytes found in reply packet at: " + reply.currentPosition());158success = false;159} else {160log.display("Reply packet parsed successfully");161}162}163164// end test of JDWP command165166} catch (Exception e) {167log.complain("Caught exception while testing JDWP command: " + e);168success = false;169} finally {170log.display("Sending command: " + "quit");171pipe.println("quit");172173log.display("Waiting for debugee exits");174int code = debugee.waitFor();175if (code == JCK_STATUS_BASE + PASSED) {176log.display("Debugee PASSED with exit code: " + code);177} else {178log.complain("Debugee FAILED with exit code: " + code);179success = false;180}181}182183} catch (Exception e) {184log.complain("Caught unexpected exception while communicating with debugee: " + e);185e.printStackTrace(out);186success = false;187}188189if (!success) {190log.complain("TEST FAILED");191return FAILED;192}193194} catch (Exception e) {195out.println("Caught unexpected exception while starting the test: " + e);196e.printStackTrace(out);197out.println("TEST FAILED");198return FAILED;199}200201out.println("TEST PASSED");202return PASSED;203204}205206}207208209