Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version002.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.Version;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132public class version002 {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.Version";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "version002";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "VirtualMachine.Version";41static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.Version;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 version002().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);84// A properly formed CommandPacket has JDWP.Flag.NONE85// for the 'flags' field. Set the 'flags' field to '!'86// simulate a bad value in the printable ASCII range.87// '!' == 0x21 which means the bad value also does not88// have the JDWP.Flag.REPLY_PACKET (0x80) set.89command.setFlags((byte) '!');9091log.display("Sending command packet:\n" + command);92transport.write(command);9394log.display("Waiting for reply packet");95ReplyPacket reply = new ReplyPacket();96transport.read(reply);9798if (true) {99// In this test (compared to version001), we100// should never reach here because the debuggee101// should have thrown an IOException and printed102// this error message:103// ERROR: Received jdwpPacket with flags != 0x0 (actual=0x21) when a jdwpCmdPacket was expected.104105throw new Failure("Debuggee did not detect bad flags field.");106}107// The code below this point of the try-catch block is108// not reachable and could be deleted. It is left in109// place to ease porting of this test to earlier releases.110111log.display("Reply packet received:\n" + reply);112113log.display("Checking reply packet header");114reply.checkHeader(command.getPacketID());115116log.display("Parsing reply packet:");117reply.resetPosition();118119String description = reply.getString();120log.display(" description: " + description);121122int jdwpMajor = reply.getInt();123log.display(" jdwpMajor: " + jdwpMajor);124125int jdwpMinor = reply.getInt();126log.display(" jdwpMinor: " + jdwpMinor);127128String vmVersion = reply.getString();129log.display(" vmVersion: " + vmVersion);130131String vmName = reply.getString();132log.display(" vmName: " + vmName);133134if (! reply.isParsed()) {135log.complain("Extra bytes in reply packet at: " + reply.currentPosition());136success = false;137}138139} catch (IOException ie) {140// version001 expects to pass.141// This test expects to fail due to an IOException.142log.display("Expected IOException caught: " + ie);143success = true;144} catch (Exception e) {145log.complain("Exception catched: " + e);146success = false;147}148149// end test of JDWP command150151log.display("Sending command: " + "quit");152pipe.println("quit");153154log.display("Waiting for debugee exits");155int code = debugee.waitFor();156if (code == JCK_STATUS_BASE + PASSED) {157log.display("Debugee PASSED: " + code);158} else {159log.complain("Debugee FAILED: " + code);160success = false;161}162163} catch (Exception e) {164log.complain("Unexpected exception: " + e);165e.printStackTrace(out);166success = false;167}168169if (!success) {170log.complain("TEST FAILED");171return FAILED;172}173174} catch (Exception e) {175out.println("Unexpected exception: " + e);176e.printStackTrace(out);177out.println("TEST FAILED");178return FAILED;179}180181out.println("TEST PASSED");182return PASSED;183184}185186}187188189