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 25 package nsk.jdi.TypeComponent.declaringType; 26 27 import nsk.share.*; 28 import nsk.share.jpda.*; 29 import nsk.share.jdi.*; 30 31 import com.sun.jdi.*; 32 import java.util.*; 33 import java.io.*; 34 35 public class decltype004 { 36 final static String METHOD_NAME_CLASS[] = { 37 "Mv", 38 "Mz", "Mz1", "Mz2", 39 "Mb", "Mb1", "Mb2", 40 "Mc", "Mc1", "Mc2", 41 "Md", "Md1", "Md2", 42 "Mf", "Mf1", "Mf2", 43 "Mi", "Mi1", "Mi2", 44 "Ml", "Ml1", "Ml2", 45 "Mr", "Mr1", "Mr2", 46 47 "MvF", "MlF", "MlF1", "MlF2", 48 "MvN", "MlN", "MlN1", "MlN2", 49 "MvS", "MlS", "MlS1", "MlS2", 50 "MvI", "MlI", "MlI1", "MlI2", 51 "MvY", "MlY", "MlY1", "MlY2", 52 "MvU", "MlU", "MlU1", "MlU2", 53 "MvR", "MlR", "MlR1", "MlR2", 54 "MvP", "MlP", "MlP1", "MlP2", 55 56 "MX", "MX1", "MX2", 57 "MO", "MO1", "MO2", 58 59 "MLF", "MLF1", "MLF2", 60 "MLN", "MLN1", "MLN2", 61 "MLS", "MLS1", "MLS2", 62 "MLI", "MLI1", "MLI2", 63 "MLY", "MLY1", "MLY2", 64 "MLU", "MLU1", "MLU2", 65 "MLR", "MLR1", "MLR2", 66 "MLP", "MLP1", "MLP2", 67 68 "ME", "ME1", "ME2", 69 "MEF", "MEF1", "MEF2", 70 "MEN", "MEN1", "MEN2", 71 "MES", "ME1S", "ME2S", 72 "MEI", "MEI1", "MEI2", 73 "MEY", "MEY1", "MEY2", 74 "MEU", "MEU1", "MEU2", 75 "MER", "MER1", "MER2", 76 "MEP", "MEP1", "MEP2" 77 }; 78 final static String METHOD_NAME_INTER[] = { 79 "Mv", 80 "Mz", "Mz1", "Mz2", 81 "Mb", "Mb1", "Mb2", 82 "Mc", "Mc1", "Mc2", 83 "Md", "Md1", "Md2", 84 "Mf", "Mf1", "Mf2", 85 "Mi", "Mi1", "Mi2", 86 "Ml", "Ml1", "Ml2", 87 "Mr", "Mr1", "Mr2", 88 89 "MvU", "MlU", "MlU1", "MlU2", 90 91 "MX", "MX1", "MX2", 92 "MO", "MO1", "MO2", 93 94 "MLU", "MLU1", "MLU2", 95 96 "ME", "ME1", "ME2", 97 "MEU", "MEU1", "MEU2", 98 }; 99 100 private static Log log; 101 private final static String prefix = "nsk.jdi.TypeComponent.declaringType."; 102 private final static String className = "decltype004"; 103 private final static String debugerName = prefix + className; 104 private final static String debugeeName = debugerName + "a"; 105 private final static String mainClassName = prefix + "decltype004aMainClass"; 106 private final static String mainInterName = prefix + "decltype004aMainInter"; 107 main(String argv[])108 public static void main(String argv[]) { 109 System.exit(95 + run(argv, System.out)); 110 } 111 run(String argv[], PrintStream out)112 public static int run(String argv[], PrintStream out) { 113 ArgumentHandler argHandler = new ArgumentHandler(argv); 114 log = new Log(out, argHandler); 115 Binder binder = new Binder(argHandler, log); 116 Debugee debugee = binder.bindToDebugee(debugeeName 117 + (argHandler.verbose() ? " -verbose" : "")); 118 IOPipe pipe = new IOPipe(debugee); 119 boolean testFailed = false; 120 ReferenceType mainClass; 121 ReferenceType mainInter; 122 123 // Connect with debugee and resume it 124 debugee.redirectStderr(out); 125 debugee.resume(); 126 String line = pipe.readln(); 127 if (line == null) { 128 log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null"); 129 return 2; 130 } 131 if (!line.equals("ready")) { 132 log.complain("debuger FAILURE> UNEXPECTED debugee's signal - " 133 + line); 134 return 2; 135 } 136 else { 137 log.display("debuger> debugee's \"ready\" signal recieved."); 138 } 139 140 // Get MainClass and decltype004aMainInter from debugee 141 mainClass = debugee.classByName(mainClassName); 142 if (mainClass == null) { 143 log.complain("debuger FAILURE> Class " + mainClassName + " not " 144 + "found."); 145 return 2; 146 } 147 mainInter = debugee.classByName(mainInterName); 148 if (mainInter == null) { 149 log.complain("debuger FAILURE> Interface " + mainInterName + " not " 150 + "found."); 151 return 2; 152 } 153 154 // Check all methods from MainClass 155 log.display("debuger> Total methods in " + mainClassName + ": " + 156 + mainClass.methods().size()); 157 for (int i = 0; i < METHOD_NAME_CLASS.length; i++) { 158 Method method; 159 List listOfMethods; 160 int totalMethodsByName; 161 String name; 162 ReferenceType declType; 163 boolean equal; 164 165 try { 166 listOfMethods = mainClass.methodsByName(METHOD_NAME_CLASS[i]); 167 } catch (Exception e) { 168 log.complain("debuger FAILURE 1> Can't get method by name " 169 + METHOD_NAME_CLASS[i]); 170 log.complain("debuger FAILURE 1> Exception: " + e); 171 testFailed = true; 172 continue; 173 } 174 totalMethodsByName = listOfMethods.size(); 175 if (totalMethodsByName != 1) { 176 log.complain("debuger FAILURE 2> Number of methods by name " 177 + METHOD_NAME_CLASS[i] + " is " + totalMethodsByName 178 + ", should be 1."); 179 testFailed = true; 180 continue; 181 } 182 method = (Method)listOfMethods.get(0); 183 name = method.name(); 184 declType = method.declaringType(); 185 if (declType == null) { 186 log.complain("debuger FAILURE 3> Declaring type is null " 187 + " for method " + name + " in class " 188 + mainClassName); 189 testFailed = true; 190 continue; 191 } 192 log.display("debuger> " + i + " method " + name + " from class " 193 + mainClassName + " read."); 194 try { 195 equal = declType.equals(mainClass); 196 } catch (ObjectCollectedException e) { 197 log.complain("debuger FAILURE 4> Cannot compare reference " 198 + " types " + declType.name() + " and " 199 + mainClassName); 200 log.complain("debuger FAILURE 4> Exception: " + e); 201 testFailed = true; 202 continue; 203 } 204 if (!equal) { 205 log.complain("debuger FAILURE 5> Declaring type of method " 206 + name + " is " + declType.name() + ", but should " 207 + "be " + mainClassName); 208 testFailed = true; 209 } 210 } 211 212 // Check all methods from MainInter 213 log.display("debuger> Total methods in " + mainInterName + ": " + 214 + mainInter.methods().size()); 215 for (int i = 0; i < METHOD_NAME_INTER.length; i++) { 216 Method method; 217 List listOfMethods; 218 int totalMethodsByName; 219 String name; 220 ReferenceType declType; 221 boolean equal; 222 223 try { 224 listOfMethods = mainInter.methodsByName(METHOD_NAME_INTER[i]); 225 } catch (Exception e) { 226 log.complain("debuger FAILURE 6> Can't get method by name " 227 + METHOD_NAME_INTER[i]); 228 log.complain("debuger FAILURE 6> Exception: " + e); 229 testFailed = true; 230 continue; 231 } 232 totalMethodsByName = listOfMethods.size(); 233 if (totalMethodsByName != 1) { 234 log.complain("debuger FAILURE 7> Number of methods by name " 235 + METHOD_NAME_INTER[i] + " is " + totalMethodsByName 236 + ", should be 1."); 237 testFailed = true; 238 continue; 239 } 240 method = (Method)listOfMethods.get(0); 241 name = method.name(); 242 declType = method.declaringType(); 243 if (declType == null) { 244 log.complain("debuger FAILURE 8> Declaring type is null " 245 + " for method " + name + " in class " 246 + mainInterName); 247 testFailed = true; 248 continue; 249 } 250 log.display("debuger> " + i + " method " + name + " from interface " 251 + mainInterName + " read."); 252 try { 253 equal = declType.equals(mainInter); 254 } catch (ObjectCollectedException e) { 255 log.complain("debuger FAILURE 9> Cannot compare reference " 256 + " types " + declType.name() + " and " 257 + mainInterName); 258 log.complain("debuger FAILURE 9> Exception: " + e); 259 testFailed = true; 260 continue; 261 } 262 if (!equal) { 263 log.complain("debuger FAILURE 10> Declaring type of method " 264 + name + " is " + declType.name() + ", but should " 265 + "be " + mainInterName); 266 testFailed = true; 267 } 268 } 269 270 pipe.println("quit"); 271 debugee.waitFor(); 272 int status = debugee.getStatus(); 273 if (testFailed) { 274 log.complain("debuger FAILURE> TEST FAILED"); 275 return 2; 276 } else { 277 if (status == 95) { 278 log.display("debuger> expected Debugee's exit " 279 + "status - " + status); 280 return 0; 281 } else { 282 log.complain("debuger FAILURE> UNEXPECTED Debugee's exit " 283 + "status (not 95) - " + status); 284 return 2; 285 } 286 } 287 } 288 } 289