Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/equals/equals001.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.equals;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.equals()</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 two <BR>44* methods with equal sets of variables and arguments, <BR>45* a debugger creates following LocalVariable objects: <BR>46* - two for the same variable in the debuggee; <BR>47* - for "the same type - different name" variable in <BR>48* the same method in the debuggee; <BR>49* - for "same name-type - different methods" variable; <BR>50* <BR>51* and applies the method LocalVariable.equals() <BR>52* to pairs of the above Localvariables to <BR>53* check up that the method returns the follwing values:<BR>54* - true if two LocalVariable mirror the same variable <BR>55* or argument in the same method in the debuggee; <BR>56* - false otherwise. <BR>57* <BR>58*/5960public class equals001 {6162//----------------------------------------------------- templete section63static final int PASSED = 0;64static final int FAILED = 2;65static final int PASS_BASE = 95;6667//----------------------------------------------------- templete parameters68static final String69sHeader1 = "\n==> nsk/jdi/LocalVariable/equals/equals001 ",70sHeader2 = "--> equals001: ",71sHeader3 = "##> equals001: ";7273//----------------------------------------------------- main method7475public static void main (String argv[]) {76int result = run(argv, System.out);77System.exit(result + PASS_BASE);78}7980public static int run (String argv[], PrintStream out) {81return new equals001().runThis(argv, out);82}8384//-------------------------------------------------- log procedures8586//private static boolean verbMode = false;8788private static Log logHandler;8990private static void log1(String message) {91logHandler.display(sHeader1 + message);92}93private static void log2(String message) {94logHandler.display(sHeader2 + message);95}96private static void log3(String message) {97logHandler.complain(sHeader3 + message);98}99100// ************************************************ test parameters101102private String debuggeeName =103"nsk.jdi.LocalVariable.equals.equals001a";104105String mName = "nsk.jdi.LocalVariable.equals";106107//====================================================== test program108109static ArgumentHandler argsHandler;110static int testExitCode = PASSED;111112//------------------------------------------------------ common section113114private int runThis (String argv[], PrintStream out) {115116Debugee debuggee;117118argsHandler = new ArgumentHandler(argv);119logHandler = new Log(out, argsHandler);120Binder binder = new Binder(argsHandler, logHandler);121122if (argsHandler.verbose()) {123debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp124} else {125debuggee = binder.bindToDebugee(debuggeeName); // *** tp126}127128IOPipe pipe = new IOPipe(debuggee);129130debuggee.redirectStderr(out);131log2("equals001a debuggee launched");132debuggee.resume();133134String line = pipe.readln();135if ((line == null) || !line.equals("ready")) {136log3("signal received is not 'ready' but: " + line);137return FAILED;138} else {139log2("'ready' recieved");140}141142VirtualMachine vm = debuggee.VM();143144//------------------------------------------------------ testing section145log1(" TESTING BEGINS");146147for (int i = 0; ; i++) {148pipe.println("newcheck");149line = pipe.readln();150151if (line.equals("checkend")) {152log2(" : returned string is 'checkend'");153break ;154} else if (!line.equals("checkready")) {155log3("ERROR: returned string is not 'checkready'");156testExitCode = FAILED;157break ;158}159160log1("new check: #" + i);161162//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part163164List listOfLoadedClasses = vm.classesByName(mName + ".TestClass");165166if (listOfLoadedClasses.size() != 1) {167testExitCode = FAILED;168log3("ERROR: listOfLoadedClasses.size() != 1 " +169listOfLoadedClasses.size());170break ;171}172173List methods1 =174((ReferenceType) listOfLoadedClasses.get(0)).175methodsByName("testmethod1");176List methods2 =177((ReferenceType) listOfLoadedClasses.get(0)).178methodsByName("testmethod2");179180Method testMethod1 = (Method) methods1.get(0);181Method testMethod2 = (Method) methods2.get(0);182183String names1[] = { "bl1", "bt1", "ch1", "db1",184"fl1", "in1", "ln1", "sh1",185"class2_1", "iface_1", "cfc_1", "param1" };186String names2[] = { "bl2", "bt2", "ch2", "db2",187"fl2", "in2", "ln2", "sh2",188"class2_2", "iface_2", "cfc_2", "param2" };189190int i2;191192for (i2 = 0; i2 < names1.length; i2++) {193194log2("new check: #" + i2);195196List lVars1 = null;197List lVars2 = null;198List lVars3 = null;199List lVars4 = null;200201try {202lVars1 = testMethod1.variablesByName(names1[i2]);203lVars2 = testMethod1.variablesByName(names1[i2]);204lVars3 = testMethod1.variablesByName(names2[i2]);205lVars4 = testMethod2.variablesByName(names1[i2]);206} catch ( AbsentInformationException e ) {207log3("ERROR: AbsentInformationException for " +208"lVars = testMethod_i.variablesByName(names[i2])" );209testExitCode = FAILED;210continue;211}212if (lVars1.size() != 1 || lVars2.size() != 1 ||213lVars3.size() != 1 || lVars4.size() != 1 ) {214testExitCode = FAILED;215log3("ERROR: lVars-i.size() != 1 for i2= " + i2);216continue;217}218219LocalVariable lVar1 = (LocalVariable) lVars1.get(0);220LocalVariable lVar2 = (LocalVariable) lVars2.get(0);221LocalVariable lVar3 = (LocalVariable) lVars3.get(0);222LocalVariable lVar4 = (LocalVariable) lVars4.get(0);223224225if (!lVar1.equals(lVar2)) {226testExitCode = FAILED;227log3("ERROR: !lVar1.equals(lvar2) for check# " + i2);228}229if (lVar1.equals(lVar3)) {230testExitCode = FAILED;231log3("ERROR: lVar1.equals(lvar3) for check# " + i2);232}233if (lVar1.equals(lVar4)) {234testExitCode = FAILED;235log3("ERROR: lVar1.equals(lvar4) for check# " + i2);236}237}238//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~239}240log1(" TESTING ENDS");241242//-------------------------------------------------- test summary section243//------------------------------------------------- standard end section244245pipe.println("quit");246log2("waiting for the debuggee to finish ...");247debuggee.waitFor();248249int status = debuggee.getStatus();250if (status != PASSED + PASS_BASE) {251log3("debuggee returned UNEXPECTED exit status: " +252status + " != PASS_BASE");253testExitCode = FAILED;254} else {255log2("debuggee returned expected exit status: " +256status + " == PASS_BASE");257}258259if (testExitCode != PASSED) {260logHandler.complain("TEST FAILED");261}262return testExitCode;263}264}265266267