Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp002.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.EventRequest.ClearAllBreakpoints;2425import java.io.*;2627import nsk.share.*;28import nsk.share.jpda.*;29import nsk.share.jdwp.*;3031/**32* Test for JDWP command: EventRequest.ClearAllBreakpoints.33*34* See clrallbreakp002.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 #waitForTestedEvent()42*/43public class clrallbreakp002 {4445// exit status constants46static final int JCK_STATUS_BASE = 95;47static final int PASSED = 0;48static final int FAILED = 2;4950// package and classes names constants51static final String PACKAGE_NAME = "nsk.jdwp.EventRequest.ClearAllBreakpoints";52static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "clrallbreakp002";53static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";5455// tested JDWP command constants56static final String JDWP_COMMAND_NAME = "EventRequest.ClearAllBreakpoints";57static final int JDWP_COMMAND_ID = JDWP.Command.EventRequest.ClearAllBreakpoints;58static final byte TESTED_EVENT_KIND = JDWP.EventKind.VM_START;59static final byte TESTED_EVENT_SUSPEND_POLICY = JDWP.SuspendPolicy.ALL;6061// name and signature of the tested class62static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";63static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";6465// usual scaffold objects66ArgumentHandler argumentHandler = null;67Log log = null;68Binder binder = null;69Debugee debugee = null;70Transport transport = null;71int waitTime = 0; // minutes72long timeout = 0; // milliseconds73boolean dead = false;74boolean success = true;7576// obtained data77long testedClassID = 0;7879// -------------------------------------------------------------------8081/**82* Start test from command line.83*/84public static void main(String argv[]) {85System.exit(run(argv,System.out) + JCK_STATUS_BASE);86}8788/**89* Start test from JCK-compilant environment.90*/91public static int run(String argv[], PrintStream out) {92return new clrallbreakp002().runIt(argv, out);93}9495// -------------------------------------------------------------------9697/**98* Perform test execution.99*/100public int runIt(String argv[], PrintStream out) {101102// make log for debugger messages103argumentHandler = new ArgumentHandler(argv);104log = new Log(out, argumentHandler);105waitTime = argumentHandler.getWaitTime();106timeout = waitTime * 60 * 1000;107108// execute test and display results109try {110log.display("\n>>> Starting debugee \n");111112// launch debuggee113binder = new Binder(argumentHandler, log);114log.display("Launching debugee");115debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);116transport = debugee.getTransport();117log.display(" ... debugee launched");118log.display("");119120// set timeout for debuggee responces121log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)");122transport.setReadTimeout(timeout);123log.display(" ... timeout set");124125// wait for debuggee started126log.display("Waiting for VM_INIT event");127debugee.waitForVMInit();128log.display(" ... VM_INIT event received");129130// query debugee for VM-dependent ID sizes131log.display("Querying for IDSizes");132debugee.queryForIDSizes();133log.display(" ... size of VM-dependent types adjusted");134135// get debuggee prepared for testing136log.display("\n>>> Getting prepared for testing \n");137prepareForTest();138139// test JDWP command140log.display("\n>>> Testing JDWP command \n");141testCommand();142143log.display("\n>>> Finishing debuggee \n");144145// resume debuggee146log.display("Resuming debuggee");147debugee.resume();148log.display(" ... debuggee resumed");149150// wait for debuggee exited151log.display("Waiting for VM_DEATH event");152debugee.waitForVMDeath();153dead = true;154log.display(" ... VM_DEATH event received");155156} catch (Failure e) {157log.complain("TEST FAILED: " + e.getMessage());158success = false;159} catch (Exception e) {160e.printStackTrace(out);161log.complain("Caught unexpected exception while running the test:\n\t" + e);162success = false;163} finally {164// quit debugee165log.display("\n>>> Finishing test \n");166quitDebugee();167}168169// check test results170if (!success) {171log.complain("TEST FAILED");172return FAILED;173}174175out.println("TEST PASSED");176return PASSED;177178}179180/**181* Get debuggee prepared for testing and obtain required data.182*/183void prepareForTest() {184// wait for tested class loaded185log.display("Waiting for tested class loaded");186testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL);187log.display(" ... got classID: " + testedClassID);188log.display("");189}190191/**192* Test JDWP command.193*/194void testCommand() {195// create command packet and fill requred out data196log.display("Create command packet: " + JDWP_COMMAND_NAME);197CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);198log.display(" no out data");199command.setLength();200log.display(" ... command packet created");201202// send command packet to debugee203try {204log.display("Sending command packet:\n" + command);205transport.write(command);206log.display(" ... command packet sent");207} catch (IOException e) {208log.complain("Unable to send command packet:\n\t" + e);209success = false;210return;211}212log.display("");213214// receive reply packet from debugee215ReplyPacket reply = new ReplyPacket();216try {217log.display("Waiting for reply packet");218transport.read(reply);219log.display(" ... reply packet received:\n" + reply);220} catch (IOException e) {221log.complain("Unable to read reply packet:\n\t" + e);222success = false;223return;224}225log.display("");226227// check reply packet header228try{229log.display("Checking header of reply packet");230reply.checkHeader(command.getPacketID());231log.display(" ... packet header is correct");232} catch (BoundException e) {233log.complain("Wrong header of reply packet for tested command:\n\t"234+ e.getMessage());235success = false;236return;237}238239// start parsing reply packet data240log.display("Parsing reply packet data:");241reply.resetPosition();242243// no out data244log.display(" no out data");245246log.display(" ... packet data is parsed");247248// check for extra data in reply packet249if (!reply.isParsed()) {250log.complain("Extra trailing bytes found in reply packet at: "251+ reply.offsetString());252success = false;253}254}255256/**257* Disconnect debuggee and wait for it exited.258*/259void quitDebugee() {260if (debugee == null)261return;262263// disconnect debugee if not dead264if (!dead) {265try {266log.display("Disconnecting debuggee");267debugee.dispose();268log.display(" ... debuggee disconnected");269} catch (Failure e) {270log.display("Failed to finally disconnect debuggee:\n\t"271+ e.getMessage());272}273}274275// wait for debugee exited276log.display("Waiting for debuggee exit");277int code = debugee.waitFor();278log.display(" ... debuggee exited with exit code: " + code);279280// analize debugee exit status code281if (code != JCK_STATUS_BASE + PASSED) {282log.complain("Debuggee FAILED with exit code: " + code);283success = false;284}285}286287}288289290