Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/name/name001.java
41161 views
/*1* Copyright (c) 2001, 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.name;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import java.util.*;31import java.io.*;3233/**34* The test for the implementation of an object of the type <BR>35* LocalVariable. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.LocalVariable.name()</code> <BR>39* complies with its spec. <BR>40* <BR>41* The cases for testing are as follows. <BR>42* <BR>43* When a gebuggee creates an object containing <BR>44* the following method: <BR>45* public void testmethod (int param) { <BR>46* boolean bl1 = false, bl2 = true; <BR>47* byte bt1 = 0, bt2 = 1; <BR>48* char ch1 = 0, ch2 = 1; <BR>49* double db1 = 0.0d, db2 = 1.0d; <BR>50* float fl1 = 0.0f, fl2 = 1.0f; <BR>51* int in1 = 0, in2 = 1; <BR>52* long ln1 = 0, ln2 = 1; <BR>53* short sh1 = 0, sh2 = 1; <BR>54* ClassForCheck_2 class2 = new ClassForCheck_2(); <BR>55* InterfaceForCheck iface = class2; <BR>56* ClassForCheck cfc[] = { new ClassForCheck(), <BR>57* new ClassForCheck() }; <BR>58* return; <BR>59* } <BR>60* a debugger checks up that the method <BR>61* LocalVariable.name() applied to each of <BR>62* method variable returns its name. <BR>63* <BR>64*/6566public class name001 {6768//----------------------------------------------------- templete section69static final int PASSED = 0;70static final int FAILED = 2;71static final int PASS_BASE = 95;7273//----------------------------------------------------- templete parameters74static final String75sHeader1 = "\n==> nsk/jdi/LocalVariable/name/name001 ",76sHeader2 = "--> name001: ",77sHeader3 = "##> name001: ";7879//----------------------------------------------------- main method8081public static void main (String argv[]) {82int result = run(argv, System.out);83System.exit(result + PASS_BASE);84}8586public static int run (String argv[], PrintStream out) {87return new name001().runThis(argv, out);88}8990//-------------------------------------------------- log procedures9192//private static boolean verbMode = false;9394private static Log logHandler;9596private static void log1(String message) {97logHandler.display(sHeader1 + message);98}99private static void log2(String message) {100logHandler.display(sHeader2 + message);101}102private static void log3(String message) {103logHandler.complain(sHeader3 + message);104}105106// ************************************************ test parameters107108private String debuggeeName =109"nsk.jdi.LocalVariable.name.name001a";110111String mName = "nsk.jdi.LocalVariable.name";112113//====================================================== test program114115static ArgumentHandler argsHandler;116static int testExitCode = PASSED;117118//------------------------------------------------------ common section119120private int runThis (String argv[], PrintStream out) {121122Debugee debuggee;123124argsHandler = new ArgumentHandler(argv);125logHandler = new Log(out, argsHandler);126Binder binder = new Binder(argsHandler, logHandler);127128if (argsHandler.verbose()) {129debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp130} else {131debuggee = binder.bindToDebugee(debuggeeName); // *** tp132}133134IOPipe pipe = new IOPipe(debuggee);135136debuggee.redirectStderr(out);137log2("name001a debuggee launched");138debuggee.resume();139140String line = pipe.readln();141if ((line == null) || !line.equals("ready")) {142log3("signal received is not 'ready' but: " + line);143return FAILED;144} else {145log2("'ready' recieved");146}147148VirtualMachine vm = debuggee.VM();149150//------------------------------------------------------ testing section151log1(" TESTING BEGINS");152153for (int i = 0; ; i++) {154pipe.println("newcheck");155line = pipe.readln();156157if (line.equals("checkend")) {158log2(" : returned string is 'checkend'");159break ;160} else if (!line.equals("checkready")) {161log3("ERROR: returned string is not 'checkready'");162testExitCode = FAILED;163break ;164}165166log1("new check: #" + i);167168//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part169170List listOfLoadedClasses = vm.classesByName(mName + ".TestClass");171172if (listOfLoadedClasses.size() != 1) {173testExitCode = FAILED;174log3("ERROR: listOfLoadedClasses.size() != 1 " +175listOfLoadedClasses.size());176break ;177}178179List methods =180((ReferenceType) listOfLoadedClasses.get(0)).181methodsByName("testmethod");182183Method testMethod = (Method) methods.get(0);184185186String names[] = { "bl1", "bt1", "ch1", "db1",187"fl1", "in1", "ln1", "sh1",188"class2", "iface", "cfc" };189190int i2;191int expresult = 0;192193for (i2 = 0; i2 < names.length; i2++) {194195log2("new check: #" + i2);196197List lVars = null;198try {199lVars = testMethod.variablesByName(names[i2]);200} catch ( AbsentInformationException e ) {201log3("ERROR: AbsentInformationException for " +202"lVars = testMethod.variablesByName(names[i2])" );203testExitCode = FAILED;204continue;205}206if (lVars.size() != 1) {207testExitCode = FAILED;208log3("ERROR: lVars.size() != 1 for i2=" + i2 + " : " + lVars.size());209continue;210}211212LocalVariable lVar = (LocalVariable) lVars.get(0);213214String lVarName = lVar.name();215216switch (i2) {217218case 0: // BooleanType219if (!lVarName.equals("bl1")) {220testExitCode = FAILED;221log3("ERROR: !lVarName.equals('bl1')");222}223224break;225226case 1: // ByteType227228if (!lVarName.equals("bt1")) {229testExitCode = FAILED;230log3("ERROR: !lVarName.equals('bt1')");231}232break;233234case 2: // CharType235if (!lVarName.equals("ch1")) {236testExitCode = FAILED;237log3("ERROR: !lVarName.equals('ch1')");238}239break;240241case 3: // DoubleType242if (!lVarName.equals("db1")) {243testExitCode = FAILED;244log3("ERROR: !lVarName.equals('db1')");245}246break;247248case 4: // FloatType249if (!lVarName.equals("fl1")) {250testExitCode = FAILED;251log3("ERROR: !lVarName.equals('fl1')");252}253break;254255case 5: // IntegerType256if (!lVarName.equals("in1")) {257testExitCode = FAILED;258log3("ERROR: !lVarName.equals('in1')");259}260break;261262case 6: // LongType263if (!lVarName.equals("ln1")) {264testExitCode = FAILED;265log3("ERROR: !lVarName.equals('ln1')");266}267break;268269case 7: // ShortType270if (!lVarName.equals("sh1")) {271testExitCode = FAILED;272log3("ERROR: !lVarName.equals('sh1')");273}274break;275276277case 8: // ClassType278if (!lVarName.equals("class2")) {279testExitCode = FAILED;280log3("ERROR: !lVarName.equals('class2')");281}282break;283284case 9: // InterfaceType285if (!lVarName.equals("iface")) {286testExitCode = FAILED;287log3("ERROR: !lVarName.equals('iface')");288}289break;290291case 10: // ArrayType292if (!lVarName.equals("cfc")) {293testExitCode = FAILED;294log3("ERROR: !lVarName.equals('cfc')");295}296break;297298299default: expresult = 2;300break ;301}302303if (expresult == 2) {304log2(" test cases finished");305break ;306}307}308//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~309}310log1(" TESTING ENDS");311312//-------------------------------------------------- test summary section313//------------------------------------------------- standard end section314315pipe.println("quit");316log2("waiting for the debuggee to finish ...");317debuggee.waitFor();318319int status = debuggee.getStatus();320if (status != PASSED + PASS_BASE) {321log3("debuggee returned UNEXPECTED exit status: " +322status + " != PASS_BASE");323testExitCode = FAILED;324} else {325log2("debuggee returned expected exit status: " +326status + " == PASS_BASE");327}328329if (testExitCode != PASSED) {330logHandler.complain("TEST FAILED");331}332return testExitCode;333}334}335336337