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.Value.type; 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 * Value. <BR> 37 * <BR> 38 * The test checks up that results of the method <BR> 39 * <code>com.sun.jdi.Value.type()</code> <BR> 40 * complies with its spec when a Value object represents <BR> 41 * an object of a primitive type. <BR> 42 * <BR> 43 * The cases for testing are as follows : <BR> 44 * <BR> 45 * when a gebuggee executes the following : <BR> 46 * static boolean bl = false; <BR> 47 * static byte bt = 0; <BR> 48 * static char ch = 0; <BR> 49 * static double db = 0.0d; <BR> 50 * static float fl = 0.0f; <BR> 51 * static int in = 0; <BR> 52 * static long ln = 0; <BR> 53 * static short sh = 0; <BR> 54 * <BR> 55 * for each of the above primitive type variables, <BR> 56 * a coresponding Type object is created in a debugger <BR> 57 * by the statement like the following : <BR> 58 * <BR> 59 * Type tbl = execClass.getValue(Field fsbl).type(); <BR> 60 * <BR> 61 * the following pair of statements don't throw <BR> 62 * ClassCastExceptions: <BR> 63 * <BR> 64 * PrimitiveType prtbl = (PrimitiveType) tbl; <BR> 65 * BooleanType bl = (BooleanType) prtbl; <BR> 66 * <BR> 67 * PrimitiveType prtbt = (PrimitiveType) tbt; <BR> 68 * ByteType bt = (ByteType) prtbt; <BR> 69 * . <BR> 70 * . <BR> 71 * PrimitiveType prtsh = (PrimitiveType) tsh; <BR> 72 * ShortType sh = (ShortType) prtsh; <BR> 73 * <BR> 74 */ 75 76 public class type001 { 77 78 //----------------------------------------------------- templete section 79 static final int PASSED = 0; 80 static final int FAILED = 2; 81 static final int PASS_BASE = 95; 82 83 //----------------------------------------------------- templete parameters 84 static final String 85 sHeader1 = "\n==> nsk/jdi/Value/type/type001", 86 sHeader2 = "--> type001: ", 87 sHeader3 = "##> type001: "; 88 89 //----------------------------------------------------- main method 90 main(String argv[])91 public static void main (String argv[]) { 92 int result = run(argv, System.out); 93 System.exit(result + PASS_BASE); 94 } 95 run(String argv[], PrintStream out)96 public static int run (String argv[], PrintStream out) { 97 return new type001().runThis(argv, out); 98 } 99 100 //-------------------------------------------------- log procedures 101 102 //private static boolean verbMode = false; 103 104 private static Log logHandler; 105 log1(String message)106 private static void log1(String message) { 107 logHandler.display(sHeader1 + message); 108 } log2(String message)109 private static void log2(String message) { 110 logHandler.display(sHeader2 + message); 111 } log3(String message)112 private static void log3(String message) { 113 logHandler.complain(sHeader3 + message); 114 } 115 116 // ************************************************ test parameters 117 118 private String debuggeeName = 119 "nsk.jdi.Value.type.type001a"; 120 121 //====================================================== test program 122 123 static ArgumentHandler argsHandler; 124 static int testExitCode = PASSED; 125 126 //------------------------------------------------------ common section 127 runThis(String argv[], PrintStream out)128 private int runThis (String argv[], PrintStream out) { 129 130 Debugee debuggee; 131 132 argsHandler = new ArgumentHandler(argv); 133 logHandler = new Log(out, argsHandler); 134 Binder binder = new Binder(argsHandler, logHandler); 135 136 if (argsHandler.verbose()) { 137 debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp 138 } else { 139 debuggee = binder.bindToDebugee(debuggeeName); // *** tp 140 } 141 142 IOPipe pipe = new IOPipe(debuggee); 143 144 debuggee.redirectStderr(out); 145 log2("type001a debuggee launched"); 146 debuggee.resume(); 147 148 String line = pipe.readln(); 149 if ((line == null) || !line.equals("ready")) { 150 log3("signal received is not 'ready' but: " + line); 151 return FAILED; 152 } else { 153 log2("'ready' recieved"); 154 } 155 156 VirtualMachine vm = debuggee.VM(); 157 158 //------------------------------------------------------ testing section 159 log1(" TESTING BEGINS"); 160 161 for (int i = 0; ; i++) { 162 pipe.println("newcheck"); 163 line = pipe.readln(); 164 165 if (line.equals("checkend")) { 166 log2(" : returned string is 'checkend'"); 167 break ; 168 } else if (!line.equals("checkready")) { 169 log3("ERROR: returned string is not 'checkready'"); 170 testExitCode = FAILED; 171 break ; 172 } 173 174 log1("new check: #" + i); 175 176 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part 177 178 List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName); 179 if (listOfDebuggeeExecClasses.size() != 1) { 180 testExitCode = FAILED; 181 log3("ERROR: listOfDebuggeeExecClasses.size() != 1"); 182 break ; 183 } 184 ReferenceType execClass = 185 (ReferenceType) listOfDebuggeeExecClasses.get(0); 186 187 Field fsbl = execClass.fieldByName("bl"); 188 Field fsbt = execClass.fieldByName("bt"); 189 Field fsch = execClass.fieldByName("ch"); 190 Field fsdb = execClass.fieldByName("db"); 191 Field fsfl = execClass.fieldByName("fl"); 192 Field fsin = execClass.fieldByName("in"); 193 Field fsln = execClass.fieldByName("ln"); 194 Field fssh = execClass.fieldByName("sh"); 195 196 int i2; 197 198 for (i2 = 0; ; i2++) { 199 200 int expresult = 0; 201 202 log2("new check: #" + i2); 203 204 switch (i2) { 205 206 case 0: // BooleanType 207 Type tbl = execClass.getValue(fsbl).type(); 208 PrimitiveType prtbl = null; 209 try { 210 prtbl = (PrimitiveType) tbl; 211 } catch ( ClassCastException e ) { 212 expresult = 1; 213 log3("ERROR: PrimitiveType prtbl = (PrimitiveType) tbl;"); 214 break ; 215 } 216 try { 217 BooleanType bl = (BooleanType) prtbl; 218 } catch ( ClassCastException e ) { 219 expresult = 1; 220 log3("ERROR: BooleanType blt = (BooleanType) prtbl;"); 221 } 222 break; 223 224 case 1: // ByteType 225 Type tbt = execClass.getValue(fsbt).type(); 226 PrimitiveType prtbt = null; 227 try { 228 prtbt = (PrimitiveType) tbt; 229 } catch ( ClassCastException e ) { 230 expresult = 1; 231 log3("ERROR: PrimitiveType ptbt = (PrimitiveType) tbt;"); 232 break ; 233 } 234 try { 235 ByteType bt = (ByteType) prtbt; 236 } catch ( ClassCastException e ) { 237 expresult = 1; 238 log3("ERROR: ByteType bt = (ByteType) ptbt;"); 239 } 240 break; 241 242 case 2: // CharType 243 Type tch = execClass.getValue(fsch).type(); 244 PrimitiveType prtch = null; 245 try { 246 prtch = (PrimitiveType) tch; 247 } catch ( ClassCastException e ) { 248 expresult = 1; 249 log3("ERROR: PrimitiveType prtch = (PrimitiveType) tch;"); 250 break ; 251 } 252 try { 253 CharType ch = (CharType) prtch; 254 } catch ( ClassCastException e ) { 255 expresult = 1; 256 log3("ERROR: CharType ch = (CharType) prtch;"); 257 } 258 break; 259 260 case 3: // DoubleType 261 Type tdb = execClass.getValue(fsdb).type(); 262 PrimitiveType prtdb = null; 263 try { 264 prtdb = (PrimitiveType) tdb; 265 } catch ( ClassCastException e ) { 266 expresult = 1; 267 log3("ERROR: PrimitiveType prtdb = (PrimitiveType) tdb;"); 268 break ; 269 } 270 try { 271 DoubleType db = (DoubleType) prtdb; 272 } catch ( ClassCastException e ) { 273 expresult = 1; 274 log3("ERROR: DoubleType db = (DoubleType) prtdb;"); 275 } 276 break; 277 278 case 4: // FloatType 279 Type tfl = execClass.getValue(fsfl).type(); 280 PrimitiveType prtfl = null; 281 try { 282 prtfl = (PrimitiveType) tfl; 283 } catch ( ClassCastException e ) { 284 expresult = 1; 285 log3("ERROR: PrimitiveType prtfl = (PrimitiveType) tfl;"); 286 break ; 287 } 288 try { 289 FloatType fl = (FloatType) prtfl; 290 } catch ( ClassCastException e ) { 291 expresult = 1; 292 log3("ERROR: FloatType fl = (FloatType) prtfl;"); 293 } 294 break; 295 296 case 5: // IntegerType 297 Type tin = execClass.getValue(fsin).type(); 298 PrimitiveType prtin = null; 299 try { 300 prtin = (PrimitiveType) tin; 301 } catch ( ClassCastException e ) { 302 expresult = 1; 303 log3("ERROR: PrimitiveType prtin = (PrimitiveType) tin;"); 304 break ; 305 } 306 try { 307 IntegerType in = (IntegerType) prtin; 308 } catch ( ClassCastException e ) { 309 expresult = 1; 310 log3("ERROR: IntegerType in = (IntegerType) prtin;"); 311 } 312 break; 313 314 case 6: // LongType 315 Type tln = execClass.getValue(fsln).type(); 316 PrimitiveType prtln = null; 317 try { 318 prtln = (PrimitiveType) tln; 319 } catch ( ClassCastException e ) { 320 expresult = 1; 321 log3("ERROR: PrimitiveType prtln = (PrimitiveType) tln;"); 322 break ; 323 } 324 try { 325 LongType ln = (LongType) prtln; 326 } catch ( ClassCastException e ) { 327 expresult = 1; 328 log3("ERROR: LongType ln = (LongType) prtln;"); 329 } 330 break; 331 332 case 7: // ShortType 333 Type tsh = execClass.getValue(fssh).type(); 334 PrimitiveType prtsh = null; 335 try { 336 prtsh = (PrimitiveType) tsh; 337 } catch ( ClassCastException e ) { 338 expresult = 1; 339 log3("ERROR: PrimitiveType prtsh = (PrimitiveType) tsh;"); 340 break ; 341 } 342 try { 343 ShortType sh = (ShortType) prtsh; 344 } catch ( ClassCastException e ) { 345 expresult = 1; 346 log3("ERROR: ShortType sh = (ShortType) prtsh;"); 347 } 348 break; 349 350 351 default: expresult = 2; 352 break ; 353 } 354 355 if (expresult == 2) { 356 log2(" test cases finished"); 357 break ; 358 } else if (expresult == 1) { 359 log3("ERROR: expresult != true; check # = " + i); 360 testExitCode = FAILED; 361 } 362 } 363 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 364 } 365 log1(" TESTING ENDS"); 366 367 //-------------------------------------------------- test summary section 368 //------------------------------------------------- standard end section 369 370 pipe.println("quit"); 371 log2("waiting for the debuggee to finish ..."); 372 debuggee.waitFor(); 373 374 int status = debuggee.getStatus(); 375 if (status != PASSED + PASS_BASE) { 376 log3("debuggee returned UNEXPECTED exit status: " + 377 status + " != PASS_BASE"); 378 testExitCode = FAILED; 379 } else { 380 log2("debuggee returned expected exit status: " + 381 status + " == PASS_BASE"); 382 } 383 384 if (testExitCode != PASSED) { 385 logHandler.complain("TEST FAILED"); 386 } 387 return testExitCode; 388 } 389 } 390