Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CreateString/createstr001.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.CreateString;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdwp.*;2829import java.io.*;30import java.util.*;3132public class createstr001 {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.CreateString";37static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "createstr001";38static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";3940static final String JDWP_COMMAND_NAME = "VirtualMachine.CreateString";41static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.CreateString;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 createstr001().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);7980String stringValue = "Testing string value";8182// begin test of JDWP command8384try {85log.display("Create command " + JDWP_COMMAND_NAME86+ " with string value: " + stringValue);87CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);88command.addString(stringValue);89command.setLength();9091log.display("Sending command packet:\n" + command);92transport.write(command);9394log.display("Waiting for reply packet");95ReplyPacket reply = new ReplyPacket();96transport.read(reply);97log.display("Reply packet received:\n" + reply);9899log.display("Checking reply packet header");100reply.checkHeader(command.getPacketID());101102log.display("Parsing reply packet:");103reply.resetPosition();104105long stringID = reply.getObjectID();106log.display(" stringID: " + stringID);107108if (! reply.isParsed()) {109log.complain("Extra bytes in reply packet at: " + reply.currentPosition());110success = false;111}112113} catch (Exception e) {114log.complain("Exception catched: " + e);115success = false;116}117118// end test of JDWP command119120log.display("Sending command: " + "quit");121pipe.println("quit");122123log.display("Waiting for debugee exits");124int code = debugee.waitFor();125if (code == JCK_STATUS_BASE + PASSED) {126log.display("Debugee PASSED: " + code);127} else {128log.complain("Debugee FAILED: " + code);129success = false;130}131132} catch (Exception e) {133log.complain("Unexpected exception: " + e);134e.printStackTrace(out);135success = false;136}137138if (!success) {139log.complain("TEST FAILED");140return FAILED;141}142143} catch (Exception e) {144out.println("Unexpected exception: " + e);145e.printStackTrace(out);146out.println("TEST FAILED");147return FAILED;148}149150out.println("TEST PASSED");151return PASSED;152153}154155}156157158