Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/signature/signature001.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.signature;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.signature()</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.signature() applied to each of <BR>62* method variable returns its JNI-style signature. <BR>63* <BR>64*/6566public class signature001 {6768//----------------------------------------------------- templete section69static final int PASSED = 0;70static final int FAILED = 2;71static final int PASS_BASE = 95;7273//----------------------------------------------------- templete parameters74static final String75sHeader1 = "\n==> nsk/jdi/LocalVariable/signature/signature001 ",76sHeader2 = "--> signature001: ",77sHeader3 = "##> signature001: ";7879//----------------------------------------------------- main method8081public static void main (String argv[]) {82int result = run(argv, System.out);83System.exit(result + PASS_BASE);84}8586public static int run (String argv[], PrintStream out) {87return new signature001().runThis(argv, out);88}8990//-------------------------------------------------- log procedures9192//private static boolean verbMode = false;9394private static Log logHandler;9596private static void log1(String message) {97logHandler.display(sHeader1 + message);98}99private static void log2(String message) {100logHandler.display(sHeader2 + message);101}102private static void log3(String message) {103logHandler.complain(sHeader3 + message);104}105106// ************************************************ test parameters107108private String debuggeeName =109"nsk.jdi.LocalVariable.signature.signature001a";110111String mName = "nsk.jdi.LocalVariable.signature";112113String mSignature = "nsk/jdi/LocalVariable/signature";114115//====================================================== test program116117static ArgumentHandler argsHandler;118static int testExitCode = PASSED;119120//------------------------------------------------------ common section121122private int runThis (String argv[], PrintStream out) {123124Debugee debuggee;125126argsHandler = new ArgumentHandler(argv);127logHandler = new Log(out, argsHandler);128Binder binder = new Binder(argsHandler, logHandler);129130if (argsHandler.verbose()) {131debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp132} else {133debuggee = binder.bindToDebugee(debuggeeName); // *** tp134}135136IOPipe pipe = new IOPipe(debuggee);137138debuggee.redirectStderr(out);139log2("signature001a 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 listOfLoadedClasses = vm.classesByName(mName + ".TestClass");173174if (listOfLoadedClasses.size() != 1) {175testExitCode = FAILED;176log3("ERROR: listOfLoadedClasses.size() != 1 " +177listOfLoadedClasses.size());178break ;179}180181List methods =182((ReferenceType) listOfLoadedClasses.get(0)).183methodsByName("testmethod");184185Method testMethod = (Method) methods.get(0);186187188String names[] = { "bl1", "bt1", "ch1", "db1",189"fl1", "in1", "ln1", "sh1",190"class2", "iface", "cfc" };191192int i2;193int expresult = 0;194195for (i2 = 0; i2 < names.length; i2++) {196197log2("new check: #" + i2);198199List lVars = null;200try {201lVars = testMethod.variablesByName(names[i2]);202} catch ( AbsentInformationException e ) {203log3("ERROR: AbsentInformationException for " +204"lVars = testMethod.variablesByName(names[i2])" );205testExitCode = FAILED;206continue;207}208if (lVars.size() != 1) {209testExitCode = FAILED;210log3("ERROR: lVars.size() != 1 for i2=" + i2 + " : " + lVars.size());211continue;212}213214LocalVariable lVar = (LocalVariable) lVars.get(0);215216String lVarSignature = lVar.signature();217218switch (i2) {219220case 0: // BooleanType221if (!lVarSignature.equals("Z")) {222testExitCode = FAILED;223log3("ERROR: !lVarSignature.equals('Z')");224}225break;226227case 1: // ByteType228229if (!lVarSignature.equals("B")) {230testExitCode = FAILED;231log3("ERROR: !lVarSignature.equals('B')");232}233break;234235case 2: // CharType236if (!lVarSignature.equals("C")) {237testExitCode = FAILED;238log3("ERROR: !lVarSignature.equals('C')");239}240break;241242case 3: // DoubleType243if (!lVarSignature.equals("D")) {244testExitCode = FAILED;245log3("ERROR: !lVarSignature.equals('D')");246}247break;248249case 4: // FloatType250if (!lVarSignature.equals("F")) {251testExitCode = FAILED;252log3("ERROR: !lVarSignature.equals('F')");253}254break;255256case 5: // IntegerType257if (!lVarSignature.equals("I")) {258testExitCode = FAILED;259log3("ERROR: !lVarSignature.equals('I')");260}261break;262263case 6: // LongType264if (!lVarSignature.equals("J")) {265testExitCode = FAILED;266log3("ERROR: !lVarSignature.equals('J')");267}268break;269270case 7: // ShortType271if (!lVarSignature.equals("S")) {272testExitCode = FAILED;273log3("ERROR: !lVarSignature.equals('S')");274}275break;276277278case 8: // ClassType279if (!lVarSignature.equals("L" + mSignature + "/ClassForCheck_2;")) {280testExitCode = FAILED;281log3("ERROR: !lVarSignature.equals(<signature>) : " + lVarSignature);282}283break;284285case 9: // InterfaceType286if (!lVarSignature.equals("L" + mSignature + "/InterfaceForCheck;")) {287testExitCode = FAILED;288log3("ERROR: !lVarSignature.equals(<signature>) : " + lVarSignature);289}290break;291292case 10: // ArrayType293if (!lVarSignature.equals("[L" + mSignature + "/ClassForCheck;")) {294testExitCode = FAILED;295log3("ERROR: !lVarSignature.equals(<signature>) : " + lVarSignature);296}297break;298299300default: expresult = 2;301break ;302}303304if (expresult == 2) {305log2(" test cases finished");306break ;307}308}309//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~310}311log1(" TESTING ENDS");312313//-------------------------------------------------- test summary section314//------------------------------------------------- standard end section315316pipe.println("quit");317log2("waiting for the debuggee to finish ...");318debuggee.waitFor();319320int status = debuggee.getStatus();321if (status != PASSED + PASS_BASE) {322log3("debuggee returned UNEXPECTED exit status: " +323status + " != PASS_BASE");324testExitCode = FAILED;325} else {326log2("debuggee returned expected exit status: " +327status + " == PASS_BASE");328}329330if (testExitCode != PASSED) {331System.out.println("TEST FAILED");332}333return testExitCode;334}335}336337338