Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/toString/tostring001.java
41161 views
/*1* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdi.LocalVariable.toString;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import com.sun.jdi.request.*;31import com.sun.jdi.event.*;32import com.sun.jdi.connect.*;33import java.io.*;34import java.util.*;3536/**37* The debugger application of the test.38*/39public class tostring001 {4041//------------------------------------------------------- immutable common fields4243final static String SIGNAL_READY = "ready";44final static String SIGNAL_GO = "go";45final static String SIGNAL_QUIT = "quit";4647private static int waitTime;48private static int exitStatus;49private static ArgumentHandler argHandler;50private static Log log;51private static Debugee debuggee;52private static ReferenceType debuggeeClass;5354//------------------------------------------------------- mutable common fields5556private final static String prefix = "nsk.jdi.LocalVariable.toString.";57private final static String className = "tostring001";58private final static String debuggerName = prefix + className;59private final static String debuggeeName = debuggerName + "a";6061//------------------------------------------------------- test specific fields6263/** debuggee's local variables for check **/64private final static String checkedVars[] = {65"z0", "z1", "z2",66"b0", "b1", "b2",67"c0", "c1", "c2",68"d0", "d1", "d2",69"f0", "f1", "f2",70"i0", "i1", "i2",71"l0", "l1", "l2",72"r0", "r1", "r2",73"Z0", "Z1", "Z2",74"B0", "B1", "B2",75"C0", "C1", "C2",76"D0", "D1", "D2",77"F0", "F1", "F2",78"I0", "I1", "I2",79"L0", "L1", "L2",80"R0", "R1", "R2",81"s0", "s1", "s2",82"o0", "o1", "o2",83"p0", "p1", "p2",84"m0", "m1", "m2"85};8687//------------------------------------------------------- immutable common methods8889public static void main(String argv[]) {90System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));91}9293private static void display(String msg) {94log.display("debugger > " + msg);95}9697private static void complain(String msg) {98log.complain("debugger FAILURE > " + msg);99}100101public static int run(String argv[], PrintStream out) {102103exitStatus = Consts.TEST_PASSED;104105argHandler = new ArgumentHandler(argv);106log = new Log(out, argHandler);107waitTime = argHandler.getWaitTime() * 60000;108109debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName);110111debuggeeClass = debuggee.classByName(debuggeeName);112if ( debuggeeClass == null ) {113complain("Class '" + debuggeeName + "' not found.");114exitStatus = Consts.TEST_FAILED;115}116117execTest();118119debuggee.quit();120121return exitStatus;122}123124//------------------------------------------------------ mutable common method125126private static void execTest() {127128// Finding of debuggee's main method129Method mainMethod = methodByName(debuggeeClass, "main");130131display("Checking toString() method for local variables of debuggee's main method...");132133// Check all methods from debuggee134for (int i = 0; i < checkedVars.length; i++) {135136LocalVariable localVar = variableByName(mainMethod, checkedVars[i]);137138try {139String str = localVar.toString();140if (str == null) {141complain("toString() returns null for LocalVariable of debuggee's local variable: " + checkedVars[i]);142exitStatus = Consts.TEST_FAILED;143} else if (str.length() == 0) {144complain("toString() returns empty string for LocalVariable of debuggee's local variable: " + checkedVars[i]);145exitStatus = Consts.TEST_FAILED;146} else {147display("toString() returns for debuggee's local variable " + checkedVars[i] + " : " + str);148}149} catch(Exception e) {150complain("Unexpected " + e + " when getting LocalVariable of debuggee's local variable: " + checkedVars[i]);151exitStatus = Consts.TEST_FAILED;152}153154}155156display("Checking completed!");157}158159//--------------------------------------------------------- test specific methods160161private static Method methodByName(ReferenceType refType, String methodName) {162List methodList = refType.methodsByName(methodName);163if (methodList == null) {164throw new Failure("Can not find method: " + methodName);165}166if (methodList.size() > 1) {167throw new Failure("Found more than one method with name : " + methodName);168}169170Method method = (Method) methodList.get(0);171return method;172}173174private static LocalVariable variableByName(Method method, String varName) {175List varList = null;176try {177varList = method.variablesByName(varName);178} catch (AbsentInformationException e) {179throw new Failure("Unexpected AbsentInformationException while getting variable: " + varName);180}181if (varList == null) {182throw new Failure("Can not find variable: " + varName);183}184if (varList.size() > 1) {185throw new Failure("Found more than one variable with name : " + varName);186}187188LocalVariable var = (LocalVariable) varList.get(0);189return var;190}191}192//--------------------------------------------------------- test specific classes193194195