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.variables; 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.variables()</code> <BR> 40 * complies with its spec if a debugged program is compiled <BR> 41 * without "-g" option, <BR> 42 * hence, the exception AbsentInformationException is expected. <BR> <BR> 43 * <BR> 44 */ 45 46 public class variables002 { 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/variables/variables002", 56 sHeader2 = "--> variables002: ", 57 sHeader3 = "##> variables002: "; 58 59 //----------------------------------------------------- main method 60 main(String argv[])61 public static void main (String argv[]) { 62 int result = run(argv, System.out); 63 System.exit(result + PASS_BASE); 64 } 65 run(String argv[], PrintStream out)66 public static int run (String argv[], PrintStream out) { 67 return new variables002().runThis(argv, out); 68 } 69 70 //-------------------------------------------------- log procedures 71 72 //private static boolean verbMode = false; 73 74 private static Log logHandler; 75 log1(String message)76 private static void log1(String message) { 77 logHandler.display(sHeader1 + message); 78 } log2(String message)79 private static void log2(String message) { 80 logHandler.display(sHeader2 + message); 81 } log3(String message)82 private static void log3(String message) { 83 logHandler.complain(sHeader3 + message); 84 } 85 86 // ************************************************ test parameters 87 88 private String debuggeeName = 89 "nsk.jdi.Method.variables.variables002a"; 90 91 String mName = "nsk.jdi.Method.variables"; 92 93 //====================================================== test program 94 95 static ArgumentHandler argsHandler; 96 static int testExitCode = PASSED; 97 98 //------------------------------------------------------ common section 99 runThis(String argv[], PrintStream out)100 private int runThis (String argv[], PrintStream out) { 101 102 Debugee debuggee; 103 104 argsHandler = new ArgumentHandler(argv); 105 logHandler = new Log(out, argsHandler); 106 Binder binder = new Binder(argsHandler, logHandler); 107 108 if (argsHandler.verbose()) { 109 debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp 110 } else { 111 debuggee = binder.bindToDebugee(debuggeeName); // *** tp 112 } 113 114 IOPipe pipe = new IOPipe(debuggee); 115 116 debuggee.redirectStderr(out); 117 log2("variables002a debuggee launched"); 118 debuggee.resume(); 119 120 String line = pipe.readln(); 121 if ((line == null) || !line.equals("ready")) { 122 log3("signal received is not 'ready' but: " + line); 123 return FAILED; 124 } else { 125 log2("'ready' recieved"); 126 } 127 128 VirtualMachine vm = debuggee.VM(); 129 130 //------------------------------------------------------ testing section 131 log1(" TESTING BEGINS"); 132 133 for (int i = 0; ; i++) { 134 pipe.println("newcheck"); 135 line = pipe.readln(); 136 137 if (line.equals("checkend")) { 138 log2(" : returned string is 'checkend'"); 139 break ; 140 } else if (!line.equals("checkready")) { 141 log3("ERROR: returned string is not 'checkready'"); 142 testExitCode = FAILED; 143 break ; 144 } 145 146 log1("new check: #" + i); 147 148 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part 149 150 List listOfDebuggeeClasses = vm.classesByName(mName + ".variables002aTestClass"); 151 if (listOfDebuggeeClasses.size() != 1) { 152 testExitCode = FAILED; 153 log3("ERROR: listOfDebuggeeClasses.size() != 1"); 154 break ; 155 } 156 157 List methods = null; 158 Method m = null; 159 List argsList = null; 160 161 162 // method with arguments 163 164 methods = ((ReferenceType) listOfDebuggeeClasses.get(0)). 165 methodsByName("primitiveargsmethod"); 166 m = (Method) methods.get(0); 167 168 try { 169 argsList = m.variables(); 170 log3(" no AbsentInformationException"); 171 testExitCode = FAILED; 172 } catch ( AbsentInformationException e ) { 173 log3(" AbsentInformationException"); 174 } 175 176 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 177 } 178 log1(" TESTING ENDS"); 179 180 //-------------------------------------------------- test summary section 181 //------------------------------------------------- standard end section 182 183 pipe.println("quit"); 184 log2("waiting for the debuggee to finish ..."); 185 debuggee.waitFor(); 186 187 int status = debuggee.getStatus(); 188 if (status != PASSED + PASS_BASE) { 189 log3("debuggee returned UNEXPECTED exit status: " + 190 status + " != PASS_BASE"); 191 testExitCode = FAILED; 192 } else { 193 log2("debuggee returned expected exit status: " + 194 status + " == PASS_BASE"); 195 } 196 197 if (testExitCode != PASSED) { 198 logHandler.complain("TEST FAILED"); 199 } 200 return testExitCode; 201 } 202 } 203