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.Locatable.location; 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 * Locatable. <BR> 37 * <BR> 38 * The test checks up that results of the method <BR> 39 * <code>com.sun.jdi.Locatable.location()</code> <BR> 40 * complies with its spec when a tested method is an abstract. <BR> 41 * <BR> 42 * The cases for testing are as follows. <BR> 43 * <BR> 44 * When a gebuggee creates an object of TestClass <BR> 45 * which contains an instance of class ClassForCheck <BR> 46 * implementing, directly and indirectly, two abstract <BR> 47 * methods from its super-class and super-interface, <BR> 48 * a debugger invokes the method Locatable.location() <BR> 49 * with these two abstract methods as arguments and <BR> 50 * checks up returned values. <BR> 51 * <BR> 52 */ 53 54 public class location002 { 55 56 //----------------------------------------------------- templete section 57 static final int PASSED = 0; 58 static final int FAILED = 2; 59 static final int PASS_BASE = 95; 60 61 //----------------------------------------------------- templete parameters 62 static final String 63 sHeader1 = "\n==> nsk/jdi/Locatable/location/location002 ", 64 sHeader2 = "--> location002: ", 65 sHeader3 = "##> location002: "; 66 67 //----------------------------------------------------- main method 68 main(String argv[])69 public static void main (String argv[]) { 70 int result = run(argv, System.out); 71 System.exit(result + PASS_BASE); 72 } 73 run(String argv[], PrintStream out)74 public static int run (String argv[], PrintStream out) { 75 return new location002().runThis(argv, out); 76 } 77 78 //-------------------------------------------------- log procedures 79 80 //private static boolean verbMode = false; 81 82 private static Log logHandler; 83 log1(String message)84 private static void log1(String message) { 85 logHandler.display(sHeader1 + message); 86 } log2(String message)87 private static void log2(String message) { 88 logHandler.display(sHeader2 + message); 89 } log3(String message)90 private static void log3(String message) { 91 logHandler.complain(sHeader3 + message); 92 } 93 94 // ************************************************ test parameters 95 96 private String debuggeeName = 97 "nsk.jdi.Locatable.location.location002a"; 98 99 String mName = "nsk.jdi.Locatable.location"; 100 101 //====================================================== test program 102 103 static ArgumentHandler argsHandler; 104 static int testExitCode = PASSED; 105 106 //------------------------------------------------------ common section 107 runThis(String argv[], PrintStream out)108 private int runThis (String argv[], PrintStream out) { 109 110 Debugee debuggee; 111 112 113 argsHandler = new ArgumentHandler(argv); 114 logHandler = new Log(out, argsHandler); 115 Binder binder = new Binder(argsHandler, logHandler); 116 117 118 if (argsHandler.verbose()) { 119 debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp 120 } else { 121 debuggee = binder.bindToDebugee(debuggeeName); // *** tp 122 } 123 124 IOPipe pipe = new IOPipe(debuggee); 125 126 debuggee.redirectStderr(out); 127 log2("location002a debuggee launched"); 128 debuggee.resume(); 129 130 String line = pipe.readln(); 131 if ((line == null) || !line.equals("ready")) { 132 log3("signal received is not 'ready' but: " + line); 133 return FAILED; 134 } else { 135 log2("'ready' recieved"); 136 } 137 138 VirtualMachine vm = debuggee.VM(); 139 140 //------------------------------------------------------ testing section 141 log1(" TESTING BEGINS"); 142 143 for (int i = 0; ; i++) { 144 pipe.println("newcheck"); 145 line = pipe.readln(); 146 147 if (line.equals("checkend")) { 148 log2(" : returned string is 'checkend'"); 149 break ; 150 } else if (!line.equals("checkready")) { 151 log3("ERROR: returned string is not 'checkready'"); 152 testExitCode = FAILED; 153 break ; 154 } 155 156 log1("new check: #" + i); 157 158 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part 159 160 List listOfDebuggeeClasses = null; 161 List methods = null; 162 Method m = null; 163 Location mLocation = null; 164 165 String testedMethod1 = "abstractMethod1"; 166 String testedMethod2 = "abstractMethod2"; 167 168 listOfDebuggeeClasses = vm.classesByName(mName + ".location002aInterfaceForCheck"); 169 if (listOfDebuggeeClasses.size() != 1) { 170 testExitCode = FAILED; 171 log3("ERROR: listOfDebuggeeClasses.size() != 1"); 172 break ; 173 } 174 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 175 methodsByName(testedMethod1); 176 m = (Method) methods.get(0); 177 mLocation = m.location(); 178 179 if (mLocation != null) { 180 log3("ERROR: mLocation != null for an abstract method in location002aInterfaceForCheck"); 181 testExitCode = FAILED; 182 } 183 184 listOfDebuggeeClasses = vm.classesByName(mName + ".location002aClassForCheck2"); 185 if (listOfDebuggeeClasses.size() != 1) { 186 testExitCode = FAILED; 187 log3("ERROR: listOfDebuggeeClasses.size() != 1"); 188 break ; 189 } 190 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 191 methodsByName(testedMethod2); 192 m = (Method) methods.get(0); 193 mLocation = m.location(); 194 195 if (mLocation != null) { 196 log3("ERROR: mLocation != null for an abstract method in location002aClassForCheck2"); 197 testExitCode = FAILED; 198 } 199 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 200 } 201 log1(" TESTING ENDS"); 202 203 //-------------------------------------------------- test summary section 204 //------------------------------------------------- standard end section 205 206 pipe.println("quit"); 207 log2("waiting for the debuggee to finish ..."); 208 debuggee.waitFor(); 209 210 int status = debuggee.getStatus(); 211 if (status != PASSED + PASS_BASE) { 212 log3("debuggee returned UNEXPECTED exit status: " + 213 status + " != PASS_BASE"); 214 testExitCode = FAILED; 215 } else { 216 log2("debuggee returned expected exit status: " + 217 status + " == PASS_BASE"); 218 } 219 220 if (testExitCode != PASSED) { 221 System.out.println("TEST FAILED"); 222 } 223 return testExitCode; 224 } 225 } 226