Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Locatable/location/location003.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.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 ReferenceTypes. <BR>41* <BR>42* The cases for testing are as follows. <BR>43* <BR>44* When a gebuggee creates an object of the following <BR>45* class type with methods returning ReferenceType objects:<BR>46* <BR>47* class TestClass { <BR>48* . <BR>49* . <BR>50* public ClassForCheck[] arraymethod () { <BR>51* return cfc; <BR>52* } <BR>53* public ClassForCheck classmethod () { <BR>54* return classFC; <BR>55* } <BR>56* public InterfaceForCheck ifacemethod () { <BR>57* return iface; <BR>58* } <BR>59* } <BR>60* a debugger checks up that for all of the above61* methods returning ReferenceType objects, <BR>62* the invocation of the method Locatable.location() <BR>63* returns non-null value. <BR>64* <BR>65*/6667public class location003 {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/Locatable/location/location003 ",77sHeader2 = "--> location003: ",78sHeader3 = "##> location003: ";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 location003().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.Locatable.location.location003a";111112String mName = "nsk.jdi.Locatable.location";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);128129130if (argsHandler.verbose()) {131debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp132} else {133debuggee = binder.bindToDebugee(debuggeeName); // *** tp134}135136IOPipe pipe = new IOPipe(debuggee);137138debuggee.redirectStderr(out);139log2("location003a debuggee launched");140debuggee.resume();141142String line = pipe.readln();143if ((line == null) || !line.equals("ready")) {144log3("signal received is not 'ready' but: " + line);145return FAILED;146} else {147log2("'ready' recieved");148}149150VirtualMachine vm = debuggee.VM();151152//------------------------------------------------------ testing section153log1(" TESTING BEGINS");154155for (int i = 0; ; i++) {156pipe.println("newcheck");157line = pipe.readln();158159if (line.equals("checkend")) {160log2(" : returned string is 'checkend'");161break ;162} else if (!line.equals("checkready")) {163log3("ERROR: returned string is not 'checkready'");164testExitCode = FAILED;165break ;166}167168log1("new check: #" + i);169170//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part171172List listOfDebuggeeClasses = vm.classesByName(mName + ".location003aTestClass");173if (listOfDebuggeeClasses.size() != 1) {174testExitCode = FAILED;175log3("ERROR: listOfDebuggeeClasses.size() != 1");176break ;177}178179List methods = null;180Method m = null;181Location mLocation = null;182183int i2;184185for (i2 = 0; ; i2++) {186187int expresult = 0;188189log2("new check: #" + i2);190191switch (i2) {192193case 0: // ArrayType194195methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).196methodsByName("arraymethod");197m = (Method) methods.get(0);198mLocation = m.location();199200if (mLocation == null) {201log3("ERROR: mLocation == null for 'arraymethod'");202testExitCode = FAILED;203}204break;205206case 1: // ClassType207208methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).209methodsByName("classmethod");210m = (Method) methods.get(0);211mLocation = m.location();212213if (mLocation == null) {214log3("ERROR: mLocation == null for 'classmethod'");215testExitCode = FAILED;216}217break;218219case 2: // InterfaceType220221methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).222methodsByName("ifacemethod");223m = (Method) methods.get(0);224mLocation = m.location();225226if (mLocation == null) {227log3("ERROR: mLocation == null for 'ifacemethod'");228testExitCode = FAILED;229}230break;231232233default: expresult = 2;234break ;235}236237if (expresult == 2) {238log2(" test cases finished");239break ;240} else if (expresult == 1) {241log3("ERROR: expresult != true; check # = " + i);242testExitCode = FAILED;243}244}245//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~246}247log1(" TESTING ENDS");248249//-------------------------------------------------- test summary section250//------------------------------------------------- standard end section251252pipe.println("quit");253log2("waiting for the debuggee to finish ...");254debuggee.waitFor();255256int status = debuggee.getStatus();257if (status != PASSED + PASS_BASE) {258log3("debuggee returned UNEXPECTED exit status: " +259status + " != PASS_BASE");260testExitCode = FAILED;261} else {262log2("debuggee returned expected exit status: " +263status + " == PASS_BASE");264}265266if (testExitCode != PASSED) {267logHandler.complain("TEST FAILED");268}269return testExitCode;270}271}272273274