test/hotspot/jtreg/vmTestbase/nsk/jdi/Method/allLineLocations/alllinelocations002.java
changeset 50018 3ba0d8631f24
child 53869 34906de6c017
equal deleted inserted replaced
50017:88cc95780b6e 50018:3ba0d8631f24
       
     1 /*
       
     2  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package nsk.jdi.Method.allLineLocations;
       
    25 
       
    26 import nsk.share.*;
       
    27 import nsk.share.jpda.*;
       
    28 import nsk.share.jdi.*;
       
    29 
       
    30 import com.sun.jdi.*;
       
    31 import java.util.*;
       
    32 import java.io.*;
       
    33 
       
    34 /**
       
    35  * The test for the implementation of an object of the type     <BR>
       
    36  * Method.                                                      <BR>
       
    37  *                                                              <BR>
       
    38  * The test checks up that results of the method                <BR>
       
    39  * <code>com.sun.jdi.Method.allLineLocations()</code>           <BR>
       
    40  * complies with its spec for non-abstract, non-native method.  <BR>
       
    41  * The test checks up that a list of locations for the method   <BR>
       
    42  *    - is not empty and                                        <BR>
       
    43  *    - is ordered in a proper, from low to high, sequence.     <BR>
       
    44  */
       
    45 
       
    46 public class alllinelocations002 {
       
    47 
       
    48     //----------------------------------------------------- templete section
       
    49     static final int PASSED = 0;
       
    50     static final int FAILED = 2;
       
    51     static final int PASS_BASE = 95;
       
    52 
       
    53     //----------------------------------------------------- templete parameters
       
    54     static final String
       
    55     sHeader1 = "\n==> nsk/jdi/Method/allLineLocations/alllinelocations002  ",
       
    56     sHeader2 = "--> debugger: ",
       
    57     sHeader3 = "##> debugger: ";
       
    58 
       
    59     //----------------------------------------------------- main method
       
    60 
       
    61     public static void main (String argv[]) {
       
    62         int result = run(argv, System.out);
       
    63         System.exit(result + PASS_BASE);
       
    64     }
       
    65 
       
    66     public static int run (String argv[], PrintStream out) {
       
    67         return new alllinelocations002().runThis(argv, out);
       
    68     }
       
    69 
       
    70     //--------------------------------------------------   log procedures
       
    71 
       
    72     private static Log  logHandler;
       
    73 
       
    74     private static void log1(String message) {
       
    75         logHandler.display(sHeader1 + message);
       
    76     }
       
    77     private static void log2(String message) {
       
    78         logHandler.display(sHeader2 + message);
       
    79     }
       
    80     private static void log3(String message) {
       
    81         logHandler.display(sHeader3 + message);
       
    82     }
       
    83 
       
    84     //  ************************************************    test parameters
       
    85 
       
    86     private String debuggeeName =
       
    87         "nsk.jdi.Method.allLineLocations.alllinelocations002a";
       
    88 
       
    89     String mName = "nsk.jdi.Method.allLineLocations";
       
    90 
       
    91     //====================================================== test program
       
    92     //------------------------------------------------------ common section
       
    93 
       
    94     static ArgumentHandler      argsHandler;
       
    95 
       
    96     static int waitTime;
       
    97 
       
    98     static VirtualMachine vm = null;
       
    99 
       
   100     static int  testExitCode = PASSED;
       
   101 
       
   102     static final int returnCode0 = 0;
       
   103     static final int returnCode1 = 1;
       
   104     static final int returnCode2 = 2;
       
   105     static final int returnCode3 = 3;
       
   106     static final int returnCode4 = 4;
       
   107 
       
   108     //------------------------------------------------------ methods
       
   109 
       
   110     private int runThis (String argv[], PrintStream out) {
       
   111 
       
   112         Debugee debuggee;
       
   113 
       
   114         argsHandler     = new ArgumentHandler(argv);
       
   115         logHandler      = new Log(out, argsHandler);
       
   116         Binder binder   = new Binder(argsHandler, logHandler);
       
   117 
       
   118         if (argsHandler.verbose()) {
       
   119             debuggee = binder.bindToDebugee(debuggeeName + " -vbs");
       
   120         } else {
       
   121             debuggee = binder.bindToDebugee(debuggeeName);
       
   122         }
       
   123 
       
   124         waitTime = argsHandler.getWaitTime();
       
   125 
       
   126 
       
   127         IOPipe pipe     = new IOPipe(debuggee);
       
   128 
       
   129         debuggee.redirectStderr(out);
       
   130         log2("issuspended002a debuggee launched");
       
   131         debuggee.resume();
       
   132 
       
   133         String line = pipe.readln();
       
   134         if ((line == null) || !line.equals("ready")) {
       
   135             log3("signal received is not 'ready' but: " + line);
       
   136             return FAILED;
       
   137         } else {
       
   138             log2("'ready' recieved");
       
   139         }
       
   140 
       
   141         vm = debuggee.VM();
       
   142 
       
   143     //------------------------------------------------------  testing section
       
   144         log1("      TESTING BEGINS");
       
   145 
       
   146         for (int i = 0; ; i++) {
       
   147 
       
   148             pipe.println("newcheck");
       
   149             line = pipe.readln();
       
   150 
       
   151             if (line.equals("checkend")) {
       
   152                 log2("     : returned string is 'checkend'");
       
   153                 break ;
       
   154             } else if (!line.equals("checkready")) {
       
   155                 log3("ERROR: returned string is not 'checkready'");
       
   156                 testExitCode = FAILED;
       
   157                 break ;
       
   158             }
       
   159 
       
   160             log1("new checkready: #" + i);
       
   161 
       
   162             //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
       
   163 
       
   164             List   methods   = null;
       
   165             Method m         = null;
       
   166             List   locations = null;
       
   167 
       
   168 
       
   169             log2("      getting: List classes = vm.classesByName(mName + '.TestClass');");
       
   170             List classes = vm.classesByName(mName + ".TestClass");
       
   171 
       
   172             if (classes.size() != 1) {
       
   173                 testExitCode = FAILED;
       
   174                 log3("ERROR: classes.size() != 1");
       
   175                 break ;
       
   176             }
       
   177 
       
   178             log2("      getting a tested method object 'm'");
       
   179             methods = ((ReferenceType) classes.get(0)).methodsByName("primitiveargsmethod");
       
   180             m = (Method) methods.get(0);
       
   181 
       
   182             log2("......locations = m.allLineLocations(); no AbsentInformationException is expected");
       
   183             try {
       
   184                 locations = m.allLineLocations();
       
   185             } catch ( AbsentInformationException e ) {
       
   186                 testExitCode = FAILED;
       
   187                 log3("ERROR: AbsentInformationException");
       
   188                 log3("       ATTENTION:     see the README file to this test");
       
   189                 break ;
       
   190             }
       
   191 
       
   192             log2("......checking up on a value of locations.size(); 0 is not expected");
       
   193             if (locations.size() == 0) {
       
   194                 testExitCode = FAILED;
       
   195                 log3("ERROR: locations.size() == 0");
       
   196                 break ;
       
   197             }
       
   198 
       
   199             log2("......checking up element order in the List");
       
   200 
       
   201             ListIterator listIterator = locations.listIterator();
       
   202 
       
   203             Location location1 = null;
       
   204             Location location2 = null;
       
   205 
       
   206             int i2;
       
   207 
       
   208             for (i2 = 0; listIterator.hasNext(); i2++) {
       
   209 
       
   210                 long codeIndex1 = 0l;
       
   211                 long codeIndex2 = 0l;
       
   212 
       
   213                 try {
       
   214                     location2 = (Location) listIterator.next();
       
   215                 } catch ( ClassCastException e) {
       
   216                     testExitCode = FAILED;
       
   217                     log3("ERROR: ClassCastException");
       
   218                     break ;
       
   219                 }
       
   220                 codeIndex2 = location2.codeIndex();
       
   221                 if (i2 == 0) {
       
   222                     continue;
       
   223                 }
       
   224 
       
   225                 if (codeIndex2 < codeIndex1) {
       
   226                     testExitCode = FAILED;
       
   227                     log3("ERROR: codeIndex disorder: codeIndex2 < codeIndex1");
       
   228                     break ;
       
   229                 }
       
   230 
       
   231                 codeIndex1 = codeIndex2;
       
   232             }
       
   233 
       
   234             log2("......compareing locations.size() to a processed number of elements in the list");
       
   235             if (locations.size() != i2) {
       
   236                 testExitCode = FAILED;
       
   237                 log3("ERROR: locations.size() != the processed number");
       
   238                 break ;
       
   239             }
       
   240 
       
   241             //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   242         }
       
   243         log1("      TESTING ENDS");
       
   244 
       
   245     //--------------------------------------------------   test summary section
       
   246     //-------------------------------------------------    standard end section
       
   247 
       
   248         pipe.println("quit");
       
   249         log2("waiting for the debuggee to finish ...");
       
   250         debuggee.waitFor();
       
   251 
       
   252         int status = debuggee.getStatus();
       
   253         if (status != PASSED + PASS_BASE) {
       
   254             log3("debuggee returned UNEXPECTED exit status: " +
       
   255                     status + " != PASS_BASE");
       
   256             testExitCode = FAILED;
       
   257         } else {
       
   258             log2("debuggee returned expected exit status: " +
       
   259                     status + " == PASS_BASE");
       
   260         }
       
   261 
       
   262         if (testExitCode != PASSED) {
       
   263             logHandler.complain("TEST FAILED");
       
   264         }
       
   265         return testExitCode;
       
   266     }
       
   267 }