Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete001.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.Method.IsObsolete;2425import java.io.*;2627import nsk.share.*;28import nsk.share.jpda.*;29import nsk.share.jdwp.*;3031/**32* Test for JDWP command: Method.IsObsolete.33*34* See isobsolete001.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 isobsolete001 {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.Method.IsObsolete";56static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "isobsolete001";57static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";5859// VM capability constatnts60static final int VM_CAPABILITY_NUMBER = JDWP.Capability.CAN_REDEFINE_CLASSES;61static final String VM_CAPABILITY_NAME = "canRedefineClasses";6263// tested JDWP command constants64static final String JDWP_COMMAND_NAME = "Method.IsObsolete";65static final int JDWP_COMMAND_ID = JDWP.Command.Method.IsObsolete;6667// tested class name and signature constants68static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";69static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";7071// tested method name constant72static final String TESTED_METHOD_NAME = "testedMethod";7374// usual scaffold objects75ArgumentHandler argumentHandler = null;76Log log = null;77Binder binder = null;78Debugee debugee = null;79Transport transport = null;80IOPipe pipe = null;8182// test passed or not83boolean success = true;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 JCK-compilant test.96*/97public static int run(String argv[], PrintStream out) {98return new isobsolete001().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);111112// execute test and display results113try {114log.display("\n>>> Preparing debugee for testing \n");115116// launch debuggee117binder = new Binder(argumentHandler, log);118log.display("Launching debugee");119debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);120transport = debugee.getTransport();121pipe = debugee.createIOPipe();122123// make debuggee ready for testing124prepareDebugee();125126// work with prepared debuggee127try {128log.display("\n>>> Checking VM capability \n");129130// check for VM capability131log.display("Checking VM capability: " + VM_CAPABILITY_NAME);132if (!debugee.getNewCapability(VM_CAPABILITY_NUMBER, VM_CAPABILITY_NAME)) {133out.println("TEST PASSED: unsupported VM capability: "134+ VM_CAPABILITY_NAME);135return PASSED;136}137138log.display("\n>>> Obtaining requred data from debugee \n");139140// query debuggee for classID of tested class141log.display("Getting classID by signature:\n"142+ " " + TESTED_CLASS_SIGNATURE);143long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);144log.display(" got classID: " + classID);145146// query debuggee for methodID of tested method (declared in the class)147log.display("Getting methodID by name: " + TESTED_METHOD_NAME);148long methodID = debugee.getMethodID(classID, TESTED_METHOD_NAME, true);149log.display(" got methodID: " + methodID);150151// perform testing JDWP command152log.display("\n>>> Testing JDWP command \n");153testCommand(classID, methodID);154155} finally {156// quit debugee157log.display("\n>>> Finishing test \n");158quitDebugee();159}160161} catch (Failure e) {162log.complain("TEST FAILED: " + e.getMessage());163success = false;164} catch (Exception e) {165e.printStackTrace(out);166log.complain("Caught unexpected exception while running the test:\n\t" + e);167success = false;168}169170if (!success) {171log.complain("TEST FAILED");172return FAILED;173}174175out.println("TEST PASSED");176return PASSED;177178}179180/**181* Prepare debugee for testing and waiting for ready signal.182*/183void prepareDebugee() {184// wait for VM_INIT event from debugee185log.display("Waiting for VM_INIT event");186debugee.waitForVMInit();187188// query debugee for VM-dependent ID sizes189log.display("Querying for IDSizes");190debugee.queryForIDSizes();191192// resume initially suspended debugee193log.display("Resuming debugee VM");194debugee.resume();195196// wait for READY signal from debugee197log.display("Waiting for signal from debugee: " + READY);198String signal = pipe.readln();199log.display("Received signal from debugee: " + signal);200if (! signal.equals(READY)) {201throw new TestBug("Unexpected signal received from debugee: " + signal202+ " (expected: " + READY + ")");203}204}205206/**207* Sending debugee signal to quit and waiting for it exits.208*/209void quitDebugee() {210// send debugee signal to quit211log.display("Sending signal to debugee: " + QUIT);212pipe.println(QUIT);213214// wait for debugee exits215log.display("Waiting for debugee exits");216int code = debugee.waitFor();217218// analize debugee exit status code219if (code == JCK_STATUS_BASE + PASSED) {220log.display("Debugee PASSED with exit code: " + code);221} else {222log.complain("Debugee FAILED with exit code: " + code);223success = false;224}225}226227/**228* Perform testing JDWP command for specified TypeID.229*/230void testCommand(long classID, long methodID) {231// create command packet and fill requred out data232log.display("Create command packet:");233log.display("Command: " + JDWP_COMMAND_NAME);234CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);235log.display(" referenceTypeID: " + classID);236command.addReferenceTypeID(classID);237log.display(" methodID: " + methodID);238command.addMethodID(methodID);239command.setLength();240241// send command packet to debugee242try {243log.display("Sending command packet:\n" + command);244transport.write(command);245} catch (IOException e) {246log.complain("Unable to send command packet:\n\t" + e);247success = false;248return;249}250251ReplyPacket reply = new ReplyPacket();252253// receive reply packet from debugee254try {255log.display("Waiting for reply packet");256transport.read(reply);257log.display("Reply packet received:\n" + reply);258} catch (IOException e) {259log.complain("Unable to read reply packet:\n\t" + e);260success = false;261return;262}263264// check reply packet header265try{266log.display("Checking reply packet header");267reply.checkHeader(command.getPacketID());268} catch (BoundException e) {269log.complain("Bad header of reply packet:\n\t" + e.getMessage());270success = false;271return;272}273274// start parsing reply packet data275log.display("Parsing reply packet:");276reply.resetPosition();277278// extract boolean result279byte isObsolete = 0;280try {281isObsolete = reply.getByte();282log.display(" isObsolete: " + isObsolete);283} catch (BoundException e) {284log.complain("Unable to extract isObsolete value from reply packet:\n\t"285+ e.getMessage());286success = false;287return;288}289290// check for extra data in reply packet291if (!reply.isParsed()) {292log.complain("Extra trailing bytes found in reply packet at: "293+ reply.offsetString());294success = false;295}296297// check that result value is false298if (isObsolete != 0) {299log.complain("Unexpected true isObsolete value received for not obsolete method: "300+ isObsolete);301success = false;302}303}304305}306307308