Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents001.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.HoldEvents;2425import java.io.*;2627import nsk.share.*;28import nsk.share.jpda.*;29import nsk.share.jdwp.*;3031/**32* Test for JDWP command: VirtualMachine.HoldEvents.33*34* See holdevents001.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 holdevents001 {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.HoldEvents";56static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "holdevents001";57static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";5859// tested JDWP command constants60static final String JDWP_COMMAND_NAME = "VirtualMachine.HoldEvents";61static final int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.HoldEvents;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 holdevents001().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// perform testing JDWP command119log.display("\n>>> Testing JDWP command \n");120testCommand();121122} finally {123124log.display("\n>>> Finishing test \n");125126// finally release events127log.display("Releasing events into debuggee");128releaseEvents();129130// quit debugee131quitDebugee();132}133134} catch (Failure e) {135log.complain("TEST FAILED: " + e.getMessage());136success = false;137} catch (Exception e) {138e.printStackTrace(out);139log.complain("Caught unexpected exception while running the test:\n\t" + e);140success = false;141}142143if (!success) {144log.complain("TEST FAILED");145return FAILED;146}147148out.println("TEST PASSED");149return PASSED;150151}152153/**154* Prepare debugee for testing and waiting for ready signal.155*/156void prepareDebugee() {157// wait for VM_INIT event from debugee158log.display("Waiting for VM_INIT event");159debugee.waitForVMInit();160161// query debugee for VM-dependent ID sizes162log.display("Querying for IDSizes");163debugee.queryForIDSizes();164165// resume initially suspended debugee166log.display("Resuming debugee VM");167debugee.resume();168169// wait for READY signal from debugee170log.display("Waiting for signal from debugee: " + READY);171String signal = pipe.readln();172log.display("Received signal from debugee: " + signal);173if (! signal.equals(READY)) {174throw new TestBug("Unexpected signal received from debugee: " + signal175+ " (expected: " + READY + ")");176}177}178179/**180* Sending debugee signal to quit and waiting for it exits.181*/182void quitDebugee() {183// send debugee signal to quit184log.display("Sending signal to debugee: " + QUIT);185pipe.println(QUIT);186187// wait for debugee exits188log.display("Waiting for debugee exits");189int code = debugee.waitFor();190191// analize debugee exit status code192if (code == JCK_STATUS_BASE + PASSED) {193log.display("Debugee PASSED with exit code: " + code);194} else {195log.complain("Debugee FAILED with exit code: " + code);196success = false;197}198}199200/**201* Release events into debuggee.202*/203void releaseEvents() {204CommandPacket command = new CommandPacket(JDWP.Command.VirtualMachine.ReleaseEvents);205ReplyPacket reply = debugee.receiveReplyFor(command);206}207208/**209* Perform testing JDWP command.210*/211void testCommand() {212// create command packet and fill requred out data213log.display("Create command packet:");214log.display("Command: " + JDWP_COMMAND_NAME);215CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);216command.setLength();217218// send command packet to debugee219try {220log.display("Sending command packet:\n" + command);221transport.write(command);222} catch (IOException e) {223log.complain("Unable to send command packet:\n\t" + e);224success = false;225return;226}227228ReplyPacket reply = new ReplyPacket();229230// receive reply packet from debugee231try {232log.display("Waiting for reply packet");233transport.read(reply);234log.display("Reply packet received:\n" + reply);235} catch (IOException e) {236log.complain("Unable to read reply packet:\n\t" + e);237success = false;238return;239}240241// check reply packet header242try{243log.display("Checking reply packet header");244reply.checkHeader(command.getPacketID());245} catch (BoundException e) {246log.complain("Bad header of reply packet:\n\t" + e.getMessage());247success = false;248return;249}250251// start parsing reply packet data252log.display("Parsing reply packet:");253reply.resetPosition();254255// no data in reply packet256257// check for extra data in reply packet258if (!reply.isParsed()) {259log.complain("Extra trailing bytes found in reply packet at: "260+ reply.offsetString());261success = false;262}263}264265}266267268