Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClasses/allclasses001.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.AllClasses;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class allclasses001 {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.AllClasses";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "allclasses001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "VirtualMachine.AllClasses";41static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.AllClasses;4243static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME;4445public static void main (String argv[]) {46System.exit(run(argv,System.out) + JCK_STATUS_BASE);47}4849public static int run(String argv[], PrintStream out) {50return new allclasses001().runIt(argv, out);51}5253public int runIt(String argv[], PrintStream out) {5455boolean success = true;5657try {58ArgumentHandler argumentHandler = new ArgumentHandler(argv);59Log log = new Log(out, argumentHandler);6061try {6263Binder binder = new Binder(argumentHandler, log);64log.display("Start debugee VM");65Debugee debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);66Transport transport = debugee.getTransport();67IOPipe pipe = debugee.createIOPipe();6869log.display("Waiting for VM_INIT event");70debugee.waitForVMInit();7172log.display("Querying for IDSizes");73debugee.queryForIDSizes();7475log.display("Resume debugee VM");76debugee.resume();7778log.display("Waiting for command: " + "ready");79String cmd = pipe.readln();80log.display("Received command: " + cmd);8182String classSignature = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";8384// begin test of JDWP command8586try {87CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);8889log.display("Sending command packet:\n" + command);90transport.write(command);9192log.display("Waiting for reply packet");93ReplyPacket reply = new ReplyPacket();94transport.read(reply);95log.display("Reply packet received:\n" + reply);9697log.display("Checking reply packet header");98reply.checkHeader(command.getPacketID());99100log.display("Parsing reply packet:");101reply.resetPosition();102103int classes = reply.getInt();104log.display(" classes: " + classes);105106int found = 0;107for (int i = 0; i < classes; i++) {108109byte refTypeTag = reply.getByte();110log.display(" " + i + " refTypeTag: " + refTypeTag);111112long typeID = reply.getReferenceTypeID();113log.display(" " + i + " typeID: " + typeID);114115String signature = reply.getString();116log.display(" " + i + " signature: " + signature);117118int status = reply.getInt();119log.display(" " + i + " status: " + status);120121if (signature.equals(classSignature)) {122found++;123log.display("FOUND: expected class signature: " + found + " time");124}125}126127if (! reply.isParsed()) {128log.complain("Extra bytes in reply packet at: " + reply.currentPosition());129success = false;130}131132if (classes < 0) {133log.complain("Negative number of returned classes: " + classes);134success = false;135}136137if (classes == 0) {138log.complain("No class returned");139success = false;140}141142if (found <= 0) {143log.complain("No expected class signature found: " + classSignature);144success = false;145}146147if (found > 1) {148log.complain("Too many classes (" + found + ") found for signature: " + classSignature);149success = false;150}151152} catch (Exception e) {153log.complain("Exception catched: " + e);154success = false;155}156157// end test of JDWP command158159log.display("Sending command: " + "quit");160pipe.println("quit");161162log.display("Waiting for debugee exits");163int code = debugee.waitFor();164if (code == JCK_STATUS_BASE + PASSED) {165log.display("Debugee PASSED: " + code);166} else {167log.complain("Debugee FAILED: " + code);168success = false;169}170171} catch (Exception e) {172log.complain("Unexpected exception: " + e);173e.printStackTrace(out);174success = false;175}176177if (!success) {178log.complain("TEST FAILED");179return FAILED;180}181182} catch (Exception e) {183out.println("Unexpected exception: " + e);184e.printStackTrace(out);185out.println("TEST FAILED");186return FAILED;187}188189out.println("TEST PASSED");190return PASSED;191192}193194}195196197