Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Locatable/location/location006.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 native. <BR>40* <BR>41* The case for testing is as follows. <BR>42* <BR>43* When a gebuggee creates an object of <BR>44* the following class type: <BR>45* class TestClass { <BR>46* public native void nativeMethod (); <BR>47* } <BR>48* a debugger checks up that the invocation of <BR>49* the method Locatable.location() on the nativeMethod <BR>50* returns not the null. <BR>51* <BR>52*/5354public class location006 {5556//----------------------------------------------------- templete section57static final int PASSED = 0;58static final int FAILED = 2;59static final int PASS_BASE = 95;6061//----------------------------------------------------- templete parameters62static final String63sHeader1 = "\n==> nsk/jdi/Locatable/location/location006 ",64sHeader2 = "--> location006: ",65sHeader3 = "##> location006: ";6667//----------------------------------------------------- main method6869public static void main (String argv[]) {70int result = run(argv, System.out);71System.exit(result + PASS_BASE);72}7374public static int run (String argv[], PrintStream out) {75return new location006().runThis(argv, out);76}7778//-------------------------------------------------- log procedures7980//private static boolean verbMode = false;8182private static Log logHandler;8384private static void log1(String message) {85logHandler.display(sHeader1 + message);86}87private static void log2(String message) {88logHandler.display(sHeader2 + message);89}90private static void log3(String message) {91logHandler.complain(sHeader3 + message);92}9394// ************************************************ test parameters9596private String debuggeeName =97"nsk.jdi.Locatable.location.location006a";9899String mName = "nsk.jdi.Locatable.location";100101//====================================================== test program102103static ArgumentHandler argsHandler;104static int testExitCode = PASSED;105106//------------------------------------------------------ common section107108private int runThis (String argv[], PrintStream out) {109110Debugee debuggee;111112argsHandler = 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("location006a 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 = vm.classesByName(mName + ".location006aTestClass");160if (listOfDebuggeeClasses.size() != 1) {161testExitCode = FAILED;162log3("ERROR: listOfDebuggeeClasses.size() != 1");163break ;164}165166List methods = null;167Method m = null;168Location mLocation = null;169170methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).171methodsByName("nativeMethod");172m = (Method) methods.get(0);173mLocation = m.location();174175if (mLocation == null) {176log3("ERROR: mLocation == null for a native method");177testExitCode = FAILED;178}179//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~180}181log1(" TESTING ENDS");182183//-------------------------------------------------- test summary section184//------------------------------------------------- standard end section185186pipe.println("quit");187log2("waiting for the debuggee to finish ...");188debuggee.waitFor();189190int status = debuggee.getStatus();191if (status != PASSED + PASS_BASE) {192log3("debuggee returned UNEXPECTED exit status: " +193status + " != PASS_BASE");194testExitCode = FAILED;195} else {196log2("debuggee returned expected exit status: " +197status + " == PASS_BASE");198}199200if (testExitCode != PASSED) {201System.out.println("TEST FAILED");202}203return testExitCode;204}205}206207208