Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassPaths/classpaths001.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.ClassPaths;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class classpaths001 {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.ClassPaths";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "classpaths001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "VirtualMachine.ClassPaths";41static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.ClassPaths;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 classpaths001().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();9899String baseDir = reply.getString();100log.display(" baseDir: " + baseDir);101102int classpaths = reply.getInt();103log.display(" classpaths: " + classpaths);104105for (int i = 0; i < classpaths; i++) {106String path = reply.getString();107log.display(" " + i + " path: " + path);108}109110int bootclasspaths = reply.getInt();111log.display(" bootclasspaths: " + bootclasspaths);112113for (int i = 0; i < bootclasspaths; i++) {114String path = reply.getString();115log.display(" " + i + " path: " + path);116}117118if (! reply.isParsed()) {119log.complain("Extra bytes in reply packet at: " + reply.currentPosition());120success = false;121}122123} catch (Exception e) {124log.complain("Exception catched: " + e);125success = false;126}127128// end test of JDWP command129130log.display("Sending command: " + "quit");131pipe.println("quit");132133log.display("Waiting for debugee exits");134int code = debugee.waitFor();135if (code == JCK_STATUS_BASE + PASSED) {136log.display("Debugee PASSED: " + code);137} else {138log.complain("Debugee FAILED: " + code);139success = false;140}141142} catch (Exception e) {143log.complain("Unexpected exception: " + e);144e.printStackTrace(out);145success = false;146}147148if (!success) {149log.complain("TEST FAILED");150return FAILED;151}152153} catch (Exception e) {154out.println("Unexpected exception: " + e);155e.printStackTrace(out);156out.println("TEST FAILED");157return FAILED;158}159160out.println("TEST PASSED");161return PASSED;162163}164165}166167168