Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/TopLevelThreadGroups/threadgroups001.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.VirtualMachine.TopLevelThreadGroups;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class threadgroups001 {33static final int JCK_STATUS_BASE = 95;34static final int PASSED = 0;35static final int FAILED = 2;36static final String PACKAGE_NAME = "nsk.jdwp.VirtualMachine.TopLevelThreadGroups";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "threadgroups001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "VirtualMachine.TopLevelThreadGroups";41static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.TopLevelThreadGroups;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 threadgroups001().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);7980// begin test of JDWP command8182try {83CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);8485log.display("Sending command packet:\n" + command);86transport.write(command);8788log.display("Waiting for reply packet");89ReplyPacket reply = new ReplyPacket();90transport.read(reply);91log.display("Reply packet received:\n" + reply);9293log.display("Checking reply packet header");94reply.checkHeader(command.getPacketID());9596log.display("Parsing reply packet:");97reply.resetPosition();9899int groups = reply.getInt();100log.display(" groups: " + groups);101102for (int i = 0; i < groups; i++) {103long threadGroupID = reply.getObjectID();104log.display(" " + i + " threadGroupID: " + threadGroupID);105}106107if (! reply.isParsed()) {108log.complain("Extra bytes in reply packet at: " + reply.currentPosition());109success = false;110}111112if (groups < 0) {113log.complain("Negative number of returned thread groups: " + groups);114success = false;115}116117if (groups == 0) {118log.complain("No thread groups returned: " + groups);119success = false;120}121122} catch (Exception e) {123log.complain("Exception catched: " + e);124success = false;125}126127// end test of JDWP command128129log.display("Sending command: " + "quit");130pipe.println("quit");131132log.display("Waiting for debugee exits");133int code = debugee.waitFor();134if (code == JCK_STATUS_BASE + PASSED) {135log.display("Debugee PASSED: " + code);136} else {137log.complain("Debugee FAILED: " + code);138success = false;139}140141} catch (Exception e) {142log.complain("Unexpected exception: " + e);143e.printStackTrace(out);144success = false;145}146147if (!success) {148log.complain("TEST FAILED");149return FAILED;150}151152} catch (Exception e) {153out.println("Unexpected exception: " + e);154e.printStackTrace(out);155out.println("TEST FAILED");156return FAILED;157}158159out.println("TEST PASSED");160return PASSED;161162}163164}165166167