Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Locatable/location/location001.java
41171 views
/*1* Copyright (c) 2001, 2019, 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.Locatable.location;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* Locatable. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.Locatable.location()</code> <BR>39* complies with its spec when a tested method <BR>40* is one of PrimitiveTypes, void or native. <BR>41* <BR>42* The cases for testing are as follows. <BR>43* <BR>44* When a gebuggee creates an object of <BR>45* the following class type: <BR>46* class TestClass { <BR>47* public static boolean bl () { return false; } <BR>48* public static byte bt () { return 0; } <BR>49* private static char ch () { return 0; } <BR>50* protected static double db () { return 0.0d; } <BR>51* public float fl () { return 0.0f; } <BR>52* public int in () { return 0; } <BR>53* private long ln () { return 0; } <BR>54* protected short sh () { return 0; } <BR>55* public void vd () { return ; } <BR>56* } <BR>57* a debugger checks up that for all of the above methods, <BR>58* the invocation of the method Locatable.location() <BR>59* returns non-null values. <BR>60* <BR>61*/6263public class location001 {6465//----------------------------------------------------- templete section66static final int PASSED = 0;67static final int FAILED = 2;68static final int PASS_BASE = 95;6970//----------------------------------------------------- templete parameters71static final String72sHeader1 = "\n==> nsk/jdi/Locatable/location/location001 ",73sHeader2 = "--> location001: ",74sHeader3 = "##> location001: ";7576//----------------------------------------------------- main method7778public static void main (String argv[]) {79int result = run(argv, System.out);80System.exit(result + PASS_BASE);81}8283public static int run (String argv[], PrintStream out) {84return new location001().runThis(argv, out);85}8687//-------------------------------------------------- log procedures8889//private static boolean verbMode = false;9091private static Log logHandler;9293private static void log1(String message) {94logHandler.display(sHeader1 + message);95}96private static void log2(String message) {97logHandler.display(sHeader2 + message);98}99private static void log3(String message) {100logHandler.complain(sHeader3 + message);101}102103// ************************************************ test parameters104105private String debuggeeName =106"nsk.jdi.Locatable.location.location001a";107108String mName = "nsk.jdi.Locatable.location";109110//====================================================== test program111112static ArgumentHandler argsHandler;113static int testExitCode = PASSED;114115//------------------------------------------------------ common section116117private int runThis (String argv[], PrintStream out) {118119Debugee debuggee;120121argsHandler = new ArgumentHandler(argv);122logHandler = new Log(out, argsHandler);123Binder binder = new Binder(argsHandler, logHandler);124125126if (argsHandler.verbose()) {127debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp128} else {129debuggee = binder.bindToDebugee(debuggeeName); // *** tp130}131132IOPipe pipe = new IOPipe(debuggee);133134debuggee.redirectStderr(out);135log2(debuggeeName + " debuggee launched");136debuggee.resume();137138String line = pipe.readln();139if ((line == null) || !line.equals("ready")) {140log3("signal received is not 'ready' but: " + line);141return FAILED;142} else {143log2("'ready' recieved");144}145146VirtualMachine vm = debuggee.VM();147148//------------------------------------------------------ testing section149log1(" TESTING BEGINS");150151for (int i = 0; ; i++) {152pipe.println("newcheck");153line = pipe.readln();154155if (line.equals("checkend")) {156log2(" : returned string is 'checkend'");157break ;158} else if (!line.equals("checkready")) {159log3("ERROR: returned string is not 'checkready'");160testExitCode = FAILED;161break ;162}163164log1("new check: #" + i);165166//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part167168List listOfDebuggeeClasses = vm.classesByName(mName + ".location001aTestClass");169if (listOfDebuggeeClasses.size() != 1) {170testExitCode = FAILED;171log3("ERROR: listOfDebuggeeClasses.size() != 1");172break ;173}174175List methods = null;176Method m = null;177Location mLocation = null;178179String bl = "bl";180String bt = "bt";181String ch = "ch";182String db = "db";183String fl = "fl";184String in = "in";185String ln = "ln";186String sh = "sh";187String vd = "vd";188189int i2;190191for (i2 = 0; ; i2++) {192193int expresult = 0;194195log2("new check: #" + i2);196197switch (i2) {198199case 0: // boolean method200methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).201methodsByName(bl);202m = (Method) methods.get(0);203mLocation = m.location();204205if (mLocation == null) {206log3("ERROR: mLocation == null for a boolean method");207expresult = 1;208break;209}210break;211212case 1: // byte method213methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).214methodsByName(bt);215m = (Method) methods.get(0);216mLocation = m.location();217218if (mLocation == null) {219log3("ERROR: mLocation == null for a byte method");220expresult = 1;221break;222}223break;224225case 2: // char method226methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).227methodsByName(ch);228m = (Method) methods.get(0);229mLocation = m.location();230231if (mLocation == null) {232log3("ERROR: mLocation == null for a char method");233expresult = 1;234break;235}236break;237238case 3: // double method239methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).240methodsByName(db);241m = (Method) methods.get(0);242mLocation = m.location();243244if (mLocation == null) {245log3("ERROR: mLocation == null for a double method");246expresult = 1;247break;248}249break;250251case 4: // float method252methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).253methodsByName(fl);254m = (Method) methods.get(0);255mLocation = m.location();256257if (mLocation == null) {258log3("ERROR: mLocation == null for a float method");259expresult = 1;260break;261}262break;263264case 5: // int method265methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).266methodsByName(in);267m = (Method) methods.get(0);268mLocation = m.location();269270if (mLocation == null) {271log3("ERROR: mLocation == null for an int method");272expresult = 1;273break;274}275break;276277case 6: // long method278methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).279methodsByName(ln);280m = (Method) methods.get(0);281mLocation = m.location();282283if (mLocation == null) {284log3("ERROR: mLocation == null for a long method");285expresult = 1;286break;287}288break;289290case 7: // short method291methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).292methodsByName(sh);293m = (Method) methods.get(0);294mLocation = m.location();295296if (mLocation == null) {297log3("ERROR: mLocation == null for a short method");298expresult = 1;299break;300}301break;302303case 8: // void method304methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).305methodsByName(vd);306m = (Method) methods.get(0);307mLocation = m.location();308309if (mLocation == null) {310log3("ERROR: mLocation == null for a void method");311expresult = 1;312break;313}314break;315316317default: expresult = 2;318break ;319}320321if (expresult == 2) {322log2(" test cases finished");323break ;324} else if (expresult == 1) {325log3("ERROR: expresult != true; check # = " + i);326testExitCode = FAILED;327}328}329//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~330}331log1(" TESTING ENDS");332333//-------------------------------------------------- test summary section334//------------------------------------------------- standard end section335336pipe.println("quit");337log2("waiting for the debuggee to finish ...");338debuggee.waitFor();339340int status = debuggee.getStatus();341if (status != PASSED + PASS_BASE) {342log3("debuggee returned UNEXPECTED exit status: " +343status + " != PASS_BASE");344testExitCode = FAILED;345} else {346log2("debuggee returned expected exit status: " +347status + " == PASS_BASE");348}349350if (testExitCode != PASSED) {351logHandler.complain("TEST FAILED");352}353return testExitCode;354}355}356357358