Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/isArgument/isargument001.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.isArgument;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.isArgument()</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.isArgument() applied to each of <BR>62* method variable returns false for all the tested <BR>63* local variables and true for the argument "param". <BR>64* <BR>65*/6667public class isargument001 {6869//----------------------------------------------------- templete section70static final int PASSED = 0;71static final int FAILED = 2;72static final int PASS_BASE = 95;7374//----------------------------------------------------- templete parameters75static final String76sHeader1 = "\n==> nsk/jdi/LocalVariable/isArgument/isargument001 ",77sHeader2 = "--> isargument001: ",78sHeader3 = "##> isargument001: ";7980//----------------------------------------------------- main method8182public static void main (String argv[]) {83int result = run(argv, System.out);84System.exit(result + PASS_BASE);85}8687public static int run (String argv[], PrintStream out) {88return new isargument001().runThis(argv, out);89}9091//-------------------------------------------------- log procedures9293//private static boolean verbMode = false;9495private static Log logHandler;9697private static void log1(String message) {98logHandler.display(sHeader1 + message);99}100private static void log2(String message) {101logHandler.display(sHeader2 + message);102}103private static void log3(String message) {104logHandler.complain(sHeader3 + message);105}106107// ************************************************ test parameters108109private String debuggeeName =110"nsk.jdi.LocalVariable.isArgument.isargument001a";111112String mName = "nsk.jdi.LocalVariable.isArgument";113114//====================================================== test program115116static ArgumentHandler argsHandler;117static int testExitCode = PASSED;118119//------------------------------------------------------ common section120121private int runThis (String argv[], PrintStream out) {122123Debugee debuggee;124125argsHandler = new ArgumentHandler(argv);126logHandler = new Log(out, argsHandler);127Binder binder = new Binder(argsHandler, logHandler);128129if (argsHandler.verbose()) {130debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp131} else {132debuggee = binder.bindToDebugee(debuggeeName); // *** tp133}134135IOPipe pipe = new IOPipe(debuggee);136137debuggee.redirectStderr(out);138log2("isargument001a debuggee launched");139debuggee.resume();140141String line = pipe.readln();142if ((line == null) || !line.equals("ready")) {143log3("signal received is not 'ready' but: " + line);144return FAILED;145} else {146log2("'ready' recieved");147}148149VirtualMachine vm = debuggee.VM();150151//------------------------------------------------------ testing section152log1(" TESTING BEGINS");153154for (int i = 0; ; i++) {155pipe.println("newcheck");156line = pipe.readln();157158if (line.equals("checkend")) {159log2(" : returned string is 'checkend'");160break ;161} else if (!line.equals("checkready")) {162log3("ERROR: returned string is not 'checkready'");163testExitCode = FAILED;164break ;165}166167log1("new check: #" + i);168169//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part170171List listOfLoadedClasses = vm.classesByName(mName + ".TestClass");172173if (listOfLoadedClasses.size() != 1) {174testExitCode = FAILED;175log3("ERROR: listOfLoadedClasses.size() != 1 " +176listOfLoadedClasses.size());177break ;178}179180List methods =181((ReferenceType) listOfLoadedClasses.get(0)).182methodsByName("testmethod");183184Method testMethod = (Method) methods.get(0);185186187String names[] = { "bl1", "bt1", "ch1", "db1",188"fl1", "in1", "ln1", "sh1",189"class2", "iface", "cfc", "param" };190191int i2;192int expresult = 0;193194for (i2 = 0; i2 < names.length; i2++) {195196log2("new check: #" + i2);197198List lVars = null;199try {200lVars = testMethod.variablesByName(names[i2]);201} catch ( AbsentInformationException e ) {202log3("ERROR: AbsentInformationException for " +203"lVars = testMethod.variablesByName(names[i2])" );204testExitCode = FAILED;205continue;206}207if (lVars.size() != 1) {208testExitCode = FAILED;209log3("ERROR: lVars.size() != 1 for i2=" + i2 + " : " + lVars.size());210continue;211}212213LocalVariable lVar = (LocalVariable) lVars.get(0);214215switch (i2) {216217case 0: // BooleanType218if (lVar.isArgument()) {219testExitCode = FAILED;220log3("ERROR: lVar.isArgument for 'bl1'");221}222break;223224case 1: // ByteType225if (lVar.isArgument()) {226testExitCode = FAILED;227log3("ERROR: lVar.isArgument for 'bt1'");228}229break;230231case 2: // CharType232if (lVar.isArgument()) {233testExitCode = FAILED;234log3("ERROR: lVar.isArgument for 'ch1'");235}236break;237238case 3: // DoubleType239if (lVar.isArgument()) {240testExitCode = FAILED;241log3("ERROR: lVar.isArgument for 'db1'");242}243break;244245case 4: // FloatType246if (lVar.isArgument()) {247testExitCode = FAILED;248log3("ERROR: lVar.isArgument for 'fl1'");249}250break;251252case 5: // IntegerType253if (lVar.isArgument()) {254testExitCode = FAILED;255log3("ERROR: lVar.isArgument for 'in1'");256}257break;258259case 6: // LongType260if (lVar.isArgument()) {261testExitCode = FAILED;262log3("ERROR: lVar.isArgument for 'ln1'");263}264break;265266case 7: // ShortType267if (lVar.isArgument()) {268testExitCode = FAILED;269log3("ERROR: lVar.isArgument for 'sh1'");270}271break;272273274case 8: // ClassType275if (lVar.isArgument()) {276testExitCode = FAILED;277log3("ERROR: lVar.isArgument for 'class2'");278}279break;280281case 9: // InterfaceType282if (lVar.isArgument()) {283testExitCode = FAILED;284log3("ERROR: lVar.isArgument for 'iface'");285}286break;287288case 10: // ArrayType289if (lVar.isArgument()) {290testExitCode = FAILED;291log3("ERROR: lVar.isArgument for 'cfc'");292}293break;294295296case 11: // argument297if (!lVar.isArgument()) {298testExitCode = FAILED;299log3("ERROR: !lVar.isArgument for 'param'");300}301break;302303304default: expresult = 2;305break ;306}307308if (expresult == 2) {309log2(" test cases finished");310break ;311}312}313//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~314}315log1(" TESTING ENDS");316317//-------------------------------------------------- test summary section318//------------------------------------------------- standard end section319320pipe.println("quit");321log2("waiting for the debuggee to finish ...");322debuggee.waitFor();323324int status = debuggee.getStatus();325if (status != PASSED + PASS_BASE) {326log3("debuggee returned UNEXPECTED exit status: " +327status + " != PASS_BASE");328testExitCode = FAILED;329} else {330log2("debuggee returned expected exit status: " +331status + " == PASS_BASE");332}333334if (testExitCode != PASSED) {335logHandler.complain("TEST FAILED");336}337return testExitCode;338}339}340341342