Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Locatable/location/location002.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 is an abstract. <BR>40* <BR>41* The cases for testing are as follows. <BR>42* <BR>43* When a gebuggee creates an object of TestClass <BR>44* which contains an instance of class ClassForCheck <BR>45* implementing, directly and indirectly, two abstract <BR>46* methods from its super-class and super-interface, <BR>47* a debugger invokes the method Locatable.location() <BR>48* with these two abstract methods as arguments and <BR>49* checks up returned values. <BR>50* <BR>51*/5253public class location002 {5455//----------------------------------------------------- templete section56static final int PASSED = 0;57static final int FAILED = 2;58static final int PASS_BASE = 95;5960//----------------------------------------------------- templete parameters61static final String62sHeader1 = "\n==> nsk/jdi/Locatable/location/location002 ",63sHeader2 = "--> location002: ",64sHeader3 = "##> location002: ";6566//----------------------------------------------------- main method6768public static void main (String argv[]) {69int result = run(argv, System.out);70System.exit(result + PASS_BASE);71}7273public static int run (String argv[], PrintStream out) {74return new location002().runThis(argv, out);75}7677//-------------------------------------------------- log procedures7879//private static boolean verbMode = false;8081private static Log logHandler;8283private static void log1(String message) {84logHandler.display(sHeader1 + message);85}86private static void log2(String message) {87logHandler.display(sHeader2 + message);88}89private static void log3(String message) {90logHandler.complain(sHeader3 + message);91}9293// ************************************************ test parameters9495private String debuggeeName =96"nsk.jdi.Locatable.location.location002a";9798String mName = "nsk.jdi.Locatable.location";99100//====================================================== test program101102static ArgumentHandler argsHandler;103static int testExitCode = PASSED;104105//------------------------------------------------------ common section106107private int runThis (String argv[], PrintStream out) {108109Debugee debuggee;110111112argsHandler = new ArgumentHandler(argv);113logHandler = new Log(out, argsHandler);114Binder binder = new Binder(argsHandler, logHandler);115116117if (argsHandler.verbose()) {118debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp119} else {120debuggee = binder.bindToDebugee(debuggeeName); // *** tp121}122123IOPipe pipe = new IOPipe(debuggee);124125debuggee.redirectStderr(out);126log2("location002a debuggee launched");127debuggee.resume();128129String line = pipe.readln();130if ((line == null) || !line.equals("ready")) {131log3("signal received is not 'ready' but: " + line);132return FAILED;133} else {134log2("'ready' recieved");135}136137VirtualMachine vm = debuggee.VM();138139//------------------------------------------------------ testing section140log1(" TESTING BEGINS");141142for (int i = 0; ; i++) {143pipe.println("newcheck");144line = pipe.readln();145146if (line.equals("checkend")) {147log2(" : returned string is 'checkend'");148break ;149} else if (!line.equals("checkready")) {150log3("ERROR: returned string is not 'checkready'");151testExitCode = FAILED;152break ;153}154155log1("new check: #" + i);156157//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part158159List listOfDebuggeeClasses = null;160List methods = null;161Method m = null;162Location mLocation = null;163164String testedMethod1 = "abstractMethod1";165String testedMethod2 = "abstractMethod2";166167listOfDebuggeeClasses = vm.classesByName(mName + ".location002aInterfaceForCheck");168if (listOfDebuggeeClasses.size() != 1) {169testExitCode = FAILED;170log3("ERROR: listOfDebuggeeClasses.size() != 1");171break ;172}173methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).174methodsByName(testedMethod1);175m = (Method) methods.get(0);176mLocation = m.location();177178if (mLocation != null) {179log3("ERROR: mLocation != null for an abstract method in location002aInterfaceForCheck");180testExitCode = FAILED;181}182183listOfDebuggeeClasses = vm.classesByName(mName + ".location002aClassForCheck2");184if (listOfDebuggeeClasses.size() != 1) {185testExitCode = FAILED;186log3("ERROR: listOfDebuggeeClasses.size() != 1");187break ;188}189methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).190methodsByName(testedMethod2);191m = (Method) methods.get(0);192mLocation = m.location();193194if (mLocation != null) {195log3("ERROR: mLocation != null for an abstract method in location002aClassForCheck2");196testExitCode = FAILED;197}198//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~199}200log1(" TESTING ENDS");201202//-------------------------------------------------- test summary section203//------------------------------------------------- standard end section204205pipe.println("quit");206log2("waiting for the debuggee to finish ...");207debuggee.waitFor();208209int status = debuggee.getStatus();210if (status != PASSED + PASS_BASE) {211log3("debuggee returned UNEXPECTED exit status: " +212status + " != PASS_BASE");213testExitCode = FAILED;214} else {215log2("debuggee returned expected exit status: " +216status + " == PASS_BASE");217}218219if (testExitCode != PASSED) {220System.out.println("TEST FAILED");221}222return testExitCode;223}224}225226227