Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/LineTable/linetable001.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.LineTable;2425import java.io.*;2627import nsk.share.*;28import nsk.share.jpda.*;29import nsk.share.jdwp.*;3031/**32* Test for JDWP command: Method.LineTable.33*34* See linetable001.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 linetable001 {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.LineTable";56static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "linetable001";57static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";5859// tested JDWP command constants60static final String JDWP_COMMAND_NAME = "Method.LineTable";61static final int JDWP_COMMAND_ID = JDWP.Command.Method.LineTable;6263// tested class name and signature constants64static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";65static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";6667// tested method name constant68static final String TESTED_METHOD_NAME = "testedMethod";6970// expected values for bound line numbers71static final int FIRST_LINE_NUMBER = linetable001a.FIRST_LINE_NUMBER;72static final int LAST_LINE_NUMBER = linetable001a.LAST_LINE_NUMBER;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 linetable001().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>>> Obtaining requred data from debugee \n");129130// query debuggee for classID of tested class131log.display("Getting classID by signature:\n"132+ " " + TESTED_CLASS_SIGNATURE);133long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);134log.display(" got classID: " + classID);135136// query debuggee for methodID of tested method (declared in the class)137log.display("Getting methodID by name: " + TESTED_METHOD_NAME);138long methodID = debugee.getMethodID(classID, TESTED_METHOD_NAME, true);139log.display(" got methodID: " + methodID);140141// perform testing JDWP command142log.display("\n>>> Testing JDWP command \n");143testCommand(classID, methodID);144145} finally {146// quit debugee147log.display("\n>>> Finishing test \n");148quitDebugee();149}150151} catch (Failure e) {152log.complain("TEST FAILED: " + e.getMessage());153success = false;154} catch (Exception e) {155e.printStackTrace(out);156log.complain("Caught unexpected exception while running the test:\n\t" + e);157success = false;158}159160if (!success) {161log.complain("TEST FAILED");162return FAILED;163}164165out.println("TEST PASSED");166return PASSED;167168}169170/**171* Prepare debugee for testing and waiting for ready signal.172*/173void prepareDebugee() {174// wait for VM_INIT event from debugee175log.display("Waiting for VM_INIT event");176debugee.waitForVMInit();177178// query debugee for VM-dependent ID sizes179log.display("Querying for IDSizes");180debugee.queryForIDSizes();181182// resume initially suspended debugee183log.display("Resuming debugee VM");184debugee.resume();185186// wait for READY signal from debugee187log.display("Waiting for signal from debugee: " + READY);188String signal = pipe.readln();189log.display("Received signal from debugee: " + signal);190if (! signal.equals(READY)) {191throw new TestBug("Unexpected signal received from debugee: " + signal192+ " (expected: " + READY + ")");193}194}195196/**197* Sending debugee signal to quit and waiting for it exits.198*/199void quitDebugee() {200// send debugee signal to quit201log.display("Sending signal to debugee: " + QUIT);202pipe.println(QUIT);203204// wait for debugee exits205log.display("Waiting for debugee exits");206int code = debugee.waitFor();207208// analize debugee exit status code209if (code == JCK_STATUS_BASE + PASSED) {210log.display("Debugee PASSED with exit code: " + code);211} else {212log.complain("Debugee FAILED with exit code: " + code);213success = false;214}215}216217/**218* Perform testing JDWP command for specified TypeID.219*/220void testCommand(long classID, long methodID) {221// create command packet and fill requred out data222log.display("Create command packet:");223log.display("Command: " + JDWP_COMMAND_NAME);224CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);225log.display(" referenceTypeID: " + classID);226command.addReferenceTypeID(classID);227log.display(" methodID: " + methodID);228command.addMethodID(methodID);229command.setLength();230231// send command packet to debugee232try {233log.display("Sending command packet:\n" + command);234transport.write(command);235} catch (IOException e) {236log.complain("Unable to send command packet:\n\t" + e);237success = false;238return;239}240241ReplyPacket reply = new ReplyPacket();242243// receive reply packet from debugee244try {245log.display("Waiting for reply packet");246transport.read(reply);247log.display("Reply packet received:\n" + reply);248} catch (IOException e) {249log.complain("Unable to read reply packet:\n\t" + e);250success = false;251return;252}253254// check reply packet header255try{256log.display("Checking reply packet header");257reply.checkHeader(command.getPacketID());258} catch (BoundException e) {259log.complain("Bad header of reply packet:\n\t" + e.getMessage());260success = false;261}262263// start parsing reply packet data264log.display("Parsing reply packet:");265reply.resetPosition();266267// extract and check reply data268269// extract start code index270long start = 0;271try {272start = reply.getLong();273log.display(" start: " + start);274} catch (BoundException e) {275log.complain("Unable to extract start line index from reply packet:\n\t"276+ e.getMessage());277success = false;278return;279}280281// check that start code index is not negative282if (start < 0) {283log.complain("Negative value of start code index in reply packet: " + start);284success = false;285}286287// extract end code index288long end = 0;289try {290end = reply.getLong();291log.display(" end: " + end);292} catch (BoundException e) {293log.complain("Unable to extract end line index from reply packet:\n\t"294+ e.getMessage());295success = false;296return;297}298299// check that end code index is not negative300if (start < 0) {301log.complain("Negative value of end code index in reply packet: " + end);302success = false;303}304305// check that start code is strongly less than end code index306if (start > end) {307log.complain("Start code index (" + start308+ ") is greater than end code index (" + end + ")");309success = false;310} else if (start == end) {311log.complain("Start code index (" + start312+ ") is equal to end code index (" + end + ")");313success = false;314}315316// extract number of lines317int lines = 0;318try {319lines = reply.getInt();320log.display(" lines: " + lines);321} catch (BoundException e) {322log.complain("Unable to extract number of lines from reply packet:\n\t"323+ e.getMessage());324success = false;325return;326}327328if (lines < 0) {329log.complain("Negative number of lines in reply packet: " + lines);330success = false;331return;332}333334if (lines == 0) {335log.complain("Zero number of lines in reply packet: " + lines);336success = false;337return;338}339340// extract and check each line attributes341long lineCodeIndex = 0, prevLineCodeIndex = 0;342int lineNumber = 0, prevLineNumber = 0;343344for (int i = 0; i < lines; i++) {345log.display(" line #" + i + ":");346347// extract code index of a line348try {349lineCodeIndex = reply.getLong();350log.display(" lineCodeIndex: " + lineCodeIndex);351} catch (BoundException e) {352log.complain("Unable to extract code index of line #" + i353+ " from reply packet:\n\t"354+ e.getMessage());355success = false;356return;357}358359// check that code index is between start and end values360if (lineCodeIndex < start) {361log.complain("Code index of line #" + i + " (" + lineCodeIndex362+ ") is less than start code index (" + start + ")");363success = false;364}365366if (lineCodeIndex > end) {367log.complain("Code index of line #" + i + " (" + lineCodeIndex368+ ") is greater than end code index (" + end + ")");369success = false;370}371372// check that code index ot the first line is equal to start value373if (i == 0) {374if (lineCodeIndex != start) {375log.complain("Code index of first line (" + lineCodeIndex376+ ") is not equal to start code index (" + start + ")");377success = false;378}379}380381// check that code index of a line is strongly greater than for previous line382if (i > 0) {383if (lineCodeIndex < prevLineCodeIndex) {384log.complain("Code index of line #" + i + " (" + lineCodeIndex385+ ") is less than code index of previous line ("386+ prevLineCodeIndex + ")");387success = false;388} else if (lineCodeIndex == prevLineCodeIndex) {389log.complain("Code index of line #" + i + " (" + lineCodeIndex390+ ") is equal to code index of previous line ("391+ prevLineCodeIndex + ")");392success = false;393}394}395396// extract number of a line397try {398lineNumber = reply.getInt();399log.display(" lineNumber: " + lineNumber);400} catch (BoundException e) {401log.complain("Unable to extract number of line #" + i402+ " from reply packet:\n\t"403+ e.getMessage());404success = false;405return;406}407408// check that code index ot the line is not negative409if (lineNumber < 0) {410log.complain("Number of line #" + i + " (" + lineNumber411+ ") is negative");412success = false;413}414415// check that code index ot the line is not less than expected416if (lineNumber < FIRST_LINE_NUMBER) {417log.complain("Number of line #" + i + " (" + lineNumber418+ ") is less than expected (" + FIRST_LINE_NUMBER + ")");419success = false;420}421422// check that code index ot the line is not greater than expected423if (lineNumber > LAST_LINE_NUMBER) {424log.complain("Number of line #" + i + " (" + lineNumber425+ ") is greater than expected (" + LAST_LINE_NUMBER + ")");426success = false;427}428429// check that line number follows directly to the number of previous line430if (i > 0) {431if (lineNumber < prevLineNumber) {432log.complain("Number of line #" + i + " (" + lineCodeIndex433+ ") is less than number of previous line ("434+ prevLineNumber + ")");435success = false;436} else if (lineNumber == prevLineNumber) {437log.complain("Number of line #" + i + " (" + lineCodeIndex438+ ") is equal to number of previous line ("439+ prevLineNumber + ")");440success = false;441} else if (lineNumber != prevLineNumber + 1) {442log.complain("Number of line #" + i + " (" + lineCodeIndex443+ ") does not follows to number of previous line ("444+ prevLineNumber + ")");445success = false;446}447}448449// save values to use them as previous line attributes450prevLineCodeIndex = lineCodeIndex;451prevLineNumber = lineNumber;452}453454// check for extra data in reply packet455if (!reply.isParsed()) {456log.complain("Extra trailing bytes found in reply packet at: "457+ reply.offsetString());458success = false;459}460}461462}463464465