Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents001.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.ReleaseEvents;2425import java.io.*;2627import nsk.share.*;28import nsk.share.jpda.*;29import nsk.share.jdwp.*;3031/**32* Test for JDWP command: VirtualMachine.ReleaseEvents.33*34* See releaseevents001.README for description of test execution.35*36* This class represents debugger part of the test.37* Test is executed by invoking method runIt().38* JDWP command is tested in the method testCommand().39*40* @see #runIt()41* @see #testCommand()42*/43public class releaseevents001 {4445// exit status constants46static final int JCK_STATUS_BASE = 95;47static final int PASSED = 0;48static final int FAILED = 2;4950// communication signals constants51static final String READY = "ready";52static final String QUIT = "quit";5354// package and classes names constants55static final String PACKAGE_NAME = "nsk.jdwp.VirtualMachine.ReleaseEvents";56static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "releaseevents001";57static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";5859// tested JDWP command constants60static final String JDWP_COMMAND_NAME = "VirtualMachine.ReleaseEvents";61static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.ReleaseEvents;6263// usual scaffold objects64ArgumentHandler argumentHandler = null;65Log log = null;66Binder binder = null;67Debugee debugee = null;68Transport transport = null;69IOPipe pipe = null;7071// test passed or not72boolean success = true;7374// -------------------------------------------------------------------7576/**77* Start test from command line.78*/79public static void main (String argv[]) {80System.exit(run(argv,System.out) + JCK_STATUS_BASE);81}8283/**84* Start JCK-compilant test.85*/86public static int run(String argv[], PrintStream out) {87return new releaseevents001().runIt(argv, out);88}8990// -------------------------------------------------------------------9192/**93* Perform test execution.94*/95public int runIt(String argv[], PrintStream out) {9697// make log for debugger messages98argumentHandler = new ArgumentHandler(argv);99log = new Log(out, argumentHandler);100101// execute test and display results102try {103log.display("\n>>> Preparing debugee for testing \n");104105// launch debuggee106binder = new Binder(argumentHandler, log);107log.display("Launching debugee");108debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);109transport = debugee.getTransport();110pipe = debugee.createIOPipe();111112// make debuggee ready for testing113prepareDebugee();114115// work with prepared debuggee116try {117118// finally release events119log.display("Holding events into debuggee");120holdEvents();121122// perform testing JDWP command123log.display("\n>>> Testing JDWP command \n");124testCommand();125126} finally {127128// quit debugee129log.display("\n>>> Finishing test \n");130quitDebugee();131}132133} catch (Failure e) {134log.complain("TEST FAILED: " + e.getMessage());135success = false;136} catch (Exception e) {137e.printStackTrace(out);138log.complain("Caught unexpected exception while running the test:\n\t" + e);139success = false;140}141142if (!success) {143log.complain("TEST FAILED");144return FAILED;145}146147out.println("TEST PASSED");148return PASSED;149150}151152/**153* Prepare debugee for testing and waiting for ready signal.154*/155void prepareDebugee() {156// wait for VM_INIT event from debugee157log.display("Waiting for VM_INIT event");158debugee.waitForVMInit();159160// query debugee for VM-dependent ID sizes161log.display("Querying for IDSizes");162debugee.queryForIDSizes();163164// resume initially suspended debugee165log.display("Resuming debugee VM");166debugee.resume();167168// wait for READY signal from debugee169log.display("Waiting for signal from debugee: " + READY);170String signal = pipe.readln();171log.display("Received signal from debugee: " + signal);172if (! signal.equals(READY)) {173throw new TestBug("Unexpected signal received from debugee: " + signal174+ " (expected: " + READY + ")");175}176}177178/**179* Sending debugee signal to quit and waiting for it exits.180*/181void quitDebugee() {182// send debugee signal to quit183log.display("Sending signal to debugee: " + QUIT);184pipe.println(QUIT);185186// wait for debugee exits187log.display("Waiting for debugee exits");188int code = debugee.waitFor();189190// analize debugee exit status code191if (code == JCK_STATUS_BASE + PASSED) {192log.display("Debugee PASSED with exit code: " + code);193} else {194log.complain("Debugee FAILED with exit code: " + code);195success = false;196}197}198199/**200* Hold events into debuggee.201*/202void holdEvents() {203CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.HoldEvents);204ReplyPacket reply = debugee.receiveReplyFor(command);205}206207/**208* Perform testing JDWP command.209*/210void testCommand() {211// create command packet and fill requred out data212log.display("Create command packet:");213log.display("Command: " + JDWP_COMMAND_NAME);214CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);215command.setLength();216217// send command packet to debugee218try {219log.display("Sending command packet:\n" + command);220transport.write(command);221} catch (IOException e) {222log.complain("Unable to send command packet:\n\t" + e);223success = false;224return;225}226227ReplyPacket reply = new ReplyPacket();228229// receive reply packet from debugee230try {231log.display("Waiting for reply packet");232transport.read(reply);233log.display("Reply packet received:\n" + reply);234} catch (IOException e) {235log.complain("Unable to read reply packet:\n\t" + e);236success = false;237return;238}239240// check reply packet header241try{242log.display("Checking reply packet header");243reply.checkHeader(command.getPacketID());244} catch (BoundException e) {245log.complain("Bad header of reply packet:\n\t" + e.getMessage());246success = false;247return;248}249250// start parsing reply packet data251log.display("Parsing reply packet:");252reply.resetPosition();253254// no data in reply packet255256// check for extra data in reply packet257if (!reply.isParsed()) {258log.complain("Extra trailing bytes found in reply packet at: "259+ reply.offsetString());260success = false;261}262}263264}265266267