Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp003.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 clrallbreakp003.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 clrallbreakp003 {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 + "." + "clrallbreakp003";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// name of field and method of tested class66static final String TESTED_METHOD_NAME = "run";67static final int BREAKPOINT_LINE = clrallbreakp003a.BREAKPOINT_LINE;6869// usual scaffold objects70ArgumentHandler argumentHandler = null;71Log log = null;72Binder binder = null;73Debugee debugee = null;74Transport transport = null;75int waitTime = 0; // minutes76long timeout = 0; // milliseconds77boolean dead = false;78boolean success = true;7980// obtained data81long testedClassID = 0;82long testedMethodID = 0;83int eventRequestID = 0;8485// -------------------------------------------------------------------8687/**88* Start test from command line.89*/90public static void main(String argv[]) {91System.exit(run(argv,System.out) + JCK_STATUS_BASE);92}9394/**95* Start test from JCK-compilant environment.96*/97public static int run(String argv[], PrintStream out) {98return new clrallbreakp003().runIt(argv, out);99}100101// -------------------------------------------------------------------102103/**104* Perform test execution.105*/106public int runIt(String argv[], PrintStream out) {107108// make log for debugger messages109argumentHandler = new ArgumentHandler(argv);110log = new Log(out, argumentHandler);111waitTime = argumentHandler.getWaitTime();112timeout = waitTime * 60 * 1000;113114// execute test and display results115try {116log.display("\n>>> Starting debugee \n");117118// launch debuggee119binder = new Binder(argumentHandler, log);120log.display("Launching debugee");121debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);122transport = debugee.getTransport();123log.display(" ... debugee launched");124log.display("");125126// set timeout for debuggee responces127log.display("Setting timeout for debuggee responces: " + waitTime + " minute(s)");128transport.setReadTimeout(timeout);129log.display(" ... timeout set");130131// wait for debuggee started132log.display("Waiting for VM_INIT event");133debugee.waitForVMInit();134log.display(" ... VM_INIT event received");135136// query debugee for VM-dependent ID sizes137log.display("Querying for IDSizes");138debugee.queryForIDSizes();139log.display(" ... size of VM-dependent types adjusted");140141// get debuggee prepared for testing142log.display("\n>>> Get debuggee prepared for testing \n");143prepareForTest();144145// test JDWP command146log.display("\n>>> Testing JDWP command \n");147testCommand();148149log.display("\n>>> Finishing debuggee \n");150151// resume debuggee152log.display("Resuming debuggee");153debugee.resume();154log.display(" ... debuggee resumed");155156// wait for debuggee exited157log.display("Waiting for fianl VM_DEATH event");158debugee.waitForVMDeath();159dead = true;160log.display(" ... VM_DEATH event received");161162} catch (Failure e) {163log.complain("TEST FAILED: " + e.getMessage());164success = false;165} catch (Exception e) {166e.printStackTrace(out);167log.complain("Caught unexpected exception while running the test:\n\t" + e);168success = false;169} finally {170// quit debugee171log.display("\n>>> Finishing test \n");172quitDebugee();173}174175// check test results176if (!success) {177log.complain("TEST FAILED");178return FAILED;179}180181out.println("TEST PASSED");182return PASSED;183184}185186void prepareForTest() {187// wait for tested class loaded188log.display("Waiting for tested class loaded");189testedClassID = debugee.waitForClassLoaded(TESTED_CLASS_NAME, JDWP.SuspendPolicy.ALL);190log.display(" ... got classID: " + testedClassID);191log.display("");192193// get methodID for tested method194log.display("Getting tested methodID by name: " + TESTED_METHOD_NAME);195testedMethodID = debugee.getMethodID(testedClassID, TESTED_METHOD_NAME, true);196log.display(" ... got methodID: " + testedMethodID);197198// make request for BREAKPOINT event199log.display("Making request for BREAKPOINT event at: "200+ TESTED_METHOD_NAME + ":" + BREAKPOINT_LINE);201eventRequestID = debugee.requestBreakpointEvent(JDWP.TypeTag.CLASS, testedClassID,202testedMethodID, BREAKPOINT_LINE,203JDWP.SuspendPolicy.ALL);204log.display(" ... got requestID: " + eventRequestID);205206// clear request for BREAKPOINT event207log.display("Clearing BREAKPOINT event requestID: " + eventRequestID);208debugee.clearEventRequest(JDWP.EventKind.BREAKPOINT, eventRequestID);209log.display(" ... request removed");210}211212213/**214* Test JDWP command.215*/216void testCommand() {217// create command packet and fill requred out data218log.display("Create command packet: " + JDWP_COMMAND_NAME);219CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);220log.display(" no out data");221command.setLength();222log.display(" ... command packet created");223224// send command packet to debugee225try {226log.display("Sending command packet:\n" + command);227transport.write(command);228log.display(" ... command packet sent");229} catch (IOException e) {230log.complain("Unable to send command packet:\n\t" + e);231success = false;232return;233}234log.display("");235236// receive reply packet from debugee237ReplyPacket reply = new ReplyPacket();238try {239log.display("Waiting for reply packet");240transport.read(reply);241log.display(" ... reply packet received:\n" + reply);242} catch (IOException e) {243log.complain("Unable to read reply packet:\n\t" + e);244success = false;245return;246}247log.display("");248249// check reply packet header250try{251log.display("Checking header of reply packet");252reply.checkHeader(command.getPacketID());253log.display(" ... packet header is correct");254} catch (BoundException e) {255log.complain("Wrong header of reply packet for tested command:\n\t"256+ e.getMessage());257success = false;258return;259}260261// start parsing reply packet data262log.display("Parsing reply packet data:");263reply.resetPosition();264265// no out data266log.display(" no out data");267268log.display(" ... packet data is parsed");269270// check for extra data in reply packet271if (!reply.isParsed()) {272log.complain("Extra trailing bytes found in reply packet at: "273+ reply.offsetString());274success = false;275}276}277278/**279* Disconnect debuggee and wait for it exited.280*/281void quitDebugee() {282if (debugee == null)283return;284285// disconnect debugee if not dead286if (!dead) {287try {288log.display("Disconnecting debuggee");289debugee.dispose();290log.display(" ... debuggee disconnected");291} catch (Failure e) {292log.display("Failed to finally disconnect debuggee:\n\t"293+ e.getMessage());294}295}296297// wait for debugee exited298log.display("Waiting for debuggee exit");299int code = debugee.waitFor();300log.display(" ... debuggee exited with exit code: " + code);301302// analize debugee exit status code303if (code != JCK_STATUS_BASE + PASSED) {304log.complain("Debuggee FAILED with exit code: " + code);305success = false;306}307}308309}310311312