Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Dispose/dispose001.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.Dispose;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class dispose001 {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.Dispose";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "dispose001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "VirtualMachine.Dispose";41static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.Dispose;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 dispose001().runIt(argv, out);49}5051public int runIt(String argv[], PrintStream out) {5253boolean success = true;5455try {56final ArgumentHandler argumentHandler = new ArgumentHandler(argv);57final Log log = new Log(out, argumentHandler);5859try {6061Binder binder = new Binder(argumentHandler, log);62log.display("Start debugee VM");63final Debugee 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);7980int bytesToWrite = 1024;8182// begin test of JDWP command8384try {85log.display("Creating command packet for " + JDWP_COMMAND_NAME);86CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);8788log.display("Sending command packet:\n" + command);89transport.write(command);9091log.display("Waiting for reply packet");92ReplyPacket reply = new ReplyPacket();93transport.read(reply);94log.display("Reply packet received:\n" + reply);9596log.display("Checking reply packet header");97reply.checkHeader(command.getPacketID());9899log.display("Parsing reply packet:");100reply.resetPosition();101102if (! reply.isParsed()) {103log.complain("Extra bytes in reply packet at: " + reply.currentPosition());104success = false;105}106107log.display("Reply packet parsed successfully");108109} catch (Exception e) {110log.complain("Exception catched: " + e);111success = false;112}113114/*115// check if transport connection has been actually closed116117if (success) {118119log.display("Trying to write VirtualMachine.Version command packet "120+ "to the closed Transport connection");121122try {123CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.Version);124transport.write(command);125126log.complain("Command packet successfully written to the closed transport channel\n"127+ "without any I/O exception thrown");128success = false;129} catch (IOException e) {130log.display("Caught expected IOException:\n\t" + e);131}132133}134*/135136// end test of JDWP command137138log.display("Sending command: " + "quit");139pipe.println("quit");140141log.display("Waiting for debugee exits");142int code = debugee.waitFor();143if (code == JCK_STATUS_BASE + PASSED) {144log.display("Debugee PASSED: " + code);145} else {146log.complain("Debugee FAILED: " + code);147success = false;148}149150} catch (Exception e) {151log.complain("Unexpected exception: " + e);152e.printStackTrace(out);153success = false;154}155156if (!success) {157log.complain("TEST FAILED");158return FAILED;159}160161} catch (Exception e) {162out.println("Unexpected exception: " + e);163e.printStackTrace(out);164out.println("TEST FAILED");165return FAILED;166}167168out.println("TEST PASSED");169return PASSED;170171}172173}174175176